Skip to content

fix: fixing visit record

Aravind swamy Majjuri requested to merge visit-record into develop

Overview

This MR updates frontend components to align with the new PatientVisit schema by removing deprecated fields and ensuring safe rendering.


What does this MR do and why?

fix(frontend): update visit references and align with PatientVisit schema

  • Replace deprecated visit.id usage with camp_visit_id
  • Remove usage of non-existent visit_date
  • Add null safety checks to prevent runtime crashes
  • Update test data to match new interface structure

These changes were required after backend schema updates where id and visit_date fields were removed.


Changes Made

Files Updated

  • VisitHistory.tsx
  • AttendanceGrid.tsx
  • Consultations.tsx
  • AttendanceGrid.test.tsx

Technical Details

VisitHistory.tsx

  • Updated React map key:
    visit.camp_visit_id || index
  • Added null safety check:
    {selectedVisit && selectedVisit.camp_visit_id && (...)}
  • Prevents rendering issues when camp_visit_id is null

AttendanceGrid.tsx

  • Updated getVisitDate():
    visit.camp_date
  • Removed fallback to visit_date (no longer exists)

Consultations.tsx

  • Updated React map key:
    visit.camp_visit_id || String(visit.camp_id)
  • Ensures stable rendering key

AttendanceGrid.test.tsx

  • Updated makeVisit() helper
  • Now matches updated PatientVisit interface structure

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 📝 Documentation update
  • 🎨 UI/UX improvement
  • ️ Refactor (no functional changes)
  • Performance improvement
  • 🧪 Test update
  • 🔧 Configuration change
  • 🚨 Security fix

Related Issues / References

  • Related to backend schema update for PatientVisit

Screenshots or Screen Recordings

Before:

Screenshot_from_2026-04-04_16-40-59

After:

image


How to Set Up and Validate Locally

  1. Pull this branch:

    git checkout  visit-record
  2. Install dependencies:

    npm install
  3. Run development server:

    npm run dev
  4. Test flows:

    • Visit history page
    • Attendance grid
    • Consultations page
  5. Expected behavior:

    • No console errors
    • Visits render correctly
    • No crashes when camp_visit_id is null

Testing Done

  • Manual testing completed
  • Unit tests updated

Test Cases Covered:

Scenario Expected Result Status
Visit list rendering No key errors
Null camp_visit_id No crash
Attendance date display Uses camp_date correctly
Test data generation Matches new schema

Code Quality Checklist

Code Standards

  • Code follows project conventions
  • No console.log() left
  • No unused imports
  • No duplicate code
  • TypeScript types properly defined
  • ESLint and Prettier pass

React Best Practices

  • Proper component structure
  • Hooks follow rules
  • No unnecessary re-renders
  • Clean event handling

Error Handling

  • Null safety added
  • Runtime errors prevented

Documentation

  • CHANGELOG.md updated

Known Limitations / Technical Debt

  • Fallback keys (index, camp_id) are used where camp_visit_id is unavailable
  • Ideally, backend should always provide unique camp_visit_id

Additional Notes

  • This MR is tightly coupled with backend schema changes
  • Ensure backend is updated before testing frontend

Edited by Aravind swamy Majjuri

Merge request reports

Loading