diff --git a/10 Tests/test stavpojisteni.py b/00 Funkční testy/10 Funkční test stavpojisteni.py similarity index 91% rename from 10 Tests/test stavpojisteni.py rename to 00 Funkční testy/10 Funkční test stavpojisteni.py index 9d3a323..409c026 100644 --- a/10 Tests/test stavpojisteni.py +++ b/00 Funkční testy/10 Funkční test stavpojisteni.py @@ -8,7 +8,7 @@ from vzpb2b_client import VZPB2BClient client = VZPB2BClient( env="production", - pfx_path="mbcert.pfx", + pfx_path="../10 Tests/MBcert.pfx", pfx_password="Vlado7309208104++", icz="00000000", dic="00000000" diff --git a/20 Ověření proti Medicus/10 Ověření proti medicus.py b/20 Ověření proti Medicus/10 Ověření proti medicus.py index 4f2a04c..2e44ee6 100644 --- a/20 Ověření proti Medicus/10 Ověření proti medicus.py +++ b/20 Ověření proti Medicus/10 Ověření proti medicus.py @@ -1,5 +1,10 @@ import pymysql from knihovny.medicus_db import MedicusDB +from jinja2 import Environment, FileSystemLoader +from weasyprint import HTML +from pathlib import Path +from datetime import datetime +import os # ========================================== # CONFIGURATION @@ -17,6 +22,20 @@ MYSQL_CONFIG = { "autocommit": True } +# ========================================== +# PATHS +# ========================================== +script_location = Path(__file__).resolve().parent +project_root = script_location.parent +template_dir = project_root / "Templates" +output_dir = script_location / "Output" +output_dir.mkdir(exist_ok=True) + +# Font paths +font_regular = (template_dir / "fonts" / "DejaVuSans.ttf").as_uri() +font_bold = (template_dir / "fonts" / "DejaVuSans-Bold.ttf").as_uri() +font_italic = (template_dir / "fonts" / "DejaVuSans-Oblique.ttf").as_uri() + # ========================================== # INIT CONNECTIONS # ========================================== @@ -30,38 +49,27 @@ mysql = pymysql.connect( ) # ========================================== -# FETCH REGISTERED PATIENTS (MEDICUS) +# FETCH REGISTERED PATIENTS # ========================================== print("Fetching registered patients from Medicus...") patients = medicus.get_active_registered_patients(as_dict=True) -patients_by_rc = { - p["rodcis"]: p - for p in patients -} - +patients_by_rc = {p["rodcis"]: p for p in patients} print(f"Loaded {len(patients_by_rc)} registered patients") # ========================================== -# FETCH LAST INSURANCE STATES (MYSQL) +# FETCH LAST INSURANCE STATES # ========================================== print("Fetching last insurance states from MySQL...") sql_last_states = """ -SELECT - rc, - stav +SELECT rc, stav FROM ( - SELECT - rc, - stav, - ROW_NUMBER() OVER ( - PARTITION BY rc - ORDER BY k_datu DESC - ) AS rn + SELECT rc, stav, + ROW_NUMBER() OVER (PARTITION BY rc ORDER BY k_datu DESC) AS rn FROM vzp_stav_pojisteni ) t -WHERE t.rn = 1 +WHERE rn = 1 """ with mysql.cursor() as cur: @@ -71,7 +79,7 @@ with mysql.cursor() as cur: print(f"Loaded {len(last_states)} last insurance states") # ========================================== -# COMPARE & FIND NON-OK STATES +# COMPARE # ========================================== suspected = [] @@ -89,26 +97,42 @@ for row in last_states: "stav": stav }) -# ========================================== -# OUTPUT -# ========================================== -print("\n==========================================") -print("PACIENTI S NEOK STAVEM POJIŠTĚNÍ") -print("==========================================") - -if not suspected: - print("✔️ Všichni registrovaní pacienti mají stav 1") -else: - for s in suspected: - print( - f'{s["rc"]} | {s["prijmeni"]} {s["jmeno"]} ' - f'| pojišťovna={s["poj"]} | stav={s["stav"]}' - ) - -print("\nCelkem nalezeno:", len(suspected)) +print(f"Nalezeno {len(suspected)} problémových záznamů") # ========================================== -# CLEANUP +# CLEANUP DB # ========================================== medicus.close() mysql.close() + +# ========================================== +# PDF GENERATION (WEASYPRINT) +# ========================================== +env = Environment( + loader=FileSystemLoader(str(template_dir)), + autoescape=True +) + +template = env.get_template("vzp_console_report.html") + +html_content = template.render( + patients=suspected, + generated_at=datetime.now().strftime("%d. %m. %Y %H:%M"), + font_regular=font_regular, + font_bold=font_bold, + font_italic=font_italic +) + +timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") +pdf_file = output_dir / f"kontrola_pojisteni_{timestamp}.pdf" + +print("Generuji PDF přes WeasyPrint...") +HTML(string=html_content, base_url=str(template_dir)).write_pdf(pdf_file) + +print("\n✅ PDF REPORT VYTVOŘEN:") +print(pdf_file.resolve()) + +try: + os.startfile(pdf_file) +except Exception: + pass diff --git a/Templates/fonts/DejaVuSans-Bold.ttf b/Templates/fonts/DejaVuSans-Bold.ttf new file mode 100644 index 0000000..6d65fa7 Binary files /dev/null and b/Templates/fonts/DejaVuSans-Bold.ttf differ diff --git a/Templates/fonts/DejaVuSans-Oblique.ttf b/Templates/fonts/DejaVuSans-Oblique.ttf new file mode 100644 index 0000000..999bac7 Binary files /dev/null and b/Templates/fonts/DejaVuSans-Oblique.ttf differ diff --git a/Templates/fonts/DejaVuSans.ttf b/Templates/fonts/DejaVuSans.ttf new file mode 100644 index 0000000..e5f7eec Binary files /dev/null and b/Templates/fonts/DejaVuSans.ttf differ diff --git a/Templates/vzp_console_report.html b/Templates/vzp_console_report.html new file mode 100644 index 0000000..0311fda --- /dev/null +++ b/Templates/vzp_console_report.html @@ -0,0 +1,122 @@ + + +
+ +| Rodné číslo | +Příjmení a jméno | +Pojišťovna | +Stav | +
|---|---|---|---|
| {{ p.rc }} | +{{ p.prijmeni }} {{ p.jmeno }} | +{{ p.poj }} | +{{ p.stav }} | +
+✔ Vše v pořádku – žádné neshody nenalezeny. +
+{% endif %} + + + +