Skip to content

Commit

Permalink
Add search by exact name
Browse files Browse the repository at this point in the history
  • Loading branch information
wardle committed May 11, 2022
1 parent 0731b1b commit 45d5666
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,37 @@ the VTM, and an AMPP will include all of the others!
"VTMID": 108537001
}
```
##### Get a product by exact name

You can search by exact name, if you have data without dm+d codes, but derived from the dm+d dataset.

This is a case-sensitive search.

```shell
http -j 'http://127.0.0.1:8080/dmd/v1/search?s=Amlodipine 5mg/5ml oral solution sugar-free'
```
Result:
```json
{
"BASIS": {
"CD": 1,
"DESC": "rINN - Recommended International Non-proprietary"
},
"BASISCD": 1,
"BNF_DETAILS": {
"ATC": "C08CA01",
"BNF": "02060200",
"DDD": 5.0,
"DDD_UOM": {
"CD": 258684004,
"DESC": "mg"
},
"DDD_UOMCD": 258684004,
"VPID": 39732011000001102
},
"CONTROL_DRUG_INFO": {
...
```

##### Map from BNF or ATC codes to VMPs

Expand Down
13 changes: 13 additions & 0 deletions cmd/com/eldrix/dmd/serve.clj
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@
context
(assoc context :result (dmd/fetch-product store (Long/parseLong product-id))))))})

(def search-product
{:name
::search-product
:enter
(fn [context]
(let [store (get-in context [:request ::store])
s (get-in context [:request :query-params :s])]
(println "Search: " s)
(if-not s
context
(assoc context :result (dmd/fetch-product-by-exact-name store s)))))})

(def fetch-lookup
{:name
::fetch-lookup
Expand Down Expand Up @@ -217,6 +229,7 @@
["/dmd/v1/product/:product-id/amps" :get (conj common-interceptors fetch-product-amps)]
["/dmd/v1/product/:product-id/atc" :get (conj common-interceptors fetch-product-atc)]
["/dmd/v1/product/:product-id" :get (conj common-interceptors fetch-product)]
["/dmd/v1/search" :get (conj common-interceptors search-product)]
["/dmd/v1/lookup/:lookup-kind" :get (conj common-interceptors fetch-lookup)]
["/dmd/v1/atc/:atc/vmps" :get (conj common-interceptors atc->vmps)]
["/dmd/v1/atc/:atc/products" :get (conj common-interceptors atc->products)]
Expand Down
4 changes: 4 additions & 0 deletions src/com/eldrix/dmd/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
(defn fetch-product [^DmdStore store product-id]
(st2/fetch-product store product-id))

(defn fetch-product-by-exact-name [^DmdStore store nm]
(when-let [id (st2/product-by-exact-name store nm)]
(st2/fetch-product store id)))

(defn fetch-lookup [^DmdStore store lookup-kind]
(st2/fetch-lookup store lookup-kind))

Expand Down
14 changes: 14 additions & 0 deletions src/com/eldrix/dmd/store2.clj
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,20 @@
(d/db (.-conn st))
re-nm))

(defn product-by-exact-name
"Returns a single product identifier for a search by exact name."
[st nm]
(d/q '[:find ?id .
:in $ ?nm
:where
[?e :PRODUCT/ID ?id]
(or
[?e :VTM/NM ?nm]
[?e :AMP/DESC ?nm]
[?e :VMP/NM ?nm])]
(d/db (.-conn st))
nm))

(defmulti vtms "Return the entity ids for the VTMs associated with this product."
(fn [^DmdStore _store product] (:PRODUCT/TYPE product)))

Expand Down

0 comments on commit 45d5666

Please sign in to comment.