Last active
June 22, 2017 14:38
-
-
Save KevinMayfield/8a333a1acd31a7460ca4fd508b987156 to your computer and use it in GitHub Desktop.
Practitioner and Organisation Search Java
This file contains 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 void run(String... args) throws Exception { | |
if (args.length > 0 && args[0].equals("exitcode")) { | |
throw new Exception(); | |
} | |
// Create a FHIR Context | |
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/"); | |
System.out.println("GET http://127.0.0.1:8181/Dstu2/Patient?identifier=https://fhir.nhs.uk/Id/nhs-number|9876543210"); | |
Bundle results = client | |
.search() | |
.forResource(Patient.class) | |
.where(Patient.IDENTIFIER.exactly().systemAndCode("https://fhir.nhs.uk/Id/nhs-number", "9876543210")) | |
.returnBundle(Bundle.class) | |
.execute(); | |
System.out.println(parser.setPrettyPrint(true).encodeResourceToString(results)); | |
if (results.getEntry().size() > 0) { | |
// Process first patient only. | |
Patient patient = (Patient) results.getEntry().get(0).getResource(); | |
System.out.println("GET http://[baseUrl]/Organization24967"); | |
if (patient.getManagingOrganization() != null) { | |
Organization surgery = client | |
.read() | |
.resource(Organization.class) | |
.withId(patient.getManagingOrganization().getReference().getValue()) | |
.execute(); | |
System.out.println(parser.setPrettyPrint(true).encodeResourceToString(surgery)); | |
} | |
if (patient.getCareProvider().size() > 0) { | |
System.out.println("GET http://[baseUrl]/Practitoner/24965"); | |
Practitioner gp= client | |
.read() | |
.resource(Practitioner.class) | |
.withId(patient.getCareProvider().get(0).getReference().getValue()) | |
.execute(); | |
System.out.println(parser.setPrettyPrint(true).encodeResourceToString(gp)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment