test: increase app/services test coverage to 100% for medical_camp, medicine, and patient_consultation
Title
Increase test coverage to 100% for app/services (medical_camp, medicine, patient_consultation)
Description
Three service files in app/services/ have low test coverage and need comprehensive tests to reach 100%.
Current coverage
| File | Stmts | Miss | Cover |
|---|---|---|---|
app/services/medical_camp_service.py |
109 | 72 | 34% |
app/services/medicine_service.py |
233 | 173 | 26% |
app/services/patient_consultation_service.py |
207 | 147 | 29% |
Goal
Bring all three files to 100% test coverage with real, meaningful tests.
Requirements
- Cover all branches, edge cases, and error paths
- No hacks: no skipping, no fake assertions, no coverage bypass
- Refactor only if required for testability — preserve behavior
- Fix genuine bugs if found
- Remove dead code if found
Areas to cover
medical_camp_service.py
- CRUD:
get_medical_camp_by_date_location,get_all_medical_camps,get_medical_camps_by_date - Not-found branches for
update_medical_camp/delete_medical_camp -
calculate_attended_patients,update_attended_patients_count -
signup_user_for_camp— no camp, restricted roles, role hierarchy, already signed up, success -
update_user_attendance— invalid UUID, no camp, not registered, success -
get_volunteer_camp_status— today's camp, fallback to latest, no camp, registered/not registered
medicine_service.py
-
create_medicine_with_inventory— duplicate medicine -
get_medicine_by_id_with_inventory,get_all_medicines_with_inventory,get_all_medicines -
update_medicine_with_inventory— not found, partial/full updates -
update_inventory_from_consultation_prescriptions— pending, replaced, missing info, no inventory, insufficient, status updates -
create_given_medicine— no prescription, insufficient inventory, websocket emit paths - Remaining CRUD:
create_inventory,update_inventory,create_prescribed_medicine,create_prescription,create_input_inventory,update_prescription,get_medicines_by_patient_book_no update_patient_visit_status_to_counselling_done
patient_consultation_service.py
-
validate_consultation_status_for_prescription_access— visit details not found - All getter functions
-
delete_patient_consultation— found/not found -
get_patient_consultations_by_book_no— all error branches + success -
get_prescriptions_by_consultation_id— not found, success -
update_prescription_by_id— replacement validation, dispatch status handling, dead code removal -
delete_prescription_by_id— not found, already dispensed, success -
add_prescriptions_to_consultation— duplicate medicines, missing medicines, visit details update -
assign_patient_to_consultation— all error branches + success
Labels
testing