BAH-5064: IPD REST-to-FHIR R4 Migration — Spike Findings

BAH-5064: IPD REST-to-FHIR R4 Migration — Spike Findings

BAH-5064: IPD REST-to-FHIR R4 Migration — Spike Findings

Jira: BAH-5064
Date: 2026-09-09
Author: Vivek Pandey
Repos analysed: openmrs-module-ipd, openmrs-module-medicationadministration, openmrs-module-fhir2, openmrs-module-ipd-frontend


1. Goal

Investigate migrating the IPD module's custom REST APIs to FHIR R4 standard endpoints so the team can make an informed GO/NO-GO decision on effort, sequencing, and risks.


2. REST API Inventory

5 controllers, 15 endpoints in openmrs-module-ipd:

Controller

Base Path

Endpoints

Domain

Controller

Base Path

Endpoints

Domain

IPDWardController

/rest/v1/ipd/wards

4

Ward patient listing, search, summary counts

IPDScheduleController

/rest/v1/ipd/schedule

5

Medication schedule create/edit/query

IPDCareTeamController

/rest/v1/ipd/careteam

1

Care team participant management

IPDMedicationAdministrationController

/rest/v1/ipd

5

Scheduled/adhoc administration, amendment notes, acknowledgement

IPDVisitController

/rest/v1/ipdVisit

1

Visit medications (orders + emergency meds)

All frontend calls use axios. No FHIR endpoints currently exist in the IPD module.


3. FHIR R4 Resource Mapping

3.1 IPDWardController → Encounter + Location

Ward = FHIR Location. Admitted patients = Encounter with status=in-progress.

Current Endpoint

FHIR R4 Equivalent

Type

Current Endpoint

FHIR R4 Equivalent

Type

GET {wardUuid}/summary

GET Encounter?location={wardUuid}&status=in-progress&_summary=count (×2: total + provider-specific)

Standard

GET {wardUuid}/patients

GET Encounter?location={wardUuid}&status=in-progress&class=IMP&_include=Encounter:patient

Standard

GET {wardUuid}/myPatients

GET Encounter?location={wardUuid}&participant={providerUuid}&status=in-progress&_include=Encounter:patient

Standard

GET {wardUuid}/patients/search

GET Encounter?location={wardUuid}&patient.name={val}&status=in-progress

Standard

Gap: fhir2 Encounter search currently missing status and class search params — must be added to fhir2 before ward queries work.

3.2 IPDScheduleController → Schedule + Task (or Slot — see Section 4)

Current Endpoint

FHIR R4 Equivalent

Type

Current Endpoint

FHIR R4 Equivalent

Type

POST type/medication (create)

POST Schedule + batch POST Task

Standard

POST type/medication/edit

PUT Schedule/{id} + PUT Task/{id}

Standard

GET type/medication (by date range)

GET Task?patient={uuid}&period=ge{start}&period=le{end}

Standard

GET type/medication (by orderUuids)

GET Task?based-on={MedicationRequestRef}

Standard

GET patientsMedicationSummary

GET Task?patient=P1,P2,...&period=ge{start}&period=le{end} + client-side grouping

Standard

includePreviousSlot and includeSlotDuration are response-augmentation flags computed client-side from Task.executionPeriod — no server-side logic needed.

3.3 IPDCareTeamController → CareTeam

Near-perfect structural match.

IPD Field

FHIR CareTeam Field

IPD Field

FHIR CareTeam Field

patientUuid

subject → Reference(Patient)

visit

encounter → Reference(Encounter)

participant.providerUuid

participant[].member → Reference(Practitioner)

participant.role

participant[].role → CodeableConcept

participant.startDate/endDate

participant[].period

Current Endpoint

FHIR R4 Equivalent

Current Endpoint

FHIR R4 Equivalent

POST /participants

POST CareTeam / PUT CareTeam/{id}

3.4 IPDMedicationAdministrationController → MedicationAdministration

Translator already exists in openmrs-module-medicationadministration. All core fields map directly.

Current Endpoint

FHIR R4 Equivalent

Type

Current Endpoint

FHIR R4 Equivalent

Type

POST /scheduledMedicationAdministrations

Batch POST MedicationAdministration

Standard

POST /adhocMedicationAdministrations

POST MedicationAdministration with category=adhoc

Standard

PUT /adhocMedicationAdministrations/{uuid}

PUT MedicationAdministration/{id}

Standard

POST /medicationAdministration/{uuid}/note

PATCH MedicationAdministration/{id} (append to note[])

Standard

POST /medicationAdministration/{uuid}/acknowledgement

POST Task referencing MedicationAdministration

Standard (already uses FhirTask)

Amendment note fields (previousNote, statusReason) added in BAH-4619 need 2 FHIR extensions on MedicationAdministration.note[] — no standard Annotation fields exist for these.

3.5 IPDVisitController → MedicationRequest + MedicationAdministration

Current single endpoint blends two concerns. FHIR separates cleanly — use FHIR Batch (single HTTP call) or two parallel client calls.

