Code Monkey home page Code Monkey logo

doseminer's Introduction

R package doseminer

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).

Installation

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')

Usage

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:

  • Dose frequency (the number of times per day a dose is administered)
  • Dose interval (the number of days between doses)
  • Dose unit (how individual doses are measured, e.g. millilitres, tablets)
  • Dose number (how many of those units comprise a single dose, e.g. 2 tablets)
  • Optional (should the dose only be taken ‘if required’ / ‘as needed’?)
library(doseminer)
extract_from_prescription('take two and a half tablets every two to three days as needed')
raw output freq itvl dose unit optional
take two and a half tablets every two to three days as needed 2.5 tab 1 2-3 2.5 tab 1

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)
raw output freq itvl dose unit optional
1 tablet to be taken daily 1 tab to be taken 1 1 1 tab 0
2.5ml four times a day when required 2.5 ml 4 1 2.5 ml 1
1.25mls three times a day 1.25 ml 3 1 1.25 ml 0
take 10mls q.d.s. p.r.n. 10 ml 1 1 10 ml 1
take 1 or 2 4 times/day 1 - 2 4 1 1-2 NA 0
2x5ml spoon 4 times/day 2 x 5 ml spoonful 4 1 10 ml spoonful 0
take 2 tablets every six hours max eight in twenty four hours 2 tab 0 - 8 in 24 hours 4 1 2 tab 0
1 tab nocte twenty eight tablets 1 tab 28 tab 1 1 1 tab 0
1-2 four times a day when required 1 - 2 4 1 1-2 NA 1
take one twice daily 1 2 1 1 NA 0
1 q4h prn 1 6 1 1 NA 1
take two every three days 2 1 3 2 NA 0
five every week 5 1 7 5 NA 0
every 72 hours 1 3 NA NA 0
1 x 5 ml spoon 4 / day for 10 days 1 x 5 ml spoonful for 10 days 4 1 5 ml spoonful 0
two to three times a day 2-3 1 NA NA 0
three times a week 1 2-3 NA NA 0
three 5ml spoonsful to be taken four times a day after food 3 x 5 ml spoonful to be taken after food 4 1 15 ml spoonful 0
take one or two every 4-6 hrs 1 - 2 4-6 1 1-2 NA 0
5ml 3 hrly when required 5 ml 8 1 5 ml 1
one every morning to reduce bp 1 to reduce bp 1 1 1 NA 0
take 1 or 2 6hrly when required 1 - 2 4 1 1-2 NA 1
take 1 or 2 four times a day as required for pain 1 - 2 for pain 4 1 1-2 NA 1
take 1 or 2 4 times/day if needed for pain 1 - 2 for pain 4 1 1-2 NA 1
1-2 tablets up to four times daily 1 - 2 tab 0-4 1 1-2 tab 1
take one or two tablets 6-8 hrly every 2-3 days 1 - 2 tab 3-4 2-3 1-2 tab 0
one and a half tablets every three hours 1.5 tab 8 1 1.5 tab 0

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.

English words to numbers

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).

Contributors

Maintained by David Selby ([email protected]) and Belay Birlie.

References

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

doseminer's People

Contributors

selbosh avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mhatrep belayb

doseminer's Issues

Accuracy issues

Thanks for this package. I need to extract doses and units from free text, so I tried this. However, there are some accuracy issues you should probably look into. For example, if you run the code:
extract_from_prescription(c("Diclofenac sodium 50mg gastro-resistant tablets", "Bendroflumethiazide 2.5mg tablets", "Co-amoxiclav 250mg/125mg tablets", "Zyban 150mg modified-release tablets (GlaxoSmithKline UK Ltd)")), you get the wrong units (first two examples), fail to detect the clavulanate dose (third example) and extract a non-existent frequency (last example).

image

Add support for fractional doses (beyond half measures)

The package currently supports expressions with half measures in them, including mixed fractions:

doseminer::replace_numbers(c('half a spoonful', 'three and a half tablets'))
## [1] "0.5 a spoonful" "3.5 tablets" 

But more unusual fractions like thirds, fifths and quarters don't really work because it just kind of adds the denominator:

doseminer::replace_numbers(c('thirty three and a third', 'four fifths'))
## [1] "37" "9" 

The problem is with fixing this (assuming such cases appear often enough in prescriptions to be worth worrying about) without unintentionally breaking the parsing of ordinal words, which look a lot like fractions:

doseminer::replace_numbers(c('every third day', 'every fifth hour'))
## [1] "every 3 day"  "every 5 hour"

However with enough ambition, 'every 1/3 day' could be interpreted as '(every day) / 3' and end up giving the right result, with an appropriate redesign of how intervals are calculated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.