Skip to content

fix: resolve doctor reassignment

Aravind swamy Majjuri requested to merge reassinged-doctor into develop

Overview

Fix doctor assignment and reassignment workflow in eHRS to ensure proper consultation lifecycle handling, prevent invalid reassignment during active consultation, and maintain consistency between consultation and queue records.


What does this MR do and why?

This MR resolves multiple issues in the doctor assignment system where:

  • Reassignment was allowed during active consultation stages
  • Same API (/assign-doctor) was used for both assign and reassign
  • Multiple active consultations could be created for a single patient
  • Consultation and queue doctor mappings became inconsistent
  • Backend startup misconfiguration caused runtime failures

Motivation

To enforce strict consultation lifecycle rules and ensure data consistency across the system.

Approach

  • Separated assignment and reassignment logic
  • Introduced status-based validation
  • Prevented duplicate active consultations
  • Synced queue and consultation records
  • Fixed backend startup configuration

Changes Made

  • Refactored doctor assignment logic
  • Added separate reassignment function
  • Introduced status validation checks
  • Prevented multiple active consultations
  • Synced doctor_id between consultation and queue
  • Fixed FastAPI startup path (app.main:app)

Technical Details

Root Causes:

  • No validation on consultation status
  • Misuse of /assign-doctor API
  • Lack of constraint on active consultations
  • Queue and consultation updates handled independently

Fix:

  • assign_patient_to_consultation → creates new consultation

  • reassign_doctor_for_consultation → updates existing consultation

  • Added strict status validation:

    Allowed:

    • REGISTERED
    • WAITING
    • CONSULTATION_COMPLETED

    Blocked:

    • IN_CONSULTATION_QUEUE
    • IN_CONSULTATION
  • Added validation query to ensure only one active consultation per patient

  • Ensured queue and consultation updates happen together


Type of Change

  • 🐛 Bug fix
  • New feature
  • 💥 Breaking change
  • 📝 Documentation update
  • 🎨 UI/UX improvement
  • ️ Refactor
  • Performance improvement
  • 🧪 Test update
  • 🔧 Configuration change
  • 🚨 Security fix

Related Issues / References

  • Fixes doctor reassignment during active consultation
  • Prevents duplicate consultation creation

Screenshots or Screen Recordings

Before:

Screenshot_from_2026-04-03_21-54-12

After:

image

Edited by Aravind swamy Majjuri

Merge request reports

Loading