Class 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 resources
      static Bundle bundle​(BundleType type, Resource... resources)
      Factory method for constructing a bundle from an array of resources
      static Canonical canonical​(java.lang.String uri)
      Factory method for creating a Canonical
      static Canonical canonical​(Library library)
      Factory method for creating a Canonical
      static Canonical canonical​(Measure measure)
      Factory method for creating a Canonical
      static Canonical canonical​(Uri uri)
      Factory method for creating a Canonical
      static Canonical canonical​(Uri uri, String version)
      Factory method for creating a Canonical
      static Coding coding​(java.lang.String code)
      Factory method for creating a simple Coding object consisting only of a code value
      static Coding coding​(java.lang.String codesystem, java.lang.String code)
      Factory method for creating a simple Coding object
      static Coding coding​(java.lang.String codesystem, java.lang.String code, java.lang.String display)
      Factory method for creating a simple Coding object
      static CodeableConcept concept​(java.lang.String code)
      Factory method for creating a Concept consisting of a single Coding object with only a code value
      static CodeableConcept concept​(java.lang.String codesystem, java.lang.String code)
      Factory method for creating a Concept consisting of a single Coding object
      static CodeableConcept concept​(Coding coding)
      Factory method for creating a simple Concept object
      static Boolean fhirboolean​(java.lang.Boolean bool)
      Perform null-safe conversion of a Java boolean to a FHIR String
      static Code fhircode​(java.lang.String code)
      Perform null-safe conversion of a Java String to a FHIR Code
      static Code fhircode​(org.opencds.cqf.cql.engine.runtime.Code code)
      Convert a CQL Code object into a FHIR code object
      static Integer fhirinteger​(java.lang.Integer value)
      Perform null-safe conversion of a Java Integer to a FHIR Integer
      static String fhirstring​(java.lang.String str)
      Perform null-safe conversion of a Java String to a FHIR String
      static Uri fhiruri​(java.lang.String uri)
      Perform null-safe conversion of a Java String to a FHIR Uri
      static 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 Boolean
      static java.lang.String javastring​(String str)
      Perform null-safe conversion of a FHIR String to a Java String
      static java.lang.String javastring​(Uri uri)
      Perform null-safe conversion of a FHIR Uri to a Java String
      static Reference reference​(Resource resource)
      Factory method for creating a server-relative Reference to a Resource
      static RelatedArtifact relatedArtifact​(RelatedArtifactType type, java.lang.String uri)
      Factory method for creating a RelatedArtifact
      static RelatedArtifact relatedArtifact​(RelatedArtifactType type, java.lang.String uri, java.lang.String version)
      Factory method for creating a RelatedArtifact
      static RelatedArtifact relatedArtifact​(RelatedArtifactType type, Canonical uri)
      Factory method for creating a RelatedArtifact
      static RelatedArtifact relatedArtifact​(RelatedArtifactType type, Uri uri, String version)
      Factory method for creating a RelatedArtifact
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ModelHelper

        public ModelHelper()
    • 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 URI
        code - Code
        display - 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 URI
        code - 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 URI
        code - 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 - RelatedArtifactType
        uri - URI of the related resource
        version - 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 - RelatedArtifactType
        uri - 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 - RelatedArtifactType
        uri - URI of the related resource
        version - version of the related resource
        Returns:
        RelatedArtifact
      • relatedArtifact

        public static RelatedArtifact relatedArtifact​(RelatedArtifactType type,
                                                      Canonical uri)
        Factory method for creating a RelatedArtifact
        Parameters:
        type - RelatedArtifactType
        uri - 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 resource
        version - 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 resource
        contentType - 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 - BundleType
        resources - 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 URI
        code - 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 - Bundle
        type - 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