Skip to content

feat(fhir): add FHIR medication interface implementation plan script#215

Merged
halcwb merged 8 commits intomasterfrom
copilot/add-fhir-medication-interface
Mar 24, 2026
Merged

feat(fhir): add FHIR medication interface implementation plan script#215
halcwb merged 8 commits intomasterfrom
copilot/add-fhir-medication-interface

Conversation

Copy link
Contributor

Copilot AI commented Mar 24, 2026

Scripts-only implementation plan for the FHIR-based medication interface described in docs/mdr/interface/genpres_interface_specification.md, demonstrating how FHIR R4 scenarios map to GenPRES orders via the OrderContext lookup mechanism and vice versa.

Author checklist

  • The described changes have already been described in an issue: #
  • This PR documents the plan in a markdown file in ./docs/implementation-plans/.
  • I have used the implementation plan template.
  • The plan has enough detail: any suggestions that a reveiewer adds to a PR that implements the plan are likely to be relatively quick to implement (intentionally vague to leave room for flexibility!).

Reviewer checklist

  • The chosen approach is a good choice.
  • The sequence of steps is complete and sensible.
  • I have documented resources that may help with implementation.

What's in the scripts

src/Informedica.FHIR.Lib/Scripts/load.fsx — standard bootstrap for FSI; references GenUNITS, GenCORE, GenSOLVER, GenFORM, ZIndex, GenORDER DLLs.

src/Informedica.FHIR.Lib/Scripts/ImplementationPlan.fsx — walks all 8 steps of the issue, covering spec scenarios 6.1–6.11:

Step What it does
1 Typed F# records (FhirScenario, ScenarioProduct, AdministrationSchema) for all spec scenarios 6.1–6.11, including reconstitution (6.8, 6.9), TPN (6.10), and enteral feeding (6.11). AdministrationSchema uses RateFormUnit (numerator) and RateTimeUnit (denominator). Each FhirScenario contains only what a FHIR resource directly provides: patient context, indication, route, shape, dose type, component orderable quantities, dose rate, and schedule frequency.
2 ZIndex.GenericProduct.get [] filtered by generic name; notes that spec GPK codes are placeholders. Concentrations and dose limits are derived from ZIndex results, not hardcoded.
3 ValueUnit construction for the four directly-available FHIR data categories: component orderable quantities, orderable dose quantity, orderable dose rate, and schedule frequency.
4 Reconstructs an OrderScenario from FHIR context via OrderContext: builds a Patient from scenario patient data, sets Filter with indication/route/shape/dose type, calls OrderContext.create + getScenarios. Concentrations and dose limits come from ZIndex/GenFORM lookup — not hardcoded.
5–6 Runs Order.solveMinMax on the retrieved scenario; prints order table.
7 Pass/fail summary across all 11 scenarios.
8 Full FHIR R4 bidirectional translation investigation with official documentation references, F# types mirroring the FHIR R4 data model, and concrete translation function sketches (fromFhirMedicationRequest and toFhirMedicationRequest).

Informedica.FHIR.Lib.fsproj updated to surface both scripts as <None> items.

Key design principle

A FHIR scenario provides only four categories of data that feed directly into the order:

  1. Component Orderable Quantities — from the FHIR products block
  2. Orderable Dose Quantity — from the FHIR administration block
  3. Orderable Dose Rate — from the FHIR schema rate (RateFormUnit/RateTimeUnit)
  4. Schedule Frequency — from the FHIR schema pattern

Everything else (concentrations, dose limits, product structure) is derived by ZIndex/GenFORM lookup via OrderContext.getScenarios, using the filter inputs: patient data, indication, route, shape, and dose type.

FHIR R4 bidirectional translation (Step 8)

Step 8 is a full investigation of the official FHIR R4 resource structure:

  • F# types mirroring FhirMedicationRequest, FhirMedication, FhirDosage, FhirTiming, FhirTimingRepeat, FhirQuantity, FhirRatio, FhirCodeableConcept
  • FhirSystems module: G-Standard OIDs — GPK (urn:oid:2.16.840.1.113883.2.4.4.7), route thesaurus 9, form thesaurus 10, UCUM
  • RouteMapping: G-Standard route code ↔ GenPRES route name
  • PeriodUnitMapping: FHIR h/d/wk ↔ GenPRES uur/dag/week
  • inferDoseType: infers Once/OnceTimed/Discontinuous/Timed/Continuous from the FHIR timing/rate structure
  • fromFhirMedicationRequest: FHIR MedicationRequest → FhirScenario (drives OrderContext filter + getScenarios to look up ZIndex rules)
  • toFhirMedicationRequest: FhirScenario → FHIR MedicationRequest with GPK coding, G-Standard route, doseAndRate.rateRatio (using RateFormUnit/RateTimeUnit), timing.repeat, and contained Medication with ingredients
  • Round-trip demonstration for all 11 scenarios verifying that Route, DoseType, and Indication survive the round-trip

