Skip to main content
fi-fhir docs

Overview

FHIR Output

fi-fhir generates FHIR R4 resources that conform to US Core profiles. This guide covers the mapping from canonical events to FHIR resources.

Overview

When events flow through a workflow with a FHIR action, fi-fhir:

  1. Maps canonical event fields to FHIR resource properties
  2. Applies US Core profile requirements
  3. Validates the generated resources
  4. Sends to the configured FHIR server

Supported Resources

fi-fhir maps to 24+ FHIR R4 resources:

Event TypeFHIR ResourcesProfile
patient_admitPatient, EncounterUS Core
patient_dischargeEncounterUS Core
patient_updatePatientUS Core
lab_resultObservation, DiagnosticReportUS Core Laboratory
vital_signObservationUS Core Vital Signs
conditionConditionUS Core
procedureProcedureUS Core
immunizationImmunizationUS Core
medication_requestMedicationRequestUS Core
allergyAllergyIntoleranceUS Core
claim_submittedClaimDa Vinci PAS
claim_adjudicatedExplanationOfBenefitPDex
eligibility_responseCoverageEligibilityResponse-
documentDocumentReferenceUS Core

Patient Resource

Maps from patient events (patient_admit, patient_update).

Field Mapping

Event FieldFHIR PathNotes
patient.mrnidentifier[0].valueMRN identifier
patient.ssnidentifier[1].valueSSN (if not redacted)
patient.name.familyname[0].familyFamily name
patient.name.givenname[0].givenGiven names array
patient.birthDatebirthDateFHIR date format
patient.gendergendermale, female, other, unknown
patient.addressaddress[0]Full address structure
patient.phonetelecom[0]Phone contact point
patient.emailtelecom[1]Email contact point
patient.raceextensionUS Core Race extension
patient.ethnicityextensionUS Core Ethnicity extension

Example Output

{
  "resourceType": "Patient",
  "id": "patient-mrn12345",
  "meta": {
    "profile": [
      "http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
    ]
  },
  "identifier": [
    {
      "type": {
        "coding": [
          {
            "system": "http://terminology.hl7.org/CodeSystem/v2-0203",
            "code": "MR"
          }
        ]
      },
      "system": "urn:oid:1.2.3.4.5.6",
      "value": "MRN12345"
    }
  ],
  "name": [
    {
      "use": "official",
      "family": "Smith",
      "given": ["John", "A"]
    }
  ],
  "gender": "male",
  "birthDate": "1980-01-15",
  "address": [
    {
      "use": "home",
      "line": ["123 Main St"],
      "city": "Springfield",
      "state": "IL",
      "postalCode": "62701"
    }
  ]
}

Encounter Resource

Maps from admit/discharge/transfer events.

Field Mapping

Event FieldFHIR PathNotes
encounter.identifieridentifier[0].valueVisit number
encounter.classclassinpatient, outpatient, emergency
encounter.typetypeEncounter type coding
encounter.statusstatusin-progress, finished, etc.
encounter.period.startperiod.startAdmit datetime
encounter.period.endperiod.endDischarge datetime
encounter.locationlocation[0].locationLocation reference
encounter.providerparticipantAttending physician

Encounter Class Mapping

Event ClassFHIR Class Code
inpatientIMP
outpatientAMB
emergencyEMER
observationOBSENC

Observation Resource (Laboratory)

Maps from lab_result events.

Field Mapping

Event FieldFHIR PathNotes
observation.codecodeLOINC coding
observation.valuevalue[x]Quantity, string, or CodeableConcept
observation.unitvalueQuantity.unitUCUM unit
observation.referenceRangereferenceRangeNormal range
observation.interpretationinterpretationH, L, A, N, etc.
observation.statusstatusfinal, preliminary, etc.
observation.effectiveDateTimeeffectiveDateTimeSpecimen collection time
observation.issuedissuedResult available time

Example Output

{
  "resourceType": "Observation",
  "meta": {
    "profile": [
      "http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-lab"
    ]
  },
  "status": "final",
  "category": [
    {
      "coding": [
        {
          "system": "http://terminology.hl7.org/CodeSystem/observation-category",
          "code": "laboratory"
        }
      ]
    }
  ],
  "code": {
    "coding": [
      {
        "system": "http://loinc.org",
        "code": "2345-7",
        "display": "Glucose [Mass/volume] in Serum or Plasma"
      }
    ]
  },
  "subject": {
    "reference": "Patient/patient-mrn12345"
  },
  "effectiveDateTime": "2024-01-15T10:30:00Z",
  "valueQuantity": {
    "value": 95,
    "unit": "mg/dL",
    "system": "http://unitsofmeasure.org",
    "code": "mg/dL"
  },
  "interpretation": [
    {
      "coding": [
        {
          "system": "http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation",
          "code": "N",
          "display": "Normal"
        }
      ]
    }
  ]
}

