Perf updates possibly working?
This commit is contained in:
parent
aa02dd5037
commit
0a8900ee78
|
@ -143,7 +143,7 @@ public class SearchBuilder {
|
|||
Join<ResourceTable, ResourceIndexedSearchParamDate> join = myResourceTableRoot.join("myParamsDate", JoinType.LEFT);
|
||||
|
||||
if (theList.get(0).getMissing() != null) {
|
||||
addPredicateParamMissing(theParamName, theList.get(0).getMissing(), join);
|
||||
addPredicateParamMissing(theResourceName, theParamName, theList.get(0).getMissing(), join);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -269,7 +269,7 @@ public class SearchBuilder {
|
|||
Join<ResourceTable, ResourceIndexedSearchParamNumber> join = myResourceTableRoot.join("myParamsNumber", JoinType.LEFT);
|
||||
|
||||
if (theList.get(0).getMissing() != null) {
|
||||
addPredicateParamMissing(theParamName, theList.get(0).getMissing(), join);
|
||||
addPredicateParamMissing(theResourceName, theParamName, theList.get(0).getMissing(), join);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -302,18 +302,18 @@ public class SearchBuilder {
|
|||
myPredicates.add(myBuilder.or(toArray(codePredicates)));
|
||||
}
|
||||
|
||||
private void addPredicateParamMissing(String theParamName, boolean theMissing, Join<ResourceTable, ? extends BaseResourceIndexedSearchParam> theJoin) {
|
||||
private void addPredicateParamMissing(String theResourceName, String theParamName, boolean theMissing, Join<ResourceTable, ? extends BaseResourceIndexedSearchParam> theJoin) {
|
||||
|
||||
myPredicates.add(myBuilder.equal(theJoin.get("myResourceType"), myResourceName));
|
||||
myPredicates.add(myBuilder.equal(theJoin.get("myResourceType"), theResourceName));
|
||||
myPredicates.add(myBuilder.equal(theJoin.get("myParamName"), theParamName));
|
||||
myPredicates.add(myBuilder.equal(theJoin.get("myMissing"), theMissing));
|
||||
}
|
||||
|
||||
private void addPredicateParamMissing(String theParamName, boolean theMissing) {
|
||||
private void addPredicateParamMissing(String theResourceName, String theParamName, boolean theMissing) {
|
||||
Join<ResourceTable, SearchParamPresent> paramPresentJoin = myResourceTableRoot.join("mySearchParamPresents", JoinType.LEFT);
|
||||
Join<SearchParamPresent, SearchParam> paramJoin = paramPresentJoin.join("mySearchParam", JoinType.LEFT);
|
||||
|
||||
myPredicates.add(myBuilder.equal(paramJoin.get("myResourceName"), myResourceName));
|
||||
myPredicates.add(myBuilder.equal(paramJoin.get("myResourceName"), theResourceName));
|
||||
myPredicates.add(myBuilder.equal(paramJoin.get("myParamName"), theParamName));
|
||||
myPredicates.add(myBuilder.equal(paramPresentJoin.get("myPresent"), !theMissing));
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ public class SearchBuilder {
|
|||
Join<ResourceTable, ResourceIndexedSearchParamQuantity> join = myResourceTableRoot.join("myParamsQuantity", JoinType.LEFT);
|
||||
|
||||
if (theList.get(0).getMissing() != null) {
|
||||
addPredicateParamMissing(theParamName, theList.get(0).getMissing(), join);
|
||||
addPredicateParamMissing(theResourceName, theParamName, theList.get(0).getMissing(), join);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -336,11 +336,14 @@ public class SearchBuilder {
|
|||
myPredicates.add(myBuilder.or(toArray(codePredicates)));
|
||||
}
|
||||
|
||||
private void addPredicateReference(String theParamName, List<? extends IQueryParameterType> theList) {
|
||||
/**
|
||||
* Add reference predicate to the current search
|
||||
*/
|
||||
private void addPredicateReference(String theResourceName, String theParamName, List<? extends IQueryParameterType> theList) {
|
||||
assert theParamName.contains(".") == false;
|
||||
|
||||
if (theList.get(0).getMissing() != null) {
|
||||
addPredicateParamMissing(theParamName, theList.get(0).getMissing());
|
||||
addPredicateParamMissing(theResourceName, theParamName, theList.get(0).getMissing());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -377,8 +380,10 @@ public class SearchBuilder {
|
|||
}
|
||||
for (Long next : targetPid) {
|
||||
ourLog.debug("Searching for resource link with target PID: {}", next);
|
||||
Predicate eq = myBuilder.equal(join.get("myTargetResourcePid"), next);
|
||||
codePredicates.add(eq);
|
||||
|
||||
Predicate pathPredicate = createResourceLinkPathPredicate(theResourceName, theParamName, join);
|
||||
Predicate pidPredicate = myBuilder.equal(join.get("myTargetResourcePid"), next);
|
||||
codePredicates.add(myBuilder.and(pathPredicate, pidPredicate));
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -469,7 +474,6 @@ public class SearchBuilder {
|
|||
}
|
||||
|
||||
foundChainMatch = true;
|
||||
// Set<Long> pids = dao.searchForIds(chain, chainValue);
|
||||
|
||||
Subquery<Long> subQ = myResourceTableQuery.subquery(Long.class);
|
||||
Root<ResourceTable> subQfrom = subQ.from(ResourceTable.class);
|
||||
|
@ -501,8 +505,9 @@ public class SearchBuilder {
|
|||
myResourceTableRoot = stackRoot;
|
||||
myPredicates = stackPredicates;
|
||||
|
||||
Predicate eq = join.get("myTargetResourcePid").in(subQ);
|
||||
codePredicates.add(eq);
|
||||
Predicate pathPredicate = createResourceLinkPathPredicate(theResourceName, theParamName, join);
|
||||
Predicate pidPredicate = join.get("myTargetResourcePid").in(subQ);
|
||||
codePredicates.add(myBuilder.and(pathPredicate, pidPredicate));
|
||||
|
||||
}
|
||||
|
||||
|
@ -525,7 +530,7 @@ public class SearchBuilder {
|
|||
Join<ResourceTable, ResourceIndexedSearchParamString> join = myResourceTableRoot.join("myParamsString", JoinType.LEFT);
|
||||
|
||||
if (theList.get(0).getMissing() != null) {
|
||||
addPredicateParamMissing(theParamName, theList.get(0).getMissing(), join);
|
||||
addPredicateParamMissing(theResourceName, theParamName, theList.get(0).getMissing(), join);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -673,7 +678,7 @@ public class SearchBuilder {
|
|||
Join<ResourceTable, ResourceIndexedSearchParamToken> join = myResourceTableRoot.join("myParamsToken", JoinType.LEFT);
|
||||
|
||||
if (theList.get(0).getMissing() != null) {
|
||||
addPredicateParamMissing(theParamName, theList.get(0).getMissing(), join);
|
||||
addPredicateParamMissing(theResourceName, theParamName, theList.get(0).getMissing(), join);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -700,12 +705,12 @@ public class SearchBuilder {
|
|||
myPredicates.add(spPredicate);
|
||||
}
|
||||
|
||||
private void addPredicateUri(String theParamName, List<? extends IQueryParameterType> theList) {
|
||||
private void addPredicateUri(String theResourceName, String theParamName, List<? extends IQueryParameterType> theList) {
|
||||
|
||||
Join<ResourceTable, ResourceIndexedSearchParamUri> join = myResourceTableRoot.join("myParamsUri", JoinType.LEFT);
|
||||
|
||||
if (theList.get(0).getMissing() != null) {
|
||||
addPredicateParamMissing(theParamName, theList.get(0).getMissing(), join);
|
||||
addPredicateParamMissing(theResourceName, theParamName, theList.get(0).getMissing(), join);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1172,8 +1177,8 @@ public class SearchBuilder {
|
|||
return combineParamIndexPredicateWithParamNamePredicate(theResourceName, theParamName, theFrom, singleCode);
|
||||
}
|
||||
|
||||
private Predicate createResourceLinkPathPredicate(String theParamName, From<?, ? extends ResourceLink> from) {
|
||||
return createResourceLinkPathPredicate(myCallingDao, myContext, theParamName, from, myResourceType);
|
||||
private Predicate createResourceLinkPathPredicate(String theResourceName, String theParamName, From<?, ? extends ResourceLink> from) {
|
||||
return createResourceLinkPathPredicate(myCallingDao, myContext, theParamName, from, theResourceName);
|
||||
}
|
||||
|
||||
private TypedQuery<Long> createSearchAllByTypeQuery(DateRangeParam theLastUpdated) {
|
||||
|
@ -1750,7 +1755,7 @@ public class SearchBuilder {
|
|||
break;
|
||||
case REFERENCE:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateReference(theParamName, nextAnd);
|
||||
addPredicateReference(theResourceName, theParamName, nextAnd);
|
||||
}
|
||||
break;
|
||||
case STRING:
|
||||
|
@ -1775,7 +1780,7 @@ public class SearchBuilder {
|
|||
break;
|
||||
case URI:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateUri(theParamName, nextAnd);
|
||||
addPredicateUri(theResourceName, theParamName, nextAnd);
|
||||
}
|
||||
break;
|
||||
case HAS:
|
||||
|
@ -1915,12 +1920,12 @@ public class SearchBuilder {
|
|||
return likeExpression.replace("%", "[%]") + "%";
|
||||
}
|
||||
|
||||
private static Predicate createResourceLinkPathPredicate(IDao theCallingDao, FhirContext theContext, String theParamName, From<?, ? extends ResourceLink> from,
|
||||
Class<? extends IBaseResource> resourceType) {
|
||||
RuntimeResourceDefinition resourceDef = theContext.getResourceDefinition(resourceType);
|
||||
private static Predicate createResourceLinkPathPredicate(IDao theCallingDao, FhirContext theContext, String theParamName, From<?, ? extends ResourceLink> theFrom,
|
||||
String theResourceType) {
|
||||
RuntimeResourceDefinition resourceDef = theContext.getResourceDefinition(theResourceType);
|
||||
RuntimeSearchParam param = theCallingDao.getSearchParamByName(resourceDef, theParamName);
|
||||
List<String> path = param.getPathsSplit();
|
||||
Predicate type = from.get("mySourcePath").in(path);
|
||||
Predicate type = theFrom.get("mySourcePath").in(path);
|
||||
return type;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Set;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.hl7.fhir.dstu3.model.Task;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.junit.AfterClass;
|
||||
|
@ -106,6 +107,9 @@ import ca.uhn.fhir.util.TestUtil;
|
|||
public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2SearchNoFtTest.class);
|
||||
|
||||
@Autowired
|
||||
private ISearchParamPresentDao mySearchParamPresentDao;
|
||||
|
||||
@Test
|
||||
public void testCodeSearch() {
|
||||
Subscription subs = new Subscription();
|
||||
|
@ -1270,9 +1274,6 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
|
|||
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ISearchParamPresentDao mySearchParamPresentDao;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Test
|
||||
public void testSearchResourceReferenceMissing() {
|
||||
|
@ -1417,7 +1418,8 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
|
|||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setSystem("urn:system").setValue("testSearchTokenParam001");
|
||||
patient.addName().addFamily("Tester").addGiven("testSearchTokenParam1");
|
||||
patient.addCommunication().getLanguage().setText("testSearchTokenParamComText").addCoding().setCode("testSearchTokenParamCode").setSystem("testSearchTokenParamSystem").setDisplay("testSearchTokenParamDisplay");
|
||||
patient.addCommunication().getLanguage().setText("testSearchTokenParamComText").addCoding().setCode("testSearchTokenParamCode").setSystem("testSearchTokenParamSystem")
|
||||
.setDisplay("testSearchTokenParamDisplay");
|
||||
myPatientDao.create(patient, mySrd);
|
||||
|
||||
patient = new Patient();
|
||||
|
|
|
@ -148,6 +148,9 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest {
|
|||
@Qualifier("myOrganizationDaoDstu3")
|
||||
protected IFhirResourceDao<Organization> myOrganizationDao;
|
||||
@Autowired
|
||||
@Qualifier("myTaskDaoDstu3")
|
||||
protected IFhirResourceDao<Task> myTaskDao;
|
||||
@Autowired
|
||||
@Qualifier("myPatientDaoDstu3")
|
||||
protected IFhirResourceDaoPatient<Patient> myPatientDao;
|
||||
@Autowired
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.junit.Test;
|
|||
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
|
||||
import ca.uhn.fhir.rest.param.TokenParam;
|
||||
import ca.uhn.fhir.rest.server.IBundleProvider;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
|
@ -238,8 +239,12 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu
|
|||
// Try with custom gender SP
|
||||
map = new SearchParameterMap();
|
||||
map.add("foo", new TokenParam(null, "male"));
|
||||
IBundleProvider res = myPatientDao.search(map);
|
||||
assertEquals(0, res.size());
|
||||
try {
|
||||
myPatientDao.search(map);
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("Unknown search parameter foo for resource type Patient", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -272,9 +277,12 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu
|
|||
// Try with custom gender SP (should find nothing)
|
||||
map = new SearchParameterMap();
|
||||
map.add("foo", new TokenParam(null, "male"));
|
||||
results = myPatientDao.search(map);
|
||||
foundResources = toUnqualifiedVersionlessIdValues(results);
|
||||
assertThat(foundResources, empty());
|
||||
try {
|
||||
myPatientDao.search(map);
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("Unknown search parameter foo for resource type Patient", e.getMessage());
|
||||
}
|
||||
|
||||
// Try with normal gender SP
|
||||
map = new SearchParameterMap();
|
||||
|
|
|
@ -85,6 +85,103 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
|
|||
myDaoConfig.setExpireSearchResultsAfterMillis(new DaoConfig().getExpireSearchResultsAfterMillis());
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Test
|
||||
public void testSearchResourceReferenceOnlyCorrectPath() {
|
||||
IIdType oid1;
|
||||
{
|
||||
Organization org = new Organization();
|
||||
org.setActive(true);
|
||||
oid1 = myOrganizationDao.create(org, mySrd).getId().toUnqualifiedVersionless();
|
||||
}
|
||||
IIdType tid1;
|
||||
{
|
||||
Task task = new Task();
|
||||
task.getRequester().setOnBehalfOf(new Reference(oid1));
|
||||
tid1 = myTaskDao.create(task, mySrd).getId().toUnqualifiedVersionless();
|
||||
}
|
||||
IIdType tid2;
|
||||
{
|
||||
Task task = new Task();
|
||||
task.setOwner(new Reference(oid1));
|
||||
tid2 = myTaskDao.create(task, mySrd).getId().toUnqualifiedVersionless();
|
||||
}
|
||||
|
||||
SearchParameterMap map;
|
||||
List<IIdType> ids;
|
||||
|
||||
map = new SearchParameterMap();
|
||||
map.add(Task.SP_ORGANIZATION, new ReferenceParam(oid1.getValue()));
|
||||
ids = toUnqualifiedVersionlessIds(myTaskDao.search(map));
|
||||
assertThat(ids, contains(tid1)); // NOT tid2
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Test
|
||||
public void testSearchResourceReferenceMissingChain() {
|
||||
IIdType oid1;
|
||||
{
|
||||
Organization org = new Organization();
|
||||
org.setActive(true);
|
||||
oid1 = myOrganizationDao.create(org, mySrd).getId().toUnqualifiedVersionless();
|
||||
}
|
||||
IIdType tid1;
|
||||
{
|
||||
Task task = new Task();
|
||||
task.getRequester().setOnBehalfOf(new Reference(oid1));
|
||||
tid1 = myTaskDao.create(task, mySrd).getId().toUnqualifiedVersionless();
|
||||
}
|
||||
IIdType tid2;
|
||||
{
|
||||
Task task = new Task();
|
||||
task.setOwner(new Reference(oid1));
|
||||
tid2 = myTaskDao.create(task, mySrd).getId().toUnqualifiedVersionless();
|
||||
}
|
||||
|
||||
IIdType oid2;
|
||||
{
|
||||
Organization org = new Organization();
|
||||
org.setActive(true);
|
||||
org.setName("NAME");
|
||||
oid2 = myOrganizationDao.create(org, mySrd).getId().toUnqualifiedVersionless();
|
||||
}
|
||||
IIdType tid3;
|
||||
{
|
||||
Task task = new Task();
|
||||
task.getRequester().setOnBehalfOf(new Reference(oid2));
|
||||
tid3 = myTaskDao.create(task, mySrd).getId().toUnqualifiedVersionless();
|
||||
}
|
||||
|
||||
SearchParameterMap map;
|
||||
List<IIdType> ids;
|
||||
|
||||
map = new SearchParameterMap();
|
||||
map.add(Organization.SP_NAME, new StringParam().setMissing(true));
|
||||
ids = toUnqualifiedVersionlessIds(myOrganizationDao.search(map));
|
||||
assertThat(ids, contains(oid1));
|
||||
|
||||
ourLog.info("Starting Search 2");
|
||||
|
||||
map = new SearchParameterMap();
|
||||
map.add(Task.SP_ORGANIZATION, new ReferenceParam("Organization", "name:missing", "true"));
|
||||
ids = toUnqualifiedVersionlessIds(myTaskDao.search(map));
|
||||
assertThat(ids, contains(tid1)); // NOT tid2
|
||||
|
||||
map = new SearchParameterMap();
|
||||
map.add(Task.SP_ORGANIZATION, new ReferenceParam("Organization", "name:missing", "false"));
|
||||
ids = toUnqualifiedVersionlessIds(myTaskDao.search(map));
|
||||
assertThat(ids, contains(tid3));
|
||||
|
||||
map = new SearchParameterMap();
|
||||
map.add(Task.SP_ORGANIZATION, new ReferenceParam("Organization", "name:missing", "true"));
|
||||
ids = toUnqualifiedVersionlessIds(myPatientDao.search(map));
|
||||
assertThat(ids, empty());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See #441
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue