In [ ]:
import os
import pandas as pd
import psycopg2
import getpass
import re
# Import the finddrugs module
import finddrugs
In [ ]:
# Create a database connection
user = 'postgres'
host = 'localhost'
dbname = 'mimic'
schema = 'mimiciii'
In [ ]:
# Connect to the database
con = psycopg2.connect(dbname=dbname, user=user, host=host,
password=getpass.getpass(prompt='Password:'.format(user)))
cur = con.cursor()
cur.execute('SET search_path to {}'.format(schema))
In [ ]:
# Get the notes to be analysed
# NOTE: we are limiting the query to 100 rows here
query = \
"""
SELECT n.row_id, n.subject_id, n.hadm_id, n.category, n.description, n.text
FROM noteevents n
WHERE n.category like 'Discharge summary'
LIMIT 100;
"""
data = pd.read_sql_query(query,con)
In [ ]:
data.head()
In [ ]:
# Search the notes
finddrugs.search(data)
In [9]:
# load the output to a dataframe
medications = pd.read_csv('output.csv')
medications.head()
Out[9]: