Module health.fhir.r4.uscore501

ballerinax/health.fhir.r4.uscore501 Ballerina library

1.0.3
FHIR R4 US Core Implementation Guide - 5.0.1 - STU5 Release US

Sample Usage

This section focuses on samples depicting how to use this package to implement FHIR related integrations

Prerequisites

  1. Install Ballerina 2201.1.2 (Swan Lake Update 1) or later

1. Parse JSON FHIR resource to FHIR resource model

Sample below is using the Patient resource in health.fhir.r4.uscore501 package.

Copy
import ballerinax/health.fhir.r4.uscore501;
import ballerinax/health.fhir.r4;

function parseSamplePatient() returns uscore501:USCorePatientProfile {
    json patientPayload = {
        "resourceType": "Patient",
        "id": "1",
        "meta": {
            "profile": [
                "http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
            ]
        },
        "active":true,
        "name":[
            {
                "use":"official",
                "family":"Chalmers",
                "given":[
                    "Peter",
                    "James"
                ]
            }
        ],
        "gender":"male",
        "birthDate":"1974-12-25",
        "managingOrganization":{
            "reference":"Organization/1"
        }
    };

    do {
        anydata parsedResult = check r4:parse(patientPayload, uscore501:USCorePatientProfile);
        uscore501:USCorePatientProfile patientModel = check parsedResult.ensureType();
        log:printInfo("string `Patient name : ${patientModel.name.toString()}`);
        return patientModel;
    } on fail error parseError {
    	log:printError(string `Error occurred while parsing : ${parseError.message()}`, parseError);
    }
}

2. Creating FHIR Resource models and serializing to JSON wire formats

Copy
import ballerinax/health.fhir.r4.uscore501;
import ballerinax/health.fhir.r4;

function createSamplePatient() returns json {
    uscore501:USCorePatientProfile patient = {
        meta: {
            lastUpdated: time:utcToString(time:utcNow()),
            profile: [uscore501:PROFILE_BASE_USCOREPATIENTPROFILE]
        },
        active: true,
        name: [{
            family: "Doe",
            given: ["Jhon"],
            use: uscore501:official,
            prefix: ["Mr"]
        }],
        address: [{
            line: ["652 S. Lantern Dr."],
            city: "New York",
            country: "United States",
            postalCode: "10022",
            'type: uscore501:physical,
            use: uscore501:home
        }]
    };
    r4:FHIRResourceEntity fhirEntity = new(patient);
    // Serialize FHIR resource record to Json payload
    json|r4:FHIRSerializerError jsonResult = fhirEntity.toJson();
    if jsonResult is json {
        log:printInfo(string `Patient resource JSON payload : ${jsonResult.toString()}`);
        return jsonResult;
    } else {
        log:printError(string `Error occurred while serializing to JSON payload : ${jsonResult.message()}`, jsonResult);
    }
}

Import

import ballerinax/health.fhir.r4.uscore501;Copy

Metadata

Released date: about 1 year ago

Version: 1.0.3


Compatibility

Platform: any

Ballerina version: 2201.5.0

GraalVM compatible: Yes


Pull count

Total: 47

Current verison: 7


Weekly downloads


Source repository


Keywords

Healthcare

FHIR

R4

IG

USCore


Contributors

Other versions

See more...