From 87f4df4f591d2b638713f355e88993938baf5523 Mon Sep 17 00:00:00 2001 From: Vladimir Buzalka Date: Wed, 5 Nov 2025 06:32:22 +0100 Subject: [PATCH] notebook --- 100 Novi pacienti.py | 98 +++++++++++++++++++++++++++ 101 test | 1 + 101 test.py | 3 + 12 Vakcina na samostatnych listech.py | 2 +- Functions.py | 52 +++++++++++++- 5 files changed, 152 insertions(+), 4 deletions(-) create mode 100644 100 Novi pacienti.py create mode 100644 101 test create mode 100644 101 test.py diff --git a/100 Novi pacienti.py b/100 Novi pacienti.py new file mode 100644 index 0000000..fb39e7b --- /dev/null +++ b/100 Novi pacienti.py @@ -0,0 +1,98 @@ + +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +Report: DXA requisitions (Medicus → Dropbox) +-------------------------------------------- +- Selects all histdoc records for year 2025 containing "DXA" +- Finds matching PDF files in Dropbox (by rod_cis + "dxa" in name) +- Outputs Excel report: datum, idpaci, rod_cis, prijmeni, jmeno, file +""" + +import os +import firebirdsql as fb +import pandas as pd +from pathlib import Path +from datetime import datetime + +from Functions import get_dropbox_path +from Functions import get_medicus_connection + +# ================== CONFIGURATION ================== +EXPORT_DIR = Path(get_dropbox_path("reporty")) +timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") +xlsx_path = EXPORT_DIR / f"{timestamp}_Nové_registrace.xlsx" + +# ================== DATABASE QUERY ================== +conn = get_medicus_connection() +sql = """ +select rodcis, + prijmeni, + jmeno, + datum_registrace, + registr.idpac, + poj + from registr + join kar on registr.idpac=kar.idpac + where kar.vyrazen!='A' and kar.rodcis is not null and idicp!=0 and datum_zruseni is null +""" + + +df = pd.read_sql(sql, conn) +conn.close() + + + + +# ================== CLEAN OLD REPORTS ================== +for f in EXPORT_DIR.glob("*_Nové_registrace.xlsx"): + try: + f.unlink() + print(f"🗑️ Deleted old report: {f.name}") + except Exception as e: + print(f"⚠️ Could not delete {f.name}: {e}") + + +# ================== EXPORT TO EXCEL ================== +with pd.ExcelWriter(xlsx_path, engine="openpyxl") as writer: + df.to_excel(writer, index=False, sheet_name="Registrace 2025") + ws = writer.sheets["Registrace 2025"] + + # Format header + from openpyxl.styles import Font, Alignment, PatternFill, Border, Side + header_fill = PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid") + for cell in ws[1]: + cell.font = Font(bold=True, color="000000") + cell.alignment = Alignment(horizontal="center", vertical="center") + cell.fill = header_fill + + # Auto column width, but hardcode FILE column to 120 + from openpyxl.utils import get_column_letter + + for col in ws.columns: + col_letter = get_column_letter(col[0].column) + header = ws.cell(row=1, column=col[0].column).value + + if header == "FILE": + ws.column_dimensions[col_letter].width = 120 + else: + max_len = max(len(str(cell.value)) if cell.value else 0 for cell in col) + ws.column_dimensions[col_letter].width = min(max_len + 2, 80) + + # Borders + thin = Side(border_style="thin", color="000000") + border = Border(top=thin, left=thin, right=thin, bottom=thin) + for row in ws.iter_rows(min_row=1, max_row=ws.max_row, + min_col=1, max_col=ws.max_column): + for cell in row: + cell.border = border + +print(f"✅ Report created: {xlsx_path}") + +print(f"🩻 {df['FILE'].astype(bool).sum()} matching DXA PDFs found") + + + + + diff --git a/101 test b/101 test new file mode 100644 index 0000000..345dda3 --- /dev/null +++ b/101 test @@ -0,0 +1 @@ +from Functions import get \ No newline at end of file diff --git a/101 test.py b/101 test.py new file mode 100644 index 0000000..822b2a2 --- /dev/null +++ b/101 test.py @@ -0,0 +1,3 @@ +from Functions import get_dropbox_path + +print(get_dropbox_path("reporty")) \ No newline at end of file diff --git a/12 Vakcina na samostatnych listech.py b/12 Vakcina na samostatnych listech.py index b1e028c..87172e9 100644 --- a/12 Vakcina na samostatnych listech.py +++ b/12 Vakcina na samostatnych listech.py @@ -33,7 +33,7 @@ SHEETS = { "Chřipka": ["vaxigrip", "influvac", "fluarix", "afluria"], "Klíšťová encefalitida": ["fsme", "encepur"], "Tetanus": ["tetavax", "boostrix", "adacel"], - "HepA": ["avaxim", "havrix"], + "HepA": ["avaxim", "havrix","vaqta"], "HepB": ["engerix"], "HepA+B": ["twinrix"], } diff --git a/Functions.py b/Functions.py index 5a60737..f4b6ad9 100644 --- a/Functions.py +++ b/Functions.py @@ -5,6 +5,46 @@ import pymysql from pymysql.cursors import DictCursor import socket +import socket +import unicodedata + +def get_reports_folder(): + hostname = socket.gethostname().strip().upper() + if hostname in ("NTBVBHP470G10", "Z230"): + return r"u:\Dropbox\!!!Days\Downloads Z230" + elif hostname in ["SESTRA","POHODA","LEKAR"]: + return r"z:\Dropbox\Ordinace\Reporty" + else: + print(f"Unknown host: {hostname}") + return None + + +def get_dropbox_path(cesta): + hostname = socket.gethostname().strip().upper() + if hostname not in ("SESTRA", "LEKAR", "POHODA", "NTBVBHP470G10", "Z230"): + print(f"Unknown host: {hostname}") + return None + + # Choose root path based on hostname + if hostname in ("NTBVBHP470G10", "Z230"): + zacatek = r"U:\Dropbox" + else: + zacatek = r"Z:\Dropbox" + + # Normalize text (optional, safer for diacritics) + cesta_norm = unicodedata.normalize("NFC", cesta).upper().strip() + + if cesta_norm == "PŘIJATÁ": + return rf"{zacatek}\ordinace\Dokumentace_přijatá" + elif cesta_norm == "ZPRACOVANÁ": + return rf"{zacatek}\ordinace\Dokumentace_zpracovaná" + elif cesta_norm == "REPORTY": + return rf"{zacatek}\ordinace\reporty" + else: + print(f"Unknown cesta: {cesta}") + return None + + def get_path_ciselniky(): hostname = socket.gethostname().strip() if hostname in ("NTBVBHP470G10", "Z230"): @@ -35,7 +75,7 @@ def get_mysql_connection(cursor_mode=None): database="medevio", autocommit=True, ) - elif hostname == "SESTRA": + elif hostname== "SESTRA": MYSQL_CFG = dict( host="127.0.0.1", port=3307, @@ -73,14 +113,20 @@ def get_medicus_connection(): password="masterkey", charset="win1250", ) - elif socket.gethostname().strip()=="SESTRA": + elif socket.gethostname().strip() in ("SESTRA","POHODA"): MEDICUS_CFG = dict( dsn=r"192.168.1.10:m:\medicus\data\medicus.fdb", user="SYSDBA", password="masterkey", charset="win1250", ) - + elif socket.gethostname().strip()=="LEKAR": + MEDICUS_CFG = dict( + dsn=r"localhost:m:\medicus\data\medicus.fdb", + user="SYSDBA", + password="masterkey", + charset="win1250", + ) try: return fdb.connect(**MEDICUS_CFG) except fdb.fbcore.DatabaseError as e: