Created
June 21, 2017 14:20
-
-
Save KevinMayfield/0b68a287b764a18eebcde9431aec7f7b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void medicationOrderQueryExample() | |
{ | |
FhirContext ctx = FhirContext.forDstu2(); | |
IParser parser = ctx.newXmlParser(); | |
// Create a client and post the transaction to the server | |
IGenericClient client = ctx.newRestfulGenericClient("http://127.0.0.1:8181/Dstu2/"); | |
// GET [baseUrl]\Patient?identifier=https://fhir.nhs.uk/Id/nhs-number|9439676165 | |
Bundle results = client | |
.search() | |
.forResource(Patient.class) | |
.where(Patient.IDENTIFIER.exactly().systemAndCode(CareConnectSystem.SystemNHSNumber,"9439676165")) | |
.returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) | |
.execute(); | |
if (results.getEntry().size()>0) { | |
Patient patient = (Patient) results.getEntry().get(0).getResource(); | |
// GET [baseUrl]\MedicationStatement?patient=6a7d31db-0bb8-4afa-bf4c-c32d5d4b8487 | |
results = client | |
.search() | |
.forResource(MedicationStatement.class) | |
.where(MedicationStatement.PATIENT.hasId(patient.getId())) | |
.returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) | |
.execute(); | |
if (results.getEntry().size() > 0) { | |
MedicationStatement statement = (MedicationStatement) results.getEntry().get(0).getResource(); | |
CodeableConceptDt code = (CodeableConceptDt) statement.getMedication(); | |
// GET [baseUrl]\MedicationOrder?patient=6a7d31db-0bb8-4afa-bf4c-c32d5d4b8487&code=http://snomed.info/sct|321153009 | |
results = client | |
.search() | |
.forResource(MedicationStatement.class) | |
.where(MedicationOrder.PATIENT.hasId(patient.getId())) | |
.and(MedicationOrder.CODE.exactly().systemAndCode(CareConnectSystem.SNOMEDCT, code.getCoding().get(0).getCode())) | |
.returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) | |
.execute(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment