Search in sources :

Example 1 with ModelInfo

use of org.hl7.elm_modelinfo.r1.ModelInfo in project quality-measure-and-cohort-service by Alvearie.

the class CohortCLITest method testCQLTranslationCustomIGWithTargetUrl.

@Test
public void testCQLTranslationCustomIGWithTargetUrl() throws Exception {
    FhirServerConfig fhirConfig = getFhirServerConfig();
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1978-05-06");
    patient.addExtension(new Extension("http://fakeIg.com/fake-extension", new StringType("fakeValue")));
    mockFhirResourceRetrieval(patient);
    Library root = getLibrary("test", DEFAULT_RESOURCE_VERSION, "cql/ig-test/Test-1.0.0.cql");
    Library helpers = getLibrary("FHIRHelpers", "4.0.0", "cql/fhir-helpers/FHIRHelpers.cql", "text/cql", "cql/fhir-helpers/FHIRHelpers.xml", "application/elm+json");
    RelatedArtifact related = new RelatedArtifact();
    related.setType(RelatedArtifactType.DEPENDSON);
    related.setResource("/Library/" + helpers.getId());
    root.addRelatedArtifact(related);
    mockFhirResourceRetrieval(root);
    mockFhirSingletonBundleRetrieval(helpers);
    File tmpFile = new File("target/fhir-stub.json");
    ObjectMapper om = new ObjectMapper();
    try (Writer w = new FileWriter(tmpFile)) {
        w.write(om.writeValueAsString(fhirConfig));
    }
    try {
        PrintStream originalOut = System.out;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try (PrintStream captureOut = new PrintStream(baos)) {
            System.setOut(captureOut);
            CohortCLI.main(new String[] { "-d", tmpFile.getAbsolutePath(), "-f", root.getId(), "-l", root.getName(), "-v", root.getVersion(), "-c", patient.getId(), "-s", "CQL", "-i", "src/test/resources/modelinfo/ig-with-target-modelinfo-0.0.1.xml" });
        } finally {
            System.setOut(originalOut);
        }
        String output = new String(baos.toByteArray());
        System.out.println(output);
        verify(1, getRequestedFor(urlEqualTo("/Patient/" + patient.getId() + "?_format=json")));
        verify(1, getRequestedFor(urlEqualTo("/Library/" + root.getId() + "?_format=json")));
        verify(1, getRequestedFor(urlEqualTo("/Library?url=%2FLibrary%2F" + helpers.getId() + "&_format=json")));
    } finally {
        tmpFile.delete();
    }
}
Also used : PrintStream(java.io.PrintStream) StringType(org.hl7.fhir.r4.model.StringType) FileWriter(java.io.FileWriter) Patient(org.hl7.fhir.r4.model.Patient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RelatedArtifact(org.hl7.fhir.r4.model.RelatedArtifact) Extension(org.hl7.fhir.r4.model.Extension) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) Library(org.hl7.fhir.r4.model.Library) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileWriter(java.io.FileWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 2 with ModelInfo

use of org.hl7.elm_modelinfo.r1.ModelInfo in project quality-measure-and-cohort-service by Alvearie.

the class SparkCqlEvaluator method createDataTypeAliases.

private Map<String, String> createDataTypeAliases(List<ContextDefinition> filteredContexts, CqlToElmTranslator translator) {
    Set<String> dataTypes = filteredContexts.stream().map(ContextDefinition::getPrimaryDataType).collect(Collectors.toSet());
    Collection<ModelInfo> modelInfos = translator.getRegisteredModelInfos().values();
    Map<String, String> dataTypeAliases = new HashMap<>();
    for (ModelInfo modelInfo : modelInfos) {
        modelInfo.getTypeInfo().stream().filter(ClassInfo.class::isInstance).map(ClassInfo.class::cast).filter(classInfo -> dataTypes.contains(classInfo.getName())).forEach(info -> {
            String dataType = info.getName();
            QName baseType = ModelUtils.getBaseTypeName(modelInfo, info);
            if (baseType != null) {
                // for inheritance types
                dataTypeAliases.put(dataType, baseType.getLocalPart());
            }
            Collection<String> choiceTypes = ModelUtils.getChoiceTypeNames(info);
            // for choice types
            choiceTypes.forEach(choiceType -> dataTypeAliases.put(dataType, choiceType));
        });
    }
    return dataTypeAliases;
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) Arrays(java.util.Arrays) CqlDataProvider(com.ibm.cohort.cql.data.CqlDataProvider) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) FileSystem(org.apache.hadoop.fs.FileSystem) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) EncodedParametersCache(com.ibm.cohort.cql.spark.util.EncodedParametersCache) DataRowDataProvider(com.ibm.cohort.datarow.engine.DataRowDataProvider) Format(com.ibm.cohort.cql.library.Format) ClassInfo(org.hl7.elm_modelinfo.r1.ClassInfo) ColumnRuleCreator(com.ibm.cohort.cql.spark.aggregation.ColumnRuleCreator) ConfigurableOutputColumnNameEncoder(com.ibm.cohort.cql.spark.data.ConfigurableOutputColumnNameEncoder) DefaultDatasetRetriever(com.ibm.cohort.cql.spark.data.DefaultDatasetRetriever) SparkSchemaCreator(com.ibm.cohort.cql.spark.data.SparkSchemaCreator) ContextDefinition(com.ibm.cohort.cql.spark.aggregation.ContextDefinition) Map(java.util.Map) Path(org.apache.hadoop.fs.Path) CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) ModelUtils(com.ibm.cohort.cql.spark.optimizer.ModelUtils) ConstraintViolation(javax.validation.ConstraintViolation) StructType(org.apache.spark.sql.types.StructType) HadoopPathOutputMetadataWriter(com.ibm.cohort.cql.spark.metadata.HadoopPathOutputMetadataWriter) Collection(java.util.Collection) Set(java.util.Set) Validator(javax.validation.Validator) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) Reader(java.io.Reader) Tuple2(scala.Tuple2) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) Serializable(java.io.Serializable) ContextRetriever(com.ibm.cohort.cql.spark.aggregation.ContextRetriever) List(java.util.List) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) CqlTerminologyProvider(com.ibm.cohort.cql.terminology.CqlTerminologyProvider) QName(javax.xml.namespace.QName) SparkOutputColumnEncoder(com.ibm.cohort.cql.spark.data.SparkOutputColumnEncoder) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) MapUtils(com.ibm.cohort.cql.util.MapUtils) ExternalFunctionProvider(org.opencds.cqf.cql.engine.data.ExternalFunctionProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Dataset(org.apache.spark.sql.Dataset) SerializableConfiguration(org.apache.spark.util.SerializableConfiguration) CqlEvaluationResult(com.ibm.cohort.cql.evaluation.CqlEvaluationResult) SparkDataRow(com.ibm.cohort.cql.spark.data.SparkDataRow) PriorityCqlLibraryProvider(com.ibm.cohort.cql.library.PriorityCqlLibraryProvider) R4FileSystemFhirTerminologyProvider(com.ibm.cohort.cql.terminology.R4FileSystemFhirTerminologyProvider) HashMap(java.util.HashMap) ValidatorFactory(javax.validation.ValidatorFactory) HadoopBasedCqlLibraryProvider(com.ibm.cohort.cql.library.HadoopBasedCqlLibraryProvider) SparkTypeConverter(com.ibm.cohort.cql.spark.data.SparkTypeConverter) Function(java.util.function.Function) ArrayList(java.util.ArrayList) CustomMetricSparkPlugin(com.ibm.cohort.cql.spark.metrics.CustomMetricSparkPlugin) CollectionUtils(org.apache.commons.collections.CollectionUtils) EvaluationError(com.ibm.cohort.cql.spark.errors.EvaluationError) DataRowRetrieveProvider(com.ibm.cohort.datarow.engine.DataRowRetrieveProvider) Validation(javax.validation.Validation) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) NoSuchElementException(java.util.NoSuchElementException) EvaluationSummary(com.ibm.cohort.cql.spark.metadata.EvaluationSummary) DataRow(com.ibm.cohort.datarow.model.DataRow) SparkSession(org.apache.spark.sql.SparkSession) PrintStream(java.io.PrintStream) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) SaveMode(org.apache.spark.sql.SaveMode) Logger(org.slf4j.Logger) CqlDebug(com.ibm.cohort.cql.evaluation.CqlDebug) Iterator(java.util.Iterator) RowFactory(org.apache.spark.sql.RowFactory) JCommander(com.beust.jcommander.JCommander) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Row(org.apache.spark.sql.Row) CollectionAccumulator(org.apache.spark.util.CollectionAccumulator) InputStreamReader(java.io.InputStreamReader) JavaPairRDD(org.apache.spark.api.java.JavaPairRDD) LongAccumulator(org.apache.spark.util.LongAccumulator) CqlExpressionConfiguration(com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration) AnyColumnFunctions(com.ibm.cohort.cql.functions.AnyColumnFunctions) MDC(org.slf4j.MDC) UnsupportedTerminologyProvider(com.ibm.cohort.cql.terminology.UnsupportedTerminologyProvider) CohortExternalFunctionProvider(com.ibm.cohort.cql.functions.CohortExternalFunctionProvider) ContextDefinitions(com.ibm.cohort.cql.spark.aggregation.ContextDefinitions) Collections(java.util.Collections) OutputMetadataWriter(com.ibm.cohort.cql.spark.metadata.OutputMetadataWriter) ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ClassInfo(org.hl7.elm_modelinfo.r1.ClassInfo)

