WilsonPharma/Practitioners-Workload-DB
1
1import sqlite32 3DB = r"w:\01-03-2026\Dr. Heba\Practitioners Workload DB\PractitionersWorkloadDB.db"4conn = sqlite3.connect(DB)5cur = conn.cursor()6 7cur.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name")8print("Tables:", [r[0] for r in cur.fetchall()])9 10cur.execute("SELECT COUNT(*) FROM practitioner_records")11print("Total rows in practitioner_records:", cur.fetchone()[0])12 13cur.execute("SELECT source_file_id, COUNT(*) FROM practitioner_records GROUP BY source_file_id ORDER BY source_file_id")14print("Rows per source_file_id:")15for r in cur.fetchall():16 print(f" file_id={r[0]}: {r[1]:,}")17 18cur.execute("SELECT id, filename, import_status, row_count FROM imported_files ORDER BY id")19print("Imported files:")20for r in cur.fetchall():21 print(f" id={r[0]}, file={r[1]}, status={r[2]}, rows={r[3]}")22 23# The CORRECT data should be file_id=2, and the row_count=338454 matches Power BI24# So 1,353,816 rows were inserted but only 338,454 are correct25# 1,353,816 / 338,454 = 4 -> the CSV was imported 4 times in one batch26print()27print("file_id=2 totals (all rows):")28cur.execute("SELECT SUM(emergency), SUM(inpatient), SUM(outpatient), COUNT(*), COUNT(DISTINCT practitioner_id) FROM practitioner_records WHERE source_file_id=2")29r = cur.fetchone()30print(f" Emergency={r[0]:,} Inpatient={r[1]:,} Outpatient={r[2]:,} Rows={r[3]:,} UniqueID={r[4]:,}")31 32print()33print("Power BI correct values: Emergency=1,355,830 Inpatient=366 Outpatient=6,553,435 Cases=7,909,631")34print(f"Ratio (rows/correct): {1353816/338454:.2f}x")35 36conn.close()37 