Created
December 6, 2018 15:25
-
-
Save KevinMayfield/238d769c7a96db63544e271f405f9160 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
private DocumentReference getSimple() { | |
Binary binary = new Binary(); | |
binary.setId(UUID.randomUUID().toString()); | |
String dummyContent = "<!DOCTYPE html><html><body>SOME TEXT</body></html>"; | |
binary.setContent (dummyContent.getBytes()); | |
binary.setContentType("text/html"); | |
//System.out.println(FhirContext.forDstu3().newJsonParser().setPrettyPrint(true).encodeResourceToString(binary)); | |
DocumentReference doc = new DocumentReference(); | |
doc.setId(UUID.randomUUID().toString()); | |
doc.setSubject(new Reference("https://demographics.spineservices.nhs.uk/STU3/Patient/9658220169")); | |
doc.setStatus(Enumerations.DocumentReferenceStatus.CURRENT); | |
doc.getType().addCoding() | |
.setSystem("http://snomed.info/sct") | |
.setCode("734163000") | |
.setDisplay("Care plan"); | |
doc.setIndexed(new Date()); | |
doc.getContext().getPracticeSetting().addCoding() | |
.setSystem("http://snomed.info/sct") | |
.setCode("408467006") | |
.setDisplay("Adult mental illness"); | |
doc.addContent().getAttachment() | |
.setContentType(binary.getContentType()) | |
.setUrl("urn:uuid:" + binary.getId()); | |
//System.out.println(FhirContext.forDstu3().newJsonParser().setPrettyPrint(true).encodeResourceToString(doc)); | |
IGenericClient clientODS = ctxFHIR.newRestfulGenericClient("https://directory.spineservices.nhs.uk/STU3/"); | |
clientODS.setEncoding(EncodingEnum.XML); | |
Organization organization = clientODS | |
.read() | |
.resource(Organization.class) | |
.withId("RR8").execute(); | |
organization.setId(UUID.randomUUID().toString()); | |
doc.addAuthor(new Reference("urn:uuid:" + organization.getId()).setDisplay(organization.getName())); | |
Patient patient = null; | |
IGenericClient clientCCRI = ctxFHIR.newRestfulGenericClient("https://data.developer.nhs.uk/ccri-fhir/STU3/"); | |
clientODS.setEncoding(EncodingEnum.XML); | |
Bundle patientSearchbundle = clientCCRI | |
.search() | |
.forResource(Patient.class) | |
.where(Patient.IDENTIFIER.exactly().systemAndCode("https://fhir.nhs.uk/Id/nhs-number","9658220169")) | |
.returnBundle(Bundle.class) | |
.execute(); | |
if (patientSearchbundle.getEntry().size()>0) { | |
if (patientSearchbundle.getEntry().get(0).getResource() instanceof Patient) | |
patient = (Patient) patientSearchbundle.getEntry().get(0).getResource(); | |
} | |
if (patient != null) { | |
patient.setId(UUID.randomUUID().toString()); | |
doc.setSubject(new Reference("urn:uuid:" + patient.getId())); | |
Bundle bundle = new Bundle(); | |
bundle.addEntry().setResource(doc).setFullUrl("urn:uuid:" + doc.getId()); | |
bundle.addEntry().setResource(binary).setFullUrl("urn:uuid:" + binary.getId()); | |
bundle.addEntry().setResource(organization).setFullUrl("urn:uuid:" + organization.getId()); | |
bundle.addEntry().setResource(patient).setFullUrl("urn:uuid:" + patient.getId()); | |
bundle.setType(Bundle.BundleType.COLLECTION); | |
System.out.println(FhirContext.forDstu3().newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle)); | |
clientCCRI.create().resource(bundle).execute(); | |
} | |
return doc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment