Skip to content

Instantly share code, notes, and snippets.

@KevinMayfield
Created December 6, 2018 15:31
Show Gist options
  • Save KevinMayfield/4445917ebcc1ce92646630beb5397136 to your computer and use it in GitHub Desktop.
Save KevinMayfield/4445917ebcc1ce92646630beb5397136 to your computer and use it in GitHub Desktop.
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.addAuthor()
.setReference("https://directory.spineservices.nhs.uk/STU3/Organization/RR8").setDisplay("LEEDS TEACHING HOSPITALS NHS TRUST");
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));
Bundle bundle = new Bundle();
bundle.addEntry().setResource(doc).setFullUrl("urn:uuid:"+doc.getId());
bundle.addEntry().setResource(binary).setFullUrl("urn:uuid:"+binary.getId());
bundle.setType(Bundle.BundleType.COLLECTION);
System.out.println(FhirContext.forDstu3().newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment