Skip to content

The HAPI FHIR SDK

QIE ships with a hapi scripting binding that surfaces the HAPI FHIR library, the reference Java SDK for building and parsing FHIR resources. Scripts can construct resources with typed setters (.setId(...), .setActive(true), .setName(...)) instead of hand-building JSON, then serialize the result with a version-specific FHIR context.

The HAPI module is optional

The hapi binding is a stub until the QIE HAPI Module is installed. Without it, calls resolve to a notCurrentlyLoaded no-op. Install the module before writing scripts that use hapi:

  1. Contact Qvera support for the HAPI-module archive that matches your QIE version.
  2. In the QIE console, open System Configuration → Manage External Libraries.
  3. Upload the module archive; check its JAR entries so QIE loads them at next startup.
  4. Restart the QIE service.
  5. Confirm the module is live from any Custom Script:

    qie.debug('HAPI plugin version: ' + hapi.context.getFactoryContextVersion());
    

FHIR context per version

The HAPI library exposes a separate parser/factory context per FHIR release: getDSTU2FhirContext(), getDSTU3FhirContext(), getR4FhirContext(), getR4bFhirContext(), getR5FhirContext(). Pick the one that matches the FHIR version of the server you are sending to; do not mix.

// Build a FHIR R4 Account resource and serialize as JSON.
var account = new hapi.r4.model.Account();
account.setId('acct-42');
account.setStatus(hapi.r4.model.Account.AccountStatus.ACTIVE);
account.setName('Encounter for Patient 12345');

var ctx  = hapi.context.getR4FhirContext();
var json = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(account);
message.setNode('/', json);

Every resource class and enum lives under hapi.<version>.model.*: hapi.r4.model.Patient, hapi.r5.model.Observation, hapi.dstu3.model.Bundle, and so on. Consult the HAPI FHIR API documentation for the full class catalogue; the Code Wizard's FHIR → HAPI menu lists the QIE-side entry points and inserts working call templates.