Clinical-Genomics / cg

Glue between Clinical Genomics apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mark old orders as delivered

seallard opened this issue · comments

Given a set of closed tickets, mark the corresponding orders as delivered.

import csv
from cg.store.store import Store
from cg.store.database import initialize_database
from cg.store.database import get_session
from cg.store.models import Order

csv_file_path = "closed_susy_tickets.csv"

store = Store()

with open(csv_file_path, newline="") as csvfile:
    reader = csv.reader(csvfile)
    next(reader)
    for row in reader:
        ticket_id = row[0]
        print(ticket_id)
        order: Order | None = store.get_order_by_ticket_id(ticket_id)

        if order:
            order.is_delivered = True

try:
    session = get_session()
    session.commit()
except Exception as e:
    session.rollback()
finally:
    session.close()

I guess one should skip the first row but on the other hand, the if order will probably take care of that. Looks good otherwise! Might want to close the file unless that is done automatically upon exit.

LGTM! If you want to be sure you could implement a dry-run where you don't commit at first. But honestly it looks good as it is 👍

I guess one should skip the first row but on the other hand, the if order will probably take care of that. Looks good otherwise! Might want to close the file unless that is done automatically upon exit.

I guess the next(reader) takes care of that

Ran in production.

  • 1693 orders were marked as delivered based on the ticket status being closed.
  • 747 out of these orders were placed in 2024.
  • 23 out of these orders have fewer completed/delivered analyses than cases.

These are the 23 orders from 2024 where the number of completed analyses did not match the number of cases

9064, 9111, 9112, 9114, 9115, 9179, 9376, 9386, 9558, 9637, 9665, 9676, 9698, 9774, 9778, 9779, 9843, 9891, 9910, 9971, 9975, 9978, 9994