Fix repeat medicine consultation and prescription flow
Overview
This MR fixes the repeat medicine flow by removing the dependency on real doctor assignment while still maintaining the existing consultation and prescription workflow.
The changes ensure repeat medicine patients can:
- Skip actual doctor selection
- Reuse the same consultation and prescription UI
- Add/update prescriptions without invalid consultation ID errors
- Continue through the normal medicine pickup flow
What does this MR do and why?
Previously, repeat medicine patients did not have a valid doctor_id or consultation mapping, which caused:
Invalid consultation ID format
while adding or updating prescriptions.
The backend prescription flow depended on:
doctor_assigning- valid consultation references
However, repeat medicine patients should not require a real doctor assignment.
This MR introduces repeat medicine flag-based backend handling to:
- support pseudo/virtual consultation flow
- allow prescription creation without real doctor selection
- keep existing queue and prescription workflow reusable
Related issue
Changes Made
Backend Changes
-
Added repeat medicine conditional handling
-
Added fallback consultation logic for:
doctor_id == None and is_repeat_medicine == True -
Allowed repeat medicine patients to reuse consultation/prescription flow
-
Prevented invalid consultation ID validation failure
-
Automatically handled consultation creation internally for repeat medicine flow
-
Maintained existing prescription APIs and workflow
Technical Details
Root Cause
Prescription APIs expected:
- valid
doctor_id - valid consultation mapping
For repeat medicine patients:
-
doctor_idwas null - consultation validation failed
Fix Implemented
if doctor_id is None and visit.is_repeat_medicine:
consultation = get_or_create_repeat_medicine_consultation()
This allows:
- pseudo consultation handling
- prescription updates without real doctor assignment
Type of Change
-
🐛 Bug fix (non-breaking change that fixes an issue) -
✨ New feature (non-breaking change that adds functionality)
How to Validate Locally
Normal Patient Flow
- Register patient
- Select specialization
- Assign doctor
- Add prescriptions
- Verify existing flow works normally
Repeat Medicine Flow
-
Register patient
-
Select repeat medicine
-
Skip doctor assignment
-
Open consultation card labeled:
Repeat Medicine -
Add/update prescriptions
-
Verify no invalid consultation ID error occurs
Testing Done
-
API endpoint tests passing
Test Cases Covered
| Scenario | Expected Result | Status |
|---|---|---|
| Normal consultation prescription flow | Works normally | |
| Repeat medicine prescription creation | Works without doctor assignment | |
| Repeat medicine prescription update | No invalid consultation ID error | |
| Consultation UI reuse | Repeat Medicine card shown |
Known Limitations / Technical Debt
- Repeat medicine currently uses pseudo consultation handling internally
- Future improvement can separate repeat medicine consultation type explicitly
Additional Notes
This MR intentionally reuses the existing consultation and prescription workflow/UI to minimize frontend and backend duplication while supporting repeat medicine patients cleanly.