Search in sources :

Example 86 with Expression

use of org.hl7.fhir.r4b.model.Expression in project pathling by aehrc.

the class CodingLiteralPathTest method roundTripWithQuotedComponentWithSingleQuote.

@Test
void roundTripWithQuotedComponentWithSingleQuote() {
    final String expression = "'Someone\\'s CodeSystem'|166056000";
    final CodingLiteralPath codingLiteralPath = CodingLiteralPath.fromString(expression, inputContext);
    final Coding literalValue = codingLiteralPath.getLiteralValue();
    assertEquals("Someone's CodeSystem", literalValue.getSystem());
    assertEquals("166056000", literalValue.getCode());
    final String actualExpression = codingLiteralPath.getExpression();
    assertEquals(expression, actualExpression);
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 87 with Expression

use of org.hl7.fhir.r4b.model.Expression in project pathling by aehrc.

the class CodingLiteralPathTest method roundTripWithQuotedComponentWithSpace.

@Test
void roundTripWithQuotedComponentWithSpace() {
    final String expression = "'Some CodeSystem'|166056000";
    final CodingLiteralPath codingLiteralPath = CodingLiteralPath.fromString(expression, inputContext);
    final Coding literalValue = codingLiteralPath.getLiteralValue();
    assertEquals("Some CodeSystem", literalValue.getSystem());
    assertEquals("166056000", literalValue.getCode());
    final String actualExpression = codingLiteralPath.getExpression();
    assertEquals(expression, actualExpression);
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 88 with Expression

use of org.hl7.fhir.r4b.model.Expression in project pathling by aehrc.

the class CombineOperatorTest method worksWithLiteralAndNonLiteralCodingValues.

@Test
void worksWithLiteralAndNonLiteralCodingValues() {
    final Dataset<Row> leftDataset = new DatasetBuilder(spark).withIdColumn(idColumnName).withEidColumn().withStructTypeColumns(codingStructType()).withRow("observation-1", makeEid(0), rowFromCoding(new Coding("http://snomed.info/sct", "18001011000036104", null))).buildWithStructValue();
    final ElementPath left = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.CODING).dataset(leftDataset).idAndEidAndValueColumns().expression("valueCoding").singular(false).build();
    final CodingLiteralPath right = CodingLiteralPath.fromString("http://snomed.info/sct|373882004", parserContext.getInputContext());
    final OperatorInput combineInput = new OperatorInput(parserContext, left, right);
    final FhirPath result = Operator.getInstance("combine").invoke(combineInput);
    final Dataset<Row> expectedDataset = new DatasetBuilder(spark).withIdColumn(idColumnName).withStructTypeColumns(codingStructType()).withRow("observation-1", rowFromCoding(new Coding("http://snomed.info/sct", "18001011000036104", null))).withRow("observation-1", rowFromCoding(new Coding("http://snomed.info/sct", "373882004", null))).withRow("observation-2", rowFromCoding(new Coding("http://snomed.info/sct", "373882004", null))).withRow("observation-3", rowFromCoding(new Coding("http://snomed.info/sct", "373882004", null))).buildWithStructValue();
    assertThat(result).hasExpression("valueCoding combine http://snomed.info/sct|373882004").isNotSingular().isElementPath(CodingPath.class).selectResult().hasRowsUnordered(expectedDataset);
}
Also used : ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) CodingLiteralPath(au.csiro.pathling.fhirpath.literal.CodingLiteralPath) FhirPath(au.csiro.pathling.fhirpath.FhirPath) SparkHelpers.rowFromCoding(au.csiro.pathling.test.helpers.SparkHelpers.rowFromCoding) Coding(org.hl7.fhir.r4.model.Coding) Row(org.apache.spark.sql.Row) DatasetBuilder(au.csiro.pathling.test.builders.DatasetBuilder) ElementPathBuilder(au.csiro.pathling.test.builders.ElementPathBuilder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 89 with Expression

use of org.hl7.fhir.r4b.model.Expression in project pathling by aehrc.

the class DrillDownBuilder method addGroupings.

private void addGroupings(final Collection<String> fhirPaths) {
    for (int i = 0; i < groupings.size(); i++) {
        final FhirPath grouping = groupings.get(i);
        final Optional<Type> label = labels.get(i);
        if (label.isPresent()) {
            final String literal = LiteralPath.expressionFor(grouping.getDataset(), grouping.getIdColumn(), label.get());
            final String equality = grouping.isSingular() ? " = " : " contains ";
            // We need to add parentheses around the grouping expression, as some expressions will not
            // play well with the equality or membership operator due to precedence.
            final String expression = literal.equals("true") && grouping.isSingular() ? grouping.getExpression() : parentheses(grouping.getExpression()) + equality + literal;
            fhirPaths.add(expression);
        } else {
            fhirPaths.add(parentheses(grouping.getExpression()) + ".empty()");
        }
    }
}
Also used : Type(org.hl7.fhir.r4.model.Type) FhirPath(au.csiro.pathling.fhirpath.FhirPath)

Example 90 with Expression

use of org.hl7.fhir.r4b.model.Expression in project CRD by HL7-DaVinci.

the class QuestionnaireEmbeddedCQLProcessor method findAndReplaceEmbeddedCql.

private void findAndReplaceEmbeddedCql(List<QuestionnaireItemComponent> itemComponents) {
    for (QuestionnaireItemComponent itemComponent : itemComponents) {
        if (hasEmbeddedCql(itemComponent)) {
            List<Extension> extensionList = itemComponent.getExtension();
            for (int i = 0; i < extensionList.size(); i++) {
                Extension extension = extensionList.get(i);
                if (extension.getUrl().equals("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression")) {
                    Expression expression = (Expression) extension.getValue();
                    if (expression.getLanguage().equals("text/cql")) {
                        String expressionString = expression.getExpression();
                        // regex for \"library\".statement
                        final String libraryRefRegex = "^\"[a-zA-Z0-9]+\".[a-zA-Z0-9]+$";
                        final Pattern pattern = Pattern.compile(libraryRefRegex, Pattern.MULTILINE);
                        // cql-execution library to throw error if it is invalid
                        if (!pattern.matcher(expressionString).find()) {
                            String cqlExpression = String.format(CQL_DEFINE_LINKID_PATTERN, itemComponent.getLinkId(), expressionString);
                            String elm = null;
                            try {
                                elm = CqlExecution.translateToElm(cqlExpression, this);
                            // logger.info("converted elm: " + elm);
                            } catch (Exception e) {
                                logger.error("Failed to convert inline CQL to elm. For linkId " + itemComponent.getLinkId());
                            }
                            if (elm != null) {
                                expression.setExpression(elm);
                                expression.setLanguage("application/elm+json");
                            }
                        }
                    }
                }
            }
        }
        if (itemComponent.hasItem()) {
            findAndReplaceEmbeddedCql(itemComponent.getItem());
        }
    }
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Pattern(java.util.regex.Pattern) QuestionnaireItemComponent(org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent) Expression(org.hl7.fhir.r4.model.Expression)

Aggregations

HashMap (java.util.HashMap)33 Test (org.junit.Test)30 Test (org.junit.jupiter.api.Test)30 Patient (org.hl7.fhir.r4.model.Patient)29 CqlEvaluator (com.ibm.cohort.cql.evaluation.CqlEvaluator)28 CqlVersionedIdentifier (com.ibm.cohort.cql.library.CqlVersionedIdentifier)28 ArrayList (java.util.ArrayList)27 Expression (org.hl7.elm.r1.Expression)26 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)25 CqlEvaluationResult (com.ibm.cohort.cql.evaluation.CqlEvaluationResult)24 FHIRException (org.hl7.fhir.exceptions.FHIRException)19 FhirServerConfig (com.ibm.cohort.fhir.client.config.FhirServerConfig)16 Coding (org.hl7.fhir.r4.model.Coding)15 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)14 Row (org.apache.spark.sql.Row)12 List (java.util.List)11 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)11 FhirPath (au.csiro.pathling.fhirpath.FhirPath)10 Nonnull (javax.annotation.Nonnull)10 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)9