Search in sources :

Example 1 with CqlLibrarySourceProvider

use of com.ibm.cohort.cql.provider.CqlLibrarySourceProvider in project quality-measure-and-cohort-service by Alvearie.

the class CqlToElmTranslatorTest method testTranslationWithIncludes.

@Test
public void testTranslationWithIncludes() throws Exception {
    CqlLibraryProvider provider = new ClasspathCqlLibraryProvider("cql");
    CqlLibraryDescriptor descriptor = new CqlLibraryDescriptor().setLibraryId("SampleLibrary").setVersion("1.0.0").setFormat(Format.CQL);
    CqlLibrary primaryLibrary = provider.getLibrary(descriptor);
    CqlLibrarySourceProvider sourceProvider = vid -> {
        CqlLibraryDescriptor d = new CqlLibraryDescriptor().setLibraryId(vid.getId()).setVersion(vid.getVersion()).setFormat(Format.CQL);
        return provider.getLibrary(d).getContentAsStream();
    };
    CqlToElmTranslator translator = new CqlToElmTranslator();
    try (Reader modelInfoXML = new FileReader(new File("src/test/resources/modelinfo/mock-modelinfo-1.0.0.xml"))) {
        translator.registerModelInfo(modelInfoXML);
    }
    CqlTranslationResult result = translator.translate(primaryLibrary, sourceProvider);
    assertEquals(1, result.getDependencies().size());
}
Also used : CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibrarySourceProvider(com.ibm.cohort.cql.provider.CqlLibrarySourceProvider) Assert.assertThrows(org.junit.Assert.assertThrows) CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) Test(org.junit.Test) Reader(java.io.Reader) Format(com.ibm.cohort.cql.library.Format) File(java.io.File) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) CqlTranslatorException(org.cqframework.cql.cql2elm.CqlTranslatorException) FileReader(java.io.FileReader) Assert.assertEquals(org.junit.Assert.assertEquals) CqlLibrarySourceProvider(com.ibm.cohort.cql.provider.CqlLibrarySourceProvider) Reader(java.io.Reader) FileReader(java.io.FileReader) FileReader(java.io.FileReader) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) File(java.io.File) Test(org.junit.Test)

Example 2 with CqlLibrarySourceProvider

use of com.ibm.cohort.cql.provider.CqlLibrarySourceProvider in project quality-measure-and-cohort-service by Alvearie.

the class R4TranslatingLibraryLoader method translateLibrary.

private String translateLibrary(String content, VersionedIdentifier libraryIdentifier) {
    LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResolutionProvider = new ResolverLibraryResolutionProvider<>(resolver);
    LibrarySourceProvider<org.hl7.fhir.r4.model.Library, Attachment> librarySourceProvider = new LibrarySourceProvider<>(libraryResolutionProvider, org.hl7.fhir.r4.model.Library::getContent, Attachment::getContentType, Attachment::getData);
    CqlLibrarySourceProvider cqlLibrarySourceProvider = new SourceProviderBasedCqlLibrarySourceProvider(librarySourceProvider);
    CqlLibraryDescriptor descriptor = new CqlLibraryDescriptor().setFormat(Format.CQL).setLibraryId(libraryIdentifier.getId()).setVersion(libraryIdentifier.getVersion());
    CqlLibrary library = new CqlLibrary().setDescriptor(descriptor).setContent(content);
    return translator.translate(library, cqlLibrarySourceProvider).getMainLibrary().getContent();
}
Also used : CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) CqlLibrarySourceProvider(com.ibm.cohort.cql.provider.CqlLibrarySourceProvider) LibrarySourceProvider(org.opencds.cqf.common.providers.LibrarySourceProvider) SourceProviderBasedCqlLibrarySourceProvider(com.ibm.cohort.cql.provider.SourceProviderBasedCqlLibrarySourceProvider) SourceProviderBasedCqlLibrarySourceProvider(com.ibm.cohort.cql.provider.SourceProviderBasedCqlLibrarySourceProvider) CqlLibrarySourceProvider(com.ibm.cohort.cql.provider.CqlLibrarySourceProvider) SourceProviderBasedCqlLibrarySourceProvider(com.ibm.cohort.cql.provider.SourceProviderBasedCqlLibrarySourceProvider) Attachment(org.hl7.fhir.r4.model.Attachment) CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) Library(org.cqframework.cql.elm.execution.Library) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) ResolverLibraryResolutionProvider(com.ibm.cohort.cql.hapi.provider.ResolverLibraryResolutionProvider)

Example 3 with CqlLibrarySourceProvider

use of com.ibm.cohort.cql.provider.CqlLibrarySourceProvider in project quality-measure-and-cohort-service by Alvearie.

the class CqlToElmTranslatorTest method testTranslationWithErrors.

@Test
public void testTranslationWithErrors() {
    CqlLibraryDescriptor descriptor = new CqlLibraryDescriptor().setLibraryId("GobbledyGook").setVersion("1.0.0").setFormat(Format.CQL);
    CqlLibrary primaryLibrary = new CqlLibrary().setDescriptor(descriptor).setContent("GobbledyGook");
    CqlLibrarySourceProvider sourceProvider = vid -> primaryLibrary.getContentAsStream();
    CqlToElmTranslator translator = new CqlToElmTranslator();
    assertThrows(CqlTranslatorException.class, () -> translator.translate(primaryLibrary, sourceProvider));
}
Also used : CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibrarySourceProvider(com.ibm.cohort.cql.provider.CqlLibrarySourceProvider) Assert.assertThrows(org.junit.Assert.assertThrows) CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) Test(org.junit.Test) Reader(java.io.Reader) Format(com.ibm.cohort.cql.library.Format) File(java.io.File) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) CqlTranslatorException(org.cqframework.cql.cql2elm.CqlTranslatorException) FileReader(java.io.FileReader) Assert.assertEquals(org.junit.Assert.assertEquals) CqlLibrarySourceProvider(com.ibm.cohort.cql.provider.CqlLibrarySourceProvider) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) Test(org.junit.Test)

Aggregations

CqlLibrary (com.ibm.cohort.cql.library.CqlLibrary)3 CqlLibraryDescriptor (com.ibm.cohort.cql.library.CqlLibraryDescriptor)3 CqlLibrarySourceProvider (com.ibm.cohort.cql.provider.CqlLibrarySourceProvider)3 ClasspathCqlLibraryProvider (com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider)2 CqlLibraryProvider (com.ibm.cohort.cql.library.CqlLibraryProvider)2 Format (com.ibm.cohort.cql.library.Format)2 File (java.io.File)2 FileReader (java.io.FileReader)2 Reader (java.io.Reader)2 CqlTranslatorException (org.cqframework.cql.cql2elm.CqlTranslatorException)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertThrows (org.junit.Assert.assertThrows)2 Test (org.junit.Test)2 ResolverLibraryResolutionProvider (com.ibm.cohort.cql.hapi.provider.ResolverLibraryResolutionProvider)1 SourceProviderBasedCqlLibrarySourceProvider (com.ibm.cohort.cql.provider.SourceProviderBasedCqlLibrarySourceProvider)1 Library (org.cqframework.cql.elm.execution.Library)1 Attachment (org.hl7.fhir.r4.model.Attachment)1 LibrarySourceProvider (org.opencds.cqf.common.providers.LibrarySourceProvider)1