Fix failing unit tests

This commit is contained in:
James Agnew 2014-08-12 12:27:51 -04:00
parent d0edc03f14
commit 0ff847ac21
8 changed files with 66 additions and 26 deletions

View File

@ -22,7 +22,7 @@ public class BaseParam implements IQueryParameterType {
@Override
public String getQueryParameterQualifier() {
if (myMissing) {
if (myMissing != null) {
return Constants.PARAMQUALIFIER_MISSING;
}
return null;

View File

@ -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.valueset.QuantityCompararatorEnum;
public class NumberParam implements IQueryParameterType {
public class NumberParam extends BaseParam implements IQueryParameterType {
private QuantityDt myQuantity = new QuantityDt();
@ -71,7 +71,8 @@ public class NumberParam implements IQueryParameterType {
@Override
public void setValueAsQueryToken(String theQualifier, String theValue) {
if (isBlank(theValue)) {
super.setValueAsQueryToken(theQualifier, theValue);
if (getMissing() != null && isBlank(theValue)) {
return;
}
if (theValue.startsWith("<=")) {
@ -94,6 +95,10 @@ public class NumberParam implements IQueryParameterType {
@Override
public String getValueAsQueryToken() {
if (getMissing() != null) {
return super.getQueryParameterQualifier();
}
StringBuilder b = new StringBuilder();
if (myQuantity.getComparator().isEmpty() == false) {
b.append(myQuantity.getComparator().getValue());
@ -106,7 +111,7 @@ public class NumberParam implements IQueryParameterType {
@Override
public String getQueryParameterQualifier() {
return null;
return super.getQueryParameterQualifier();
}
}

View File

@ -146,7 +146,7 @@ public class QuantityParam extends BaseParam implements IQueryParameterType {
@Override
public String getQueryParameterQualifier() {
return null;
return super.getQueryParameterQualifier();
}
public UriDt getSystem() {

View File

@ -49,10 +49,12 @@ public class StringParam extends BaseParam implements IQueryParameterType {
@Override
public String getQueryParameterQualifier() {
if (isExact()) {
if (getMissing() != null) {
return super.getQueryParameterQualifier();
}else if (isExact()) {
return Constants.PARAMQUALIFIER_STRING_EXACT;
} else {
return super.getQueryParameterQualifier();
return null;
}
}

View File

@ -49,29 +49,29 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
public TokenParam(String theSystem, String theValue, boolean theText) {
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);
setValue(theValue);
setText(theText);
}
/**
* Constructor which copies the {@link CodingDt#getSystem() system} and {@link CodingDt#getCode() code} from a {@link CodingDt}
* instance and adds it as a parameter
* Constructor which copies the {@link CodingDt#getSystem() system} and {@link CodingDt#getCode() code} from a {@link CodingDt} instance and adds it as a parameter
*
* @param theCodingDt The coding
* @param theCodingDt
* The coding
*/
public TokenParam(CodingDt theCodingDt) {
this(toSystemValue(theCodingDt.getSystem()), theCodingDt.getCode().getValue());
}
/**
* Constructor which copies the {@link IdentifierDt#getSystem() system} and {@link IdentifierDt#getValue() value} from a {@link IdentifierDt}
* instance and adds it as a parameter
* Constructor which copies the {@link IdentifierDt#getSystem() system} and {@link IdentifierDt#getValue() value} from a {@link IdentifierDt} instance and adds it as a parameter
*
* @param theCodingDt The coding
* @param theCodingDt
* The coding
*/
public TokenParam(IdentifierDt theIdentifierDt) {
this(toSystemValue(theIdentifierDt.getSystem()), theIdentifierDt.getValue().getValue());
@ -83,7 +83,9 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
@Override
public String getQueryParameterQualifier() {
if (isText()) {
if (getMissing() != null) {
return super.getQueryParameterQualifier();
} else if (isText()) {
return Constants.PARAMQUALIFIER_TOKEN_TEXT;
} else {
return null;
@ -103,8 +105,10 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
*/
@Override
public String getValueAsQueryToken() {
if (getSystem() != null) {
return ParameterUtil.escape(StringUtils.defaultString(getSystem())) + '|' + ParameterUtil.escape(getValue());
if (getMissing() != null) {
return super.getValueAsQueryToken();
} else if (getSystem() != null) {
return ParameterUtil.escape(StringUtils.defaultString(getSystem())) + '|' + ParameterUtil.escape(getValue());
} else {
return ParameterUtil.escape(getValue());
}
@ -118,11 +122,9 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
return StringUtils.isEmpty(myValue);
}
public boolean isText() {
return myText;
}
}
public void setSystem(String theSystem) {
mySystem = theSystem;
@ -141,7 +143,12 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
*/
@Override
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) {
setSystem(theParameter.substring(0, barIndex));
setValue(ParameterUtil.unescape(theParameter.substring(barIndex + 1)));
@ -150,7 +157,6 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
}
}
@Override
public String toString() {
ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
@ -159,6 +165,9 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
if (myText) {
builder.append("text", myText);
}
if (getMissing() != null) {
builder.append("missing", getMissing());
}
return builder.toString();
}

View File

@ -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" : "");
TypedQuery<Long> countQuery = myEntityManager.createQuery(querySring, Long.class);
countQuery.setParameter("PID", theId.getIdPartAsLong());
countQuery.setParameter("PID", translateForcedIdToPid(theId));
countQuery.setParameter("RESTYPE", resourceType);
countQuery.setParameter("END", end.getValue(), TemporalType.TIMESTAMP);
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" : "")
+ " ORDER BY h.myUpdated ASC", ResourceHistoryTable.class);
q.setParameter("PID", theId.getIdPartAsLong());
q.setParameter("PID", translateForcedIdToPid(theId));
q.setParameter("RESTYPE", resourceType);
q.setParameter("END", end.getValue(), TemporalType.TIMESTAMP);
if (theSince != null) {

View File

@ -78,7 +78,7 @@ public class JpaResourceProvider<T extends IResource> extends BaseJpaProvider im
public IBundleProvider getHistoryForResourceInstance(HttpServletRequest theRequest, @IdParam IdDt theId, @Since Date theDate) {
startRequest(theRequest);
try {
return myDao.history(theId.getIdPartAsLong(), theDate);
return myDao.history(theId, theDate);
} finally {
endRequest(theRequest);
}

View File

@ -620,6 +620,30 @@ public class FhirResourceDaoTest {
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
public void testSearchByIdParam() {
IdDt id1;