Observation Resource (Vital Signs)

Maps from vital_sign events to specific US Core Vital Signs profiles.

Supported Vital Signs

Vital SignLOINC CodeUS Core Profile
Blood Pressure85354-9us-core-blood-pressure
BMI39156-5us-core-bmi
Body Height8302-2us-core-body-height
Body Weight29463-7us-core-body-weight
Body Temperature8310-5us-core-body-temperature
Heart Rate8867-4us-core-heart-rate
Respiratory Rate9279-1us-core-respiratory-rate
Pulse Oximetry2708-6us-core-pulse-oximetry

DiagnosticReport Resource

Groups related observations for lab panels.

Field Mapping

Event FieldFHIR PathNotes
diagnosticReport.codecodePanel/test code
diagnosticReport.statusstatusfinal, preliminary
diagnosticReport.categorycategoryLAB category
diagnosticReport.effectiveDateTimeeffectiveDateTimeCollection time
diagnosticReport.resultsresultReferences to Observations

Claim Resource

Maps from claim_submitted events (EDI 837P/837I).

Field Mapping

Event FieldFHIR PathNotes
claim.identifieridentifierClaim control number
claim.statusstatusactive, draft
claim.typetypeinstitutional, professional
claim.patientpatientPatient reference
claim.providerproviderBilling provider
claim.diagnosisdiagnosisICD-10 codes
claim.procedureprocedureCPT/HCPCS codes
claim.totaltotalClaim total amount

FHIR Bundles

Multiple resources are grouped into bundles:

Transaction Bundle

{
  "resourceType": "Bundle",
  "type": "transaction",
  "entry": [
    {
      "fullUrl": "urn:uuid:patient-1",
      "resource": {
        /* Patient */
      },
      "request": {
        "method": "PUT",
        "url": "Patient/mrn12345"
      }
    },
    {
      "fullUrl": "urn:uuid:encounter-1",
      "resource": {
        /* Encounter */
      },
      "request": {
        "method": "POST",
        "url": "Encounter"
      }
    }
  ]
}

Batch Bundle

Same structure, but type: "batch" for independent operations.

Validation

Enable Validation

actions:
  - type: fhir
    endpoint: https://fhir.example.com
    validate_fhir: true # Validate before sending

Validation Levels

  • Structural: JSON schema validation
  • Profile: US Core profile conformance
  • Business Rules: Required fields, code systems

CLI Validation

# Validate a FHIR resource
fi-fhir fhir validate patient.json

# Validate a bundle
fi-fhir fhir validate bundle.json --profile us-core

Authentication

OAuth2 Client Credentials

actions:
  - type: fhir
    endpoint: https://fhir.example.com/r4
    auth:
      type: oauth2
      tokenUrl: https://auth.example.com/token
      clientId: ${FHIR_CLIENT_ID}
      clientSecret: ${FHIR_CLIENT_SECRET}
      scopes:
        - system/Patient.read
        - system/Patient.write
        - system/Encounter.write

Token Caching

OAuth2 tokens are cached and automatically refreshed before expiration.

401 Handling

If a 401 is received:

  1. Token is refreshed
  2. Request is retried
  3. If still failing, error is returned

Batch Operations

For high-volume scenarios:

actions:
  - type: fhir
    endpoint: https://fhir.example.com/r4
    batch:
      enabled: true
      size: 100 # Bundle size
      timeout: 30s

US Core Profile Compliance

All generated resources include:

  1. Profile declaration in meta.profile
  2. Must-Support elements populated when available
  3. Required extensions (race, ethnicity for Patient)
  4. Standard terminologies (LOINC, SNOMED, ICD-10)

Checking Compliance

# Generate FHIR from event
fi-fhir parse sample.hl7 | fi-fhir fhir generate --profile us-core

# Validate against US Core
fi-fhir fhir validate output.json --profile us-core

Custom Mappings

Override default mappings in Source Profile:

fhirMapping:
  targetVersion: R4
  bundleType: transaction

  resourceMappings:
    - event_type: patient_admit
      resources: [Patient, Encounter]
      customFields:
        - source: patient.custom_field
          target: Patient.extension
          extension_url: http://example.com/fhir/extension

See Also