feat: Temperature Vitals Implementation
MR: Temperature Vitals Implementation
Overview
This Merge Request implements a new Temperature field across the entire EHR system. It enables medical camp volunteers to record patient body temperature, validates the input for medical accuracy (allowing decimals like 98.6°F), and ensures data is persisted and retrievable in the patient's vitals history.
What does this MR do and why?
Comprehensive patient assessment requires recording temperature, which was previously missing from the vitals recording workflow. This change provides a critical health metric for clinical decision-making.
The implementation follows the established architecture:
-
Scalable Schema: Uses
Numeric(10, 2)in PostgreSQL to store precise temperature readings. - Robust Validation: Implemented a regex-based validator on the frontend to handle decimal inputs while preventing invalid characters.
-
Seamless UX: Integrated the field into the existing
RecordVitalsPageandVitalsHistoryviews without disrupting the current volunteer workflow.
Changes Made
Frontend (ehrs-frontend-vite)
-
Modified
src/types/api.ts: AddedtemperaturetoVitalUpdateandVitalWithCampInfointerfaces. -
Modified
src/pages/volunteer/RecordVitalsPage.tsx:- Added UI input for Temperature.
- Created
handleFloatChangeto manage decimal state. - Updated
validateFieldto allow float numbers for temperature. - Updated
updateVitalsMutationto include temperature in the API payload.
-
Modified
src/components/VitalsByCampSection.tsx: Updated the display logic to show stored temperature values. -
Modified
src/locales/en/translations.json: Added "Temperature" labels and "98.6" placeholders.
Backend (ehrs-fastapi)
-
Modified
app/models/patient_visit_details.py: Addedtemperaturecolumn and aCheckConstraint(0 < value < 150). -
Modified
app/schemas/patient.py: Updated Pydantic schemas to include the new field. -
Modified
app/api/v1/routes/patient_routes.py: Explicitly mapped thetemperaturefield in the PUT endpoint. -
Modified
app/services/patient_service.py: Updatedcreate_vitalandupdate_vitallogic to persist the new field.
Technical Details
Bug Fix/Integration Fix:
-
Root Cause: Initially, the temperature was showing as
NULLin the DB because the API endpoint was not explicitly mapping the field from the request schema to the internal service object. -
Fix: Updated
patient_routes.pyandpatient_service.pyto ensure every path (creation and update) explicitly handles thetemperatureattribute.
Type of Change
-
✨ New feature (non-breaking change that adds functionality) -
🐛 Bug fix (resolved NULL storage issue) -
📝 Documentation update -
♻ ️ Refactor
Screenshots or Screen Recordings
| Before | After |
|---|---|
| (Missing Temperature) |
How to Set Up and Validate Locally
-
Frontend Validation:
- Run
bun dev. - Go to "Record Vitals".
- Enter
98.6in the Temperature field. - Click "Save Vitals".
- Run
-
Backend Validation:
- Run
alembic upgrade head. - Restart the server.
- Verify the value in the database:
SELECT temperature FROM patient_visit_details WHERE book_no = 10;
- Run
Testing Done
-
Manual testing completed -
Unit tests added/updated
Test Cases Covered:
| Scenario | Expected Result | Status |
|---|---|---|
| Enter decimal (99.5) | Stored as 99.50 | |
| Enter whole number (100) | Stored as 100.00 | |
| Leave empty | Stored as NULL |
Code Quality Checklist
-
Code follows project conventions -
No console.log() statements left -
TypeScript types are properly defined in src/types/api.ts -
i18n support implemented for all new strings
closes #335 (closed)

