Search in sources :

Example 1 with TranslatedLibrary

use of org.cqframework.cql.cql2elm.model.TranslatedLibrary in project quality-measure-and-cohort-service by Alvearie.

the class CqlToElmTranslator method translate.

public CqlTranslationResult translate(CqlLibrary primaryLibrary, CqlLibrarySourceProvider sourceProvider) {
    LibraryBuilder.SignatureLevel signatureLevel = LibraryBuilder.SignatureLevel.None;
    LibraryManager libraryManager = newLibraryManager(sourceProvider);
    Collection<CqlLibrary> dependencies = new ArrayList<>();
    CqlTranslator cqlTranslator = CqlTranslator.fromText(primaryLibrary.getContent(), libraryManager.getModelManager(), libraryManager, /* ucumService= */
    null, CqlTranslatorException.ErrorSeverity.Info, signatureLevel, getOptionsArray());
    if (cqlTranslator.getErrors().size() > 0) {
        throw new CqlTranslatorException("There were errors during cql translation: " + formatMsg(cqlTranslator.getErrors()));
    } else if (cqlTranslator.getExceptions().size() > 0) {
        throw new CqlTranslatorException("There were exceptions during cql translation: " + formatMsg(cqlTranslator.getExceptions()));
    } else if (cqlTranslator.getWarnings().size() > 0) {
        String msg = "There were warnings during cql translation:\n" + cqlTranslator.getWarnings().stream().map(Object::toString).collect(Collectors.joining("\n"));
        LOG.warn(msg);
    }
    CqlLibrary translatedLibrary = new CqlLibrary().setDescriptor(new CqlLibraryDescriptor().setLibraryId(primaryLibrary.getDescriptor().getLibraryId()).setVersion(primaryLibrary.getDescriptor().getVersion()).setFormat(Format.ELM)).setContent(cqlTranslator.toXml());
    try {
        for (TranslatedLibrary tl : libraryManager.getTranslatedLibraries().values()) {
            CqlLibrary library = new CqlLibrary().setDescriptor(new CqlLibraryDescriptor().setLibraryId(tl.getLibrary().getIdentifier().getId()).setVersion(tl.getLibrary().getIdentifier().getVersion()).setFormat(Format.ELM)).setContent(CqlTranslator.convertToXml(tl.getLibrary()));
            dependencies.add(library);
        }
    } catch (JAXBException ex) {
        throw new RuntimeException("ELM serialization failure", ex);
    }
    return new CqlTranslationResult(translatedLibrary, dependencies);
}
Also used : LibraryBuilder(org.cqframework.cql.cql2elm.LibraryBuilder) CqlTranslator(org.cqframework.cql.cql2elm.CqlTranslator) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) CqlTranslatorException(org.cqframework.cql.cql2elm.CqlTranslatorException) CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) TranslatedLibrary(org.cqframework.cql.cql2elm.model.TranslatedLibrary) LibraryManager(org.cqframework.cql.cql2elm.LibraryManager) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor)

Example 2 with TranslatedLibrary

use of org.cqframework.cql.cql2elm.model.TranslatedLibrary in project cqf-ruler by DBCG.

the class DataRequirements method getModuleDefinitionLibraryR4.

public static org.hl7.fhir.r4.model.Library getModuleDefinitionLibraryR4(LibraryManager libraryManager, TranslatedLibrary translatedLibrary, CqlTranslatorOptions options, SearchParameterResolver searchParameterResolver, TerminologyProvider terminologyProvider, ModelResolver modelResolver, IBaseConformance capStatement) {
    org.hl7.fhir.r5.model.Library libraryR5 = getModuleDefinitionLibraryR5(libraryManager, translatedLibrary, options);
    VersionConvertor_40_50 versionConvertor_40_50 = new VersionConvertor_40_50(new BaseAdvisor_40_50());
    org.hl7.fhir.r4.model.Library libraryR4 = (org.hl7.fhir.r4.model.Library) versionConvertor_40_50.convertResource(libraryR5);
    libraryR4 = addDataRequirementFhirQueries(libraryR4, searchParameterResolver, terminologyProvider, modelResolver, capStatement);
    return libraryR4;
}
Also used : BaseAdvisor_40_50(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_40_50) VersionConvertor_40_50(org.hl7.fhir.convertors.conv40_50.VersionConvertor_40_50) TranslatedLibrary(org.cqframework.cql.cql2elm.model.TranslatedLibrary)

Example 3 with TranslatedLibrary

use of org.cqframework.cql.cql2elm.model.TranslatedLibrary in project cqf-ruler by DBCG.

the class DataRequirements method getModuleDefinitionLibraryR4.

