Skip to content

Commit

Permalink
Issue #2981 - Update testcases to handle date with 0 milliseconds fie…
Browse files Browse the repository at this point in the history
…ld (#2996)

* Issue #2981 - Update testcases to handle date with 0 milliseconds field

Signed-off-by: Troy Biesterfeld <[email protected]>
  • Loading branch information
tbieste authored Nov 17, 2021
1 parent 6b5f17b commit 7e6616c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,17 @@ public void testGenerateLowerUpperBoundWithNullPrefixYearMonthDayHoursMinutesSec
assertEquals(upperBound.toString(), "2019-10-11T11:00:00.123456Z");
}

@Test
public void testGenerateLowerUpperBoundWithNullPrefixYearMonthDayHoursMinutesSecondsZeroNanos()
throws FHIRSearchException {
String v = "2019-10-11T11:00:00.000000000";
TemporalAccessor value = DateTimeHandler.parse(v);
Instant lowerBound = DateTimeHandler.generateLowerBound(null, value, v);
Instant upperBound = DateTimeHandler.generateUpperBound(null, value, v);
assertEquals(lowerBound.toString(), "2019-10-11T11:00:00Z");
assertEquals(upperBound.toString(), "2019-10-11T11:00:00Z");
}

@Test
public void testGenerateLowerUpperBoundWithNonNullPrefix() throws FHIRSearchException {
String v = "2019";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.math.BigDecimal;
import java.time.Instant;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -308,6 +309,13 @@ public void testValidChainWithDateSearchParameter() throws Exception {
FHIRSearchContext searchContext;
Class<ClinicalImpression> resourceType = ClinicalImpression.class;
Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS);
// If the Instant has a millseconds value of exactly 0, then the toString() will not include milliseconds in the search query,
// which will cause the lower/upper bound to include all milliseconds within the second, instead of just the exact millisecond.
// For the purpose of this testcase, just ensure that there is a non-0 value for milliseconds, so the toString() includes
// milliseconds in the search query.
if (now.get(ChronoField.MILLI_OF_SECOND) == 0) {
now = now.plusMillis(1);
}
String queryString = "&investigation:RiskAssessment.date=" + now.toString();

queryParameters.put("investigation:RiskAssessment.date", Collections.singletonList(now.toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.math.BigDecimal;
import java.time.Instant;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -587,6 +588,13 @@ public void testValidReverseChainWithDateSearchParameter() throws Exception {
FHIRSearchContext searchContext;
Class<Patient> resourceType = Patient.class;
Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS);
// If the Instant has a millseconds value of exactly 0, then the toString() will not include milliseconds in the search query,
// which will cause the lower/upper bound to include all milliseconds within the second, instead of just the exact millisecond.
// For the purpose of this testcase, just ensure that there is a non-0 value for milliseconds, so the toString() includes
// milliseconds in the search query.
if (now.get(ChronoField.MILLI_OF_SECOND) == 0) {
now = now.plusMillis(1);
}
String queryString = "&_has:RiskAssessment:subject:date=" + now.toString();

queryParameters.put("_has:RiskAssessment:subject:date", Collections.singletonList(now.toString()));
Expand Down

0 comments on commit 7e6616c

Please sign in to comment.