#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Pro každého z 66 pacientů mimo Medicus: - Zavolá VZP API na registrující lékaře v odbornosti 001 - Vypíše, kdo je jejich lékař (nebo že ho nemají) """ import sys try: sys.stdout.reconfigure(encoding="utf-8") sys.stderr.reconfigure(encoding="utf-8") except AttributeError: import io sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8") sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8") sys.path.insert(0, 'U:/OrdinaceProjekt') import pymysql from Knihovny.medicus_db import get_medicus_db from Knihovny.vzpb2b_client import VZPB2BClient from pathlib import Path import time DB_CONFIG = { "host": "192.168.1.76", "port": 3306, "user": "root", "password": "Vlado9674+", "database": "medevio", "charset": "utf8mb4", "cursorclass": pymysql.cursors.DictCursor, } # Certifikát CERT_PATH = Path("U:/OrdinaceProjekt/Insurance/Certificates/picka.pfx") CERT_PASSWORD = "Vlado7309208104+" ICZ = "09305000" # ==================== MAIN ==================== def main(): # Načti registrované v Medicusu db = get_medicus_db() rows = db.get_active_registered_patients() medicus_rc = {r[0].strip() for r in rows if r[0]} db.close() # Najdi všechny ACTIVE s účtem mimo Medicus conn = pymysql.connect(**DB_CONFIG) with conn.cursor() as cur: cur.execute(""" SELECT name, surname, identification_number FROM medevio_pacient WHERE status = 'ACTIVE' AND user_id IS NOT NULL AND identification_number IS NOT NULL ORDER BY surname, name """) all_with_account = cur.fetchall() conn.close() # Filtruj ty mimo Medicus extras = [ r for r in all_with_account if r["identification_number"] not in medicus_rc ] print("=" * 100) print(f"DOTAZ VZP NA REGISTRUJÍCÍHO LÉKAŘE — {len(extras)} pacientů\n") print(f"{'#':3s} {'Jméno':30s} {'RC':13s} {'Lékař v 001':40s}") print("=" * 100) # Inicializuj VZP client try: client = VZPB2BClient("prod", str(CERT_PATH), CERT_PASSWORD, icz=ICZ) except Exception as e: print(f"CHYBA: Nelze se připojit k VZP API: {e}") return # Pro každého pacienta for i, r in enumerate(extras, 1): name = f"{r['surname']} {r['name']}" rc = r["identification_number"] try: # Zavolej VZP API xml_response = client.registrace_lekare(rc, odbornosti=["001"]) parsed = client.parse_registrace_lekare(xml_response) # Pokud má lékaře v 001 if parsed and parsed[0].get("ma_lekare"): p = parsed[0] lekar = f"{p.get('nazev_lekare', '?')} (ICP: {p.get('ICP', '?')})" else: lekar = "NEMÁ LÉKAŘE" print(f"{i:3d} {name:30s} {rc:13s} {lekar:40s}") except Exception as e: print(f"{i:3d} {name:30s} {rc:13s} CHYBA: {str(e)[:40]}") # Delay pro API time.sleep(0.5) print("=" * 100) if __name__ == "__main__": main()