6.0 KiB
HIS Simulator - Patient Journeys Summary
Overview
This document summarizes the patient journeys implemented in the HIS simulator and the survey delivery system.
Patient Journeys (4 Types)
The HIS simulator supports 4 distinct patient journey types, each with its own survey template:
1. Inpatient Journey (PatientType: 1)
- Survey Template: Inpatient Post-Discharge Survey
- Requirements: Must have a discharge date
- Flow:
- Patient admission
- Hospital stay
- Discharge event → Triggers survey
- Survey sent via SMS
2. OPD Journey (PatientType: 2)
- Survey Template: OPD Patient Experience Survey
- Requirements: No discharge required (sent after visit)
- Flow:
- Patient registration
- Consultation/visit
- Visit completion → Triggers survey
- Survey sent via SMS
3. EMS Journey (PatientType: 3)
- Survey Template: EMS Emergency Services Survey
- Requirements: No discharge required (sent after emergency visit)
- Flow:
- Emergency arrival
- Emergency treatment
- Visit completion → Triggers survey
- Survey sent via SMS
4. Day Case Journey (PatientType: 4)
- Survey Template: Day Case Patient Survey
- Requirements: Has discharge date (same-day procedure)
- Flow:
- Patient admission
- Procedure/treatment
- Same-day discharge → Triggers survey
- Survey sent via SMS
Technical Implementation
HIS Integration Endpoint
- URL:
POST /api/integrations/events/ - View:
HISPatientDataView(inapps/integrations/views.py) - Service:
HISAdapter.process_his_data()(inapps/integrations/services/his_adapter.py)
Patient Type Mapping
The system maps HIS PatientType codes to survey types:
| HIS Code | Survey Type | Template Name |
|---|---|---|
| "1" | INPATIENT | Inpatient Post-Discharge Survey |
| "2", "O" | OPD | OPD Patient Experience Survey |
| "3", "E" | EMS | EMS Emergency Services Survey |
| "4" | DAYCASE | Day Case Patient Survey |
Survey Template Selection Logic
The system searches for appropriate survey templates using a hierarchical approach:
- Primary search: Look for template by patient type keywords, filtered by hospital
- Secondary search: Look for template by patient type keywords, without hospital filter
- Fallback 1: Use any active template for the hospital
- Fallback 2: Use any active template in the system
Search terms (in order of specificity):
- INPATIENT: "INPATIENT", "Inpatient"
- OPD: "OPD", "Outpatient"
- EMS: "EMS", "Emergency"
- DAYCASE: "Day Case"
Data Flow
HIS System
↓
POST /api/integrations/events/
↓
HISPatientDataView
↓
HISAdapter.process_his_data()
↓
1. Parse patient data
2. Get or create Hospital
3. Get or create Patient
4. Get appropriate SurveyTemplate (based on PatientType)
5. Create SurveyInstance
6. Send survey via SMS (SurveyDeliveryService.deliver_survey)
↓
Survey sent to patient's phone number
Patient Data Structure
{
"FetchPatientDataTimeStampList": [{
"PatientID": "MRN001",
"AdmissionID": "ADM001",
"HospitalID": "1",
"HospitalName": "Al Hammadi Hospital - Riyadh",
"PatientType": "1", // 1=Inpatient, 2=OPD, 3=EMS, 4=Day Case
"AdmitDate": "28-Jan-2025 09:00",
"DischargeDate": "01-Feb-2025 14:00", // Required for Inpatient/Day Case
"PatientName": "Full Name",
"Gender": "Male",
"MobileNo": "0501234567",
"Email": "email@example.com",
"DOB": "15-Mar-1985 00:00",
// ... additional fields
}],
"FetchPatientDataTimeStampVisitDataList": [
// Visit/activity data
],
"Code": 200,
"Status": "Success"
}
Survey Templates
All survey templates are created via Django management command:
python manage.py create_his_survey_templates
This creates 4 templates for the specified hospital:
- Inpatient Post-Discharge Survey (7 questions)
- OPD Patient Experience Survey (6 questions)
- EMS Emergency Services Survey (6 questions)
- Day Case Patient Survey (6 questions)
Testing
A comprehensive test script is available:
python test_all_patient_types.py
This script tests all 4 patient types and verifies:
- Survey creation
- Correct template selection
- Survey URL generation
- Database persistence
Key Features
- Patient Deduplication: Existing patients are updated with new information
- Survey Deduplication: Only one survey per admission ID
- Hospital Management: Automatic hospital creation/lookup
- Flexible Template Matching: Multiple fallback mechanisms ensure a survey is always sent
- SMS Delivery: Surveys are automatically sent via SMS
- Status Tracking: Survey status is tracked (SENT, COMPLETED, etc.)
Important Notes
- Inpatient patients MUST have a discharge date before a survey is sent
- OPD and EMS patients do NOT require discharge dates (surveys sent after visit)
- Day Case patients have discharge dates (same-day procedures)
- Survey templates must be active (
is_active=True) - Patient phone number is required for SMS delivery
Files Modified/Created
Core Integration Files
apps/integrations/views.py- HISPatientDataViewapps/integrations/services/his_adapter.py- HISAdapter serviceapps/integrations/urls.py- API endpoint configuration
Survey Templates
apps/surveys/management/commands/create_his_survey_templates.py- Template creation command
Testing
test_all_patient_types.py- Comprehensive test suite for all patient types
Summary
The HIS simulator successfully implements 4 patient journey types, each with:
- Distinct patient classification (Inpatient, OPD, EMS, Day Case)
- Appropriate survey template selection
- Automatic survey creation and delivery
- Patient and hospital management
- Flexible fallback mechanisms
All journeys are tested and working correctly, with surveys being sent via SMS to patients based on their patient type and discharge status.