fix(consultations): enforce vitals completion before prescription submission
This merge request resolves a workflow validation issue in the prescription endpoint.
Previously, the following endpoint:
POST /api/v1/consultations/{consultation_id}/prescription
allowed prescriptions to be created even when the patient's vitals had not been recorded. This resulted in an incorrect workflow sequence and enabled step skipping in the consultation process.
Root Cause
The backend did not enforce validation to ensure that the "vitals" step was completed before allowing prescription submission. As a result, the system relied solely on frontend flow control, which is insufficient for enforcing business rules.
Fix Implemented
A validation guard has been introduced at the beginning of the prescription endpoint to enforce proper workflow order:
The consultation is first validated for existence (returns 404 if not found).
The associated patient visit status is retrieved.
The system checks whether VisitStatusEnum.vitals exists in the visit status.
If vitals are not recorded, the API returns:
{ "detail": "Vitals are not recorded" }
with HTTP status code 400.
If vitals are completed, the existing prescription creation logic executes without modification.
Impact
Ensures strict backend enforcement of workflow order.
Prevents prescription submission before vitals collection.
Maintains data integrity.
Does not affect existing functionality.
Scope of Changes
No database schema changes.
No modifications to models or enums.
No changes to unrelated endpoints.
No refactoring of existing logic.
Only a minimal validation guard was added to the prescription endpoint.
Testing
Attempted to submit prescription before vitals → correctly blocked with HTTP 400.
Submitted prescription after completing vitals → successful.
Existing tests continue to pass.
The bug has been reproduced and confirmed.
A clear and concise fix has been implemented.
New tests have been added to prevent regressions.
Existing tests are passing.
screeenshot:
