This commit is contained in:
2025-11-05 06:32:22 +01:00
parent ab0e5eee29
commit 87f4df4f59
5 changed files with 152 additions and 4 deletions

98
100 Novi pacienti.py Normal file
View File

@@ -0,0 +1,98 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Report: DXA requisitions (Medicus → Dropbox)
--------------------------------------------
- Selects all histdoc records for year 2025 containing "DXA"
- Finds matching PDF files in Dropbox (by rod_cis + "dxa" in name)
- Outputs Excel report: datum, idpaci, rod_cis, prijmeni, jmeno, file
"""
import os
import firebirdsql as fb
import pandas as pd
from pathlib import Path
from datetime import datetime
from Functions import get_dropbox_path
from Functions import get_medicus_connection
# ================== CONFIGURATION ==================
EXPORT_DIR = Path(get_dropbox_path("reporty"))
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
xlsx_path = EXPORT_DIR / f"{timestamp}_Nové_registrace.xlsx"
# ================== DATABASE QUERY ==================
conn = get_medicus_connection()
sql = """
select rodcis,
prijmeni,
jmeno,
datum_registrace,
registr.idpac,
poj
from registr
join kar on registr.idpac=kar.idpac
where kar.vyrazen!='A' and kar.rodcis is not null and idicp!=0 and datum_zruseni is null
"""
df = pd.read_sql(sql, conn)
conn.close()
# ================== CLEAN OLD REPORTS ==================
for f in EXPORT_DIR.glob("*_Nové_registrace.xlsx"):
try:
f.unlink()
print(f"🗑️ Deleted old report: {f.name}")
except Exception as e:
print(f"⚠️ Could not delete {f.name}: {e}")
# ================== EXPORT TO EXCEL ==================
with pd.ExcelWriter(xlsx_path, engine="openpyxl") as writer:
df.to_excel(writer, index=False, sheet_name="Registrace 2025")
ws = writer.sheets["Registrace 2025"]
# Format header
from openpyxl.styles import Font, Alignment, PatternFill, Border, Side
header_fill = PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid")
for cell in ws[1]:
cell.font = Font(bold=True, color="000000")
cell.alignment = Alignment(horizontal="center", vertical="center")
cell.fill = header_fill
# Auto column width, but hardcode FILE column to 120
from openpyxl.utils import get_column_letter
for col in ws.columns:
col_letter = get_column_letter(col[0].column)
header = ws.cell(row=1, column=col[0].column).value
if header == "FILE":
ws.column_dimensions[col_letter].width = 120
else:
max_len = max(len(str(cell.value)) if cell.value else 0 for cell in col)
ws.column_dimensions[col_letter].width = min(max_len + 2, 80)
# Borders
thin = Side(border_style="thin", color="000000")
border = Border(top=thin, left=thin, right=thin, bottom=thin)
for row in ws.iter_rows(min_row=1, max_row=ws.max_row,
min_col=1, max_col=ws.max_column):
for cell in row:
cell.border = border
print(f"✅ Report created: {xlsx_path}")
print(f"🩻 {df['FILE'].astype(bool).sum()} matching DXA PDFs found")

1
101 test Normal file
View File

@@ -0,0 +1 @@
from Functions import get

3
101 test.py Normal file
View File

@@ -0,0 +1,3 @@
from Functions import get_dropbox_path
print(get_dropbox_path("reporty"))

View File

@@ -33,7 +33,7 @@ SHEETS = {
"Chřipka": ["vaxigrip", "influvac", "fluarix", "afluria"], "Chřipka": ["vaxigrip", "influvac", "fluarix", "afluria"],
"Klíšťová encefalitida": ["fsme", "encepur"], "Klíšťová encefalitida": ["fsme", "encepur"],
"Tetanus": ["tetavax", "boostrix", "adacel"], "Tetanus": ["tetavax", "boostrix", "adacel"],
"HepA": ["avaxim", "havrix"], "HepA": ["avaxim", "havrix","vaqta"],
"HepB": ["engerix"], "HepB": ["engerix"],
"HepA+B": ["twinrix"], "HepA+B": ["twinrix"],
} }

View File

@@ -5,6 +5,46 @@ import pymysql
from pymysql.cursors import DictCursor from pymysql.cursors import DictCursor
import socket import socket
import socket
import unicodedata
def get_reports_folder():
hostname = socket.gethostname().strip().upper()
if hostname in ("NTBVBHP470G10", "Z230"):
return r"u:\Dropbox\!!!Days\Downloads Z230"
elif hostname in ["SESTRA","POHODA","LEKAR"]:
return r"z:\Dropbox\Ordinace\Reporty"
else:
print(f"Unknown host: {hostname}")
return None
def get_dropbox_path(cesta):
hostname = socket.gethostname().strip().upper()
if hostname not in ("SESTRA", "LEKAR", "POHODA", "NTBVBHP470G10", "Z230"):
print(f"Unknown host: {hostname}")
return None
# Choose root path based on hostname
if hostname in ("NTBVBHP470G10", "Z230"):
zacatek = r"U:\Dropbox"
else:
zacatek = r"Z:\Dropbox"
# Normalize text (optional, safer for diacritics)
cesta_norm = unicodedata.normalize("NFC", cesta).upper().strip()
if cesta_norm == "PŘIJATÁ":
return rf"{zacatek}\ordinace\Dokumentace_přijatá"
elif cesta_norm == "ZPRACOVANÁ":
return rf"{zacatek}\ordinace\Dokumentace_zpracovaná"
elif cesta_norm == "REPORTY":
return rf"{zacatek}\ordinace\reporty"
else:
print(f"Unknown cesta: {cesta}")
return None
def get_path_ciselniky(): def get_path_ciselniky():
hostname = socket.gethostname().strip() hostname = socket.gethostname().strip()
if hostname in ("NTBVBHP470G10", "Z230"): if hostname in ("NTBVBHP470G10", "Z230"):
@@ -73,14 +113,20 @@ def get_medicus_connection():
password="masterkey", password="masterkey",
charset="win1250", charset="win1250",
) )
elif socket.gethostname().strip()=="SESTRA": elif socket.gethostname().strip() in ("SESTRA","POHODA"):
MEDICUS_CFG = dict( MEDICUS_CFG = dict(
dsn=r"192.168.1.10:m:\medicus\data\medicus.fdb", dsn=r"192.168.1.10:m:\medicus\data\medicus.fdb",
user="SYSDBA", user="SYSDBA",
password="masterkey", password="masterkey",
charset="win1250", charset="win1250",
) )
elif socket.gethostname().strip()=="LEKAR":
MEDICUS_CFG = dict(
dsn=r"localhost:m:\medicus\data\medicus.fdb",
user="SYSDBA",
password="masterkey",
charset="win1250",
)
try: try:
return fdb.connect(**MEDICUS_CFG) return fdb.connect(**MEDICUS_CFG)
except fdb.fbcore.DatabaseError as e: except fdb.fbcore.DatabaseError as e: