public org.hl7.fhir.r4.model.Bundle convertBundle(org.hl7.fhir.instance.model.Bundle src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.r4.model.Bundle tgt = new org.hl7.fhir.r4.model.Bundle(); copyResource(src, tgt); tgt.setType(convertBundleType(src.getType())); if (src.hasTotal()) tgt.setTotal(src.getTotal()); for (org.hl7.fhir.instance.model.Bundle.BundleLinkComponent t : src.getLink()) tgt.addLink(convertBundleLinkComponent(t)); for (org.hl7.fhir.instance.model.Bundle.BundleEntryComponent t : src.getEntry()) tgt.addEntry(convertBundleEntryComponent(t)); tgt.setSignature(convertSignature(src.getSignature())); return tgt; }
ensureBundle(); myBundle.setId(UUID.randomUUID().toString()); myBundle.getMeta().setLastUpdatedElement(InstantType.withCurrentTime()); myBundle.addLink().setRelation(Constants.LINK_FHIR_BASE).setUrl(theServerBase); myBundle.addLink().setRelation(Constants.LINK_SELF).setUrl(theCompleteUrl); myBundle.getTypeElement().setValueAsString(theBundleType.getCode()); BundleEntryComponent nextEntry = myBundle.addEntry(); myBundle.getTotalElement().setValue(theTotalResults);
public org.hl7.fhir.instance.model.Bundle convertBundle(org.hl7.fhir.dstu3.model.Bundle src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.instance.model.Bundle tgt = new org.hl7.fhir.instance.model.Bundle(); copyResource(src, tgt); tgt.setType(convertBundleType(src.getType())); if (src.hasTotal()) tgt.setTotal(src.getTotal()); for (org.hl7.fhir.dstu3.model.Bundle.BundleLinkComponent t : src.getLink()) tgt.addLink(convertBundleLinkComponent(t)); for (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent t : src.getEntry()) tgt.addEntry(convertBundleEntryComponent(t)); if (src.hasSignature()) tgt.setSignature(convertSignature(src.getSignature())); return tgt; }
@Override public void setProperty(String name, Base value) throws FHIRException { if (name.equals("type")) this.type = new BundleTypeEnumFactory().fromType(value); // Enumeration<BundleType> else if (name.equals("total")) this.total = castToUnsignedInt(value); // UnsignedIntType else if (name.equals("link")) this.getLink().add((BundleLinkComponent) value); else if (name.equals("entry")) this.getEntry().add((BundleEntryComponent) value); else if (name.equals("signature")) this.signature = castToSignature(value); // Signature else super.setProperty(name, value); }
@Override public Base addChild(String name) throws FHIRException { if (name.equals("type")) { throw new FHIRException("Cannot call addChild on a primitive type Bundle.type"); } else if (name.equals("total")) { throw new FHIRException("Cannot call addChild on a primitive type Bundle.total"); } else if (name.equals("link")) { return addLink(); } else if (name.equals("entry")) { return addEntry(); } else if (name.equals("signature")) { this.signature = new Signature(); return this.signature; } else return super.addChild(name); }
@Test public void testSendManualPdqmWithCount() { Bundle page1 = sendManuallyWithCount(familyParameters(), 2); assertEquals(Bundle.BundleType.SEARCHSET, page1.getType()); assertEquals(ResourceType.Bundle, page1.getResourceType()); assertTrue(page1.hasEntry()); assertEquals(3, page1.getTotal()); assertEquals(2, page1.getEntry().size()); Bundle page2 = nextPage(page1); assertEquals(Bundle.BundleType.SEARCHSET, page2.getType()); assertEquals(ResourceType.Bundle, page2.getResourceType()); assertTrue(page2.hasEntry()); assertEquals(3, page2.getTotal()); assertEquals(1, page2.getEntry().size()); } }
@Override public Object evaluate(Exchange exchange) { if (returnError) throw new InternalErrorException("Something went wrong"); Bundle requestBundle = exchange.getIn().getBody(Bundle.class); Bundle responseBundle = new Bundle() .setType(Bundle.BundleType.TRANSACTIONRESPONSE) .setTotal(requestBundle.getTotal()); for (Bundle.BundleEntryComponent requestEntry : requestBundle.getEntry()) { Bundle.BundleEntryResponseComponent response = new Bundle.BundleEntryResponseComponent() .setStatus("201 Created") .setLastModified(new Date()) .setLocation(requestEntry.getResource().getClass().getSimpleName() + "/" + 4711); responseBundle.addEntry() .setResponse(response) .setResource(responseResource(requestEntry.getResource())); } return responseBundle; }
private void loadValueSets(FhirContext theContext, Map<String, ValueSet> theValueSets, String theFile) { InputStream valuesetText = DefaultProfileValidationSupport.class.getResourceAsStream(theFile); try { if (valuesetText != null) { InputStreamReader reader = null; try { reader = new InputStreamReader(valuesetText, "UTF-8"); FhirContext ctx = FhirInstanceValidator.getHl7OrgDstu2Ctx(theContext); Bundle bundle = ctx.newXmlParser().parseResource(Bundle.class, reader); for (BundleEntryComponent next : bundle.getEntry()) { ValueSet nextValueSet = (ValueSet) next.getResource(); String system = nextValueSet.getCodeSystem().getSystem(); if (isNotBlank(system)) { theValueSets.put(system, nextValueSet); } } } catch (UnsupportedEncodingException e) { // Shouldn't happen! throw new InternalErrorException("UTF-8 encoding not supported on this platform", e); } finally { IOUtils.closeQuietly(reader); } } } finally { IOUtils.closeQuietly(valuesetText); } }
ensureBundle(); if (myBundle.getIdElement().isEmpty()) { myBundle.setId(theId); if (isBlank(myBundle.getId())) { myBundle.setId(UUID.randomUUID().toString()); if (myBundle.getMeta().getLastUpdated() == null) { InstantType instantType = new InstantType(); instantType.setValueAsString(theLastUpdated.getValueAsString()); myBundle.getMeta().setLastUpdatedElement(instantType); myBundle.addLink().setRelation(Constants.LINK_SELF).setUrl(theLinkSelf); myBundle.addLink().setRelation(Constants.LINK_NEXT).setUrl(theLinkNext); myBundle.addLink().setRelation(Constants.LINK_PREVIOUS).setUrl(theLinkPrev); if (myBundle.getTypeElement().isEmpty() && theBundleType != null) { myBundle.getTypeElement().setValueAsString(theBundleType.getCode()); if (myBundle.getTotalElement().isEmpty() && theTotalResults != null) { myBundle.getTotalElement().setValue(theTotalResults);
protected Bundle provideAndRegister() throws Exception { Bundle bundle = new Bundle().setType(Bundle.BundleType.TRANSACTION); bundle.getMeta().addProfile(Iti65Constants.ITI65_PROFILE); manifest.addContent() .setP(new Reference(REFERENCE_FULL_URL)); bundle.addEntry() .setRequest( new Bundle.BundleEntryRequestComponent() .setCode("urn:ihe:pcc:handp:2008") .setSystem("urn:oid:1.3.6.1.4.1.19376.1.2.3"); bundle.addEntry() .setFullUrl(REFERENCE_FULL_URL) .setRequest( binary.getMeta().setLastUpdated(timestamp); bundle.addEntry() .setFullUrl(BINARY_FULL_URL) .setRequest(new Bundle.BundleEntryRequestComponent()
/** * Validates bundle type, meta data and consistency of contained resources * * @param bundle transaction bundle */ protected void validateTransactionBundle(Bundle bundle) { if (!Bundle.BundleType.TRANSACTION.equals(bundle.getType())) { throw FhirUtils.unprocessableEntity( OperationOutcome.IssueSeverity.ERROR, OperationOutcome.IssueType.INVALID, null, null, "Bundle type must be %s, but was %s", Bundle.BundleType.TRANSACTION.toCode(), bundle.getType().toCode()); } List<UriType> profiles = bundle.getMeta().getProfile(); if (profiles.isEmpty() || !Iti65Constants.ITI65_PROFILE.equals(profiles.get(0).getValue())) { throw FhirUtils.unprocessableEntity( OperationOutcome.IssueSeverity.ERROR, OperationOutcome.IssueType.INVALID, null, null, "Request bundle must have profile", Iti65Constants.ITI65_PROFILE); } }
@Test public void testSendManualPdqmWithBirthdayRange() { Bundle result = client.search() .forResource(PdqPatient.class) .where(PdqPatient.BIRTHDATE.exactly().day("2011-12-31")) .and(PdqPatient.FAMILY.matches().value("Miller")) .returnBundle(Bundle.class) .execute(); assertEquals(Bundle.BundleType.SEARCHSET, result.getType()); assertEquals(ResourceType.Bundle, result.getResourceType()); assertTrue(result.hasEntry()); }
private void ensureBundle() { if (myBundle == null) { myBundle = new Bundle(); } }
public Bundle copy() { Bundle dst = new Bundle(); copyValues(dst); dst.type = type == null ? null : type.copy(); dst.total = total == null ? null : total.copy(); if (link != null) { dst.link = new ArrayList<BundleLinkComponent>(); for (BundleLinkComponent i : link) dst.link.add(i.copy()); }; if (entry != null) { dst.entry = new ArrayList<BundleEntryComponent>(); for (BundleEntryComponent i : entry) dst.entry.add(i.copy()); }; dst.signature = signature == null ? null : signature.copy(); return dst; }
private boolean hasLink(String theLinkType, Bundle theBundle) { for (BundleLinkComponent next : theBundle.getLink()) { if (theLinkType.equals(next.getRelation())) { return true; } } return false; }
@Test public void testSendIti66WithPatientReference() { Bundle result = sendManually(manifestPatientReferenceParameter()); assertEquals(Bundle.BundleType.SEARCHSET, result.getType()); assertEquals(ResourceType.Bundle, result.getResourceType()); assertEquals(1, result.getTotal()); DocumentManifest p = (DocumentManifest) result.getEntry().get(0).getResource(); assertEquals("9bc72458-49b0-11e6-8a1c-3c1620524153", p.getIdElement().getIdPart()); }
for (BundleEntryComponent next : bundle.getEntry()) { IdType nextId = new IdType(next.getFullUrl()); if (nextId.isEmpty() || !nextId.getValue().startsWith("http://hl7.org/fhir/ValueSet/")) {
@Override public void setProperty(String name, Base value) throws FHIRException { if (name.equals("type")) this.type = new BundleTypeEnumFactory().fromType(value); // Enumeration<BundleType> else if (name.equals("total")) this.total = castToUnsignedInt(value); // UnsignedIntType else if (name.equals("link")) this.getLink().add((BundleLinkComponent) value); else if (name.equals("entry")) this.getEntry().add((BundleEntryComponent) value); else if (name.equals("signature")) this.signature = castToSignature(value); // Signature else super.setProperty(name, value); }
ensureBundle(); if (myBundle.getIdElement().isEmpty()) { myBundle.setId(theId); if (isBlank(myBundle.getId())) { myBundle.setId(UUID.randomUUID().toString()); if (myBundle.getMeta().getLastUpdated() == null) { InstantType instantType = new InstantType(); instantType.setValueAsString(theLastUpdated.getValueAsString()); myBundle.getMeta().setLastUpdatedElement(instantType); myBundle.addLink().setRelation(Constants.LINK_SELF).setUrl(theLinkSelf); myBundle.addLink().setRelation(Constants.LINK_NEXT).setUrl(theLinkNext); myBundle.addLink().setRelation(Constants.LINK_PREVIOUS).setUrl(theLinkPrev); if (myBundle.getTypeElement().isEmpty() && theBundleType != null) { myBundle.getTypeElement().setValueAsString(theBundleType.getCode()); if (myBundle.getTotalElement().isEmpty() && theTotalResults != null) { myBundle.getTotalElement().setValue(theTotalResults);