Package ca.uhn.fhir.util
Class BundleUtil
java.lang.Object
ca.uhn.fhir.util.BundleUtil
Fetch resources from a bundle
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic List<org.apache.commons.lang3.tuple.Pair<String,IBaseResource>>getBundleEntryUrlsAndResources(FhirContext theContext, IBaseBundle theBundle)static StringgetBundleType(FhirContext theContext, IBaseBundle theBundle)static StringgetLinkUrlOfType(FhirContext theContext, IBaseBundle theBundle, String theLinkRelation)static IntegergetTotal(FhirContext theContext, IBaseBundle theBundle)static booleanisDstu3TransactionPatch(FhirContext theContext, IBaseResource thePayloadResource)DSTU3 did not allow the PATCH verb for transaction bundles- so instead we infer that a bundle is a patch if the payload is a binary resource containing a patch.static voidprocessEntries(FhirContext theContext, IBaseBundle theBundle, Consumer<ModifiableBundleEntry> theProcessor)Given a bundle, and a consumer, apply the consumer to each entry in the bundle.static voidsetBundleType(FhirContext theContext, IBaseBundle theBundle, String theType)static voidsetTotal(FhirContext theContext, IBaseBundle theBundle, Integer theTotal)static voidsortEntriesIntoProcessingOrder(FhirContext theContext, IBaseBundle theBundle)Function which will do an in-place sort of a bundles' entries, to the correct processing order, which is: 1.static List<BundleEntryParts>toListOfEntries(FhirContext theContext, IBaseBundle theBundle)Extract all of the resources from a given bundletoListOfResourceIds(FhirContext theContext, IBaseBundle theBundle)Extract all of ids of all the resources from a given bundlestatic List<IBaseResource>toListOfResources(FhirContext theContext, IBaseBundle theBundle)Extract all of the resources from a given bundlestatic <T extends IBaseResource>
List<T>toListOfResourcesOfType(FhirContext theContext, IBaseBundle theBundle, Class<T> theTypeToInclude)Extract all of the resources of a given type from a given bundle
-
Constructor Details
-
BundleUtil
public BundleUtil()
-
-
Method Details
-
getLinkUrlOfType
public static String getLinkUrlOfType(FhirContext theContext, IBaseBundle theBundle, String theLinkRelation)- Returns:
- Returns
nullif the link isn't found or has no value
-
getBundleEntryUrlsAndResources
public static List<org.apache.commons.lang3.tuple.Pair<String,IBaseResource>> getBundleEntryUrlsAndResources(FhirContext theContext, IBaseBundle theBundle) -
getBundleType
-
setBundleType
-
getTotal
-
setTotal
-
toListOfEntries
public static List<BundleEntryParts> toListOfEntries(FhirContext theContext, IBaseBundle theBundle)Extract all of the resources from a given bundle -
sortEntriesIntoProcessingOrder
public static void sortEntriesIntoProcessingOrder(FhirContext theContext, IBaseBundle theBundle) throws IllegalStateExceptionFunction which will do an in-place sort of a bundles' entries, to the correct processing order, which is: 1. Deletes 2. Creates 3. Updates Furthermore, within these operation types, the entries will be sorted based on the order in which they should be processed e.g. if you have 2 CREATEs, one for a Patient, and one for an Observation which has this Patient as its Subject, the patient will come first, then the observation. In cases of there being a cyclic dependency (e.g. Organization/1 is partOf Organization/2 and Organization/2 is partOf Organization/1) this function will throw an IllegalStateException.- Parameters:
theContext- The FhirContext.theBundle- TheIBaseBundlewhich contains the entries you would like sorted into processing order.- Throws:
IllegalStateException
-
processEntries
public static void processEntries(FhirContext theContext, IBaseBundle theBundle, Consumer<ModifiableBundleEntry> theProcessor)Given a bundle, and a consumer, apply the consumer to each entry in the bundle.- Parameters:
theContext- The FHIR ContexttheBundle- The bundle to have its entries processed.theProcessor- aConsumerwhich will operate on all the entries of a bundle.
-
toListOfResources
Extract all of the resources from a given bundle -
toListOfResourceIds
Extract all of ids of all the resources from a given bundle -
toListOfResourcesOfType
public static <T extends IBaseResource> List<T> toListOfResourcesOfType(FhirContext theContext, IBaseBundle theBundle, Class<T> theTypeToInclude)Extract all of the resources of a given type from a given bundle -
isDstu3TransactionPatch
public static boolean isDstu3TransactionPatch(FhirContext theContext, IBaseResource thePayloadResource)DSTU3 did not allow the PATCH verb for transaction bundles- so instead we infer that a bundle is a patch if the payload is a binary resource containing a patch. This method tests whether a resource (which should have come fromBundle.entry.resourceis a Binary resource with a patch payload type.
-