Class LibraryHelper


  • public class LibraryHelper
    extends Object
    Helper methods for working with FHIR Library resources and specifically those that pertain to Clinical Quality Language (CQL) evaluation.
    • Constructor Detail

      • LibraryHelper

        public LibraryHelper()
    • Method Detail

      • loadLibraries

        public static List<Library> loadLibraries​(Library fhirLibrary)
        Create a collection of the given library resource and all of its dependencies.
        Parameters:
        fhirLibrary - root library in the tree of dependencies
        Returns:
        List of Library resources corresponding to all dependencies.
      • loadLibraries

        protected static List<Library> loadLibraries​(Library fhirLibrary,
                                                     Set<String> visited)
        Create a collection of the given library resource and all of its dependencies.
        Parameters:
        fhirLibrary - root library in the tree of dependencies
        visited - set of canonical URLs corresponding to the library resources that have already been loaded. This allows us to prevent infinite loops.
        Returns:
        List of Library resources corresponding to all dependencies.
      • loadLibrary

        public static List<org.cqframework.cql.elm.execution.Library> loadLibrary​(CqlTranslationProvider translator,
                                                                                  Library fhirLibrary)
        Load the CQL Library from the attachment data associated with a FHIR Library resource.
        Parameters:
        translator - CQL Translation Provider that will be used to translate CQL for Library resources with only CQL attachment data
        fhirLibrary - Library resource containing the attachment data to load
        Returns:
        List of CQL Libraries that were translated. A single CQL file might output multiple Library objects based on the include definitions in the CQL.
      • deserializeElm

        public static org.cqframework.cql.elm.execution.Library deserializeElm​(Library fhirLibrary,
                                                                               Attachment elm)
        Deserialize the contents of an application/elm+xml attachment.
        Parameters:
        fhirLibrary - FHIR Library that contains the attachment
        elm - Attachment that contains the ELM data
        Returns:
        CQL Library
      • isLibraryReference

        public static boolean isLibraryReference​(String resource)
        Helper function for determining if a reference resource is a Library resource
        Parameters:
        resource - Resource reference
        Returns:
        true if the resource string refers to a library. Otherwise, false.
      • isLogicLibrary

        public static boolean isLogicLibrary​(Library fhirLibrary)
        Helper function for determining if a Library resource contains CQL logic. This is most correctly determined by the Library.type property, but, in the absence of a type field, any Library that contains a CQL or ELM attachment will be considered a logic library.
        Parameters:
        resource - Resource reference
        Returns:
        true if the resource string refers to a library. Otherwise, false.
      • getLogicLibraryConcept

        public static CodeableConcept getLogicLibraryConcept()
        Helper method for generating a CodeableConcept that contains the logic-library code.
        Returns:
        CodeableConcept containing the logic-library code
      • getLogicLibraryCoding

        public static Coding getLogicLibraryCoding()
        Helper method for generating a Coding that contains the logic-library code.
        Returns:
        Coding containing the logic-library code
      • getModelDefinitionCoding

        public static Coding getModelDefinitionCoding()
        Helper method for generating a Coding that contains the model-definition code.
        Returns:
        Coding containing the logic-library code
      • getLibraryCoding

        public static Coding getLibraryCoding​(String code)
        Helper method for generating a Coding that contains the model-definition code.
        Returns:
        Coding containing the logic-library code
      • getAttachmentData

        public static InputStream getAttachmentData​(Attachment attachment)
                                             throws IOException
        Helper method for converting an Attachment resource's contents into an InputStream
        Returns:
        InputStream for reading the attachment data
        Throws:
        IOException
      • canonicalUrl

        public static String canonicalUrl​(Library library)
        Helper method for building a canonical URL string from the relevant fields in a Library resource.
        Returns:
        canonical URL