notebookVB
This commit is contained in:
@@ -8,7 +8,7 @@ from vzpb2b_client import VZPB2BClient
|
|||||||
|
|
||||||
client = VZPB2BClient(
|
client = VZPB2BClient(
|
||||||
env="production",
|
env="production",
|
||||||
pfx_path="mbcert.pfx",
|
pfx_path="../10 Tests/MBcert.pfx",
|
||||||
pfx_password="Vlado7309208104++",
|
pfx_password="Vlado7309208104++",
|
||||||
icz="00000000",
|
icz="00000000",
|
||||||
dic="00000000"
|
dic="00000000"
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
import pymysql
|
import pymysql
|
||||||
from knihovny.medicus_db import MedicusDB
|
from knihovny.medicus_db import MedicusDB
|
||||||
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
from weasyprint import HTML
|
||||||
|
from pathlib import Path
|
||||||
|
from datetime import datetime
|
||||||
|
import os
|
||||||
|
|
||||||
# ==========================================
|
# ==========================================
|
||||||
# CONFIGURATION
|
# CONFIGURATION
|
||||||
@@ -17,6 +22,20 @@ MYSQL_CONFIG = {
|
|||||||
"autocommit": True
|
"autocommit": True
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ==========================================
|
||||||
|
# PATHS
|
||||||
|
# ==========================================
|
||||||
|
script_location = Path(__file__).resolve().parent
|
||||||
|
project_root = script_location.parent
|
||||||
|
template_dir = project_root / "Templates"
|
||||||
|
output_dir = script_location / "Output"
|
||||||
|
output_dir.mkdir(exist_ok=True)
|
||||||
|
|
||||||
|
# Font paths
|
||||||
|
font_regular = (template_dir / "fonts" / "DejaVuSans.ttf").as_uri()
|
||||||
|
font_bold = (template_dir / "fonts" / "DejaVuSans-Bold.ttf").as_uri()
|
||||||
|
font_italic = (template_dir / "fonts" / "DejaVuSans-Oblique.ttf").as_uri()
|
||||||
|
|
||||||
# ==========================================
|
# ==========================================
|
||||||
# INIT CONNECTIONS
|
# INIT CONNECTIONS
|
||||||
# ==========================================
|
# ==========================================
|
||||||
@@ -30,38 +49,27 @@ mysql = pymysql.connect(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# ==========================================
|
# ==========================================
|
||||||
# FETCH REGISTERED PATIENTS (MEDICUS)
|
# FETCH REGISTERED PATIENTS
|
||||||
# ==========================================
|
# ==========================================
|
||||||
print("Fetching registered patients from Medicus...")
|
print("Fetching registered patients from Medicus...")
|
||||||
patients = medicus.get_active_registered_patients(as_dict=True)
|
patients = medicus.get_active_registered_patients(as_dict=True)
|
||||||
|
|
||||||
patients_by_rc = {
|
patients_by_rc = {p["rodcis"]: p for p in patients}
|
||||||
p["rodcis"]: p
|
|
||||||
for p in patients
|
|
||||||
}
|
|
||||||
|
|
||||||
print(f"Loaded {len(patients_by_rc)} registered patients")
|
print(f"Loaded {len(patients_by_rc)} registered patients")
|
||||||
|
|
||||||
# ==========================================
|
# ==========================================
|
||||||
# FETCH LAST INSURANCE STATES (MYSQL)
|
# FETCH LAST INSURANCE STATES
|
||||||
# ==========================================
|
# ==========================================
|
||||||
print("Fetching last insurance states from MySQL...")
|
print("Fetching last insurance states from MySQL...")
|
||||||
|
|
||||||
sql_last_states = """
|
sql_last_states = """
|
||||||
SELECT
|
SELECT rc, stav
|
||||||
rc,
|
|
||||||
stav
|
|
||||||
FROM (
|
FROM (
|
||||||
SELECT
|
SELECT rc, stav,
|
||||||
rc,
|
ROW_NUMBER() OVER (PARTITION BY rc ORDER BY k_datu DESC) AS rn
|
||||||
stav,
|
|
||||||
ROW_NUMBER() OVER (
|
|
||||||
PARTITION BY rc
|
|
||||||
ORDER BY k_datu DESC
|
|
||||||
) AS rn
|
|
||||||
FROM vzp_stav_pojisteni
|
FROM vzp_stav_pojisteni
|
||||||
) t
|
) t
|
||||||
WHERE t.rn = 1
|
WHERE rn = 1
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with mysql.cursor() as cur:
|
with mysql.cursor() as cur:
|
||||||
@@ -71,7 +79,7 @@ with mysql.cursor() as cur:
|
|||||||
print(f"Loaded {len(last_states)} last insurance states")
|
print(f"Loaded {len(last_states)} last insurance states")
|
||||||
|
|
||||||
# ==========================================
|
# ==========================================
|
||||||
# COMPARE & FIND NON-OK STATES
|
# COMPARE
|
||||||
# ==========================================
|
# ==========================================
|
||||||
suspected = []
|
suspected = []
|
||||||
|
|
||||||
@@ -89,26 +97,42 @@ for row in last_states:
|
|||||||
"stav": stav
|
"stav": stav
|
||||||
})
|
})
|
||||||
|
|
||||||
# ==========================================
|
print(f"Nalezeno {len(suspected)} problémových záznamů")
|
||||||
# OUTPUT
|
|
||||||
# ==========================================
|
|
||||||
print("\n==========================================")
|
|
||||||
print("PACIENTI S NEOK STAVEM POJIŠTĚNÍ")
|
|
||||||
print("==========================================")
|
|
||||||
|
|
||||||
if not suspected:
|
|
||||||
print("✔️ Všichni registrovaní pacienti mají stav 1")
|
|
||||||
else:
|
|
||||||
for s in suspected:
|
|
||||||
print(
|
|
||||||
f'{s["rc"]} | {s["prijmeni"]} {s["jmeno"]} '
|
|
||||||
f'| pojišťovna={s["poj"]} | stav={s["stav"]}'
|
|
||||||
)
|
|
||||||
|
|
||||||
print("\nCelkem nalezeno:", len(suspected))
|
|
||||||
|
|
||||||
# ==========================================
|
# ==========================================
|
||||||
# CLEANUP
|
# CLEANUP DB
|
||||||
# ==========================================
|
# ==========================================
|
||||||
medicus.close()
|
medicus.close()
|
||||||
mysql.close()
|
mysql.close()
|
||||||
|
|
||||||
|
# ==========================================
|
||||||
|
# PDF GENERATION (WEASYPRINT)
|
||||||
|
# ==========================================
|
||||||
|
env = Environment(
|
||||||
|
loader=FileSystemLoader(str(template_dir)),
|
||||||
|
autoescape=True
|
||||||
|
)
|
||||||
|
|
||||||
|
template = env.get_template("vzp_console_report.html")
|
||||||
|
|
||||||
|
html_content = template.render(
|
||||||
|
patients=suspected,
|
||||||
|
generated_at=datetime.now().strftime("%d. %m. %Y %H:%M"),
|
||||||
|
font_regular=font_regular,
|
||||||
|
font_bold=font_bold,
|
||||||
|
font_italic=font_italic
|
||||||
|
)
|
||||||
|
|
||||||
|
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
||||||
|
pdf_file = output_dir / f"kontrola_pojisteni_{timestamp}.pdf"
|
||||||
|
|
||||||
|
print("Generuji PDF přes WeasyPrint...")
|
||||||
|
HTML(string=html_content, base_url=str(template_dir)).write_pdf(pdf_file)
|
||||||
|
|
||||||
|
print("\n✅ PDF REPORT VYTVOŘEN:")
|
||||||
|
print(pdf_file.resolve())
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.startfile(pdf_file)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|||||||
BIN
Templates/fonts/DejaVuSans-Bold.ttf
Normal file
BIN
Templates/fonts/DejaVuSans-Bold.ttf
Normal file
Binary file not shown.
BIN
Templates/fonts/DejaVuSans-Oblique.ttf
Normal file
BIN
Templates/fonts/DejaVuSans-Oblique.ttf
Normal file
Binary file not shown.
BIN
Templates/fonts/DejaVuSans.ttf
Normal file
BIN
Templates/fonts/DejaVuSans.ttf
Normal file
Binary file not shown.
122
Templates/vzp_console_report.html
Normal file
122
Templates/vzp_console_report.html
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="cs">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Kontrola stavu pojištění</title>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
@font-face {
|
||||||
|
font-family: 'DejaVu';
|
||||||
|
src: url('{{ font_regular }}');
|
||||||
|
font-weight: normal;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: 'DejaVu';
|
||||||
|
src: url('{{ font_bold }}');
|
||||||
|
font-weight: bold;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: 'DejaVu';
|
||||||
|
src: url('{{ font_italic }}');
|
||||||
|
font-weight: normal;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
@page {
|
||||||
|
size: A4;
|
||||||
|
margin: 1.5cm;
|
||||||
|
@bottom-right {
|
||||||
|
content: "Strana " counter(page) " z " counter(pages);
|
||||||
|
font-size: 9pt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: 'DejaVu', sans-serif;
|
||||||
|
font-size: 10pt;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 16pt;
|
||||||
|
border-bottom: 2px solid #2c3e50;
|
||||||
|
padding-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta {
|
||||||
|
font-size: 9pt;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
|
||||||
|
th, td {
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
padding: 6px 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
background-color: #f2f2f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr {
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:nth-child(even) {
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-bad {
|
||||||
|
color: #d9534f;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>Kontrola stavu pojištění (VZP)</h1>
|
||||||
|
|
||||||
|
<div class="meta">
|
||||||
|
Vygenerováno: {{ generated_at }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% if patients %}
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Rodné číslo</th>
|
||||||
|
<th>Příjmení a jméno</th>
|
||||||
|
<th>Pojišťovna</th>
|
||||||
|
<th>Stav</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for p in patients %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ p.rc }}</td>
|
||||||
|
<td><strong>{{ p.prijmeni }}</strong> {{ p.jmeno }}</td>
|
||||||
|
<td>{{ p.poj }}</td>
|
||||||
|
<td class="status-bad">{{ p.stav }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% else %}
|
||||||
|
<p style="color: green; font-weight: bold;">
|
||||||
|
✔ Vše v pořádku – žádné neshody nenalezeny.
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
Reference in New Issue
Block a user