This commit is contained in:
2026-04-10 12:06:49 +02:00
parent 1b00c10f42
commit bafd58d2b7
28 changed files with 390 additions and 0 deletions
+118
View File
@@ -0,0 +1,118 @@
import pandas as pd
from openpyxl import load_workbook
from openpyxl.styles import Font, PatternFill, Alignment, Border, Side
from openpyxl.utils import get_column_letter
INPUT_FILE = "accountability_combined.xlsx"
OUTPUT_FILE = "accountability_formatted.xlsx"
SHEET_NAME = "CountryMedicationOverview"
COLUMN_RENAMES = {
"Site": "Site",
"Medication ID": "Med ID",
"Packaged Lot number": "Lot No.",
"Original Expiration Date when Packaged Lot was Added": "Orig Exp Date",
"Expiration date": "Exp Date",
"Received Date": "Rcv Date",
"Shipment Receipt User": "Rcpt User",
"Subject Identifier": "Subject ID",
"Quantity Assigned": "Qty Asgn",
"IRT Transaction": "IRT Tx",
"Date Assigned": "Date Asgn",
"Assignment User": "Asgn User",
"Dispensation Status": "Disp Status",
"Dispensing Date": "Disp Date",
"Quantity Dispensed": "Qty Disp",
"Dispensing User": "Disp User",
"Quantity Returned": "Qty Ret",
"Date Returned": "Date Ret",
"Return User": "Ret User",
"DestroyedOn": "Destroyed",
"Basket number": "Basket No.",
}
DATE_COLUMNS = {
"Orig Exp Date", "Exp Date", "Rcv Date",
"Date Asgn", "Disp Date", "Date Ret", "Destroyed",
}
COLUMN_WIDTHS = {
"Site": 14,
"Med ID": 10,
"Lot No.": 12,
"Orig Exp Date": 16,
"Exp Date": 14,
"Rcv Date": 14,
"Rcpt User": 22,
"Subject ID": 14,
"Qty Asgn": 9,
"IRT Tx": 8,
"Date Asgn": 14,
"Asgn User": 20,
"Disp Status": 16,
"Disp Date": 14,
"Qty Disp": 9,
"Disp User": 20,
"Qty Ret": 10,
"Date Ret": 14,
"Ret User": 18,
"Destroyed": 14,
"Basket No.": 12,
}
# ── 1. Load with pandas and convert date columns ─────────────────────────────
df = pd.read_excel(INPUT_FILE)
df.rename(columns=COLUMN_RENAMES, inplace=True)
for col in DATE_COLUMNS:
if col in df.columns:
df[col] = pd.to_datetime(df[col], dayfirst=True, errors="coerce")
df.sort_values(["Site", "Rcv Date", "Med ID"], inplace=True, ignore_index=True)
df.to_excel(OUTPUT_FILE, index=False, sheet_name=SHEET_NAME)
# ── 2. Format with openpyxl ───────────────────────────────────────────────────
wb = load_workbook(OUTPUT_FILE)
ws = wb[SHEET_NAME]
header_fill = PatternFill("solid", start_color="1F4E79")
header_font = Font(bold=True, color="FFFFFF", name="Arial", size=10)
new_col_fill = PatternFill("solid", start_color="E2EFDA")
row_font = Font(name="Arial", size=10)
thin = Side(style="thin", color="000000")
border = Border(left=thin, right=thin, top=thin, bottom=thin)
headers = [cell.value for cell in ws[1]]
new_cols = {"Destroyed", "Basket No."}
# Header row
for cell in ws[1]:
cell.fill = header_fill
cell.font = header_font
cell.alignment = Alignment(horizontal="center", vertical="center", wrap_text=False)
cell.border = border
# Data rows
max_row = ws.max_row
for row in ws.iter_rows(min_row=2, max_row=max_row):
for cell in row:
col_name = headers[cell.column - 1] if cell.column <= len(headers) else None
cell.font = row_font
cell.border = border
cell.alignment = Alignment(horizontal="center")
if col_name in DATE_COLUMNS:
cell.number_format = "DD-MMM-YYYY"
if col_name in new_cols:
cell.fill = new_col_fill
# Column widths
for cell in ws[1]:
width = COLUMN_WIDTHS.get(cell.value, 14)
ws.column_dimensions[get_column_letter(cell.column)].width = width
ws.auto_filter.ref = ws.dimensions
ws.freeze_panes = "A2"
wb.save(OUTPUT_FILE)
print(f"Saved: {OUTPUT_FILE} ({max_row - 1} rows, sheet '{SHEET_NAME}')")
+74
View File
@@ -0,0 +1,74 @@
from playwright.sync_api import sync_playwright
import json
# ── CONFIG ──────────────────────────────────────────────────────────────────
BASE_URL = "https://janssen.4gclinical.com"
STUDY = "42847922MDD3003"
EMAIL = "vbuzalka@its.jnj.com"
PASSWORD = "Vlado123++-" # doplň heslo
# ────────────────────────────────────────────────────────────────────────────
def list_reports():
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
page = browser.new_page()
# Přihlášení
page.goto(BASE_URL)
page.wait_for_load_state("networkidle")
page.get_by_label("Email *").fill(EMAIL)
page.get_by_label("Password *").fill(PASSWORD)
page.locator('#login__submit').click()
page.wait_for_load_state("networkidle")
# Výběr studie — klikni na dropdown, vyber studii, klikni SELECT
page.get_by_label("Study *").click()
page.get_by_role("option", name=STUDY).click()
page.get_by_role("button", name="SELECT").click()
page.wait_for_load_state("networkidle")
# Přejdi na seznam reportů
page.goto(f"{BASE_URL}/reports")
page.wait_for_load_state("networkidle")
page.wait_for_selector('[role="gridcell"] a', timeout=15000)
# Získej názvy reportů
names = page.evaluate("""
() => Array.from(document.querySelectorAll('[role="gridcell"] a'))
.map(a => a.innerText.trim())
.filter(n => n)
""")
print(f"\nNalezeno {len(names)} reportů, zjišťuji URL...\n")
# Pro každý report klikni, zaznamenej URL a vrať se zpět
reports = []
for name in names:
with page.expect_navigation(timeout=15000):
page.locator('[role="gridcell"] a').filter(has_text=name).click()
page.wait_for_load_state("networkidle")
page.wait_for_timeout(2000)
path = page.url.replace(BASE_URL, "")
reports.append({"name": name, "href": path})
print(f" {name:50s} {path}")
# Průběžné uložení po každém reportu
with open("reports.json", "w", encoding="utf-8") as f:
json.dump(reports, f, ensure_ascii=False, indent=2)
if page.url != f"{BASE_URL}/reports":
page.goto(f"{BASE_URL}/reports")
page.wait_for_load_state("networkidle")
page.wait_for_timeout(2000)
page.wait_for_selector('[role="gridcell"] a', timeout=30000)
browser.close()
with open("reports.json", "w", encoding="utf-8") as f:
json.dump(reports, f, ensure_ascii=False, indent=2)
print(f"\nUloženo do reports.json")
return reports
list_reports()
@@ -0,0 +1,92 @@
import pandas as pd
from openpyxl import load_workbook
from openpyxl.styles import Font, PatternFill, Alignment, Border, Side
from openpyxl.utils import get_column_letter
SOURCE_FILE = "accountability_combined.xlsx"
OUTPUT_FILE = "sheet_assigned_not_dispensed.xlsx"
SHEET_NAME = "Assigned not dispensed"
DATE_COLUMNS = {
"Orig Exp Date", "Exp Date", "Rcv Date",
"Date Asgn", "Disp Date", "Date Ret", "Destroyed",
}
COLUMN_WIDTHS = {
"Site": 14,
"Med ID": 10,
"Lot No.": 12,
"Orig Exp Date": 16,
"Exp Date": 14,
"Rcv Date": 14,
"Rcpt User": 22,
"Subject ID": 14,
"Qty Asgn": 9,
"IRT Tx": 8,
"Date Asgn": 14,
"Asgn User": 20,
"Disp Status": 16,
"Disp Date": 14,
"Qty Disp": 9,
"Disp User": 20,
"Qty Ret": 10,
"Date Ret": 14,
"Ret User": 18,
"Destroyed": 14,
"Basket No.": 12,
}
df = pd.read_excel(SOURCE_FILE)
for col in DATE_COLUMNS:
if col in df.columns:
df[col] = pd.to_datetime(df[col], errors="coerce")
# Filter: Subject ID present AND Disp Date missing
mask = df["Subject ID"].notna() & df["Disp Date"].isna()
filtered = df[mask].copy().reset_index(drop=True)
print(f"Assigned not dispensed: {len(filtered)}")
filtered.to_excel(OUTPUT_FILE, index=False, sheet_name=SHEET_NAME)
# Formatting
wb = load_workbook(OUTPUT_FILE)
ws = wb[SHEET_NAME]
header_fill = PatternFill("solid", start_color="833C00") # dark orange
header_font = Font(bold=True, color="FFFFFF", name="Arial", size=10)
row_font = Font(name="Arial", size=10)
subj_fill = PatternFill("solid", start_color="FFF2CC") # light yellow highlight for Subject ID
thin = Side(style="thin", color="000000")
border = Border(left=thin, right=thin, top=thin, bottom=thin)
headers = [cell.value for cell in ws[1]]
for cell in ws[1]:
cell.fill = header_fill
cell.font = header_font
cell.alignment = Alignment(horizontal="center", vertical="center", wrap_text=False)
cell.border = border
for row in ws.iter_rows(min_row=2, max_row=ws.max_row):
for cell in row:
col_name = headers[cell.column - 1] if cell.column <= len(headers) else None
cell.font = row_font
cell.border = border
cell.alignment = Alignment(horizontal="center")
if col_name in DATE_COLUMNS:
cell.number_format = "DD-MMM-YYYY"
if col_name == "Subject ID":
cell.fill = subj_fill
for cell in ws[1]:
width = COLUMN_WIDTHS.get(cell.value, 14)
ws.column_dimensions[get_column_letter(cell.column)].width = width
ws.auto_filter.ref = ws.dimensions
ws.freeze_panes = "A2"
wb.save(OUTPUT_FILE)
print(f"Saved: {OUTPUT_FILE} (sheet: '{SHEET_NAME}')")
+97
View File
@@ -0,0 +1,97 @@
import pandas as pd
from datetime import date
from openpyxl import load_workbook
from openpyxl.styles import Font, PatternFill, Alignment, Border, Side
from openpyxl.utils import get_column_letter
SOURCE_FILE = "accountability_combined.xlsx"
OUTPUT_FILE = "sheet_expired.xlsx"
DATE_COLUMNS = {
"Orig Exp Date", "Exp Date", "Rcv Date",
"Date Asgn", "Disp Date", "Date Ret", "Destroyed",
}
COLUMN_WIDTHS = {
"Site": 14,
"Med ID": 10,
"Lot No.": 12,
"Orig Exp Date": 16,
"Exp Date": 14,
"Rcv Date": 14,
"Rcpt User": 22,
"Subject ID": 14,
"Qty Asgn": 9,
"IRT Tx": 8,
"Date Asgn": 14,
"Asgn User": 20,
"Disp Status": 16,
"Disp Date": 14,
"Qty Disp": 9,
"Disp User": 20,
"Qty Ret": 10,
"Date Ret": 14,
"Ret User": 18,
"Destroyed": 14,
"Basket No.": 12,
}
today = date.today()
sheet_name = f"Expired as of {today.strftime('%d-%b-%Y')}"
# Load source
df = pd.read_excel(SOURCE_FILE)
# Convert date columns
for col in DATE_COLUMNS:
if col in df.columns:
df[col] = pd.to_datetime(df[col], errors="coerce")
# Filter: not in basket AND not assigned to patient AND Exp Date < today
mask = df["Basket No."].isna() & df["Subject ID"].isna() & (df["Exp Date"] < pd.Timestamp(today))
filtered = df[mask].copy().reset_index(drop=True)
print(f"Expired kits not in basket: {len(filtered)}")
filtered.to_excel(OUTPUT_FILE, index=False, sheet_name=sheet_name)
# Formatting
wb = load_workbook(OUTPUT_FILE)
ws = wb[sheet_name]
header_fill = PatternFill("solid", start_color="C00000") # dark red
header_font = Font(bold=True, color="FFFFFF", name="Arial", size=10)
row_font = Font(name="Arial", size=10)
exp_fill = PatternFill("solid", start_color="FFE0E0") # light red highlight for Exp Date
thin = Side(style="thin", color="000000")
border = Border(left=thin, right=thin, top=thin, bottom=thin)
headers = [cell.value for cell in ws[1]]
for cell in ws[1]:
cell.fill = header_fill
cell.font = header_font
cell.alignment = Alignment(horizontal="center", vertical="center", wrap_text=False)
cell.border = border
for row in ws.iter_rows(min_row=2, max_row=ws.max_row):
for cell in row:
col_name = headers[cell.column - 1] if cell.column <= len(headers) else None
cell.font = row_font
cell.border = border
cell.alignment = Alignment(horizontal="center")
if col_name in DATE_COLUMNS:
cell.number_format = "DD-MMM-YYYY"
if col_name == "Exp Date":
cell.fill = exp_fill
for cell in ws[1]:
width = COLUMN_WIDTHS.get(cell.value, 14)
ws.column_dimensions[get_column_letter(cell.column)].width = width
ws.auto_filter.ref = ws.dimensions
ws.freeze_panes = "A2"
wb.save(OUTPUT_FILE)
print(f"Saved: {OUTPUT_FILE} (sheet: '{sheet_name}')")
@@ -0,0 +1,99 @@
import pandas as pd
from openpyxl import load_workbook
from openpyxl.styles import Font, PatternFill, Alignment, Border, Side
from openpyxl.utils import get_column_letter
SOURCE_FILE = "accountability_combined.xlsx"
OUTPUT_FILE = "sheet_kits_for_destruction.xlsx"
SHEET_NAME = "Kits for destruction"
DATE_COLUMNS = {
"Orig Exp Date", "Exp Date", "Rcv Date",
"Date Asgn", "Disp Date", "Date Ret", "Destroyed",
}
COLUMN_WIDTHS = {
"Site": 14,
"Med ID": 10,
"Lot No.": 12,
"Orig Exp Date": 16,
"Exp Date": 14,
"Rcv Date": 14,
"Rcpt User": 22,
"Subject ID": 14,
"Qty Asgn": 9,
"IRT Tx": 8,
"Date Asgn": 14,
"Asgn User": 20,
"Disp Status": 16,
"Disp Date": 14,
"Qty Disp": 9,
"Disp User": 20,
"Qty Ret": 10,
"Date Ret": 14,
"Ret User": 18,
"Destroyed": 14,
"Basket No.": 12,
}
df = pd.read_excel(SOURCE_FILE)
for col in DATE_COLUMNS:
if col in df.columns:
df[col] = pd.to_datetime(df[col], errors="coerce")
# Filter: no basket AND (Date Ret filled OR Disp Status == NOT DISPENSED)
mask = (
df["Basket No."].isna() &
(
df["Date Ret"].notna() |
(df["Disp Status"].str.upper() == "NOT DISPENSED")
)
)
filtered = df[mask].copy().sort_values(["Site", "Date Ret"], ascending=[True, True])
filtered = filtered.drop(columns=["Destroyed", "Basket No."]).reset_index(drop=True)
print(f"Kits for destruction: {len(filtered)}")
filtered.to_excel(OUTPUT_FILE, index=False, sheet_name=SHEET_NAME)
# Formatting
wb = load_workbook(OUTPUT_FILE)
ws = wb[SHEET_NAME]
header_fill = PatternFill("solid", start_color="595959") # dark grey
header_font = Font(bold=True, color="FFFFFF", name="Arial", size=10)
row_font = Font(name="Arial", size=10)
basket_fill = PatternFill("solid", start_color="FFE0E0") # light red for empty Basket No.
thin = Side(style="thin", color="000000")
border = Border(left=thin, right=thin, top=thin, bottom=thin)
headers = [cell.value for cell in ws[1]]
for cell in ws[1]:
cell.fill = header_fill
cell.font = header_font
cell.alignment = Alignment(horizontal="center", vertical="center", wrap_text=False)
cell.border = border
for row in ws.iter_rows(min_row=2, max_row=ws.max_row):
for cell in row:
col_name = headers[cell.column - 1] if cell.column <= len(headers) else None
cell.font = row_font
cell.border = border
cell.alignment = Alignment(horizontal="center")
if col_name in DATE_COLUMNS:
cell.number_format = "DD-MMM-YYYY"
if col_name == "Basket No.":
cell.fill = basket_fill
for cell in ws[1]:
width = COLUMN_WIDTHS.get(cell.value, 14)
ws.column_dimensions[get_column_letter(cell.column)].width = width
ws.auto_filter.ref = ws.dimensions
ws.freeze_panes = "A2"
wb.save(OUTPUT_FILE)
print(f"Saved: {OUTPUT_FILE} (sheet: '{SHEET_NAME}')")
+102
View File
@@ -0,0 +1,102 @@
import pandas as pd
from openpyxl import load_workbook
from openpyxl.styles import Font, PatternFill, Alignment, Border, Side
from openpyxl.utils import get_column_letter
SOURCE_FILE = "accountability_combined.xlsx"
OUTPUT_FILE = "sheet_not_returned.xlsx"
SHEET_NAME = "Not returned"
DATE_COLUMNS = {
"Orig Exp Date", "Exp Date", "Rcv Date",
"Date Asgn", "Disp Date", "Max Visit Date",
}
COLUMN_WIDTHS = {
"Site": 14,
"Med ID": 10,
"Lot No.": 12,
"Orig Exp Date": 16,
"Exp Date": 14,
"Rcv Date": 14,
"Rcpt User": 22,
"Subject ID": 14,
"Qty Asgn": 9,
"IRT Tx": 8,
"Date Asgn": 14,
"Asgn User": 20,
"Disp Status": 16,
"Disp Date": 14,
"Qty Disp": 9,
"Disp User": 20,
"Max Visit Date": 16,
}
df = pd.read_excel(SOURCE_FILE)
for col in DATE_COLUMNS:
if col in df.columns:
df[col] = pd.to_datetime(df[col], errors="coerce")
# Kits with no return date, assigned to a patient, and not "NOT DISPENSED"
no_ret = df[
df["Date Ret"].isna() &
df["Subject ID"].notna() &
(df["Disp Status"].str.upper() != "NOT DISPENSED")
].copy()
# Max Date Asgn per patient (from full dataset)
max_asgn = df.groupby("Subject ID")["Date Asgn"].max().rename("Max Visit Date")
no_ret = no_ret.join(max_asgn, on="Subject ID")
# Keep only kits where Date Asgn is NOT the latest for that patient
filtered = no_ret[no_ret["Date Asgn"] < no_ret["Max Visit Date"]].copy()
# Drop columns Q-U and keep Max Visit Date
filtered = filtered.drop(columns=["Qty Ret", "Date Ret", "Ret User", "Destroyed", "Basket No."])
filtered = filtered.reset_index(drop=True)
print(f"Not returned kits: {len(filtered)}")
filtered.to_excel(OUTPUT_FILE, index=False, sheet_name=SHEET_NAME)
# Formatting
wb = load_workbook(OUTPUT_FILE)
ws = wb[SHEET_NAME]
header_fill = PatternFill("solid", start_color="375623") # dark green
header_font = Font(bold=True, color="FFFFFF", name="Arial", size=10)
row_font = Font(name="Arial", size=10)
ret_fill = PatternFill("solid", start_color="E2EFDA") # light green highlight for Date Ret
thin = Side(style="thin", color="000000")
border = Border(left=thin, right=thin, top=thin, bottom=thin)
headers = [cell.value for cell in ws[1]]
for cell in ws[1]:
cell.fill = header_fill
cell.font = header_font
cell.alignment = Alignment(horizontal="center", vertical="center", wrap_text=False)
cell.border = border
for row in ws.iter_rows(min_row=2, max_row=ws.max_row):
for cell in row:
col_name = headers[cell.column - 1] if cell.column <= len(headers) else None
cell.font = row_font
cell.border = border
cell.alignment = Alignment(horizontal="center")
if col_name in DATE_COLUMNS:
cell.number_format = "DD-MMM-YYYY"
if col_name == "Max Visit Date":
cell.fill = ret_fill
for cell in ws[1]:
width = COLUMN_WIDTHS.get(cell.value, 14)
ws.column_dimensions[get_column_letter(cell.column)].width = width
ws.auto_filter.ref = ws.dimensions
ws.freeze_panes = "A2"
wb.save(OUTPUT_FILE)
print(f"Saved: {OUTPUT_FILE} (sheet: '{SHEET_NAME}')")