diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseHapiTerminologySvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseHapiTerminologySvcImpl.java index f1a8d5b49f3..daef9c67328 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseHapiTerminologySvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseHapiTerminologySvcImpl.java @@ -990,22 +990,33 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc, } private void addLoincFilterAncestorEqual(String theSystem, QueryBuilder theQb, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter) { - TermConcept code = findCode(theSystem, theFilter.getValue()) - .orElseThrow(() -> new InvalidRequestException("Invalid filter criteria - code does not exist: {" + theSystem + "}" + theFilter.getValue())); + addLoincFilterAncestorEqual(theSystem, theQb, theBool, theFilter.getProperty(), theFilter.getValue()); + } - logFilteringValueOnProperty(theFilter.getValue(), theFilter.getProperty()); - theBool.must(theQb.keyword().onField("myParentPids").matching("" + code.getId()).createQuery()); + private void addLoincFilterAncestorEqual(String theSystem, QueryBuilder theQb, BooleanJunction theBool, String theProperty, String theValue) { + List terms = getAncestorTerms(theSystem, theProperty, theValue); + theBool.must(new TermsQuery(terms)); } private void addLoincFilterAncestorIn(String theSystem, QueryBuilder theQb, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter) { - throw new UnsupportedOperationException(); - // FIXME: DM 2019-09-30 - Working on this presently. - // FIXME: DM 2019-09-25 - Filter with op=IN on ancestor; see #1512 in GitHub. - // FIXME: DM 2019-09-26 - Once implemented, fix changelog entry for #1454 in changes.xml -// String[] values = theFilter.getValue().split(","); -// for (String value : values) { -// logFilteringValueOnProperty(value, theFilter.getProperty()); -// } + String[] values = theFilter.getValue().split(","); + List terms = new ArrayList<>(); + for (String value : values) { + terms.addAll(getAncestorTerms(theSystem, theFilter.getProperty(), value)); + } + theBool.must(new TermsQuery(terms)); + } + + private List getAncestorTerms(String theSystem, String theProperty, String theValue) { + List retVal = new ArrayList<>(); + + TermConcept code = findCode(theSystem, theValue) + .orElseThrow(() -> new InvalidRequestException("Invalid filter criteria - code does not exist: {" + theSystem + "}" + theValue)); + + retVal.add(new Term("myParentPids", "" + code.getId())); + logFilteringValueOnProperty(theValue, theProperty); + + return retVal; } private void handleFilterLoincDescendant(String theSystem, QueryBuilder theQb, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter) { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplDstu3Test.java index e2153aa4e63..9d2d785b5ee 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplDstu3Test.java @@ -619,7 +619,6 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { assertThat(codes, containsInAnyOrder("50015-7", "43343-3", "43343-4", "47239-9")); } - @Ignore("Not yet implemented; see #1512 in GitHub.") @Test public void testExpandValueSetPropertyFilterLoincAncestorWithExcludeAndIn() { createLoincSystemWithSomeCodes(); @@ -707,7 +706,6 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { assertEquals(0, outcome.getExpansion().getContains().size()); } - @Ignore("Not yet implemented; see #1512 in GitHub.") @Test public void testExpandValueSetPropertyFilterLoincAncestorWithIncludeAndIn() { createLoincSystemWithSomeCodes(); diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 816f7f06dea..b72f400977b 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -249,6 +249,10 @@ =]]> or in]]> operators. At present, the ancestor]]> filter can only be used with the =]]> operator. + + Support for the LOINC ancestor]]> filter with the in]]> + operator has been added. + The JPA server failed to find codes defined in not-present codesystems in some cases, and reported that the CodeSystem did not exist. This has been corrected.