dm+d storage using sqlite
dm+d storage using sqlite
(apids conn id)Return AMP ids for the given product.
Return AMP ids for the given product.
(apids-for-vpids conn vpids)Return APIDs for the given VPIDs.
Return APIDs for the given VPIDs.
(appids conn id)Return AMPP ids for the given product.
Return AMPP ids for the given product.
(atc->ecl conn
atc
&
{:keys [include-tf? include-product-packs?]
:or {include-tf? false include-product-packs? false}})DEPRECATED: use atc->products-for-ecl instead and use that data to build
an ECL expression outside of this library.
Convert an ATC code into a SNOMED CT expression that will identify all
dm+d products relating to that code. It is almost always better to build an
ECL expression using atc->products-for-ecl rather than this function.
Not all VMPs have a VTM, but a given VTM will subsume all VTMs, VMPs and AMPs in the SNOMED drug model.
Unfortunately, while the UK SNOMED drug extension includes trade family entities, dm+d does not. This is unfortunate. In order to identify the TF concept for any given AMP, we can use an ECL expression of the form (>'amp-concept-id' AND <9191801000001103|Trade Family|) to identify parent concepts in the hierarchy up to and not including the TF concept itself. However, this can result in a very long expression indeed. If you need to build an ECL expression that includes TF, this is better done within the context of the SNOMED drug extension. You can use 'atc->products-for-ecl' to help build that ECL expression.
It would not be usual to want to include VMPP or AMPP, but you can include if required. All AMPPs are subsumed by VMPPs, so we simply add clauses to include VMPPs and descendants for each VMP using the 'Has VMP' relationship.
DEPRECATED: use `atc->products-for-ecl` instead and use that data to build an ECL expression outside of this library. Convert an ATC code into a SNOMED CT expression that will identify all dm+d products relating to that code. It is almost always better to build an ECL expression using `atc->products-for-ecl` rather than this function. Not all VMPs have a VTM, but a given VTM will subsume all VTMs, VMPs and AMPs in the SNOMED drug model. Unfortunately, while the UK SNOMED drug extension includes trade family entities, dm+d does not. This is unfortunate. In order to identify the TF concept for any given AMP, we can use an ECL expression of the form (>'amp-concept-id' AND <9191801000001103|Trade Family|) to identify parent concepts in the hierarchy up to and not including the TF concept itself. However, this can result in a very long expression indeed. If you need to build an ECL expression that includes TF, this is better done within the context of the SNOMED drug extension. You can use 'atc->products-for-ecl' to help build that ECL expression. It would not be usual to want to include VMPP or AMPP, but you can include if required. All AMPPs are subsumed by VMPPs, so we simply add clauses to include VMPPs and descendants for each VMP using the 'Has VMP' relationship.
(atc->products-for-ecl conn atc)Returns a map containing product type as key and a sequence of product identifiers as each value, designed for building an ECL expression. Parameters:
As the child relationships of a VTM include all VMPs and AMPs, we do not have to include VMPs or AMPs unless there is no VTM for a given VMP. As such, VMPs are only returned iff there is no associated VTM. However, all AMPs are returned as it is likely that those will be needed in order to derive a list of TF products. It is sadly the case that the stock dm+d does not include TF products, while the SNOMED drug extension does include those products.
Returns a map containing product type as key and a sequence of product identifiers as each value, designed for building an ECL expression. Parameters: - conn : database connection - atc : a string representing the ATC code, or prefix. As the child relationships of a VTM include all VMPs and AMPs, we do not have to include VMPs or AMPs unless there is no VTM for a given VMP. As such, VMPs are only returned iff there is no associated VTM. However, all AMPs are returned as it is likely that those will be needed in order to derive a list of TF products. It is sadly the case that the stock dm+d does not include TF products, while the SNOMED drug extension does include those products.
(atc-code conn id)Return the ATC code for the product specified.
Return the ATC code for the product specified.
(batch->sql batch)For the given batch of dm+d entities, return a map of :stmts and :errors
{:stmts ({:stmt "insert into SUPPLIER(CD,DESC) VALUES (?, ?) ON CONFLICT(CD) DO UPDATE SET DESC=excluded.DESC",
:data ([2070501000001104 "DDC Ltd"]
[3146101000001108 "Dragon Pharm Ltd"] ...)})}
:errors nil
For the given batch of dm+d entities, return a map of :stmts and :errors
```
{:stmts ({:stmt "insert into SUPPLIER(CD,DESC) VALUES (?, ?) ON CONFLICT(CD) DO UPDATE SET DESC=excluded.DESC",
:data ([2070501000001104 "DDC Ltd"]
[3146101000001108 "Dragon Pharm Ltd"] ...)})}
:errors nil(close ds)Close the store, releasing pooled connections.
Close the store, releasing pooled connections.
(create-indexes conn)Creates all database indexes; each entity may define none, one, or many.
Creates all database indexes; each entity may define none, one, or many.
(create-search-index conn)Creates and populates a full-text (FTS5) index of product names. This is derived data, built after import rather than being an import target.
Creates and populates a full-text (FTS5) index of product names. This is derived data, built after import rather than being an import target.
(create-store filename
dirs
&
{:keys [batch-size release-date trud] :or {batch-size 50000}})Create a dm+d store at filename from the directories dirs.
Options:
Create a dm+d store at `filename` from the directories `dirs`. Options: - :batch-size - number of components per write batch (default 50000) - :release-date - date of the dm+d release - :trud - source TRUD release information, stored for provenance
(create-tables conn)Creates all database tables for dm+d entities.
Creates all database tables for dm+d entities.
(current-ids conn id)Returns the set of identifiers in current use for the given (usually historic) identifier, excluding the identifier itself. Usually a single identifier, but the data model permits more than one.
Returns the set of identifiers in current use for the given (usually historic) identifier, excluding the identifier itself. Usually a single identifier, but the data model permits more than one.
(dmd-database? f)Returns true if f is a dm+d SQLite database created by this library
(SQLite magic + application_id == 0x646D2B64). Strict by default: legacy
dm+d databases predating application_id support return false.
Returns true if `f` is a dm+d SQLite database created by this library (SQLite magic + application_id == 0x646D2B64). Strict by default: legacy dm+d databases predating application_id support return false.
(fetch-amp conn apid)Return the given AMP with extended information, including the parent VMP.
Return the given AMP with extended information, including the parent VMP.
(fetch-amp* conn apid)Return the given AMP without extended information.
Return the given AMP without extended information.
(fetch-ampp conn appid)Return the given AMPP with extended information, including the parent AMP and VMP.
Return the given AMPP with extended information, including the parent AMP and VMP.
(fetch-ampp* conn appid)Return the given AMPP without extended information.
Return the given AMPP without extended information.
(fetch-history conn id)Returns all history entries in which id is the current identifier,
ordered by start date. Includes 'self' entries (IDCURRENT=IDPREVIOUS) which
record the period of validity of the current identifier itself.
Returns all history entries in which `id` is the current identifier, ordered by start date. Includes 'self' entries (IDCURRENT=IDPREVIOUS) which record the period of validity of the current identifier itself.
(fetch-ingredient conn isid)Returns the ingredient specified.
Returns the ingredient specified.
(fetch-product conn id)Returns extended information about the product with identifier specified.
Returns extended information about the product with identifier specified.
(fetch-product-by-exact-name conn s)Return a single product with the given exact name
Return a single product with the given exact name
(fetch-vmp conn vpid)Return the given VMP with extended information to include its relationships such as its parent VTM.
Return the given VMP with extended information to include its relationships such as its parent VTM.
(fetch-vmp* conn vpid)Return the given VMP without extended information.
Return the given VMP without extended information.
(fetch-vmpp conn vppid)Return the given VMPP with extended information, including its parent VMP.
Return the given VMPP with extended information, including its parent VMP.
(fetch-vmpp* conn vppid)Return the given VMPP without extended information.
Return the given VMPP without extended information.
Returns the given VTM. VTMs do not have extended information so this
returns the same as fetch-vtm*.
Returns the given VTM. VTMs do not have extended information so this returns the same as `fetch-vtm*`.
(fetch-vtm* conn vtmid)Returns the given VTM with no extended information.
Returns the given VTM with no extended information.
Set of lookup types, as keywords, each of which is the name of a lookup table, e.g. #{:BASIS_OF_NAME :SUPPLIER ...}.
Set of lookup types, as keywords, each of which is the name of a lookup
table, e.g. #{:BASIS_OF_NAME :SUPPLIER ...}.(open-store filename)Open a read-only dm+d store, returning a pooled DataSource that supports concurrent use. Throws an exception if the file does not exist, is not a dm+d database (checked via SQLite application_id), or was created with an incompatible store version (checked via SQLite user_version). Legacy databases, including those predating application_id support, are rejected and must be rebuilt using this version of the library.
Open a read-only dm+d store, returning a pooled DataSource that supports concurrent use. Throws an exception if the file does not exist, is not a dm+d database (checked via SQLite application_id), or was created with an incompatible store version (checked via SQLite user_version). Legacy databases, including those predating application_id support, are rejected and must be rebuilt using this version of the library.
(plan-products conn product-type)Returns a reducible (clojure.lang.IReduceInit) over all rows of the given
product type (:VTM :VMP :AMP :VMPP or :AMPP), for streaming iteration
without realising all rows in memory. Each row is a next.jdbc row
abstraction; access columns by keyword, e.g. (map :NM).
Returns a reducible (clojure.lang.IReduceInit) over all rows of the given product type (:VTM :VMP :AMP :VMPP or :AMPP), for streaming iteration without realising all rows in memory. Each row is a `next.jdbc` row abstraction; access columns by keyword, e.g. (map :NM).
(previous-ids conn id)Returns the set of prior identifiers for the given current identifier, excluding the identifier itself.
Returns the set of prior identifiers for the given current identifier, excluding the identifier itself.
(product-ids-from-atc conn atc)(product-ids-from-atc conn atc product-types)Return a lazy sequence of product ids matching the ATC code
Return a lazy sequence of product ids matching the ATC code
Map of product type to its table and primary key column.
Map of product type to its table and primary key column.
(product-type conn id)Returns a keyword :VTM :VMP :AMP :VMPP or :AMPP for the product with the identifier specified.
Returns a keyword :VTM :VMP :AMP :VMPP or :AMPP for the product with the identifier specified.
(search conn s & {:keys [types limit] :or {limit 100}})Search product names, returning a sequence of maps of :SEARCH/ID,
:SEARCH/TYPE and :SEARCH/NM, best matches first. Each token of s is
matched as a prefix; multiple tokens must all match.
Options:
Search product names, returning a sequence of maps of :SEARCH/ID,
:SEARCH/TYPE and :SEARCH/NM, best matches first. Each token of `s` is
matched as a prefix; multiple tokens must all match.
Options:
- :types - product types to include e.g. #{:VMP :AMP}; default, all
- :limit - maximum number of results; default 100(sqlite-database? f)Returns true if f is a SQLite 3 database file (checked by header magic).
Returns true if `f` is a SQLite 3 database file (checked by header magic).
(status conn)Returns a structured description of an open dm+d store:
Returns a structured description of an open dm+d store: - :version - store (schema) version - :created - java.time.LocalDateTime the database was created - :release - java.time.LocalDate of the dm+d release - :trud - source TRUD release information, when installed via TRUD - :files - inventory of imported source files - :counts - a map of entity type to row count
(vmps-from-atc conn atc)Return VMPs matching the given ATC code as a prefix.
Return VMPs matching the given ATC code as a prefix.
(vpids conn id)Return VMP ids for the given product.
Return VMP ids for the given product.
(vpids-for-apids conn apids)Return VPIDs for the given APIDs.
Return VPIDs for the given APIDs.
(vpids-for-vtmids conn vtmids)Return VPIDs for the given VTMIDs.
Return VPIDs for the given VTMIDs.
(vpids-from-atc conn atc)Return a vector of VPIDs matching the given ATC code.
Return a vector of VPIDs matching the given ATC code.
(vpids-from-atc-wo-vtms conn atc)Return a vector of VPIDs matching the given ATC code/prefix that do not have an associated VTM. This is only useful when constructing SNOMED ECL expressions that use a combination of VTMs, VMPs and TFs, and therefore do not need VMPs unless there is no associated VTM.
Return a vector of VPIDs matching the given ATC code/prefix that do not have an associated VTM. This is only useful when constructing SNOMED ECL expressions that use a combination of VTMs, VMPs and TFs, and therefore do not need VMPs unless there is no associated VTM.
(vppids conn id)Return VMPP ids for the given product.
Return VMPP ids for the given product.
(vtm-ingredients conn vtmid)Returns ingredient (ISID) identifiers for the given VTM.
Returns ingredient (ISID) identifiers for the given VTM.
(vtmids conn id)Return VTM ids for the given product.
Return VTM ids for the given product.
(vtmids-for-vpids conn vpids)Return VTMIDs for the given VPIDs.
Return VTMIDs for the given VPIDs.
(vtms-for-ingredient conn isid)Returns VTM identifiers for the given ingredient.
Returns VTM identifiers for the given ingredient.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |