z230
This commit is contained in:
@@ -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}")
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
+31
-12
@@ -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()
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user