diff --git a/IWRS/create_accountability_report.py b/IWRS/create_accountability_report.py index 8638cbc..dfee950 100644 --- a/IWRS/create_accountability_report.py +++ b/IWRS/create_accountability_report.py @@ -5,10 +5,13 @@ from openpyxl import load_workbook from openpyxl.styles import Font, PatternFill, Alignment, Border, Side from openpyxl.utils import get_column_letter -INVENTORY_DIR = Path("xls_reports") -DESTRUCTION_DIR = Path("xls_ip_destruction") +# STUDY = "42847922MDD3003" +STUDY = "77242113UCO3001" + +INVENTORY_DIR = Path(f"xls_reports_{STUDY}") +DESTRUCTION_DIR = Path(f"xls_ip_destruction_{STUDY}") OUTPUT_DIR = Path("output") -OUTPUT_FILE = OUTPUT_DIR / f"{date.today().strftime('%Y-%m-%d')} 42847922MDD3003 CZ IWRS overview.xlsx" +OUTPUT_FILE = OUTPUT_DIR / f"{date.today().strftime('%Y-%m-%d')} {STUDY} CZ IWRS overview.xlsx" # ── Shared constants ────────────────────────────────────────────────────────── @@ -27,6 +30,7 @@ COLUMN_RENAMES = { "Assignment User": "Asgn User", "Dispensation Status": "Disp Status", "Dispensing Date": "Disp Date", + "Dispensing date": "Disp Date", "Quantity Dispensed": "Qty Disp", "Dispensing User": "Disp User", "Quantity Returned": "Qty Ret", @@ -70,13 +74,19 @@ COLUMN_WIDTHS = { def read_inventory(path): df = pd.read_excel(path, header=None) - header_row = df[df[0] == "Medication ID"].index[0] - data = pd.read_excel(path, header=header_row) + # Support both "Medication ID" (MDD3003) and "Medication" (UCO3001) + mask = df[0].isin(["Medication ID", "Medication"]) meta = {} - for i in range(header_row): + for i in range(len(df)): val = str(df.iloc[i, 0]) if pd.notna(df.iloc[i, 0]) else "" if val.startswith("Site:"): meta["site"] = val.replace("Site:", "").strip() + if not mask.any(): + print(f" {path.name}: no data (skipping)") + return None, meta + header_row = df[mask].index[0] + data = pd.read_excel(path, header=header_row) + data = data.rename(columns={"Medication": "Medication ID"}) return data, meta @@ -140,6 +150,8 @@ def build_main(lookup): all_rows = [] for path in sorted(INVENTORY_DIR.glob("onsite_inventory_detail_*.xlsx")): df, meta = read_inventory(path) + if df is None: + continue df["DestroyedOn"] = df["Medication ID"].apply( lambda x: lookup.get(int(x), (None, None))[1] if pd.notna(x) else None) df["Basket number"] = df["Medication ID"].apply( @@ -208,7 +220,7 @@ def build_kits_for_destruction(df): def main(): # Prepare output dir, remove any previous overview file OUTPUT_DIR.mkdir(exist_ok=True) - for old in OUTPUT_DIR.glob("*42847922MDD3003 CZ IWRS overview.xlsx"): + for old in OUTPUT_DIR.glob(f"*{STUDY} CZ IWRS overview.xlsx"): old.unlink() print(f"Removed old file: {old.name}") diff --git a/IWRS/download_ip_destruction.py b/IWRS/download_ip_destruction.py index 5e2959d..848fb3d 100644 --- a/IWRS/download_ip_destruction.py +++ b/IWRS/download_ip_destruction.py @@ -7,7 +7,10 @@ BASE_URL = "https://janssen.4gclinical.com" EMAIL = "vbuzalka@its.jnj.com" PASSWORD = "Vlado123++-" -OUTPUT_DIR = "xls_ip_destruction" +# STUDY = "42847922MDD3003" +STUDY = "77242113UCO3001" + +OUTPUT_DIR = f"xls_ip_destruction_{STUDY}" # ──────────────────────────────────────────────────────────────────────────── os.makedirs(OUTPUT_DIR, exist_ok=True) @@ -29,7 +32,7 @@ def download_ip_destruction(): # Výběr studie page.get_by_label("Study *").click() - page.get_by_role("option", name="42847922MDD3003").click() + page.get_by_role("option", name=STUDY).click() page.get_by_role("button", name="SELECT").click() page.wait_for_load_state("networkidle") @@ -40,11 +43,17 @@ def download_ip_destruction(): # Přečti dostupné košíky page.locator('input[placeholder="search"], input[type="text"]').first.click() page.wait_for_timeout(1000) - baskets = [b.strip() for b in page.locator('mat-option').all_inner_texts()] + baskets = [b.strip() for b in page.locator('mat-option').all_inner_texts() + if b.strip() != "No results found"] print(f"Nalezeno {len(baskets)} košíků: {baskets}") page.keyboard.press("Escape") page.wait_for_timeout(500) + if not baskets: + print("Žádné destruction košíky nenalezeny — přeskakuji.") + browser.close() + return + for basket in baskets: filename = os.path.join(OUTPUT_DIR, f"ip_destruction_basket_{basket}.xlsx") if os.path.exists(filename): diff --git a/IWRS/download_reports.py b/IWRS/download_reports.py index 8196945..806a7b3 100644 --- a/IWRS/download_reports.py +++ b/IWRS/download_reports.py @@ -7,16 +7,35 @@ BASE_URL = "https://janssen.4gclinical.com" EMAIL = "vbuzalka@its.jnj.com" PASSWORD = "Vlado123++-" -SITES = [ - "S10-CZ10002", - "S10-CZ10004", - "S10-CZ10005", - "S10-CZ10008", - "S10-CZ10011", - "S10-CZ10012", -] +# STUDY = "42847922MDD3003" +STUDY = "77242113UCO3001" -OUTPUT_DIR = "xls_reports" +SITES = { + "42847922MDD3003": [ + "S10-CZ10002", + "S10-CZ10004", + "S10-CZ10005", + "S10-CZ10008", + "S10-CZ10011", + "S10-CZ10012", + ], + "77242113UCO3001": [ + "DD5-CZ10001", + "DD5-CZ10003", + "DD5-CZ10006", + "DD5-CZ10009", + "DD5-CZ10010", + "DD5-CZ10012", + "DD5-CZ10013", + "DD5-CZ10015", + "DD5-CZ10016", + "DD5-CZ10020", + "DD5-CZ10021", + "DD5-CZ10022", + ], +} + +OUTPUT_DIR = f"xls_reports_{STUDY}" # ──────────────────────────────────────────────────────────────────────────── os.makedirs(OUTPUT_DIR, exist_ok=True) @@ -38,7 +57,7 @@ def download_reports(): # Výběr studie page.get_by_label("Study *").click() - page.get_by_role("option", name="42847922MDD3003").click() + page.get_by_role("option", name=STUDY).click() page.get_by_role("button", name="SELECT").click() page.wait_for_load_state("networkidle") @@ -46,7 +65,7 @@ def download_reports(): page.goto(f"{BASE_URL}/report/onsite_inventory_detail") page.wait_for_load_state("networkidle", timeout=15000) - for site_id in SITES: + for site_id in SITES[STUDY]: print(f"[{site_id}] Stahuji...") # Otevři dropdown a vyber site @@ -63,7 +82,7 @@ def download_reports(): download = dl.value filename = os.path.join(OUTPUT_DIR, f"onsite_inventory_detail_{site_id}.xlsx") download.save_as(filename) - print(f"[{site_id}] Uloženo → {filename}") + print(f"[{site_id}] Ulozeno: {filename}") # Zruš výběr site pro další iteraci page.get_by_role("button", name="Clear").click() diff --git a/IWRS/output/2026-04-10 42847922MDD3003 CZ IWRS overview.xlsx b/IWRS/output/2026-04-10 42847922MDD3003 CZ IWRS overview.xlsx index 3ace6aa..c609cba 100644 Binary files a/IWRS/output/2026-04-10 42847922MDD3003 CZ IWRS overview.xlsx and b/IWRS/output/2026-04-10 42847922MDD3003 CZ IWRS overview.xlsx differ diff --git a/IWRS/output/2026-04-10 77242113UCO3001 CZ IWRS overview.xlsx b/IWRS/output/2026-04-10 77242113UCO3001 CZ IWRS overview.xlsx new file mode 100644 index 0000000..ebacc09 Binary files /dev/null and b/IWRS/output/2026-04-10 77242113UCO3001 CZ IWRS overview.xlsx differ diff --git a/IWRS/xls_ip_destruction/ip_destruction_basket_194.xlsx b/IWRS/xls_ip_destruction_42847922MDD3003/ip_destruction_basket_194.xlsx similarity index 100% rename from IWRS/xls_ip_destruction/ip_destruction_basket_194.xlsx rename to IWRS/xls_ip_destruction_42847922MDD3003/ip_destruction_basket_194.xlsx diff --git a/IWRS/xls_ip_destruction/ip_destruction_basket_202.xlsx b/IWRS/xls_ip_destruction_42847922MDD3003/ip_destruction_basket_202.xlsx similarity index 100% rename from IWRS/xls_ip_destruction/ip_destruction_basket_202.xlsx rename to IWRS/xls_ip_destruction_42847922MDD3003/ip_destruction_basket_202.xlsx diff --git a/IWRS/xls_ip_destruction/ip_destruction_basket_248.xlsx b/IWRS/xls_ip_destruction_42847922MDD3003/ip_destruction_basket_248.xlsx similarity index 100% rename from IWRS/xls_ip_destruction/ip_destruction_basket_248.xlsx rename to IWRS/xls_ip_destruction_42847922MDD3003/ip_destruction_basket_248.xlsx diff --git a/IWRS/xls_ip_destruction/ip_destruction_basket_269.xlsx b/IWRS/xls_ip_destruction_42847922MDD3003/ip_destruction_basket_269.xlsx similarity index 100% rename from IWRS/xls_ip_destruction/ip_destruction_basket_269.xlsx rename to IWRS/xls_ip_destruction_42847922MDD3003/ip_destruction_basket_269.xlsx diff --git a/IWRS/xls_ip_destruction/ip_destruction_basket_273.xlsx b/IWRS/xls_ip_destruction_42847922MDD3003/ip_destruction_basket_273.xlsx similarity index 100% rename from IWRS/xls_ip_destruction/ip_destruction_basket_273.xlsx rename to IWRS/xls_ip_destruction_42847922MDD3003/ip_destruction_basket_273.xlsx diff --git a/IWRS/xls_ip_destruction/ip_destruction_basket_276.xlsx b/IWRS/xls_ip_destruction_42847922MDD3003/ip_destruction_basket_276.xlsx similarity index 100% rename from IWRS/xls_ip_destruction/ip_destruction_basket_276.xlsx rename to IWRS/xls_ip_destruction_42847922MDD3003/ip_destruction_basket_276.xlsx diff --git a/IWRS/xls_reports/onsite_inventory_detail_S10-CZ10002.xlsx b/IWRS/xls_reports_42847922MDD3003/onsite_inventory_detail_S10-CZ10002.xlsx similarity index 100% rename from IWRS/xls_reports/onsite_inventory_detail_S10-CZ10002.xlsx rename to IWRS/xls_reports_42847922MDD3003/onsite_inventory_detail_S10-CZ10002.xlsx diff --git a/IWRS/xls_reports/onsite_inventory_detail_S10-CZ10004.xlsx b/IWRS/xls_reports_42847922MDD3003/onsite_inventory_detail_S10-CZ10004.xlsx similarity index 100% rename from IWRS/xls_reports/onsite_inventory_detail_S10-CZ10004.xlsx rename to IWRS/xls_reports_42847922MDD3003/onsite_inventory_detail_S10-CZ10004.xlsx diff --git a/IWRS/xls_reports/onsite_inventory_detail_S10-CZ10005.xlsx b/IWRS/xls_reports_42847922MDD3003/onsite_inventory_detail_S10-CZ10005.xlsx similarity index 100% rename from IWRS/xls_reports/onsite_inventory_detail_S10-CZ10005.xlsx rename to IWRS/xls_reports_42847922MDD3003/onsite_inventory_detail_S10-CZ10005.xlsx diff --git a/IWRS/xls_reports/onsite_inventory_detail_S10-CZ10008.xlsx b/IWRS/xls_reports_42847922MDD3003/onsite_inventory_detail_S10-CZ10008.xlsx similarity index 100% rename from IWRS/xls_reports/onsite_inventory_detail_S10-CZ10008.xlsx rename to IWRS/xls_reports_42847922MDD3003/onsite_inventory_detail_S10-CZ10008.xlsx diff --git a/IWRS/xls_reports/onsite_inventory_detail_S10-CZ10011.xlsx b/IWRS/xls_reports_42847922MDD3003/onsite_inventory_detail_S10-CZ10011.xlsx similarity index 100% rename from IWRS/xls_reports/onsite_inventory_detail_S10-CZ10011.xlsx rename to IWRS/xls_reports_42847922MDD3003/onsite_inventory_detail_S10-CZ10011.xlsx diff --git a/IWRS/xls_reports/onsite_inventory_detail_S10-CZ10012.xlsx b/IWRS/xls_reports_42847922MDD3003/onsite_inventory_detail_S10-CZ10012.xlsx similarity index 100% rename from IWRS/xls_reports/onsite_inventory_detail_S10-CZ10012.xlsx rename to IWRS/xls_reports_42847922MDD3003/onsite_inventory_detail_S10-CZ10012.xlsx diff --git a/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10001.xlsx b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10001.xlsx new file mode 100644 index 0000000..f33c99b Binary files /dev/null and b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10001.xlsx differ diff --git a/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10003.xlsx b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10003.xlsx new file mode 100644 index 0000000..8672d78 Binary files /dev/null and b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10003.xlsx differ diff --git a/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10006.xlsx b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10006.xlsx new file mode 100644 index 0000000..f524b72 Binary files /dev/null and b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10006.xlsx differ diff --git a/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10009.xlsx b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10009.xlsx new file mode 100644 index 0000000..a471042 Binary files /dev/null and b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10009.xlsx differ diff --git a/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10010.xlsx b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10010.xlsx new file mode 100644 index 0000000..ac9d62b Binary files /dev/null and b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10010.xlsx differ diff --git a/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10012.xlsx b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10012.xlsx new file mode 100644 index 0000000..22e6d6c Binary files /dev/null and b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10012.xlsx differ diff --git a/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10013.xlsx b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10013.xlsx new file mode 100644 index 0000000..813e5c7 Binary files /dev/null and b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10013.xlsx differ diff --git a/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10015.xlsx b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10015.xlsx new file mode 100644 index 0000000..067fdd3 Binary files /dev/null and b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10015.xlsx differ diff --git a/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10016.xlsx b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10016.xlsx new file mode 100644 index 0000000..7888ee4 Binary files /dev/null and b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10016.xlsx differ diff --git a/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10020.xlsx b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10020.xlsx new file mode 100644 index 0000000..49f4296 Binary files /dev/null and b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10020.xlsx differ diff --git a/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10021.xlsx b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10021.xlsx new file mode 100644 index 0000000..88e3538 Binary files /dev/null and b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10021.xlsx differ diff --git a/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10022.xlsx b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10022.xlsx new file mode 100644 index 0000000..c948bf7 Binary files /dev/null and b/IWRS/xls_reports_77242113UCO3001/onsite_inventory_detail_DD5-CZ10022.xlsx differ