Official FHIR R4 documentation references included:

  • MedicationRequest: https://hl7.org/fhir/R4/medicationrequest.html
  • Medication: https://hl7.org/fhir/R4/medication.html
  • Dosage: https://hl7.org/fhir/R4/dosage.html
  • Timing: https://hl7.org/fhir/R4/datatypes.html#Timing
Original prompt

This section details on the original issue you should resolve

<issue_title>First implementation plan for a FHIR based medication interface</issue_title>
<issue_description>Is your feature request related to a problem? Please describe.
GenPRES needs to provide an interface to communicate medication orders.

The requirements and how an interface should work to import and export medication orders is described at: docs/mdr/interface/genpres_interface_specification.md. Specifically the document describes a number of scenarios.

The architecture document: docs/roadmap/genpres-architecture-and-timeline.md, shows where this should fit in. This should be implemented in the project stub: src/Informedica.FHIR.Lib

This should be implemented using the
There should be a script based implementation plan with the following steps:

  1. Create a src/Informedica.FHIR.Lib/Scripts/ImplementationPlan.fsx
  2. Use the provided scenarios as examples.
  3. Lookup the product information provided by the product codes in the examples
  4. Parse the quantitative variables to ValueUnits
  5. Translate each scenario to the medication string representation: src/Informedica.GenORDER.Lib/Medication.fs
  6. Try to run the scenario by the Medication.fromString as an order
  7. Print out the results.
  8. Try to translate this process to a FHIR based solution
    </issue_description>

<agent_instructions>See issue</agent_instructions>

Comments on the Issue (you are @copilot in this section)


⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

Copilot AI changed the title [WIP] Add first implementation plan for FHIR based medication interface feat(fhir): add FHIR medication interface implementation plan script Mar 24, 2026
Copilot AI requested a review from halcwb March 24, 2026 11:14
Copy link
Collaborator

@halcwb halcwb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename:

  • RateUnit1 to RateFormUnit
  • RateUnit2 to RateTimeUnit

Note: try to match names with the existing naming policy in the code base and data structures.

The current implementation assumes knowledge about dosing but that is not in the scenarios. Only the following can be provided:

  1. Component Orderable Quantities
  2. Ordererable Dose Quantity and/or
  3. Orderable Dose Rate and/or
  4. Schedule Frequency

Everything else is derived by lookup or calculation.

For the reconstruction of the OrderScenario type the following is provided:

  • Patient data
  • Indication
  • Route
  • Shape
  • Dose type

The code should reflect this.

…ve hardcoded dosing knowledge

Co-authored-by: halcwb <683631+halcwb@users.noreply.github.com>
Agent-Logs-Url: https://github.com/informedica/GenPRES/sessions/88fb1713-6692-41d3-aaa6-a4b2fd7fb287
Copy link
Contributor Author

Copilot AI commented Mar 24, 2026

Rename:

  • RateUnit1 to RateFormUnit
  • RateUnit2 to RateTimeUnit...

Done in b2ad01b.

  • Renamed RateUnit1RateFormUnit and RateUnit2RateTimeUnit throughout AdministrationSchema and all scenario definitions.
  • Restructured the script to reflect the correct data model: FhirScenario now contains only what a FHIR resource actually provides (patient data, indication, route, shape, dose type, component orderable quantities, dose rate, and schedule frequency).
  • Removed all hardcoded concentrations and dose limits from the old scenarioToMedicationText function entirely.
  • Step 4 now shows the correct approach: build a Patient from scenario patient data, set the Filter with indication/route/shape/dose type from the FHIR scenario, and call OrderContext.create + getScenarios to retrieve concentrations and dose limits from ZIndex/GenFORM by lookup.

Copilot AI requested a review from halcwb March 24, 2026 11:38
Copy link
Collaborator

@halcwb halcwb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Investigate how GenPRES can translate the FIHR data from and to a scenario and how a scenario then can be translated to a medication and order scenario and vice versa. Look at the official FHIR documentation.

…nal translation, all spec scenarios

Co-authored-by: halcwb <683631+halcwb@users.noreply.github.com>
Agent-Logs-Url: https://github.com/informedica/GenPRES/sessions/88a3340d-6a54-45d9-b098-a445c37c0329
Copy link
Contributor Author

Copilot AI commented Mar 24, 2026

Investigate how GenPRES can translate the FIHR data from and to a scenario and how a scenario then can be translated to a medication and order scenario and vice versa. Look at the official FHIR docume...

Done in 1665770. Step 8 is now a full FHIR R4 investigation:

F# types mirroring the official FHIR R4 resources (with documentation links):

  • FhirMedicationRequest, FhirMedication, FhirDosage, FhirDosageAndRate, FhirTiming/FhirTimingRepeat, FhirQuantity, FhirRatio, FhirCodeableConcept, FhirCoding, FhirMedicationIngredient

