count = 1; for (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent i : bundle.getEntry()) { org.hl7.fhir.r4.model.Resource next = i.getResource(); next.setId(next.getIdElement().toUnqualifiedVersionless()); count = 1; for (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent i : bundle.getEntry()) { org.hl7.fhir.r4.model.Resource next = i.getResource(); next.setId(next.getIdElement().toUnqualifiedVersionless()); count = 1; for (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent i : bundle.getEntry()) { org.hl7.fhir.r4.model.Resource next = i.getResource(); if (next.getIdElement().isIdPartValidLong()) { next.setIdElement(new org.hl7.fhir.r4.model.IdType("v2-" + next.getIdElement().getIdPart()));
BundleEntryComponent entry = myBundle.addEntry().setResource((Resource) next); Resource nextAsResource = (Resource) next; IIdType id = populateBundleEntryFullUrl(next, entry); entry.getRequest().getMethodElement().setValueAsString(httpVerb); if (id != null) { entry.getRequest().setUrl(id.getValue()); entry.getResponse().setStatus("201 Created"); } else if (isNotBlank(id.getVersionIdPart())) { entry.getResponse().setStatus("200 OK"); entry.getResponse().setEtag(RestfulServerUtils.createEtag(id.getVersionIdPart())); entry.getSearch().getModeElement().setValueAsString(searchMode); entry.setResource((Resource) next).getSearch().setMode(SearchEntryMode.INCLUDE); populateBundleEntryFullUrl(next, entry);
public BundleEntryComponent copy() { BundleEntryComponent dst = new BundleEntryComponent(); copyValues(dst); if (link != null) { dst.link = new ArrayList<BundleLinkComponent>(); for (BundleLinkComponent i : link) dst.link.add(i.copy()); }; dst.fullUrl = fullUrl == null ? null : fullUrl.copy(); dst.resource = resource == null ? null : resource.copy(); dst.search = search == null ? null : search.copy(); dst.request = request == null ? null : request.copy(); dst.response = response == null ? null : response.copy(); return dst; }
.flatMap(Collection::stream) .forEach(entry -> { if (ResourceType.DocumentReference == entry.getResource().getResourceType()) { if (!expectedReferenceFullUrls.remove(entry.getFullUrl())) { throw FhirUtils.unprocessableEntity( OperationOutcome.IssueSeverity.ERROR, null, null, "DocumentReference with URL %s is not referenced by any DocumentManifest", entry.getFullUrl() ); } else if (ResourceType.Binary == entry.getResource().getResourceType()) { if (!expectedBinaryFullUrls.remove(entry.getFullUrl())) { throw FhirUtils.unprocessableEntity( OperationOutcome.IssueSeverity.ERROR, null, null, "Binary with URL %s is not referenced by any DocumentReference", entry.getFullUrl() );
BundleEntryComponent entry = myBundle.addEntry().setResource((Resource) next); Resource nextAsResource = (Resource) next; IIdType id = populateBundleEntryFullUrl(next, entry); entry.getRequest().getMethodElement().setValueAsString(httpVerb); if (id != null) { entry.getRequest().setUrl(id.getValue()); entry.getResponse().setStatus("201 Created"); } else if (isNotBlank(id.getVersionIdPart())) { entry.getResponse().setStatus("200 OK"); entry.getResponse().setEtag(RestfulServerUtils.createEtag(id.getVersionIdPart())); entry.getSearch().getModeElement().setValueAsString(searchMode); entry.setResource((Resource) next).getSearch().setMode(SearchEntryMode.INCLUDE); populateBundleEntryFullUrl(next, entry);
BundleEntryComponent entry = myBundle.addEntry().setResource(next); if (next.getIdElement().hasBaseUrl()) { entry.setFullUrl(next.getId()); entry.getRequest().getMethodElement().setValueAsString(httpVerb); entry.getRequest().getUrlElement().setValue(next.getId()); entry.setResource((Resource) next).getSearch().setMode(SearchEntryMode.INCLUDE); if (next.getIdElement().hasBaseUrl()) { entry.setFullUrl(next.getIdElement().getValue());
Bundle bundle = new Bundle().setType(Bundle.BundleType.DOCUMENT); for (IBaseResource resource : resourceList) { bundle.addEntry(new Bundle.BundleEntryComponent().setResource((Resource) resource));
BundleEntryComponent nextEntry = myBundle.addEntry(); nextEntry.setResource(next); if (next.getIdElement().isEmpty()) { nextEntry.getRequest().setMethod(HTTPVerb.POST); } else { nextEntry.getRequest().setMethod(HTTPVerb.PUT); if (next.getIdElement().isAbsolute()) { nextEntry.getRequest().setUrl(next.getId()); } else { String resourceType = myContext.getResourceDefinition(next).getName(); nextEntry.getRequest().setUrl(new IdType(theServerBase, resourceType, next.getIdElement().getIdPart(), next.getIdElement().getVersionIdPart()).getValue());
for (int i = c; i < Math.min(b.getEntry().size(), c+size); i++) { BundleEntryComponent be = bt.addEntry(); be.setResource(b.getEntry().get(i).getResource()); be.getRequest().setMethod(HTTPVerb.PUT); be.getRequest().setUrl(be.getResource().getResourceType().toString()+"/"+be.getResource().getId()); if (!t.getResponse().getStatus().startsWith("2")) { System.out.println("failed status at "+Integer.toString(i)+": "+t.getResponse().getStatus()); return c+i;
@Override public Base addChild(String name) throws FHIRException { if (name.equals("link")) { return addLink(); } else if (name.equals("fullUrl")) { throw new FHIRException("Cannot call addChild on a primitive type Bundle.fullUrl"); } else if (name.equals("resource")) { throw new FHIRException("Cannot call addChild on an abstract type Bundle.resource"); } else if (name.equals("search")) { this.search = new BundleEntrySearchComponent(); return this.search; } else if (name.equals("request")) { this.request = new BundleEntryRequestComponent(); return this.request; } else if (name.equals("response")) { this.response = new BundleEntryResponseComponent(); return this.response; } else return super.addChild(name); }
/** * Returns the {@link #getLink() link} which matches a given {@link BundleLinkComponent#getRelation() relation}. * If no link is found which matches the given relation, creates a new BundleLinkComponent with the * given relation and adds it to this Bundle. If more than one * link is found which matches the given relation, returns the first matching BundleLinkComponent. * * @param theRelation * The relation, such as "next", or "self. See the constants such as {@link IBaseBundle#LINK_SELF} and {@link IBaseBundle#LINK_NEXT}. * @return Returns a matching BundleLinkComponent, or <code>null</code> * @see IBaseBundle#LINK_NEXT * @see IBaseBundle#LINK_PREV * @see IBaseBundle#LINK_SELF */ public BundleLinkComponent getLinkOrCreate(String theRelation) { org.apache.commons.lang3.Validate.notBlank(theRelation, "theRelation may not be null or empty"); for (BundleLinkComponent next : getLink()) { if (theRelation.equals(next.getRelation())) { return next; } } BundleLinkComponent retVal = new BundleLinkComponent(); retVal.setRelation(theRelation); getLink().add(retVal); return retVal; } protected void listChildren(List<Property> children) {
@Override public Base setProperty(int hash, String name, Base value) throws FHIRException { switch (hash) { case 3321850: // link this.getLink().add((BundleLinkComponent) value); // BundleLinkComponent return value; case -511251360: // fullUrl this.fullUrl = castToUri(value); // UriType return value; case -341064690: // resource this.resource = castToResource(value); // Resource return value; case -906336856: // search this.search = (BundleEntrySearchComponent) value; // BundleEntrySearchComponent return value; case 1095692943: // request this.request = (BundleEntryRequestComponent) value; // BundleEntryRequestComponent return value; case -340323263: // response this.response = (BundleEntryResponseComponent) value; // BundleEntryResponseComponent return value; default: return super.setProperty(hash, name, value); } }
/** * Converts a {@link Bundle} into a map grouped by the entry resources types * * @param bundle Bundle * @return map of entries grouped by their resource type */ public static Map<ResourceType, List<Bundle.BundleEntryComponent>> getBundleEntries(Bundle bundle) { return bundle.getEntry().stream() .collect(Collectors.groupingBy(entry -> { Bundle.BundleEntryRequestComponent request = entry.getRequest(); if (request == null || request.getUrl() == null) { throw unprocessableEntity( OperationOutcome.IssueSeverity.ERROR, OperationOutcome.IssueType.INVALID, null, null, "Invalid bundle entry request element %s", entry); } return entry.getResource().getResourceType(); } , LinkedHashMap::new, Collectors.toList())); }
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(); }
/** * Returns the {@link #getLink() link} which matches a given {@link BundleLinkComponent#getRelation() relation}. * If no link is found which matches the given relation, returns <code>null</code>. If more than one * link is found which matches the given relation, returns the first matching BundleLinkComponent. * * @param theRelation * The relation, such as "next", or "self. See the constants such as {@link IBaseBundle#LINK_SELF} and {@link IBaseBundle#LINK_NEXT}. * @return Returns a matching BundleLinkComponent, or <code>null</code> * @see IBaseBundle#LINK_NEXT * @see IBaseBundle#LINK_PREV * @see IBaseBundle#LINK_SELF */ public BundleLinkComponent getLink(String theRelation) { org.apache.commons.lang3.Validate.notBlank(theRelation, "theRelation may not be null or empty"); for (BundleLinkComponent next : getLink()) { if (theRelation.equals(next.getRelation())) { return next; } } return null; }
private void loadStructureDefinitions(FhirContext theContext, Map<String, StructureDefinition> theCodeSystems, String theClasspath) { ourLog.info("Loading structure definitions from classpath: {}", theClasspath); InputStream valuesetText = DefaultProfileValidationSupport.class.getResourceAsStream(theClasspath); if (valuesetText != null) { InputStreamReader reader = new InputStreamReader(valuesetText, Constants.CHARSET_UTF8); Bundle bundle = theContext.newXmlParser().parseResource(Bundle.class, reader); for (BundleEntryComponent next : bundle.getEntry()) { if (next.getResource() instanceof StructureDefinition) { StructureDefinition nextSd = (StructureDefinition) next.getResource(); nextSd.getText().setDivAsString(""); String system = nextSd.getUrl(); if (isNotBlank(system)) { theCodeSystems.put(system, nextSd); } } } } else { ourLog.warn("Unable to load resource: {}", theClasspath); } }
public org.hl7.fhir.instance.model.Bundle.BundleEntryComponent convertBundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; if (advisor.ignoreEntry(src)) return null; org.hl7.fhir.instance.model.Bundle.BundleEntryComponent tgt = new org.hl7.fhir.instance.model.Bundle.BundleEntryComponent(); copyElement(src, tgt); for (org.hl7.fhir.r4.model.Bundle.BundleLinkComponent t : src.getLink()) tgt.addLink(convertBundleLinkComponent(t)); tgt.setFullUrl(src.getFullUrl()); org.hl7.fhir.instance.model.Resource res = advisor.convertR2(src.getResource()); if (res == null) res = convertResource(src.getResource()); tgt.setResource(res); if (src.hasSearch()) tgt.setSearch(convertBundleEntrySearchComponent(src.getSearch())); if (src.hasRequest()) tgt.setRequest(convertBundleEntryRequestComponent(src.getRequest())); if (src.hasResponse()) tgt.setResponse(convertBundleEntryResponseComponent(src.getResponse())); return tgt; }
@Override public void validateRequest(FhirContext context, Object payload, Map<String, Object> parameters) { Bundle transactionBundle = (Bundle) payload; validateTransactionBundle(transactionBundle); validateBundleConsistency(transactionBundle); for (Bundle.BundleEntryComponent entry : transactionBundle.getEntry()) { Class<? extends IBaseResource> clazz = entry.getResource().getClass(); if (VALIDATORS.containsKey(clazz)) { FhirValidator validator = context.newValidator(); validator.registerValidatorModule(VALIDATORS.get(clazz)); ValidationResult validationResult = validator.validateWithResult(entry.getResource()); if (!validationResult.isSuccessful()) { IBaseOperationOutcome operationOutcome = validationResult.toOperationOutcome(); throw FhirUtils.exception(UnprocessableEntityException::new, operationOutcome, "Validation Failed"); } } } }
private static void LoadZipFile(String server, String file, IParser p, int size, int start, int end) throws IOException, Exception { System.out.println("Load Zip file "+file); Bundle b = new Bundle(); b.setType(BundleType.COLLECTION); b.setId(UUID.randomUUID().toString().toLowerCase()); ZipInputStream zip = new ZipInputStream(new FileInputStream(file)); ZipEntry entry; while((entry = zip.getNextEntry())!=null) { try { Resource r = p.parse(zip); b.addEntry().setResource(r); } catch (Exception e) { throw new Exception("Error parsing "+entry.getName()+": "+e.getMessage(), e); } } loadBundle(server, b, size, start, end); }
@Override public Base setProperty(String name, Base value) throws FHIRException { if (name.equals("link")) { this.getLink().add((BundleLinkComponent) value); } else if (name.equals("fullUrl")) { this.fullUrl = castToUri(value); // UriType } else if (name.equals("resource")) { this.resource = castToResource(value); // Resource } else if (name.equals("search")) { this.search = (BundleEntrySearchComponent) value; // BundleEntrySearchComponent } else if (name.equals("request")) { this.request = (BundleEntryRequestComponent) value; // BundleEntryRequestComponent } else if (name.equals("response")) { this.response = (BundleEntryResponseComponent) value; // BundleEntryResponseComponent } else return super.setProperty(name, value); return value; }