4.0 KiB
Physician Reference Fixes
Summary
Fixed all references to use the correct model (organizations.Staff) instead of incorrect Physician model references.
Root Cause
The system uses organizations.Staff model for physicians, not a separate Physician model. Several templates and code were incorrectly trying to access a physician attribute on PhysicianMonthlyRating and PatientJourneyStageInstance objects, when the actual field is staff.
Files Fixed
1. Journeys Module
File: apps/journeys/ui_views.py
- Changed
prefetch_related()parameter from'stage_instances__physician'to'stage_instances__staff'in two places - Line 40 (journey_instance_list view) and Line 149 (journey_instance_detail view)
- This was the source of the original AttributeError: "Cannot find 'physician' on PatientJourneyStageInstance object"
File: apps/journeys/serializers.py
- Changed
PatientJourneyStageInstanceSerializerfield fromphysiciantostaff - Changed
physician_namemethod tostaff_name - Updated fields list to use
staffandstaff_nameinstead ofphysicianandphysician_name - The
PatientJourneyStageInstancemodel has astafffield, notphysician
2. Appreciation Module
File: apps/appreciation/views.py
- Changed all
Physician.objectsreferences toStaff.objects - Updated queryset filters and filters context to use Staff model
File: apps/appreciation/serializers.py
- Changed model reference from
PhysiciantoStaff - Updated all field references from
physiciantostaff
3. Dashboard Module
File: templates/dashboard/command_center.html
- Changed
rating.physician.*references torating.staff.* - The
PhysicianMonthlyRatingmodel has astafffield, notphysician
4. Physicians Templates
File: templates/physicians/ratings_list.html
- Changed all
rating.physician.*references torating.staff.*
File: templates/physicians/specialization_overview.html
- Changed all
rating.physician.*references torating.staff.*
File: templates/physicians/department_overview.html
- Changed all
rating.physician.*references torating.staff.*
5. Physicians App (Verified - No Changes Needed)
The physicians app is already correctly implemented:
apps/physicians/models.py-PhysicianMonthlyRating.stafffield correctly points toorganizations.Staffapps/physicians/views.py- All code correctly usesstafffield when queryingPhysicianMonthlyRatingapps/physicians/serializers.py- All serializers correctly referencestafffieldapps/physicians/ui_views.py- All views correctly usestafffieldtemplates/physicians/*.html- All templates correctly access physician attributes throughphysician.*wherephysicianis a Staff object
The variable name physician is used correctly in templates as it represents a Staff object passed from views, not a separate Physician model.
Model Structure
organizations.Staff
- This is the actual physician model
- Contains fields like:
first_name,last_name,license_number,specialization,department,hospital
physicians.PhysicianMonthlyRating
- Contains monthly aggregated ratings for physicians
- Has a
stafffield (ForeignKey toorganizations.Staff), NOTphysician - This was the source of most template errors
journeys.PatientJourneyStageInstance
- Contains stage instances in patient journeys
- Has a
stafffield (ForeignKey toorganizations.Staff), NOTphysician - This was the source of the serializer error
Verification
All imports were verified to be correct:
PhysicianMonthlyRatingimports are all correct- No old
Physicianmodel imports exist - Only one
physician_profilereference found, which is a commented line
Testing
The application should now work correctly without the following errors:
AttributeError: Cannot find 'physician' on PatientJourneyStageInstance object- Template rendering errors due to
rating.physiciannot existing - All physician-related views should display correctly