Skip to content

Commit

Permalink
Fix support for wildcards in ATC codes to match ICD-10 wildcards
Browse files Browse the repository at this point in the history
  • Loading branch information
wardle committed May 1, 2024
1 parent 662fbb7 commit 889499a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
8 changes: 4 additions & 4 deletions cmd/com/eldrix/codelists/cmd.clj
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@
(uncaughtException [_ thread ex]
(log/error ex "Uncaught exception on" (.getName thread)))))
(let [cfg (cond-> {}
port (assoc ::http/port port)
bind-address (assoc ::http/host bind-address)
allowed-origins (assoc ::http/allowed-origins allowed-origins))]
port (assoc ::http/port port)
bind-address (assoc ::http/host bind-address)
allowed-origins (assoc ::http/allowed-origins allowed-origins))]
(-> (merge service-map cfg)
(assoc ::http/join? join?)
(http/default-interceptors)
Expand Down Expand Up @@ -163,7 +163,7 @@
params' (cond (= ["*"] allowed-origins') (assoc params :allowed-origins (constantly true))
(seq allowed-origins') (assoc params :allowed-origins allowed-origins')
:else params)
status {:hermes (map :term (hermes/get-release-information hermes'))
status {:hermes (map :term (hermes/release-information hermes'))
:dmd {:releaseDate (dmd/fetch-release-date dmd')}}]
(log/info "starting codelists server " params')
(start-server {:com.eldrix/hermes hermes'
Expand Down
20 changes: 13 additions & 7 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{:paths ["src" "resources" "classes"]

:deps {org.clojure/clojure {:mvn/version "1.11.1"}
:deps {org.clojure/clojure {:mvn/version "1.11.2"}
org.clojure/data.json {:mvn/version "2.5.0"}
org.clojure/tools.logging {:mvn/version "1.3.0"}

com.eldrix/dmd {:mvn/version "1.0.174"}
com.eldrix/hermes {:mvn/version "1.4.1351"}}
com.eldrix/dmd {:mvn/version "1.0.202"}
com.eldrix/hermes {:mvn/version "1.4.1368"}}

:aliases {:dev
{:extra-paths ["cmd" "test/src" "test/resources"]}

:build
{:deps {io.github.clojure/tools.build {:git/tag "v0.9.6" :git/sha "8e78bcc"}
{:deps {io.github.clojure/tools.build {:git/tag "v0.10.0" :git/sha "3a2c484"}
slipset/deps-deploy {:mvn/version "RELEASE"}
io.github.borkdude/gh-release-artifact {:git/sha "4a9a74f0e50e897c45df8cc70684360eb30fce80"}}
:ns-default build}
Expand All @@ -21,18 +21,24 @@
:extra-deps {org.clojure/tools.cli {:mvn/version "1.1.230"}
io.pedestal/pedestal.service {:mvn/version "0.6.3"}
io.pedestal/pedestal.jetty {:mvn/version "0.6.3"}
ch.qos.logback/logback-classic {:mvn/version "1.5.0"}}
ch.qos.logback/logback-classic {:mvn/version "1.5.6"}}
:main-opts ["-m" "com.eldrix.codelists.cmd"]
:jvm-opts ["--add-opens" "java.base/java.nio=ALL-UNNAMED"
"--add-opens" "java.base/sun.nio.ch=ALL-UNNAMED"]}

:nrepl-server
{:extra-deps {nrepl/nrepl {:mvn/version "1.1.1"}
cider/cider-nrepl {:mvn/version "0.47.1"}}
:main-opts ["--main" "nrepl.cmdline"
"--middleware" "[cider.nrepl/cider-middleware]"]}

:socket
{:jvm-opts ["-Dclojure.server.repl={:port,50505,:accept,clojure.core.server/repl}"]}

:test
{:extra-paths ["test"]
:extra-deps {io.github.cognitect-labs/test-runner {:git/sha "7284cda41fb9edc0f3bc6b6185cfb7138fc8a023"}
ch.qos.logback/logback-classic {:mvn/version "1.5.0"}
ch.qos.logback/logback-classic {:mvn/version "1.5.6"}
org.clojure/data.csv {:mvn/version "1.1.0"}}
:main-opts ["-m" "cognitect.test-runner"]
:exec-fn cognitect.test-runner.api/test
Expand All @@ -50,7 +56,7 @@
:check
{:extra-deps {athos/clj-check
{:git/url "https://github.com/athos/clj-check.git"
:sha "518d5a1cbfcd7c952f548e6dbfcb9a4a5faf9062"}}
:sha "d997df866b2a04b7ce7b17533093ee0a2e2cb729"}}
:main-opts ["-m" "clj-check.check"]}

:test/cloverage
Expand Down
22 changes: 12 additions & 10 deletions src/com/eldrix/codelists/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@
(f x)))

(defn tf-for-product [hermes concept-id]
(filter #(seq (hermes/component-refset-items hermes % 999000631000001100)) (hermes/all-parents hermes concept-id)))
(filter #(seq (hermes/component-refset-items hermes % 999000631000001100))
(hermes/all-parents hermes concept-id)))

(defn atc->snomed-ecl
"Map an ATC regexp into a SNOMED expression that can include all UK product
"Map an ATC code into a SNOMED expression that can include all UK product
identifiers (VTM, VMP, AMP and TF). This does not include product packs,
by design."
[{:com.eldrix/keys [dmd hermes]} atc]
Expand All @@ -60,12 +61,12 @@
(defn realize-concepts*
[{:com.eldrix/keys [hermes dmd] :as env} {and' :and or' :or not' :not :keys [ecl icd10 atc]}]
(let [incl (set/union
(when and' (apply set/intersection (map #(realize-concepts env %) and')))
(when or' (apply set/union (map #(realize-concepts env %) or')))
(when ecl (apply-union #(into #{} (map :conceptId (hermes/expand-ecl-historic hermes %))) ecl))
(when icd10 (hermes/with-historical hermes (set (apply-union #(hermes/member-field-wildcard hermes 447562003 "mapTarget" %) icd10))))
(when atc (apply-union #(let [atc' (atc->snomed-ecl env (re-pattern (str/replace % "*" ".*")))]
(when-not (= "" atc') (into #{} (map :conceptId (hermes/expand-ecl-historic hermes atc' ))))) atc)))]
(when and' (apply set/intersection (map #(realize-concepts env %) and')))
(when or' (apply set/union (map #(realize-concepts env %) or')))
(when ecl (apply-union #(into #{} (map :conceptId (hermes/expand-ecl-historic hermes %))) ecl))
(when icd10 (hermes/with-historical hermes (set (apply-union #(hermes/member-field-wildcard hermes 447562003 "mapTarget" %) icd10))))
(when atc (apply-union #(let [atc' (atc->snomed-ecl env %)]
(when-not (= "" atc') (into #{} (map :conceptId (hermes/expand-ecl-historic hermes atc'))))) atc)))]
(if not'
(set/difference incl (realize-concepts env not'))
incl)))
Expand Down Expand Up @@ -114,18 +115,19 @@
(comment

(def hermes (hermes/open "/Users/mark/Dev/hermes/snomed.db"))
(def dmd (dmd/open-store "/Users/mark/Dev/dmd/dmd-2022-05-09.db"))
(def dmd (dmd/open-store "/Users/mark/Dev/dmd/dmd-2024-01-29.db"))
(def system {:com.eldrix/hermes hermes :com.eldrix/dmd dmd})
(defn ps [id] (vector id (:term (hermes/preferred-synonym (:com.eldrix/hermes system) id "en-GB"))))
(ps 24700007)
(dmd/fetch-release-date dmd)
(dmd/fetch-product dmd 108537001)
(hermes/concept hermes 108537001)
(ps 108537001)
(def calcium-channel (realize-concepts system {:atc #"C08CA.*"})) ;; see https://www.whocc.no/atc_ddd_index/?code=C08CA01
(def calcium-channel (realize-concepts system {:atc "C08CA"})) ;; see https://www.whocc.no/atc_ddd_index/?code=C08CA01
(count calcium-channel)
(contains? calcium-channel 108537001)

(atc->snomed-ecl system #"C08CA.*")
(def multiple-sclerosis (realize-concepts system {:icd10 "G35"}))
(contains? multiple-sclerosis 24700007)

Expand Down
7 changes: 3 additions & 4 deletions test/com/eldrix/codelists/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[com.eldrix.dmd.core :as dmd]
[com.eldrix.hermes.core :as hermes]))


(def ^:dynamic *hermes* nil)
(def ^:dynamic *dmd* nil)

Expand All @@ -22,12 +21,12 @@

(deftest simple-ecl)


(comment
(def hermes (hermes/open "../hermes/snomed.db"))
(def dmd (dmd/open-store "../dmd/dmd-2024-01-29.db"))
(def env {:com.eldrix/hermes hermes :com.eldrix/dmd dmd})
(defn ps [id] (vector id (:term (hermes/preferred-synonym hermes id "en-GB"))))
(map ps (cl/realize-concepts env {:icd10 ["B20.*", "B21.*", "B22.*", "B24.*", "F02.4" "O98.7" "Z21.*", "R75"]}))
(cl/to-icd10 env (cl/realize-concepts env {:ecl "<24700007"})))
(cl/parse-json "[{\"ecl\": \"<<24700007\"}] ")
(cl/to-icd10 env (cl/realize-concepts env {:ecl "<24700007"}))
(cl/realize-concepts env {:atc ["C09AA*"]}))
(cl/parse-json "[{\"ecl\": \"<<24700007\"}] ")

0 comments on commit 889499a

Please sign in to comment.