Search in sources :

Example 71 with Library

use of org.hl7.fhir.r5.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class DefaultVT method testMeasureEvaluationByMeasureIdentifier.

// to tag a specific test to be part of DVT (deployment verification test)
@Category(DVT.class)
@Test
public /**
 * Test a successful measure evaluation using identifier and version as the lookup key
 */
void testMeasureEvaluationByMeasureIdentifier() throws Exception {
    // You want -Denabled.dark.features=all in your Liberty jvm.options
    Assume.assumeTrue(isServiceDarkFeatureEnabled(CohortEngineRestConstants.DARK_LAUNCHED_MEASURE_EVALUATION));
    final String RESOURCE = getUrlBase() + CohortServiceAPISpec.CREATE_DELETE_EVALUATION_PATH;
    FhirContext fhirContext = FhirContext.forR4();
    IParser parser = fhirContext.newJsonParser().setPrettyPrint(true);
    Library library = TestHelper.getTemplateLibrary();
    Identifier identifier = new Identifier().setValue("measure-identifier").setSystem("http://ibm.com/health/test");
    Measure measure = TestHelper.getTemplateMeasure(library);
    measure.setIdentifier(Arrays.asList(identifier));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    TestHelper.createMeasureArtifact(baos, parser, measure, library);
    // Files.write( baos.toByteArray(), new File("target/test_measure_v1_0_0.zip"));
    Map<String, Parameter> parameterOverrides = new HashMap<>();
    parameterOverrides.put("Measurement Period", new IntervalParameter(new DateParameter("2019-07-04"), true, new DateParameter("2020-07-04"), true));
    MeasureEvaluation requestData = new MeasureEvaluation();
    requestData.setDataServerConfig(dataServerConfig);
    requestData.setTerminologyServerConfig(termServerConfig);
    // This is a patient ID that is assumed to exist in the target FHIR server
    requestData.setPatientId(VALID_PATIENT_ID);
    requestData.setMeasureContext(new MeasureContext(null, parameterOverrides, new com.ibm.cohort.engine.measure.Identifier(identifier.getSystem(), identifier.getValue()), measure.getVersion()));
    requestData.setEvidenceOptions(new MeasureEvidenceOptions(false, MeasureEvidenceOptions.DefineReturnOptions.NONE));
    ObjectMapper om = new ObjectMapper();
    System.out.println(om.writeValueAsString(requestData));
    RequestSpecification request = buildBaseRequest(new Headers()).queryParam(CohortEngineRestHandler.VERSION, ServiceBuildConstants.DATE).multiPart(CohortEngineRestHandler.REQUEST_DATA_PART, requestData, "application/json").multiPart(CohortEngineRestHandler.MEASURE_PART, "test_measure_v1_0_0.zip", new ByteArrayInputStream(baos.toByteArray()));
    ValidatableResponse response = request.post(RESOURCE, getServiceVersion()).then();
    ValidatableResponse vr = runSuccessValidation(response, ContentType.JSON, HttpStatus.SC_OK);
    String expected = getJsonFromFile(ServiceAPIGlobalSpec.EXP_FOLDER_TYPE, "measure_evaluation_exp.json");
    String actual = vr.extract().asString();
    assertMeasureReportEquals(parser, expected, actual, false);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) HashMap(java.util.HashMap) MeasureEvaluation(com.ibm.cohort.engine.api.service.model.MeasureEvaluation) PatientListMeasureEvaluation(com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation) Headers(com.jayway.restassured.response.Headers) RequestSpecification(com.jayway.restassured.specification.RequestSpecification) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) MeasureContext(com.ibm.cohort.engine.measure.MeasureContext) Identifier(org.hl7.fhir.r4.model.Identifier) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) ByteArrayInputStream(java.io.ByteArrayInputStream) Measure(org.hl7.fhir.r4.model.Measure) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) Library(org.hl7.fhir.r4.model.Library) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IParser(ca.uhn.fhir.parser.IParser) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 72 with Library

use of org.hl7.fhir.r5.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class SparkCqlEvaluator method getFilteredRequests.

/**
 * @param requests     Request object to filter.
 * @param libraries    Map of library id to version used for filtering
 *                     down request based on library id. If this argument
 *                     is null or empty, then no library id filtering
 *                     is performed.
 * @param expressions  Used to optionally override which expressions will
 *                     run for each individual CqlEvaluationRequest. If this
 *                     argument is null or empty, no expressions are overwritten.
 *
 * @return CqlEvaluationRequests with the original requests optionally filtered
 *         based on the library ids the.
 *         Requests will optionally have their expressions overridden
 *         by args.expressions. if any are provided.
 *         Individual requests will also will also have any global
 *         parameters set on each individual CqlEvaluationRequest.
 */
