diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/StringParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/StringParam.java index db31031ad21..fc475699ae4 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/StringParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/StringParam.java @@ -106,6 +106,9 @@ public class StringParam extends BaseParam implements IQueryParameterType { if (myExact) { builder.append("exact", myExact); } + if (getMissing() != null) { + builder.append("missing", getMissing().booleanValue()); + } return builder.toString(); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java index a701831c982..aadb4797b33 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java @@ -1044,6 +1044,9 @@ public abstract class BaseFhirDao implements IDao { quantityParams = extractSearchParamQuantity(entity, theResource); dateParams = extractSearchParamDates(entity, theResource); + ourLog.info("Indexing resource: {}", entity.getId()); + ourLog.info("Storing string indexes: {}", stringParams); + tokenParams = new ArrayList(); for (BaseResourceIndexedSearchParam next : extractSearchParamTokens(entity, theResource)) { if (next instanceof ResourceIndexedSearchParamToken) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java index 00cdf668fb9..f52ceeb9c46 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java @@ -366,25 +366,32 @@ public abstract class BaseFhirResourceDao extends BaseFhirD } private Set addPredicateParamMissing(Set thePids, String joinName, String theParamName, Class theParamTable) { + String resourceType = getContext().getResourceDefinition(getResourceType()).getName(); + CriteriaBuilder builder = myEntityManager.getCriteriaBuilder(); CriteriaQuery cq = builder.createQuery(Long.class); Root from = cq.from(ResourceTable.class); cq.select(from.get("myId").as(Long.class)); - + Subquery subQ = cq.subquery(Long.class); Root subQfrom = subQ.from(theParamTable); subQ.select(subQfrom.get("myResourcePid").as(Long.class)); - subQ.where(builder.equal(subQfrom.get("myParamName"), theParamName)); - + Predicate subQname = builder.equal(subQfrom.get("myParamName"), theParamName); + Predicate subQtype = builder.equal(subQfrom.get("myResourceType"), resourceType); + subQ.where(builder.and(subQtype, subQname)); + Predicate joinPredicate = builder.not(builder.in(from.get("myId")).value(subQ)); + Predicate typePredicate = builder.equal(from.get("myResourceType"), resourceType); if (thePids.size() > 0) { Predicate inPids = (from.get("myId").in(thePids)); - cq.where(builder.and(inPids, joinPredicate)); + cq.where(builder.and(inPids, typePredicate, joinPredicate)); } else { - cq.where(joinPredicate); + cq.where(builder.and(typePredicate, joinPredicate)); } + ourLog.info("Adding :missing qualifier for parameter '{}'", theParamName); + TypedQuery q = myEntityManager.createQuery(cq); List resultList = q.getResultList(); HashSet retVal = new HashSet(resultList); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java index d241569d8e1..d1a72fd4fd9 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java @@ -355,7 +355,7 @@ public class ResourceProviderDstu2Test { List list = toIdListUnqualifiedVersionless(found); ourLog.info(methodName + ": " + list.toString()); assertThat(list, not(containsInRelativeOrder(orgNotMissing))); - assertThat(list, containsInRelativeOrder(orgMissing)); + assertThat("Wanted " + orgMissing + " but found: " + list, list, containsInRelativeOrder(orgMissing)); } }