Module health.fhir.r4.aubase421

ballerinax/health.fhir.r4.aubase421 Ballerina library

1.1.0
FHIR R4 AUBase module - Version 4.2.1

Sample Usage

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

Prerequisites

  1. Install Ballerina 2201.6.0 or later

1. Parse JSON FHIR resource to FHIR resource model

Sample below is using the AUBasePatient resource in health.fhir.r4.aubase421 package.

Copy
import ballerina/log;
import ballerinax/health.fhir.r4.aubase421;
import ballerinax/health.fhir.r4.parser;

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

    do {
        anydata parsedResult = check parser:parse(patientPayload, aubase421:AUBasePatient);
        aubase421:AUBasePatient patientModel = check parsedResult.ensureType();
        log:printInfo(string `Patient name : ${patientModel.name.toString()}`);
    } 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 ballerina/log;
import ballerina/time;
import ballerinax/health.fhir.r4;
import ballerinax/health.fhir.r4.aubase421;

public function main() {
    aubase421:AUBasePatient patient = {
        meta: {
            lastUpdated: time:utcToString(time:utcNow()),
            profile: [aubase421:PROFILE_BASE_AUBASEPATIENT]
        },
        active: true,
        name: [{
            family: "Doe",
            given: ["Jhon"],
            use: r4:official,
            prefix: ["Mr"]
        }],
        address: [{
            line: ["652 S. Lantern Dr."],
            city: "New York",
            country: "United States",
            postalCode: "10022",
            'type: r4:physical,
            use: r4: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.toJsonString()}`);
    } else {
        log:printError(string `Error occurred while serializing to JSON payload : ${jsonResult.message()}`, jsonResult);
    }
}

Import

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

Metadata

Released date: 14 days ago

Version: 1.1.0


Compatibility

Platform: any

Ballerina version: 2201.10.2

GraalVM compatible: Yes


Pull count

Total: 417

Current verison: 15


Weekly downloads



Keywords

Healthcare

FHIR

R4

aubase421


Contributors

Other versions

1.1.0

1.0.0