0d30c58bf0
Snapshot of the working tree on srv1071960 (branch main), taken during server cleanup. .env files, node_modules, builds, logs and media were excluded.
128 lines
4.3 KiB
Python
128 lines
4.3 KiB
Python
"""Seed the minimum MVP system described in report §10.2.
|
|
|
|
Creates: 1 company, 1 headquarters, 1 AGM, 1 ABM, 1 MR, 1 System Admin,
|
|
15 doctors (3 flagged as core) and 5 chemists, all assigned to the MR.
|
|
|
|
python -m scripts.seed
|
|
|
|
Idempotent: running it twice does not duplicate anything.
|
|
"""
|
|
|
|
import asyncio
|
|
import sys
|
|
import uuid
|
|
from datetime import date
|
|
|
|
from sqlalchemy import select
|
|
|
|
from app.auth.security import hash_password
|
|
from app.chemists.models import Chemist, ChemistAssignment
|
|
from app.common.enums import Role
|
|
from app.database.session import AsyncSessionLocal
|
|
from app.doctors.models import Doctor, DoctorAssignment
|
|
from app.organization.models import AMHeadquarters, Company, Headquarters
|
|
from app.users.models import User
|
|
|
|
DEMO_PASSWORD = "ChangeMe123!"
|
|
|
|
SPECIALITIES = [
|
|
"General Medicine", "Paediatrics", "Orthopaedics", "Cardiology", "Dermatology",
|
|
]
|
|
|
|
SURNAMES = [
|
|
"Sen", "Patra", "Rout", "Mishra", "Jena", "Sahoo", "Panda", "Das",
|
|
"Nayak", "Pradhan", "Behera", "Swain", "Barik", "Mohapatra", "Tripathy",
|
|
]
|
|
|
|
|
|
async def seed() -> None:
|
|
async with AsyncSessionLocal() as db:
|
|
existing = (
|
|
await db.execute(select(Company).where(Company.name == "Acme Pharma Pvt Ltd"))
|
|
).scalar_one_or_none()
|
|
if existing:
|
|
print("Seed data already present — nothing to do.")
|
|
return
|
|
|
|
company = Company(id=uuid.uuid4(), name="Acme Pharma Pvt Ltd", address="Bhubaneswar")
|
|
db.add(company)
|
|
await db.flush()
|
|
|
|
hq = Headquarters(
|
|
id=uuid.uuid4(), company_id=company.id, code="BBSR",
|
|
name="Bhubaneswar", district="Khordha", state="Odisha",
|
|
)
|
|
db.add(hq)
|
|
await db.flush()
|
|
|
|
def make(role: Role, name: str, code: str, hq_id=None) -> User:
|
|
return User(
|
|
id=uuid.uuid4(), company_id=company.id,
|
|
email=f"{code.lower()}@acmepharma.in",
|
|
password_hash=hash_password(DEMO_PASSWORD),
|
|
full_name=name, employee_code=code, role=role, headquarters_id=hq_id,
|
|
)
|
|
|
|
admin = make(Role.ADMIN, "System Administrator", "ADM001")
|
|
gm = make(Role.AGM, "Anita Mohanty", "GM001")
|
|
am = make(Role.ABM, "Suresh Behera", "AM001")
|
|
mr = make(Role.MR, "Ravi Das", "MR001", hq.id)
|
|
db.add_all([admin, gm, am, mr])
|
|
await db.flush()
|
|
|
|
db.add(
|
|
AMHeadquarters(
|
|
area_manager_user_id=am.id, headquarters_id=hq.id, effective_from=date.today()
|
|
)
|
|
)
|
|
|
|
for i in range(15):
|
|
doctor = Doctor(
|
|
id=uuid.uuid4(), headquarters_id=hq.id,
|
|
name=f"Dr {SURNAMES[i]}",
|
|
speciality=SPECIALITIES[i % len(SPECIALITIES)],
|
|
qualification="MBBS, MD" if i % 3 == 0 else "MBBS",
|
|
clinic_address=f"Clinic {i + 1}, Unit {i % 9 + 1}, Bhubaneswar",
|
|
is_core_doctor=i < 3,
|
|
)
|
|
db.add(doctor)
|
|
await db.flush()
|
|
db.add(
|
|
DoctorAssignment(
|
|
doctor_id=doctor.id, mr_user_id=mr.id, effective_from=date.today()
|
|
)
|
|
)
|
|
|
|
for i in range(5):
|
|
chemist = Chemist(
|
|
id=uuid.uuid4(), headquarters_id=hq.id,
|
|
name=f"{['Konark','Utkal','Kalinga','Sriya','Jagannath'][i]} Medical Stores",
|
|
shop_address=f"Shop {i + 1}, Market Building, Bhubaneswar",
|
|
contact_number=f"9{i}0000000{i}",
|
|
)
|
|
db.add(chemist)
|
|
await db.flush()
|
|
db.add(
|
|
ChemistAssignment(
|
|
chemist_id=chemist.id, mr_user_id=mr.id, effective_from=date.today()
|
|
)
|
|
)
|
|
|
|
await db.commit()
|
|
|
|
print("Seeded the minimum MVP system.\n")
|
|
print(f" Password for every account: {DEMO_PASSWORD}\n")
|
|
print(" System Admin adm001@acmepharma.in")
|
|
print(" Assistant General Manager (AGM) gm001@acmepharma.in")
|
|
print(" Area Business Manager (ABM) am001@acmepharma.in")
|
|
print(" MR mr001@acmepharma.in")
|
|
print("\n 1 headquarters (BBSR), 15 doctors (3 core), 5 chemists — all assigned to MR001.")
|
|
print("\n CHANGE THESE PASSWORDS before any real use.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
asyncio.run(seed())
|
|
except KeyboardInterrupt:
|
|
sys.exit(1)
|