# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python [conda root]
#     language: python
#     name: conda-root-py
# ---

# +
# Database libraries
import psycopg2
import getpass

# Data processing libraries
import pandas as pd
import numpy as np
import itertools
# -

# create a database connection
user = "xxxx"
password = "<PASSWORD>"
host = "hst953.csail.mit.edu"
dbname = "mimic"
schema = "mimiciii"

# Connect to the database
con = psycopg2.connect(dbname=dbname, user=user, host=host, password=password)
# alternatively: password=getpass.getpass(prompt='Password:'.format(user)))
cur = con.cursor()
cur.execute('SET search_path to {}'.format(schema))


# admissions.csv
query0 = \
"""
SELECT *
FROM admissions
"""
# read from the sql query to access the database
data = pd.read_sql_query(query0, con)


# export to excel spreadsheet
data.to_excel('admissions.xlsx', sheet_name='sheet1', index=False)


# callout.csv
query1 = \
"""
SELECT *
FROM callout
"""
data1 = pd.read_sql_query(query1, con)


data1.to_excel('callout.xlsx', sheet_name='sheet1', index=False)

# caregivers.csv
query2 = \
"""
SELECT *
FROM caregivers
"""
data2 = pd.read_sql_query(query2, con)


data2.to_excel('caregivers.xlsx', sheet_name='sheet1', index=False)

# chartevents.csv - COME BACK TO THIS ONE IT'S NOT DOWNLOADING
query3 = \
"""
SELECT *
FROM services
"""
data3 = pd.read_sql_query(query3, con)

# cptevents.csv
data3.to_excel('services.xlsx', sheet_name='sheet1', index=False)

# datetimeevents.csv
query4 = \
"""
SELECT *
FROM datetimeevents
"""
data4 = pd.read_sql_query(query4, con)

data4.to_excel('datetimeevents.xlsx', sheet_name='sheet1', index=False)

# +
# diagnoses_icd.csv

# +
# drgcodes.csv

# +
# d_cpt.csv

# +
# d_icd_diagnoses.csv

# +
# d_icd_procedures.csv

# +
# d_items.csv

# +
# d_labitems.csv

# +
# icustays.csv

# +
# inputevents_cv.csv

# +
# inputevents_mv.csv

# +
# labevents.csv

# +
# microbiologyevents.csv

# +
# noteevents.csv

# +
# patients.csv

# +
# prescriptions.csv

# +
# procedureevents_mv.csv

# +
# procedures_icd.csv

# +
# services.csv

# +
# transfers.csv
# -



StarcoderdataJupyterScriptsDedupFiltered