diff --git a/Medevio3.py b/Medevio3.py deleted file mode 100644 index 0df5e02..0000000 --- a/Medevio3.py +++ /dev/null @@ -1,42 +0,0 @@ -# save_patient_detail_page.py -from pathlib import Path -from playwright.sync_api import sync_playwright - -STATE_FILE = r"/medevio_storage.json" -BASE_URL = "https://my.medevio.cz/mudr-buzalkova/klinika/pacienti" -PATIENT_ID = "fcb2414b-067b-4ca2-91b2-6c36a86d4cbb" # <-- any valid patient UUID - -def main(): - out_dir = Path(f"capture_patient_{PATIENT_ID}") - out_dir.mkdir(exist_ok=True) - - html_path = out_dir / "detail.html" - screenshot_path = out_dir / "detail.png" - - with sync_playwright() as p: - browser = p.chromium.launch(headless=True) # set False if you want to watch - context = browser.new_context(storage_state=STATE_FILE) - page = context.new_page() - - # Open the detail directly - target_url = f"{BASE_URL}?pacient={PATIENT_ID}" - page.goto(target_url, wait_until="domcontentloaded") - - # Wait a bit for the detail drawer/dialog to render - try: - page.wait_for_selector("[role='dialog'], div.MuiDrawer-paper, div[aria-modal='true']", timeout=10000) - except: - print("Warning: did not detect a detail panel quickly") - - # Save raw HTML and screenshot - html_path.write_text(page.content(), encoding="utf-8") - page.screenshot(path=str(screenshot_path), full_page=True) - - browser.close() - - print("Saved:") - print(" -", html_path.resolve()) - print(" -", screenshot_path.resolve()) - -if __name__ == "__main__": - main() diff --git a/Medevio3CapturePatients.py b/Medevio3CapturePatients.py new file mode 100644 index 0000000..9163117 --- /dev/null +++ b/Medevio3CapturePatients.py @@ -0,0 +1,111 @@ +from playwright.sync_api import sync_playwright +import mysql.connector +import time + +MYSQL_CFG = dict( + host="192.168.1.76", + port=3307, + user="root", + password="Vlado9674+", + database="medevio", +) + +# --- load 3 patients from DB --- +conn = mysql.connector.connect(**MYSQL_CFG) +with conn.cursor() as cur: + cur.execute(""" + SELECT rid, prijmeni, jmeno, rc + FROM patients_extracted + WHERE prijmeni IS NOT NULL + ORDER BY prijmeni ASC + LIMIT 3 + """) + rows = cur.fetchall() + if not rows: + raise RuntimeError("No entries found in patients_extracted") + +STATE_FILE = r"medevio_storage.json" +BASE_URL = "https://my.medevio.cz/mudr-buzalkova/klinika/pacienti" + +NOT_FOUND_SEL = "div[role='alert']:has-text('Pacient nebyl nalezen'), div:has-text('Pacient nebyl nalezen')" +DIALOG_SEL = "[role='dialog'], div.MuiDrawer-paper, div[aria-modal='true']" + +def close_dialog_if_open(page): + dlg = page.locator(DIALOG_SEL) + try: + if dlg.count(): + # Try a close button; if not, press Escape + try: + dlg.locator("button:has-text('Zavřít'), [aria-label='Zavřít'], [aria-label='Close'], [data-testid='CloseIcon']").first.click(timeout=1000) + except: + page.keyboard.press("Escape") + page.wait_for_selector(DIALOG_SEL, state="detached", timeout=1500) + except: + pass # best-effort close + +def main(): + with sync_playwright() as p: + browser = p.chromium.launch(headless=False) + try: + context = browser.new_context(storage_state=STATE_FILE) + page = context.new_page() + + for rid, surname, name, rc in rows: + # 0) close any previous dialog to avoid stale matches + close_dialog_if_open(page) + + target_url = f"{BASE_URL}?pacient={rid}" + page.goto(target_url, wait_until="domcontentloaded") + page.wait_for_load_state("networkidle") + + # 1) Not-found toast? + try: + page.wait_for_selector(NOT_FOUND_SEL, timeout=3000) + print(f"{surname} {name} {rc} – ⚠️ pacient s RID {rid} nebyl nalezen, přeskočeno") + # (optional) set mamedevioucet=NULL for this rid here + continue + except: + pass + + # 2) Detail panel + try: + page.wait_for_selector(DIALOG_SEL, timeout=6000) + except: + print(f"⚠️ {surname} {name} {rc}: detailový panel se nenačetl, přeskočeno") + continue + + # 3) Verify dialog belongs to current patient (avoid stale dialog) + detail = page.locator(DIALOG_SEL).first + detail_text = detail.inner_text() + + if (surname not in detail_text) and (rc not in detail_text): + # Still looks wrong; give UI a moment and re-check once + page.wait_for_timeout(500) + detail_text = detail.inner_text() + if (surname not in detail_text) and (rc not in detail_text): + print(f"⚠️ {surname} {name} {rc}: detail neodpovídá (stará karta?), přeskočeno") + continue + + # 4) Check Medevio account text + if "zatím nemá Medevio účet" in detail_text: + has_account = 0 + print(f"{surname} {name} {rc} – ❌ zatím nemá Medevio účet") + else: + has_account = 1 + print(f"{surname} {name} {rc} – ✅ má Medevio účet") + + # Update DB by RID (or swap to rc if you prefer) + with conn.cursor() as c: + c.execute( + "UPDATE patients_extracted SET mamedevioucet = %s WHERE rid = %s", + (has_account, rid), + ) + conn.commit() + + time.sleep(0.5) # gentle pacing + + finally: + browser.close() + +if __name__ == "__main__": + main() diff --git a/Medevio5_ReadNamesFromKartoteka_html.py b/Medevio5_ReadNamesFromKartoteka_html.py index b931254..4b6ec99 100644 --- a/Medevio5_ReadNamesFromKartoteka_html.py +++ b/Medevio5_ReadNamesFromKartoteka_html.py @@ -1,10 +1,8 @@ import mysql.connector from bs4 import BeautifulSoup import re +import time - -# ---------- CONFIG ---------- -# MySQL connection settings (fill in) MYSQL_CFG = dict( host="192.168.1.76", port=3307, @@ -13,30 +11,100 @@ MYSQL_CFG = dict( database="medevio", ) -conn=mysql.connector.connect(**MYSQL_CFG) -cur=conn.cursor() -cur.execute("select html from kartoteka_html where 'fetched-at'=(SELECT MAX('fetched-at') FROM kartoteka_html)") -html=cur.fetchone() -html=html[0] +#Helper functions +def is_valid_rc(rc: str) -> bool: + """ + Very basic RC check: + – remove any slash + – must be 9 or 10 digits + """ + rc_clean = rc.replace("/", "") + return bool(re.fullmatch(r"\d{9,10}", rc_clean)) +conn = mysql.connector.connect(**MYSQL_CFG) -# html is the string containing the entire web page -soup = BeautifulSoup(html, "html.parser") +# --- get latest HTML (single-row result) --- +with conn.cursor() as cur: + cur.execute(""" + SELECT html + FROM kartoteka_html + where round=3 + ORDER BY `fetched-at` DESC + """) + rows = cur.fetchall() + if not rows: + raise RuntimeError("No HTML found in kartoteka_html") -# Find every
Načítání
\ No newline at end of file diff --git a/capture_patient_0117c85c-630d-44c4-a5ca-dd9f3b28e25e/detail.png b/capture_patient_0117c85c-630d-44c4-a5ca-dd9f3b28e25e/detail.png new file mode 100644 index 0000000..51c5a85 Binary files /dev/null and b/capture_patient_0117c85c-630d-44c4-a5ca-dd9f3b28e25e/detail.png differ