Merge pull request #877 from anthonys123/master

Fixes for issue #512 (:contains modifier not working).
This commit is contained in:
James Agnew 2018-03-26 08:40:44 -04:00 committed by GitHub
commit 5beeda1af3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -60,6 +60,8 @@ public class DaoConfig {
* update setter javadoc if default changes
*/
private boolean myAllowExternalReferences = false;
private boolean myAllowContainsSearches = true;
/**
* update setter javadoc if default changes
*/
@ -1097,6 +1099,16 @@ public class DaoConfig {
}
public boolean allowContainsSearches() {
return myAllowContainsSearches;
}
public void setAllowContainsSearches(boolean myAllowContainsSearches) {
this.myAllowContainsSearches = myAllowContainsSearches;
}
public enum IndexEnabledEnum {
ENABLED,
DISABLED

View File

@ -28,6 +28,7 @@ import ca.uhn.fhir.jpa.search.JpaRuntimeSearchParam;
import ca.uhn.fhir.jpa.term.IHapiTerminologySvc;
import ca.uhn.fhir.jpa.term.VersionIndependentConcept;
import ca.uhn.fhir.jpa.util.BaseIterator;
import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException;
import ca.uhn.fhir.util.StopWatch;
import ca.uhn.fhir.model.api.*;
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
@ -1090,6 +1091,11 @@ public class SearchBuilder implements ISearchBuilder {
} else if (theParameter instanceof StringParam) {
StringParam id = (StringParam) theParameter;
rawSearchTerm = id.getValue();
if ((id.isContains()) &&
(!myCallingDao.getConfig().allowContainsSearches()))
{
throw new MethodNotAllowedException(":contains modifier is disabled on this server");
}
} else if (theParameter instanceof IPrimitiveDatatype<?>) {
IPrimitiveDatatype<?> id = (IPrimitiveDatatype<?>) theParameter;
rawSearchTerm = id.getValueAsString();
@ -1103,7 +1109,20 @@ public class SearchBuilder implements ISearchBuilder {
}
String likeExpression = BaseHapiFhirDao.normalizeString(rawSearchTerm);
likeExpression = createLeftMatchLikeExpression(likeExpression);
if (myCallingDao.getConfig().allowContainsSearches()) {
if (theParameter instanceof StringParam) {
if (((StringParam) theParameter).isContains()) {
likeExpression = createLeftAndRightMatchLikeExpression(likeExpression);
} else {
likeExpression = createLeftMatchLikeExpression(likeExpression);
}
} else {
likeExpression = createLeftMatchLikeExpression(likeExpression);
}
}
else {
likeExpression = createLeftMatchLikeExpression(likeExpression);
}
Predicate singleCode = theBuilder.like(theFrom.get("myValueNormalized").as(String.class), likeExpression);
if (theParameter instanceof StringParam && ((StringParam) theParameter).isExact()) {
@ -2005,6 +2024,10 @@ public class SearchBuilder implements ISearchBuilder {
return likeExpression.replace("%", "[%]") + "%";
}
private static String createLeftAndRightMatchLikeExpression(String likeExpression) {
return "%" + likeExpression.replace("%", "[%]") + "%";
}
private static Predicate createResourceLinkPathPredicate(IDao theCallingDao, FhirContext theContext, String theParamName, From<?, ? extends ResourceLink> theFrom,
String theResourceType) {
RuntimeResourceDefinition resourceDef = theContext.getResourceDefinition(theResourceType);