Fix processing of NotSelectable filters using in | not-in

This commit is contained in:
Grahame Grieve 2024-03-14 16:47:45 +11:00
parent 93c98b551a
commit e0d17ceb97
4 changed files with 37 additions and 7 deletions

View File

@ -9,6 +9,7 @@ import org.hl7.fhir.r5.model.CodeSystem.PropertyComponent;
import org.hl7.fhir.r5.model.CodeSystem.PropertyType;
import org.hl7.fhir.r5.model.Enumerations.FilterOperator;
import org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent;
import org.hl7.fhir.utilities.Utilities;
public class KnownPropertyFilter extends ConceptFilter {
@ -31,10 +32,10 @@ public class KnownPropertyFilter extends ConceptFilter {
case EQUAL: return filter.getValue().equals(v);
case EXISTS: throw fail("not supported yet: "+filter.getOp().toCode());
case GENERALIZES: throw fail("not supported yet: "+filter.getOp().toCode());
case IN: throw fail("not supported yet: "+filter.getOp().toCode());
case IN: return Utilities.existsInListTrimmed(v, filter.getValue().split("\\,"));
case ISA: throw fail("not supported yet: "+filter.getOp().toCode());
case ISNOTA: throw fail("not supported yet: "+filter.getOp().toCode());
case NOTIN: throw fail("not supported yet: "+filter.getOp().toCode());
case NOTIN: return Utilities.existsInListTrimmed(v, filter.getValue().split("\\,"));
case NULL: throw fail("not supported yet: "+filter.getOp().toCode());
case REGEX: throw fail("not supported yet: "+filter.getOp().toCode());
default:

View File

@ -9,6 +9,7 @@ import org.hl7.fhir.r5.model.CodeSystem.PropertyComponent;
import org.hl7.fhir.r5.model.CodeSystem.PropertyType;
import org.hl7.fhir.r5.model.Enumerations.FilterOperator;
import org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent;
import org.hl7.fhir.utilities.Utilities;
public class PropertyFilter extends ConceptFilter {
@ -31,17 +32,17 @@ public class PropertyFilter extends ConceptFilter {
case EQUAL: return filter.getValue().equals(v);
case EXISTS: throw fail("not supported yet: "+filter.getOp().toCode());
case GENERALIZES: throw fail("not supported yet: "+filter.getOp().toCode());
case IN: throw fail("not supported yet: "+filter.getOp().toCode());
case IN: return Utilities.existsInListTrimmed(v, filter.getValue().split("\\,"));
case ISA: throw fail("not supported yet: "+filter.getOp().toCode());
case ISNOTA: throw fail("not supported yet: "+filter.getOp().toCode());
case NOTIN: throw fail("not supported yet: "+filter.getOp().toCode());
case NOTIN: return !Utilities.existsInListTrimmed(v, filter.getValue().split("\\,"));
case NULL: throw fail("not supported yet: "+filter.getOp().toCode());
case REGEX: throw fail("not supported yet: "+filter.getOp().toCode());
default:
throw fail("Shouldn't get here");
}
} else {
return false;
return filter.getOp() == FilterOperator.NOTIN;
}
}

View File

@ -680,8 +680,6 @@ public class ValueSetExpander extends ValueSetProcessBase {
if (debug) {
e.printStackTrace();
}
// well, we couldn't expand, so we'll return an interface to a checker that can check membership of the set
// that might fail too, but it might not, later.
return new ValueSetExpansionOutcome(e.getMessage(), TerminologyServiceErrorClass.UNKNOWN, allErrors, e instanceof EFhirClientException || e instanceof TerminologyServiceException);
}
}

View File

@ -1395,6 +1395,36 @@ public class ValueSetValidator extends ValueSetProcessBase {
}
d = CodeSystemUtilities.getProperty(cs, code, f.getProperty());
return d != null && d.primitiveValue() != null && d.primitiveValue().matches(f.getValue());
case IN:
if (f.getValue() == null) {
return false;
}
String[] values = f.getValue().split("\\,");
d = CodeSystemUtilities.getProperty(cs, code, f.getProperty());
if (d != null) {
String v = d.primitiveValue();
for (String value : values) {
if (v != null && v.equals(value.trim())) {
return true;
}
}
}
return false;
case NOTIN:
if (f.getValue() == null) {
return true;
}
values = f.getValue().split("\\,");
d = CodeSystemUtilities.getProperty(cs, code, f.getProperty());
if (d != null) {
String v = d.primitiveValue();
for (String value : values) {
if (v != null && v.equals(value.trim())) {
return false;
}
}
}
return true;
default:
System.out.println("todo: handle property filters with op = "+f.getOp());
throw new FHIRException(context.formatMessage(I18nConstants.UNABLE_TO_HANDLE_SYSTEM__PROPERTY_FILTER_WITH_OP__, cs.getUrl(), f.getOp()));