Get reverse includes working
This commit is contained in:
parent
e84fdb33b0
commit
ef88eb9a97
|
@ -855,7 +855,7 @@ public abstract class BaseFhirDao implements IDao {
|
|||
RuntimeResourceDefinition type = myContext.getResourceDefinition(theEntity.getResourceType());
|
||||
return toResource(type.getImplementingClass(), theEntity);
|
||||
}
|
||||
|
||||
|
||||
protected <T extends IBaseResource> T toResource(Class<T> theResourceType, BaseHasResource theEntity) {
|
||||
String resourceText = null;
|
||||
switch (theEntity.getEncoding()) {
|
||||
|
|
|
@ -1122,14 +1122,13 @@ public abstract class BaseFhirResourceDao<T extends IResource> extends BaseFhirD
|
|||
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<ResourceTable> cq = builder.createQuery(ResourceTable.class);
|
||||
Root<ResourceTable> from = cq.from(ResourceTable.class);
|
||||
cq.where(builder.equal(from.get("myResourceType"), getContext().getResourceDefinition(myResourceType).getName()));
|
||||
if (theIncludePids != null) {
|
||||
cq.where(from.get("myId").in(theIncludePids));
|
||||
}
|
||||
// cq.where(builder.equal(from.get("myResourceType"), getContext().getResourceDefinition(myResourceType).getName()));
|
||||
cq.where(from.get("myId").in(theIncludePids));
|
||||
TypedQuery<ResourceTable> q = myEntityManager.createQuery(cq);
|
||||
|
||||
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());
|
||||
if (index == null) {
|
||||
ourLog.warn("Got back unexpected resource PID {}", next.getId());
|
||||
|
@ -1442,7 +1441,6 @@ public abstract class BaseFhirResourceDao<T extends IResource> extends BaseFhirD
|
|||
return;
|
||||
}
|
||||
|
||||
Long[] matchesArray = theMatches.toArray(new Long[theMatches.size()]);
|
||||
Set<Long> pidsToInclude = new HashSet<Long>();
|
||||
|
||||
for (Include nextInclude : theRevIncludes) {
|
||||
|
@ -1465,10 +1463,10 @@ public abstract class BaseFhirResourceDao<T extends IResource> extends BaseFhirD
|
|||
}
|
||||
|
||||
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);
|
||||
q.setParameter("src_path", nextPath);
|
||||
q.setParameter("target_pids", matchesArray);
|
||||
q.setParameter("target_pids", theMatches);
|
||||
List<ResourceLink> results = q.getResultList();
|
||||
for (ResourceLink resourceLink : results) {
|
||||
pidsToInclude.add(resourceLink.getSourceResourcePid());
|
||||
|
|
|
@ -18,6 +18,7 @@ import static org.junit.Assert.fail;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
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
|
||||
public void testResourceInstanceMetaOperation() {
|
||||
deleteEverything();
|
||||
|
|
Loading…
Reference in New Issue