Coder Social home page Coder Social logo

parserx's Introduction

ParseRx

Medication sig parser.

Features:

  • Custom Django Rest Framework API built in.
  • Custom ReactJS frontend review and demo tool w/ easy documentation reference.
  • API and Python module support parsing individual sigs and batch parsing CSV sigs.
  • Supports feedback loop from "customers" via API call.
  • Accepts NDCs or RXCUIs via API call to infer things like method, route, or dose form if missing from sig text.
  • Version controls sigs that parse differently after code changes. API has logic built in to return the most recent version that is positively reviewed, OR will always return the most recent version if there are no reviews.

Getting started

Instructions for Linux:

Clone repo and cd into parserx directory.

Create virutal environment

python3 -m venv venv
source venv/bin/activate

Install dependencies

pip install -r requirements.txt
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential

Initialize the database

How to initially setup MySQL: https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-20-04

Info on MySQLClient: https://pypi.org/project/mysqlclient/

Gunicorn/Nginx: https://realpython.com/django-nginx-gunicorn/#replacing-wsgiserver-with-gunicorn

Inital setup of MySQL

sudo mysql_secure_installation

Follow prompts to create root user password and accept default settings.

sudo mysql
CREATE USER 'parserx'@'localhost' IDENTIFIED BY 'P@ssw0rd';
GRANT ALL PRIVILEGES ON parserx.* TO 'parserx'@'localhost' WITH GRANT OPTION;
quit

(back in terminal)

mysql -u parserx -p
<enter password = P@ssw0rd>
drop database if exists parserx;
create database parserx;
quit

(back in terminal)

source venv/bin/activate
python manage.py makemigrations
python manage.py makemigrations sig
python manage.py migrate
python manage.py createsuperuser
<follow createsuperuser prompts>
python manage.py runserver localhost:8000

Authenticate and parse a sig via the API

Recommend using Postman

1.) Authenticate with user

POST localhost:8000/auth/token/login/
Headers
Content-Type application/json
Body
{
	"username": "<superuser username>",
	"password": "<password>"
}
Response
{
    "auth_token": "<auth token>"
}

2.) Run query via API

POST localhost:8000/sig/
Headers
Content-Type    application/json
Authorization   Token <auth token>
Body
{
    "sig_text": "take 1-2 tabs po qid prn anxiety x7d"
}

Parsing / reparsing an entire CSV of sigs

NOTE: to change the csv file that the API runs: - Go to parserx/sig/views - Edit filepath in the create method of CsvSigCreateViewSet - The csv file is stored in parserx/parsers/csv

Edit the name of the csv file in parserx.io/sig/views.py to be the csv you want to parse.

***NOTE: ensure you have converted it to just one column full of sigs with no header.

This will create new versions of parsed sigs if code has changed to parse a sig differently. Old versions will still be visible using the Review tool in the frontend.

Postman

1.) Authenticate with superuser

POST localhost:8000/auth/token/login/
Headers
Content-Type application/json
Body
{
	"username": "<superuser username>",
	"password": "<password>"
}
Response
{
    "auth_token": "<auth token>"
}

2.) Run ParseRx on csv file via API

POST localhost:8000/csv_sig/
Headers
Content-Type	application/json
Authorization	Token <auth token>

Submiting batch sig reviews to ParseRx via API (feedback loop)

This would be for a "customer" that is receiving parsed sigs and wants to send back some feedback as a batch every night via the API.

1.) Get auth token from ParseRx

POST api.parserx.io/auth/token/login/
Headers
Content-Type application/json
Body
{
	"username": "<customer username>",
	"password": "<password>"
}
Response
{
    "auth_token": "<auth token>"
}

2.) Sumbit batch reviews to ParseRx

POST api.parserx.io/sig_reviewed/
Headers
Content-Type application/json
Authorization Token <auth token>
Body
[
    {
        "owner": <user_id>,
        "sig_parsed": <sig_parsed_id>,
        "sig_correct": "<true|false>",
        "sig_corrected": "<sig_corrected>"        
    }

    ...

]

Starting the frontend

If your API is hosted somewhere other than localhost:8000, go to frontend/webpack.config.js and change apiUrl (near the bottom) to the correct URL.

cd frontend
npm install
npm start

Go to localhost:8080

