org.hl7.fhir.r4.model.Bundle Java Examples
The following examples show how to use
org.hl7.fhir.r4.model.Bundle.
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: FHIRToolingClient.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
public <T extends Resource> T getCanonical(Class<T> resourceClass, String canonicalURL) { ResourceRequest<T> result = null; try { result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndCanonical(resourceClass, canonicalURL), getPreferredResourceFormat()); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405);//unknown result.addSuccessStatus(200);//Only one for now if(result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome)result.getPayload()); } } catch (Exception e) { handleException("An error has occurred while trying to read this version of the resource", e); } Bundle bnd = (Bundle) result.getPayload(); if (bnd.getEntry().size() == 0) throw new EFhirClientException("No matching resource found for canonical URL '"+canonicalURL+"'"); if (bnd.getEntry().size() > 1) throw new EFhirClientException("Multiple matching resources found for canonical URL '"+canonicalURL+"'"); return (T) bnd.getEntry().get(0).getResource(); }
Example #2
Source File: MultitenantServerR4IT.java From hapi-fhir-jpaserver-starter with Apache License 2.0 | 6 votes |
@Test public void testCreateAndReadInTenantA() { ourLog.info("Base URL is: " + HapiProperties.getServerAddress()); // Create tenant A ourClientTenantInterceptor.setTenantId("DEFAULT"); ourClient .operation() .onServer() .named(ProviderConstants.PARTITION_MANAGEMENT_CREATE_PARTITION) .withParameter(Parameters.class, ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID, new IntegerType(1)) .andParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME, new CodeType("TENANT-A")) .execute(); ourClientTenantInterceptor.setTenantId("TENANT-A"); Patient pt = new Patient(); pt.addName().setFamily("Family A"); ourClient.create().resource(pt).execute().getId(); Bundle searchResult = ourClient.search().forResource(Patient.class).returnBundle(Bundle.class).cacheControl(new CacheControlDirective().setNoCache(true)).execute(); assertEquals(1, searchResult.getEntry().size()); Patient pt2 = (Patient) searchResult.getEntry().get(0).getResource(); assertEquals("Family A", pt2.getName().get(0).getFamily()); }
Example #3
Source File: MultitenantServerR4IT.java From hapi-fhir-jpaserver-starter with Apache License 2.0 | 6 votes |
@Test public void testCreateAndReadInTenantB() { ourLog.info("Base URL is: " + HapiProperties.getServerAddress()); // Create tenant A ourClientTenantInterceptor.setTenantId("DEFAULT"); ourClient .operation() .onServer() .named(ProviderConstants.PARTITION_MANAGEMENT_CREATE_PARTITION) .withParameter(Parameters.class, ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID, new IntegerType(2)) .andParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME, new CodeType("TENANT-B")) .execute(); ourClientTenantInterceptor.setTenantId("TENANT-B"); Patient pt = new Patient(); pt.addName().setFamily("Family B"); ourClient.create().resource(pt).execute().getId(); Bundle searchResult = ourClient.search().forResource(Patient.class).returnBundle(Bundle.class).cacheControl(new CacheControlDirective().setNoCache(true)).execute(); assertEquals(1, searchResult.getEntry().size()); Patient pt2 = (Patient) searchResult.getEntry().get(0).getResource(); assertEquals("Family B", pt2.getName().get(0).getFamily()); }
Example #4
Source File: LoincToDEConvertor.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
public Bundle process(String sourceFile) throws FileNotFoundException, SAXException, IOException, ParserConfigurationException { this.definitions = sourceFile; log("Begin. Produce Loinc CDEs in "+dest+" from "+definitions); loadLoinc(); log("LOINC loaded"); now = DateTimeType.now(); bundle = new Bundle(); bundle.setType(BundleType.COLLECTION); bundle.setId("http://hl7.org/fhir/commondataelement/loinc"); bundle.setMeta(new Meta().setLastUpdatedElement(InstantType.now())); processLoincCodes(); return bundle; }
Example #5
Source File: GraphQLEngineTests.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
@Override public Bundle search(Object appInfo, String type, List<Argument> searchParams) throws FHIRException { try { Bundle bnd = new Bundle(); BundleLinkComponent bl = bnd.addLink(); bl.setRelation("next"); bl.setUrl("http://test.fhir.org/r4/Patient?_format=text/xhtml&search-id=77c97e03-8a6c-415f-a63d-11c80cf73f&&active=true&_sort=_id&search-offset=50&_count=50"); bl = bnd.addLink(); bl.setRelation("self"); bl.setUrl("http://test.fhir.org/r4/Patient?_format=text/xhtml&search-id=77c97e03-8a6c-415f-a63d-11c80cf73f&&active=true&_sort=_id&search-offset=0&_count=50"); BundleEntryComponent be = bnd.addEntry(); be.setFullUrl("http://hl7.org/fhir/Patient/example"); be.setResource(new XmlParser().parse(new FileInputStream(Utilities.path(TestingUtilities.resourceNameToFile("patient-example.xml"))))); be = bnd.addEntry(); be.setFullUrl("http://hl7.org/fhir/Patient/example"); be.setResource(new XmlParser().parse(new FileInputStream(Utilities.path(TestingUtilities.resourceNameToFile("patient-example-xds.xml"))))); be.getSearch().setScore(0.5); be.getSearch().setMode(SearchEntryMode.MATCH); bnd.setTotal(50); return bnd; } catch (Exception e) { throw new FHIRException(e); } }
Example #6
Source File: ResourceRoundTripTests.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
@Test public void testBundle() throws FHIRException, IOException { // Create new Atom Feed Bundle feed = new Bundle(); // Serialize Atom Feed IParser comp = new JsonParser(); ByteArrayOutputStream os = new ByteArrayOutputStream(); comp.compose(os, feed); os.close(); String json = os.toString(); // Deserialize Atom Feed JsonParser parser = new JsonParser(); InputStream is = new ByteArrayInputStream(json.getBytes("UTF-8")); Resource result = parser.parse(is); if (result == null) throw new FHIRException("Bundle was null"); }
Example #7
Source File: Unbundler.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private static void unbundle(String src) throws FHIRFormatError, FileNotFoundException, IOException { String folder = Utilities.getDirectoryForFile(src); Bundle bnd = (Bundle) new JsonParser().parse(new FileInputStream(src)); for (BundleEntryComponent be : bnd.getEntry()) { Resource r = be.getResource(); if (r != null) { if (StringUtils.isBlank(r.getId())) { if (r instanceof MetadataResource) r.setId(tail((MetadataResource) r)); } if (!StringUtils.isBlank(r.getId())) { String tgt = Utilities.path(folder, r.fhirType()+"-"+r.getId()+".json"); if (!new File(tgt).exists()) new JsonParser().compose(new FileOutputStream(tgt), r); } } } }
Example #8
Source File: FhirR4.java From synthea with Apache License 2.0 | 6 votes |
/** * Map the JsonObject for a Supply into a FHIR SupplyDelivery and add it to the Bundle. * * @param personEntry The Person entry. * @param bundle Bundle to add to. * @param supply The supplied object to add. * @param encounter The encounter during which the supplies were delivered * @return The added Entry. */ private static BundleEntryComponent supplyDelivery(BundleEntryComponent personEntry, Bundle bundle, HealthRecord.Supply supply, Encounter encounter) { SupplyDelivery supplyResource = new SupplyDelivery(); supplyResource.setStatus(SupplyDeliveryStatus.COMPLETED); supplyResource.setPatient(new Reference(personEntry.getFullUrl())); CodeableConcept type = new CodeableConcept(); type.addCoding() .setCode("device") .setDisplay("Device") .setSystem("http://terminology.hl7.org/CodeSystem/supply-item-type"); supplyResource.setType(type); SupplyDeliverySuppliedItemComponent suppliedItem = new SupplyDeliverySuppliedItemComponent(); suppliedItem.setItem(mapCodeToCodeableConcept(supply.codes.get(0), SNOMED_URI)); suppliedItem.setQuantity(new Quantity(supply.quantity)); supplyResource.setSuppliedItem(suppliedItem); supplyResource.setOccurrence(convertFhirDateTime(supply.start, true)); return newEntry(bundle, supplyResource); }
Example #9
Source File: FhirR4.java From synthea with Apache License 2.0 | 6 votes |
/** * Helper function to create an Entry for the given Resource within the given Bundle. Sets the * resourceID to a random UUID, sets the entry's fullURL to that resourceID, and adds the entry to * the bundle. * * @param bundle The Bundle to add the Entry to * @param resource Resource the new Entry should contain * @param resourceID The Resource ID to assign * @return the created Entry */ private static BundleEntryComponent newEntry(Bundle bundle, Resource resource, String resourceID) { BundleEntryComponent entry = bundle.addEntry(); resource.setId(resourceID); entry.setFullUrl(getUrlPrefix(resource.fhirType()) + resourceID); entry.setResource(resource); if (TRANSACTION_BUNDLE) { BundleEntryRequestComponent request = entry.getRequest(); request.setMethod(HTTPVerb.POST); request.setUrl(resource.getResourceType().name()); entry.setRequest(request); } return entry; }
Example #10
Source File: MeasureOperationsProvider.java From cqf-ruler with Apache License 2.0 | 6 votes |
private void addEvaluatedResourcesToParameters(Bundle contained, Parameters parameters) { Map<String, Resource> resourceMap = new HashMap<>(); if (contained.hasEntry()) { for (Bundle.BundleEntryComponent entry : contained.getEntry()) { if (entry.hasResource() && !(entry.getResource() instanceof ListResource)) { if (!resourceMap.containsKey(entry.getResource().getIdElement().getValue())) { parameters.addParameter(new Parameters.ParametersParameterComponent().setName("resource") .setResource(entry.getResource())); resourceMap.put(entry.getResource().getIdElement().getValue(), entry.getResource()); resolveReferences(entry.getResource(), parameters, resourceMap); } } } } }
Example #11
Source File: MeasureOperationsProvider.java From cqf-ruler with Apache License 2.0 | 6 votes |
private Bundle createTransactionBundle(Bundle bundle) { Bundle transactionBundle; if (bundle != null) { if (bundle.hasType() && bundle.getType() == Bundle.BundleType.TRANSACTION) { transactionBundle = bundle; } else { transactionBundle = new Bundle().setType(Bundle.BundleType.TRANSACTION); if (bundle.hasEntry()) { for (Bundle.BundleEntryComponent entry : bundle.getEntry()) { if (entry.hasResource()) { transactionBundle.addEntry(createTransactionEntry(entry.getResource())); } } } } } else { transactionBundle = new Bundle().setType(Bundle.BundleType.TRANSACTION).setEntry(new ArrayList<>()); } return transactionBundle; }
Example #12
Source File: LoincToDEConvertor.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
public void process() throws FHIRFormatError, IOException, XmlPullParserException, SAXException, ParserConfigurationException { log("Begin. Produce Loinc CDEs in "+dest+" from "+definitions); loadLoinc(); log("LOINC loaded"); now = DateTimeType.now(); bundle = new Bundle(); bundle.setId("http://hl7.org/fhir/commondataelement/loinc"); bundle.setMeta(new Meta().setLastUpdatedElement(InstantType.now())); processLoincCodes(); if (dest != null) { log("Saving..."); saveBundle(); } log("Done"); }
Example #13
Source File: HospitalExporterR4.java From synthea with Apache License 2.0 | 5 votes |
/** * Export the hospital in FHIR R4 format. */ public static void export(long stop) { if (Boolean.parseBoolean(Config.get("exporter.hospital.fhir.export"))) { Bundle bundle = new Bundle(); if (Boolean.parseBoolean(Config.get("exporter.fhir.transaction_bundle"))) { bundle.setType(BundleType.TRANSACTION); } else { bundle.setType(BundleType.COLLECTION); } for (Provider h : Provider.getProviderList()) { // filter - exports only those hospitals in use Table<Integer, String, AtomicInteger> utilization = h.getUtilization(); int totalEncounters = utilization.column(Provider.ENCOUNTERS).values().stream() .mapToInt(ai -> ai.get()).sum(); if (totalEncounters > 0) { BundleEntryComponent entry = FhirR4.provider(bundle, h); addHospitalExtensions(h, (Organization) entry.getResource()); } } String bundleJson = FHIR_CTX.newJsonParser().setPrettyPrint(true) .encodeResourceToString(bundle); // get output folder List<String> folders = new ArrayList<>(); folders.add("fhir"); String baseDirectory = Config.get("exporter.baseDirectory"); File f = Paths.get(baseDirectory, folders.toArray(new String[0])).toFile(); f.mkdirs(); Path outFilePath = f.toPath().resolve("hospitalInformation" + stop + ".json"); try { Files.write(outFilePath, Collections.singleton(bundleJson), StandardOpenOption.CREATE_NEW); } catch (IOException e) { e.printStackTrace(); } } }
Example #14
Source File: BundlesTest.java From bunsen with Apache License 2.0 | 5 votes |
@Test public void testRetrieveBundle() { BundleContainer container = bundlesRdd.first(); Bundle bundle = (Bundle) container.getBundle(); Assert.assertNotNull(bundle); Assert.assertTrue(bundle.getEntry().size() > 0); }
Example #15
Source File: ValidationSupportR4.java From synthea with Apache License 2.0 | 5 votes |
private void handleResource(IBaseResource resource) { if (resource instanceof Bundle) { Bundle bundle = (Bundle) resource; for (BundleEntryComponent entry : bundle.getEntry()) { if (entry.hasResource()) { handleResource(entry.getResource()); } } } else { resources.add(resource); if (resource instanceof CodeSystem) { CodeSystem cs = (CodeSystem) resource; resourcesMap.put(cs.getUrl(), cs); codeSystemMap.put(cs.getUrl(), cs); } else if (resource instanceof ValueSet) { ValueSet vs = (ValueSet) resource; resourcesMap.put(vs.getUrl(), vs); if (vs.hasExpansion() && vs.getExpansion().hasContains()) { processExpansion(vs.getExpansion().getContains()); } } else if (resource instanceof StructureDefinition) { StructureDefinition sd = (StructureDefinition) resource; resourcesMap.put(sd.getUrl(), sd); definitions.add(sd); definitionsMap.put(sd.getUrl(), sd); } } }
Example #16
Source File: FhirR4.java From synthea with Apache License 2.0 | 5 votes |
/** * Find the Practitioner entry in this bundle, and return the associated "fullUrl" * attribute. * @param clinician A given clinician. * @param bundle The current bundle being generated. * @return Practitioner.fullUrl if found, otherwise null. */ private static String findPractitioner(Clinician clinician, Bundle bundle) { for (BundleEntryComponent entry : bundle.getEntry()) { if (entry.getResource().fhirType().equals("Practitioner")) { Practitioner doc = (Practitioner) entry.getResource(); if (doc.getIdentifierFirstRep().getValue() .equals("" + (9_999_999_999L - clinician.identifier))) { return entry.getFullUrl(); } } } return null; }
Example #17
Source File: MeasureOperationsProvider.java From cqf-ruler with Apache License 2.0 | 5 votes |
@Operation(name = "$collect-data", idempotent = true, type = Measure.class) public Parameters collectData(@IdParam IdType theId, @RequiredParam(name = "periodStart") String periodStart, @RequiredParam(name = "periodEnd") String periodEnd, @OptionalParam(name = "patient") String patientRef, @OptionalParam(name = "practitioner") String practitionerRef, @OptionalParam(name = "lastReceivedOn") String lastReceivedOn) throws FHIRException { // TODO: Spec says that the periods are not required, but I am not sure what to // do when they aren't supplied so I made them required MeasureReport report = evaluateMeasure(theId, periodStart, periodEnd, null, null, patientRef, null, practitionerRef, lastReceivedOn, null, null, null); report.setGroup(null); Parameters parameters = new Parameters(); parameters.addParameter( new Parameters.ParametersParameterComponent().setName("measurereport").setResource(report)); if (report.hasContained()) { for (Resource contained : report.getContained()) { if (contained instanceof Bundle) { addEvaluatedResourcesToParameters((Bundle) contained, parameters); } } } // TODO: need a way to resolve referenced resources within the evaluated // resources // Should be able to use _include search with * wildcard, but HAPI doesn't // support that return parameters; }
Example #18
Source File: FhirR4.java From synthea with Apache License 2.0 | 5 votes |
/** * Find the Location entry in this bundle for the given provider, and return the * "fullUrl" attribute. * * @param provider A given provider. * @param bundle The current bundle being generated. * @return Location.fullUrl if found, otherwise null. */ private static String findLocationUrl(Provider provider, Bundle bundle) { for (BundleEntryComponent entry : bundle.getEntry()) { if (entry.getResource().fhirType().equals("Location")) { org.hl7.fhir.r4.model.Location location = (org.hl7.fhir.r4.model.Location) entry.getResource(); if (location.getManagingOrganization() .getReference().endsWith(provider.getResourceID())) { return entry.getFullUrl(); } } } return null; }
Example #19
Source File: MeasureOperationsProvider.java From cqf-ruler with Apache License 2.0 | 5 votes |
@Operation(name = "$submit-data", idempotent = true, type = Measure.class) public Resource submitData(RequestDetails details, @IdParam IdType theId, @OperationParam(name = "measure-report", min = 1, max = 1, type = MeasureReport.class) MeasureReport report, @OperationParam(name = "resource") List<IAnyResource> resources) { Bundle transactionBundle = new Bundle().setType(Bundle.BundleType.TRANSACTION); /* * TODO - resource validation using $data-requirements operation (params are the * provided id and the measurement period from the MeasureReport) * * TODO - profile validation ... not sure how that would work ... (get * StructureDefinition from URL or must it be stored in Ruler?) */ transactionBundle.addEntry(createTransactionEntry(report)); for (IAnyResource resource : resources) { Resource res = (Resource) resource; if (res instanceof Bundle) { for (Bundle.BundleEntryComponent entry : createTransactionBundle((Bundle) res).getEntry()) { transactionBundle.addEntry(entry); } } else { // Build transaction bundle transactionBundle.addEntry(createTransactionEntry(res)); } } return (Resource) this.registry.getSystemDao().transaction(details, transactionBundle); }
Example #20
Source File: FhirR4.java From synthea with Apache License 2.0 | 5 votes |
/** * Find the provider entry in this bundle, and return the associated "fullUrl" attribute. * * @param provider A given provider. * @param bundle The current bundle being generated. * @return Provider.fullUrl if found, otherwise null. */ private static String findProviderUrl(Provider provider, Bundle bundle) { for (BundleEntryComponent entry : bundle.getEntry()) { if (entry.getResource().fhirType().equals("Organization")) { Organization org = (Organization) entry.getResource(); if (org.getIdentifierFirstRep().getValue() != null && org.getIdentifierFirstRep().getValue().equals(provider.getResourceID())) { return entry.getFullUrl(); } } } return null; }
Example #21
Source File: MeasureOperationsProvider.java From cqf-ruler with Apache License 2.0 | 5 votes |
private Bundle.BundleEntryComponent createTransactionEntry(Resource resource) { Bundle.BundleEntryComponent transactionEntry = new Bundle.BundleEntryComponent().setResource(resource); if (resource.hasId()) { transactionEntry.setRequest( new Bundle.BundleEntryRequestComponent().setMethod(Bundle.HTTPVerb.PUT).setUrl(resource.getId())); } else { transactionEntry.setRequest(new Bundle.BundleEntryRequestComponent().setMethod(Bundle.HTTPVerb.POST) .setUrl(resource.fhirType())); } return transactionEntry; }
Example #22
Source File: ResourceUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public static Resource getById(Bundle feed, ResourceType type, String reference) { for (BundleEntryComponent item : feed.getEntry()) { if (item.getResource().getId().equals(reference) && item.getResource().getResourceType() == type) return item.getResource(); } return null; }
Example #23
Source File: ResourceUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public static BundleEntryComponent getEntryById(Bundle feed, ResourceType type, String reference) { for (BundleEntryComponent item : feed.getEntry()) { if (item.getResource().getId().equals(reference) && item.getResource().getResourceType() == type) return item; } return null; }
Example #24
Source File: ResourceUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public static String getLink(Bundle feed, String rel) { for (BundleLinkComponent link : feed.getLink()) { if (link.getRelation().equals(rel)) return link.getUrl(); } return null; }
Example #25
Source File: FHIRToolingClient.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public Bundle fetchFeed(String url) { Bundle feed = null; try { feed = utils.issueGetFeedRequest(new URI(url), getPreferredResourceFormat()); } catch (Exception e) { handleException("An error has occurred while trying to retrieve history since last update",e); } return feed; }
Example #26
Source File: FHIRToolingClient.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public Bundle transaction(Bundle batch) { Bundle transactionResult = null; try { transactionResult = utils.postBatchRequest(resourceAddress.getBaseServiceUri(), utils.getFeedAsByteArray(batch, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat()); } catch (Exception e) { handleException("An error occurred trying to process this transaction request", e); } return transactionResult; }
Example #27
Source File: ClientUtils.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public Bundle issuePostFeedRequest(URI resourceUri, Map<String, String> parameters, String resourceName, Resource resource, String resourceFormat) throws IOException { HttpPost httppost = new HttpPost(resourceUri); String boundary = "----WebKitFormBoundarykbMUo6H8QaUnYtRy"; httppost.addHeader("Content-Type", "multipart/form-data; boundary="+boundary); httppost.addHeader("Accept", resourceFormat); configureFhirRequest(httppost, null); HttpResponse response = sendPayload(httppost, encodeFormSubmission(parameters, resourceName, resource, boundary)); return unmarshalFeed(response, resourceFormat); }
Example #28
Source File: FhirR4.java From synthea with Apache License 2.0 | 4 votes |
/** * Map the given Observation with attachment element to a FHIR Media resource, and add it to the * given Bundle. * * @param personEntry The Entry for the Person * @param bundle Bundle to add the Media to * @param encounterEntry Current Encounter entry * @param obs The Observation to map to FHIR and add to the bundle * @return The added Entry */ private static BundleEntryComponent media(BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Observation obs) { org.hl7.fhir.r4.model.Media mediaResource = new org.hl7.fhir.r4.model.Media(); // Hard code as Image since we don't anticipate using video or audio any time soon Code mediaType = new Code("http://terminology.hl7.org/CodeSystem/media-type", "image", "Image"); if (obs.codes != null && obs.codes.size() > 0) { List<CodeableConcept> reasonList = obs.codes.stream() .map(code -> mapCodeToCodeableConcept(code, SNOMED_URI)).collect(Collectors.toList()); mediaResource.setReasonCode(reasonList); } mediaResource.setType(mapCodeToCodeableConcept(mediaType, MEDIA_TYPE_URI)); mediaResource.setStatus(MediaStatus.COMPLETED); mediaResource.setSubject(new Reference(personEntry.getFullUrl())); mediaResource.setEncounter(new Reference(encounterEntry.getFullUrl())); Attachment content = (Attachment) obs.value; org.hl7.fhir.r4.model.Attachment contentResource = new org.hl7.fhir.r4.model.Attachment(); contentResource.setContentType(content.contentType); contentResource.setLanguage(content.language); if (content.data != null) { contentResource.setDataElement(new org.hl7.fhir.r4.model.Base64BinaryType(content.data)); } contentResource.setUrl(content.url); contentResource.setSize(content.size); contentResource.setTitle(content.title); if (content.hash != null) { contentResource.setHashElement(new org.hl7.fhir.r4.model.Base64BinaryType(content.hash)); } mediaResource.setWidth(content.width); mediaResource.setHeight(content.height); mediaResource.setContent(contentResource); return newEntry(bundle, mediaResource); }
Example #29
Source File: FhirChCrlDocumentBundle.java From elexis-3-core with Eclipse Public License 1.0 | 4 votes |
@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); } }
Example #30
Source File: LoincToDEConvertor.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
public Bundle getBundle() { return bundle; }