Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Added fhirPath and valueFhirPath Feature #10

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/main/java/de/numcodex/sq2cql/model/Mapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,46 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public final class Mapping {

private final TermCode concept;
private final TermCode termCodeKey;
private final String resourceType;
private final List<Modifier> fixedCriteria;
private final String valueFhirPath;

private Mapping(TermCode concept, String resourceType, List<Modifier> fixedCriteria) {
this.concept = concept;
private Mapping(TermCode termCodeKey, String resourceType, String valueFhirPath, List<Modifier> fixedCriteria) {
this.termCodeKey = termCodeKey;
this.resourceType = resourceType;
this.valueFhirPath = valueFhirPath;
this.fixedCriteria = fixedCriteria;
}

@JsonCreator
public static Mapping of(@JsonProperty("key") TermCode concept,
public static Mapping of(@JsonProperty("key") TermCode termCodeKey,
@JsonProperty("fhirResourceType") String resourceType,
@JsonProperty("valueFhirPath") String valueFhirPath,
@JsonProperty("fixedCriteria") Modifier... fixedCriteria) {
return new Mapping(Objects.requireNonNull(concept), Objects.requireNonNull(resourceType),
return new Mapping(Objects.requireNonNull(termCodeKey), Objects.requireNonNull(resourceType),
valueFhirPath,
fixedCriteria == null ? List.of() : List.of(fixedCriteria));
}

public TermCode getConcept() {
return concept;
public TermCode getKey() {
return termCodeKey;
}

public String getResourceType() {
return resourceType;
}

public String getValueFhirPath(){
return valueFhirPath;
}

public String getFhirPath() {
if (fixedCriteria.size() == 0){
return "value";
}
return fixedCriteria.get(0).getFhirPath();
}
public List<Modifier> getFixedCriteria() {
return fixedCriteria;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final class TermCode {
private final String code;
private final String display;

private TermCode(String system, String code, String display) {
public TermCode(String system, String code, String display) {
this.system = Objects.requireNonNull(system);
this.code = Objects.requireNonNull(code);
this.display = Objects.requireNonNull(display);
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/de/numcodex/sq2cql/model/cql/RetrieveExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,28 @@ public final class RetrieveExpression implements Expression {

private final String resourceType;
private final Expression terminology;
private final String valueFhirPath;
private final String fhirPath;

private RetrieveExpression(String resourceType, Expression terminology) {
private RetrieveExpression(String resourceType, Expression terminology, String valueFhirPath, String fhirPath) {
this.resourceType = Objects.requireNonNull(resourceType);
this.terminology = Objects.requireNonNull(terminology);
this.valueFhirPath = valueFhirPath;
this.fhirPath = fhirPath;
}

public static RetrieveExpression of(String resourceType, Expression terminology) {
return new RetrieveExpression(resourceType, terminology);
public static RetrieveExpression of(String resourceType, Expression terminology, String valueFhirPath, String fhirPath) {
return new RetrieveExpression(resourceType, terminology, valueFhirPath, fhirPath);
}

public String getResourceType() {
return resourceType;
}

public String getValueFhirPath() { return valueFhirPath; }

public String getFhirPath() { return fhirPath; }

@Override
public String print(PrintContext printContext) {
return "[%s: %s]".formatted(resourceType, terminology.print(printContext));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static Container<CodeSelector> codeSelector(MappingContext mappingContext, TermC
static Container<RetrieveExpression> retrieveExpr(MappingContext mappingContext, TermCode concept) {
return codeSelector(mappingContext, concept).map(terminology -> {
var mapping = mappingContext.getMapping(concept).orElseThrow(() -> new MappingNotFoundException(concept));
return RetrieveExpression.of(mapping.getResourceType(), terminology);
return RetrieveExpression.of(mapping.getResourceType(), terminology, mapping.getValueFhirPath(), mapping.getFhirPath());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public Container<BooleanExpression> expression(MappingContext mappingContext, Ex
return Container.of(MembershipExpression.in(propertyExpr, list));
}

@Override
public String getFhirPath() {
return path;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public Container<BooleanExpression> expression(MappingContext mappingContext, Ex
.reduce(Container.empty(), Container.OR);
}

@Override
public String getFhirPath() {
return path;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public interface Criterion {
@JsonCreator
static Criterion create(@JsonProperty("termCode") TermCode termCode,
@JsonProperty("valueFilter") ObjectNode valueFilter,
@JsonProperty("timeRestriction") ObjectNode timeRestriction) {
@JsonProperty("timeRestriction") ObjectNode timeRestriction,
@JsonProperty("valueFhirPath") String valueFhirPath){
if (valueFilter == null) {
return ConceptCriterion.of(termCode);
}
Expand All @@ -47,7 +48,7 @@ static Criterion create(@JsonProperty("termCode") TermCode termCode,
if (unit == null) {
return NumericCriterion.of(termCode, comparator, value);
} else {
return NumericCriterion.of(termCode, comparator, value, unit.get("code").asText());
return NumericCriterion.of(termCode, comparator, value, unit.get("code").asText(), valueFhirPath);
}
}
if ("quantity-range".equals(type)) {
Expand All @@ -65,7 +66,7 @@ static Criterion create(@JsonProperty("termCode") TermCode termCode,
if (selectedConcepts == null) {
throw new IllegalArgumentException("Missing `selectedConcepts` key in concept criterion.");
}
return ValueSetCriterion.of(termCode, StreamSupport.stream(selectedConcepts.spliterator(), false)
return ValueSetCriterion.of(termCode, "",StreamSupport.stream(selectedConcepts.spliterator(), false)
.map(TermCode::fromJsonNode).toArray(TermCode[]::new));
}
throw new IllegalArgumentException("unknown valueFilter type: " + type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ static Modifier create(@JsonProperty("type") String type,
}

Container<BooleanExpression> expression(MappingContext mappingContext, Expression alias);

String getFhirPath();
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class NumericCriterion extends AbstractCriterion {
private final BigDecimal value;
private final String unit;

private NumericCriterion(TermCode concept, Comparator comparator, BigDecimal value, String unit) {
private NumericCriterion(TermCode concept, Comparator comparator, BigDecimal value, String unit, String valueFhirPath) {
super(concept, List.of());
this.value = Objects.requireNonNull(value);
this.comparator = Objects.requireNonNull(comparator);
Expand All @@ -49,7 +49,7 @@ private NumericCriterion(TermCode concept, Comparator comparator, BigDecimal val
* @return the {@code NumericCriterion}
*/
public static NumericCriterion of(TermCode concept, Comparator comparator, BigDecimal value) {
return new NumericCriterion(concept, comparator, value, null);
return new NumericCriterion(concept, comparator, value, null, "");
}

/**
Expand All @@ -61,8 +61,8 @@ public static NumericCriterion of(TermCode concept, Comparator comparator, BigDe
* @param unit the unit of the value
* @return the {@code NumericCriterion}
*/
public static NumericCriterion of(TermCode concept, Comparator comparator, BigDecimal value, String unit) {
return new NumericCriterion(concept, comparator, value, Objects.requireNonNull(unit));
public static NumericCriterion of(TermCode concept, Comparator comparator, BigDecimal value, String unit, String valueFhirPath) {
return new NumericCriterion(concept, comparator, value, Objects.requireNonNull(unit), valueFhirPath);
}

public Comparator getComparator() {
Expand All @@ -81,7 +81,7 @@ public Container<BooleanExpression> toCql(MappingContext mappingContext) {
return retrieveExpr(mappingContext, termCode).map(retrieveExpr -> {
var alias = AliasExpression.of(retrieveExpr.getResourceType().substring(0, 1));
var sourceClause = SourceClause.of(retrieveExpr, alias);
var castExpr = TypeExpression.of(InvocationExpression.of(alias, "value"), "Quantity");
var castExpr = TypeExpression.of(InvocationExpression.of(alias, retrieveExpr.getValueFhirPath()), "Quantity");
var whereExpression = ComparatorExpression.of(castExpr, comparator, quantityExpression(value, unit));
var queryExpr = QueryExpression.of(sourceClause, WhereClause.of(whereExpression));
return ExistsExpression.of(queryExpr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Container<BooleanExpression> toCql(MappingContext mappingContext) {
return retrieveExpr(mappingContext, termCode).map(retrieveExpr -> {
var alias = AliasExpression.of(retrieveExpr.getResourceType().substring(0, 1));
var sourceClause = SourceClause.of(retrieveExpr, alias);
var castExpr = TypeExpression.of(InvocationExpression.of(alias, "value"), "Quantity");
var castExpr = TypeExpression.of(InvocationExpression.of(alias, retrieveExpr.getValueFhirPath()), "Quantity");
var whereExpression = BetweenExpression.of(castExpr, quantityExpression(lowerBound, unit),
quantityExpression(upperBound, unit));
var queryExpr = QueryExpression.of(sourceClause, WhereClause.of(whereExpression));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ private ValueSetCriterion(TermCode concept, List<TermCode> selectedConcepts) {
* @param selectedConcepts at least one selected value concept
* @return the {@code ValueSetCriterion}
*/
public static ValueSetCriterion of(TermCode concept, TermCode... selectedConcepts) {
public static ValueSetCriterion of(TermCode concept, String fhirPath, TermCode... selectedConcepts) {
if (selectedConcepts == null || selectedConcepts.length == 0) {
throw new IllegalArgumentException("empty selected concepts");
}
return new ValueSetCriterion(concept, List.of(selectedConcepts));
return new ValueSetCriterion(concept,List.of(selectedConcepts));
}

public List<TermCode> getSelectedConcepts() {
Expand All @@ -53,7 +53,7 @@ public Container<BooleanExpression> toCql(MappingContext mappingContext) {
return retrieveExpr(mappingContext, termCode).flatMap(retrieveExpr -> {
var alias = AliasExpression.of(retrieveExpr.getResourceType().substring(0, 1));
var sourceClause = SourceClause.of(retrieveExpr, alias);
var codingExpr = InvocationExpression.of(InvocationExpression.of(alias, "value"), "coding");
var codingExpr = InvocationExpression.of(InvocationExpression.of(alias, retrieveExpr.getFhirPath()), "coding");
return whereExpr(mappingContext, codingExpr).map(whereExpr ->
ExistsExpression.of(QueryExpression.of(sourceClause, WhereClause.of(whereExpr))));
});
Expand Down
Loading