Log in with superuser username and password.

Once logged in, you should be taken back to the homepage. You need to refresh the homepage to see additional options in the nav bar for "Review" and "Demo".

Review - lets you review previously parsed sigs and mark them as correct or incorrect. If incorrect, you can select which components are incorrect. This also gets stored in the database.

Demo - lets you enter individual free text sigs and shows the parsed response.

Sometimes a malformed parsed sig will prevent the Review page from loading. If this happens, either remove the sig from the database in MySQL phpMyadmin or enter 10 new sigs in the Demo page to clear it out.

API documentation

Request authentication

All requests must have an API key.

Create your own API key at http://localhost:8000/admin

To authenticate:

Headers of your request must include:

Authorization: Api-Key <your API key here>
Content-Type: application/json

Invalid API keys will result in an HTTP 401, Unauthorized error.

API resources

The ParseRx API expects HTTP URL request parameters and returns JSON responses. All requests must include your API key.

Request

POST /sig/ = Generate / return a parsed sig and information on review status.

URL = http://localhost:8000/sig/

Format = JSON

Body

  • sig_text (REQUIRED) string - your sig text here
  • ndc (optional) numeric ndc11 string - if you want to infer sig elements by ndc
  • rxcui (optional) numeric rxcui string - if you want to infer sig elements by rxcui

Example:

{
    "sig_text": "tk 1-2 tab po qid x10d prn pain",
    "ndc": "12345678911", 
    "rxcui": "123456"
}

NOTE: Depending on whether you submit a sig that ParseRx has parsed before, you will receive two different server responses.

  • HTTP 200, OK - ParseRx has parsed this sig before, so it is just returning that previously parsed sig from the database.
  • HTTP 201, Created - ParseRx has not parsed this sig before, so it is dynamically parsing it, saving it to the database, and returning the result.

Response

sig_text

A string containing the modified sig_text from the request, converted to lower case, extraneous characters removed, and duplicate spaces converted to single spaces.

sig_parsed

A JSON object containing all the parsed components of the free text sig. See details of each component below.

sig_inferred

A JSON object containing all the inferred sig components if the request included an ndc or rxcui parameter. See details of each component below.

This entire object will only appear if a valid ndc or rxcui are included as a request parameter. If both are included, ndc will take precedence over rxcui.

original_sig_text

A string containing the original, un-modified sig_text from the request.

Parsed sig components

method

How the medication is administered (i.e. take, inject, inhale).

dose

dose_max

dose_unit

How much medication patient is instructed to take based on dosage (i.e. 2 tablets, 30 units, 1-2 puffs).

Numbers represented as words in the sig will be converted to integers (i.e. “one” will be converted to 1).

strength

strength_max

strength_unit

How much medication the patient is instructed to take based on strength (i.e. 500 mg, 15 mL, 17 g).

NOTE: ParseRx intentionally does not parse multiple ingredient strengths (i.e. if 5/325 mg is in a sig, it will return null for strength).

route

Route of administration of the medication (i.e. by mouth, via inhalation, in left eye).

frequency

frequency_max

period

period_max

period_unit

time_duration

time_duration_unit

day_of_week

time_of_day

when

offset

bounds

count

frequency_readable

How often medication should be administered (i.e. every 4-6 hours, three times daily, once daily in the morning with meal).

Due to the complexity and variety of medication instructions, these elements are based off of an existing standard - FHIR Timing.

For convenience, a frequency_readable is generated to represent a human-readable representation of the sig frequency.

duration

duration_max

duration_unit

How long the patient is instructed to take the medication (i.e. for 7 days, for 7-10 days, for 28 days).

NOTE: this is different from days’ supply, which represents how long a given supply of medication should last.

as_needed

indication

Whether the medication should be taken “as needed” (i.e. PRN), and the specific reason the patient is taking the medication (i.e. for pain, for wheezing and shortness of breath, for insomnia).

NOTE: indication may be populated even if as_needed is false. There are chronic indications represented in sigs as well (i.e. for cholesterol, for high blood pressure, for diabetes).

sig_reviewed_status

This is an indicator that a pharmacist / pharmacy resident has reviewed the sig.

Depending on the review status of the sig, it will return either unreviewed, correct, incorrect, or unknown.

sig_reviewed

