Add one more test for #2023

This commit is contained in:
jamesagnew 2020-08-11 08:54:03 -04:00
parent f3fbad63e7
commit 90ebaf8549
2 changed files with 65 additions and 13 deletions

View File

@ -27,7 +27,7 @@ import ca.uhn.fhir.rest.param.ParamPrefixEnum;
*/
public class NumberClientParam extends BaseClientParam implements IParam {
private String myParamName;
private final String myParamName;
public NumberClientParam(String theParamName) {
myParamName = theParamName;
@ -37,12 +37,12 @@ public class NumberClientParam extends BaseClientParam implements IParam {
return new IMatches<ICriterion<NumberClientParam>>() {
@Override
public ICriterion<NumberClientParam> number(long theNumber) {
return new StringCriterion<NumberClientParam>(getParamName(), Long.toString(theNumber));
return new StringCriterion<>(getParamName(), Long.toString(theNumber));
}
@Override
public ICriterion<NumberClientParam> number(String theNumber) {
return new StringCriterion<NumberClientParam>(getParamName(), (theNumber));
return new StringCriterion<>(getParamName(), (theNumber));
}
};
}
@ -56,12 +56,12 @@ public class NumberClientParam extends BaseClientParam implements IParam {
return new IMatches<ICriterion<NumberClientParam>>() {
@Override
public ICriterion<NumberClientParam> number(long theNumber) {
return new StringCriterion<NumberClientParam>(getParamName(), ParamPrefixEnum.GREATERTHAN, Long.toString(theNumber));
return new StringCriterion<>(getParamName(), ParamPrefixEnum.GREATERTHAN, Long.toString(theNumber));
}
@Override
public ICriterion<NumberClientParam> number(String theNumber) {
return new StringCriterion<NumberClientParam>(getParamName(), ParamPrefixEnum.GREATERTHAN, (theNumber));
return new StringCriterion<>(getParamName(), ParamPrefixEnum.GREATERTHAN, (theNumber));
}
};
}
@ -70,12 +70,12 @@ public class NumberClientParam extends BaseClientParam implements IParam {
return new IMatches<ICriterion<NumberClientParam>>() {
@Override
public ICriterion<NumberClientParam> number(long theNumber) {
return new StringCriterion<NumberClientParam>(getParamName(), ParamPrefixEnum.GREATERTHAN_OR_EQUALS, Long.toString(theNumber));
return new StringCriterion<>(getParamName(), ParamPrefixEnum.GREATERTHAN_OR_EQUALS, Long.toString(theNumber));
}
@Override
public ICriterion<NumberClientParam> number(String theNumber) {
return new StringCriterion<NumberClientParam>(getParamName(), ParamPrefixEnum.GREATERTHAN_OR_EQUALS, (theNumber));
return new StringCriterion<>(getParamName(), ParamPrefixEnum.GREATERTHAN_OR_EQUALS, (theNumber));
}
};
}
@ -84,12 +84,12 @@ public class NumberClientParam extends BaseClientParam implements IParam {
return new IMatches<ICriterion<NumberClientParam>>() {
@Override
public ICriterion<NumberClientParam> number(long theNumber) {
return new StringCriterion<NumberClientParam>(getParamName(), ParamPrefixEnum.LESSTHAN, Long.toString(theNumber));
return new StringCriterion<>(getParamName(), ParamPrefixEnum.LESSTHAN, Long.toString(theNumber));
}
@Override
public ICriterion<NumberClientParam> number(String theNumber) {
return new StringCriterion<NumberClientParam>(getParamName(), ParamPrefixEnum.LESSTHAN, (theNumber));
return new StringCriterion<>(getParamName(), ParamPrefixEnum.LESSTHAN, (theNumber));
}
};
}
@ -98,12 +98,12 @@ public class NumberClientParam extends BaseClientParam implements IParam {
return new IMatches<ICriterion<NumberClientParam>>() {
@Override
public ICriterion<NumberClientParam> number(long theNumber) {
return new StringCriterion<NumberClientParam>(getParamName(), ParamPrefixEnum.LESSTHAN_OR_EQUALS, Long.toString(theNumber));
return new StringCriterion<>(getParamName(), ParamPrefixEnum.LESSTHAN_OR_EQUALS, Long.toString(theNumber));
}
@Override
public ICriterion<NumberClientParam> number(String theNumber) {
return new StringCriterion<NumberClientParam>(getParamName(), ParamPrefixEnum.LESSTHAN_OR_EQUALS, (theNumber));
return new StringCriterion<>(getParamName(), ParamPrefixEnum.LESSTHAN_OR_EQUALS, (theNumber));
}
};
}
@ -112,12 +112,12 @@ public class NumberClientParam extends BaseClientParam implements IParam {
return new IMatches<ICriterion<NumberClientParam>>() {
@Override
public ICriterion<NumberClientParam> number(long theNumber) {
return new StringCriterion<NumberClientParam>(getParamName(), thePrefix, Long.toString(theNumber));
return new StringCriterion<>(getParamName(), thePrefix, Long.toString(theNumber));
}
@Override
public ICriterion<NumberClientParam> number(String theNumber) {
return new StringCriterion<NumberClientParam>(getParamName(), thePrefix, (theNumber));
return new StringCriterion<>(getParamName(), thePrefix, (theNumber));
}
};
}

View File

@ -35,6 +35,12 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.model.dstu2.resource.SearchParameter;
import ca.uhn.fhir.model.dstu2.valueset.XPathUsageTypeEnum;
import ca.uhn.fhir.model.primitive.IntegerDt;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.gclient.NumberClientParam;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
@ -168,6 +174,52 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
}
}
/**
* See #2023
*/
@Test
public void testCustomNumberSearchParam() {
SearchParameter numberParameter = new SearchParameter();
numberParameter.setId("future-appointment-count");
numberParameter.setName("Future Appointment Count");
numberParameter.setCode("future-appointment-count");
numberParameter.setDescription("Count of future appointments for the patient");
numberParameter.setUrl("http://integer");
numberParameter.setStatus(ca.uhn.fhir.model.dstu2.valueset.ConformanceResourceStatusEnum.ACTIVE);
numberParameter.setBase(ca.uhn.fhir.model.dstu2.valueset.ResourceTypeEnum.PATIENT);
numberParameter.setType(ca.uhn.fhir.model.dstu2.valueset.SearchParamTypeEnum.NUMBER);
numberParameter.setXpathUsage(XPathUsageTypeEnum.NORMAL);
numberParameter.setXpath("Patient.extension('http://integer')");
ourClient.update().resource(numberParameter).execute();
// This fires every 10 seconds
mySearchParamRegistry.refreshCacheIfNecessary();
Patient patient = new Patient();
patient.setId("future-appointment-count-pt");
patient.setActive(true);
patient.addUndeclaredExtension(false, "http://integer", new IntegerDt(2));
ourClient.update().resource(patient).execute();
Bundle futureAppointmentCountBundle2 = ourClient
.search()
.forResource(Patient.class)
.where(new NumberClientParam("future-appointment-count").greaterThan().number(1))
.returnBundle(Bundle.class)
.execute();
assertEquals(futureAppointmentCountBundle2.getTotal().intValue(), 1);
Bundle futureAppointmentCountBundle3 = ourClient
.search()
.forResource(Patient.class)
.where(new NumberClientParam("future-appointment-count").exactly().number(2))
.returnBundle(Bundle.class)
.execute();
assertEquals(futureAppointmentCountBundle3.getTotal().intValue(), 1);
}
/**
* See #484
*/