Skip to content

Commit 2ecf0a4

Browse files
committed
Update Issue 255
- Add missing tests in testng.xml - Remove references to Timezone - Update DateTimeHandler - Update logging properties Signed-off-by: Paul Bastide <pbastide@us.ibm.com>
1 parent 0ae0482 commit 2ecf0a4

10 files changed

Lines changed: 48 additions & 42 deletions

File tree

fhir-persistence-jdbc/src/main/java/com/ibm/fhir/persistence/jdbc/dao/impl/FHIRDbDAOImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.sql.SQLException;
1414
import java.util.ArrayList;
1515
import java.util.Arrays;
16-
import java.util.Calendar;
1716
import java.util.List;
1817
import java.util.Properties;
1918
import java.util.logging.Level;

fhir-persistence-jdbc/src/main/java/com/ibm/fhir/persistence/jdbc/impl/FHIRPersistenceJDBCImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.sql.SQLException;
2222
import java.sql.Timestamp;
2323
import java.time.ZoneOffset;
24+
import java.time.temporal.TemporalAccessor;
2425
import java.util.ArrayList;
2526
import java.util.Collection;
2627
import java.util.Collections;
@@ -100,13 +101,13 @@
100101
import com.ibm.fhir.persistence.jdbc.util.JDBCParameterBuildingVisitor;
101102
import com.ibm.fhir.persistence.jdbc.util.JDBCQueryBuilder;
102103
import com.ibm.fhir.persistence.jdbc.util.ParameterNamesCache;
103-
import com.ibm.fhir.persistence.jdbc.util.QueryBuilderUtil;
104104
import com.ibm.fhir.persistence.jdbc.util.ResourceTypesCache;
105105
import com.ibm.fhir.persistence.jdbc.util.SqlQueryData;
106106
import com.ibm.fhir.persistence.util.FHIRPersistenceUtil;
107107
import com.ibm.fhir.search.SearchConstants;
108108
import com.ibm.fhir.search.SummaryValueSet;
109109
import com.ibm.fhir.search.context.FHIRSearchContext;
110+
import com.ibm.fhir.search.date.DateTimeHandler;
110111
import com.ibm.fhir.search.parameters.QueryParameter;
111112
import com.ibm.fhir.search.util.SearchUtil;
112113

@@ -1233,7 +1234,9 @@ private ExtractedParameterValue processPrimitiveValue(FHIRPathSystemValue system
12331234
parameter = p;
12341235
} else if (systemValue.isTemporalValue()) {
12351236
DateParmVal p = new DateParmVal();
1236-
p.setValueDate(Timestamp.from(QueryBuilderUtil.getInstantFromPartial(systemValue.asTemporalValue().temporal())));
1237+
TemporalAccessor v = systemValue.asTemporalValue().temporal();
1238+
java.time.Instant inst = DateTimeHandler.generateValue(v);
1239+
p.setValueDate(DateTimeHandler.generateTimestamp(inst));
12371240
parameter = p;
12381241
} else if (systemValue.isStringValue()) {
12391242
StringParmVal p = new StringParmVal();

fhir-persistence-jdbc/src/main/java/com/ibm/fhir/persistence/jdbc/util/JDBCParameterBuildingVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ private void setDateValues(DateParmVal p, DateTime dateTime) {
667667
if (dateTime.getValue() != null) {
668668
java.time.Instant inst = DateTimeHandler.generateValue(dateTime.getValue());
669669
p.setValueDate(DateTimeHandler.generateTimestamp(inst));
670-
}
670+
}
671671
}
672672

