Skip to main content

FHIR

HL7 FHIR (Fast Healthcare Interoperability Resources) R4 support is provided through the ballerinax/health.fhir.r4 module (v6.3.0). It includes typed resource models, serialization to JSON/XML, bundle creation, reference handling, search parameter management, and XSD validation for healthcare integration.

Module

ballerinax/health.fhir.r4

Usage

Create a FHIR resource

import ballerinax/health.fhir.r4;

r4:Patient patient = {
resourceType: "Patient",
id: "patient-001",
name: [{family: "Smith", given: ["Jane"]}],
gender: "female",
birthDate: "1990-05-15",
address: [{
use: "home",
city: "Springfield",
state: "IL"
}]
};

Serialize to JSON and XML

import ballerinax/health.fhir.r4;

r4:Patient patient = {
resourceType: "Patient",
id: "patient-001",
name: [{family: "Smith", given: ["Jane"]}],
gender: "female",
birthDate: "1990-05-15"
};

// Serialize to JSON
json patientJson = check r4:executeResourceJsonSerializer(patient);

// Serialize to XML
xml patientXml = check r4:executeResourceXMLSerializer(patient);

Create a FHIR bundle

import ballerinax/health.fhir.r4;

r4:Patient patient1 = {
resourceType: "Patient",
id: "p1",
name: [{family: "Smith", given: ["Jane"]}],
gender: "female",
birthDate: "1990-05-15"
};

r4:Patient patient2 = {
resourceType: "Patient",
id: "p2",
name: [{family: "Doe", given: ["John"]}],
gender: "male",
birthDate: "1985-03-20"
};

r4:Bundle bundle = r4:createFhirBundle(r4:BUNDLE_TYPE_SEARCHSET, [patient1, patient2]);

Create resource references

import ballerinax/health.fhir.r4;

// Relative reference
r4:Reference ref = check r4:createRelativeFhirReference(r4:Patient, "Patient/patient-001");

// Absolute reference
r4:Reference absRef = check r4:createAbsoluteFhirReference(
r4:Patient,
"https://fhir.example.com/Patient/patient-001"
);

Functions

FunctionDescription
executeResourceJsonSerializerSerialize any FHIR resource to JSON.
executeResourceXMLSerializerSerialize any FHIR resource to XML.
createFhirBundleCreate a FHIR Bundle from an array of resources.
createRelativeFhirReferenceCreate a relative resource reference.
createAbsoluteFhirReferenceCreate an absolute resource reference.
createContainedFhirReferenceCreate a contained resource reference.
errorToOperationOutcomeConvert a FHIR error to an OperationOutcome resource.

Core resource types

TypeDescription
PatientPatient demographic and administrative information.
BundleContainer for a collection of resources.
OperationOutcomeInformation about the outcome of an operation.
CapabilityStatementServer capability declaration.
CodeSystemCode system definition.
ValueSetValue set definition.
ConceptMapConcept mapping between code systems.
ParametersOperation parameters.

Common data types

TypeFieldsDescription
HumanNameuse, family, given, prefix, suffix, text, periodPerson name with components.
Addressuse, type, line, city, state, postalCode, country, periodPostal or physical address.
ContactPointsystem, value, use, rank, periodPhone, email, fax, or URL.
Identifieruse, type, system, value, period, assignerBusiness identifier.
CodeableConceptcoding, textCoded value with optional text.
Codingsystem, version, code, display, userSelectedCode from a terminology system.
Referencereference, type, identifier, displayReference to another resource.
Periodstart, endTime range with start and end.
Quantityvalue, comparator, unit, system, codeMeasured amount with unit.

Bundle types

ConstantDescription
BUNDLE_TYPE_DOCUMENTClinical document.
BUNDLE_TYPE_MESSAGEMessage for event notification.
BUNDLE_TYPE_TRANSACTIONTransaction request.
BUNDLE_TYPE_BATCHBatch of independent requests.
BUNDLE_TYPE_SEARCHSETSearch results.
BUNDLE_TYPE_COLLECTIONGeneral collection.
BUNDLE_TYPE_HISTORYVersion history.