<jupyter_start><jupyter_text>infusionDrugContinuous infusions are documented here and are entered from the nursing flowsheet (either manually or interfaced from the hospital electronic health record system).Infusion drugs entered directly into the source system (eCareManager) by clinicians must include the concentration of the drug being infused. This is done by entering the "drugAmount" and "volumeOfFluid" and this is independent of the amount being infused (drugRate or infusionRate). Interfaced values from source EMRs may not contain the concentration.<jupyter_code># Import libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import psycopg2
import getpass
import pdvega

# for configuring connection 
from configobj import ConfigObj
import os

%matplotlib inline
# Create a database connection using settings from config file
config='../db/config.ini'

# connection info
conn_info = dict()
if os.path.isfile(config):
    config = ConfigObj(config)
    conn_info["sqluser"] = config['username']
    conn_info["sqlpass"] = config['password']
    conn_info["sqlhost"] = config['host']
    conn_info["sqlport"] = config['port']
    conn_info["dbname"] = config['dbname']
    conn_info["schema_name"] = config['schema_name']
else:
    conn_info["sqluser"] = 'postgres'
    conn_info["sqlpass"] = ''
    conn_info["sqlhost"] = 'localhost'
    conn_info["sqlport"] = 5432
    conn_info["dbname"] = 'eicu'
    conn_info["schema_name"] = 'public,eicu_crd'
    
# Connect to the eICU database
print('Database: {}'.format(conn_info['dbname']))
print('Username: {}'.format(conn_info["sqluser"]))
if conn_info["sqlpass"] == '':
    # try connecting without password, i.e. peer or OS authentication
    try:
        if (conn_info["sqlhost"] == 'localhost') & (conn_info["sqlport"]=='5432'):
            con = psycopg2.connect(dbname=conn_info["dbname"],
                                   user=conn_info["sqluser"])            
        else:
            con = psycopg2.connect(dbname=conn_info["dbname"],
                                   host=conn_info["sqlhost"],
                                   port=conn_info["sqlport"],
                                   user=conn_info["sqluser"])
    except:
        conn_info["sqlpass"] = getpass.getpass('Password: ')

        con = psycopg2.connect(dbname=conn_info["dbname"],
                               host=conn_info["sqlhost"],
                               port=conn_info["sqlport"],
                               user=conn_info["sqluser"],
                               password=conn_info["sqlpass"])
query_schema = 'set search_path to ' + conn_info['schema_name'] + ';'<jupyter_output>Database: eicu
Username: alistairewj<jupyter_text>Examine a single patient<jupyter_code>patientunitstayid = 242380
query = query_schema + """
select *
from infusiondrug
where patientunitstayid = {}
order by infusionoffset
""".format(patientunitstayid)

df = pd.read_sql_query(query, con)
df.head()<jupyter_output><empty_output><jupyter_text>Above we can see a patient is admitted on (or quickly administered after admission) two drugs: nitroglycerin and heparin. The `drugrate` contains the infusion rate (1000 units/hr for herparin, 10 mcg/min for nitroglycerin). Further, the `drugamount` and `volumeoffluid` likely indicate the contents of the bag holding the fluid: a 500 mL bag containing a total of 25,000 units for heparin, and a 250 mL bag containing a total of 50 mg of nitroglycerin (note the unit change between the rate/amount in the nitroglycerin bag).Sometimes patient drugs are dosed by weight - in those cases, the `patientweight` column would be populated.  Hospitals with data available<jupyter_code>query = query_schema + """
select 
  pt.hospitalid
  , count(distinct pt.patientunitstayid) as number_of_patients
  , count(distinct d.patientunitstayid) as number_of_patients_with_tbl
from patient pt
left join infusiondrug d
  on pt.patientunitstayid = d.patientunitstayid
group by pt.hospitalid
""".format(patientunitstayid)

df = pd.read_sql_query(query, con)
df['data completion'] = df['number_of_patients_with_tbl'] / df['number_of_patients'] * 100.0
df.sort_values('number_of_patients_with_tbl', ascending=False, inplace=True)
df.head(n=10)
df[['data completion']].vgplot.hist(bins=10,
                                    var_name='Number of hospitals',
                                    value_name='Percent of patients with data')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10231097150549696, 'fraction_numerical': 0.01009647745120036, 'mean_word_length': 3.677859391395593, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '182171', 'license': 'MIT', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1269, 'n_words': 366, 'path': 'notebooks/infusiondrug.ipynb', 'repo_name': 'vishwas1234567/eicu-code', 'size': '4457'}