Current Response Part

FHIR R4 Equivalent

Current Response Part

FHIR R4 Equivalent

prescribedOrders

GET MedicationRequest?encounter={visitUuid}

emergencyMedications

GET MedicationAdministration?context={visitUuid}&category=emergency

FHIR Batch option (single HTTP call):

POST /ws/fhir2/R4 { "resourceType": "Bundle", "type": "batch", "entry": [ { "request": { "method": "GET", "url": "MedicationRequest?encounter={visitUuid}" } }, { "request": { "method": "GET", "url": "MedicationAdministration?context={visitUuid}&category=emergency" } } ]}

4. Open Decision — Slot vs Task for Medication Slots

The IPD ipd_slot table represents individual scheduled medication administration times. Two FHIR R4 resources are candidates.

Field coverage comparison

IPD Slot Field

Slot

Task

IPD Slot Field

Slot

Task

Parent Schedule link

✓ Slot.schedule (native, mandatory 1..1)

✗ Extension needed

Start / end time

✓ Slot.start / Slot.end

✓ Task.executionPeriod.start/end

Workflow status

✗ Extension needed — standard values are busy\|free\|busy-unavailable\|busy-tentative\|entered-in-error (availability codes, not workflow states)

✓ Task.status maps perfectly: requested→SCHEDULED, completed→COMPLETED, rejected→NOT_DONE, cancelled→STOPPED, failed→MISSED

Order (MedicationRequest) link

✗ Extension needed

✓ Task.basedOn (native)

MedicationAdministration link

✗ Extension needed

✓ Task.output[].value (native)

Service type

✓ Slot.serviceType

✓ Task.code

Comments

✓ Slot.comment

✓ Task.note[]

variableDosageSequence

✗ Extension

✗ Extension

Direct patient search

✗ No patient param on Slot — 2-step query required

✓ Task?patient={uuid} (native)

Extensions required

3

2

Trade-offs

 

Slot

Task

 

Slot

Task

Semantic fit

Better — "a scheduled time block for a service" is literally what a medication slot is

Looser — Task is a work item, not a time block

Structural fit

Better — Schedule→Slot is the intended FHIR pair

Approximate — no native Schedule reference on Task

Status fit

Poor — availability codes (busy/free) are semantically wrong for medication workflow states

Excellent — workflow state codes match exactly

Patient search

2 queries: Schedule→Slot

1 query: Task?patient={}

Order linkage

Extension

Native (basedOn)

Extensions required

3

2

Recommendation

Task is the stronger technical fit due to:

  1. Status codes are semantically correct (workflow states, not availability)

  2. Direct patient search in one query — critical for date-range slot queries

  3. Order and MedicationAdministration links are native fields, no extensions needed

Slot is a valid alternative if the team prioritises semantic naming and the Schedule→Slot structural purity — but requires misrepresenting status semantics or carrying a custom status extension that overrides the standard field.

This is an open decision for the team to align on before Phase 5 implementation begins.


5. FHIR Extensions Required

