Process :missing qualifier on date params

This commit is contained in:
James 2017-05-19 20:36:06 -04:00
parent 7a24bff0eb
commit f6ee4db598
7 changed files with 122 additions and 10 deletions

View File

@ -62,6 +62,7 @@ public class DateRangeParam implements IQueryParameterAnd<DateParam> {
* theUpperBound may both be populated, or one may be null, but it is not valid for both to be null.
*/
public DateRangeParam(Date theLowerBound, Date theUpperBound) {
this();
setRangeFromDatesInclusive(theLowerBound, theUpperBound);
}
@ -71,6 +72,7 @@ public class DateRangeParam implements IQueryParameterAnd<DateParam> {
* or upper bound, with no opposite bound.
*/
public DateRangeParam(DateParam theDateParam) {
this();
if (theDateParam == null) {
throw new NullPointerException("theDateParam can not be null");
}
@ -117,6 +119,7 @@ public class DateRangeParam implements IQueryParameterAnd<DateParam> {
* theUpperBound may both be populated, or one may be null, but it is not valid for both to be null.
*/
public DateRangeParam(DateParam theLowerBound, DateParam theUpperBound) {
this();
setRangeFromDatesInclusive(theLowerBound, theUpperBound);
}
@ -133,6 +136,7 @@ public class DateRangeParam implements IQueryParameterAnd<DateParam> {
* theUpperBound may both be populated, or one may be null, but it is not valid for both to be null.
*/
public DateRangeParam(IPrimitiveType<Date> theLowerBound, IPrimitiveType<Date> theUpperBound) {
this();
setRangeFromDatesInclusive(theLowerBound, theUpperBound);
}
@ -149,6 +153,7 @@ public class DateRangeParam implements IQueryParameterAnd<DateParam> {
* one may be null, but it is not valid for both to be null.
*/
public DateRangeParam(String theLowerBound, String theUpperBound) {
this();
setRangeFromDatesInclusive(theLowerBound, theUpperBound);
}
@ -158,9 +163,14 @@ public class DateRangeParam implements IQueryParameterAnd<DateParam> {
throw new InvalidRequestException("Can not have multiple date range parameters for the same param without a qualifier");
}
myLowerBound = new DateParam(ParamPrefixEnum.EQUAL, theParsed.getValueAsString());
myUpperBound = new DateParam(ParamPrefixEnum.EQUAL, theParsed.getValueAsString());
if (theParsed.getMissing() != null) {
myLowerBound = theParsed;
myUpperBound = theParsed;
} else {
myLowerBound = new DateParam(ParamPrefixEnum.EQUAL, theParsed.getValueAsString());
myUpperBound = new DateParam(ParamPrefixEnum.EQUAL, theParsed.getValueAsString());
}
} else {
switch (theParsed.getPrefix()) {
@ -248,11 +258,15 @@ public class DateRangeParam implements IQueryParameterAnd<DateParam> {
@Override
public List<DateParam> getValuesAsQueryTokens() {
ArrayList<DateParam> retVal = new ArrayList<DateParam>();
if (myLowerBound != null && !myLowerBound.isEmpty()) {
if (myLowerBound.getMissing() != null) {
retVal.add((myLowerBound));
}
if (myUpperBound != null && !myUpperBound.isEmpty()) {
retVal.add((myUpperBound));
} else {
if (myLowerBound != null && !myLowerBound.isEmpty()) {
retVal.add((myLowerBound));
}
if (myUpperBound != null && !myUpperBound.isEmpty()) {
retVal.add((myUpperBound));
}
}
return retVal;
}

View File

@ -187,7 +187,8 @@ public class SearchBuilder implements ISearchBuilder {
Join<ResourceTable, ResourceIndexedSearchParamDate> join = myResourceTableRoot.join("myParamsDate", JoinType.LEFT);
if (theList.get(0).getMissing() != null) {
addPredicateParamMissing(theResourceName, theParamName, theList.get(0).getMissing(), join);
Boolean missing = theList.get(0).getMissing();
addPredicateParamMissing(theResourceName, theParamName, missing, join);
return;
}

View File

@ -130,6 +130,11 @@ public class SearchParamExtractorDstu3 extends BaseSearchParamExtractor implemen
if (nextObject == null) {
continue;
}
if (nextObject instanceof Extension) {
Extension nextExtension = (Extension)nextObject;
nextObject = nextExtension.getValue();
}
ResourceIndexedSearchParamDate nextEntity;
if (nextObject instanceof BaseDateTimeType) {

View File

@ -225,7 +225,6 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu
Extension extParent = patient
.addExtension()
.setUrl("http://acme.org/foo");
extParent
.addExtension()
.setUrl("http://acme.org/bar")
@ -244,6 +243,44 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu
assertThat(foundResources, contains(p2id.getValue()));
}
@Test
public void testSearchForExtensionTwoDeepCodeableConcept() {
SearchParameter siblingSp = new SearchParameter();
siblingSp.addBase("Patient");
siblingSp.setCode("foobar");
siblingSp.setType(org.hl7.fhir.dstu3.model.Enumerations.SearchParamType.TOKEN);
siblingSp.setTitle("FooBar");
siblingSp.setExpression("Patient.extension('http://acme.org/foo').extension('http://acme.org/bar')");
siblingSp.setXpathUsage(org.hl7.fhir.dstu3.model.SearchParameter.XPathUsageType.NORMAL);
siblingSp.setStatus(org.hl7.fhir.dstu3.model.Enumerations.PublicationStatus.ACTIVE);
siblingSp.getTarget().add(new CodeType("Organization"));
mySearchParameterDao.create(siblingSp, mySrd);
mySearchParamRegsitry.forceRefresh();
Patient patient = new Patient();
patient.addName().setFamily("P2");
Extension extParent = patient
.addExtension()
.setUrl("http://acme.org/foo");
extParent
.addExtension()
.setUrl("http://acme.org/bar")
.setValue(new CodeableConcept().addCoding(new Coding().setSystem("foo").setCode("bar")));
IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
SearchParameterMap map;
IBundleProvider results;
List<String> foundResources;
map = new SearchParameterMap();
map.add("foobar", new TokenParam("foo", "bar"));
results = myPatientDao.search(map);
foundResources = toUnqualifiedVersionlessIdValues(results);
assertThat(foundResources, contains(p2id.getValue()));
}
@Test
public void testSearchForExtensionTwoDeepReferenceWrongType() {
SearchParameter siblingSp = new SearchParameter();

View File

@ -152,7 +152,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
assertThat(ids, contains(moId.getValue()));
}
@Test
public void testEverythingTimings() throws Exception {
String methodName = "testEverythingTimings";
@ -2614,6 +2614,26 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
}
}
@Test
public void testSearchWithMissingDate2() {
MedicationRequest mr1 = new MedicationRequest();
mr1.getCategory().addCoding().setSystem("urn:medicationroute").setCode("oral");
mr1.addDosageInstruction().getTiming().addEventElement().setValueAsString("2017-01-01");
IIdType id1 = myMedicationRequestDao.create(mr1).getId().toUnqualifiedVersionless();
MedicationRequest mr2 = new MedicationRequest();
mr2.getCategory().addCoding().setSystem("urn:medicationroute").setCode("oral");
IIdType id2 = myMedicationRequestDao.create(mr2).getId().toUnqualifiedVersionless();
SearchParameterMap map = new SearchParameterMap();
map.add(MedicationRequest.SP_DATE, new DateParam().setMissing(true));
IBundleProvider results = myMedicationRequestDao.search(map);
List<String> ids = toUnqualifiedVersionlessIdValues(results);
assertThat(ids, contains(id2.getValue()));
}
@Test
public void testSearchWithMissingQuantity() {
IIdType notMissing;

View File

@ -125,6 +125,7 @@ import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import com.google.common.collect.Lists;
import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
import ca.uhn.fhir.jpa.entity.Search;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.model.primitive.UriDt;
@ -134,12 +135,14 @@ import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.SummaryEnum;
import ca.uhn.fhir.rest.client.IGenericClient;
import ca.uhn.fhir.rest.gclient.StringClientParam;
import ca.uhn.fhir.rest.param.DateParam;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.ParamPrefixEnum;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.StringOrListParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
@ -175,6 +178,35 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
myDaoConfig.setAllowMultipleDelete(true);
}
@Test
public void testSearchWithMissingDate2() throws Exception {
MedicationRequest mr1 = new MedicationRequest();
mr1.getCategory().addCoding().setSystem("urn:medicationroute").setCode("oral");
mr1.addDosageInstruction().getTiming().addEventElement().setValueAsString("2017-01-01");
IIdType id1 = myMedicationRequestDao.create(mr1).getId().toUnqualifiedVersionless();
MedicationRequest mr2 = new MedicationRequest();
mr2.getCategory().addCoding().setSystem("urn:medicationroute").setCode("oral");
IIdType id2 = myMedicationRequestDao.create(mr2).getId().toUnqualifiedVersionless();
HttpGet get = new HttpGet(ourServerBase + "/MedicationRequest?date:missing=false");
CloseableHttpResponse resp = ourHttpClient.execute(get);
try {
assertEquals(200, resp.getStatusLine().getStatusCode());
Bundle bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, IOUtils.toString(resp.getEntity().getContent(), Constants.CHARSET_UTF8));
List<String> ids = toUnqualifiedVersionlessIdValues(bundle);
assertThat(ids, contains(id1.getValue()));
} finally {
IOUtils.closeQuietly(resp);
}
}
@Test
public void testSaveAndRetrieveResourceWithExtension() {
Patient nextPatient = new Patient();

View File

@ -105,6 +105,9 @@
Server now respects the If-Modified-Since header and will return an HTTP 304 if appropriate
for read operations.
</action>
<action type="fix">
JPA server did not correctly process :missing qualifier on date parameters
</action>
</release>
<release version="2.4" date="2017-04-19">
<action type="add">