Java Code Examples for org.hl7.fhir.r4.model.Bundle.BundleEntryComponent#setResource()
The following examples show how to use
org.hl7.fhir.r4.model.Bundle.BundleEntryComponent#setResource() .
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: 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 2
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 3
Source File: BatchLoader.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
private static void sendFile(FHIRToolingClient client, File f, int size, IniFile ini) throws FHIRFormatError, FileNotFoundException, IOException { long ms = System.currentTimeMillis(); System.out.print("Loading "+f.getName()+".. "); IParser parser = f.getName().endsWith(".json") ? new JsonParser() : new XmlParser(); Resource res = parser.parse(new FileInputStream(f)); System.out.println(" done: ("+Long.toString(System.currentTimeMillis()-ms)+" ms)"); if (res instanceof Bundle) { Bundle bnd = (Bundle) res; int cursor = ini.hasProperty("progress", f.getName()) ? ini.getIntegerProperty("progress", f.getName()) : 0; while (cursor < bnd.getEntry().size()) { Bundle bt = new Bundle(); bt.setType(BundleType.BATCH); bt.setId(UUID.randomUUID().toString().toLowerCase()); for (int i = cursor; i < Math.min(bnd.getEntry().size(), cursor+size); i++) { BundleEntryComponent be = bt.addEntry(); be.setResource(bnd.getEntry().get(i).getResource()); be.getRequest().setMethod(HTTPVerb.PUT); be.getRequest().setUrl(be.getResource().getResourceType().toString()+"/"+be.getResource().getId()); } System.out.print(f.getName()+" ("+cursor+"/"+bnd.getEntry().size()+"): "); ms = System.currentTimeMillis(); Bundle resp = client.transaction(bt); int ncursor = cursor+size; for (int i = 0; i < resp.getEntry().size(); i++) { BundleEntryComponent t = resp.getEntry().get(i); if (!t.getResponse().getStatus().startsWith("2")) { System.out.println("failed status at "+Integer.toString(i)+": "+t.getResponse().getStatus()); ncursor = cursor+i-1; break; } } cursor = ncursor; System.out.println(" .. done: ("+Long.toString(System.currentTimeMillis()-ms)+" ms) "+SimpleDateFormat.getInstance().format(new Date())); ini.setIntegerProperty("progress", f.getName(), cursor, null); ini.save(); } ini.setBooleanProperty("finished", f.getName(), true, null); ini.save(); } else { client.update(res); ini.setBooleanProperty("finished", f.getName(), true, null); ini.save(); } }
Example 4
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); } }