G-Standard/FHIR constants and mappings:

  • FhirSystems module: GPK OID urn:oid:2.16.840.1.113883.2.4.4.7, route thesaurus 9, form thesaurus 10, UCUM
  • RouteMapping: G-Standard route code ↔ GenPRES route name (INTRAVENEUS, RECTAAL, ORAAL, …)
  • PeriodUnitMapping: FHIR h/d/wk ↔ GenPRES uur/dag/week

Bidirectional translation:

  • inferDoseType: infers Once/OnceTimed/Discontinuous/Timed/Continuous from the FHIR timing/rate structure
  • fromFhirMedicationRequest: FHIR MedicationRequest → FhirScenario (which then drives OrderContext filter + getScenarios to look up ZIndex rules)
  • toFhirMedicationRequest: FhirScenario → FHIR MedicationRequest with GPK coding, G-Standard route, doseAndRate.rateRatio (using RateFormUnit/RateTimeUnit), and timing.repeat

All 11 spec scenarios (6.1–6.11 including reconstitution, TPN, enteral feeding) are now defined and run through the round-trip demonstration.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • build.fhir.org
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)
  • hl7.org
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)
  • www.hl7.org
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from halcwb March 24, 2026 11:51
@halcwb halcwb marked this pull request as ready for review March 24, 2026 17:08
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 24, 2026

Greptile Summary

This PR adds a script-only implementation plan (ImplementationPlan.fsx + load.fsx) for the FHIR-based medication interface described in the GenPRES specification, together with a minimal .fsproj update to surface the scripts in the IDE.

  • The .fsproj change is correct and non-invasive: the two scripts are registered as <None> items, so they are included in the solution explorer but never compiled into the production assembly.
  • Per project policy, the .fsx script files are excluded from this code review.
  • No production source files (Library.fs or any .fs file) were modified.

Confidence Score: 5/5

  • Safe to merge — only non-compiled script files and a trivial .fsproj update are included.
  • The sole production file change is a two-line addition of <None> items to the .fsproj, which has no effect on compilation or runtime behaviour. The .fsx scripts are excluded from review per project policy and do not affect the built assembly.
  • No files require special attention.

Important Files Changed

Filename Overview
src/Informedica.FHIR.Lib/Informedica.FHIR.Lib.fsproj Adds <None Include="..."> entries for the two new .fsx script files so they appear in the IDE solution explorer; no production compilation is affected.
src/Informedica.FHIR.Lib/Scripts/load.fsx Standard FSI bootstrap script; excluded from code review per project policy on .fsx files.
src/Informedica.FHIR.Lib/Scripts/ImplementationPlan.fsx 1794-line script-based implementation plan for FHIR medication interface; excluded from code review per project policy on .fsx files.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[FHIR MedicationRequest\nR4 Resource] -->|fromFhirMedicationRequest| B[FhirScenario\nPatient / Route / Shape / DoseType\nProducts / AdminQty / Schema]
    B -->|Build Patient| C[Patient record\nweight / height / age / gender]
    B -->|Build Filter| D[Filter\nIndication / Route / Shape / DoseType]
    C --> E[OrderContext.create\n+ getScenarios]
    D --> E
    E -->|ZIndex / GenFORM lookup| F[OrderScenario\nConcentrations & Dose Limits]
    B -->|Apply orderable quantities\n& schedule from FHIR| F
    F -->|Order.solveMinMax| G[Solved Order]
    G -->|toFhirMedicationRequest| H[FHIR MedicationRequest\nR4 Resource]
    H -->|Round-trip check| A
Loading

Reviews (1): Last reviewed commit: "Merge branch 'master' into copilot/add-f..." | Re-trigger Greptile

@halcwb halcwb merged commit 1ac9191 into master Mar 24, 2026
4 checks passed
@halcwb halcwb deleted the copilot/add-fhir-medication-interface branch March 24, 2026 17:43
github-actions bot pushed a commit to halcwb/GenPRES that referenced this pull request Mar 24, 2026
- Add FhirExpectoTests.fsx: Expecto test scaffolding for the FHIR bidirectional
  translation layer — 6 test suites covering FhirSystems constants, RouteMapping
  round-trips, PeriodUnitMapping round-trips, inferDoseType logic, and
  toFhirMedicationRequest / fromFhirMedicationRequest round-trips for all 11
  scenarios defined in ImplementationPlan.fsx
- Update CHANGELOG [Unreleased] with 24 March 2026 commits: FHIR implementation
  plan script (PR informedica#215), UI interactions improvements (PR informedica#216), fix select-all
  in treatment plan (PR informedica#217), Fantomas exclusions fix (PR informedica#218, informedica#219)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

First implementation plan for a FHIR based medication interface

2 participants