notebookVB
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#this script can be run several times on the same day, in such case it works incrementaly
|
||||
# this script can be run several times on the same day, in such case it works incrementally
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# add project root (one level up) to PYTHONPATH
|
||||
# ==========================================
|
||||
# PROJECT ROOT (import fix)
|
||||
# ==========================================
|
||||
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(PROJECT_ROOT))
|
||||
|
||||
|
||||
import time
|
||||
import logging
|
||||
from knihovny.medicus_db import MedicusDB
|
||||
from vzpb2b_client import VZPB2BClient
|
||||
from knihovny.vzpb2b_client import VZPB2BClient
|
||||
import pymysql
|
||||
from datetime import date
|
||||
|
||||
@@ -57,43 +58,64 @@ mysql = pymysql.connect(
|
||||
# ==========================================
|
||||
# SAVE RESULT
|
||||
# ==========================================
|
||||
def save_insurance_status(mysql_conn, rc, k_datu, result, xml_text):
|
||||
def save_insurance_status(mysql_conn, rc, prijmeni, jmeno, k_datu, result, xml_text):
|
||||
"""
|
||||
Uloží čistou odpověď VZP + identifikační údaje pacienta.
|
||||
Pojišťovna je VÝHRADNĚ z odpovědi VZP.
|
||||
"""
|
||||
sql = """
|
||||
INSERT INTO vzp_stav_pojisteni
|
||||
(rc, k_datu, stav, kod_pojistovny, nazev_pojistovny,
|
||||
(rc, prijmeni, jmeno, k_datu,
|
||||
stav, kod_pojistovny, nazev_pojistovny,
|
||||
pojisteni_kod, stav_vyrizeni, response_xml)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
|
||||
VALUES (%s, %s, %s, %s,
|
||||
%s, %s, %s,
|
||||
%s, %s, %s)
|
||||
"""
|
||||
|
||||
with mysql_conn.cursor() as cur:
|
||||
cur.execute(sql, (
|
||||
rc,
|
||||
prijmeni,
|
||||
jmeno,
|
||||
k_datu,
|
||||
result["stav"],
|
||||
result["kodPojistovny"],
|
||||
result["nazevPojistovny"],
|
||||
result["pojisteniKod"],
|
||||
result["stavVyrizeni"],
|
||||
result["kodPojistovny"], # ← VZP
|
||||
result["nazevPojistovny"], # ← VZP
|
||||
result["pojisteniKod"], # ← VZP
|
||||
result["stavVyrizeni"], # ← VZP
|
||||
xml_text
|
||||
))
|
||||
|
||||
|
||||
# ==========================================
|
||||
# CONFIGURATION
|
||||
# ==========================================
|
||||
HOST = "192.168.1.4"
|
||||
DB_PATH = r"z:\Medicus 3\data\MEDICUS.FDB"
|
||||
|
||||
PFX_PATH = r"MBcert.pfx"
|
||||
PFX_PATH = PROJECT_ROOT / "certificates" / "MBcert.pfx"
|
||||
PFX_PASSWORD = "Vlado7309208104++"
|
||||
|
||||
ENV = "prod"
|
||||
ICZ = "00000000"
|
||||
DIC = "00000000"
|
||||
|
||||
# sanity check
|
||||
if not PFX_PATH.exists():
|
||||
raise FileNotFoundError(f"PFX certificate not found: {PFX_PATH}")
|
||||
|
||||
# ==========================================
|
||||
# INIT CONNECTIONS
|
||||
# ==========================================
|
||||
db = MedicusDB(HOST, DB_PATH)
|
||||
vzp = VZPB2BClient(ENV, PFX_PATH, PFX_PASSWORD, icz=ICZ, dic=DIC)
|
||||
vzp = VZPB2BClient(
|
||||
ENV,
|
||||
str(PFX_PATH), # <-- important: pass as string
|
||||
PFX_PASSWORD,
|
||||
icz=ICZ,
|
||||
dic=DIC
|
||||
)
|
||||
|
||||
# ==========================================
|
||||
# FETCH REGISTERED PATIENTS
|
||||
@@ -108,7 +130,7 @@ today = date.today()
|
||||
# ==========================================
|
||||
patients_to_check = []
|
||||
|
||||
with mysql.cursor() as cur:
|
||||
with mysql.cursor(pymysql.cursors.DictCursor) as cur:
|
||||
for rc, prijmeni, jmeno, poj in patients:
|
||||
cur.execute(
|
||||
"SELECT MAX(k_datu) AS last_check FROM vzp_stav_pojisteni WHERE rc = %s",
|
||||
@@ -151,7 +173,15 @@ for idx, (rodcis, prijmeni, jmeno) in enumerate(patients_to_check, 1):
|
||||
continue
|
||||
|
||||
try:
|
||||
save_insurance_status(mysql, rodcis, today, result, xml)
|
||||
save_insurance_status(
|
||||
mysql,
|
||||
rodcis,
|
||||
prijmeni,
|
||||
jmeno,
|
||||
today,
|
||||
result,
|
||||
xml
|
||||
)
|
||||
except Exception as e:
|
||||
log_error(f"❌ MYSQL INSERT ERROR for RC {rodcis}: {e}")
|
||||
time.sleep(2)
|
||||
|
||||
Reference in New Issue
Block a user