Skip to content

Commit e19202a

Browse files
authored
Update FHIRPath implementation to accommodate new grammar version (#411)
* Issue #329 - turn down logging Signed-off-by: John T.E. Timm <johntimm@us.ibm.com> * Issue #355 - Fixed semantic errors in FHIRPathType.isAssignableFrom Signed-off-by: John T.E. Timm <johntimm@us.ibm.com> * Issue #355 - Added unit tests, fixed tabs/spaces issue. Signed-off-by: John T.E. Timm <johntimm@us.ibm.com> * Issue #355 - Fixed indentation Signed-off-by: John T.E. Timm <johntimm@us.ibm.com> * Issue #355 - updated per PR feedback Signed-off-by: John T.E. Timm <johntimm@us.ibm.com> * Issue #389 - upgrade FHIRPath grammar version Signed-off-by: John T.E. Timm <johntimm@us.ibm.com> * Issue #389 - refactor quantity processing Signed-off-by: John T.E. Timm <johntimm@us.ibm.com> * Issue #389 - Updates per PR feedback Signed-off-by: John T.E. Timm <johntimm@us.ibm.com>
1 parent 9304877 commit e19202a

60 files changed

Lines changed: 3453 additions & 2657 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

fhir-model/FHIRPath.g4

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
grammar FHIRPath;
22

33
// Grammar rules
4+
// [FHIRPath](http://hl7.org/fhirpath/N1) Normative Release
45

56
//prog: line (line)*;
67
//line: ID ( '(' expr ')') ':' expr '\r'? '\n';
@@ -35,13 +36,14 @@ literal
3536
| ('true' | 'false') #booleanLiteral
3637
| STRING #stringLiteral
3738
| NUMBER #numberLiteral
39+
| DATE #dateLiteral
3840
| DATETIME #dateTimeLiteral
3941
| TIME #timeLiteral
4042
| quantity #quantityLiteral
4143
;
4244

4345
externalConstant
44-
: '%' identifier
46+
: '%' ( identifier | STRING )
4547
;
4648

4749
invocation // Terms that can be used after the function/member invocation '.'
@@ -90,6 +92,8 @@ identifier
9092
: IDENTIFIER
9193
| DELIMITEDIDENTIFIER
9294
| 'as'
95+
| 'contains'
96+
| 'in'
9397
| 'is'
9498
;
9599

@@ -98,40 +102,34 @@ identifier
98102
Lexical rules
99103
*****************************************************************/
100104

101-
// Not sure why, but with these as lexical rules, when the grammar is imported into CQL, they are not correctly recognized
102-
// Moving the same rules into the literal production rule above corrects the issue
103-
//EMPTY
104-
// : '{' '}'
105-
// ; // To create an empty array (and avoid a NULL literal)
105+
/*
106+
NOTE: The goal of these rules in the grammar is to provide a date
107+
token to the parser. As such it is not attempting to validate that
108+
the date is a correct date, that task is for the parser or interpreter.
109+
*/
106110

107-
//BOOL
108-
// : 'true'
109-
// | 'false'
110-
// ;
111+
DATE
112+
: '@' DATEFORMAT
113+
;
111114

112115
DATETIME
113-
: '@'
114-
[0-9][0-9][0-9][0-9] // year
115-
(
116-
'-'[0-9][0-9] // month
117-
(
118-
'-'[0-9][0-9] // day
119-
(
120-
'T' TIMEFORMAT
121-
)?
122-
)?
123-
)?
124-
'Z'? // UTC specifier
116+
: '@' DATEFORMAT 'T' (TIMEFORMAT TIMEZONEOFFSETFORMAT?)?
125117
;
126118

127119
TIME
128120
: '@' 'T' TIMEFORMAT
129121
;
130122

123+
fragment DATEFORMAT
124+
: [0-9][0-9][0-9][0-9] ('-'[0-9][0-9] ('-'[0-9][0-9])?)?
125+
;
126+
131127
fragment TIMEFORMAT
132-
:
133-
[0-9][0-9] (':'[0-9][0-9] (':'[0-9][0-9] ('.'[0-9]+)?)?)?
134-
('Z' | ('+' | '-') [0-9][0-9]':'[0-9][0-9])? // timezone
128+
: [0-9][0-9] (':'[0-9][0-9] (':'[0-9][0-9] ('.'[0-9]+)?)?)?
129+
;
130+
131+
fragment TIMEZONEOFFSETFORMAT
132+
: ('Z' | ('+' | '-') [0-9][0-9]':'[0-9][0-9])
135133
;
136134

137135
IDENTIFIER

fhir-model/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<dependency>
1919
<groupId>org.antlr</groupId>
2020
<artifactId>antlr4-runtime</artifactId>
21-
<version>4.5.3</version>
21+
<version>4.7.2</version>
2222
</dependency>
2323
<dependency>
2424
<groupId>net.jcip</groupId>
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
token literal names:
2+
null
3+
'.'
4+
'['
5+
']'
6+
'+'
7+
'-'
8+
'*'
9+
'/'
10+
'div'
11+
'mod'
12+
'&'
13+
'is'
14+
'as'
15+
'|'
16+
'<='
17+
'<'
18+
'>'
19+
'>='
20+
'='
21+
'~'
22+
'!='
23+
'!~'
24+
'in'
25+
'contains'
26+
'and'
27+
'or'
28+
'xor'
29+
'implies'
30+
'('
31+
')'
32+
'{'
33+
'}'
34+
'true'
35+
'false'
36+
'%'
37+
'$this'
38+
'$index'
39+
'$total'
40+
','
41+
'year'
42+
'month'
43+
'week'
44+
'day'
45+
'hour'
46+
'minute'
47+
'second'
48+
'millisecond'
49+
'years'
50+
'months'
51+
'weeks'
52+
'days'
53+
'hours'
54+
'minutes'
55+
'seconds'
56+
'milliseconds'
57+
null
58+
null
59+
null
60+
null
61+
null
62+
null
63+
null
64+
null
65+
null
66+
null
67+
68+
token symbolic names:
69+
null
70+
null
71+
null
72+
null
73+
null
74+
null
75+
null
76+
null
77+
null
78+
null
79+
null
80+
null
81+
null
82+
null
83+
null
84+
null
85+
null
86+
null
87+
null
88+
null
89+
null
90+
null
91+
null
92+
null
93+
null
94+
null
95+
null
96+
null
97+
null
98+
null
99+
null
100+
null
101+
null
102+
null
103+
null
104+
null
105+
null
106+
null
107+
null
108+
null
109+
null
110+
null
111+
null
112+
null
113+
null
114+
null
115+
null
116+
null
117+
null
118+
null
119+
null
120+
null
121+
null
122+
null
123+
null
124+
DATE
125+
DATETIME
126+
TIME
127+
IDENTIFIER
128+
DELIMITEDIDENTIFIER
129+
STRING
130+
NUMBER
131+
WS
132+
COMMENT
133+
LINE_COMMENT
134+
135+
rule names:
136+
expression
137+
term
138+
literal
139+
externalConstant
140+
invocation
141+
function
142+
paramList
143+
quantity
144+
unit
145+
dateTimePrecision
146+
pluralDateTimePrecision
147+
typeSpecifier
148+
qualifiedIdentifier
149+
identifier
150+
151+
152+
atn:
153+
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 66, 152, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 3, 2, 3, 2, 3, 2, 3, 2, 5, 2, 35, 10, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 7, 2, 75, 10, 2, 12, 2, 14, 2, 78, 11, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 87, 10, 3, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 5, 4, 98, 10, 4, 3, 5, 3, 5, 3, 5, 5, 5, 103, 10, 5, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 5, 6, 110, 10, 6, 3, 7, 3, 7, 3, 7, 5, 7, 115, 10, 7, 3, 7, 3, 7, 3, 8, 3, 8, 3, 8, 7, 8, 122, 10, 8, 12, 8, 14, 8, 125, 11, 8, 3, 9, 3, 9, 5, 9, 129, 10, 9, 3, 10, 3, 10, 3, 10, 5, 10, 134, 10, 10, 3, 11, 3, 11, 3, 12, 3, 12, 3, 13, 3, 13, 3, 14, 3, 14, 3, 14, 7, 14, 145, 10, 14, 12, 14, 14, 14, 148, 11, 14, 3, 15, 3, 15, 3, 15, 2, 3, 2, 16, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 2, 14, 3, 2, 6, 7, 3, 2, 8, 11, 4, 2, 6, 7, 12, 12, 3, 2, 16, 19, 3, 2, 20, 23, 3, 2, 24, 25, 3, 2, 27, 28, 3, 2, 13, 14, 3, 2, 34, 35, 3, 2, 41, 48, 3, 2, 49, 56, 5, 2, 13, 14, 24, 25, 60, 61, 2, 171, 2, 34, 3, 2, 2, 2, 4, 86, 3, 2, 2, 2, 6, 97, 3, 2, 2, 2, 8, 99, 3, 2, 2, 2, 10, 109, 3, 2, 2, 2, 12, 111, 3, 2, 2, 2, 14, 118, 3, 2, 2, 2, 16, 126, 3, 2, 2, 2, 18, 133, 3, 2, 2, 2, 20, 135, 3, 2, 2, 2, 22, 137, 3, 2, 2, 2, 24, 139, 3, 2, 2, 2, 26, 141, 3, 2, 2, 2, 28, 149, 3, 2, 2, 2, 30, 31, 8, 2, 1, 2, 31, 35, 5, 4, 3, 2, 32, 33, 9, 2, 2, 2, 33, 35, 5, 2, 2, 13, 34, 30, 3, 2, 2, 2, 34, 32, 3, 2, 2, 2, 35, 76, 3, 2, 2, 2, 36, 37, 12, 12, 2, 2, 37, 38, 9, 3, 2, 2, 38, 75, 5, 2, 2, 13, 39, 40, 12, 11, 2, 2, 40, 41, 9, 4, 2, 2, 41, 75, 5, 2, 2, 12, 42, 43, 12, 9, 2, 2, 43, 44, 7, 15, 2, 2, 44, 75, 5, 2, 2, 10, 45, 46, 12, 8, 2, 2, 46, 47, 9, 5, 2, 2, 47, 75, 5, 2, 2, 9, 48, 49, 12, 7, 2, 2, 49, 50, 9, 6, 2, 2, 50, 75, 5, 2, 2, 8, 51, 52, 12, 6, 2, 2, 52, 53, 9, 7, 2, 2, 53, 75, 5, 2, 2, 7, 54, 55, 12, 5, 2, 2, 55, 56, 7, 26, 2, 2, 56, 75, 5, 2, 2, 6, 57, 58, 12, 4, 2, 2, 58, 59, 9, 8, 2, 2, 59, 75, 5, 2, 2, 5, 60, 61, 12, 3, 2, 2, 61, 62, 7, 29, 2, 2, 62, 75, 5, 2, 2, 4, 63, 64, 12, 15, 2, 2, 64, 65, 7, 3, 2, 2, 65, 75, 5, 10, 6, 2, 66, 67, 12, 14, 2, 2, 67, 68, 7, 4, 2, 2, 68, 69, 5, 2, 2, 2, 69, 70, 7, 5, 2, 2, 70, 75, 3, 2, 2, 2, 71, 72, 12, 10, 2, 2, 72, 73, 9, 9, 2, 2, 73, 75, 5, 24, 13, 2, 74, 36, 3, 2, 2, 2, 74, 39, 3, 2, 2, 2, 74, 42, 3, 2, 2, 2, 74, 45, 3, 2, 2, 2, 74, 48, 3, 2, 2, 2, 74, 51, 3, 2, 2, 2, 74, 54, 3, 2, 2, 2, 74, 57, 3, 2, 2, 2, 74, 60, 3, 2, 2, 2, 74, 63, 3, 2, 2, 2, 74, 66, 3, 2, 2, 2, 74, 71, 3, 2, 2, 2, 75, 78, 3, 2, 2, 2, 76, 74, 3, 2, 2, 2, 76, 77, 3, 2, 2, 2, 77, 3, 3, 2, 2, 2, 78, 76, 3, 2, 2, 2, 79, 87, 5, 10, 6, 2, 80, 87, 5, 6, 4, 2, 81, 87, 5, 8, 5, 2, 82, 83, 7, 30, 2, 2, 83, 84, 5, 2, 2, 2, 84, 85, 7, 31, 2, 2, 85, 87, 3, 2, 2, 2, 86, 79, 3, 2, 2, 2, 86, 80, 3, 2, 2, 2, 86, 81, 3, 2, 2, 2, 86, 82, 3, 2, 2, 2, 87, 5, 3, 2, 2, 2, 88, 89, 7, 32, 2, 2, 89, 98, 7, 33, 2, 2, 90, 98, 9, 10, 2, 2, 91, 98, 7, 62, 2, 2, 92, 98, 7, 63, 2, 2, 93, 98, 7, 57, 2, 2, 94, 98, 7, 58, 2, 2, 95, 98, 7, 59, 2, 2, 96, 98, 5, 16, 9, 2, 97, 88, 3, 2, 2, 2, 97, 90, 3, 2, 2, 2, 97, 91, 3, 2, 2, 2, 97, 92, 3, 2, 2, 2, 97, 93, 3, 2, 2, 2, 97, 94, 3, 2, 2, 2, 97, 95, 3, 2, 2, 2, 97, 96, 3, 2, 2, 2, 98, 7, 3, 2, 2, 2, 99, 102, 7, 36, 2, 2, 100, 103, 5, 28, 15, 2, 101, 103, 7, 62, 2, 2, 102, 100, 3, 2, 2, 2, 102, 101, 3, 2, 2, 2, 103, 9, 3, 2, 2, 2, 104, 110, 5, 28, 15, 2, 105, 110, 5, 12, 7, 2, 106, 110, 7, 37, 2, 2, 107, 110, 7, 38, 2, 2, 108, 110, 7, 39, 2, 2, 109, 104, 3, 2, 2, 2, 109, 105, 3, 2, 2, 2, 109, 106, 3, 2, 2, 2, 109, 107, 3, 2, 2, 2, 109, 108, 3, 2, 2, 2, 110, 11, 3, 2, 2, 2, 111, 112, 5, 28, 15, 2, 112, 114, 7, 30, 2, 2, 113, 115, 5, 14, 8, 2, 114, 113, 3, 2, 2, 2, 114, 115, 3, 2, 2, 2, 115, 116, 3, 2, 2, 2, 116, 117, 7, 31, 2, 2, 117, 13, 3, 2, 2, 2, 118, 123, 5, 2, 2, 2, 119, 120, 7, 40, 2, 2, 120, 122, 5, 2, 2, 2, 121, 119, 3, 2, 2, 2, 122, 125, 3, 2, 2, 2, 123, 121, 3, 2, 2, 2, 123, 124, 3, 2, 2, 2, 124, 15, 3, 2, 2, 2, 125, 123, 3, 2, 2, 2, 126, 128, 7, 63, 2, 2, 127, 129, 5, 18, 10, 2, 128, 127, 3, 2, 2, 2, 128, 129, 3, 2, 2, 2, 129, 17, 3, 2, 2, 2, 130, 134, 5, 20, 11, 2, 131, 134, 5, 22, 12, 2, 132, 134, 7, 62, 2, 2, 133, 130, 3, 2, 2, 2, 133, 131, 3, 2, 2, 2, 133, 132, 3, 2, 2, 2, 134, 19, 3, 2, 2, 2, 135, 136, 9, 11, 2, 2, 136, 21, 3, 2, 2, 2, 137, 138, 9, 12, 2, 2, 138, 23, 3, 2, 2, 2, 139, 140, 5, 26, 14, 2, 140, 25, 3, 2, 2, 2, 141, 146, 5, 28, 15, 2, 142, 143, 7, 3, 2, 2, 143, 145, 5, 28, 15, 2, 144, 142, 3, 2, 2, 2, 145, 148, 3, 2, 2, 2, 146, 144, 3, 2, 2, 2, 146, 147, 3, 2, 2, 2, 147, 27, 3, 2, 2, 2, 148, 146, 3, 2, 2, 2, 149, 150, 9, 13, 2, 2, 150, 29, 3, 2, 2, 2, 14, 34, 74, 76, 86, 97, 102, 109, 114, 123, 128, 133, 146]

