Skip to content

feat: Temperature Vitals Implementation

Vandana reddy Balannagari requested to merge feat/temperature into develop

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 RecordVitalsPage and VitalsHistory views without disrupting the current volunteer workflow.

Changes Made

Frontend (ehrs-frontend-vite)

  • Modified src/types/api.ts: Added temperature to VitalUpdate and VitalWithCampInfo interfaces.
  • Modified src/pages/volunteer/RecordVitalsPage.tsx:
    • Added UI input for Temperature.
    • Created handleFloatChange to manage decimal state.
    • Updated validateField to allow float numbers for temperature.
    • Updated updateVitalsMutation to 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: Added temperature column and a CheckConstraint (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 the temperature field in the PUT endpoint.
  • Modified app/services/patient_service.py: Updated create_vital and update_vital logic to persist the new field.

Technical Details

Bug Fix/Integration Fix:

  • Root Cause: Initially, the temperature was showing as NULL in 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.py and patient_service.py to ensure every path (creation and update) explicitly handles the temperature attribute.

Type of Change

  • New feature (non-breaking change that adds functionality)
  • 🐛 Bug fix (resolved NULL storage issue)
  • 📝 Documentation update
  • ️ Refactor

Screenshots or Screen Recordings

image image

Before After
(Missing Temperature) Temperature Implementation

How to Set Up and Validate Locally

  1. Frontend Validation:

    • Run bun dev.
    • Go to "Record Vitals".
    • Enter 98.6 in the Temperature field.
    • Click "Save Vitals".
  2. 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;

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)

Edited by Vandana reddy Balannagari

Merge request reports

Loading