Documentation / Exploitation / Guides pratiques / Connect a FHIR warehouse

Connect a FHIR warehouse

Wire the patient and prescription ports to a real FHIR R4 warehouse using the bundled @posos/fhir plugin, instead of an in-memory or demo adapter. This assumes you already have an instance manifest — see Your first instance if you don't, and Configure ports and adapters for how port/adapter selection works in general.

Before you start

  • A reachable FHIR R4 server. @posos/fhir is tested against samply/blaze and against Synthea-generated bundles loaded into it (external-plugins/fhir/plugin.yaml, external-plugins/fhir/adapters/patient.ts). Other FHIR R4 servers may work but are untested.
  • @posos/fhir present in your plugin set. It is a core plugin shipped in the API image (external-plugins/fhir) and is loaded like any other plugin (a PLUGINS_PATH root); nothing below is registry-specific.

1. Stand up a test warehouse (optional)

If you don't have a FHIR store yet, run Blaze locally and load Synthea data:

docker run -d --name blaze -p 8090:8080 -e STORAGE=in-memory samply/blaze:latest
node apps/api/scripts/load-synthea.mjs   # loads Synthea bundles into Blaze

The docker-compose.yml stack profile also runs a persistent Blaze (samply/blaze:1.10.1, RocksDB storage) on the same port mapping (8090:8080); use that instead for anything longer-lived than a one-off test.

2. Point the ports at the warehouse

In your instance manifest, set the patient and prescription ports to the fhir adapter and give it a baseUrl (the plugin's two adapters share the same shape of config — see external-plugins/fhir/plugin.yaml):

ports:
  patient:      { adapter: fhir, config: { baseUrl: http://localhost:8090/fhir } }
  prescription: { adapter: fhir, config: { baseUrl: http://localhost:8090/fhir } }

instance.example.yaml at the repo root wires both ports this way against the local Blaze from step 1. There is no separate FHIR configuration surface beyond these two port entries — everything the adapter needs comes from config.baseUrl.

Note that FHIR has no single "prescription" resource: the prescription port adapter treats the id you pass it as a patient id and aggregates that patient's MedicationRequest resources (external-plugins/fhir/adapters/prescription.ts). For the full resource mapping behind both ports (Patient, MedicationRequest, Condition, AllergyIntolerance, Observation, Communication, Task…), see FHIR resource mapping (apps/ehr-lab/docs/resources/reference/fhir-mapping.md) and the port contracts reference.

3. Fall back to an environment variable instead (optional)

If you'd rather not put a URL in the manifest (e.g. it differs per environment), omit config.baseUrl and set FHIR_BASE_URL instead — the adapter resolves config.baseUrl ?? process.env.FHIR_BASE_URL at call time (external-plugins/fhir/adapters/client.ts):

ports:
  patient:      { adapter: fhir }
  prescription: { adapter: fhir }
export FHIR_BASE_URL=http://localhost:8090/fhir

config.baseUrl always wins when both are set. If neither is set, the adapter throws ([fhir] baseUrl manquant) the first time a workflow actually calls the port — not at startup — naming both config.baseUrl and FHIR_BASE_URL in the error. See the environment variables reference for where FHIR_BASE_URL fits among the platform's other env-driven settings.

4. Declare the plugin's own dependencies

@posos/fhir's manifest lists dependsOn: { "@posos/clinical": "*", "@posos/common": "*" } (external-plugins/fhir/plugin.yaml): its default event bindings project raw FHIR resources onto domain events owned by those two plugins (e.g. fhir-creatinineBioResultReceived, fhir-communication-receivedCommunicationReceived). If you're assembling your instance from plugins pulled off a registry rather than using the bundled set as-is, make sure @posos/clinical and @posos/common are declared alongside @posos/fhir — see Declare and install plugins and Set up a plugin registry.

Connecting the warehouse as an event source (polling FHIR for new resources, e.g. new lab results) is a separate concern from the port wiring above — see Connect an event source.

5. Verify the connection

  • Smoke-test the store directly: curl http://localhost:8090/fhir/Patient?_count=1 should return a Bundle.

  • Run the adapter's own integration check, which reads and writes through the real patient port against Blaze:

    FHIR_BASE_URL=http://localhost:8090/fhir pnpm run test:fhir
    

    This requires at least one adult Patient already loaded (the Synthea bundles from step 1 provide this) — see apps/api/tests/test-fhir.ts.

  • Boot the endpoint against the manifest that wires FHIR (INSTANCE_CONFIG=instance.example.yaml pnpm run endpoint:fhir, or pnpm run dev:fhir for the full endpoint+proxy+UI stack) and confirm a workflow can read a patient snapshot end to end.

75 documents7 sectionssource : /docs · généré au build