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 |
|---|---|---|---|
|
| 4 | Ward patient listing, search, summary counts |
|
| 5 | Medication schedule create/edit/query |
|
| 1 | Care team participant management |
|
| 5 | Scheduled/adhoc administration, amendment notes, acknowledgement |
|
| 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 |
|---|---|---|
|
| Standard |
|
| Standard |
|
| Standard |
|
| 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 |
|---|---|---|
|
| Standard |
|
| Standard |
|
| Standard |
|
| Standard |
|
| 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 |
|---|---|
|
|
|
|
|
|
|
|
|
|
Current Endpoint | FHIR R4 Equivalent |
|---|---|
|
|
3.4 IPDMedicationAdministrationController → MedicationAdministration
Translator already exists in openmrs-module-medicationadministration. All core fields map directly.
Current Endpoint | FHIR R4 Equivalent | Type |
|---|---|---|
| Batch | Standard |
|
| Standard |
|
| Standard |
|
| Standard |
|
| 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 |
|---|---|
|
|
|
|
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 |
|
|
|---|---|---|
Parent Schedule link | ✓ | ✗ Extension needed |
Start / end time | ✓ | ✓ |
Workflow status | ✗ Extension needed — standard values are | ✓ |
Order (MedicationRequest) link | ✗ Extension needed | ✓ |
MedicationAdministration link | ✗ Extension needed | ✓ |
Service type | ✓ | ✓ |
Comments | ✓ | ✓ |
| ✗ Extension | ✗ Extension |
Direct patient search | ✗ No | ✓ |
Extensions required | 3 | 2 |
Trade-offs
|
|
|
|---|---|---|
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 ( | Excellent — workflow state codes match exactly |
Patient search | 2 queries: Schedule→Slot | 1 query: |
Order linkage | Extension | Native ( |
Extensions required | 3 | 2 |
Recommendation
Task is the stronger technical fit due to:
Status codes are semantically correct (workflow states, not availability)
Direct patient search in one query — critical for date-range slot queries
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 |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|---|---|---|
| ipd |
|
| ipd |
|
| ipd | Patient reference (indirect via |
| ipd |
|
| ipd |
|
| medication-administration |
|
| medication-administration |
|
| medication-administration |
|
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 |
|---|---|---|---|
| ✅ Yes (fhirExtension module) | ✅ Yes (partial) | Extend for 2 amendment note extensions |
| ❌ No | ❌ No | Build translator + provider |
| ❌ No | ❌ No | Build translator + provider |
| ✅ Yes — | ✅ Yes — | Wire |
| ✅ Yes | ✅ Yes | Add |
| ✅ Yes | ✅ Yes | No change |
| ✅ 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 |
|---|---|---|
FHIR version | ✅ R4 (HAPI FHIR 5.7.9) | R3 also supported for backward compat |
| ✅ Implemented | Via |
Encounter | ✅ Supported | Confirmed in |
Encounter | ✅ Supported | Confirmed in |
Encounter | ❌ Not implemented | Must be added to fhir2 |
Encounter | ❌ Not implemented | Must be added to fhir2 |
Task ResourceProvider (R4) | ✅ Exists |
|
Task Translator | ✅ Exists |
|
CareTeam ResourceProvider | ❌ Not implemented | New build required |
Schedule ResourceProvider | ❌ Not implemented | New build required |
Extension pattern | ✅ Established | Constants in |
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 |
|---|---|---|
CareTeam | 1 |
|
Visit Medications | 1 |
|
MedicationAdministration | 4 |
|
Ward | 4 |
|
Schedule + Slots | 7 |
|
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 |
|---|---|---|---|---|
1 | CareTeam | S — 1 new translator + provider | S — 1 call site | Fix |
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 | 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 |
|---|---|---|
1 |
| ✅ Already works via |
2 | Fix | ⬜ 1-pointer, do in Phase 1 |
3 | Extension URL naming convention | ✅ Pattern established in |
4 | Add | ⬜ Required before Phase 4 |
5 | Align on | ⬜ 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