Fix failing unit tests
This commit is contained in:
parent
d0edc03f14
commit
0ff847ac21
|
@ -22,7 +22,7 @@ public class BaseParam implements IQueryParameterType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getQueryParameterQualifier() {
|
public String getQueryParameterQualifier() {
|
||||||
if (myMissing) {
|
if (myMissing != null) {
|
||||||
return Constants.PARAMQUALIFIER_MISSING;
|
return Constants.PARAMQUALIFIER_MISSING;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -28,7 +28,7 @@ import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||||
import ca.uhn.fhir.model.dstu.composite.QuantityDt;
|
import ca.uhn.fhir.model.dstu.composite.QuantityDt;
|
||||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||||
|
|
||||||
public class NumberParam implements IQueryParameterType {
|
public class NumberParam extends BaseParam implements IQueryParameterType {
|
||||||
|
|
||||||
private QuantityDt myQuantity = new QuantityDt();
|
private QuantityDt myQuantity = new QuantityDt();
|
||||||
|
|
||||||
|
@ -71,7 +71,8 @@ public class NumberParam implements IQueryParameterType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueAsQueryToken(String theQualifier, String theValue) {
|
public void setValueAsQueryToken(String theQualifier, String theValue) {
|
||||||
if (isBlank(theValue)) {
|
super.setValueAsQueryToken(theQualifier, theValue);
|
||||||
|
if (getMissing() != null && isBlank(theValue)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (theValue.startsWith("<=")) {
|
if (theValue.startsWith("<=")) {
|
||||||
|
@ -94,6 +95,10 @@ public class NumberParam implements IQueryParameterType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValueAsQueryToken() {
|
public String getValueAsQueryToken() {
|
||||||
|
if (getMissing() != null) {
|
||||||
|
return super.getQueryParameterQualifier();
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
if (myQuantity.getComparator().isEmpty() == false) {
|
if (myQuantity.getComparator().isEmpty() == false) {
|
||||||
b.append(myQuantity.getComparator().getValue());
|
b.append(myQuantity.getComparator().getValue());
|
||||||
|
@ -106,7 +111,7 @@ public class NumberParam implements IQueryParameterType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getQueryParameterQualifier() {
|
public String getQueryParameterQualifier() {
|
||||||
return null;
|
return super.getQueryParameterQualifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,7 @@ public class QuantityParam extends BaseParam implements IQueryParameterType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getQueryParameterQualifier() {
|
public String getQueryParameterQualifier() {
|
||||||
return null;
|
return super.getQueryParameterQualifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
public UriDt getSystem() {
|
public UriDt getSystem() {
|
||||||
|
|
|
@ -49,10 +49,12 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getQueryParameterQualifier() {
|
public String getQueryParameterQualifier() {
|
||||||
if (isExact()) {
|
if (getMissing() != null) {
|
||||||
|
return super.getQueryParameterQualifier();
|
||||||
|
}else if (isExact()) {
|
||||||
return Constants.PARAMQUALIFIER_STRING_EXACT;
|
return Constants.PARAMQUALIFIER_STRING_EXACT;
|
||||||
} else {
|
} else {
|
||||||
return super.getQueryParameterQualifier();
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,29 +49,29 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||||
|
|
||||||
public TokenParam(String theSystem, String theValue, boolean theText) {
|
public TokenParam(String theSystem, String theValue, boolean theText) {
|
||||||
if (theText && isNotBlank(theSystem)) {
|
if (theText && isNotBlank(theSystem)) {
|
||||||
throw new IllegalArgumentException("theSystem can not be non-blank if theText is true (:text searches do not include a system). In other words, set the first parameter to null for a text search");
|
throw new IllegalArgumentException(
|
||||||
|
"theSystem can not be non-blank if theText is true (:text searches do not include a system). In other words, set the first parameter to null for a text search");
|
||||||
}
|
}
|
||||||
setSystem(theSystem);
|
setSystem(theSystem);
|
||||||
setValue(theValue);
|
setValue(theValue);
|
||||||
setText(theText);
|
setText(theText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor which copies the {@link CodingDt#getSystem() system} and {@link CodingDt#getCode() code} from a {@link CodingDt}
|
* Constructor which copies the {@link CodingDt#getSystem() system} and {@link CodingDt#getCode() code} from a {@link CodingDt} instance and adds it as a parameter
|
||||||
* instance and adds it as a parameter
|
|
||||||
*
|
*
|
||||||
* @param theCodingDt The coding
|
* @param theCodingDt
|
||||||
|
* The coding
|
||||||
*/
|
*/
|
||||||
public TokenParam(CodingDt theCodingDt) {
|
public TokenParam(CodingDt theCodingDt) {
|
||||||
this(toSystemValue(theCodingDt.getSystem()), theCodingDt.getCode().getValue());
|
this(toSystemValue(theCodingDt.getSystem()), theCodingDt.getCode().getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor which copies the {@link IdentifierDt#getSystem() system} and {@link IdentifierDt#getValue() value} from a {@link IdentifierDt}
|
* Constructor which copies the {@link IdentifierDt#getSystem() system} and {@link IdentifierDt#getValue() value} from a {@link IdentifierDt} instance and adds it as a parameter
|
||||||
* instance and adds it as a parameter
|
|
||||||
*
|
*
|
||||||
* @param theCodingDt The coding
|
* @param theCodingDt
|
||||||
|
* The coding
|
||||||
*/
|
*/
|
||||||
public TokenParam(IdentifierDt theIdentifierDt) {
|
public TokenParam(IdentifierDt theIdentifierDt) {
|
||||||
this(toSystemValue(theIdentifierDt.getSystem()), theIdentifierDt.getValue().getValue());
|
this(toSystemValue(theIdentifierDt.getSystem()), theIdentifierDt.getValue().getValue());
|
||||||
|
@ -83,7 +83,9 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getQueryParameterQualifier() {
|
public String getQueryParameterQualifier() {
|
||||||
if (isText()) {
|
if (getMissing() != null) {
|
||||||
|
return super.getQueryParameterQualifier();
|
||||||
|
} else if (isText()) {
|
||||||
return Constants.PARAMQUALIFIER_TOKEN_TEXT;
|
return Constants.PARAMQUALIFIER_TOKEN_TEXT;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -103,8 +105,10 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getValueAsQueryToken() {
|
public String getValueAsQueryToken() {
|
||||||
if (getSystem() != null) {
|
if (getMissing() != null) {
|
||||||
return ParameterUtil.escape(StringUtils.defaultString(getSystem())) + '|' + ParameterUtil.escape(getValue());
|
return super.getValueAsQueryToken();
|
||||||
|
} else if (getSystem() != null) {
|
||||||
|
return ParameterUtil.escape(StringUtils.defaultString(getSystem())) + '|' + ParameterUtil.escape(getValue());
|
||||||
} else {
|
} else {
|
||||||
return ParameterUtil.escape(getValue());
|
return ParameterUtil.escape(getValue());
|
||||||
}
|
}
|
||||||
|
@ -118,11 +122,9 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||||
return StringUtils.isEmpty(myValue);
|
return StringUtils.isEmpty(myValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isText() {
|
public boolean isText() {
|
||||||
return myText;
|
return myText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setSystem(String theSystem) {
|
public void setSystem(String theSystem) {
|
||||||
mySystem = theSystem;
|
mySystem = theSystem;
|
||||||
|
@ -141,7 +143,12 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setValueAsQueryToken(String theQualifier, String theParameter) {
|
public void setValueAsQueryToken(String theQualifier, String theParameter) {
|
||||||
int barIndex = ParameterUtil.nonEscapedIndexOf(theParameter,'|');
|
super.setValueAsQueryToken(theQualifier, theParameter);
|
||||||
|
if (getMissing() != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int barIndex = ParameterUtil.nonEscapedIndexOf(theParameter, '|');
|
||||||
if (barIndex != -1) {
|
if (barIndex != -1) {
|
||||||
setSystem(theParameter.substring(0, barIndex));
|
setSystem(theParameter.substring(0, barIndex));
|
||||||
setValue(ParameterUtil.unescape(theParameter.substring(barIndex + 1)));
|
setValue(ParameterUtil.unescape(theParameter.substring(barIndex + 1)));
|
||||||
|
@ -150,7 +157,6 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
|
ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
|
||||||
|
@ -159,6 +165,9 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||||
if (myText) {
|
if (myText) {
|
||||||
builder.append("text", myText);
|
builder.append("text", myText);
|
||||||
}
|
}
|
||||||
|
if (getMissing() != null) {
|
||||||
|
builder.append("missing", getMissing());
|
||||||
|
}
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -231,7 +231,7 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
||||||
|
|
||||||
String querySring = "SELECT count(h) FROM ResourceHistoryTable h " + "WHERE h.myResourceId = :PID AND h.myResourceType = :RESTYPE" + " AND h.myUpdated < :END" + (theSince != null ? " AND h.myUpdated >= :SINCE" : "");
|
String querySring = "SELECT count(h) FROM ResourceHistoryTable h " + "WHERE h.myResourceId = :PID AND h.myResourceType = :RESTYPE" + " AND h.myUpdated < :END" + (theSince != null ? " AND h.myUpdated >= :SINCE" : "");
|
||||||
TypedQuery<Long> countQuery = myEntityManager.createQuery(querySring, Long.class);
|
TypedQuery<Long> countQuery = myEntityManager.createQuery(querySring, Long.class);
|
||||||
countQuery.setParameter("PID", theId.getIdPartAsLong());
|
countQuery.setParameter("PID", translateForcedIdToPid(theId));
|
||||||
countQuery.setParameter("RESTYPE", resourceType);
|
countQuery.setParameter("RESTYPE", resourceType);
|
||||||
countQuery.setParameter("END", end.getValue(), TemporalType.TIMESTAMP);
|
countQuery.setParameter("END", end.getValue(), TemporalType.TIMESTAMP);
|
||||||
if (theSince != null) {
|
if (theSince != null) {
|
||||||
|
@ -269,7 +269,7 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
||||||
|
|
||||||
TypedQuery<ResourceHistoryTable> q = myEntityManager.createQuery("SELECT h FROM ResourceHistoryTable h WHERE h.myResourceId = :PID AND h.myResourceType = :RESTYPE AND h.myUpdated < :END " + (theSince != null ? " AND h.myUpdated >= :SINCE" : "")
|
TypedQuery<ResourceHistoryTable> q = myEntityManager.createQuery("SELECT h FROM ResourceHistoryTable h WHERE h.myResourceId = :PID AND h.myResourceType = :RESTYPE AND h.myUpdated < :END " + (theSince != null ? " AND h.myUpdated >= :SINCE" : "")
|
||||||
+ " ORDER BY h.myUpdated ASC", ResourceHistoryTable.class);
|
+ " ORDER BY h.myUpdated ASC", ResourceHistoryTable.class);
|
||||||
q.setParameter("PID", theId.getIdPartAsLong());
|
q.setParameter("PID", translateForcedIdToPid(theId));
|
||||||
q.setParameter("RESTYPE", resourceType);
|
q.setParameter("RESTYPE", resourceType);
|
||||||
q.setParameter("END", end.getValue(), TemporalType.TIMESTAMP);
|
q.setParameter("END", end.getValue(), TemporalType.TIMESTAMP);
|
||||||
if (theSince != null) {
|
if (theSince != null) {
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class JpaResourceProvider<T extends IResource> extends BaseJpaProvider im
|
||||||
public IBundleProvider getHistoryForResourceInstance(HttpServletRequest theRequest, @IdParam IdDt theId, @Since Date theDate) {
|
public IBundleProvider getHistoryForResourceInstance(HttpServletRequest theRequest, @IdParam IdDt theId, @Since Date theDate) {
|
||||||
startRequest(theRequest);
|
startRequest(theRequest);
|
||||||
try {
|
try {
|
||||||
return myDao.history(theId.getIdPartAsLong(), theDate);
|
return myDao.history(theId, theDate);
|
||||||
} finally {
|
} finally {
|
||||||
endRequest(theRequest);
|
endRequest(theRequest);
|
||||||
}
|
}
|
||||||
|
|
|
@ -620,6 +620,30 @@ public class FhirResourceDaoTest {
|
||||||
assertTrue(patients.size() >= 2);
|
assertTrue(patients.size() >= 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHistoryByForcedId() {
|
||||||
|
IdDt idv1;
|
||||||
|
IdDt idv2;
|
||||||
|
{
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.addIdentifier("urn:system", "testHistoryByForcedId");
|
||||||
|
patient.addName().addFamily("Tester").addGiven("testHistoryByForcedId");
|
||||||
|
patient.setId("Patient/testHistoryByForcedId");
|
||||||
|
idv1 = ourPatientDao.create(patient).getId();
|
||||||
|
|
||||||
|
patient.addName().addFamily("Tester").addGiven("testHistoryByForcedIdName2");
|
||||||
|
idv2 = ourPatientDao.update(patient, idv1.toUnqualifiedVersionless()).getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Patient> patients = toList(ourPatientDao.history(idv1.toVersionless(), null));
|
||||||
|
assertTrue(patients.size() == 2);
|
||||||
|
// Newest first
|
||||||
|
assertEquals("Patient/testHistoryByForcedId/_history/2", patients.get(0).getId().toUnqualified().getValue());
|
||||||
|
assertEquals("Patient/testHistoryByForcedId/_history/1", patients.get(1).getId().toUnqualified().getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchByIdParam() {
|
public void testSearchByIdParam() {
|
||||||
IdDt id1;
|
IdDt id1;
|
||||||
|
|
Loading…
Reference in New Issue