Package com.ibm.fhir.model.util
Class FHIRUtil
- java.lang.Object
-
- com.ibm.fhir.model.util.FHIRUtil
-
public class FHIRUtil extends Object
Utility methods for working with the FHIR object model.
-
-
Field Summary
Fields Modifier and Type Field Description static OperationOutcome
ALL_OK
static Extension
DATA_ABSENT_REASON_UNKNOWN
static Pattern
REFERENCE_PATTERN
static String
STRING_DATA_ABSENT_REASON_UNKNOWN
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Resource>
TaddTag(T resource, Coding tag)
Return a copy of resourceresource
with tagtag
static URI
buildLocationURI(String type, Resource resource)
Builds a relative "Location" header value for the specified resource.static OperationOutcome
buildOperationOutcome(FHIRException e, boolean includeCausedByClauses)
Build an OperationOutcome with an id from exception e and a single issue of type 'exception' and severity 'fatal'.static OperationOutcome
buildOperationOutcome(FHIROperationException e, boolean includeCausedByClauses)
Build an OperationOutcome with an id and a list of issues from exception e.static OperationOutcome
buildOperationOutcome(Exception exception, boolean includeCausedByClauses)
Build an OperationOutcome for the specified exception with a single issue of type 'exception' and severity 'fatal'.static OperationOutcome
buildOperationOutcome(Exception exception, IssueType issueType, IssueSeverity severity, boolean includeCausedByClauses)
Build an OperationOutcome for the specified exception.static OperationOutcome
buildOperationOutcome(String message, IssueType issueType, IssueSeverity severity)
Build an OperationOutcome for the specified exception.static OperationOutcome
buildOperationOutcome(Collection<OperationOutcome.Issue> issues)
Build an OperationOutcome that contains the specified list of operation outcome issues.static OperationOutcome.Issue
buildOperationOutcomeIssue(IssueSeverity severity, IssueType code, String details)
static OperationOutcome.Issue
buildOperationOutcomeIssue(IssueSeverity severity, IssueType code, String details, String expression)
static OperationOutcome.Issue
buildOperationOutcomeIssue(String msg, IssueType code)
static Bundle
createStandaloneBundle(BundleType bundleType, Map<String,Resource> resources)
Create a self-contained bundle from the passed map of resources, replacing Resource.id values and references with a generated UUID.static String
getExtensionStringValue(Resource resource, String extensionUrl)
Returns the string value of the specified extension element within the specified resource.static String
getExtensionStringValue(Element element, String extensionUrl)
Returns the string value of the specified extension element within the specified element.static boolean
hasTag(Resource resource, Coding tag)
static void
init()
Loads the class in the classloader in order to initialize static members.static boolean
isFailure(IssueSeverity severity)
Determine if the given severity should be treated as a failurestatic Bundle.Entry
resolveBundleReference(Bundle bundle, Bundle.Entry sourceEntry, Reference ref)
Resolve the referenceref
to an entry withinbundle
static <T extends Resource>
TresolveBundleReference(Class<T> resourceType, Bundle bundle, Bundle.Entry sourceEntry, Reference ref)
Resolve the referenceref
to an entry withinbundle
and return the corresponding resourcestatic Resource
resolveContainedReference(DomainResource resource, Reference ref)
Resolve the referenceref
to a bundle entry and return the corresponding resource containerstatic Resource
resolveReference(Reference ref, DomainResource resource, Bundle bundle, Bundle.Entry entry)
Resolve referenceref
to a bundle entry or a resource contained withinresource
and return the corresponding resource container.static jakarta.json.JsonObjectBuilder
toJsonObjectBuilder(jakarta.json.JsonObject jsonObject)
static String
toString(Visitable visitable)
Converts a Visitable (Element or Resource) instance to a string using a FHIRGenerator.
-
-
-
Field Detail
-
REFERENCE_PATTERN
public static final Pattern REFERENCE_PATTERN
-
DATA_ABSENT_REASON_UNKNOWN
public static final Extension DATA_ABSENT_REASON_UNKNOWN
-
STRING_DATA_ABSENT_REASON_UNKNOWN
public static final String STRING_DATA_ABSENT_REASON_UNKNOWN
-
ALL_OK
public static final OperationOutcome ALL_OK
-
-
Method Detail
-
init
public static void init()
Loads the class in the classloader in order to initialize static members. Call this before using the class in order to avoid a slight performance hit on first use.
-
toString
public static String toString(Visitable visitable)
Converts a Visitable (Element or Resource) instance to a string using a FHIRGenerator.The toString format (JSON or XML) can be specified through
FHIRModelConfig.setToStringFormat(Format)
.- Parameters:
visitable
- the Element or Resource instance to be converted- Returns:
- the String version of the element or resource
-
toJsonObjectBuilder
public static jakarta.json.JsonObjectBuilder toJsonObjectBuilder(jakarta.json.JsonObject jsonObject)
-
buildOperationOutcomeIssue
public static OperationOutcome.Issue buildOperationOutcomeIssue(String msg, IssueType code)
-
buildOperationOutcomeIssue
public static OperationOutcome.Issue buildOperationOutcomeIssue(IssueSeverity severity, IssueType code, String details)
-
buildOperationOutcomeIssue
public static OperationOutcome.Issue buildOperationOutcomeIssue(IssueSeverity severity, IssueType code, String details, String expression)
-
buildOperationOutcome
public static OperationOutcome buildOperationOutcome(Collection<OperationOutcome.Issue> issues)
Build an OperationOutcome that contains the specified list of operation outcome issues.
-
buildOperationOutcome
public static OperationOutcome buildOperationOutcome(FHIROperationException e, boolean includeCausedByClauses)
Build an OperationOutcome with an id and a list of issues from exception e.
-
buildOperationOutcome
public static OperationOutcome buildOperationOutcome(FHIRException e, boolean includeCausedByClauses)
Build an OperationOutcome with an id from exception e and a single issue of type 'exception' and severity 'fatal'.
-
buildOperationOutcome
public static OperationOutcome buildOperationOutcome(Exception exception, boolean includeCausedByClauses)
Build an OperationOutcome for the specified exception with a single issue of type 'exception' and severity 'fatal'.
-
buildOperationOutcome
public static OperationOutcome buildOperationOutcome(Exception exception, IssueType issueType, IssueSeverity severity, boolean includeCausedByClauses)
Build an OperationOutcome for the specified exception.
-
buildOperationOutcome
public static OperationOutcome buildOperationOutcome(String message, IssueType issueType, IssueSeverity severity)
Build an OperationOutcome for the specified exception.- Parameters:
issueType
- defaults to IssueTypeList.EXCEPTIONseverity
- defaults to IssueSeverityList.FATAL
-
buildLocationURI
public static URI buildLocationURI(String type, Resource resource)
Builds a relative "Location" header value for the specified resource. This will be a string of the form"
. Note that the server will turn this into an absolute URL prior to returning it to the client./ /_history/ " - Parameters:
resource
- the resource for which the location header value should be returned
-
resolveReference
public static Resource resolveReference(Reference ref, DomainResource resource, Bundle bundle, Bundle.Entry entry) throws Exception
Resolve referenceref
to a bundle entry or a resource contained withinresource
and return the corresponding resource container. Resolvingref
to a resource that exists outside of the bundle is not yet supported, but this support may be added in the future.- Throws:
Exception
- if the resource could not be found, the reference has no value, or the value does not match the expected format for a reference
-
resolveContainedReference
public static Resource resolveContainedReference(DomainResource resource, Reference ref) throws Exception
Resolve the referenceref
to a bundle entry and return the corresponding resource container- Throws:
Exception
- if the resource could not be found, the reference has no value, or the value does not match the expected format for a contained reference
-
resolveBundleReference
public static <T extends Resource> T resolveBundleReference(Class<T> resourceType, Bundle bundle, Bundle.Entry sourceEntry, Reference ref) throws Exception
Resolve the referenceref
to an entry withinbundle
and return the corresponding resource- Parameters:
resourceType
-bundle
-sourceEntry
- allowed to be null if and only if the reference is absoluteref
-- Throws:
Exception
- if the resource could not be found, the reference has no value, or the value does not match the expected format for a bundle referenceClassCastException
- if the referenced resource cannot be cast to typeresourceType
-
resolveBundleReference
public static Bundle.Entry resolveBundleReference(Bundle bundle, Bundle.Entry sourceEntry, Reference ref) throws FHIRException, URISyntaxException
Resolve the referenceref
to an entry withinbundle
- Parameters:
bundle
-sourceEntry
- allowed to be null if and only if the reference is absoluteref
-- Throws:
FHIRException
- if the resource could not be found or the reference has no valueURISyntaxException
- if theref
value is not a valid URIIllegalArgumentException
- ifref
contains a fragment reference
-
getExtensionStringValue
public static String getExtensionStringValue(Resource resource, String extensionUrl)
Returns the string value of the specified extension element within the specified resource.- Parameters:
resource
-extensionUrl
-- Returns:
- the value of the first such extension with a valueString or null if the resource has no such extensions
-
getExtensionStringValue
public static String getExtensionStringValue(Element element, String extensionUrl)
Returns the string value of the specified extension element within the specified element.- Parameters:
element
-extensionUrl
-- Returns:
- the value of the first such extension with a valueString or null if the resource has no such extensions
-
addTag
public static <T extends Resource> T addTag(T resource, Coding tag)
Return a copy of resourceresource
with tagtag
- Type Parameters:
T
-- Parameters:
resource
- the resource to add the tag tootag
- the tag to add- Returns:
- a copy of the resource with the new tag (if it didn't already exist), or the resource passed in if the tag is already present
-
isFailure
public static boolean isFailure(IssueSeverity severity)
Determine if the given severity should be treated as a failure- Parameters:
severity
-- Returns:
-
createStandaloneBundle
public static Bundle createStandaloneBundle(BundleType bundleType, Map<String,Resource> resources)
Create a self-contained bundle from the passed map of resources, replacing Resource.id values and references with a generated UUID.- Parameters:
bundleType
- The type of bundle to createresources
- A mapping from String identifiers to Resources. For resources with no logical id, the key can be any string- Returns:
- a Bundle with the passed resources with ids and references replaced by UUIDs
-
-