feat: complete production hardening implementation, specialty canonicalization, google-genai migration, voice reliability, sqlite concurrency, and test suite consolidation

This commit is contained in:
2026-09-07 12:57:54 +05:30
parent c23d979338
commit 92fa71ae4a
99 changed files with 5167 additions and 3550 deletions
@@ -27,14 +27,14 @@ CARDIOLOGY_CONFIG = {
"collapsed",
"sudden loss of consciousness",
"cannot breathe",
"call 108",
"emergency ambulance",
"hospital emergency room",
"alert duty doctor",
],
"clarification_rules": [
"If the patient describes chest burning or heaviness, ask whether it is related to walking/exertion (angina) or happens after spicy/oily food (gastric acidity).",
"Ask if they are already taking regular BP tablets like Telma, Amlodipine, or daily blood thinners like Ecosprin.",
"Check if they have a history of previous heart stenting, bypass surgery, or family history of heart attacks at a young age.",
"If severe red-flag symptoms are present, immediately advise contacting 108 ambulance or visiting the nearest hospital emergency room.",
"If severe red-flag symptoms are present, immediately advise informing hospital emergency staff or visiting the hospital emergency room.",
],
}
@@ -0,0 +1,32 @@
DERMATOLOGY_CONFIG = {
"code": "dermatology",
"name": "Dermatology (Skin & Hair Care)",
"purpose": (
"Collect history of skin lesions, rashes, itching, acne, fungal infections, "
"duration, body distribution, trigger factors, and topical or oral treatments used."
),
"focus_areas": [
"Chief skin complaint (rash, severe itching/pruritus, eczema, acne/pimples, fungal infection, blisters, discoloration)",
"Lesion distribution and onset (face, scalp, trunk, arms, legs, localized vs generalized)",
"Associated symptoms (burning sensation, pain, scaling, oozing, bleeding)",
"Triggers and exposures (spicy/oily food, new soap/cosmetics, detergent, dust, sunlight, medications)",
"Current and prior treatments (antifungal creams like Clotrimazole, steroid creams, oral antihistamines like Cetirizine/Levocetirizine)",
"Known allergies (soaps, metals, cosmetics, drugs)",
],
"emergency_keywords": [
"sudden widespread peeling",
"stevens johnson syndrome",
"toxic epidermal necrolysis",
"severe facial swelling with breathing difficulty",
"rapidly spreading painful skin breakdown",
],
"clarification_rules": [
"If patient mentions skin itching or rash, ask how many days they have had it and if it spreads at night.",
"Check if they are using any over-the-counter steroid creams or soaps.",
"Inquire if any other family members share similar skin symptoms.",
],
}
@@ -24,7 +24,7 @@ DIABETOLOGY_CONFIG = {
"deep labored breathing",
"fruity breath",
"diabetic ketoacidosis",
"108 ambulance",
"hospital emergency staff / ER",
],
"clarification_rules": [
@@ -0,0 +1,32 @@
GASTROENTEROLOGY_CONFIG = {
"code": "gastroenterology",
"name": "Gastroenterology (Stomach & Digestive Care)",
"purpose": (
"Collect abdominal symptoms including stomach ache, acid reflux/GERD, "
"vomiting, bowel movement alterations (diarrhea/constipation), and dietary associations."
),
"focus_areas": [
"Abdominal pain location and character (upper stomach burning/acidity, right upper quadrant, lower abdominal cramps)",
"Bowel habits (loose stools/diarrhea frequency, constipation, bloody stools/melena)",
"Upper GI symptoms (nausea, persistent vomiting, heartburn, difficulty swallowing/dysphagia)",
"Relationship to meals (worse after oily/spicy food, pain relieved by eating or antacids)",
"Current GI medications (Pantoprazole/Pan-D, Omeprazole, Gelusil, ORS, probiotics)",
"History of ulcer disease, gallstones, jaundice, or liver disease",
],
"emergency_keywords": [
"vomiting blood or coffee ground material",
"black tarry stools",
"severe rigid abdomen with intolerable pain",
"high fever with severe jaundice and vomiting",
"acute abdomen",
],
"clarification_rules": [
"If abdominal pain is reported, ask exact location (upper stomach vs lower belly) and duration.",
"Check if symptom is accompanied by vomiting, loose motions, or acidity after meals.",
"Inquire if patient has taken antacids (Pan-D, Digene) or ORS.",
],
}
@@ -22,7 +22,7 @@ GENERAL_CONFIG = {
"severe bleeding",
"coughing up blood",
"very low blood pressure",
"108 ambulance",
"hospital emergency staff / ER",
],
"clarification_rules": [
@@ -0,0 +1,34 @@
NEUROLOGY_CONFIG = {
"code": "neurology",
"name": "Neurology (Brain & Nervous System)",
"purpose": (
"Collect neurological symptoms including headache character, dizziness, numbness, "
"weakness, seizure history, and past neurological evaluation."
),
"focus_areas": [
"Headache characteristics (throbbing, one-sided migraine, tension type, occipital, duration)",
"Associated neurological features (nausea, vomiting, sensitivity to light/sound, visual aura)",
"Dizziness or vertigo (spinning sensation, loss of balance, unsteady gait)",
"Focal symptoms (numbness/tingling in hands/feet, facial drooping, speech slurring, limb weakness)",
"Seizure or blackout history (loss of consciousness, involuntary movements, aura)",
"Current neurological medications (painkillers, migraine prophylactics like Propranolol/Flunarizine, anti-epileptics)",
],
"emergency_keywords": [
"sudden thunderclap headache",
"worst headache of my life",
"sudden weakness on one side of body",
"facial drooping with slurred speech",
"stroke symptoms",
"active seizure",
"loss of consciousness",
],
"clarification_rules": [
"If headache is reported, clarify duration, exact location (one side vs forehead), and if accompanied by nausea or light sensitivity.",
"If numbness or tingling is present, clarify if it affects both feet (diabetic neuropathy) or one side of the body.",
"Check if patient has a history of high blood pressure or previous stroke.",
],
}
@@ -0,0 +1,32 @@
ORTHOPEDICS_CONFIG = {
"code": "orthopedics",
"name": "Orthopedics (Bone & Joint Care)",
"purpose": (
"Collect musculoskeletal complaints including joint pain, spinal/back pain, "
"trauma history, stiffness, mobility restriction, and painkiller usage."
),
"focus_areas": [
"Primary joint/bone complaint (knee pain, lumbar back pain, neck pain, shoulder stiffness, ankle sprain)",
"Onset and progression (acute post-injury/fall vs chronic osteoarthritis/wear-and-tear)",
"Functional impact (difficulty walking, standing up from chair, climbing stairs, lifting objects)",
"Swelling, redness, deformity, or morning stiffness",
"Medications and pain management (NSAIDs like Aceclofenac/Diclofenac/Paracetamol, calcium, Vitamin D3 supplements)",
"Surgical or orthopedic history (previous fractures, knee replacement, spine surgery)",
],
"emergency_keywords": [
"open fracture with visible bone",
"inability to feel or move leg after injury",
"sudden loss of bowel or bladder control with back pain",
"cauda equina syndrome",
"severe traumatic limb injury",
],
"clarification_rules": [
"If knee or joint pain is reported, ask if it occurs during walking/stair climbing and how long it has been present.",
"Clarify if there was any recent fall, injury, or heavy lifting event.",
"Check if patient takes regular pain relief tablets or calcium supplements.",
],
}
@@ -0,0 +1,32 @@
PULMONOLOGY_CONFIG = {
"code": "pulmonology",
"name": "Pulmonology (Lungs & Respiratory Care)",
"purpose": (
"Collect respiratory history including cough type, breathlessness, wheezing, "
"asthma/COPD history, inhaler usage, and environmental/smoking exposure."
),
"focus_areas": [
"Cough character and duration (dry cough vs productive/phlegm, nocturnal cough, duration)",
"Shortness of breath (on exertion, at rest, when lying flat/orthopnea)",
"Wheezing or chest tightness ( whistling sound while breathing out)",
"Triggers (cold air, dust, pollen, smoke, exercise, seasonal changes)",
"Current inhalers and respiratory medicines (Asthalin/Salbutamol, Budecort/Budesonide, Montair-LC, antibiotics)",
"History of Asthma, COPD, Tuberculosis (TB), pneumonia, or smoking/bidi history",
],
"emergency_keywords": [
"severe acute breathlessness unable to speak full sentences",
"blue lips or fingernails / cyanosis",
"coughing up significant blood / hemoptysis",
"severe asthma attack unyielding to inhaler",
"respiratory distress",
],
"clarification_rules": [
"If cough is reported, ask whether dry or with phlegm and how many days it has persisted.",
"Check if patient experiences wheezing or breathlessness when walking or sleeping.",
"Clarify if patient uses regular inhalers (Asthalin, Budecort) or allergy tablets.",
],
}
@@ -1,18 +1,53 @@
from app.specialties.cardiology import CARDIOLOGY_CONFIG
from app.specialties.dermatology import DERMATOLOGY_CONFIG
from app.specialties.diabetology import DIABETOLOGY_CONFIG
from app.specialties.gastroenterology import GASTROENTEROLOGY_CONFIG
from app.specialties.general import GENERAL_CONFIG
from app.specialties.mental_health import MENTAL_HEALTH_CONFIG
from app.specialties.neurology import NEUROLOGY_CONFIG
from app.specialties.orthopedics import ORTHOPEDICS_CONFIG
from app.specialties.pulmonology import PULMONOLOGY_CONFIG
SPECIALTIES = {
"cardiology": CARDIOLOGY_CONFIG,
"dermatology": DERMATOLOGY_CONFIG,
"diabetology": DIABETOLOGY_CONFIG,
"gastroenterology": GASTROENTEROLOGY_CONFIG,
"general": GENERAL_CONFIG,
"mental_health": MENTAL_HEALTH_CONFIG,
"neurology": NEUROLOGY_CONFIG,
"orthopedics": ORTHOPEDICS_CONFIG,
"pulmonology": PULMONOLOGY_CONFIG,
}
CANONICAL_ALIASES = {
"general_medicine": "general",
"psychiatry": "mental_health",
}
def get_specialty_config(code: str) -> dict:
canonical_code = CANONICAL_ALIASES.get(code, code)
return SPECIALTIES.get(
code,
canonical_code,
GENERAL_CONFIG,
)
def validate_specialty_registry() -> dict:
"""
Automated validation for specialty registry completeness and integrity.
"""
canonical_codes = set(SPECIALTIES.keys())
missing_configs = []
for code, config in SPECIALTIES.items():
if not config or not isinstance(config, dict) or config.get("code") != code:
missing_configs.append(code)
return {
"valid": len(missing_configs) == 0,
"registered_count": len(SPECIALTIES),
"canonical_codes": list(canonical_codes),
"missing_configs": missing_configs,
}