Example 3 with ModelInfo

use of org.hl7.elm_modelinfo.r1.ModelInfo in project quality-measure-and-cohort-service by Alvearie.

the class CustomModelInfoProvider method addModel.

protected void addModel(ModelInfo modelInfo) {
    VersionedIdentifier modelId = new VersionedIdentifier().withId(modelInfo.getName()).withVersion(modelInfo.getVersion());
    models.put(modelId, modelInfo);
}
Also used : VersionedIdentifier(org.hl7.elm.r1.VersionedIdentifier)

Example 4 with ModelInfo

use of org.hl7.elm_modelinfo.r1.ModelInfo in project quality-measure-and-cohort-service by Alvearie.

the class ModelUtilsTest method testGetBaseTypeNameIncludedNamespacePrefixMissing.

@Test
public void testGetBaseTypeNameIncludedNamespacePrefixMissing() {
    ModelSpecifier otherModel = new ModelSpecifier().withName("Other").withVersion("1.2.3").withUrl("urn:oid:Other");
    ModelInfo modelInfo = new ModelInfo();
    modelInfo.setName("Dummy");
    modelInfo.setVersion("5.4.3");
    modelInfo.setUrl("urn:oid:Dummy");
    modelInfo.getRequiredModelInfo().add(otherModel);
    ClassInfo typeInfo = new ClassInfo();
    typeInfo.setName("MyType");
    typeInfo.setBaseType("Missing.BaseType");
    IllegalArgumentException iex = assertThrows(IllegalArgumentException.class, () -> ModelUtils.getBaseTypeName(modelInfo, typeInfo));
    assertTrue(iex.getMessage(), iex.getMessage().contains("Missing"));
    assertTrue(iex.getMessage(), iex.getMessage().contains(modelInfo.getName()));
    assertTrue(iex.getMessage(), iex.getMessage().contains(modelInfo.getVersion()));
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) ModelSpecifier(org.hl7.elm_modelinfo.r1.ModelSpecifier) ClassInfo(org.hl7.elm_modelinfo.r1.ClassInfo) Test(org.junit.Test)