fhir-model/src/main/java/com/ibm/fhir/model/path/FHIRPath.tokens

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,16 @@ T__50=51
5252
T__51=52
5353
T__52=53
5454
T__53=54
55-
DATETIME=55
56-
TIME=56
57-
IDENTIFIER=57
58-
DELIMITEDIDENTIFIER=58
59-
STRING=59
60-
NUMBER=60
61-
WS=61
62-
COMMENT=62
63-
LINE_COMMENT=63
55+
DATE=55
56+
DATETIME=56
57+
TIME=57
58+
IDENTIFIER=58
59+
DELIMITEDIDENTIFIER=59
60+
STRING=60
61+
NUMBER=61
62+
WS=62
63+
COMMENT=63
64+
LINE_COMMENT=64
6465
'.'=1
6566
'['=2
6667
']'=3

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public abstract class FHIRPathAbstractNode implements FHIRPathNode {
1717
protected final String name;
1818
protected final String path;
1919
protected final FHIRPathType type;
20-
protected final FHIRPathPrimitiveValue value;
20+
protected final FHIRPathSystemValue value;
2121
protected final Collection<FHIRPathNode> children;
2222

2323
protected FHIRPathAbstractNode(Builder builder) {
@@ -49,7 +49,7 @@ public boolean hasValue() {
4949
}
5050

5151
@Override
52-
public FHIRPathPrimitiveValue getValue() {
52+
public FHIRPathSystemValue getValue() {
5353
return value;
5454
}
5555

@@ -87,7 +87,7 @@ public static abstract class Builder implements FHIRPathNode.Builder {
8787
// optional
8888
protected String name;
8989
protected String path;
90-
protected FHIRPathPrimitiveValue value;
90+
protected FHIRPathSystemValue value;
9191
protected Collection<FHIRPathNode> children = new ArrayList<>();
9292

9393
protected Builder(FHIRPathType type) {
@@ -108,7 +108,7 @@ public Builder path(String path) {
108108
}
109109

110110
@Override
111-
public Builder value(FHIRPathPrimitiveValue value) {
111+
public Builder value(FHIRPathSystemValue value) {
112112
children.remove(this.value);
113113
this.value = value;
114114
children.add(this.value);

0 commit comments

Comments
 (0)