ballerinax/health.clients.fhir Ballerina library

2.0.0

Overview

The connector serves as an interface for interacting with FHIR servers, allowing easy integration of FHIR data.

Usage

Import the package to a Ballerina program.

Copy
import ballerinax/health.clients.fhir;

Create the required authentication configuration. The connector can accept various client authentication configurations supported by Ballerina, such as basic authentication, token-based authentication, etc. For instance, if it is required to use the client credentials grant, the config has to be created like the following.

Copy
http:OAuth2ClientCredentialsGrantConfig ehrSystemAuthConfig = {
    tokenUrl: "<tokenUrl>",
    clientId: "<clientId>",
    clientSecret: "<clientSecret>",
    scopes: ["system/Patient.read, system/Patient.write"]
};

Initialize the connector configuration record.

Copy
fhir:FHIRConnectorConfig ehrSystemConfig = {
    baseURL: "https://test.org/fhir/r4",
    mimeType: fhir:FHIR_JSON,
    authConfig : ehrSystemAuthConfig
};

Initialize the connector.

Copy
fhir:FHIRConnector fhirConnectorObj = check new (ehrSystemConfig);

Invoke the connector operations by passing the required parameters.

Copy
fhir:FHIRResponse|fhir:FHIRError fhirResponse = fhirConnectorObj->getById("Patient", "123456");

PKJWT Support

In addition to the authentication methods supported by Ballerina, the connector also supports private key JWT authentication, which requires creating the config as following.

  • Import the health.base authentication package.

    Copy
    import ballerinax/health.base.auth;
  • Create the auth config.

    Copy
    auth:PKJWTAuthConfig ehrSystemAuthConfig = {
        keyFile: "<path_to_key_file>",
        clientId: "<clientId>",
        tokenEndpoint: "<tokenUrl>"
    };

This can be passed to the connector configuration.

Bulk Data Export Operations Support

This connector supports FHIR Bulk Data Export operations and does not require any additional configuration. However, if the generated files get stored in another file server apart from the FHIR server, add the file server configurations to the connector configuration record.

  • Update the connector config.

    Copy
    fhir:FHIRConnectorConfig ehrSystemConfig = {
        baseURL: "https://test.org/fhir/r4",
        mimeType: fhir:FHIR_JSON,
        authConfig : ehrSystemAuthConfig,
        bulkFileServerConfig: {
            fileServerBaseURL: "https://storage.test.org",
            fileServerAuthConfig: fileServerAuthConfig
        }
    };

Now the exported files can be accessed from the file server using the connector.

Rewrite FHIR Server URL

This connector can rewrite/replace FHIR server URL in the response payload and headers with a custom URL.

  • Update the connector config to enable this feature.

    Copy
    fhir:FHIRConnectorConfig ehrSystemConfig = {
        baseURL: "https://test.org/fhir/r4",
        mimeType: fhir:FHIR_JSON,
        authConfig : ehrSystemAuthConfig,
        urlRewrite: true,
        replacementURL: "https://my.fhir.service/r4"
    };

Now the FHIR server URLs will get replaced with the replacement URL.

Import

import ballerinax/health.clients.fhir;Copy

Metadata

Released date: 5 months ago

Version: 2.0.0


Compatibility

Platform: any

Ballerina version: 2201.8.1

GraalVM compatible: Yes


Pull count

Total: 460

Current verison: 65


Weekly downloads


Source repository


Keywords

Healthcare

FHIR

client

R4


Contributors

Other versions