lenovo
This commit is contained in:
@@ -73,6 +73,8 @@ class StazeniRadek:
|
|||||||
pacient: str
|
pacient: str
|
||||||
stav: str # "OK" | "CHYBA" | "PRESKOCENO"
|
stav: str # "OK" | "CHYBA" | "PRESKOCENO"
|
||||||
detail: str = "" # stav receptu nebo chybová zpráva
|
detail: str = "" # stav receptu nebo chybová zpráva
|
||||||
|
datum_vystaveni: str = ""
|
||||||
|
platnost_do: str = ""
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -164,6 +166,32 @@ def volej_nacist_predpis(sess, erp_kod):
|
|||||||
return resp.status_code, resp.text
|
return resp.status_code, resp.text
|
||||||
|
|
||||||
|
|
||||||
|
_STAV_POPIS = {
|
||||||
|
"PREDEPSANY": "nevyzvednutý",
|
||||||
|
"CASTECNE_VYDANY": "částečně vydaný",
|
||||||
|
"PLNE_VYDANY": "plně vydaný",
|
||||||
|
"ZRUSENY": "zrušený",
|
||||||
|
"PRIPRAVOVANY": "připravovaný",
|
||||||
|
}
|
||||||
|
|
||||||
|
def _stav_z_xml(xml_text):
|
||||||
|
"""Vytáhne stav receptu — funguje i s namespace prefixem (<ns:Stav>)."""
|
||||||
|
for kod in _STAV_POPIS:
|
||||||
|
if f">{kod}<" in xml_text:
|
||||||
|
return _STAV_POPIS[kod]
|
||||||
|
return "?"
|
||||||
|
|
||||||
|
|
||||||
|
def _datum_z_xml(xml_text, tag):
|
||||||
|
"""Vytáhne datum z XML tagu (prvý výskyt), vrátí jen YYYY-MM-DD nebo ''."""
|
||||||
|
try:
|
||||||
|
start = xml_text.index(f"{tag}>") + len(tag) + 1
|
||||||
|
end = xml_text.index("<", start)
|
||||||
|
return xml_text[start:end].strip()[:10]
|
||||||
|
except ValueError:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def faze_stazeni(datum_od, limit, out_dir, souhrn: Souhrn):
|
def faze_stazeni(datum_od, limit, out_dir, souhrn: Souhrn):
|
||||||
print("Připojuji MySQL...")
|
print("Připojuji MySQL...")
|
||||||
mysql = connect_mysql(database="medicus", cursorclass=pymysql.cursors.DictCursor)
|
mysql = connect_mysql(database="medicus", cursorclass=pymysql.cursors.DictCursor)
|
||||||
@@ -208,8 +236,15 @@ def faze_stazeni(datum_od, limit, out_dir, souhrn: Souhrn):
|
|||||||
xml_file = out_dir / f"{erp_kod}.xml"
|
xml_file = out_dir / f"{erp_kod}.xml"
|
||||||
xml_file.write_text(text, encoding="utf-8")
|
xml_file.write_text(text, encoding="utf-8")
|
||||||
kb = len(text.encode()) / 1024
|
kb = len(text.encode()) / 1024
|
||||||
print(f"OK {kb:5.1f} KB {lek_str[:40]}")
|
stav_receptu = _stav_z_xml(text)
|
||||||
souhrn.stazeni.append(StazeniRadek(erp_kod=erp_kod, pacient=label, stav="OK", detail=lek_str[:60]))
|
datum_vystaveni = _datum_z_xml(text, "DatumVystaveni")
|
||||||
|
platnost_do = _datum_z_xml(text, "PlatnostDo")
|
||||||
|
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,
|
||||||
|
))
|
||||||
else:
|
else:
|
||||||
chyba_short = text[:120].replace("\n", " ")
|
chyba_short = text[:120].replace("\n", " ")
|
||||||
print(f"CHYBA HTTP {status} {chyba_short}")
|
print(f"CHYBA HTTP {status} {chyba_short}")
|
||||||
@@ -438,14 +473,18 @@ def sestav_email(souhrn: Souhrn) -> tuple[str, str]:
|
|||||||
if not radky:
|
if not radky:
|
||||||
return ""
|
return ""
|
||||||
rows = "".join(
|
rows = "".join(
|
||||||
f"<tr><td style='{td}'>{r.erp_kod}</td><td style='{td}'>{r.pacient}</td>"
|
f"<tr><td style='{td}'>{r.erp_kod}</td>"
|
||||||
|
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><td style='{td}'>{r.detail}</td></tr>"
|
||||||
for r in radky
|
for r in radky
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
f"<h2 style='{h2}'>{nadpis}</h2>"
|
f"<h2 style='{h2}'>{nadpis}</h2>"
|
||||||
f"<table style='border-collapse:collapse;width:100%'>"
|
f"<table style='border-collapse:collapse;width:100%'>"
|
||||||
f"<tr><th style='{th}'>ERP kód</th><th style='{th}'>Pacient</th>"
|
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></tr>"
|
||||||
f"{rows}</table>"
|
f"{rows}</table>"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user