All materials
init_db.py
pyinit_db.py
import sqlite3
import random
import os
DATABASE = '/app/ehr.db'
HAITIAN_FIRST_NAMES = [
'Jean', 'Pierre', 'Marie', 'Rose', 'Joseph', 'Paul', 'Jacques', 'Francois',
'Claudette', 'Yolande', 'Frantz', 'Guerline', 'Dieulita', 'Mackenson', 'Wisline',
'Reginald', 'Esther', 'Bernadette', 'Emmanuel', 'Roseline', 'Jocelyn', 'Kettly',
'Duckinson', 'Mireille', 'Wilner', 'Fabienne', 'Dieudonn\u00e9', 'Natacha', 'Herv\u00e9',
'Carmelle', 'Ren\u00e9', 'Lourdes', 'Gervais', 'Nadine', 'Edouard', 'Margarette',
'Serge', 'Yanick', 'Phara', 'Mirlande', 'Raymond', 'Guerda', 'Wilfried',
'Beatrice', 'Evens', 'Martine', 'Johanne', 'Lesly', 'Daphn\u00e9', 'Widelson'
]
HAITIAN_LAST_NAMES = [
'Jean-Baptiste', 'Pierre-Louis', 'Saint-Fleur', 'Desrosiers', 'Celestin',
'Moreau', 'Toussaint', 'Estimé', 'Charles', 'Francois', 'Auguste',
'Belfort', 'Duval', 'Larose', 'Prophete', 'Guerrier', 'Beaubrun',
'Thermidor', 'Dorval', 'Petit-Frere', 'Alexis', 'Lucien', 'Noel',
'Dessalines', 'Louverture', 'Bazile', 'Germain', 'Hyppolite', 'Janvier',
'Lafontant'
]
CLINICS = [
'Clinique Cap-Haitien Centre',
'Clinique Milot',
'Clinique Limonade',
'Clinique Quartier Morin',
'Clinique Grande Riviere du Nord',
'Clinique Dondon'
]
DIAGNOSES = [
'Hypertension', 'Type 2 Diabetes', 'Tuberculosis', 'HIV/AIDS',
'Prenatal Care', 'Malaria', 'Typhoid Fever', 'Anemia',
'Acute Respiratory Infection', 'Gastroenteritis', 'Skin Infection',
'Urinary Tract Infection', 'Dental Abscess', 'Pneumonia',
'Chronic Kidney Disease'
]
def initialize():
random.seed(42)
os.makedirs(os.path.dirname(DATABASE), exist_ok=True)
conn = sqlite3.connect(DATABASE)
cursor = conn.cursor()
# Users table
cursor.execute('''
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
role TEXT NOT NULL
)
''')
users = [
('admin', 'admin', 'administrator'),
('frantz', 'clinique2024', 'it_admin'),
('dr.moreau', 'password123', 'physician'),
('nurse.celestin', 'rsn2024', 'nurse'),
]
for username, password, role in users:
cursor.execute(
'INSERT OR IGNORE INTO users (username, password, role) VALUES (?, ?, ?)',
(username, password, role)
)
# Patients table
cursor.execute('''
CREATE TABLE IF NOT EXISTS patients (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
date_of_birth TEXT NOT NULL,
clinic TEXT NOT NULL,
diagnosis TEXT NOT NULL,
last_visit TEXT NOT NULL,
phone TEXT
)
''')
for i in range(50):
first = random.choice(HAITIAN_FIRST_NAMES)
last = random.choice(HAITIAN_LAST_NAMES)
name = f'{first} {last}'
year = random.randint(1955, 2005)
month = random.randint(1, 12)
day = random.randint(1, 28)
dob = f'{year}-{month:02d}-{day:02d}'
clinic = random.choice(CLINICS)
diagnosis = random.choice(DIAGNOSES)
visit_month = random.randint(1, 12)
visit_day = random.randint(1, 28)
last_visit = f'2024-{visit_month:02d}-{visit_day:02d}'
phone = f'+509 {random.randint(3000, 4999)}-{random.randint(1000, 9999)}'
cursor.execute(
'INSERT INTO patients (name, date_of_birth, clinic, diagnosis, last_visit, phone) VALUES (?, ?, ?, ?, ?, ?)',
(name, dob, clinic, diagnosis, last_visit, phone)
)
# Notes table (XSS target -- content rendered with | safe)
cursor.execute('''
CREATE TABLE IF NOT EXISTS notes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
patient_id INTEGER NOT NULL,
author TEXT NOT NULL,
content TEXT NOT NULL,
created_at TEXT NOT NULL,
FOREIGN KEY (patient_id) REFERENCES patients (id)
)
''')
# Add some sample clinical notes
sample_notes = [
(1, 'dr.moreau', 'Patient presents with elevated blood pressure (150/95). Adjusted medication dosage. Follow-up in 2 weeks.', '2024-03-15 09:30:00'),
(1, 'nurse.celestin', 'Blood pressure check: 140/90. Patient reports taking medication as prescribed.', '2024-03-29 10:15:00'),
(5, 'dr.moreau', 'Prenatal visit - 28 weeks. Fetal heartbeat normal. No complications noted. Next visit in 2 weeks.', '2024-03-20 11:00:00'),
(12, 'dr.moreau', 'TB medication adherence confirmed. Sputum test scheduled for next visit.', '2024-03-18 14:30:00'),
(23, 'nurse.celestin', 'HIV rapid test result: positive. Counseling provided. Referral to Cap-Haitien Centre for ARV initiation.', '2024-03-22 08:45:00'),
]
for patient_id, author, content, created_at in sample_notes:
cursor.execute(
'INSERT INTO notes (patient_id, author, content, created_at) VALUES (?, ?, ?, ?)',
(patient_id, author, content, created_at)
)
conn.commit()
conn.close()
if __name__ == '__main__':
initialize()
print(f'Database initialized at {DATABASE}')