If sig_reviewed_status is unreviewed or unknown, this will be null. Otherwise, this will return an object containing the reviewed components of the parsed sig. See details of each component below.

NOTE: ParseRx will be constantly improving, and as such, there may be multiple different versions of parsing a given sig. Each of these parsing versions will be reviewed by a pharmacist or pharmacy resident in time. If there exists a version that has a sig_reviewed_status of correct, this is the version that will be returned. Otherwise, the most recently parsed version of the sig will be returned.

IMPORTANT: Pay close attention to the sig_reviewed_status and sig_reviewed object. It is your responsibility to use this information safely.

Reviewed sig components

sig_correct

Whether the sig is considered to be parsed correctly overall or not.

method_status

dose_status

strength_status

route_status

frequency_status

duration_status

indication_status

If the sig is not considered to be parsed correctly overall, there may be values in these fields representing what the specific issue(s) are.

  • 0 = incorrect - ParseRx returned something for this component, but it was not correct
  • 1 = missing - ParseRx did not return anything for this component, when it should have
  • 2 = optimize - ParseRx returned something for this component, but it could be improved

Inferred sig components

method

dose_unit

route

This entire object will only appear if a valid ndc or rxcui are included as a request parameter. If both are included, ndc will take precedence over rxcui.

Any or all of the inferred sig components may be null if it is not possible to infer them.

parserx's People

Contributors

jrlegrand avatar

Watchers

 avatar

Forkers

coderxio

parserx's Issues

Add indications

take 1 tablet by mouth every day for thyroid - labs due

take 1 capsule 100 mg total by mouth 2 times daily for 7 days for acute bacterial infection of the sinuses

1-to-2 tablets evaluates as 2 tablets

take 1-to-2 tablets by mouth 2 to 3 hours before bedtime

Different example
take 1& 1/2- tabs by mouth every day

Another different example
take one-25 milligram tablet along with 100 milligram tablet twice daily maximum daily dose 50 mg

Another different example
1 1/2 tablets 4 times daily as directed for severe agitation catatonia

Duration work

  • 1 drop ou bid x 1-2 wks then stop

  • 1 app top bid instr x 3 wks then 2-3 times a wk as needed

f1w

  • 1t po d f1w then 2t po d f1w

Method work

  • taking 1 tablet dailytaking 1 tablet daily

Chewable should be method chew

  • 1 tablet chewable at bedtime after brushing teeth

  • 1 tab s chewed qpm

  • test bg twice daily or as directed

  • rinse 1/2 oz bid for 30 sec for 14 days

Route work

Evaluates to via inhalation (wrong)

  • spray 2 puffs by each nostril route every day

Should prefer left ear over otic

  • 4 drp by otic ear route 2 times per day left ear

Account for typo

  • inject intramuscularrly every 12weeks -

vn == via nostrils?

  • 2 sprays vn bid prn

Topical routes

  • apply small amount to bilateral legs arms and abdomen

  • 1 packets top qamx30 days

  • 5 gtts in bilateral ears qhs for 7 days

  • 2 intranasal every day as needed

  • take 40 units s/q once daily

  • place 1 film to the gum daily 14 films for 14 day xb2891706

  • place 1 films inside the cheek tid for opioid dependence 45 films for 15 days xb2891706

  • pea-sized amount on a q-tip inserted approximately 1cm into anus three times a day

Structure max daily dose MDD

Basic:

take 1 tablet by mouth in the morning -- max 1 tab/day

take 1 tablet by mouth every 6 hours as needed for pain do not take more than 8 tablets in 24 hour period

take 1 capsule by mouth three times daily do not exceed 3 per 24 hours mdd 3

2 po q8 hrs prn pain max dose 6 tabs per day max 3000mg/day

MDD:

place 1 tablet under the tongue 2 times daily max daily dose: 2 tablets

1 tablet by mouth every 6 hours for chronic severe pain mdd 4

1tab sl three times a day mdd 3. reference : 162955383 xa4557166 mdd 3

take 1 capsule by mouth 2 two times daily max daily amount: 150 mg

1 tablet orally three times a day mdd=3 30 days

take 1 tablet by mouth every six hours as needed severe pain initial therapy for up to 3 days max daily amount 4 tablets

take one tablet by mouth every 8 hours as needed maximum daily dose is 3 tablets

