1
votes

I am working with a HAPI FHIR Server and am somewhat new to the java client. What I am hoping to accomplish is to create FHIR Patient Bundles that include a single identifying patient resource and all of their other resources in one complete bundle and to save it as a json file.

Patient Resource 1
Observation Resource 1
Condition Resource 1
Lab Resource 1
Observation Resource 2
...

I come from a python background so if it would be more simple to do as request or curl to iterate through the right endpoint for the patients that would be welcome as well. This is a one-time process. If their are alternatives that are more transactional that would be great as well. Any advice is sincerely appreciated!

2

2 Answers

2
votes

it sounds like you want Patient/$everything (see http://hl7.org/fhir/patient-operations.html#everything) (though not all servers support that operation)

1
votes

A Bundle resource in FHIR could be used to bundle the Resources like condition, encounters, Observations, patient etc.

//Example scala pseudo code
//For each of your FHIR resources, add them to a new Entry in your Bundle
// Create a new Patient
val patient = new Patient()
// Add the patient name
patient.addName()
 .addGiven("Bender Bending")
 .addFamily("Rodriguez")
//similarly you can create observation and condition object. 

//Every Bundle *must* contain a Patient resource
bundle.addEntry().setResource(patient)
bundle.addEntry().setResource(observation)
bundle.addEntry().setResource(condition)
bundle.setType(BundleTypeEnum.COLLECTION)
FhirContext ourCtx = FhirContext.forDstu3();
String output =ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle);

// output will contain the JSON created from the bundle. more details on how 

the JSON will look like are provided below. Example: Bundle JSON hierarchy: Bundle Entry: Resource-type = Condition Resource-type = Observation Resource-type = Patient

Json representation of Bundle

This is supported both in DSTU2 and DSTU3 however i couldn't find a suitable json in the test server for DSTU3, that's the only reason i pasted DSTU2 test server link.

The Bundle structures the entries as shown in this snap.

More details on Bundle