lenovo
This commit is contained in:
@@ -75,6 +75,7 @@ class StazeniRadek:
|
||||
detail: str = "" # stav receptu nebo chybová zpráva
|
||||
datum_vystaveni: str = ""
|
||||
platnost_do: str = ""
|
||||
zbyva_vydat: str = ""
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -192,6 +193,61 @@ def _datum_z_xml(xml_text, tag):
|
||||
return ""
|
||||
|
||||
|
||||
def _zbyva_vydat_z_xml(xml_text):
|
||||
"""Vrátí 'Nx NAZEV SILA; ...' pro léky, u nichž zbývá vydat (předepsáno − vydáno > 0)."""
|
||||
try:
|
||||
ns = f"{{{NAMESPACE}}}"
|
||||
root = ET.fromstring(xml_text)
|
||||
doklad = root.find(f".//{ns}Doklad")
|
||||
if doklad is None:
|
||||
return ""
|
||||
|
||||
predepsano = {} # id_lp -> {"mnozstvi": int, "nazev": str}
|
||||
for plp in doklad.findall(f"{ns}PLP"):
|
||||
id_lp_el = plp.find(f"{ns}ID_LP")
|
||||
mn_el = plp.find(f"{ns}Mnozstvi")
|
||||
if id_lp_el is None or mn_el is None:
|
||||
continue
|
||||
id_lp = (id_lp_el.text or "").strip()
|
||||
try:
|
||||
mnozstvi = int(mn_el.text)
|
||||
except (ValueError, TypeError):
|
||||
continue
|
||||
hvlp = plp.find(f"{ns}HVLPReg")
|
||||
nazev = ""
|
||||
if hvlp is not None:
|
||||
n_el = hvlp.find(f"{ns}Nazev")
|
||||
s_el = hvlp.find(f"{ns}Sila")
|
||||
nazev_base = (n_el.text or "").strip() if n_el is not None else ""
|
||||
sila = (s_el.text or "").strip() if s_el is not None else ""
|
||||
nazev = f"{nazev_base} {sila}".strip()
|
||||
predepsano[id_lp] = {"mnozstvi": mnozstvi, "nazev": nazev}
|
||||
|
||||
vydano = {} # id_lp -> int (součet přes všechny Vydej)
|
||||
for vydej in doklad.findall(f"{ns}Vydej"):
|
||||
for vlp in vydej.findall(f"{ns}VLP"):
|
||||
id_el = vlp.find(f"{ns}IdLpErp")
|
||||
mn_el = vlp.find(f"{ns}Mnozstvi")
|
||||
if id_el is None or mn_el is None:
|
||||
continue
|
||||
id_lp = (id_el.text or "").strip()
|
||||
try:
|
||||
mn = int(mn_el.text)
|
||||
except (ValueError, TypeError):
|
||||
continue
|
||||
vydano[id_lp] = vydano.get(id_lp, 0) + mn
|
||||
|
||||
zbytky = []
|
||||
for id_lp, info in predepsano.items():
|
||||
zbyva = info["mnozstvi"] - vydano.get(id_lp, 0)
|
||||
if zbyva > 0:
|
||||
zbytky.append(f"{zbyva}× {info['nazev']}")
|
||||
return "; ".join(zbytky)
|
||||
|
||||
except Exception:
|
||||
return ""
|
||||
|
||||
|
||||
def faze_stazeni(datum_od, limit, out_dir, souhrn: Souhrn):
|
||||
print("Připojuji MySQL...")
|
||||
mysql = connect_mysql(database="medicus", cursorclass=pymysql.cursors.DictCursor)
|
||||
@@ -239,11 +295,13 @@ def faze_stazeni(datum_od, limit, out_dir, souhrn: Souhrn):
|
||||
stav_receptu = _stav_z_xml(text)
|
||||
datum_vystaveni = _datum_z_xml(text, "DatumVystaveni")
|
||||
platnost_do = _datum_z_xml(text, "PlatnostDo")
|
||||
zbyva_vydat = _zbyva_vydat_z_xml(text)
|
||||
print(f"OK {kb:5.1f} KB {stav_receptu} {lek_str[:40]}")
|
||||
souhrn.stazeni.append(StazeniRadek(
|
||||
erp_kod=erp_kod, pacient=label, stav="OK",
|
||||
detail=f"{stav_receptu} | {lek_str[:50]}",
|
||||
datum_vystaveni=datum_vystaveni, platnost_do=platnost_do,
|
||||
zbyva_vydat=zbyva_vydat,
|
||||
))
|
||||
else:
|
||||
chyba_short = text[:120].replace("\n", " ")
|
||||
@@ -477,7 +535,9 @@ def sestav_email(souhrn: Souhrn) -> tuple[str, str]:
|
||||
f"<td style='{td}'>{r.datum_vystaveni}</td>"
|
||||
f"<td style='{td}'>{r.platnost_do}</td>"
|
||||
f"<td style='{td}'>{r.pacient}</td>"
|
||||
f"<td style='{td}'>{_badge(r.stav)}</td><td style='{td}'>{r.detail}</td></tr>"
|
||||
f"<td style='{td}'>{_badge(r.stav)}</td>"
|
||||
f"<td style='{td}'>{r.detail}</td>"
|
||||
f"<td style='{td}'>{r.zbyva_vydat}</td></tr>"
|
||||
for r in radky
|
||||
)
|
||||
return (
|
||||
@@ -485,7 +545,8 @@ def sestav_email(souhrn: Souhrn) -> tuple[str, str]:
|
||||
f"<table style='border-collapse:collapse;width:100%'>"
|
||||
f"<tr><th style='{th}'>ERP kód</th><th style='{th}'>Vystaveno</th>"
|
||||
f"<th style='{th}'>Platnost do</th><th style='{th}'>Pacient</th>"
|
||||
f"<th style='{th}'>Stav</th><th style='{th}'>Detail</th></tr>"
|
||||
f"<th style='{th}'>Stav</th><th style='{th}'>Detail</th>"
|
||||
f"<th style='{th}'>Zbývá vydat</th></tr>"
|
||||
f"{rows}</table>"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user