From 170b6079922d5916ab73eb17d11555f6c9e75a2d Mon Sep 17 00:00:00 2001 From: Diederik Muylwyk Date: Mon, 30 Dec 2019 18:43:15 -0500 Subject: [PATCH 1/3] Added some FIXMEs. --- .../src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java | 1 + .../test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java index aa20383f423..c6441ca8f2b 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java @@ -388,6 +388,7 @@ public class DateRangeParam implements IQueryParameterAnd { return Objects.hash(myLowerBound, myUpperBound); } + // FIXME: DM 2019-12-30 - We're matching exactly but need to account for intervals (see issue #1652). public boolean isDateWithinRange(Date theDate) { boolean retVal = false; diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java index 6cfd86d3ad2..952884e3b0c 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java @@ -48,6 +48,8 @@ public class DateRangeParamTest { myAfter = new Date(); } + // FIXME: DM 2019-12-30 - We're matching exactly but need to account for intervals (see issue #1652). + @Test public void testIsDateWithinRangeExclusive() { DateParam lowerBound = new DateParam(GREATERTHAN, myLower); From 48f7ee5afbc7b608aa3609a45e7eaabf100cc078 Mon Sep 17 00:00:00 2001 From: Diederik Muylwyk Date: Tue, 31 Dec 2019 09:25:56 -0500 Subject: [PATCH 2/3] Rolling back previous unnecessary changes. --- .../uhn/fhir/rest/param/DateRangeParam.java | 99 ---------- .../fhir/rest/param/DateRangeParamTest.java | 184 ------------------ .../hapi/fhir/changelog/4_2_0/changes.yaml | 9 - 3 files changed, 292 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java index c6441ca8f2b..6094edcb7ca 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java @@ -388,105 +388,6 @@ public class DateRangeParam implements IQueryParameterAnd { return Objects.hash(myLowerBound, myUpperBound); } - // FIXME: DM 2019-12-30 - We're matching exactly but need to account for intervals (see issue #1652). - public boolean isDateWithinRange(Date theDate) { - boolean retVal = false; - - if (theDate == null) { - throw new NullPointerException("theDate can not be null"); - } - - boolean hasLowerBound = hasBound(myLowerBound); - boolean hasUpperBound = hasBound(myUpperBound); - boolean hasLowerAndUpperBounds = hasLowerBound && hasUpperBound && (myLowerBound.getValue().getTime() != myUpperBound.getValue().getTime()); - - if (hasLowerAndUpperBounds) { - retVal = isDateWithinLowerAndUpperBounds(theDate); - } else if (hasLowerBound) { - retVal = isDateWithinLowerBound(theDate); - } else if (hasUpperBound) { - retVal = isDateWithinUpperBound(theDate); - } - - return retVal; - } - - private boolean isDateWithinLowerAndUpperBounds(Date theDate) { - return isDateWithinLowerBound(theDate, true) && isDateWithinUpperBound(theDate, true); - } - - public boolean isDateWithinLowerBound(Date theDate) { - return isDateWithinLowerBound(theDate, false); - } - - private boolean isDateWithinLowerBound(Date theDate, boolean theIsRange) { - boolean retVal = false; - - if (theDate == null) { - throw new NullPointerException("theDate can not be null"); - } - - if (hasBound(myLowerBound)) { - long lowerBound = myLowerBound.getValue().getTime(); - switch (myLowerBound.getPrefix()) { - case GREATERTHAN: - case STARTS_AFTER: - retVal = theDate.getTime() > lowerBound; - break; - case EQUAL: - if (theIsRange) { - retVal = theDate.getTime() >= lowerBound; - } else { - retVal = theDate.getTime() == lowerBound; - } - break; - case GREATERTHAN_OR_EQUALS: - retVal = theDate.getTime() >= lowerBound; - break; - default: - throw new IllegalStateException("Invalid lower bound comparator: " + myLowerBound.getPrefix()); - } - } - - return retVal; - } - - public boolean isDateWithinUpperBound(Date theDate) { - return isDateWithinUpperBound(theDate, false); - } - - private boolean isDateWithinUpperBound(Date theDate, boolean theIsRange) { - boolean retVal = false; - - if (theDate == null) { - throw new NullPointerException("theDate can not be null"); - } - - if (hasBound(myUpperBound)) { - long upperBound = myUpperBound.getValue().getTime(); - switch (myUpperBound.getPrefix()) { - case LESSTHAN: - case ENDS_BEFORE: - retVal = theDate.getTime() < upperBound; - break; - case EQUAL: - if (theIsRange) { - retVal = theDate.getTime() <= upperBound; - } else { - retVal = theDate.getTime() == upperBound; - } - break; - case LESSTHAN_OR_EQUALS: - retVal = theDate.getTime() <= upperBound; - break; - default: - throw new IllegalStateException("Invalid upper bound comparator: " + myUpperBound.getPrefix()); - } - } - - return retVal; - } - public boolean isEmpty() { return (getLowerBoundAsInstant() == null) && (getUpperBoundAsInstant() == null); } diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java index 952884e3b0c..eb79adb23bf 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java @@ -3,209 +3,25 @@ package ca.uhn.fhir.rest.param; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.api.QualifiedParamList; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; import java.util.ArrayList; -import java.util.Date; import java.util.List; -import static ca.uhn.fhir.rest.param.ParamPrefixEnum.*; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @RunWith(JUnit4.class) public class DateRangeParamTest { private FhirContext fhirContext; - private Date myBefore; - private Date myLower; - private Date myBetween; - private Date myUpper; - private Date myAfter; - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); @Before public void initMockContext() { fhirContext = Mockito.mock(FhirContext.class); } - @Before - public void initDates() throws InterruptedException { - myBefore = new Date(); - Thread.sleep(1L); - myLower = new Date(); - Thread.sleep(1L); - myBetween = new Date(); - Thread.sleep(1L); - myUpper = new Date(); - Thread.sleep(1L); - myAfter = new Date(); - } - - // FIXME: DM 2019-12-30 - We're matching exactly but need to account for intervals (see issue #1652). - - @Test - public void testIsDateWithinRangeExclusive() { - DateParam lowerBound = new DateParam(GREATERTHAN, myLower); - DateParam upperBound = new DateParam(LESSTHAN, myUpper); - DateRangeParam dateRangeParam = new DateRangeParam(lowerBound, upperBound); - - assertFalse(dateRangeParam.isDateWithinRange(myBefore)); - assertFalse(dateRangeParam.isDateWithinRange(myLower)); - assertTrue(dateRangeParam.isDateWithinRange(myBetween)); - assertFalse(dateRangeParam.isDateWithinRange(myUpper)); - assertFalse(dateRangeParam.isDateWithinRange(myAfter)); - } - - @Test - public void testIsDateWithinRangeInclusive() { - DateParam lowerBound = new DateParam(EQUAL, myLower); - DateParam upperBound = new DateParam(EQUAL, myUpper); - DateRangeParam dateRangeParam = new DateRangeParam(lowerBound, upperBound); - - assertFalse(dateRangeParam.isDateWithinRange(myBefore)); - assertTrue(dateRangeParam.isDateWithinRange(myLower)); - assertTrue(dateRangeParam.isDateWithinRange(myBetween)); - assertTrue(dateRangeParam.isDateWithinRange(myUpper)); - assertFalse(dateRangeParam.isDateWithinRange(myAfter)); - } - - @Test - public void testIsDateWithinRangeOnlyLower() { - DateParam lowerBound = new DateParam(EQUAL, myLower); - DateRangeParam dateRangeParam = new DateRangeParam(); - dateRangeParam.setLowerBound(lowerBound); - - assertFalse(dateRangeParam.isDateWithinRange(myBefore)); - assertTrue(dateRangeParam.isDateWithinRange(myLower)); - assertFalse(dateRangeParam.isDateWithinRange(myBetween)); - assertFalse(dateRangeParam.isDateWithinRange(myUpper)); - assertFalse(dateRangeParam.isDateWithinRange(myAfter)); - } - - @Test - public void testIsDateWithinRangeOnlyUpper() { - DateParam upperBound = new DateParam(EQUAL, myUpper); - DateRangeParam dateRangeParam = new DateRangeParam(); - dateRangeParam.setUpperBound(upperBound); - - assertFalse(dateRangeParam.isDateWithinRange(myBefore)); - assertFalse(dateRangeParam.isDateWithinRange(myLower)); - assertFalse(dateRangeParam.isDateWithinRange(myBetween)); - assertTrue(dateRangeParam.isDateWithinRange(myUpper)); - assertFalse(dateRangeParam.isDateWithinRange(myAfter)); - } - - @Test - public void testIsDateWithinLowerBoundGreaterThan() { - DateParam lowerBound = new DateParam(GREATERTHAN, myLower); - DateRangeParam dateRangeParam = new DateRangeParam(); - dateRangeParam.setLowerBound(lowerBound); - - assertFalse(dateRangeParam.isDateWithinLowerBound(myBefore)); - assertFalse(dateRangeParam.isDateWithinLowerBound(myLower)); - assertTrue(dateRangeParam.isDateWithinLowerBound(myBetween)); - assertTrue(dateRangeParam.isDateWithinLowerBound(myUpper)); - assertTrue(dateRangeParam.isDateWithinLowerBound(myAfter)); - } - - @Test - public void testIsDateWithinLowerBoundStartsAfter() { - DateParam lowerBound = new DateParam(STARTS_AFTER, myLower); - DateRangeParam dateRangeParam = new DateRangeParam(); - dateRangeParam.setLowerBound(lowerBound); - - assertFalse(dateRangeParam.isDateWithinLowerBound(myBefore)); - assertFalse(dateRangeParam.isDateWithinLowerBound(myLower)); - assertTrue(dateRangeParam.isDateWithinLowerBound(myBetween)); - assertTrue(dateRangeParam.isDateWithinLowerBound(myUpper)); - assertTrue(dateRangeParam.isDateWithinLowerBound(myAfter)); - } - - @Test - public void testIsDateWithinLowerBoundEqual() { - DateParam lowerBound = new DateParam(EQUAL, myLower); - DateRangeParam dateRangeParam = new DateRangeParam(); - dateRangeParam.setLowerBound(lowerBound); - - assertFalse(dateRangeParam.isDateWithinLowerBound(myBefore)); - assertTrue(dateRangeParam.isDateWithinLowerBound(myLower)); - assertFalse(dateRangeParam.isDateWithinLowerBound(myBetween)); - assertFalse(dateRangeParam.isDateWithinLowerBound(myUpper)); - assertFalse(dateRangeParam.isDateWithinLowerBound(myAfter)); - } - - @Test - public void testIsDateWithinLowerBoundGreaterThanOrEquals() { - DateParam lowerBound = new DateParam(GREATERTHAN_OR_EQUALS, myLower); - DateRangeParam dateRangeParam = new DateRangeParam(); - dateRangeParam.setLowerBound(lowerBound); - - assertFalse(dateRangeParam.isDateWithinLowerBound(myBefore)); - assertTrue(dateRangeParam.isDateWithinLowerBound(myLower)); - assertTrue(dateRangeParam.isDateWithinLowerBound(myBetween)); - assertTrue(dateRangeParam.isDateWithinLowerBound(myUpper)); - assertTrue(dateRangeParam.isDateWithinLowerBound(myAfter)); - } - - @Test - public void testIsDateWithinUpperBoundLessThan() { - DateParam upperBound = new DateParam(LESSTHAN, myUpper); - DateRangeParam dateRangeParam = new DateRangeParam(); - dateRangeParam.setUpperBound(upperBound); - - assertTrue(dateRangeParam.isDateWithinUpperBound(myBefore)); - assertTrue(dateRangeParam.isDateWithinUpperBound(myLower)); - assertTrue(dateRangeParam.isDateWithinUpperBound(myBetween)); - assertFalse(dateRangeParam.isDateWithinUpperBound(myUpper)); - assertFalse(dateRangeParam.isDateWithinUpperBound(myAfter)); - } - - @Test - public void testIsDateWithinUpperBoundEndsBefore() { - DateParam upperBound = new DateParam(ENDS_BEFORE, myUpper); - DateRangeParam dateRangeParam = new DateRangeParam(); - dateRangeParam.setUpperBound(upperBound); - - assertTrue(dateRangeParam.isDateWithinUpperBound(myBefore)); - assertTrue(dateRangeParam.isDateWithinUpperBound(myLower)); - assertTrue(dateRangeParam.isDateWithinUpperBound(myBetween)); - assertFalse(dateRangeParam.isDateWithinUpperBound(myUpper)); - assertFalse(dateRangeParam.isDateWithinUpperBound(myAfter)); - } - - @Test - public void testIsDateWithinUpperBoundEqual() { - DateParam upperBound = new DateParam(EQUAL, myUpper); - DateRangeParam dateRangeParam = new DateRangeParam(); - dateRangeParam.setUpperBound(upperBound); - - assertFalse(dateRangeParam.isDateWithinUpperBound(myBefore)); - assertFalse(dateRangeParam.isDateWithinUpperBound(myLower)); - assertFalse(dateRangeParam.isDateWithinUpperBound(myBetween)); - assertTrue(dateRangeParam.isDateWithinUpperBound(myUpper)); - assertFalse(dateRangeParam.isDateWithinUpperBound(myAfter)); - } - - @Test - public void testIsDateWithinUpperBoundLessThanOrEquals() { - DateParam upperBound = new DateParam(LESSTHAN_OR_EQUALS, myUpper); - DateRangeParam dateRangeParam = new DateRangeParam(); - dateRangeParam.setUpperBound(upperBound); - - assertTrue(dateRangeParam.isDateWithinUpperBound(myBefore)); - assertTrue(dateRangeParam.isDateWithinUpperBound(myLower)); - assertTrue(dateRangeParam.isDateWithinUpperBound(myBetween)); - assertTrue(dateRangeParam.isDateWithinUpperBound(myUpper)); - assertFalse(dateRangeParam.isDateWithinUpperBound(myAfter)); - } - /** Can happen e.g. when the query parameter for {@code _lastUpdated} is left empty. */ @Test public void testParamWithoutPrefixAndWithoutValue() { diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/4_2_0/changes.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/4_2_0/changes.yaml index 751ab54a333..2f066f06574 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/4_2_0/changes.yaml +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/4_2_0/changes.yaml @@ -56,12 +56,3 @@ type: "fix" title: "Several misleading comments in documentation code snippets were fixed. Thanks to Jafer Khan for the pull request!" -- item: - issue: "1645" - type: "add" - title: "The following utility methods have been added: -
    -
  • DateRangeParam#isDateWithinRange(Date theDate)
  • -
  • DateRangeParam#isDateWithinLowerBound(Date theDate)
  • -
  • DateRangeParam#isDateWithinUpperBound(Date theDate)
  • -
" From 8615d1073014e1d61958e0303eb38a55701044f9 Mon Sep 17 00:00:00 2001 From: Diederik Muylwyk Date: Tue, 31 Dec 2019 09:27:26 -0500 Subject: [PATCH 3/3] Fix typo. --- .../src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java index 6094edcb7ca..d65d91fdf9d 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java @@ -485,7 +485,7 @@ public class DateRangeParam implements IQueryParameterAnd { continue; } if (paramList.size() > 1) { - throw new InvalidRequestException("DateRange parameter does not suppport OR queries"); + throw new InvalidRequestException("DateRange parameter does not support OR queries"); } String param = paramList.get(0);