Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# MediMemo-DevWeek2024

This application is currently in development. Our goal is to create a health app that prevents the loss of patient data during data entry due to network loss and seamlessly updates patient files once the connection is restored.
This application is currently in development. Our goal is to create a health app that prevents the loss of patient data during data entry due to network loss and seamlessly updates patient files once the connection is restored.

## Anticipated Features:

- Scheduling Tool
- Data Entry Tool
- Patient History Viewer
Expand Down Expand Up @@ -31,9 +32,8 @@

- To query the database with SQL commands, you must be given the login credientials by an administrator.
- Then you can use the **query** function defined in **fake_data/connect.py**:
- from fake_data.connect import query
- query("SELECT * FROM patients LIMIT 5")
- results will populate in query.csv
- from fake_data.connect import query
- query("SELECT \* FROM patients LIMIT 5")
- results will populate in query.csv

### Thank you!!

24 changes: 17 additions & 7 deletions fake_data/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
from configparser import ConfigParser
import os
from configparser import ConfigParser


def load_config(filename='database.ini', section='postgresql'):
def load_config(filename="database.ini", section="postgresql"):
"""

:param filename: (Default value = "database.ini")
:param section: (Default value = "postgresql")

"""
if not os.path.exists(filename):
raise FileNotFoundError(f"{filename} does not exist. Please request access to database.ini from the administrator.")
raise FileNotFoundError(
f"{filename} does not exist. Please request access to database.ini from the administrator."
)


parser = ConfigParser()
parser.read(filename)

Expand All @@ -16,10 +24,12 @@ def load_config(filename='database.ini', section='postgresql'):
for param in params:
config[param[0]] = param[1]
else:
raise Exception('Section {0} not found in the {1} file'.format(section, filename))
raise Exception("Section {0} not found in the {1} file".format(
section, filename))

return config

if __name__ == '__main__':

if __name__ == "__main__":
config = load_config()
print(config)
print(config)
25 changes: 18 additions & 7 deletions fake_data/connect.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
import csv

import psycopg2
from config import load_config
from tabulate import tabulate
import csv


def connect(config):
""" Connect to the PostgreSQL database server """
"""Connect to the PostgreSQL database server

:param config:

"""
try:
# connecting to the PostgreSQL server
with psycopg2.connect(**config) as conn:
print('Connected to the PostgreSQL server.')
print("Connected to the PostgreSQL server.")
return conn
except (psycopg2.DatabaseError, Exception) as error:
print(error)


def query(operation):
'''Fetch data from the PostgreSQL database server'''
"""Fetch data from the PostgreSQL database server

:param operation:

"""
try:
config = load_config()
with psycopg2.connect(**config) as conn:
with conn.cursor() as cur:
cur.execute(operation)
headers = [desc[0] for desc in cur.description]
results = cur.fetchall()
with open('query.csv', 'w', newline='') as file:
with open("query.csv", "w", newline="") as file:
writer = csv.writer(file)
writer.writerow(headers)
for item in results:
Expand All @@ -32,11 +43,11 @@ def query(operation):
print(error)


if __name__ == '__main__':
if __name__ == "__main__":
# config = load_config()
# connect(config)

headers, staff = query('SELECT * FROM staff LIMIT 2;')
headers, staff = query("SELECT * FROM staff LIMIT 2;")
# staff = query('SELECT * FROM staff;')
# print(headers)
# print(staff)
Expand Down
27 changes: 19 additions & 8 deletions fake_data/insurances.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
from faker import Faker
import csv
fake = Faker()

'''
from faker import Faker

fake = Faker()
"""
name VARCHAR UNIQUE
phone VARCHAR
'''
"""

insurances_list = ['Aetna', 'Blue Cross Blue Shield', 'Cigna', 'UnitedHealth Group', 'Centene Corp.', 'Kaiser Permanente', 'Humana', 'Health Care Services Corporation']
insurances_list = [
"Aetna",
"Blue Cross Blue Shield",
"Cigna",
"UnitedHealth Group",
"Centene Corp.",
"Kaiser Permanente",
"Humana",
"Health Care Services Corporation",
]

header = ['name', 'phone']
header = ["name", "phone"]

with open('insurances.csv', 'w', newline='') as file:
with open("insurances.csv", "w", newline="") as file:
writer = csv.writer(file)
writer.writerow(header)
for item in insurances_list:
writer.writerow([item, fake.random_int(min=1000000000, max=9999999999)])
writer.writerow(
[item, fake.random_int(min=1000000000, max=9999999999)])
133 changes: 83 additions & 50 deletions fake_data/insurances_patients_join.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from random import randrange
import csv
from faker import Faker
from random import randrange

import psycopg2
from config import load_config
from faker import Faker

fake = Faker()

#Assign patient a random insurance.
'''
# Assign patient a random insurance.
"""
insurance_id uuid
patient_id uuid
primary_insured_name varchar
Expand All @@ -16,58 +17,90 @@
primary_insured_relationship varchar
member_number varchar
group_number varchar
'''
"""

# save insurance_ids in a list


#save insurance_ids in a list
def list_insurances():
insurances = []
with open('insurance_ids.csv') as file:
reader_obj = csv.reader(file)
for row in reader_obj:
insurances.append(row[0])
insurances.pop(0) #remove the header
print("insurance 1:", insurances[0]) #test
num_insurances = len(insurances)
return insurances, num_insurances

#pair each patient with a random insurance
""" """
insurances = []
with open("insurance_ids.csv") as file:
reader_obj = csv.reader(file)
for row in reader_obj:
insurances.append(row[0])
insurances.pop(0) # remove the header
print("insurance 1:", insurances[0]) # test
num_insurances = len(insurances)
return insurances, num_insurances


# pair each patient with a random insurance


def loop_through_patients(insurances, num_insurances):
insurances_patients_join = []
with open('patient_ids.csv') as file_obj:
reader_obj = csv.reader(file_obj)
for row in reader_obj:
join = { "patient_id": row[0],
"insurance_id": insurances[randrange(0,num_insurances)],
# "primary_insured_name": fake.name(),
# "primary_insured_birthdate": fake.date_of_birth(),
# "primary_insured_SSN": fake.random_int(min=100000000, max=999999999),
# "primary_insured_relationship": fake.word()
}
insurances_patients_join.append(join)
insurances_patients_join.pop(0) #remove the header
print("join 1:", insurances_patients_join[0]) #test
return insurances_patients_join
"""

:param insurances:
:param num_insurances:

"""
insurances_patients_join = []
with open("patient_ids.csv") as file_obj:
reader_obj = csv.reader(file_obj)
for row in reader_obj:
join = {
"patient_id": row[0],
"insurance_id": insurances[randrange(0, num_insurances)],
# "primary_insured_name": fake.name(),
# "primary_insured_birthdate": fake.date_of_birth(),
# "primary_insured_SSN": fake.random_int(min=100000000, max=999999999),
# "primary_insured_relationship": fake.word()
}
insurances_patients_join.append(join)
insurances_patients_join.pop(0) # remove the header
print("join 1:", insurances_patients_join[0]) # test
return insurances_patients_join


# write offices_patient_join to a new csv file


def write_to_join_csv(insurances_patients_join):
with open('insurances_patients_join.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["insurance_id", "patient_id", 'primary_insured_name', 'primary_insured_birthdate', 'primary_insured_SSN', 'primary_insured_relationship', 'member_number', 'group_number'])
for join in insurances_patients_join:
writer.writerow([join["insurance_id"], join["patient_id"]])
"""

:param insurances_patients_join:

"""
with open("insurances_patients_join.csv", "w", newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerow([
"insurance_id",
"patient_id",
"primary_insured_name",
"primary_insured_birthdate",
"primary_insured_SSN",
"primary_insured_relationship",
"member_number",
"group_number",
])
for join in insurances_patients_join:
writer.writerow([join["insurance_id"], join["patient_id"]])


def query_patient_data():
config = load_config()
with psycopg2.connect(**config) as conn:
with conn.cursor() as cur:
cur.execute("SELECT * FROM patients")
patients = cur.fetchall()
print(type(patients))
return patients

if __name__ == '__main__':
# insurances, num_insurances = list_insurances()
# insurances_patients_join = loop_through_patients(insurances, num_insurances)
# write_to_join_csv(insurances_patients_join)
query_patient_data()
""" """
config = load_config()
with psycopg2.connect(**config) as conn:
with conn.cursor() as cur:
cur.execute("SELECT * FROM patients")
patients = cur.fetchall()
print(type(patients))
return patients


if __name__ == "__main__":
# insurances, num_insurances = list_insurances()
# insurances_patients_join = loop_through_patients(insurances, num_insurances)
# write_to_join_csv(insurances_patients_join)
query_patient_data()
Loading