org.hl7.fhir.r4.model.Composition Java Examples

The following examples show how to use org.hl7.fhir.r4.model.Composition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FhirChCrlDocumentBundle.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void createBundle(){
	try {
		Date now = new Date();
		
		this.bundle = new Bundle();
		bundle.setId("BundleFromPractitioner");
		bundle.setMeta(new Meta().setLastUpdated(now).setProfile(Collections.singletonList(
			new CanonicalType("http://fhir.ch/ig/ch-crl/StructureDefinition/ch-crl-bundle"))));
		bundle.setType(BundleType.DOCUMENT);
		
		BundleEntryComponent compositionEntry = bundle.addEntry();
		Composition composition = new Composition();
		compositionEntry.setResource(composition);
		composition.setId("CompFromPractitioner");
		composition.setMeta(new Meta().setLastUpdated(now)
			.setProfile(Collections.singletonList(new CanonicalType(
				"http://fhir.ch/ig/ch-crl/StructureDefinition/ch-crl-composition"))));
		composition.setStatus(CompositionStatus.FINAL);
		composition.setType(new CodeableConcept(
			new Coding("http://loinc.org", "72134-0", "Cancer event report")));
		composition.setDate(now);
		composition.setTitle("Report to the Cancer Registry");
		
		BundleEntryComponent subjectEntry = bundle.addEntry();
		IFhirTransformer<Patient, IPatient> patientTransformer =
			(IFhirTransformer<Patient, IPatient>) FhirTransformersHolder
				.getTransformerFor(Patient.class, IPatient.class);
		Patient subject = patientTransformer.getFhirObject(patient)
			.orElseThrow(() -> new IllegalStateException("Could not create subject"));
		subject.getExtension().clear();
		fixAhvIdentifier(subject);
		
		subjectEntry.setResource(subject);
		
		BundleEntryComponent practitionerEntry = bundle.addEntry();
		IFhirTransformer<Practitioner, IMandator> practitionerTransformer =
			(IFhirTransformer<Practitioner, IMandator>) FhirTransformersHolder
				.getTransformerFor(Practitioner.class, IMandator.class);
		Practitioner practitioner = practitionerTransformer.getFhirObject(author)
			.orElseThrow(() -> new IllegalStateException("Could not create autor"));
		practitioner.getExtension().clear();
		practitioner.getIdentifier().clear();
		practitionerEntry.setResource(practitioner);
		
		BundleEntryComponent documentReferenceEntry = bundle.addEntry();
		DocumentReference documentReference = new DocumentReference();
		documentReferenceEntry.setResource(documentReference);
		documentReference.setId(document.getId());
		DocumentReferenceContentComponent content = documentReference.addContent();
		content.setAttachment(new Attachment().setContentType("application/pdf")
			.setData(IOUtils.toByteArray(document.getContent())));
		
		composition.setSubject(new Reference(subject));
		composition.setAuthor(Collections.singletonList(new Reference(practitioner)));
		SectionComponent section = composition.addSection();
		section.addEntry(new Reference(documentReference));
	} catch (IOException e) {
		LoggerFactory.getLogger(getClass()).error("Error creating FHIR bundle", e);
		throw new IllegalStateException("Error creating FHIR bundle", e);
	}
}