673673
private IllegalArgumentException invalidComboException(SearchParamType paramType, Element value) {

fhir-persistence-jdbc/src/main/java/com/ibm/fhir/persistence/jdbc/util/type/DateParmBehaviorUtil.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,24 +132,24 @@ public void buildPredicates(StringBuilder whereClauseSegment, List<Timestamp> bi
132132
// LT - Less Than
133133
// the range below the search value intersects (i.e. overlaps) with the range of the target value
134134
buildCommonClause(whereClauseSegment, bindVariables, tableAlias, DATE_VALUE, DATE_END,
135-
LT, value, value);
135+
LT, value, value);
136136
break;
137137
case AP:
138138
// AP - Approximate - Relative
139139
// -10% of the Lower Bound
140140
// +10% of the Upper Bound
141-
buildApproxRangeClause(whereClauseSegment, bindVariables, tableAlias, lowerBound, upperBound, value);
141+
buildApproxRangeClause(whereClauseSegment, bindVariables, tableAlias, lowerBound, upperBound);
142142
break;
143143
case NE:
144144
// NE: Upper and Lower Bounds - Range Based Search
145145
// the range of the search value does not fully contain the range of the target value
146-
buildNotEqualsRangeClause(whereClauseSegment, bindVariables, tableAlias, value, upperBound, value);
146+
buildNotEqualsRangeClause(whereClauseSegment, bindVariables, tableAlias, value, upperBound);
147147
break;
148148
case EQ:
149149
default:
150150
// EQ: Upper and Lower Bounds - Range Based Search
151151
// the range of the search value fully contains the range of the target value
152-
buildEqualsRangeClause(whereClauseSegment, bindVariables, tableAlias, value, upperBound, value);
152+
buildEqualsRangeClause(whereClauseSegment, bindVariables, tableAlias, value, upperBound);
153153
break;
154154
}
155155
}
@@ -189,11 +189,10 @@ public void buildCommonClause(StringBuilder whereClauseSegment, List<Timestamp>
189189
* @param tableAlias
190190
* @param lowerBound
191191
* @param upperBound
192-
* @param value
193192
*/
194193
public void buildEqualsRangeClause(StringBuilder whereClauseSegment, List<Timestamp> bindVariables,
195-
String tableAlias,
196-
Instant lowerBound, Instant upperBound, Instant value) {
194+
String tableAlias, Instant lowerBound, Instant upperBound) {
195+
// buildEqualsRangeClause(whereClauseSegment, bindVariables, tableAlias, value, upperBound, value);
197196
// @formatter:off
198197
whereClauseSegment
199198
.append(LEFT_PAREN).append(LEFT_PAREN)
@@ -223,10 +222,9 @@ public void buildEqualsRangeClause(StringBuilder whereClauseSegment, List<Timest
223222
* @param tableAlias
224223
* @param lowerBound
225224
* @param upperBound
226-
* @param value
227225
*/
228226
public void buildApproxRangeClause(StringBuilder whereClauseSegment, List<Timestamp> bindVariables,
229-
String tableAlias, Instant lowerBound, Instant upperBound, Instant value) {
227+
String tableAlias, Instant lowerBound, Instant upperBound) {
230228
// @formatter:off
231229
whereClauseSegment
232230
.append(LEFT_PAREN)
@@ -258,10 +256,9 @@ public void buildApproxRangeClause(StringBuilder whereClauseSegment, List<Timest
258256
* @param tableAlias
259257
* @param lowerBound
260258
* @param upperBound
261-
* @param value
262259
*/
263260
public void buildNotEqualsRangeClause(StringBuilder whereClauseSegment, List<Timestamp> bindVariables,
264-
String tableAlias, Instant lowerBound, Instant upperBound, Instant value) {
261+
String tableAlias, Instant lowerBound, Instant upperBound) {
265262
// @formatter:off
266263
whereClauseSegment
267264
.append(LEFT_PAREN)

fhir-persistence-jdbc/src/test/java/testng.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
<class name="com.ibm.fhir.persistence.jdbc.test.util.UriModifierUtilTest" />
99
<class name="com.ibm.fhir.persistence.jdbc.test.util.NumberParmBehaviorUtilTest" />
1010
<class name="com.ibm.fhir.persistence.jdbc.test.util.QuantityParmBehaviorUtilTest" />
11+
<class name="com.ibm.fhir.persistence.jdbc.test.util.DateParmBehaviorUtilTest" />
12+
<class name="com.ibm.fhir.persistence.jdbc.test.util.LastUpdatedParmBehaviorUtilTest" />
13+
<class name="com.ibm.fhir.persistence.jdbc.test.util.LocationParmBehaviorUtilTest" />
1114
</classes>
1215
</test>
1316
<test name="JDBCSpecTest">

fhir-persistence/src/test/java/com/ibm/fhir/persistence/search/test/AbstractPLSearchTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66

77
package com.ibm.fhir.persistence.search.test;
88

9+
import static com.ibm.fhir.model.test.TestUtil.isResourceInResponse;
910
import static com.ibm.fhir.model.type.String.string;
1011
import static org.testng.AssertJUnit.assertEquals;
1112
import static org.testng.AssertJUnit.assertFalse;
1213
import static org.testng.AssertJUnit.assertNotNull;
1314
import static org.testng.AssertJUnit.assertTrue;
14-
import static com.ibm.fhir.model.test.TestUtil.isResourceInResponse;
1515

1616
import java.util.Collections;
1717
import java.util.HashMap;
1818
import java.util.List;
1919
import java.util.Map;
20-
import java.util.TimeZone;
2120

2221
import org.testng.annotations.AfterClass;
2322
import org.testng.annotations.BeforeClass;
@@ -48,8 +47,6 @@
4847
* https://github.com/cbeust/testng-eclipse/issues/435
4948
*/
5049
public abstract class AbstractPLSearchTest extends AbstractPersistenceTest {
51-
private static final String DEFAULT_ZONE = "UTC";
52-
5350
protected Basic savedResource;
5451
protected Composition composition;
5552

@@ -67,7 +64,6 @@ public abstract class AbstractPLSearchTest extends AbstractPersistenceTest {
6764

6865
@BeforeClass
6966
public void createResources() throws Exception {
70-
TimeZone.setDefault(TimeZone.getTimeZone(DEFAULT_ZONE));
7167
setTenant();
7268
saveBasicResource(getBasicResource());
7369
createCompositionReferencingSavedResource();

fhir-persistence/src/test/java/com/ibm/fhir/persistence/search/test/AbstractSearchDateTest.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ protected void setTenant() throws Exception {
3333
FHIRRequestContext.get().setTenantId("date");
3434
}
3535

36+
@Test
37+
public void testSearchDate_date_UTC() throws Exception {
38+
// "date" is 2018-10-29
39+
// The following tests use 2018-10-28
40+
assertSearchDoesntReturnSavedResource("date", "2018-10-28T23:59:59.999999Z");
41+
assertSearchReturnsSavedResource("date", "ne2018-10-28T23:59:59.999999Z");
42+
assertSearchDoesntReturnSavedResource("date", "lt2018-10-28T23:59:59.999999Z");
43+
assertSearchReturnsSavedResource("date", "gt2018-10-28T23:59:59.999999Z");
44+
assertSearchDoesntReturnSavedResource("date", "le2018-10-28T23:59:59.999999Z");
45+
assertSearchReturnsSavedResource("date", "ge2018-10-28T23:59:59.999999Z");
46+
assertSearchReturnsSavedResource("date", "sa2018-10-28T23:59:59.999999Z");
47+
assertSearchDoesntReturnSavedResource("date", "eb2018-10-28T23:59:59.999999Z");
48+
assertSearchReturnsSavedResource("date", "ap2018-10-28T23:59:59.999999Z");
49+
}
50+
3651
@Test
3752
public void testSearchDate_date() throws Exception {
3853
// "date" is 2018-10-29
@@ -73,17 +88,6 @@ public void testSearchDate_date() throws Exception {
7388
assertSearchDoesntReturnSavedResource("date", "eb2018-10-28");
7489
assertSearchReturnsSavedResource("date", "ap2018-10-28");
7590

76-
assertSearchReturnsSavedResource("date", "2018-10-28T23:59:59.999999Z");
77-
assertSearchDoesntReturnSavedResource("date", "ne2018-10-28T23:59:59.999999Z");
78-
assertSearchDoesntReturnSavedResource("date", "lt2018-10-28T23:59:59.999999Z");
79-
assertSearchDoesntReturnSavedResource("date", "gt2018-10-28T23:59:59.999999Z");
80-
assertSearchReturnsSavedResource("date", "gt2018-10-27T23:59:59.999999Z");
81-
assertSearchReturnsSavedResource("date", "le2018-10-28T23:59:59.999999Z");
82-
assertSearchReturnsSavedResource("date", "ge2018-10-28T23:59:59.999999Z");
83-
assertSearchDoesntReturnSavedResource("date", "sa2018-10-28T23:59:59.999999Z");
84-
assertSearchDoesntReturnSavedResource("date", "eb2018-10-28T23:59:59.999999Z");
85-
assertSearchReturnsSavedResource("date", "ap2018-10-28T23:59:59.999999Z");
86-
8791
assertSearchDoesntReturnSavedResource("date", "2018-10-30");
8892
assertSearchReturnsSavedResource("date", "ne2018-10-30");
8993
assertSearchReturnsSavedResource("date", "lt2018-10-30");
@@ -900,7 +904,7 @@ public void testSearchDate_Period_NoStart() throws Exception {
900904
assertSearchReturnsSavedResource("Period-noStart", "ne2018-10-29T17:18:00-04:00");
901905
assertSearchDoesntReturnSavedResource("Period-noStart", "lt2018-10-29T17:18:00-04:00");
902906
assertSearchReturnsSavedResource("Period-noStart", "lt2018-10-29T17:18:01-04:00");
903-
907+
904908
assertSearchDoesntReturnSavedResource("Period-noStart", "gt2018-10-29T17:18:00-04:00");
905909
assertSearchReturnsSavedResource("Period-noStart", "le2018-10-29T17:18:00-04:00");
906910
assertSearchDoesntReturnSavedResource("Period-noStart", "ge2018-10-29T17:18:00-04:00");

fhir-persistence/src/test/java/com/ibm/fhir/persistence/search/test/AbstractWholeSystemSearchTest.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,15 @@ public void testSearchAllUsingIdAndLastUpdated() throws Exception {
119119
* generates the output into a resource.
120120
*/
121121
public static void generateOutput(Resource resource) {
122-
123122
try (StringWriter writer = new StringWriter();) {
124123
FHIRGenerator.generator(Format.JSON, true).generate(resource, System.out);
125124
System.out.println(writer.toString());
126125
} catch (FHIRGeneratorException e) {
127-
128-
e.printStackTrace();
129-
fail("unable to generate the fhir resource to JSON");
130-
126+
fail("unable to generate the fhir resource to JSON", e);
131127
} catch (IOException e1) {
132128
e1.printStackTrace();
133-
fail("unable to generate the fhir resource to JSON (io problem) ");
129+
fail("unable to generate the fhir resource to JSON (io problem) ", e1);
134130
}
135-
136131
}
137132

138133
@Test

fhir-persistence/src/test/resources/logging.unitTest.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
4949
############################################################
5050

5151
# Set this to FINE or higher to output the SQL statements and related debug info
52-
com.ibm.fhir.persistence.level = FINE
52+
com.ibm.fhir.persistence.level = INFO
5353
com.ibm.fhir.search.level = INFO

fhir-search/src/main/java/com/ibm/fhir/search/date/DateTimeHandler.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ public static Instant generateValue(TemporalAccessor value) {
172172
return response;
173173
}
174174

175+
/**
176+
* convience method to generate upper bound.
177+
* @param value
178+
* @return
179+
*/
180+
public static Instant generateUpperBound(TemporalAccessor value) {
181+
return generateUpperBound(null, value, value.toString());
182+
}
183+
175184
/**
176185
* generate upper bounds
177186
*
@@ -231,7 +240,7 @@ public static Instant generateUpperBound(Prefix prefix, TemporalAccessor value,
231240

232241
} else if (value instanceof ZonedDateTime) {
233242
ZonedDateTime zdt = (ZonedDateTime) value;
234-
long precision = originalString.chars().filter(ch -> ch == ':' || ch == '.' || ch == 'Z' ).count();
243+
long precision = originalString.chars().filter(ch -> ch == ':' || ch == '.' || ch == 'Z').count();
235244
// Shift by 1 as the Zone includes a semicolon.
236245
if (precision == 1) {
237246
// HH - First Colon (Zone is colon)
@@ -245,7 +254,7 @@ public static Instant generateUpperBound(Prefix prefix, TemporalAccessor value,
245254
// HH:MM:SS - Third Colon
246255
// 2019-12-11T00:00:00+05:00
247256
zdt = zdt.truncatedTo(ChronoUnit.SECONDS).plus(1, ChronoUnit.SECONDS).minus(TICK, ChronoUnit.NANOS);
248-
} else if (precision == 4) {
257+
} else if (precision == 4) {
249258
// Nanoseconds
250259
// 2019-12-11T00:00:00.000000+05:00
251260
zdt = zdt.truncatedTo(ChronoUnit.MILLIS).plus(1, ChronoUnit.MILLIS).minus(TICK, ChronoUnit.NANOS);

0 commit comments

Comments
 (0)