Three times daily evaluates as daily

take 1 tablet 3 times daily as needed mdd 6mg per day

Different example
apply thinly on the left upper arm rash 1-2 times daily until resolved

Structure additional info

Capturing

may fill:
2 tabs po bidinstr:may fill 7/6/2022
1 tabs po tidprn:as needed for paininstr:maximum of 90/month may fill 7/2/2022

for suspected overdose call 911 / if no response in x min repeat
0.1 ml nasal as directedinstr:for suspected overdose call 911. if no response in 3 min repeat

take with x medication
take 1 tablet by mouth every day take with medroxyprogesterone

Non Capturing

on an empty stomach
take 1 tablet by mouth in the morning on an empty stomach
take 1 tablet by mouth every morning on an empty stomach 30
take 1 tablet by mouth once daily in the morning on an empty stomach 30

shake well before using
5 drops otic qidx10 daysinstr:shake well before using

one hour before sexual activity
take 1 oral tablet one hour before sexual activity

take with 12+ ounces of only water at least one half-hour before any meal beverage or medication and remain standing upright do not lie down or recline for at least 30 minutes after administering
take 1 tablet by mouth once weekly in the morning take with 12+ ounces of only water at least one half-hour before any meal beverage or medication and remain standing upright do not lie down or recline for at least 30 minutes after administering

allow to disintegrate / no chewing or crushing
place one whole tablet on the tongue and allow it to disintegrate without chewing or crushing one time daily
take 1 tablet 150 milligram total by mouth every morning swallow whole do not crush break or chew

allow to dissolve
place 1 film under the tongue and allow to dissolve sublingual twice a day 30 days

at onset of migrate / take with fluids
take one 1 tablet by mouth at onset of migraine with fluids

as directed
take 1 tablet by mouth every day as directed

retain in mouth as long as possible before swallowing
5 ml po qid x10 day s instr retain in mouth as long as possible before swallowing

after brushing teeth
1 tablet chewable at bedtime after brushing teeth

leave patch on for up to 12 hours and then leave off for at least 12 hours
place 1 patch transdermal q 24 hours leave patch on for up to 12 hours and then leave off for at least 12 hours prn pain

leave in for 1 min / rinse
wash by topical route every day the affected area s leave in for 1 min and rinse

as directed per package instructions
take by oral route as directed per package instructions

patient needs an appointment
1 tab s po daily instr pt needs an appt !

no further refills
take one 1 capsule by mouth in the morning no further refills until seen

take at same time each day / gargle after each use
inhale 1 puff by inhalation route once daily at the same time each day gargle after each use

take on full stomach / take with antacid
take 1 tablet oral 2 times per day prn for 15 days take on a full stomach or with an antacid

rotate sites
inject 0.5ml subcutaneously once per week - rotate sites
inject 0.5 milligram sub-cutaneously every week rotate injection sites

until finished
take 1 tablet twice daily after meals until finished
take 1 tab every 8 hours until finish

may sprinkle contents of capsule on food / do not chew capsule
take 1 capsule 30 mg total by mouth every morning max daily dose 30 mg may sprinkle contents of capsule on food do not chew capsule

shake well before each use
inhale 1-2 puffs into the lungs every 4 hours as needed for wheezing shake well before each use

may cause drowsiness
one 1 tablet by mouth twice a day may cause drowsiness

Frequency work

bed time with a space

  • 1 tablets before bed time

Once does not capture

  • 5 ml po once instr take on 7/8/22

NOTE: make sure "once daily" doesn't start capturing as "once"

Should be once

  • 2 tabs by mouth x 1

Specific topical route locations and demote "apply"

apply to the affected areas on the back torso and arms for 2 weeks when flaring

This captures "apply" as "topically" where it should probably be "to affected area"
apply sufficient amount to affected area once every day

apply bid to aa on back x 2 weeks as needed

Ophthalmic example - evaluates as topically, not left eye
apply 1 drop to the left eye 4 times a day for 7 days with eyelid closure for 2 minutes

Not sure if we have "to eye lid" as route, but this should be added if not. Don't know what rast means
apply to eye lid rast three times a day

bid to arms

apply to left great toe 3x a day for 5-7 days

apply 1 drop to each eye at bedtime with eyelid closure for 2 minutes

