z230
This commit is contained in:
+26
-20
@@ -139,16 +139,16 @@ def write_prehled(wb, df):
|
||||
ws.sheet_view.showGridLines = False
|
||||
|
||||
today = datetime.date.today().strftime("%d-%b-%Y")
|
||||
write_title(ws, f"Covance Samples — {STUDY} ({today})", 8)
|
||||
write_title(ws, f"Covance Samples — {STUDY} ({today})", 9)
|
||||
|
||||
headers = ["Site", "Investigátor", "Pacient", "Visit", "Datum odběru",
|
||||
"Celkem", "Received", "Not Received"]
|
||||
widths = [9, 22, 14, 12, 14, 8, 10, 13]
|
||||
headers = ["Site", "Investigátor", "Pacient", "Visit", "Accession",
|
||||
"Datum odběru", "Celkem", "Received", "Not Received"]
|
||||
widths = [9, 22, 14, 12, 13, 14, 8, 10, 13]
|
||||
write_headers(ws, headers, widths)
|
||||
|
||||
agg = (
|
||||
df.groupby(["investigator_no", "investigator_name",
|
||||
"patient_no", "protocol_visit_code", "collection_date"])
|
||||
"patient_no", "protocol_visit_code", "accession", "collection_date"])
|
||||
.agg(
|
||||
celkem =("sample_status", "count"),
|
||||
received =("sample_status", lambda x: (x == "Received").sum()),
|
||||
@@ -169,22 +169,22 @@ def write_prehled(wb, df):
|
||||
|
||||
values = [
|
||||
row["investigator_no"], row["investigator_name"], row["patient_no"],
|
||||
row["protocol_visit_code"], date_str,
|
||||
row["protocol_visit_code"], row["accession"], date_str,
|
||||
int(row["celkem"]), int(row["received"]), int(row["not_received"]),
|
||||
]
|
||||
for c_idx, val in enumerate(values, 1):
|
||||
cell = ws.cell(row=excel_row, column=c_idx, value=val)
|
||||
cell.fill = fill
|
||||
cell.border = BORDER
|
||||
cell.alignment = CENTER if c_idx in (1, 4, 5, 6, 7, 8) else LEFT
|
||||
if c_idx == 8 and has_missing:
|
||||
cell.alignment = CENTER if c_idx in (1, 4, 5, 6, 7, 8, 9) else LEFT
|
||||
if c_idx == 9 and has_missing:
|
||||
cell.font = RED_FONT
|
||||
else:
|
||||
cell.font = NORMAL_FONT
|
||||
ws.row_dimensions[excel_row].height = 16
|
||||
|
||||
ws.freeze_panes = "A3"
|
||||
ws.auto_filter.ref = f"A2:H{len(agg) + 2}"
|
||||
ws.auto_filter.ref = f"A2:I{len(agg) + 2}"
|
||||
|
||||
|
||||
# ── sheet 2: Chybějící ────────────────────────────────────────────────────────
|
||||
@@ -275,34 +275,35 @@ def write_kity(wb, df_kits):
|
||||
.sort_values("site_code")
|
||||
.values.tolist())
|
||||
|
||||
# sloupce: A=Kit Type, B=Popis, C=≤30 dní, D=>30 dní
|
||||
# sloupce: A=Kit Type, B=Popis, C=≤30 dní, D=>30 dní, E=Celkem
|
||||
ws.column_dimensions["A"].width = 9
|
||||
ws.column_dimensions["B"].width = 28
|
||||
ws.column_dimensions["C"].width = 14
|
||||
ws.column_dimensions["D"].width = 14
|
||||
ws.column_dimensions["E"].width = 10
|
||||
|
||||
write_title(ws, f"Kit Inventory — {STUDY} ({today_str})", 4)
|
||||
write_title(ws, f"Kit Inventory — {STUDY} ({today_str})", 5)
|
||||
|
||||
# sub-header (řádek 2)
|
||||
# sub-header (řádek 2) — bez pevné výšky, Excel si ji sám přizpůsobí
|
||||
for col, txt in [(1, "Kit Type"), (2, "Popis"),
|
||||
(3, f"Expiruje ≤30 dní\n({cutoff.strftime('%d-%b-%Y')})"),
|
||||
(4, "Expiruje >30 dní")]:
|
||||
(4, "Expiruje >30 dní"),
|
||||
(5, "Celkem")]:
|
||||
c = ws.cell(row=2, column=col, value=txt)
|
||||
c.font = HEADER_FONT; c.fill = HEADER_FILL
|
||||
c.alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
||||
c.border = BORDER
|
||||
ws.row_dimensions[2].height = 28
|
||||
|
||||
cur_row = 3
|
||||
|
||||
for site_code, investigator in sites:
|
||||
# ── site header ───────────────────────────────────────────────────────
|
||||
ws.merge_cells(f"A{cur_row}:D{cur_row}")
|
||||
ws.merge_cells(f"A{cur_row}:E{cur_row}")
|
||||
c = ws.cell(row=cur_row, column=1,
|
||||
value=f"{site_code} — {investigator}")
|
||||
c.font = SITE_HDR_FONT; c.fill = SITE_HDR_FILL
|
||||
c.alignment = LEFT; c.border = BORDER
|
||||
for col in range(2, 5):
|
||||
for col in range(2, 6):
|
||||
ws.cell(row=cur_row, column=col).fill = SITE_HDR_FILL
|
||||
ws.cell(row=cur_row, column=col).border = BORDER
|
||||
ws.row_dimensions[cur_row].height = 17
|
||||
@@ -310,7 +311,6 @@ def write_kity(wb, df_kits):
|
||||
|
||||
# kity tohoto centra
|
||||
site_df = df_kits[df_kits["site_code"] == site_code].copy()
|
||||
# přepočítej expiraci od dnešního dne
|
||||
site_df["exp_date"] = pd.to_datetime(site_df["expiration_date"]).dt.date
|
||||
|
||||
site_soon = 0
|
||||
@@ -324,26 +324,32 @@ def write_kity(wb, df_kits):
|
||||
lambda d: d is not None and d > cutoff)).sum())
|
||||
site_soon += soon
|
||||
site_later += later
|
||||
total = soon + later
|
||||
|
||||
fill = EVEN_FILL if kt_idx % 2 == 0 else ODD_FILL
|
||||
|
||||
_cell(ws, cur_row, 1, kt, BOLD_FONT, fill, CENTER, BORDER)
|
||||
_cell(ws, cur_row, 2, kt_desc.get(kt, ""), NORMAL_FONT, fill, LEFT, BORDER)
|
||||
_cell(ws, cur_row, 3, soon if soon else None,
|
||||
RED_FONT if soon else NORMAL_FONT,
|
||||
RED_FONT if soon else NORMAL_FONT,
|
||||
SOON_FILL if soon else fill, CENTER, BORDER)
|
||||
_cell(ws, cur_row, 4, later if later else None,
|
||||
NORMAL_FONT, fill, CENTER, BORDER)
|
||||
_cell(ws, cur_row, 5, total if total else None,
|
||||
BOLD_FONT, fill, CENTER, BORDER)
|
||||
ws.row_dimensions[cur_row].height = 16
|
||||
cur_row += 1
|
||||
|
||||
# ── součet centra ─────────────────────────────────────────────────────
|
||||
_cell(ws, cur_row, 1, "Celkem", BOLD_FONT, TOTAL_FILL, CENTER, BORDER)
|
||||
_cell(ws, cur_row, 2, "", BOLD_FONT, TOTAL_FILL, LEFT, BORDER)
|
||||
site_total = site_soon + site_later
|
||||
_cell(ws, cur_row, 1, "Celkem", BOLD_FONT, TOTAL_FILL, CENTER, BORDER)
|
||||
_cell(ws, cur_row, 2, "", BOLD_FONT, TOTAL_FILL, LEFT, BORDER)
|
||||
_cell(ws, cur_row, 3, site_soon if site_soon else None,
|
||||
BOLD_FONT, TOTAL_FILL, CENTER, BORDER)
|
||||
_cell(ws, cur_row, 4, site_later if site_later else None,
|
||||
BOLD_FONT, TOTAL_FILL, CENTER, BORDER)
|
||||
_cell(ws, cur_row, 5, site_total if site_total else None,
|
||||
BOLD_FONT, TOTAL_FILL, CENTER, BORDER)
|
||||
ws.row_dimensions[cur_row].height = 16
|
||||
cur_row += 2 # prázdný řádek mezi centry
|
||||
|
||||
|
||||
Reference in New Issue
Block a user