use of org.hl7.fhir.r5.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);
}
use of org.hl7.fhir.r5.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);
}
use of org.hl7.fhir.r5.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);
}
use of org.hl7.fhir.r5.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()");
}
}
}
use of org.hl7.fhir.r5.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());
}
}
}
Aggregations