2.4 KiB
2.4 KiB
EMR App Refactoring Plan
Changes Required
1. Remove Encounter Model ❌
The entire Encounter class and EncounterManager need to be removed from emr/models.py since they now live in core/models.py.
2. Add Imports ✅
# At the top of emr/models.py
from core.models import Encounter, Patient, TenantScopedModel
3. Update Patient References (8 models)
All models currently reference 'patients.PatientProfile' - these need to change to 'core.Patient':
-
VitalSigns
patient = FK('patients.PatientProfile')→FK('core.Patient')- Keep
encounter = FK(Encounter)(local reference, will become core reference)
-
ProblemList
patient = FK('patients.PatientProfile')→FK('core.Patient')related_encounter = FK(Encounter)→ stays the same
-
CarePlan
patient = FK('patients.PatientProfile')→FK('core.Patient')
-
ClinicalNote
patient = FK('patients.PatientProfile')→FK('core.Patient')encounter = FK(Encounter)→ stays the same
-
ClinicalRecommendation
patient = FK('patients.PatientProfile')→FK('core.Patient')related_encounter = FK(Encounter)→ stays the same
-
AllergyAlert
patient = FK('patients.PatientProfile')→FK('core.Patient')
-
CriticalAlert
patient = FK('patients.PatientProfile')→FK('core.Patient')related_encounter = FK(Encounter)→ stays the same
-
DiagnosticSuggestion
patient = FK('patients.PatientProfile')→FK('core.Patient')
4. Models That Don't Need Patient Changes
These models don't have patient FKs:
- NoteTemplate (tenant-scoped only)
- Icd10 (global reference data)
- TreatmentProtocol (tenant-scoped only)
- ClinicalGuideline (tenant-scoped only)
5. Consider Using TenantScopedModel
Many EMR models could inherit from TenantScopedModel instead of manually defining tenant/timestamps/etc. This is optional but recommended for consistency.
Implementation Strategy
Given the large file size (~1500 lines), we'll use a targeted approach:
- Add imports at top
- Remove Encounter and EncounterManager classes (lines ~20-300)
- Update each model's patient FK using replace_in_file
- Test that all references work
Expected Benefits
- ✅ Encounter available to all apps
- ✅ Patient identity centralized
- ✅ Consistent with core architecture
- ✅ Cleaner separation of concerns