From 9e83f1d40a181e54ad77a4c2c12de0b988a76ee9 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Mon, 9 Sep 2019 14:22:42 -0400 Subject: [PATCH] changelog --- .../fhir/model/primitive/BaseDateTimeDt.java | 21 +++++++++-------- .../fhir/rest/param/BaseParamWithPrefix.java | 2 +- .../matcher/InMemoryResourceMatcherTest.java | 23 +++++++++++++------ src/changes/changes.xml | 7 ++++++ 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/BaseDateTimeDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/BaseDateTimeDt.java index e3c7e1db190..903c7e1cf87 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/BaseDateTimeDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/BaseDateTimeDt.java @@ -20,21 +20,20 @@ package ca.uhn.fhir.model.primitive; * #L% */ -import static org.apache.commons.lang3.StringUtils.isBlank; +import ca.uhn.fhir.model.api.BasePrimitive; +import ca.uhn.fhir.model.api.TemporalPrecisionEnum; +import ca.uhn.fhir.parser.DataFormatException; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; +import org.apache.commons.lang3.time.DateUtils; +import org.apache.commons.lang3.time.FastDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.Validate; -import org.apache.commons.lang3.time.DateUtils; -import org.apache.commons.lang3.time.FastDateFormat; - -import ca.uhn.fhir.model.api.BasePrimitive; -import ca.uhn.fhir.model.api.TemporalPrecisionEnum; -import ca.uhn.fhir.parser.DataFormatException; +import static org.apache.commons.lang3.StringUtils.isBlank; public abstract class BaseDateTimeDt extends BasePrimitive { static final long NANOS_PER_MILLIS = 1000000L; @@ -343,6 +342,10 @@ public abstract class BaseDateTimeDt extends BasePrimitive { throwBadDateFormat(value); } + if (value.equalsIgnoreCase("%now")) { + return new Date(); + } + TemporalPrecisionEnum precision = null; cal.set(Calendar.YEAR, parseInt(value, value.substring(0, 4), 0, 9999)); precision = TemporalPrecisionEnum.YEAR; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/BaseParamWithPrefix.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/BaseParamWithPrefix.java index 50c461c7c9f..d96c5920378 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/BaseParamWithPrefix.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/BaseParamWithPrefix.java @@ -47,7 +47,7 @@ public abstract class BaseParamWithPrefix extends BaseParam break; } else { char nextChar = theString.charAt(offset); - if (nextChar == '-' || Character.isDigit(nextChar)) { + if (nextChar == '-' || nextChar == '%' || Character.isDigit(nextChar)) { break; } } diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcherTest.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcherTest.java index 1f905e35eed..8f466e23b3b 100644 --- a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcherTest.java +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcherTest.java @@ -29,6 +29,8 @@ public class InMemoryResourceMatcherTest { public static final String OBS_DATE = "1970-10-17"; private static final String EARLY_DATE = "1965-08-09"; private static final String LATE_DATE = "2000-06-29"; + // FIXME KHS move this + private static final String NOW = "NOW"; @Autowired private @@ -67,13 +69,6 @@ public class InMemoryResourceMatcherTest { mySearchParams = extractDateSearchParam(myObservation); } - private ResourceIndexedSearchParams extractDateSearchParam(Observation theObservation) { - ResourceIndexedSearchParams retval = new ResourceIndexedSearchParams(); - BaseDateTimeType dateValue = (BaseDateTimeType) theObservation.getEffective(); - ResourceIndexedSearchParamDate dateParam = new ResourceIndexedSearchParamDate("date", dateValue.getValue(), dateValue.getValue(), dateValue.getValueAsString()); - retval.myDateParams.add(dateParam); - return retval; - } @Test public void testUnsupportedOps() { @@ -115,7 +110,21 @@ public class InMemoryResourceMatcherTest { assertTrue(result.getUnsupportedReason(), result.supported()); assertEquals(result.matched(), theLater); } + } + @Test + public void testNow() { + InMemoryMatchResult result = myInMemoryResourceMatcher.match("date=lt%now", myObservation, mySearchParams); + assertTrue(result.getUnsupportedReason(), result.supported()); + assertTrue(result.matched()); + } + + private ResourceIndexedSearchParams extractDateSearchParam(Observation theObservation) { + ResourceIndexedSearchParams retval = new ResourceIndexedSearchParams(); + BaseDateTimeType dateValue = (BaseDateTimeType) theObservation.getEffective(); + ResourceIndexedSearchParamDate dateParam = new ResourceIndexedSearchParamDate("date", dateValue.getValue(), dateValue.getValue(), dateValue.getValueAsString()); + retval.myDateParams.add(dateParam); + return retval; } } diff --git a/src/changes/changes.xml b/src/changes/changes.xml index af872a8c8df..da7a8f048e8 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -117,6 +117,13 @@ the RequestValidatingInterceptor, but not including any HAPI FHIR security interceptors) could be bypassed if a Content Type was not included. + + Added support for comparing resource dates to the current time via a new variable %now. E.g. + Procedure?date=gt%now would match future procedures. + + + Add support for in-memory matching on date comparisons ge,gt,eq,lt,le. +