Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

HWC - Removing Van Chain & Implementing Facility Hierarchy

1. EXISTING SYSTEM - How It Works Today

Admin Setup (One-time, for each HWC)

To set up one HWC like "Gunjalli HWC", admin must go through 6 pages in sequence:

...

Problem: HWC is a fixed building, not a moving vehicle. But the system forces admin to create fake Zone, Parking Place, and Van just to make login and worklist work. This creates unnecessary complexity and 7 database records across 6 tables for one HWC.

...

User Login (Every time a user opens the app)

When Dr. Ravi opens HWC app:

...

3 API calls, 7+ table reads just to log in.

...

Daily Patient Flow

  1. Search Patient - Nurse searches "Lakshmi" by name/phone. System finds benRegID=50001. (No vanID used here)

  2. Submit to Nurse - System writes a record in i_ben_flow_outreach table with vanID=5 and parkingPlaceID=3 (from session). This is how system knows "this patient is at this HWC."

  3. Nurse Worklist - Query runs: WHERE vanID = 5 AND nurseFlag = 1. Shows "Lakshmi" waiting for nurse. There are 16 such queries in the codebase for nurse, doctor, lab, pharmacist, radiologist, TC specialist worklists.

  4. Nurse completes → Doctor worklist → Doctor completes → Lab → Pharmacist - Same pattern. Every worklist query filters by vanID. Every visit record stores vanID and parkingPlaceID.

vanID is being used as a location identifier, not as a vehicle identifier.

...

2. NEW SYSTEM - How It Will Work After Facility Hierarchy

Admin Setup (One-time, for each HWC)

To set up "Gunjalli HWC", admin goes through 2 pages only:

...

2 pages, 2 tables. Location info is already inside the facility record.

...

User Login (Every time a user opens the app)

When Dr. Ravi opens HWC app:

...

For old users like Dr. Ravi who were already mapped to a Van: The new API has a fallback. It reads m_uservanmappingm_van → FacilityID. So Dr. Ravi logs in without any admin re-mapping.

...

Daily Patient Flow

  1. Search Patient - Same as before, no change.

  2. Submit to Nurse - System writes facilityID=4 in i_ben_flow_outreach instead of vanID. vanID and parkingPlaceID will be NULL for new records.

  3. Nurse Worklist - Query runs: WHERE facilityID = 4 AND nurseFlag = 1. Same 16 queries, just vanID replaced with facilityID. Same result for the nurse - no visible difference.

  4. Rest of the flow - Same as before. Doctor, Lab, Pharmacist all see their worklists filtered by facilityID instead of vanID. Patient data (vitals, diagnosis, prescription) is saved exactly the same way.

Nurse and Doctor experience does not change at all. Only the internal identifier changes from vanID to facilityID.

...

3. IMPACT ON OTHER SERVICE LINES

Each service line has its own API codebase, its own repository, and its own deployment. They share the same database but do not share code.

...

Key point: We are NOT deleting any Van tables (m_van, m_parkingplace, m_zone, m_uservanmapping, m_userparkingplacemap). All these tables stay in the database. MMU and TM continue reading them. We are only stopping HWC from using them.

...

4. DATABASE CHANGES

What we ADD (before deploying new code)

Change 1: Add facilityID column to worklist table

...

For new users, admin maps them directly to a facility. Old users still work through the existing Van mapping tables (fallback).

What we DO NOT change

  • m_van - NOT deleted, NOT modified (MMU/TM reads it)
  • m_parkingplace - NOT deleted, NOT modified
  • m_parkingplacesubdistrictmap - NOT deleted, NOT modified
  • m_userparkingplacemap - NOT deleted, NOT modified (old user fallback)
  • m_uservanmapping - NOT deleted, NOT modified (old user fallback)
  • m_zone - NOT deleted, NOT modified
  • m_itemfacilitymapping - NOT changed (already uses facilityID)
  • t_itemstockentry - NOT changed (already uses facilityID)

Zero tables deleted. Zero columns deleted. Only 1 column added, 1 table created.

Pre-deployment verification

-- Must return 0 rows. If any Van has NULL FacilityID, fix it first.
SELECT VanID, VanName FROM db_iemr.m_van
WHERE FacilityID IS NULL AND Deleted = false;

Post-deployment verification

-- Must return 0. All old records should have facilityID filled.
SELECT COUNT(*) FROM db_iemr.i_ben_flow_outreach
WHERE facilityID IS NULL AND vanID IS NOT NULL;

Rollback

If anything goes wrong after deployment:

...

          Fully reversible with zero data loss

TWO OPTIONS FOR INVENTORY MAP

