Fix issue with JPA search params
This commit is contained in:
parent
bba62b2972
commit
e0ae780ff2
|
@ -81,7 +81,7 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
|||
private Class<T> myResourceType;
|
||||
private String mySecondaryPrimaryKeyParamName;
|
||||
|
||||
private Set<Long> addPredicateDate(Set<Long> thePids, List<IQueryParameterType> theOrParams) {
|
||||
private Set<Long> addPredicateDate(String theParamName, Set<Long> thePids, List<IQueryParameterType> theOrParams) {
|
||||
if (theOrParams == null || theOrParams.isEmpty()) {
|
||||
return thePids;
|
||||
}
|
||||
|
@ -111,11 +111,12 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
|||
Predicate masterCodePredicate = builder.or(codePredicates.toArray(new Predicate[0]));
|
||||
|
||||
Predicate type = builder.equal(from.get("myResourceType"), myResourceName);
|
||||
Predicate name = builder.equal(from.get("myParamName"), theParamName);
|
||||
if (thePids.size() > 0) {
|
||||
Predicate inPids = (from.get("myResourcePid").in(thePids));
|
||||
cq.where(builder.and(type, inPids, masterCodePredicate));
|
||||
cq.where(builder.and(type, name, masterCodePredicate,inPids));
|
||||
} else {
|
||||
cq.where(builder.and(type, masterCodePredicate));
|
||||
cq.where(builder.and(type, name,masterCodePredicate));
|
||||
}
|
||||
|
||||
TypedQuery<Long> q = myEntityManager.createQuery(cq);
|
||||
|
@ -161,7 +162,7 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
|||
}
|
||||
}
|
||||
|
||||
private Set<Long> addPredicateQuantity(Set<Long> thePids, List<IQueryParameterType> theOrParams) {
|
||||
private Set<Long> addPredicateQuantity(String theParamName, Set<Long> thePids, List<IQueryParameterType> theOrParams) {
|
||||
if (theOrParams == null || theOrParams.isEmpty()) {
|
||||
return thePids;
|
||||
}
|
||||
|
@ -234,11 +235,12 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
|||
Predicate masterCodePredicate = builder.or(codePredicates.toArray(new Predicate[0]));
|
||||
|
||||
Predicate type = builder.equal(from.get("myResourceType"), myResourceName);
|
||||
Predicate name = builder.equal(from.get("myParamName"), theParamName);
|
||||
if (thePids.size() > 0) {
|
||||
Predicate inPids = (from.get("myResourcePid").in(thePids));
|
||||
cq.where(builder.and(type, inPids, masterCodePredicate));
|
||||
cq.where(builder.and(type, name, masterCodePredicate, inPids));
|
||||
} else {
|
||||
cq.where(builder.and(type, masterCodePredicate));
|
||||
cq.where(builder.and(type, name, masterCodePredicate));
|
||||
}
|
||||
|
||||
TypedQuery<Long> q = myEntityManager.createQuery(cq);
|
||||
|
@ -276,7 +278,9 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
|||
Long targetPid = Long.valueOf(resourceId);
|
||||
ourLog.info("Searching for resource link with target PID: {}", targetPid);
|
||||
Predicate eq = builder.equal(from.get("myTargetResourcePid"), targetPid);
|
||||
|
||||
codePredicates.add(eq);
|
||||
|
||||
} else {
|
||||
String chain = getContext().getResourceDefinition(myResourceType).getSearchParam(theParamName).getPath();
|
||||
BaseRuntimeChildDefinition def = getContext().newTerser().getDefinition(myResourceType, chain);
|
||||
|
@ -331,7 +335,7 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
|||
Predicate type = builder.equal(from.get("mySourcePath"), path);
|
||||
if (pidsToRetain.size() > 0) {
|
||||
Predicate inPids = (from.get("mySourceResourcePid").in(pidsToRetain));
|
||||
cq.where(builder.and(type, inPids, masterCodePredicate));
|
||||
cq.where(builder.and(type, masterCodePredicate, inPids));
|
||||
} else {
|
||||
cq.where(builder.and(type, masterCodePredicate));
|
||||
}
|
||||
|
@ -340,7 +344,7 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
|||
return new HashSet<Long>(q.getResultList());
|
||||
}
|
||||
|
||||
private Set<Long> addPredicateString(Set<Long> thePids, List<IQueryParameterType> theOrParams) {
|
||||
private Set<Long> addPredicateString(String theParamName, Set<Long> thePids, List<IQueryParameterType> theOrParams) {
|
||||
if (theOrParams == null || theOrParams.isEmpty()) {
|
||||
return thePids;
|
||||
}
|
||||
|
@ -373,18 +377,19 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
|||
Predicate masterCodePredicate = builder.or(codePredicates.toArray(new Predicate[0]));
|
||||
|
||||
Predicate type = builder.equal(from.get("myResourceType"), myResourceName);
|
||||
Predicate name = builder.equal(from.get("myParamName"), theParamName);
|
||||
if (thePids.size() > 0) {
|
||||
Predicate inPids = (from.get("myResourcePid").in(thePids));
|
||||
cq.where(builder.and(type, inPids, masterCodePredicate));
|
||||
cq.where(builder.and(type, name, masterCodePredicate, inPids));
|
||||
} else {
|
||||
cq.where(builder.and(type, masterCodePredicate));
|
||||
cq.where(builder.and(type, name, masterCodePredicate));
|
||||
}
|
||||
|
||||
TypedQuery<Long> q = myEntityManager.createQuery(cq);
|
||||
return new HashSet<Long>(q.getResultList());
|
||||
}
|
||||
|
||||
private Set<Long> addPredicateToken(Set<Long> thePids, List<IQueryParameterType> theOrParams) {
|
||||
private Set<Long> addPredicateToken(String theParamName, Set<Long> thePids, List<IQueryParameterType> theOrParams) {
|
||||
if (theOrParams == null || theOrParams.isEmpty()) {
|
||||
return thePids;
|
||||
}
|
||||
|
@ -430,11 +435,12 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
|||
Predicate masterCodePredicate = builder.or(codePredicates.toArray(new Predicate[0]));
|
||||
|
||||
Predicate type = builder.equal(from.get("myResourceType"), myResourceName);
|
||||
Predicate name = builder.equal(from.get("myParamName"), theParamName);
|
||||
if (thePids.size() > 0) {
|
||||
Predicate inPids = (from.get("myResourcePid").in(thePids));
|
||||
cq.where(builder.and(type, inPids, masterCodePredicate));
|
||||
cq.where(builder.and(type, name, masterCodePredicate,inPids));
|
||||
} else {
|
||||
cq.where(builder.and(type, masterCodePredicate));
|
||||
cq.where(builder.and(type, name, masterCodePredicate));
|
||||
}
|
||||
|
||||
TypedQuery<Long> q = myEntityManager.createQuery(cq);
|
||||
|
@ -752,28 +758,28 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
|||
if (nextParamDef != null) {
|
||||
if (nextParamDef.getParamType() == SearchParamTypeEnum.TOKEN) {
|
||||
for (List<IQueryParameterType> nextAnd : nextParamEntry.getValue()) {
|
||||
pids = addPredicateToken(pids, nextAnd);
|
||||
pids = addPredicateToken(nextParamName, pids, nextAnd);
|
||||
if (pids.isEmpty()) {
|
||||
return new HashSet<Long>();
|
||||
}
|
||||
}
|
||||
} else if (nextParamDef.getParamType() == SearchParamTypeEnum.STRING) {
|
||||
for (List<IQueryParameterType> nextAnd : nextParamEntry.getValue()) {
|
||||
pids = addPredicateString(pids, nextAnd);
|
||||
pids = addPredicateString(nextParamName, pids, nextAnd);
|
||||
if (pids.isEmpty()) {
|
||||
return new HashSet<Long>();
|
||||
}
|
||||
}
|
||||
} else if (nextParamDef.getParamType() == SearchParamTypeEnum.QUANTITY) {
|
||||
for (List<IQueryParameterType> nextAnd : nextParamEntry.getValue()) {
|
||||
pids = addPredicateQuantity(pids, nextAnd);
|
||||
pids = addPredicateQuantity(nextParamName, pids, nextAnd);
|
||||
if (pids.isEmpty()) {
|
||||
return new HashSet<Long>();
|
||||
}
|
||||
}
|
||||
} else if (nextParamDef.getParamType() == SearchParamTypeEnum.DATE) {
|
||||
for (List<IQueryParameterType> nextAnd : nextParamEntry.getValue()) {
|
||||
pids = addPredicateDate(pids, nextAnd);
|
||||
pids = addPredicateDate(nextParamName, pids, nextAnd);
|
||||
if (pids.isEmpty()) {
|
||||
return new HashSet<Long>();
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public abstract class BaseResourceIndexedSearchParam implements Serializable {
|
|||
private Long myId;
|
||||
|
||||
@Column(name = "SP_NAME", length = 100, nullable=false)
|
||||
private String myName;
|
||||
private String myParamName;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "RES_ID", referencedColumnName="RES_ID")
|
||||
|
@ -33,12 +33,12 @@ public abstract class BaseResourceIndexedSearchParam implements Serializable {
|
|||
@Column(name = "RES_ID", insertable = false, updatable = false)
|
||||
private Long myResourcePid;
|
||||
|
||||
public String getName() {
|
||||
return myName;
|
||||
public String getParamName() {
|
||||
return myParamName;
|
||||
}
|
||||
|
||||
public void setName(String theName) {
|
||||
myName = theName;
|
||||
public void setParamName(String theName) {
|
||||
myParamName = theName;
|
||||
}
|
||||
|
||||
public ResourceTable getResource() {
|
||||
|
|
|
@ -10,7 +10,7 @@ import javax.persistence.TemporalType;
|
|||
|
||||
@Entity
|
||||
@Table(name = "HFJ_SPIDX_DATE" /*, indexes= {@Index(name="IDX_SP_DATE", columnList= "SP_VALUE_LOW,SP_VALUE_HIGH")}*/)
|
||||
@org.hibernate.annotations.Table(appliesTo = "HFJ_SPIDX_DATE", indexes= {@org.hibernate.annotations.Index(name="IDX_SP_DATE", columnNames= {"SP_VALUE_LOW","SP_VALUE_HIGH"})})
|
||||
@org.hibernate.annotations.Table(appliesTo = "HFJ_SPIDX_DATE", indexes= {@org.hibernate.annotations.Index(name="IDX_SP_DATE", columnNames= {"RES_TYPE", "SP_NAME", "SP_VALUE_LOW","SP_VALUE_HIGH"})})
|
||||
public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchParam {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
@ -29,7 +29,7 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar
|
|||
}
|
||||
|
||||
public ResourceIndexedSearchParamDate(String theName, Date theLow, Date theHigh) {
|
||||
setName(theName);
|
||||
setParamName(theName);
|
||||
setValueLow(theLow);
|
||||
setValueHigh(theHigh);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import javax.persistence.Table;
|
|||
|
||||
@Entity
|
||||
@Table(name = "HFJ_SPIDX_NUMBER" /*, indexes= {@Index(name="IDX_SP_NUMBER", columnList="SP_VALUE")}*/ )
|
||||
@org.hibernate.annotations.Table(appliesTo = "HFJ_SPIDX_NUMBER", indexes= {@org.hibernate.annotations.Index(name="IDX_SP_NUMBER", columnNames= {"SP_VALUE"})})
|
||||
@org.hibernate.annotations.Table(appliesTo = "HFJ_SPIDX_NUMBER", indexes= {@org.hibernate.annotations.Index(name="IDX_SP_NUMBER", columnNames= {"RES_TYPE", "SP_NAME", "SP_VALUE"})})
|
||||
public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchParam {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
@ -23,7 +23,7 @@ public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchP
|
|||
public BigDecimal myValue;
|
||||
|
||||
public ResourceIndexedSearchParamNumber(String theParamName, BigDecimal theValue, String theSystem, String theUnits) {
|
||||
setName(theParamName);
|
||||
setParamName(theParamName);
|
||||
setSystem(theSystem);
|
||||
setValue(theValue);
|
||||
setUnits(theUnits);
|
||||
|
|
|
@ -7,7 +7,7 @@ import javax.persistence.Table;
|
|||
@Entity
|
||||
@Table(name = "HFJ_SPIDX_STRING"/*, indexes= {@Index(name="IDX_SP_STRING", columnList="SP_VALUE_NORMALIZED")}*/)
|
||||
@org.hibernate.annotations.Table(appliesTo="HFJ_SPIDX_STRING",indexes= {
|
||||
@org.hibernate.annotations.Index(name="IDX_SP_STRING", columnNames= {"SP_VALUE_NORMALIZED"})})
|
||||
@org.hibernate.annotations.Index(name="IDX_SP_STRING", columnNames= {"RES_TYPE", "SP_NAME", "SP_VALUE_NORMALIZED"})})
|
||||
public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchParam {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
@ -22,7 +22,7 @@ public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchP
|
|||
}
|
||||
|
||||
public ResourceIndexedSearchParamString(String theName, String theValueNormalized, String theValueExact) {
|
||||
setName(theName);
|
||||
setParamName(theName);
|
||||
setValueNormalized(theValueNormalized);
|
||||
setValueExact(theValueExact);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
|
||||
@Entity
|
||||
@Table(name = "HFJ_SPIDX_TOKEN" /* , indexes = { @Index(name = "IDX_SP_TOKEN", columnList = "SP_SYSTEM,SP_VALUE") } */)
|
||||
@org.hibernate.annotations.Table(appliesTo = "HFJ_SPIDX_TOKEN", indexes = { @org.hibernate.annotations.Index(name = "IDX_SP_TOKEN", columnNames = { "SP_SYSTEM", "SP_VALUE" }) })
|
||||
@org.hibernate.annotations.Table(appliesTo = "HFJ_SPIDX_TOKEN", indexes = { @org.hibernate.annotations.Index(name = "IDX_SP_TOKEN", columnNames = { "RES_TYPE", "SP_NAME", "SP_SYSTEM", "SP_VALUE" }) })
|
||||
public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchParam {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
@ -23,7 +23,7 @@ public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchPa
|
|||
}
|
||||
|
||||
public ResourceIndexedSearchParamToken(String theName, String theSystem, String theValue) {
|
||||
setName(theName);
|
||||
setParamName(theName);
|
||||
setSystem(theSystem);
|
||||
setValue(theValue);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import org.apache.commons.lang3.Validate;
|
|||
@Entity
|
||||
@Table(name = "HFJ_RES_LINK"/*, indexes= {@Index(name="IDX_RL_TPATHRES", columnList= "SRC_PATH,TARGET_RESOURCE_ID")}*/)
|
||||
@org.hibernate.annotations.Table(appliesTo="HFJ_RES_LINK",indexes= {
|
||||
@org.hibernate.annotations.Index(name="IDX_RL_TPATHRES", columnNames= {"SRC_PATH","TARGET_RESOURCE_ID"})})
|
||||
@org.hibernate.annotations.Index(name="IDX_RL_TPATHRES", columnNames= {"SRC_PATH", "TARGET_RESOURCE_ID"})})
|
||||
public class ResourceLink implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
@ -160,9 +160,13 @@ public class FhirResourceDaoTest {
|
|||
|
||||
ourPatientDao.create(patient);
|
||||
|
||||
List<Patient> found = ourPatientDao.search("birthdate", new QualifiedDateParam(QuantityCompararatorEnum.GREATERTHAN, "2000-01-01"));
|
||||
List<Patient> found = ourPatientDao.search(Patient.SP_BIRTHDATE, new QualifiedDateParam(QuantityCompararatorEnum.GREATERTHAN, "2000-01-01"));
|
||||
assertEquals(1, found.size());
|
||||
|
||||
// If this throws an exception, that would be an acceptable outcome as well..
|
||||
found = ourPatientDao.search(Patient.SP_BIRTHDATE+"AAAA", new QualifiedDateParam(QuantityCompararatorEnum.GREATERTHAN, "2000-01-01"));
|
||||
assertEquals(0, found.size());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -228,7 +232,7 @@ public class FhirResourceDaoTest {
|
|||
map.get(Patient.SP_IDENTIFIER).get(0).add(new IdentifierDt("urn:system", "001testPersistSearchParams"));
|
||||
map.put(Patient.SP_GENDER, new ArrayList<List<IQueryParameterType>>());
|
||||
map.get(Patient.SP_GENDER).add(new ArrayList<IQueryParameterType>());
|
||||
map.get(Patient.SP_GENDER).get(0).add(new IdentifierDt(null, "M"));
|
||||
map.get(Patient.SP_GENDER).get(0).add(new IdentifierDt(AdministrativeGenderCodesEnum.M.getSystem(), "M"));
|
||||
found = ourPatientDao.search(map);
|
||||
assertEquals(1, found.size());
|
||||
assertEquals(id, found.get(0).getId().asLong().longValue());
|
||||
|
@ -239,7 +243,7 @@ public class FhirResourceDaoTest {
|
|||
map.get(Patient.SP_IDENTIFIER).get(0).add(new IdentifierDt("urn:system", "001testPersistSearchParams"));
|
||||
map.put(Patient.SP_GENDER, new ArrayList<List<IQueryParameterType>>());
|
||||
map.get(Patient.SP_GENDER).add(new ArrayList<IQueryParameterType>());
|
||||
map.get(Patient.SP_GENDER).get(0).add(new IdentifierDt(null, "F"));
|
||||
map.get(Patient.SP_GENDER).get(0).add(new IdentifierDt(AdministrativeGenderCodesEnum.M.getSystem(), "F"));
|
||||
found = ourPatientDao.search(map);
|
||||
assertEquals(0, found.size());
|
||||
|
||||
|
@ -287,12 +291,25 @@ public class FhirResourceDaoTest {
|
|||
assertEquals(1, patients.size());
|
||||
assertEquals(id1.getUnqualifiedId(), patients.get(0).getId().getUnqualifiedId());
|
||||
|
||||
// Given name shouldn't return for family param
|
||||
params = new HashMap<String, IQueryParameterType>();
|
||||
params.put(Patient.SP_FAMILY, new StringDt("testSearchNameParam01Giv"));
|
||||
patients = ourPatientDao.search(params);
|
||||
assertEquals(0, patients.size());
|
||||
|
||||
params = new HashMap<String, IQueryParameterType>();
|
||||
params.put(Patient.SP_NAME, new StringDt("testSearchNameParam01Fam"));
|
||||
patients = ourPatientDao.search(params);
|
||||
assertEquals(1, patients.size());
|
||||
assertEquals(id1.getUnqualifiedId(), patients.get(0).getId().getUnqualifiedId());
|
||||
|
||||
params = new HashMap<String, IQueryParameterType>();
|
||||
params.put(Patient.SP_NAME, new StringDt("testSearchNameParam01Giv"));
|
||||
patients = ourPatientDao.search(params);
|
||||
assertEquals(1, patients.size());
|
||||
assertEquals(id1.getUnqualifiedId(), patients.get(0).getId().getUnqualifiedId());
|
||||
|
||||
|
||||
params = new HashMap<String, IQueryParameterType>();
|
||||
params.put(Patient.SP_FAMILY, new StringDt("testSearchNameParam01Foo"));
|
||||
patients = ourPatientDao.search(params);
|
||||
|
@ -329,14 +346,14 @@ public class FhirResourceDaoTest {
|
|||
|
||||
ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[] { patientId01, patientId02, obsId01, obsId02, drId01 });
|
||||
|
||||
List<Observation> result = ourObservationDao.search(Observation.SP_SUBJECT, new ReferenceParam(Patient.SP_IDENTIFIER, "testSearchResourceLinkWithChain01"));
|
||||
List<Observation> result = ourObservationDao.search(Observation.SP_SUBJECT, new ReferenceParam(Patient.SP_IDENTIFIER, "urn:system|testSearchResourceLinkWithChain01"));
|
||||
assertEquals(1, result.size());
|
||||
assertEquals(obsId01.getUnqualifiedId(), result.get(0).getId().getUnqualifiedId());
|
||||
|
||||
result = ourObservationDao.search(Observation.SP_SUBJECT, new ReferenceParam(Patient.SP_IDENTIFIER, "999999999999"));
|
||||
assertEquals(0, result.size());
|
||||
|
||||
result = ourObservationDao.search(Observation.SP_SUBJECT, new ReferenceParam(Patient.SP_IDENTIFIER, "testSearchResourceLinkWithChainXX"));
|
||||
result = ourObservationDao.search(Observation.SP_SUBJECT, new ReferenceParam(Patient.SP_IDENTIFIER, "urn:system|testSearchResourceLinkWithChainXX"));
|
||||
assertEquals(2, result.size());
|
||||
|
||||
}
|
||||
|
@ -607,13 +624,13 @@ public class FhirResourceDaoTest {
|
|||
}
|
||||
|
||||
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
|
||||
params.put(Patient.SP_FAMILY, new StringDt("testSearchStringParamWithNonNormalized_hora"));
|
||||
params.put(Patient.SP_GIVEN, new StringDt("testSearchStringParamWithNonNormalized_hora"));
|
||||
List<Patient> patients = ourPatientDao.search(params);
|
||||
assertEquals(2, patients.size());
|
||||
|
||||
StringParam parameter = new StringParam("testSearchStringParamWithNonNormalized_hora");
|
||||
parameter.setExact(true);
|
||||
params.put(Patient.SP_FAMILY, parameter);
|
||||
params.put(Patient.SP_GIVEN, parameter);
|
||||
patients = ourPatientDao.search(params);
|
||||
assertEquals(0, patients.size());
|
||||
|
||||
|
|
Loading…
Reference in New Issue