89 lines
2.6 KiB
Python
89 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import sys
|
|
try:
|
|
sys.stdout.reconfigure(encoding="utf-8")
|
|
sys.stderr.reconfigure(encoding="utf-8")
|
|
except AttributeError:
|
|
import io
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
|
|
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8")
|
|
|
|
sys.path.insert(0, 'U:/OrdinaceProjekt')
|
|
|
|
import pymysql
|
|
from Knihovny.medicus_db import get_medicus_db
|
|
|
|
DB_CONFIG = {
|
|
"host": "192.168.1.76",
|
|
"port": 3306,
|
|
"user": "root",
|
|
"password": "Vlado9674+",
|
|
"database": "medevio",
|
|
"charset": "utf8mb4",
|
|
"cursorclass": pymysql.cursors.DictCursor,
|
|
}
|
|
|
|
# Načti registrované v Medicusu
|
|
db = get_medicus_db()
|
|
rows = db.get_active_registered_patients()
|
|
medicus_rc = {r[0].strip() for r in rows if r[0]}
|
|
db.close()
|
|
print(f"Registrovaní v Medicusu: {len(medicus_rc)}\n")
|
|
|
|
# Načti všechny pacienty z MySQL
|
|
conn = pymysql.connect(**DB_CONFIG)
|
|
with conn.cursor() as cur:
|
|
cur.execute("SELECT status, user_id, identification_number FROM medevio_pacient ORDER BY status, user_id")
|
|
all_rows = cur.fetchall()
|
|
conn.close()
|
|
|
|
# Analýza
|
|
stats = {}
|
|
for r in all_rows:
|
|
status = r['status']
|
|
has_user_id = "S user_id" if r['user_id'] else "BEZ user_id"
|
|
|
|
key = f"{status} — {has_user_id}"
|
|
if key not in stats:
|
|
stats[key] = {"total": 0, "in_medicus": 0, "out_medicus": 0}
|
|
|
|
stats[key]["total"] += 1
|
|
|
|
if r['identification_number']:
|
|
if r['identification_number'] in medicus_rc:
|
|
stats[key]["in_medicus"] += 1
|
|
else:
|
|
stats[key]["out_medicus"] += 1
|
|
|
|
print("=" * 90)
|
|
print("STATISTIKA user_id v Medeviu")
|
|
print("=" * 90)
|
|
|
|
for key in sorted(stats.keys()):
|
|
s = stats[key]
|
|
print(f"\n{key:40s}")
|
|
print(f" Celkem: {s['total']:5d}")
|
|
print(f" V Medicusu: {s['in_medicus']:5d}")
|
|
print(f" MIMO Medicus: {s['out_medicus']:5d}")
|
|
|
|
print("\n" + "=" * 90)
|
|
print("SHRNUTÍ:")
|
|
print("=" * 90)
|
|
|
|
with_user = sum(s['total'] for k, s in stats.items() if "S user_id" in k)
|
|
without_user = sum(s['total'] for k, s in stats.items() if "BEZ user_id" in k)
|
|
|
|
print(f"\nCelkem S user_id: {with_user}")
|
|
print(f"Celkem BEZ user_id: {without_user}")
|
|
print(f"CELKEM: {with_user + without_user}")
|
|
|
|
# Vztah k Medicusu
|
|
active_with_user_out = sum(s['out_medicus'] for k, s in stats.items() if "ACTIVE" in k and "S user_id" in k)
|
|
active_without_user_out = sum(s['out_medicus'] for k, s in stats.items() if "ACTIVE" in k and "BEZ user_id" in k)
|
|
|
|
print(f"\nACTIVE S user_id mimo Medicus: {active_with_user_out}")
|
|
print(f"ACTIVE BEZ user_id mimo Medicus: {active_without_user_out}")
|
|
print("=" * 90)
|