
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 IBase
createNewBundleEntryWithSingleField
(FhirContext theContext, String theFieldName, IBase... theValues) create a new bundle entry and set a value for a single fieldstatic List<org.apache.commons.lang3.tuple.Pair<String,
IBaseResource>> getBundleEntryUrlsAndResources
(FhirContext theContext, IBaseBundle theBundle) static String
getBundleType
(FhirContext theContext, IBaseBundle theBundle) static String
getLinkUrlOfType
(FhirContext theContext, IBaseBundle theBundle, String theLinkRelation) static List<SearchBundleEntryParts>
getSearchBundleEntryParts
(FhirContext theContext, IBaseBundle theBundle) static Integer
getTotal
(FhirContext theContext, IBaseBundle theBundle) 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.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.static void
setBundleType
(FhirContext theContext, IBaseBundle theBundle, String theType) static void
setTotal
(FhirContext theContext, IBaseBundle theBundle, Integer theTotal) static void
sortEntriesIntoProcessingOrder
(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
null
if 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
Extract all of the resources from a given bundle -
sortEntriesIntoProcessingOrder
public static void sortEntriesIntoProcessingOrder(FhirContext theContext, IBaseBundle theBundle) throws IllegalStateException Function 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
- TheIBaseBundle
which contains the entries you would like sorted into processing order.- Throws:
IllegalStateException
-
getSearchBundleEntryParts
public static List<SearchBundleEntryParts> getSearchBundleEntryParts(FhirContext theContext, IBaseBundle theBundle) -
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
- aConsumer
which 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.resource
is a Binary resource with a patch payload type. -
createNewBundleEntryWithSingleField
public static IBase createNewBundleEntryWithSingleField(FhirContext theContext, String theFieldName, IBase... theValues) create a new bundle entry and set a value for a single field- Parameters:
theContext
- Context holding resource definitiontheFieldName
- Child field name of the bundle entry to settheValues
- The values to set on the bundle entry child field name- Returns:
- the new bundle entry
-