private Bundle batch(final RequestDetails theRequestDetails, Bundle theRequest) { ourLog.info("Beginning batch with {} resources", theRequest.getEntry().size()); long start = System.currentTimeMillis(); txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); Bundle resp = new Bundle(); resp.setType(BundleTypeEnum.BATCH_RESPONSE); for (final Entry nextRequestEntry : theRequest.getEntry()) { Entry subResponseEntry = nextResponseBundle.getEntry().get(0); resp.addEntry(subResponseEntry); subResponseEntry.setResource(nextResponseBundle.getEntry().get(0).getResource()); Entry nextEntry = resp.addEntry();
@Override public void addRootPropertiesToBundle(String theId, String theServerBase, String theLinkSelf, String theLinkPrev, String theLinkNext, Integer theTotalResults, BundleTypeEnum theBundleType, IPrimitiveType<Date> theLastUpdated) { myBase = theServerBase; if (myBundle.getIdElement().isEmpty()) { myBundle.setId(theId); } if (myBundle.getId().isEmpty()) { myBundle.setId(UUID.randomUUID().toString()); } if (ResourceMetadataKeyEnum.UPDATED.get(myBundle) == null) { ResourceMetadataKeyEnum.UPDATED.put(myBundle, (InstantDt) theLastUpdated); } if (!hasLink(Constants.LINK_SELF, myBundle) && isNotBlank(theLinkSelf)) { myBundle.addLink().setRelation(Constants.LINK_SELF).setUrl(theLinkSelf); } if (!hasLink(Constants.LINK_NEXT, myBundle) && isNotBlank(theLinkNext)) { myBundle.addLink().setRelation(Constants.LINK_NEXT).setUrl(theLinkNext); } if (!hasLink(Constants.LINK_PREVIOUS, myBundle) && isNotBlank(theLinkPrev)) { 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); } }
private boolean hasLink(String theLinkType, Bundle theBundle) { for (Link next : theBundle.getLink()) { if (theLinkType.equals(next.getRelation())) { return true; } } return false; }
@Override protected void preProcessResourceForStorage(Bundle theResource) { super.preProcessResourceForStorage(theResource); Set<String> allowedBundleTypes = getConfig().getBundleTypesAllowedForStorage(); if (!allowedBundleTypes.contains(defaultString(theResource.getType()))) { String message = "Unable to store a Bundle resource on this server with a Bundle.type value of: " + (theResource.getType() != null ? theResource.getType() : "(missing)"); throw new UnprocessableEntityException(message); } for (Entry next : theResource.getEntry()) { next.setFullUrl((String)null); } }
public static void main(String[] args) throws Exception { FhirContext ctx = FhirContext.forDstu2(); String serverBase = "http://fhirtest.uhn.ca/baseDstu2"; IGenericClient client = ctx.newRestfulGenericClient(serverBase); // use RelatedPerson because there aren't that many on the server Bundle bundle = client.search().forResource(RelatedPerson.class).returnBundle(Bundle.class).execute(); BundleFetcher.fetchRestOfBundle(client, bundle); if (bundle.getTotal() != bundle.getEntry().size()) { System.out.println("Counts didn't match! Expected " + bundle.getTotal() + " but bundle only had " + bundle.getEntry().size() + " entries!"); } // IParser parser = ctx.newXmlParser().setPrettyPrint(true); // System.out.println(parser.encodeResourceToString(bundle)); } }
private static void addAnyResourcesNotAlreadyPresentToBundle(Bundle theAggregatedBundle, Bundle thePartialBundle, Set<String> theResourcesAlreadyAdded) { for (Bundle.Entry entry : thePartialBundle.getEntry()) { if (!theResourcesAlreadyAdded.contains(entry.getFullUrl())) { theResourcesAlreadyAdded.add(entry.getFullUrl()); theAggregatedBundle.getEntry().add(entry); } } }
@Override public void initializeBundleFromResourceList(String theAuthor, List<? extends IBaseResource> theResources, String theServerBase, String theCompleteUrl, int theTotalResults, BundleTypeEnum theBundleType) { myBundle = new Bundle(); myBundle.setId(UUID.randomUUID().toString()); myBundle.addLink().setRelation(Constants.LINK_FHIR_BASE).setUrl(theServerBase); myBundle.addLink().setRelation(Constants.LINK_SELF).setUrl(theCompleteUrl); myBundle.getTypeElement().setValueAsString(theBundleType.getCode()); Entry nextEntry = myBundle.addEntry(); myBundle.getTotalElement().setValue(theTotalResults);
private Bundle getBundleFromFileDstu2(Integer limit, File inputFile, FhirContext ctx) throws IOException, UnsupportedEncodingException { Bundle bundle = new Bundle(); bundle.addEntry().setRequest(new EntryRequest().setMethod(HTTPVerbEnum.POST)).setResource((IResource) nextResource); continue; bundle.addEntry().setRequest(new EntryRequest().setMethod(HTTPVerbEnum.POST)).setResource((IResource) parsed);
/** * Gets the first repetition for <b>entry</b> (), * creating it if it does not already exist. * * <p> * <b>Definition:</b> * An entry in a bundle resource - will either contain a resource, or information about a resource (transactions and history only) * </p> */ public Entry getEntryFirstRep() { if (getEntry().isEmpty()) { return addEntry(); } return getEntry().get(0); }
@Operation(name="$everything", idempotent=true) public Bundle patientTypeOperation( @OperationParam(name="start") DateDt theStart, @OperationParam(name="end") DateDt theEnd) { Bundle retVal = new Bundle(); // Populate bundle with matching resources return retVal; } //END SNIPPET: patientTypeOperation
@SuppressWarnings("unchecked") private Bundle doTransaction(ServletRequestDetails theRequestDetails, Bundle theRequest, String theActionName) { BundleTypeEnum transactionType = theRequest.getTypeElement().getValueAsEnum(); if (transactionType == BundleTypeEnum.BATCH) { return batch(theRequestDetails, theRequest); } return doTransaction(theRequestDetails, theRequest, theActionName, transactionType); }
Bundle extras = intent.getExtras(); int id = extras.getId( "selection" );
/** * Sets the value(s) for <b>type</b> () * * <p> * <b>Definition:</b> * Indicates the purpose of this bundle- how it was intended to be used * </p> */ public Bundle setType(BundleTypeEnum theValue) { setType(new BoundCodeDt<BundleTypeEnum>(BundleTypeEnum.VALUESET_BINDER, theValue)); /* getTypeElement().setValueAsEnum(theValue); */ return this; }
private static void addInitialUrlsToSet(Bundle theBundle, Set<String> theResourcesAlreadyAdded) { for (Bundle.Entry entry : theBundle.getEntry()) { theResourcesAlreadyAdded.add(entry.getFullUrl()); } }
ensureBundle(); myBundle.setId(UUID.randomUUID().toString()); myBundle.addLink().setRelation(Constants.LINK_FHIR_BASE).setUrl(theServerBase); myBundle.addLink().setRelation(Constants.LINK_SELF).setUrl(theCompleteUrl); myBundle.getTypeElement().setValueAsString(theBundleType.getCode()); Entry nextEntry = myBundle.addEntry(); myBundle.getTotalElement().setValue(theTotalResults);
@Override public void addResourcesToBundle(List<IBaseResource> theResult, BundleTypeEnum theBundleType, String theServerBase, BundleInclusionRule theBundleInclusionRule, Set<Include> theIncludes) { if (myBundle == null) { myBundle = new Bundle(); Entry entry = myBundle.addEntry().setResource(next); BundleEntryTransactionMethodEnum httpVerb = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(next); if (httpVerb != null) { Entry entry = myBundle.addEntry(); entry.setResource(next).getSearch().setMode(SearchEntryModeEnum.INCLUDE); populateBundleEntryFullUrl(next, entry);
@Override protected void preProcessResourceForStorage(Bundle theResource) { super.preProcessResourceForStorage(theResource); Set<String> allowedBundleTypes = getConfig().getBundleTypesAllowedForStorage(); if (!allowedBundleTypes.contains(defaultString(theResource.getType()))) { String message = "Unable to store a Bundle resource on this server with a Bundle.type value of: " + (theResource.getType() != null ? theResource.getType() : "(missing)"); throw new UnprocessableEntityException(message); } for (Entry next : theResource.getEntry()) { next.setFullUrl((String)null); } }