public static org.hl7.fhir.r4.model.Library getModuleDefinitionLibraryR4(org.hl7.fhir.r4.model.Measure measureToUse, LibraryManager libraryManager, TranslatedLibrary translatedLibrary, CqlTranslatorOptions options, SearchParameterResolver searchParameterResolver, TerminologyProvider terminologyProvider, ModelResolver modelResolver, IBaseConformance capStatement) {
    VersionConvertor_40_50 versionConvertor_40_50 = new VersionConvertor_40_50(new BaseAdvisor_40_50());
    org.hl7.fhir.r5.model.Measure r5Measure = (org.hl7.fhir.r5.model.Measure) versionConvertor_40_50.convertResource(measureToUse);
    Set<String> expressionList = getExpressions(r5Measure);
    DataRequirementsProcessor dqReqTrans = new DataRequirementsProcessor();
    org.hl7.fhir.r5.model.Library effectiveDataRequirements = dqReqTrans.gatherDataRequirements(libraryManager, translatedLibrary, options, expressionList, true);
    org.hl7.fhir.r4.model.Library r4EffectiveDataRequirements = (org.hl7.fhir.r4.model.Library) versionConvertor_40_50.convertResource(effectiveDataRequirements);
    r4EffectiveDataRequirements = addDataRequirementFhirQueries(r4EffectiveDataRequirements, searchParameterResolver, terminologyProvider, modelResolver, capStatement);
    return r4EffectiveDataRequirements;
}
Also used : BaseAdvisor_40_50(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_40_50) VersionConvertor_40_50(org.hl7.fhir.convertors.conv40_50.VersionConvertor_40_50) Measure(org.hl7.fhir.r5.model.Measure) Measure(org.hl7.fhir.r5.model.Measure) DataRequirementsProcessor(org.cqframework.cql.elm.requirements.fhir.DataRequirementsProcessor) TranslatedLibrary(org.cqframework.cql.cql2elm.model.TranslatedLibrary)

Example 4 with TranslatedLibrary

use of org.cqframework.cql.cql2elm.model.TranslatedLibrary in project cqf-ruler by DBCG.

the class DataRequirements method getModuleDefinitionLibraryDstu3.

public static org.hl7.fhir.dstu3.model.Library getModuleDefinitionLibraryDstu3(org.hl7.fhir.dstu3.model.Measure measureToUse, LibraryManager libraryManager, TranslatedLibrary translatedLibrary, CqlTranslatorOptions options) {
    VersionConvertor_30_50 versionConvertor_30_50 = new VersionConvertor_30_50(new BaseAdvisor_30_50());
    org.hl7.fhir.r5.model.Measure r5Measure = (org.hl7.fhir.r5.model.Measure) versionConvertor_30_50.convertResource(measureToUse);
    Set<String> expressionList = getExpressions(r5Measure);
    DataRequirementsProcessor dqReqTrans = new DataRequirementsProcessor();
    org.hl7.fhir.r5.model.Library effectiveDataRequirements = dqReqTrans.gatherDataRequirements(libraryManager, translatedLibrary, options, expressionList, true);
    org.hl7.fhir.dstu3.model.Library stu3EffectiveDataRequirements = (org.hl7.fhir.dstu3.model.Library) versionConvertor_30_50.convertResource(effectiveDataRequirements);
    // TODO: Support dataRequirementFhirQueries in STU3
    return stu3EffectiveDataRequirements;
}
Also used : Measure(org.hl7.fhir.r5.model.Measure) BaseAdvisor_30_50(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_50) VersionConvertor_30_50(org.hl7.fhir.convertors.conv30_50.VersionConvertor_30_50) Measure(org.hl7.fhir.r5.model.Measure) DataRequirementsProcessor(org.cqframework.cql.elm.requirements.fhir.DataRequirementsProcessor) TranslatedLibrary(org.cqframework.cql.cql2elm.model.TranslatedLibrary)

Aggregations

TranslatedLibrary (org.cqframework.cql.cql2elm.model.TranslatedLibrary)4 DataRequirementsProcessor (org.cqframework.cql.elm.requirements.fhir.DataRequirementsProcessor)2 BaseAdvisor_40_50 (org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_40_50)2 VersionConvertor_40_50 (org.hl7.fhir.convertors.conv40_50.VersionConvertor_40_50)2 Measure (org.hl7.fhir.r5.model.Measure)2 CqlLibrary (com.ibm.cohort.cql.library.CqlLibrary)1 CqlLibraryDescriptor (com.ibm.cohort.cql.library.CqlLibraryDescriptor)1 ArrayList (java.util.ArrayList)1 JAXBException (javax.xml.bind.JAXBException)1 CqlTranslator (org.cqframework.cql.cql2elm.CqlTranslator)1 CqlTranslatorException (org.cqframework.cql.cql2elm.CqlTranslatorException)1 LibraryBuilder (org.cqframework.cql.cql2elm.LibraryBuilder)1 LibraryManager (org.cqframework.cql.cql2elm.LibraryManager)1 BaseAdvisor_30_50 (org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_50)1 VersionConvertor_30_50 (org.hl7.fhir.convertors.conv30_50.VersionConvertor_30_50)1