Get reverse includes working
This commit is contained in:
parent
e84fdb33b0
commit
ef88eb9a97
|
@ -1122,14 +1122,13 @@ public abstract class BaseFhirResourceDao<T extends IResource> extends BaseFhirD
|
||||||
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
|
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
|
||||||
CriteriaQuery<ResourceTable> cq = builder.createQuery(ResourceTable.class);
|
CriteriaQuery<ResourceTable> cq = builder.createQuery(ResourceTable.class);
|
||||||
Root<ResourceTable> from = cq.from(ResourceTable.class);
|
Root<ResourceTable> from = cq.from(ResourceTable.class);
|
||||||
cq.where(builder.equal(from.get("myResourceType"), getContext().getResourceDefinition(myResourceType).getName()));
|
// cq.where(builder.equal(from.get("myResourceType"), getContext().getResourceDefinition(myResourceType).getName()));
|
||||||
if (theIncludePids != null) {
|
cq.where(from.get("myId").in(theIncludePids));
|
||||||
cq.where(from.get("myId").in(theIncludePids));
|
|
||||||
}
|
|
||||||
TypedQuery<ResourceTable> q = myEntityManager.createQuery(cq);
|
TypedQuery<ResourceTable> q = myEntityManager.createQuery(cq);
|
||||||
|
|
||||||
for (ResourceTable next : q.getResultList()) {
|
for (ResourceTable next : q.getResultList()) {
|
||||||
T resource = toResource(myResourceType, next);
|
Class<? extends IBaseResource> resourceType = getContext().getResourceDefinition(next.getResourceType()).getImplementingClass();
|
||||||
|
IResource resource = (IResource) toResource(resourceType, next);
|
||||||
Integer index = position.get(next.getId());
|
Integer index = position.get(next.getId());
|
||||||
if (index == null) {
|
if (index == null) {
|
||||||
ourLog.warn("Got back unexpected resource PID {}", next.getId());
|
ourLog.warn("Got back unexpected resource PID {}", next.getId());
|
||||||
|
@ -1442,7 +1441,6 @@ public abstract class BaseFhirResourceDao<T extends IResource> extends BaseFhirD
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Long[] matchesArray = theMatches.toArray(new Long[theMatches.size()]);
|
|
||||||
Set<Long> pidsToInclude = new HashSet<Long>();
|
Set<Long> pidsToInclude = new HashSet<Long>();
|
||||||
|
|
||||||
for (Include nextInclude : theRevIncludes) {
|
for (Include nextInclude : theRevIncludes) {
|
||||||
|
@ -1465,10 +1463,10 @@ public abstract class BaseFhirResourceDao<T extends IResource> extends BaseFhirD
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String nextPath : param.getPathsSplit()) {
|
for (String nextPath : param.getPathsSplit()) {
|
||||||
String sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r.myTargetResourcePid IN :target_pids";
|
String sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r.myTargetResourcePid IN (:target_pids)";
|
||||||
TypedQuery<ResourceLink> q = myEntityManager.createQuery(sql, ResourceLink.class);
|
TypedQuery<ResourceLink> q = myEntityManager.createQuery(sql, ResourceLink.class);
|
||||||
q.setParameter("src_path", nextPath);
|
q.setParameter("src_path", nextPath);
|
||||||
q.setParameter("target_pids", matchesArray);
|
q.setParameter("target_pids", theMatches);
|
||||||
List<ResourceLink> results = q.getResultList();
|
List<ResourceLink> results = q.getResultList();
|
||||||
for (ResourceLink resourceLink : results) {
|
for (ResourceLink resourceLink : results) {
|
||||||
pidsToInclude.add(resourceLink.getSourceResourcePid());
|
pidsToInclude.add(resourceLink.getSourceResourcePid());
|
||||||
|
|
|
@ -18,6 +18,7 @@ import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -846,6 +847,29 @@ public class FhirResourceDaoDstu2Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReverseIncludes() {
|
||||||
|
String methodName = "testReverseIncludes";
|
||||||
|
Organization org = new Organization();
|
||||||
|
org.setName("X"+methodName+"X");
|
||||||
|
IdDt orgId = ourOrganizationDao.create(org).getId();
|
||||||
|
|
||||||
|
Patient pat = new Patient();
|
||||||
|
pat.addName().addFamily("X"+methodName+"X");
|
||||||
|
pat.getManagingOrganization().setReference(orgId.toUnqualifiedVersionless());
|
||||||
|
ourPatientDao.create(pat);
|
||||||
|
|
||||||
|
SearchParameterMap map = new SearchParameterMap();
|
||||||
|
map.add(Organization.SP_NAME, new StringParam("X"+methodName+"X"));
|
||||||
|
map.setRevIncludes(Collections.singleton(Patient.INCLUDE_ORGANIZATION));
|
||||||
|
IBundleProvider resultsP = ourOrganizationDao.search(map);
|
||||||
|
assertEquals(1, resultsP.size());
|
||||||
|
List<IResource> results = resultsP.getResources(0, resultsP.size());
|
||||||
|
assertEquals(2, results.size());
|
||||||
|
assertEquals(Organization.class, results.get(0).getClass());
|
||||||
|
assertEquals(Patient.class, results.get(1).getClass());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResourceInstanceMetaOperation() {
|
public void testResourceInstanceMetaOperation() {
|
||||||
deleteEverything();
|
deleteEverything();
|
||||||
|
|
Loading…
Reference in New Issue