1 application 2 times a day to clean dry skin to affected area for 30 days

apply to the involved areas at bedtime

apply 1 gram to vagina three times a week as directed

apply to blood blister on leg twice a day

apply topically to buttocks externally twice a day 30 days

1 application 4-5 grams intravaginally nightly x 6 weeks

Indication work

"to prevent" as a trigger for indication

  • take 1 tablet by mouth twice daily regularly to prevent migraines

  • take 1 capsule by mouth every day for mood and pain

  • take 1 tablet by mouth every day for choleserol in diabetes

  • take 1 tablet by mouth 2 times per day with meals for type 2 diabetes

  • 1 tablet s q4h every 4 hours prn n/v restlessness/agitation

  • take 1 capsule 50 milligram total by mouth at bedtime for urinary tract infection

  • take 3 tablets by mouth daily for 90 days indications ulcerative colitis an inflammatory condition of the intestines

  • spray 1 squirt in the nostrils select frequency as needed prn overdose

  • take 238 g by mouth once for 1 dose indications emptying of the bowel

Maybe add "indications" as trigger for non-PRN indication capture?

  • take 1 tablet by mouth daily indications major depressive disorder

  • 1 capsule nightly for neuropathic pain fill when due mdd 1

  • take 1 capsule 300 mg total by mouth 3 times daily for 5 days for infection of the skin and/or soft tissue

  • 1 tab s po daily instr prn panic attack

  • take 1 tablet by mouth daily for hyperlipidemia

Evaluates to pain - should evaluate to nerve pain

  • take as directed 1-2 caps po three times a day for nerve pain

  • place 1 films inside the cheek tid for opioid dependence 45 films for 15 days xb2891706

  • take 1 tab by mouth for one dose for prophylaxis for tick bite

  • apply daily to the face chest and shoulders in the am

  • 1 tab s po daily x30 day s instr for prostate swelling

  • take 1 tab by mouth once daily as needed for panic attacks

  • take 1 tablet delayed release enteric coated orally qday for stroke max daily dose 325mg

  • take 1 tablet orally qday for heart max daily dose 40mg

  • take 1 tablet orally qday for blood pressure/hair max daily dose 50mg

  • take 1 tablet by mouth 3 three times daily as needed anxiety heart rates

  • take half a tablet 12.5 mg by mouth daily for heart failure

Hypothyroidism synonym

  • take 1 capsule 200 mcg by mouth daily in the morning on an empty stomach for underactive thyroid

  • twice a day or as directed for blood glucose monitoring

prnf

  • 1t po qid prnf anxiety

This misses the indication

  • 1 tabs po q12hrprnas needed for anxiety

1&1/2 evaluates to 0

take 1&1/2 tablets by mouth every night at bedtime

Different example
take half of a tablet 5 mg by mouth daily

Prevent take with and combined dosage from resulting in strengths

take 1 capsule by mouth daily take with a 75 mg tablet for a combined dosage of 225 mg once a day

take 1 tablet by mouth once a day in addition to 5mg tab for total of 25mg daily

MDD example
take 1 tablet by mouth twice a day maximum daily dose = 2 mdd 40mg

1 by mouth every day take in addition to 150 mcg- increasing daily dose to 175 mcg- pt wants to finish current supply of 150 mcg tabs

Capture hours before x

1 capsule 1 to 3 hours before bedtime orally once at bedtime 30 days

take 3 tablets by mouth two hours before bedtime

1 tab by mouth 1 hour prior to procedure mdd 1 tablet

4 capsule orally 1 hours before dental work 2 years after joint replacement surgery

1 tab qd one hour ac po

twice a week 30 minutes before torsemide

Dose unit work

  • 1 applic by topical route 2 times per day

  • 1 appl by apply externally route twice daily apply bilateral thigh area until clear

  • use one troche 5 times daily for 5 days

Currently evaluates to gum - should add gummie

  • take 1 gummie by mouth at bedtime

Should evaluate to application, but evaluates to film

  • 1 app top bid x7 day s instr apply a thin film

Evaluates to oral capsule - should probably just be capsule

  • take 1 oral capsule every morning

  • 4 drp by otic ear route 2 times per day left ear

Misses tablet

  • 1tb

Maybe normalize to applicatorful

  • 0.5 applicator per vagina nightly 2x/week

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.