Skip to content

Commit 2243ded

Browse files
Merge pull request #431 from IBM/master
sync with master
2 parents 346742a + 31a0125 commit 2243ded

5 files changed

Lines changed: 58 additions & 57 deletions

File tree

fhir-model/src/main/java/com/ibm/fhir/model/path/FHIRPathDateTimeValue.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import static com.ibm.fhir.model.path.util.FHIRPathUtil.getTemporalAmount;
1212

1313
import java.time.LocalDate;
14+
import java.time.LocalDateTime;
1415
import java.time.Year;
1516
import java.time.YearMonth;
1617
import java.time.ZonedDateTime;
@@ -32,15 +33,26 @@ public class FHIRPathDateTimeValue extends FHIRPathAbstractNode implements FHIRP
3233
.appendPattern("-MM")
3334
.optionalStart()
3435
.appendPattern("-dd")
36+
.appendLiteral("T")
3537
.optionalStart()
36-
.appendPattern("'T'HH:mm:ss")
38+
.appendPattern("HH")
3739
.optionalStart()
38-
.appendFraction(ChronoField.MICRO_OF_SECOND, 0, 6, true)
40+
.appendPattern(":mm")
41+
.optionalStart()
42+
.appendPattern(":ss")
43+
.optionalStart()
44+
.appendFraction(ChronoField.MICRO_OF_SECOND, 0, 6, true)
45+
.optionalEnd()
46+
.optionalEnd()
47+
.optionalEnd()
48+
.optionalStart()
49+
.appendPattern("XXX")
3950
.optionalEnd()
40-
.appendPattern("XXX")
4151
.optionalEnd()
4252
.optionalEnd()
4353
.optionalEnd()
54+
.parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0)
55+
.parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0)
4456
.toFormatter();
4557

4658
private final TemporalAccessor dateTime;
@@ -71,7 +83,7 @@ public Temporal temporal() {
7183
}
7284

7385
public static FHIRPathDateTimeValue dateTimeValue(String dateTime) {
74-
return FHIRPathDateTimeValue.builder(DATE_TIME_PARSER_FORMATTER.parseBest(dateTime, ZonedDateTime::from, LocalDate::from, YearMonth::from, Year::from)).build();
86+
return FHIRPathDateTimeValue.builder(DATE_TIME_PARSER_FORMATTER.parseBest(dateTime, ZonedDateTime::from, LocalDateTime::from, LocalDate::from, YearMonth::from, Year::from)).build();
7587
}
7688

7789
public static FHIRPathDateTimeValue dateTimeValue(TemporalAccessor dateTime) {
@@ -171,6 +183,9 @@ private int compareTo(FHIRPathDateTimeValue value) {
171183
if (dateTime instanceof LocalDate || value.dateTime instanceof LocalDate) {
172184
return LocalDate.from(dateTime).compareTo(LocalDate.from(value.dateTime));
173185
}
186+
if (dateTime instanceof LocalDateTime || value.dateTime instanceof LocalDateTime) {
187+
return LocalDateTime.from(dateTime).compareTo(LocalDateTime.from(value.dateTime));
188+
}
174189
return ZonedDateTime.from(dateTime).compareTo(ZonedDateTime.from(value.dateTime));
175190
}
176191

fhir-model/src/main/java/com/ibm/fhir/model/path/FHIRPathNumberValue.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ default Number number() {
5252

5353
@Override
5454
default boolean isComparableTo(FHIRPathNode other) {
55-
return other instanceof FHIRPathQuantityValue ||
55+
return (other instanceof FHIRPathQuantityNode && ((FHIRPathQuantityNode) other).getQuantityValue() != null) ||
56+
other instanceof FHIRPathQuantityValue ||
5657
other.getValue() instanceof FHIRPathQuantityValue ||
5758
other instanceof FHIRPathNumberValue ||
5859
other.getValue() instanceof FHIRPathNumberValue;
@@ -63,6 +64,9 @@ default int compareTo(FHIRPathNode other) {
6364
if (!isComparableTo(other)) {
6465
throw new IllegalArgumentException();
6566
}
67+
if (other instanceof FHIRPathQuantityNode) {
68+
return decimal().compareTo(((FHIRPathQuantityNode) other).getQuantityValue());
69+
}
6670
if (other instanceof FHIRPathQuantityValue) {
6771
return decimal().compareTo(((FHIRPathQuantityValue) other).value());
6872
}

fhir-model/src/main/java/com/ibm/fhir/model/path/FHIRPathTimeValue.java

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@
1010
import static com.ibm.fhir.model.path.util.FHIRPathUtil.getTemporalAmount;
1111

1212
import java.time.LocalTime;
13-
import java.time.OffsetTime;
14-
import java.time.ZoneOffset;
1513
import java.time.format.DateTimeFormatter;
1614
import java.time.format.DateTimeFormatterBuilder;
1715
import java.time.temporal.ChronoField;
1816
import java.time.temporal.Temporal;
19-
import java.time.temporal.TemporalAccessor;
2017
import java.time.temporal.TemporalAmount;
2118
import java.util.Collection;
2219
import java.util.Objects;
@@ -25,16 +22,22 @@
2522

2623
public class FHIRPathTimeValue extends FHIRPathAbstractNode implements FHIRPathTemporalValue {
2724
private static final DateTimeFormatter TIME_PARSER_FORMATTER = new DateTimeFormatterBuilder()
28-
.appendPattern("'T'HH:mm:ss")
25+
.appendLiteral("T")
26+
.appendPattern("HH")
2927
.optionalStart()
30-
.appendFraction(ChronoField.MICRO_OF_SECOND, 0, 6, true)
31-
.optionalEnd()
32-
.optionalStart()
33-
.appendPattern("XXX")
28+
.appendPattern(":mm")
29+
.optionalStart()
30+
.appendPattern(":ss")
31+
.optionalStart()
32+
.appendFraction(ChronoField.MICRO_OF_SECOND, 0, 6, true)
33+
.optionalEnd()
34+
.optionalEnd()
3435
.optionalEnd()
36+
.parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0)
37+
.parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0)
3538
.toFormatter();
3639

37-
private final TemporalAccessor time;
40+
private final LocalTime time;
3841
private final Temporal temporal;
3942

4043
protected FHIRPathTimeValue(Builder builder) {
@@ -48,18 +51,7 @@ public boolean isTimeValue() {
4851
return true;
4952
}
5053

51-
public boolean hasTimeZone() {
52-
return getTimeZone() != null;
53-
}
54-
55-
public ZoneOffset getTimeZone() {
56-
if (time instanceof OffsetTime) {
57-
return ((OffsetTime) time).getOffset();
58-
}
59-
return null;
60-
}
61-
62-
public TemporalAccessor time() {
54+
public LocalTime time() {
6355
return time;
6456
}
6557

@@ -69,14 +61,14 @@ public Temporal temporal() {
6961
}
7062

7163
public static FHIRPathTimeValue timeValue(String time) {
72-
return FHIRPathTimeValue.builder(TIME_PARSER_FORMATTER.parseBest(time, OffsetTime::from, LocalTime::from)).build();
64+
return FHIRPathTimeValue.builder(LocalTime.parse(time, TIME_PARSER_FORMATTER)).build();
7365
}
7466

75-
private static FHIRPathTimeValue timeValue(TemporalAccessor time) {
67+
private static FHIRPathTimeValue timeValue(LocalTime time) {
7668
return FHIRPathTimeValue.builder(time).build();
7769
}
7870

79-
public static FHIRPathTimeValue timeValue(String name, TemporalAccessor time) {
71+
public static FHIRPathTimeValue timeValue(String name, LocalTime time) {
8072
return FHIRPathTimeValue.builder(time).name(name).build();
8173
}
8274

@@ -85,14 +77,14 @@ public Builder toBuilder() {
8577
return new Builder(type, time);
8678
}
8779

88-
public static Builder builder(TemporalAccessor time) {
80+
public static Builder builder(LocalTime time) {
8981
return new Builder(FHIRPathType.SYSTEM_TIME, time);
9082
}
9183

9284
public static class Builder extends FHIRPathAbstractNode.Builder {
93-
private final TemporalAccessor time;
85+
private final LocalTime time;
9486

95-
private Builder(FHIRPathType type, TemporalAccessor time) {
87+
private Builder(FHIRPathType type, LocalTime time) {
9688
super(type);
9789
this.time = time;
9890
}
@@ -131,29 +123,19 @@ public FHIRPathTimeValue build() {
131123
public FHIRPathTimeValue add(FHIRPathQuantityValue quantityValue) {
132124
Temporal temporal = getTemporal(time);
133125
TemporalAmount temporalAmount = getTemporalAmount(quantityValue);
134-
return timeValue(temporal.plus(temporalAmount));
126+
return timeValue(LocalTime.from(temporal.plus(temporalAmount)));
135127
}
136128

137129
public FHIRPathTimeValue subtract(FHIRPathQuantityValue quantityValue) {
138130
Temporal temporal = getTemporal(time);
139131
TemporalAmount temporalAmount = getTemporalAmount(quantityValue);
140-
return timeValue(temporal.minus(temporalAmount));
132+
return timeValue(LocalTime.from(temporal.minus(temporalAmount)));
141133
}
142134

143135
@Override
144136
public boolean isComparableTo(FHIRPathNode other) {
145-
if (other instanceof FHIRPathTimeValue) {
146-
return isComparableTo((FHIRPathTimeValue) other);
147-
}
148-
if (other.getValue() instanceof FHIRPathTimeValue) {
149-
return isComparableTo((FHIRPathTimeValue) other.getValue());
150-
}
151-
return false;
152-
}
153-
154-
private boolean isComparableTo(FHIRPathTimeValue timeValue) {
155-
return (time instanceof LocalTime && timeValue.time instanceof LocalTime) ||
156-
(time instanceof OffsetTime && timeValue.time instanceof OffsetTime);
137+
return other instanceof FHIRPathTimeValue ||
138+
other.getValue() instanceof FHIRPathTimeValue;
157139
}
158140

159141
@Override
@@ -162,10 +144,7 @@ public int compareTo(FHIRPathNode other) {
162144
throw new IllegalArgumentException();
163145
}
164146
FHIRPathTimeValue timeValue = (FHIRPathTimeValue) ((other instanceof FHIRPathTimeValue) ? other : other.getValue());
165-
if (time instanceof LocalTime) {
166-
return LocalTime.from(time).compareTo(LocalTime.from(timeValue.time));
167-
}
168-
return OffsetTime.from(time).compareTo(OffsetTime.from(timeValue.time));
147+
return time.compareTo(timeValue.time());
169148
}
170149

171150
@Override

fhir-model/src/main/java/com/ibm/fhir/model/path/evaluator/FHIRPathEvaluator.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -906,13 +906,11 @@ public Collection<FHIRPathNode> visitStringLiteral(FHIRPathParser.StringLiteralC
906906
@Override
907907
public Collection<FHIRPathNode> visitNumberLiteral(FHIRPathParser.NumberLiteralContext ctx) {
908908
debug(ctx);
909-
// TODO: needs alternative to using exception for control flow
910-
BigDecimal decimal = new BigDecimal(ctx.getText());
911-
try {
912-
Integer integer = decimal.intValueExact();
913-
return singleton(integerValue(integer));
914-
} catch (ArithmeticException e) {
915-
return singleton(decimalValue(decimal));
909+
String text = ctx.getText();
910+
if (text.contains(".")) {
911+
return singleton(decimalValue(new BigDecimal(text)));
912+
} else {
913+
return singleton(integerValue(Integer.parseInt(text)));
916914
}
917915
}
918916

fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/control/FhirResourceGroup.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ public void addLogicalResources(List<IDatabaseObject> group, String prefix) {
159159
.setTablespace(fhirTablespace)
160160
.addPrivileges(resourceTablePrivileges)
161161
.enableAccessControl(this.sessionVariable)
162+
// Add indexes to avoid dead lock issue of derby, and improve Db2 performance
163+
// Derby requires all columns used in where clause to be indexed, otherwise whole table lock will be
164+
// used instead of row lock, which can cause dead lock issue frequently during concurrent accesses.
165+
.addIndex(IDX + tableName + CURRENT_RESOURCE_ID, CURRENT_RESOURCE_ID)
166+
.addIndex(IDX + tableName + LOGICAL_ID, LOGICAL_ID)
162167
.build(model);
163168

164169
group.add(tbl);

0 commit comments

Comments
 (0)