{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Parse out medications from discharge summaries in MIMIC " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import os\n", "import pandas as pd\n", "import psycopg2\n", "import getpass\n", "import re\n", "\n", "# Import the finddrugs module\n", "import finddrugs" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Create a database connection\n", "user = 'postgres'\n", "host = 'localhost'\n", "dbname = 'mimic'\n", "schema = 'mimiciii'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Connect to the database\n", "con = psycopg2.connect(dbname=dbname, user=user, host=host, \n", " password=getpass.getpass(prompt='Password:'.format(user)))\n", "cur = con.cursor()\n", "cur.execute('SET search_path to {}'.format(schema))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Get the notes to be analysed\n", "# NOTE: we are limiting the query to 100 rows here\n", "query = \\\n", "\"\"\"\n", "SELECT n.row_id, n.subject_id, n.hadm_id, n.category, n.description, n.text\n", "FROM noteevents n\n", "WHERE n.category like 'Discharge summary'\n", "LIMIT 100;\n", "\"\"\"\n", "\n", "data = pd.read_sql_query(query,con)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Search the notes\n", "finddrugs.search(data)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | ROW_ID | \n", "SUBJECT_ID | \n", "HADM_ID | \n", "HIST_FOUND | \n", "DEPRESSION | \n", "ADMIT_FOUND | \n", "DIS_FOUND | \n", "GEN_DEPRESS_MEDS_FOUND | \n", "GROUP | \n", "SSRI | \n", "MISC | \n", "citalopram | \n", "escitalopram | \n", "fluoxetine | \n", "fluvoxamine | \n", "paroxetine | \n", "sertraline | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "174 | \n", "22532 | \n", "167853 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
1 | \n", "175 | \n", "13702 | \n", "107527 | \n", "1 | \n", "0 | \n", "1 | \n", "1 | \n", "0 | \n", "3 | \n", "1 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
2 | \n", "176 | \n", "13702 | \n", "167118 | \n", "1 | \n", "1 | \n", "1 | \n", "1 | \n", "0 | \n", "3 | \n", "1 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
3 | \n", "177 | \n", "13702 | \n", "196489 | \n", "1 | \n", "1 | \n", "1 | \n", "1 | \n", "0 | \n", "3 | \n", "1 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
4 | \n", "178 | \n", "26880 | \n", "135453 | \n", "1 | \n", "0 | \n", "1 | \n", "1 | \n", "0 | \n", "3 | \n", "1 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "