diff --git a/src/com/eldrix/hermes/core.clj b/src/com/eldrix/hermes/core.clj index 83ca268..10c23d7 100644 --- a/src/com/eldrix/hermes/core.clj +++ b/src/com/eldrix/hermes/core.clj @@ -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? diff --git a/test/src/com/eldrix/hermes/core_test.clj b/test/src/com/eldrix/hermes/core_test.clj index 1ab35b8..2a8fdca 100644 --- a/test/src/com/eldrix/hermes/core_test.clj +++ b/test/src/com/eldrix/hermes/core_test.clj @@ -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") @@ -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))))