One more bugfix on #1772

This commit is contained in:
jamesagnew 2020-04-07 15:22:59 -04:00
parent c2e00bb73b
commit 35e1dbae32
3 changed files with 47 additions and 10 deletions

View File

@ -23,7 +23,6 @@ package ca.uhn.fhir.jpa.dao.predicate;
import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
import ca.uhn.fhir.context.BaseRuntimeElementDefinition;
import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeChildChoiceDefinition;
import ca.uhn.fhir.context.RuntimeChildResourceDefinition;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
@ -328,10 +327,11 @@ class PredicateBuilderReference extends BasePredicateBuilder {
throw newInvalidTargetTypeForChainException(theResourceName, theParamName, typeValue);
}
Predicate pathPredicate = createResourceLinkPathPredicate(theResourceName, theParamName, theJoin);
Predicate sourceTypeParameter = myCriteriaBuilder.equal(theJoin.get("mySourceResourceType"), myResourceName);
Predicate targetTypeParameter = myCriteriaBuilder.equal(theJoin.get("myTargetResourceType"), typeValue);
Predicate composite = myCriteriaBuilder.and(sourceTypeParameter, targetTypeParameter);
Predicate composite = myCriteriaBuilder.and(pathPredicate, sourceTypeParameter, targetTypeParameter);
myQueryRoot.addPredicate(composite);
return composite;
}
@ -427,12 +427,7 @@ class PredicateBuilderReference extends BasePredicateBuilder {
}
Predicate createResourceLinkPathPredicate(String theResourceName, String theParamName, From<?, ? extends ResourceLink> from) {
return createResourceLinkPathPredicate(myContext, theParamName, from, theResourceName);
}
private Predicate createResourceLinkPathPredicate(FhirContext theContext, String theParamName, From<?, ? extends ResourceLink> theFrom,
String theResourceType) {
RuntimeResourceDefinition resourceDef = theContext.getResourceDefinition(theResourceType);
RuntimeResourceDefinition resourceDef = myContext.getResourceDefinition(theResourceName);
RuntimeSearchParam param = mySearchParamRegistry.getSearchParamByName(resourceDef, theParamName);
List<String> path = param.getPathsSplit();
@ -445,12 +440,18 @@ class PredicateBuilderReference extends BasePredicateBuilder {
ListIterator<String> iter = path.listIterator();
while (iter.hasNext()) {
String nextPath = trim(iter.next());
if (!nextPath.contains(theResourceType + ".")) {
if (!nextPath.contains(theResourceName + ".")) {
iter.remove();
}
}
return theFrom.get("mySourcePath").in(path);
// one value
if (path.size() == 1) {
return myCriteriaBuilder.equal(from.get("mySourcePath").as(String.class), path.get(0));
}
// multiple values
return from.get("mySourcePath").in(path);
}
private IQueryParameterType mapReferenceChainToRawParamType(String remainingChain, RuntimeSearchParam param, String theParamName, String qualifier, Class<? extends IBaseResource> nextType, String chain, boolean isMeta, String resourceId) {

View File

@ -144,6 +144,9 @@ public abstract class BaseJpaR4Test extends BaseJpaTest {
@Qualifier("myCarePlanDaoR4")
protected IFhirResourceDao<CarePlan> myCarePlanDao;
@Autowired
@Qualifier("myCareTeamDaoR4")
protected IFhirResourceDao<CareTeam> myCareTeamDao;
@Autowired
@Qualifier("myCodeSystemDaoR4")
protected IFhirResourceDaoCodeSystem<CodeSystem, Coding, CodeableConcept> myCodeSystemDao;
@Autowired

View File

@ -416,6 +416,39 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
}
@Test
public void testChainOnType2() {
CareTeam ct = new CareTeam();
ct.addNote().setText("Care Team");
IIdType ctId = myCareTeamDao.create(ct).getId().toUnqualifiedVersionless();
DiagnosticReport dr1 = new DiagnosticReport();
dr1.getPerformerFirstRep().setReferenceElement(ctId);
IIdType drId1 = myDiagnosticReportDao.create(dr1).getId().toUnqualifiedVersionless();
DiagnosticReport dr2 = new DiagnosticReport();
dr2.getResultsInterpreterFirstRep().setReferenceElement(ctId);
myDiagnosticReportDao.create(dr2).getId().toUnqualifiedVersionless();
// Log the link rows
runInTransaction(() -> myResourceLinkDao.findAll().forEach(t -> ourLog.info("ResLink: {}", t.toString())));
List<String> ids;
SearchParameterMap map;
IBundleProvider results;
myCaptureQueriesListener.clear();
map = new SearchParameterMap();
map.setLoadSynchronous(true);
map.add(DiagnosticReport.SP_PERFORMER, new ReferenceParam( "CareTeam").setChain(PARAM_TYPE));
results = myDiagnosticReportDao.search(map);
ids = toUnqualifiedVersionlessIdValues(results);
assertThat(ids.toString(), ids, contains(drId1.getValue()));
myCaptureQueriesListener.logSelectQueriesForCurrentThread();
}
/**
* See #441
*/