Class ModelHelper
- java.lang.Object
-
- org.linuxforhealth.fhir.cql.helpers.ModelHelper
-
public class ModelHelper extends java.lang.Object
Utilities for working with FHIR model objects. This consists mainly of null-safe factory objects for creating FHIR types from Java types, but also some null-safe helpers for going the opposite direction (FHIR to Java), and some factory methods for creating resources that are commonly used in the execution of CQL and FHIR Quality Measure operations.
-
-
Constructor Summary
Constructors Constructor Description ModelHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Bundle
bundle(Resource... resources)
Factory method for constructing a SearchSet bundle from an array of resourcesstatic Bundle
bundle(BundleType type, Resource... resources)
Factory method for constructing a bundle from an array of resourcesstatic Canonical
canonical(java.lang.String uri)
Factory method for creating a Canonicalstatic Canonical
canonical(Library library)
Factory method for creating a Canonicalstatic Canonical
canonical(Measure measure)
Factory method for creating a Canonicalstatic Canonical
canonical(Uri uri)
Factory method for creating a Canonicalstatic Canonical
canonical(Uri uri, String version)
Factory method for creating a Canonicalstatic Coding
coding(java.lang.String code)
Factory method for creating a simple Coding object consisting only of a code valuestatic Coding
coding(java.lang.String codesystem, java.lang.String code)
Factory method for creating a simple Coding objectstatic Coding
coding(java.lang.String codesystem, java.lang.String code, java.lang.String display)
Factory method for creating a simple Coding objectstatic CodeableConcept
concept(java.lang.String code)
Factory method for creating a Concept consisting of a single Coding object with only a code valuestatic CodeableConcept
concept(java.lang.String codesystem, java.lang.String code)
Factory method for creating a Concept consisting of a single Coding objectstatic CodeableConcept
concept(Coding coding)
Factory method for creating a simple Concept objectstatic Boolean
fhirboolean(java.lang.Boolean bool)
Perform null-safe conversion of a Java boolean to a FHIR Stringstatic Code
fhircode(java.lang.String code)
Perform null-safe conversion of a Java String to a FHIR Codestatic Code
fhircode(org.opencds.cqf.cql.engine.runtime.Code code)
Convert a CQL Code object into a FHIR code objectstatic Integer
fhirinteger(java.lang.Integer value)
Perform null-safe conversion of a Java Integer to a FHIR Integerstatic String
fhirstring(java.lang.String str)
Perform null-safe conversion of a Java String to a FHIR Stringstatic Uri
fhiruri(java.lang.String uri)
Perform null-safe conversion of a Java String to a FHIR Uristatic java.util.Optional<Attachment>
getAttachmentByType(Library library, java.lang.String contentType)
Helper method for retrieving a Library attachment with a specific content type.static java.util.Optional<Extension>
getExtensionByUrl(Element element, java.lang.String url)
Retrieve the Element extension that matches the given URL.static java.util.Optional<java.lang.String>
getLinkByType(Bundle bundle, java.lang.String type)
Helper method for retrieving a Bundle link by a specific link type.static java.time.ZoneOffset
getZoneOffset(Element element)
For the given Element, retrieve the timezone offset from the Element's extensions based on HL7 tz-offset and tz-code extensions.static java.lang.Boolean
javaboolean(Boolean bool)
Perform null-safe conversion of a FHIR Boolean to a Java Booleanstatic java.lang.String
javastring(String str)
Perform null-safe conversion of a FHIR String to a Java Stringstatic java.lang.String
javastring(Uri uri)
Perform null-safe conversion of a FHIR Uri to a Java Stringstatic Reference
reference(Resource resource)
Factory method for creating a server-relative Reference to a Resourcestatic RelatedArtifact
relatedArtifact(RelatedArtifactType type, java.lang.String uri)
Factory method for creating a RelatedArtifactstatic RelatedArtifact
relatedArtifact(RelatedArtifactType type, java.lang.String uri, java.lang.String version)
Factory method for creating a RelatedArtifactstatic RelatedArtifact
relatedArtifact(RelatedArtifactType type, Canonical uri)
Factory method for creating a RelatedArtifactstatic RelatedArtifact
relatedArtifact(RelatedArtifactType type, Uri uri, String version)
Factory method for creating a RelatedArtifactstatic ValueSet
valueset(java.lang.String codesystem, java.lang.String code)
Factory method for constructing a ValueSet resource that contains an expansion with a single code.
-
-
-
Method Detail
-
fhircode
public static Code fhircode(org.opencds.cqf.cql.engine.runtime.Code code)
Convert a CQL Code object into a FHIR code object- Parameters:
code
- CQL Code- Returns:
- FHIR Code
-
fhircode
public static Code fhircode(java.lang.String code)
Perform null-safe conversion of a Java String to a FHIR Code- Parameters:
code
- Java code (null-safe)- Returns:
- FHIR Code or null if the input was null
-
fhirinteger
public static Integer fhirinteger(java.lang.Integer value)
Perform null-safe conversion of a Java Integer to a FHIR Integer- Parameters:
value
- Java Integer (null-safe)- Returns:
- FHIR Integer or null if the input was null
-
fhirstring
public static String fhirstring(java.lang.String str)
Perform null-safe conversion of a Java String to a FHIR String- Parameters:
str
- Java string (null-safe)- Returns:
- FHIR String or null if the input was null
-
fhiruri
public static Uri fhiruri(java.lang.String uri)
Perform null-safe conversion of a Java String to a FHIR Uri- Parameters:
uri
- Java string (null-safe)- Returns:
- FHIR Uri or null if the input was null
-
fhirboolean
public static Boolean fhirboolean(java.lang.Boolean bool)
Perform null-safe conversion of a Java boolean to a FHIR String- Parameters:
Java
- string (null-safe)- Returns:
- FHIR String or null if the input was null
-
javastring
public static java.lang.String javastring(String str)
Perform null-safe conversion of a FHIR String to a Java String- Parameters:
str
- FHIR string (null-safe)- Returns:
- Java String or null if the input was null
-
javastring
public static java.lang.String javastring(Uri uri)
Perform null-safe conversion of a FHIR Uri to a Java String- Parameters:
uri
- FHIR uri (null-safe)- Returns:
- Java String or null if the input was null
-
javaboolean
public static java.lang.Boolean javaboolean(Boolean bool)
Perform null-safe conversion of a FHIR Boolean to a Java Boolean- Parameters:
bool
- FHIR boolean (null-safe)- Returns:
- Java Boolean or null if the input was null
-
coding
public static Coding coding(java.lang.String codesystem, java.lang.String code, java.lang.String display)
Factory method for creating a simple Coding object- Parameters:
codesystem
- CodeSystem URIcode
- Codedisplay
- Display- Returns:
- FHIR Coding
-
coding
public static Coding coding(java.lang.String codesystem, java.lang.String code)
Factory method for creating a simple Coding object- Parameters:
codesystem
- CodeSystem URIcode
- Code- Returns:
- FHIR Coding
-
coding
public static Coding coding(java.lang.String code)
Factory method for creating a simple Coding object consisting only of a code value- Parameters:
code
- Code- Returns:
- FHIR Coding
-
concept
public static CodeableConcept concept(java.lang.String code)
Factory method for creating a Concept consisting of a single Coding object with only a code value- Parameters:
code
- Code- Returns:
- FHIR Concept
-
concept
public static CodeableConcept concept(java.lang.String codesystem, java.lang.String code)
Factory method for creating a Concept consisting of a single Coding object- Parameters:
codesystem
- CodeSystem URIcode
- Code- Returns:
- FHIR Concept
-
concept
public static CodeableConcept concept(Coding coding)
Factory method for creating a simple Concept object- Parameters:
coding
- Coding- Returns:
- FHIR Concept
-
relatedArtifact
public static RelatedArtifact relatedArtifact(RelatedArtifactType type, Uri uri, String version)
Factory method for creating a RelatedArtifact- Parameters:
type
- RelatedArtifactTypeuri
- URI of the related resourceversion
- version of the related resource- Returns:
- RelatedArtifact
-
relatedArtifact
public static RelatedArtifact relatedArtifact(RelatedArtifactType type, java.lang.String uri)
Factory method for creating a RelatedArtifact- Parameters:
type
- RelatedArtifactTypeuri
- URI of the related resource- Returns:
- RelatedArtifact
-
relatedArtifact
public static RelatedArtifact relatedArtifact(RelatedArtifactType type, java.lang.String uri, java.lang.String version)
Factory method for creating a RelatedArtifact- Parameters:
type
- RelatedArtifactTypeuri
- URI of the related resourceversion
- version of the related resource- Returns:
- RelatedArtifact
-
relatedArtifact
public static RelatedArtifact relatedArtifact(RelatedArtifactType type, Canonical uri)
Factory method for creating a RelatedArtifact- Parameters:
type
- RelatedArtifactTypeuri
- URI of the related resource- Returns:
- RelatedArtifact
-
canonical
public static Canonical canonical(Measure measure)
Factory method for creating a Canonical- Parameters:
measure
- Measure resource- Returns:
- Canonical URL
-
canonical
public static Canonical canonical(Library library)
Factory method for creating a Canonical- Parameters:
library
- Library resource- Returns:
- Canonical URL
-
canonical
public static Canonical canonical(java.lang.String uri)
Factory method for creating a Canonical- Parameters:
uri
- URI of the related resource- Returns:
- Canonical URL
-
canonical
public static Canonical canonical(Uri uri)
Factory method for creating a Canonical- Parameters:
uri
- URI of the related resource- Returns:
- Canonical URL
-
canonical
public static Canonical canonical(Uri uri, String version)
Factory method for creating a Canonical- Parameters:
uri
- URI of the related resourceversion
- null-safe version of the related resource- Returns:
- Canonical URL consisting of URL and then "|" + version if version is non-null
-
reference
public static Reference reference(Resource resource)
Factory method for creating a server-relative Reference to a Resource- Parameters:
resource
- resource- Returns:
- server-relative Reference
-
getAttachmentByType
public static java.util.Optional<Attachment> getAttachmentByType(Library library, java.lang.String contentType)
Helper method for retrieving a Library attachment with a specific content type. Attachment types are assumed to be singleton and an exception will be thrown if more than one Attachment with the same type is found.- Parameters:
library
- Library resourcecontentType
- ContentType string for the attachment to retrieve- Returns:
- Optional Attachment
-
bundle
public static Bundle bundle(Resource... resources)
Factory method for constructing a SearchSet bundle from an array of resources- Parameters:
resources
- Resources- Returns:
- Bundle
-
bundle
public static Bundle bundle(BundleType type, Resource... resources)
Factory method for constructing a bundle from an array of resources- Parameters:
bundleType
- BundleTyperesources
- Resources- Returns:
- Bundle
-
valueset
public static ValueSet valueset(java.lang.String codesystem, java.lang.String code)
Factory method for constructing a ValueSet resource that contains an expansion with a single code.- Parameters:
codesystem
- CodeSystem URIcode
- Code- Returns:
- ValueSet
-
getLinkByType
public static java.util.Optional<java.lang.String> getLinkByType(Bundle bundle, java.lang.String type)
Helper method for retrieving a Bundle link by a specific link type. Bundle links are assumed to be singleton instances and an exception will be thrown if more than one of the same type are found.- Parameters:
bundle
- Bundletype
- link type to retrieve- Returns:
- Optional link
-
getExtensionByUrl
public static java.util.Optional<Extension> getExtensionByUrl(Element element, java.lang.String url)
Retrieve the Element extension that matches the given URL. Extension elements are assumed to be singleton values.- Parameters:
element
- FHIR Element- Returns:
- Optional containing the extension if found
-
getZoneOffset
public static java.time.ZoneOffset getZoneOffset(Element element)
For the given Element, retrieve the timezone offset from the Element's extensions based on HL7 tz-offset and tz-code extensions. See FHIR Extension Timezone Offset- Parameters:
element
- FHIR Element (date, dateTime, instant)- Returns:
- Java ZoneOffset using data from the provided Element's extensions
-
-