David Selby and Belay Birlie
An R implementation of the text mining algorithm of Karystianis et al. (2015) for extracting drug dosage information from electronic prescription data (especially from CPRD). The aim of this project is to provide a complete replacement for the algorithm, entirely written in R with no external dependencies (unlike the original implementation, which depended on Python and Java). This should make the tool more portable, extensible and suitable for use across different platforms (Windows, Mac, Unix).
You can install doseminer from CRAN using
install.packages('doseminer')
or get the latest development version via GitHub:
# install.packages('remotes')
remotes::install_github('Selbosh/doseminer')
The workhorse function is called extract_from_prescription
. Pass it a
character vector of freetext prescriptions and it will try to extract
the following variables:
library(doseminer)
extract_from_prescription('take two and a half tablets every two to three days as needed')
Anything not matched is returned as NA
, though some inferences are
also made. For instance: if a dosage is specified as multiple times per
day, with no explicit interval between days, it’s inferred the interval
is one day. Similarly, if an interval is specified (e.g. every 3 days)
but not a daily frequency, it’s presumed the dose is taken only once
during the day.
To see the package in action, a small vector of example prescriptions is
included in the variable example_prescriptions
.
extract_from_prescription(example_prescriptions)
The column output
represents the ‘residual’ text after other features
have been extracted. It can be ignored for most applications, but is
useful for debugging prescriptions that have not been parsed as
expected.
Built into this package is a series of functions for extracting and parsing natural language English numbers into their digit-based numeric form. This could be spun out into its own package for more general use.
replace_numbers(c('Thirty seven bottles of beer on the wall',
'Take one down, pass it around',
'Thirty-six bottles of beer on the wall!',
'One MILLION dollars.',
'We do not take any half measures'))
## [1] "37 bottles of beer on the wall" "Take 1 down, pass it around"
## [3] "36 bottles of beer on the wall!" "1e+06 dollars."
## [5] "We do not take any 0.5 measures"
Inspired by Ben Marwick’s words2number
(https://github.com/benmarwick/words2number).
Maintained by David Selby (david.selby@manchester.ac.uk
) and Belay
Birlie.
Karystianis, G., Sheppard, T., Dixon, W.G. et al. Modelling and extraction of variability in free-text medication prescriptions from an anonymised primary care electronic medical record research database. BMC Med Inform Decis Mak 16, 18 (2015). https://doi.org/10.1186/s12911-016-0255-x
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.