Option A: Remove Van Chain from HWC (Full Change)

What: Stop using vanID in HWC completely. Login, worklist, visit save - everything uses facilityID directly.

Work involved:

  • DB: Add facilityID column to i_ben_flow_outreach, backfill old records, new table m_userfacilitymapping
  • HWC-API:

...

  •   (new login API, 16 worklist queries, visit save, entity change)
  • HWC-UI:

...

  • (login flow, session, worklist calls, visit save)
  • Inventory-API:

...

  •   (hierarchy walk)

...

Benefit:

...

]

  • No more fake Van, Zone, Parking Place for HWC
  • Clean architecture - HWC uses facility directly
  • Login: 2 API calls instead of 3
  • Hierarchy built-in (DH→CHC→PHC→SC)

Risk:

  • Old data needs backfill
  • Old user login needs fallback logic

...

Option B: Keep Van, Use Existing FacilityID for Hierarchy (Minimal Change)

What: Van flow stays exactly as it is. Login still uses vanID, worklist still filters by vanID, visit save still stores vanID. BUT - every Van already has FacilityID in m_van table. And m_facility now has ParentFacilityID (hierarchy is already done). So hierarchy is already connected through the existing link:

Van (VanID=5) → m_van.FacilityID=4 → m_facility (FacilityID=4, ParentFacilityID=3)
                                        → Kavital PHC (3, Parent=2)
                                          → Manvi CHC (2, Parent=1)
                                            → Raichur DH (1)

The chain already exists. No need to change login, worklist, or visit save.

Work involved:

  • DB: ZERO changes to i_ben_flow_outreach (no new column, no backfill)
  • HWC-API: ZERO changes to login, worklist, visit save
  • HWC-UI: ZERO changes to login, worklist, visit save
  • Inventory-API:

...

  • (hierarchy walk using Van → FacilityID → ParentFacilityID)

...

Benefit:

  • Almost no code changes
  • No risk to existing flow - everything stays as is
  • No old data migration needed
  • Hierarchy is available whenever needed through Van → FacilityID → m_facility
  • Inventory hierarchy walk works (Van → FacilityID → walk up parents)
  • Can be done very quickly

Limitation:

  • Admin still needs 6 pages to set up a new HWC (fake Van, Zone, Parking Place still required)
  • vanID is still the main identifier everywhere in HWC code
  • For every new HWC facility in hierarchy, admin must still create a corresponding Van

...

Side by Side


Option A (Remove Van)Option B (Keep Van + Hierarchy)
Files to change~57~3-5



DB migrationYes (ALTER + backfill)No
Login flowChanged (facilityID)No change
Worklist queriesChanged (16 queries)No change
Visit saveChangedNo change
Admin setup for new HWC2 pages6 pages (same as now)
Fake Van/Zone neededNoYes (same as now)
Hierarchy availableYes (direct)Yes (through Van → FacilityID)
Inventory hierarchy walkYesYes
RiskMedium (many changes)Very low (minimal changes)
Testing effortHigh (~57 files)Low (~3-5 files)



Old data handlingBackfill neededNo change needed
RollbackRedeploy old codeAlmost nothing to rollback

...

...

 

OLD DATA HANDLING - COMPLETE IMPACT ANALYSIS

...

1. HOW DATA IS STORED TODAY (Before any change)

i_ben_flow_outreach table - current state:

benRegIDvisitCodevanIDparkingPlaceIDfacilityIDproviderServiceMapIDnurseFlagdoctorFlag
50001V_50001_153NULL5 (HWC)10
50002V_50002_153NULL5 (HWC)11
50003V_50003_194NULL3 (MMU)10
50005V_50005_120-NULL5 (HWC)29

facilityID column does not exist yet. vanID is the only location identifier. Row 50005 is an existing pending TC request - vanID already updated to TM specialist Van (20) when HWC doctor referred.

m_van table - the bridge:

VanIDVanNameParkingPlaceIDFacilityIDProviderServiceMapID
5Gunjalli HWC Van345 (HWC)
9MMU Van Raichur473 (MMU)
20TM Specialist Van-NULL6 (TM)

Every HWC Van must have FacilityID. This is the bridge for backfill. TM Van has NULL FacilityID - this is fine, TM queries by vanID not facilityID.

...

2. PRE-DEPLOYMENT MANDATORY CHECKS (Before running DB script)

This is the only genuine risk in the entire implementation.

If any HWC Van has FacilityID = NULL in m_van, the backfill JOIN will set facilityID = NULL for those patient records. After code deploy, new worklist query WHERE facilityID = 4 will NOT find those patients. They disappear from worklist.

Check 1: Must return 0 rows. If not, fix those Vans in Admin first.

SELECT VanID, VanName FROM m_van
WHERE FacilityID IS NULL
AND Deleted = false
AND ProviderServiceMapID = 5; -- HWC service map only

If any Van returned → go to Admin → open that Van → map it to correct Facility → recheck.

Only proceed to DB script after this returns 0 rows.

...

3. STEP 1 - ADD COLUMN (DB Script, before code deploy)

ALTER TABLE i_ben_flow_outreach ADD COLUMN facilityID INT DEFAULT NULL;

i_ben_flow_outreach after ALTER TABLE:

benRegIDvanIDparkingPlaceIDfacilityIDproviderServiceMapIDnurseFlag
5000153NULL5 (HWC)1
5000253NULL5 (HWC)1
5000394NULL3 (MMU)1
5000520-NULL5 (HWC)2

Column added. All NULL. Old code still running. vanID still there. All users working normally. Zero disruption.

...

4. STEP 2 - BACKFILL (same DB script, before code deploy)

UPDATE i_ben_flow_outreach bf
JOIN m_van v ON bf.vanID = v.VanID
SET bf.facilityID = v.FacilityID
WHERE bf.facilityID IS NULL;

i_ben_flow_outreach after backfill:

benRegIDvanIDparkingPlaceIDfacilityIDproviderServiceMapIDnurseFlagnote
50001534 (HWC)5 (HWC)1filled from Van 5
50002534 (HWC)5 (HWC)1filled from Van 5
50003947 (MMU)3 (MMU)1filled from Van 9
5000520-NULL5 (HWC)2TM Van - NULL is fine, TM queries by vanID=20

vanID=5 → FacilityID=4 (HWC records filled) vanID=9 → FacilityID=7 (MMU records filled) vanID=20 → FacilityID=NULL (TM Van - no facility mapping needed, TM still works)

vanID untouched for all records. Old code still runs fine.

Check 2: Post-backfill verification. Must return 0 before deploying code.

SELECT COUNT(*) FROM i_ben_flow_outreach
WHERE facilityID IS NULL
AND vanID IN (
    SELECT VanID FROM m_van WHERE ProviderServiceMapID = 5
)
AND providerServiceMapID = 5;

If this returns any count → some HWC Van still has NULL FacilityID → fix in Admin → re-run backfill → recheck.

Only proceed to code deployment after this returns 0.

...

5. AFTER CODE DEPLOY - NEW PATIENT VISITS

benRegIDvanIDparkingPlaceIDfacilityIDproviderServiceMapIDnurseFlagnote
500015345 (HWC)1old - backfilled
500025345 (HWC)1old - backfilled
50099NULLNULL45 (HWC)1new - direct
500039473 (MMU)1MMU - untouched
5000520-NULL5 (HWC)2TM TC - vanID=20 intact

...

6. HOW EACH SERVICE READS THIS TABLE

HWC Nurse worklist (new query - confirmed from code):

WHERE facilityID = 4 AND providerServiceMapID = 5 AND nurseFlag = 1

Finds: 50001, 50002 (old backfilled) + 50099 (new direct). All HWC patients. Correct.

MMU Nurse worklist (unchanged query - confirmed from code):

WHERE vanID = 9 AND providerServiceMapID = 3 AND nurseFlag = 1

Finds: 50003. Only MMU patients. Correct.

HWC records never appear in MMU query. MMU records never appear in HWC query. Zero overlap.

...

7. TM (TELEMEDICINE) - ZERO CHANGE. ZERO IMPACT.

TM uses HWC code for TC flow. We are not touching TM-API at all.

When HWC doctor refers patient to TM specialist, HWC-API updates the record:

SET vanID = TM_Specialist_Van_20,
    specialist_flag = 1,
    tCSpecialistUserID = 300

The record's vanID is overwritten with TM specialist's vanID (20) at the time of TC request. This happens whether the original record had vanID=5 (old) or vanID=NULL (new after our change).

Old pending TC (before go-live):

benRegIDvanIDfacilityIDspecialist_flag
5000520 (TM Van)NULL1 (pending)

TM specialist worklist:

WHERE specialist_flag = 1 AND vanID = 20

Finds 50005. Old TC request visible. Zero break.

New TC request (after go-live): New HWC record has vanID=NULL, facilityID=4. Doctor refers to TM → update writes vanID=20 → TM finds it. Zero break.

...

8. FLW - ZERO CHANGE. ZERO IMPACT.

FLW ASHA workers register patients and do home visits. Their data lives in separate FLW-specific tables (AncCare, PNCCare, ChildVaccination etc.). They do NOT write to i_ben_flow_outreach.