Only 4 IPD-specific fields have no FHIR R4 standard equivalent. All follow the existing fhir2 convention (http://fhir.openmrs.org/ext/...):

Extension URL

Resource

Field

Extension URL

Resource

Field

http://fhir.openmrs.org/ext/ipd/task/variable-dosage-sequence

Task

variableDosageSequence

http://fhir.openmrs.org/ext/ipd/note/previous-note-id

MedicationAdministration.note[]

previousNote (amendment chain)

http://fhir.openmrs.org/ext/ipd/note/amendment-reason

MedicationAdministration.note[]

statusReason on note

http://fhir.openmrs.org/ext/ipd/schedule/visit-reference

Schedule

visit (Encounter not valid in Schedule.actor in R4)

If Slot is chosen over Task: replace the Task extension with http://fhir.openmrs.org/ext/ipd/slot/based-on, http://fhir.openmrs.org/ext/ipd/slot/medication-administration, and http://fhir.openmrs.org/ext/ipd/slot/workflow-status.


6. DB Model Assessment

No DB migrations required for the FHIR layer. All data is accessible via existing JPA/ORM traversal:

Table

Module

FHIR Resource

Table

Module

FHIR Resource

ipd_schedule

ipd

Schedule

ipd_slot

ipd

Task (or Slot)

ipd_reference

ipd

Patient reference (indirect via target_uuid)

care_team

ipd

CareTeam

care_team_participant

ipd

CareTeam.participant[]

medication_administration

medication-administration

MedicationAdministration

medication_administration_note

medication-administration

MedicationAdministration.note[]

medication_administration_performer

medication-administration

MedicationAdministration.performer[]

Pre-existing bug fix required: care_team_participant has no role column despite the REST API accepting/returning role. A single liquibase changeset (role_id concept FK) fixes both the bug and enables CareTeam.participant[].role. Do this in Phase 1.


7. Translator Gap Analysis (validated against fhir2 codebase)

FHIR Resource

Translator in fhir2?

ResourceProvider in fhir2?

Action

FHIR Resource

Translator in fhir2?

ResourceProvider in fhir2?

Action

MedicationAdministration

✅ Yes (fhirExtension module)

✅ Yes (partial)

Extend for 2 amendment note extensions

CareTeam

❌ No

❌ No

Build translator + provider

Schedule

❌ No

❌ No

Build translator + provider

Task (for Slot)

✅ Yes — TaskTranslatorImpl in fhir2

✅ Yes — TaskFhirResourceProvider in fhir2

Wire ipd_slot → existing Task translator

Encounter (ward)

✅ Yes

✅ Yes

Add status + class search params

MedicationRequest

✅ Yes

✅ Yes

No change

Location

✅ Yes

✅ Yes

No change

Key finding: TaskTranslatorImpl and TaskFhirResourceProvider already exist in fhir2 R4. Phase 5 only needs a new ScheduleTranslator and a mapping layer from ipd_slot to the existing Task translator — not a full Task implementation from scratch.


8. fhir2 Module Validation Findings

Capability

Status

Notes

Capability

Status

Notes

FHIR version

✅ R4 (HAPI FHIR 5.7.9)

R3 also supported for backward compat

_summary=count

✅ Implemented

Via SummaryInterceptor — works globally across all resource providers

Encounter location search

✅ Supported

Confirmed in EncounterSearchParams

Encounter participant search

✅ Supported

Confirmed in EncounterSearchParams

Encounter status search

❌ Not implemented

Must be added to fhir2

Encounter class search

❌ Not implemented

Must be added to fhir2

Task ResourceProvider (R4)

✅ Exists

TaskFhirResourceProvider

Task Translator

✅ Exists

TaskTranslatorImpl — maps status, basedOn, executionPeriod, for, owner, output

CareTeam ResourceProvider

❌ Not implemented

New build required

Schedule ResourceProvider

❌ Not implemented

New build required

Extension pattern

✅ Established

Constants in FhirConstants.java, prefix: http://fhir.openmrs.org/ext/

FHIR Batch

✅ Supported

Standard HAPI FHIR capability


9. Frontend Impact Assessment

14 API call sites across 7 files. All use axios.

Controller

Call Sites

Key Files Affected

Controller

Call Sites

Key Files Affected

CareTeam

1

CareViewPatientsUtils.js

Visit Medications

1

AllMedications.jsx

MedicationAdministration

4

NursingTasksUtils.js, EmergencyTasksUtils.js, DrugChartUtils.js

Ward

4

CareViewSummary.js, CareViewPatientsUtils.js

Schedule + Slots

7

DrugChartUtils.js, NursingTasksUtils.js, CareViewSummary.js, TreatmentsUtils.js, DrugChartSliderUtils.js

Nature of change: URL swap + request body remap + response parsing rewrite. Current responses are flat custom DTOs; FHIR returns Bundle resources. Every component consuming slot/schedule data (DrugChart, NursingTasks, CareViewSummary, Treatments) needs response-parsing updates.


10. Migration Sequencing

Phase

Scope

Backend Effort

Frontend Effort

Dependency

Phase

Scope

Backend Effort

Frontend Effort

Dependency

1

CareTeam

S — 1 new translator + provider

S — 1 call site

Fix role column (liquibase)

2

MedicationAdministration

S — wiring + 2 extensions

M — 4 call sites, response parsing

—

3

Visit Medications

S — no new translators

S — 1 call site, split into 2 queries

BAH-5110

4

Ward

M — add status+class to fhir2 Encounter

M — 4 call sites, Bundle parsing

fhir2 Encounter search params

5

Schedule + Slots

XL — ScheduleTranslator + Slot→Task wiring

XL — 7 call sites, 4 feature areas

Phases 1–4 + Slot vs Task decision

Old REST controllers stay alive in parallel during transition — migrate one phase at a time safely.


11. Prerequisites Before Starting

#

Prerequisite

Status

#

Prerequisite

Status

1

_summary=count on Encounter

✅ Already works via SummaryInterceptor

2

Fix care_team_participant.role column (liquibase changeset)

⬜ 1-pointer, do in Phase 1

3

Extension URL naming convention

✅ Pattern established in FhirConstants.java

4

Add status + class search params to Encounter in fhir2

⬜ Required before Phase 4

5

Align on Slot vs Task for medication slots

⬜ Required before Phase 5


12. GO Decision

Recommended: GO on Phases 1–4.

  • Phases 1–3 can be completed in a single sprint as confidence builders — low risk, high learning value

  • Phase 5 (Schedule+Slots) warrants its own planning, pending the Slot vs Task decision

  • No DB migrations required for the FHIR layer

  • All endpoints map to standard FHIR R4 — no custom operations needed

  • Existing fhir2 infrastructure (TaskTranslator, MedicationAdministrationTranslator, extension pattern) significantly reduces build effort

The Bahmni documentation is licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)