Search in sources :

Example 1 with CqlTranslator

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

the class Translators method getTranslator.

public static CqlTranslator getTranslator(InputStream cqlStream, LibraryManager libraryManager, ModelManager modelManager) {
    CqlTranslator translator;
    try {
        List<CqlTranslator.Options> options = generateDefaultTranslatorOptions();
        translator = CqlTranslator.fromStream(cqlStream, modelManager, libraryManager, options.toArray(new CqlTranslator.Options[options.size()]));
    } catch (IOException e) {
        throw new IllegalArgumentException(String.format("Errors occurred translating library: %s", e.getMessage()));
    }
    return translator;
}
Also used : CqlTranslatorOptions(org.cqframework.cql.cql2elm.CqlTranslatorOptions) CqlTranslator(org.cqframework.cql.cql2elm.CqlTranslator) IOException(java.io.IOException)

Example 2 with CqlTranslator

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

the class DataOperationsProvider method processDataRequirements.

private Library processDataRequirements(Library library, RequestDetails theRequestDetails) {
    LibraryManager libraryManager = createLibraryManager(library, theRequestDetails);
    CqlTranslator translator = translateLibrary(library, libraryManager, theRequestDetails);
    // TODO: Enable passing a capability statement as a parameter to the operation
    return DataRequirements.getModuleDefinitionLibraryR4(libraryManager, translator.getTranslatedLibrary(), Translators.getTranslatorOptions(), searchParameterResolver, jpaTerminologyProviderFactory.create(theRequestDetails), myModelResolver, null);
}
Also used : CqlTranslator(org.cqframework.cql.cql2elm.CqlTranslator) LibraryManager(org.cqframework.cql.cql2elm.LibraryManager)

Example 3 with CqlTranslator

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

the class CqlBuilder method validate.

private void validate(String cql) {
    ModelManager modelManager = new ModelManager();
    LibraryManager libraryManager = new LibraryManager(modelManager);
    libraryManager.getLibrarySourceLoader().registerProvider(new FhirLibrarySourceProvider());
    CqlTranslator translator;
    try {
        translator = CqlTranslator.fromStream(new ByteArrayInputStream(cql.getBytes()), modelManager, libraryManager);
    } catch (IOException e) {
        throw new CqlTranslatorException("Error validating cql", e);
    }
    if (translator.getErrors().size() > 0) {
        throw new CqlTranslatorException("Error validating cql: " + Translators.errorsToString(translator.getErrors()));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CqlTranslator(org.cqframework.cql.cql2elm.CqlTranslator) LibraryManager(org.cqframework.cql.cql2elm.LibraryManager) IOException(java.io.IOException) ModelManager(org.cqframework.cql.cql2elm.ModelManager) FhirLibrarySourceProvider(org.cqframework.cql.cql2elm.FhirLibrarySourceProvider) CqlTranslatorException(org.cqframework.cql.cql2elm.CqlTranslatorException)

Example 4 with CqlTranslator

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

the class CQLParameterTests method toLibrary.

public Library toLibrary(String text) throws Exception {
    ModelManager modelManager = new ModelManager();
    LibraryManager libraryManager = new LibraryManager(modelManager);
    CqlTranslator translator = CqlTranslator.fromText(text, modelManager, libraryManager);
    assertEquals(translator.getErrors().toString(), 0, translator.getErrors().size());
    String xml = translator.toXml();
    return CqlLibraryReader.read(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CqlTranslator(org.cqframework.cql.cql2elm.CqlTranslator) LibraryManager(org.cqframework.cql.cql2elm.LibraryManager) ModelManager(org.cqframework.cql.cql2elm.ModelManager)

Example 5 with CqlTranslator

use of org.cqframework.cql.cql2elm.CqlTranslator 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)

Aggregations

CqlTranslator (org.cqframework.cql.cql2elm.CqlTranslator)73 Test (org.testng.annotations.Test)46 CompiledLibrary (org.cqframework.cql.cql2elm.model.CompiledLibrary)32 HashMap (java.util.HashMap)30 LibraryManager (org.cqframework.cql.cql2elm.LibraryManager)24 ModelManager (org.cqframework.cql.cql2elm.ModelManager)17 BeforeTest (org.testng.annotations.BeforeTest)16 TestUtils.visitFileLibrary (org.cqframework.cql.cql2elm.TestUtils.visitFileLibrary)13 ExpressionDef (org.hl7.elm.r1.ExpressionDef)5 Library (org.hl7.elm.r1.Library)5 CqlTranslatorException (org.cqframework.cql.cql2elm.CqlTranslatorException)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 NamespaceInfo (org.cqframework.cql.cql2elm.NamespaceInfo)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 JAXBException (javax.xml.bind.JAXBException)2 FhirLibrarySourceProvider (org.cqframework.cql.cql2elm.FhirLibrarySourceProvider)2 TrackBack (org.cqframework.cql.elm.tracking.TrackBack)2 UcumEssenceService (org.fhir.ucum.UcumEssenceService)2 UcumService (org.fhir.ucum.UcumService)2