protected CqlEvaluationRequests getFilteredRequests(CqlEvaluationRequests requests, Map<String, String> libraries, Collection<String> expressions) {
    if (requests != null) {
        List<CqlEvaluationRequest> evaluations = requests.getEvaluations();
        if (libraries != null && !libraries.isEmpty()) {
            evaluations = evaluations.stream().filter(r -> libraries.keySet().contains(r.getDescriptor().getLibraryId())).collect(Collectors.toList());
        }
        if (expressions != null && !expressions.isEmpty()) {
            evaluations.forEach(x -> x.setExpressions(x.getExpressions().stream().filter(e -> expressions.contains(e.getName())).collect(Collectors.toSet())));
        }
        if (requests.getGlobalParameters() != null) {
            for (CqlEvaluationRequest evaluation : evaluations) {
                for (Map.Entry<String, Parameter> globalParameter : requests.getGlobalParameters().entrySet()) {
                    Map<String, Parameter> parameters = evaluation.getParameters();
                    if (parameters == null) {
                        evaluation.setParameters(new HashMap<>());
                        parameters = evaluation.getParameters();
                    }
                    parameters.putIfAbsent(globalParameter.getKey(), globalParameter.getValue());
                }
            }
        }
        requests.setEvaluations(evaluations);
        jobSpecification.set(requests);
    }
    return requests;
}
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) CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) Map(java.util.Map) HashMap(java.util.HashMap)

Example 73 with Library

use of org.hl7.fhir.r5.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class R4LibraryDependencyGatherer method gatherForLibraryId.

public List<Library> gatherForLibraryId(String rootLibraryId) {
    List<Library> retVal = Collections.emptyList();
    Library rootLibrary = resolveLibrary(rootLibraryId);
    if (rootLibrary != null) {
        retVal = recurse(rootLibrary, new HashSet<>());
    }
    return retVal;
}
Also used : Library(org.hl7.fhir.r4.model.Library) HashSet(java.util.HashSet)

Example 74 with Library

use of org.hl7.fhir.r5.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class R4FhirBundleExtractorTest method extractAll.

@Test
public void extractAll() {
    String firstVersion = "1.0.0";
    String secondVersion = "2.0.0";
    String thirdVersion = "3.0.0";
    String fourthVersion = "4.0.0";
    Library library1 = new Library().setVersion(firstVersion);
    Library library2 = new Library().setVersion(secondVersion);
    Measure measure = new Measure().setVersion(thirdVersion);
    Library library3 = new Library().setVersion(fourthVersion);
    Bundle bundle = new Bundle();
    addToBundle(library1, bundle);
    addToBundle(library2, bundle);
    addToBundle(measure, bundle);
    addToBundle(library3, bundle);
    R4FhirBundleExtractor<Library> extractor = getExtractor();
    List<Library> libraries = extractor.extractAll(bundle);
    List<String> actual = libraries.stream().map(Library::getVersion).collect(Collectors.toList());
    List<String> expected = Arrays.asList(firstVersion, secondVersion, fourthVersion);
    Assert.assertEquals(expected, actual);
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) Measure(org.hl7.fhir.r4.model.Measure) Library(org.hl7.fhir.r4.model.Library) Test(org.junit.Test)

Example 75 with Library

use of org.hl7.fhir.r5.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class R4LibraryDependencyGathererTest method withCodelessType.

private void withCodelessType(Library library) {
    CodeableConcept type = new CodeableConcept();
    type.setText("text");
    library.setType(type);
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Aggregations

Library (org.hl7.fhir.r4.model.Library)130 Test (org.junit.Test)85 Measure (org.hl7.fhir.r4.model.Measure)60 Patient (org.hl7.fhir.r4.model.Patient)41 HashMap (java.util.HashMap)36 Test (org.junit.jupiter.api.Test)34 ArrayList (java.util.ArrayList)32 Library (org.hl7.fhir.dstu3.model.Library)23 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 CapabilityStatement (org.hl7.fhir.r4.model.CapabilityStatement)21 MeasureReport (org.hl7.fhir.r4.model.MeasureReport)21 StringType (org.hl7.fhir.r4.model.StringType)21 IOException (java.io.IOException)20 VersionedIdentifier (org.cqframework.cql.elm.execution.VersionedIdentifier)20 FhirContext (ca.uhn.fhir.context.FhirContext)19 IParser (ca.uhn.fhir.parser.IParser)19 MeasureEvidenceOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions)19 Bundle (org.hl7.fhir.r4.model.Bundle)19 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)18