Skip to content

Commit

Permalink
Add intersect-ecl-fn
Browse files Browse the repository at this point in the history
  • Loading branch information
wardle committed Dec 7, 2024
1 parent d8e061d commit de8d645
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
14 changes: 13 additions & 1 deletion src/com/eldrix/hermes/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -697,12 +697,24 @@
:args (s/cat :svc ::svc :concept-ids (s/coll-of :info.snomed.Concept/id) :ecl ::non-blank-string))
(defn intersect-ecl
"Returns the subset of the concept identifiers that satisfy the SNOMED ECL
expression."
expression. Use [[intersect-ecl-fn]] if the same ECL expression will be
used repeatedly."
[^Svc svc concept-ids ^String ecl]
(let [q1 (search/q-concept-ids concept-ids)
q2 (ecl/parse svc ecl)]
(search/do-query-for-concept-ids (.-searcher svc) (search/q-and [q1 q2]))))

(s/fdef intersect-ecl-fn
:args (s/cat :svc ::svc :ecl ::non-blank-string))
(defn intersect-ecl-fn
"Return a function that can return the subset the specified concept
identifiers that satisfy the SNOMED ECL expression."
[^Svc svc ^String ecl]
(let [q2 (ecl/parse svc ecl)]
(fn [concept-ids]
(let [q1 (search/q-concept-ids concept-ids)]
(search/do-query-for-concept-ids (.-searcher svc) (search/q-and [q1 q2]))))))

(s/fdef valid-ecl?
:args (s/cat :s string?))
(defn valid-ecl?
Expand Down
12 changes: 8 additions & 4 deletions test/src/com/eldrix/hermes/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@

(deftest ^:live test-intersect-ecl
(is (= #{24700007} (hermes/intersect-ecl *svc* [24700007] "<<24700007")) "Descendant or self expression should include self")
(is (= #{24700007} ((hermes/intersect-ecl-fn *svc* "<<24700007") [24700007])) "Descendant or self expression should include self")
(is (= #{816984002} (hermes/intersect-ecl *svc* [816984002] "<<24700007")) "Primary progressive multiple sclerosis is a type of MS")
(is (= #{816984002} ((hermes/intersect-ecl-fn *svc* "<<24700007") [816984002])) "Primary progressive multiple sclerosis is a type of MS")
(is (= #{24700007} (hermes/intersect-ecl *svc* [24700007] "^447562003")) "Multiple sclerosis should be in the ICD-10 complex map reference set")
(is (= #{24700007} ((hermes/intersect-ecl-fn *svc* "^447562003") [24700007])) "Multiple sclerosis should be in the ICD-10 complex map reference set")
(is (= #{24700007} (hermes/intersect-ecl *svc* #{315560000 24700007} "<64572001")) "Born in Wales is not a type of disease")
(is (= #{24700007} ((hermes/intersect-ecl-fn *svc* "<64572001") #{315560000 24700007})) "Born in Wales is not a type of disease")
(let [concept-ids-1 (set (map :conceptId (hermes/search *svc* {:s "m"})))
concept-ids-2 (hermes/intersect-ecl *svc* concept-ids-1 "<<138875005")]
(is (empty? (set/difference concept-ids-1 concept-ids-2)) "All concepts should be children of root SNOMED CT")))
concept-ids-2 (hermes/intersect-ecl *svc* concept-ids-1 "<<138875005")
concept-ids-3 ((hermes/intersect-ecl-fn *svc* "<<138875005") concept-ids-1)]
(is (empty? (set/difference concept-ids-1 concept-ids-2)) "All concepts should be children of root SNOMED CT")
(is (empty? (set/difference concept-ids-1 concept-ids-3)) "All concepts should be children of root SNOMED CT")))

(deftest ^:live test-expand-historic
(is (every? true? (->> (hermes/expand-ecl *svc* "<<24700007")
Expand Down Expand Up @@ -101,8 +107,6 @@
(is (seq (filter #{"Appendicectomy"} (map :term r2))) "Appendicectomy should be a preferred term for en-GB locale")
(is (seq (filter #{"Appendectomy"} (map :term r3))) "Appendectomy should be a preferred term for en-US locale")))



(deftest ^:live test-with-historical
(is (:active (hermes/concept *svc* 24700007)))
(is (not (:active (hermes/concept *svc* 586591000000100))))
Expand Down

0 comments on commit de8d645

Please sign in to comment.