Example 5 with ModelInfo

use of org.hl7.elm_modelinfo.r1.ModelInfo in project quality-measure-and-cohort-service by Alvearie.

the class ModelUtilsTest method testGetBaseTypeNameNoNamespacePrefix.

@Test
public void testGetBaseTypeNameNoNamespacePrefix() {
    ModelInfo modelInfo = new ModelInfo();
    modelInfo.setName("Dummy");
    modelInfo.setUrl("urn:oid:Dummy");
    ClassInfo typeInfo = new ClassInfo();
    typeInfo.setName("MyType");
    typeInfo.setBaseType("BaseType");
    QName qname = ModelUtils.getBaseTypeName(modelInfo, typeInfo);
    assertEquals(new QName(modelInfo.getUrl(), "BaseType"), qname);
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) QName(javax.xml.namespace.QName) ClassInfo(org.hl7.elm_modelinfo.r1.ClassInfo) Test(org.junit.Test)

Aggregations

ModelInfo (org.hl7.elm_modelinfo.r1.ModelInfo)25 Test (org.junit.Test)13 ClassInfo (org.hl7.elm_modelinfo.r1.ClassInfo)12 QName (javax.xml.namespace.QName)11 File (java.io.File)7 Map (java.util.Map)5 TypeNode (com.ibm.cohort.cql.spark.optimizer.ModelUtils.TypeNode)4 IOException (java.io.IOException)4 Collection (java.util.Collection)4 Collectors (java.util.stream.Collectors)4 VersionedIdentifier (org.hl7.elm.r1.VersionedIdentifier)4 ModelSpecifier (org.hl7.elm_modelinfo.r1.ModelSpecifier)4 TypeInfo (org.hl7.elm_modelinfo.r1.TypeInfo)4 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 List (java.util.List)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 CqlEvaluationRequest (com.ibm.cohort.cql.evaluation.CqlEvaluationRequest)2 CqlEvaluationRequests (com.ibm.cohort.cql.evaluation.CqlEvaluationRequests)2