Healthcare Application Development | Vicert
Read about ideas that untangle
the complexity of Digital Health

How to use a HAPI-FHIR library and SMART Health IT #FirstEncounter

Posted by Tech Team on Nov 30, 2017

FHIR (pronounced "Fire") is a standard for interoperable exchange of healthcare data developed under the HL7 organization. FHIR includes all features present in HL7 V2, HL7 V3, and CDA.

For more information on FHIR and benefits for providers, payers, clinicians, etc. - check out latest white paper:

 Download

Now, let's immediately double click into the HAPI-FHIR Library.

HAPI-FHIR library

HAPI-FHIR library is an open-source implementation of the FHIR specification in Java. It can be used for development of the client and RESTful client and server applications.

You can start testing the HAPI-FHIR by for example creating a simple client application for inserting Patient data into the test FHIR server.

In order to create a client application, the developer must include the Core library and one of the data structure libraries into the project. The appropriate data structure is selected based on the FHIR version that the developer is planning to use. The following maven configuration example shows how DSTU2 dependency with HL7 data model definitions is included into the project:

<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-client</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-hl7org-dstu2</artifactId>
<version>3.0.0</version>
</dependency>

The following example shows how HAPI-FHIR framework can be used to create a model that will be used as a part of the Add Patient transaction (This example uses hapi-fhir-structures-hl7org-dstu2 structures):

FhirContext ctx = FhirContext.forDstu2Hl7Org();
String serverBase = "http://fhirtest.uhn.ca/baseDstu2";

IGenericClient client = ctx.newRestfulGenericClient(serverBase);

Patient patient = new Patient();

// FIRST AND LAST NAME
patient.addName()
.addFamily("Last name")
.addGiven("First name");

// SOCIAL SECURITY NUMBER
// https://www.hl7.org/FHIR/datatypes.html#Identifier
// https://www.hl7.org/FHIR/identifier-registry.html

patient.addIdentifier()
.setType(new CodeableConcept().addCoding(
new Coding().setCode("SB").setSystem("http://hl7.org/fhir/v2/0203")
))
.setSystem("http://hl7.org/fhir/sid/us-ssn")
.setValue("123456789");

// GENDER
patient.setGender(AdministrativeGender.FEMALE);

// ADDRESS INFORMATION
patient.addAddress()
.setUse(Address.AddressUse.HOME)
.addLine("Street name, number, direction & P.O. Box etc.")
.setCity("Name of city, town etc.")
.setState("Sub-unit of country (abbreviations ok)")
.setPostalCode("Postal/ZIP code for area");

// CONTACT https://www.hl7.org/fhir/datatypes-examples.html#ContactPoint
patient.addTelecom()
.setSystem(ContactPointSystem.PHONE)
.setValue("(555) 675 5745");

patient.addTelecom()
.setSystem(ContactPointSystem.PHONE)
.setValue("(415) 675 5745");

patient.addTelecom()
.setSystem(ContactPointSystem.EMAIL)
.setValue("test@test.com");

// EMERGENCY CONTACT https://www.hl7.org/FHIR/patient-definitions.html#Patient.contact
ContactComponent emergencyContact = new ContactComponent();

emergencyContact.addTelecom().setSystem(ContactPointSystem.PHONE)
.setValue("(111) 675 5745");

// Relationship to patient
emergencyContact
.addRelationship()
.addCoding()
.setSystem("http://hl7.org/fhir/ValueSet/v2-0131")
.setCode("C");

emergencyContact.setName(
new HumanName().addFamily("Last Name contact").addGiven("First name contact")
);

patient.addContact(emergencyContact);

// Encode to JSON
IParser jsonParser = ctx.newJsonParser();
jsonParser.setPrettyPrint(true);
String encoded = jsonParser.encodeResourceToString(patient);

Serialized version of Patient resource created in the previous step is below:

{
"resourceType": "Patient",
"identifier": [
{
"type": {
"coding": [
{
"system": "http://hl7.org/fhir/v2/0203",
"code": "SB"
}
]
},
"system": "http://hl7.org/fhir/sid/us-ssn",
"value": "123456789"
}
],
"name": [
{
"family": [
"Last name"
],
"given": [
"First name"
]
}
],
"telecom": [
{
"system": "phone",
"value": "(555) 675 5745"
},
{
"system": "phone",
"value": "(415) 675 5745"
},
{
"system": "email",
"value": "test@test.com"
}
],
"gender": "female",
"address": [
{
"use": "home",
"line": [
"Street name, number, direction & P.O. Box etc."
],
"city": "Name of city, town etc.",
"state": "Sub-unit of country (abbreviations ok)",
"postalCode": "Postal/ZIP code for area"
}
],
"contact": [
{
"relationship": [
{
"coding": [
{
"system": "http://hl7.org/fhir/ValueSet/v2-0131",
"code": "C"
}
]
}
],
"name": {
"family": [
"Last Name contact"
],
"given": [
"First name contact"
]
},
"telecom": [
{
"system": "phone",
"value": "(111) 675 5745"
}
]
}
]
}

Developers should carefully choose data structure dependency as there are some differences in the HAPI-FHIR API. For example hapi-fhir-structures-dstu2 and hapi-fhir-structures-hl7org-dstu2 dependencies have completely different resource model classes. Our recommendation would be to go with the HL7 version as it's more in line with the naming conventions of the official FHIR specification.

HAPI-FHIR framework is a fairly simple framework to use. The complexity is in the maturity of the FHIR specification. Numerous hours can be spent trying to figure out how to populate FHIR resource request objects, so be sure to allocate enough time on this or consult with someone in advance.

SMART Health IT

SMART Health IT is a guideline, based on open standards, for creating healthcare applications.

When describing SMART Health IT we must keep the following terms in mind:

  1. FHIR is a data model definition.
  2. EHR systems are populating FHIR data model with the actual patient data.
  3. SMART defines how 3rd party applications can be executed inside of the EHR itself (There is a default launch mechanism definition). It tackles security as well, as it defines how to determine identity and data access rights of the EHR user.

You can create a sample SMART application by following the introductory Cerner tutorial. The process is rather simple, but we did encounter some surprises along the way. Namely, at least in the Cerner Sandbox, almost all FHIR operations are Read Only. Currently, only the following resources are writable: AllergyIntolerance, Appointment, Condition, DocumentReference and MedicationStatement.

Creating SMART applications is not challenging from the technological perspective. The documentation is not quite there yet since it's still a young project, but the expectation is that the SMART organization and vendors will improve in this area. The bigger problem might be the vendors and their interpretation of the FHIR specification. One example of such difference is as follows: FHIR medication resource, Epic sites implement with the RXNorm standard; however, a Cerner implementation would use an internal Cerner ID. Each vendor has their own specifics for EHR API's so maybe, for start, go with some of the integration platforms like Redox.

Smart References:

  1. More in-depth details about SMART can be found on the following URL: https://fhirblog.com/2016/07/08/what-is-smart-and-why-should-you-care/.
  2. Here is a sample tutorial on how to create an application on the Cerner’s sandbox: http://engineering.cerner.com/smart-on-fhir-tutorial/#run-your-app-against-smart-health-it-sandbox.

If you want to double click into FHIR and exchange ideas with our engineers around it ping us, we would love to connect!

 

Topics: Java, FHIR