When FLW registers patient Lakshmi → benRegID=50001 in shared beneficiary tables. When Lakshmi walks into HWC → nurse searches by name/phone → finds benRegID=50001 → visible in HWC.

Search is by name/phone/Aadhaar. vanID never part of search. Zero break.

...

9. CROSS SERVICE - SAME PATIENT VISITS MULTIPLE SERVICES

Lakshmi (benRegID=50001) visited MMU in January, HWC in March:

benRegIDvanIDfacilityIDproviderServiceMapIDservicedate
50001973MMUJan visit
50001NULL45HWCMar visit

MMU query: WHERE vanID=9 AND psmID=3 → Jan MMU visit only HWC query: WHERE facilityID=4 AND psmID=5 → Mar HWC visit only

Each service sees only its own records. No overlap. No data leak.

...

10. OLD USER LOGIN ON PROD (No admin action needed)

Old HWC user Dr. Ravi - mapped to Van:

UserIDVanIDm_van FacilityID
10054

New login API fallback:

UserID=100 → m_uservanmapping → VanID=5
           → m_van → FacilityID=4
           → m_facility(4) → District=Raichur, Block=Manvi
Session: facilityID=4

Dr. Ravi logs in. Worklist shows all patients (old backfilled + new). No re-mapping needed.

New user Dr. Priya - mapped directly to facility:

Admin maps: UserID=200 → FacilityID=4 (m_userfacilitymapping)
Login: UserID=200 → m_userfacilitymapping → FacilityID=4

Both old and new users work simultaneously. No conflict.

...

11. COMPLETE TABLE AND SERVICE LINE IMPACT

TableChangeHWCMMUTMFLW1041097ECDFHIRSchedulerImpact
i_ben_flow_outreachADD facilityID + backfillfacilityID columnvanID untouchedTC vanID=TM Van intactNot usedNot usedNot usedNot usedReads dataNot usedZero operational impact
m_vanNOT touchedOld user fallbackStill readsStill readsStill reads---Still readsStill readsZero
m_facilityHierarchy donefacilityID + locationNot usedNot usedNot usedfacilityID fieldNot usedNot usedReads dataNot usedZero
m_userfacilitymappingNEW tableNew users onlyNot usedNot usedNot usedNot usedNot usedNot usedNot usedNot usedAdditive only
m_uservanmappingNOT touchedOld user fallbackStill readsStill reads------Zero
t_beneficiaryNOT touchedSearch by name/phoneStill readsStill readsStill readsStill readsStill readsStill readsReads data-Zero
i_beneficiarymappingNOT touchedvanID nullableStill readsStill readsStill readsStill readsStill readsStill readsReads data-Zero
FLW-specific tablesNOT touchedNot usedNot usedNot usedFully intactNot usedNot usedNot usedNot usedNot usedZero

...

12. ALL REPOS CONFIRMED FROM CODE

RepoChangeStatus
HWC-APIYES Login, worklist, visit save
HWC-UIYES Login flow, session, worklist
Admin-APISMALL User-facility mapping endpoint
Inventory-APISMALLHierarchy walk for items
TM-APIZEROTC flow unaffected. Not touching TM code
FLW-APIZEROSeparate tables. benRegID search unchanged
MMU-APIZEROSeparate codebase, own vanID
Identity-APIZEROvanID nullable in beneficiary tables
BeneficiaryID-Gen-APIZEROMMU offline sync only. HWC never calls it
Common-APIZEROFacilityLoginRepo already exists
Helpline104-APIZEROIMRMMR reporting only. No worklist impact
Helpline1097-APIZEROZero vanID/facilityID usage at all
ECD-APIZEROOne nullable DTO field only
Scheduler-APIZEROVan scheduling for TM only
FHIR-APIZEROData exchange only. Models already support facilityID

...

13. PROD GO-LIVE STEP BY STEP

Step 1: Run pre-check query
        SELECT VanID FROM m_van WHERE FacilityID IS NULL
        AND Deleted = false AND ProviderServiceMapID = 5
        → Must return 0. Fix any Vans in Admin if needed.

Step 2: Run DB script
        ALTER TABLE (add facilityID column)
        Old code still running. Users unaffected.

Step 3: Run backfill
        UPDATE from m_van JOIN
        All HWC records get facilityID filled silently.

Step 4: Run post-backfill verification
        SELECT COUNT(*) WHERE facilityID IS NULL (HWC records)
        → Must return 0.

Step 5: Deploy HWC-API and HWC-UI
        New code uses facilityID.
        Old records already have it. New records write it directly.

Step 6: Verify on prod
        Old users login and check worklist.
        New patient registration and worklist check.