diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/candidate/EmpiCandidateSearchCriteriaBuilderSvc.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/candidate/EmpiCandidateSearchCriteriaBuilderSvc.java index 00c93ce4a00..38c7753941b 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/candidate/EmpiCandidateSearchCriteriaBuilderSvc.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/candidate/EmpiCandidateSearchCriteriaBuilderSvc.java @@ -46,16 +46,17 @@ public class EmpiCandidateSearchCriteriaBuilderSvc { public Optional buildResourceQueryString(String theResourceType, IAnyResource theResource, List theFilterCriteria, EmpiResourceSearchParamJson resourceSearchParam) { List criteria = new ArrayList<>(); - resourceSearchParam.iterator().forEachRemaining(searchParam -> { - //to compare it to all known PERSON objects, using the overlapping search parameters that they have. - List valuesFromResourceForSearchParam = myEmpiSearchParamSvc.getValueFromResourceForSearchParam(theResource, searchParam); - if (!valuesFromResourceForSearchParam.isEmpty()) { - criteria.add(buildResourceMatchQuery(searchParam, valuesFromResourceForSearchParam)); - } - }); - if (criteria.isEmpty()) { - return Optional.empty(); + //If there is no candidateSearchParams, then we want to just use the filters. + if (resourceSearchParam != null) { + resourceSearchParam.iterator().forEachRemaining(searchParam -> { + //to compare it to all known PERSON objects, using the overlapping search parameters that they have. + List valuesFromResourceForSearchParam = myEmpiSearchParamSvc.getValueFromResourceForSearchParam(theResource, searchParam); + if (!valuesFromResourceForSearchParam.isEmpty()) { + criteria.add(buildResourceMatchQuery(searchParam, valuesFromResourceForSearchParam)); + } + }); } + criteria.addAll(theFilterCriteria); return Optional.of(theResourceType + "?" + String.join("&", criteria)); } diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/candidate/EmpiCandidateSearchSvc.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/candidate/EmpiCandidateSearchSvc.java index e78ba51cb27..175a753a7dd 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/candidate/EmpiCandidateSearchSvc.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/candidate/EmpiCandidateSearchSvc.java @@ -80,13 +80,18 @@ public class EmpiCandidateSearchSvc { List filterCriteria = buildFilterQuery(filterSearchParams, theResourceType); - for (EmpiResourceSearchParamJson resourceSearchParam : myEmpiConfig.getEmpiRules().getCandidateSearchParams()) { + List candidateSearchParams = myEmpiConfig.getEmpiRules().getCandidateSearchParams(); + if (candidateSearchParams == null || candidateSearchParams.isEmpty()) { + searchForIdsAndAddToMap(theResourceType, theResource, matchedPidsToResources, filterCriteria, null); + } else { + for (EmpiResourceSearchParamJson resourceSearchParam : candidateSearchParams) { - if (!isSearchParamForResource(theResourceType, resourceSearchParam)) { - continue; + if (!isSearchParamForResource(theResourceType, resourceSearchParam)) { + continue; + } + + searchForIdsAndAddToMap(theResourceType, theResource, matchedPidsToResources, filterCriteria, resourceSearchParam); } - - searchForIdsAndAddToMap(theResourceType, theResource, matchedPidsToResources, filterCriteria, resourceSearchParam); } //Obviously we don't want to consider the freshly added resource as a potential candidate. //Sometimes, we are running this function on a resource that has not yet been persisted,