This commit is contained in:
2026-06-03 07:10:15 +02:00
parent 9ed9f97140
commit 681095d557
60 changed files with 215 additions and 2161 deletions
+57 -28
View File
@@ -156,38 +156,62 @@ def run(page, study):
total_notif = 0
for subject in subjects:
filename = os.path.join(out_dir, f"{today} {study} {subject} Subject Detail.xlsx")
print(f" [{subject}] Stahuji...")
input_field = page.locator('input[placeholder="search"], input[type="text"]').first
input_field.click()
input_field.fill(subject)
page.wait_for_timeout(500)
# Zachytíme table_1 response při výběru subjektu
if api_base:
success = False
table1_data = None
for attempt in range(1, 4):
try:
with page.expect_response(
lambda r: "report_data" in r.url and "table_1" in r.url,
timeout=60000
) as resp_info:
print(f" [{subject}] Stahuji... (pokus {attempt}/3)")
input_field = page.locator('input[placeholder="search"], input[type="text"]').first
input_field.click()
input_field.fill(subject)
page.wait_for_timeout(500)
# Zachytíme table_1 response při výběru subjektu
if api_base:
try:
with page.expect_response(
lambda r: "report_data" in r.url and "table_1" in r.url,
timeout=60000
) as resp_info:
page.locator("mat-option").first.dispatch_event("click")
table1_data = resp_info.value.json()
except Exception as e:
print(f" [{subject}] CHYBA zachycení table_1: {e}")
page.locator("mat-option").first.dispatch_event("click")
page.wait_for_load_state("networkidle", timeout=120000)
table1_data = None
else:
page.locator("mat-option").first.dispatch_event("click")
table1_data = resp_info.value.json()
except Exception as e:
print(f" [{subject}] CHYBA zachycení table_1: {e}")
page.locator("mat-option").first.dispatch_event("click")
page.wait_for_load_state("networkidle", timeout=120000)
table1_data = None
page.wait_for_load_state("networkidle", timeout=120000)
table1_data = None
else:
page.locator("mat-option").first.dispatch_event("click")
page.wait_for_load_state("networkidle", timeout=120000)
table1_data = None
page.wait_for_timeout(2000)
page.wait_for_load_state("networkidle", timeout=120000)
page.wait_for_timeout(1000)
with page.expect_download(timeout=60000) as dl:
page.get_by_role("button", name="Download XLS").click()
dl.value.save_as(filename)
print(f" [{subject}] XLS OK")
success = True
break
except Exception as e:
print(f" [{subject}] pokus {attempt} selhal: {e}")
if attempt < 3:
try:
page.goto(f"{BASE_URL}/report/patient_detail_report")
page.wait_for_load_state("networkidle", timeout=120000)
except Exception as ge:
print(f" [{subject}] refresh selhal: {ge}")
with page.expect_download(timeout=120000) as dl:
page.get_by_role("button", name="Download XLS").click()
dl.value.save_as(filename)
print(f" [{subject}] XLS OK")
if not success:
print(f" [{subject}] PŘESKAKUJI po 3 neúspěšných pokusech")
try:
page.goto(f"{BASE_URL}/report/patient_detail_report")
page.wait_for_load_state("networkidle", timeout=120000)
except Exception:
pass
continue
# Stáhnout notifikace pro tohoto subjekta
if api_base and table1_data:
@@ -196,8 +220,13 @@ def run(page, study):
)
total_notif += n
page.get_by_role("button", name="Clear").click()
page.wait_for_load_state("networkidle", timeout=120000)
try:
page.get_by_role("button", name="Clear").click()
page.wait_for_load_state("networkidle", timeout=120000)
except Exception as e:
print(f" [{subject}] Clear selhal: {e} — refresh")
page.goto(f"{BASE_URL}/report/patient_detail_report")
page.wait_for_load_state("networkidle", timeout=120000)
print(f" [{study}] Subject details hotovo. Nových notifikací: {total_notif}")