Skip to content

Commit 4177960

Browse files
committed
update
1 parent f5cb64a commit 4177960

File tree

75 files changed

+87
-49
lines changed

Some content is hidden

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

75 files changed

+87
-49
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.cpcache
22
.nrepl-port
3+
tmp

Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
.PHONY: test
2+
3+
ANTLR_URL = https://storage.googleapis.com/aidbox-public/antlr-4.7.2-complete.jar
4+
ANTLR_PATH = $(shell echo "`pwd`/tmp/antlr.jar")
5+
ANTLR = java -Xmx500M -cp "${ANTLR_PATH}:$CLASSPATH" org.antlr.v4.Tool
6+
17
repl:
28
clj -A:test:nrepl -e "(-main)" -r
39

410
test:
511
clj -A:test:runner
12+
13+
gen-parser:
14+
test -f ${ANTLR_PATH} || curl ${ANTLR_URL} > ${ANTLR_PATH}
15+
cd parser && rm -rf *class *java && ${ANTLR} -visitor FHIRPath.g4 && env CLASSPATH="${ANTLR_PATH}:$CLASSPATH" javac *.java

README.md

+23-4

deps.edn

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
{:paths ["src" "parser" "parser/antlr-4.7.2-complete.jar" "test"]
2-
:deps {exoscale/clj-yaml {:mvn/version "0.5.6"}}
1+
{:paths ["src" "parser" "test"]
2+
:deps {clj-commons/clj-yaml {:mvn/version "0.7.0"}
3+
org.antlr/antlr4-runtime {:mvn/version "4.7.2"}}
34

45
:aliases
56
{:nrepl
@@ -8,8 +9,9 @@
89
{spyscope {:mvn/version "0.1.6"}
910
org.clojure/clojure {:mvn/version "1.10.0-RC4"}
1011
org.clojure/tools.nrepl {:mvn/version "0.2.13"}
11-
cider/cider-nrepl {:mvn/version "0.19.0-SNAPSHOT"}
12-
refactor-nrepl/refactor-nrepl {:mvn/version "2.4.0-SNAPSHOT"}}
12+
cider/cider-nrepl {:mvn/version "0.22.3"}
13+
refactor-nrepl/refactor-nrepl {:mvn/version "2.4.0"}
14+
zprint {:mvn/version "0.5.3"}}
1315
:jvm-opts ^:replace ["-XX:-OmitStackTraceInFastThrow"]}
1416

1517
:test {:extra-paths ["test"]}

parser/FHIRPathBaseListener.class

0 Bytes
Binary file not shown.

parser/FHIRPathBaseVisitor.class

0 Bytes
Binary file not shown.

parser/FHIRPathLexer.class

0 Bytes
Binary file not shown.

parser/FHIRPathListener.class

0 Bytes
Binary file not shown.
Binary file not shown.
19 Bytes
Binary file not shown.
19 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19 Bytes
Binary file not shown.
19 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19 Bytes
Binary file not shown.
Binary file not shown.
19 Bytes
Binary file not shown.
19 Bytes
Binary file not shown.
19 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19 Bytes
Binary file not shown.
19 Bytes
Binary file not shown.
19 Bytes
Binary file not shown.
19 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19 Bytes
Binary file not shown.
Binary file not shown.
19 Bytes
Binary file not shown.
19 Bytes
Binary file not shown.
19 Bytes
Binary file not shown.
19 Bytes
Binary file not shown.
19 Bytes
Binary file not shown.
19 Bytes
Binary file not shown.
19 Bytes
Binary file not shown.
Binary file not shown.
19 Bytes
Binary file not shown.

parser/FHIRPathParser.class

55 Bytes
Binary file not shown.

parser/FHIRPathVisitor.class

0 Bytes
Binary file not shown.

parser/antlr-4.7.2-complete.jar

-1.98 MB
Binary file not shown.

src/fhirpath/core.clj

+19-23
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,11 @@
110110
`(fp-union ~@(proxy-super visitChildren ctx)))
111111

112112
(visitExternalConstantTerm [^FHIRPathParser$ExternalConstantTermContext ctx]
113-
(let [var (subs (.getText ctx) 1)
114-
local-var (str "localvar-" var)]
115-
;; `(or (var-get ~(symbol local-var)))
116-
`(get ~'**env ~(keyword var))))
113+
(let [v (subs (.getText ctx) 1)
114+
v (if (str/starts-with? v "\"")
115+
(str/replace v #"\"" "")
116+
v)]
117+
`(get ~'**env ~(keyword v))))
117118

118119
;; (visitDateTimeLiteral [^FHIRPathParser$DateTimeLiteralContext ctx])
119120
;; (visitDateTimePrecision [^FHIRPathParser$DateTimePrecisionContext ctx])
@@ -378,15 +379,13 @@
378379
(defn fp-substring [s & [i j]]
379380
(let [s (singl s)]
380381
(when (string? s)
381-
(if (and i j)
382-
(when (and (< i j) (let [l (count s)] (and (< -1 i l) (< -1 (+ i j) l))))
383-
(subs s i (+ i j)))
384-
(when (< i (count s))
385-
(subs s i)))))
386-
#_(try
387-
388-
(catch Exception e
389-
(assert false (pr-str e s i j)))))
382+
(let [l (count s)]
383+
(if (and i j)
384+
(when (and (< -1 i l))
385+
(subs s i (min l (+ i j))))
386+
(when (< i l)
387+
(subs s i)))))))
388+
390389
(defn fp-startsWith [s ss]
391390
(let [s (singl s)]
392391
(when (string? s)
@@ -405,7 +404,7 @@
405404
(defn fp-replace [s ss r]
406405
(let [s (singl s)]
407406
(when (string? s)
408-
(str/replace s ss r))))
407+
(str/replace s (re-pattern ss) r))))
409408

410409
(defn fp-matches [s ss]
411410
(let [s (singl s)]
@@ -434,21 +433,18 @@
434433
(let [ch (fp-children s)]
435434
(into ch (mapcat #(seqy (fp-descendants %)) ch))))
436435

437-
(fp-descendants {:a [{:e 1 :d 20}] :b 2 :c 3})
436+
;; (fp-descendants {:a [{:e 1 :d 20}] :b 2 :c 3})
438437

439-
(fp-descendants {:a [{:b 1 :c [{:d 1}]}]})
438+
;; (fp-descendants {:a [{:b 1 :c [{:d 1}]}]})
440439

441440
(defn fp [expr data & [env]]
442-
(if env
443-
((compile expr) data env)
444-
((compile expr) data)))
445-
441+
((compile expr) data (assoc (or env {}) :context data)))
446442

447-
(parse "Functions.coll1[0].a.take(10).where(use= 'ok').subs(1)")
448-
(parse "%var.a")
449443

444+
;; (parse "Functions.coll1[0].a.take(10).where(use= 'ok').subs(1)")
445+
;; (parse "%var.a")
450446

451-
(fp "%varo.a" {} {:varo {:a 1}})
447+
;; (fp "%varo.a" {} {:varo {:a 1}})
452448

453449
;; (type (fp "101.99" {}))
454450

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/cases/5.6_string_manipulation.yaml test/fhirpath/cases/5.6_string_manipulation.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ tests:
100100
- desc: '** surround'
101101
expression: Functions.str.attr.replace('', 'x')
102102
disable: true
103-
result: 'xtxexsxtx xsxtxrxixnxg'
103+
result: 'xtxexsxtx xsxtxrxixnxgx'
104104

105105
- desc: '5.6.7. matches(regex : string) : boolean'
106106
# If the input collection contains a single item of type string, the function will return true when the value matches the given regular expression. Regular expressions should function consistently, regardless of any culture- and locale-specific settings in the environment, should be case-sensitive, use 'single line' mode and allow Unicode characters.
@@ -123,7 +123,7 @@ tests:
123123
result: 'match string'
124124

125125
- desc: '** replaceMatches 2'
126-
expression: Functions.str.date.replace('\\b(?<month>\\d{1,2})/(?<day>\\d{1,2})/(?<year>\\d{2,4})\\b', '${day}-${month}-${year}')
126+
expression: "Functions.str.date.replace('\\b(?<month>\\d{1,2})/(?<day>\\d{1,2})/(?<year>\\d{2,4})\\b', '${day}-${month}-${year}')"
127127
disable: true
128128
result: '30-11-1972'
129129

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
tests:
2-
- desc: '%resource (FHIR extension)'
3-
expression: '%resource.n1'
4-
result: [1]
52
- desc: '%context'
63
expression: '%context.n1'
7-
result: [1]
8-
- desc: '%context'
9-
context: 'g1'
10-
expression: '%context.n1'
11-
result: [2]
4+
result: 1
125
- desc: '%ucum'
6+
variables:
7+
ucum: 'http://unitsofmeasure.org'
138
expression: '%ucum'
14-
result: ['http://unitsofmeasure.org']
9+
result: 'http://unitsofmeasure.org'
1510
- expression: '%a - 1'
1611
variables:
1712
a: 5
@@ -24,5 +19,3 @@ tests:
2419

2520
subject:
2621
n1: 1
27-
g1:
28-
n1: 2
File renamed without changes.
File renamed without changes.

test/fhirpath/core_test.clj

+22-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
(:require [fhirpath.core :as sut]
33
[clj-yaml.core :as yaml]
44
[clojure.test :refer :all]
5-
[clojure.java.io :as io]))
6-
7-
5+
[clojure.java.io :as io]
6+
[clojure.string :as str]))
87

98
(deftest basic-tests
109

@@ -45,10 +44,10 @@
4544

4645

4746
(defn load-case [path]
48-
(yaml/parse-string (slurp (io/resource path))))
47+
(yaml/parse-string (slurp (io/resource (str "fhirpath/" path)))))
4948

5049
(defn do-test [path]
51-
(let [data (load-case path)]
50+
(let [data (load-case (str path))]
5251
(doseq [t (:tests data)]
5352
(println (:desc t))
5453
(println "EXPR=>" (:expression t))
@@ -172,15 +171,33 @@
172171
(is (= 4 (sut/fp "a.iif(b = 3, 4, 5 )" {:a {:b 3}})))
173172
(is (= 5 (sut/fp "a.iif(b = 3, 4, 5 )" {:a {:b 4}})))
174173

174+
(sut/fp "attr.substring(2, 1)" {:attr "abcdefg"})
175+
176+
(is (= "cdefg"
177+
(sut/fp "attr.substring(2, 5555)" {:attr "abcdefg"})))
178+
179+
180+
(sut/fp "attr.replace('', 'x')", {:attr "abc"})
181+
182+
(sut/fp "attr.replace('\\b(?<month>\\d{1,2})/(?<day>\\d{1,2})/(?<year>\\d{2,4})\\b', '${day}-${month}-${year}')",
183+
{:attr "11/30/1972"})
184+
185+
175186
(do-test "cases/6.6_math.yaml")
176187

177188

178189
(is (= 1 (sut/fp "%v.a" {} {:v {:a 1}})))
179190

191+
(sut/fp "%v.a" {} {:v {:a 1}})
192+
180193

181194
(do-test "cases/5.6_string_manipulation.yaml")
182195
(do-test "cases/5.7_tree_navigation.yaml")
183196
(do-test "cases/8_variables.yaml")
197+
(do-test "cases/6.6_math.yaml")
198+
;; (do-test "cases/6.1_equality.yaml")
199+
200+
;; (do-test "cases/6.5_boolean_logic.yaml")
184201

185202
)
186203

0 commit comments

Comments
 (0)