-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
196 lines (169 loc) · 6.03 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env python3
import json
import csv
import time
import os
from tkinter import *
import easygui
import requests
import shutil
title = "Healthcare Cost Transparency Tool"
facilities = []
sites = {}
allurls = {}
class Hospital:
def __init__(self, location, url):
global facilities
self.location = location
self.url = url
facilities.append(location)
sites[location] = self
allurls[location] = url
################################################################################################################
# Add new hospitals here. The url should point to your .csv pricelist (open the url below for example formating)
h01 = Hospital("Local General Hospital", "https://github.com/se7enack/randomfiles/raw/main/hospital1.csv")
h02 = Hospital("Big City Hospital", "https://github.com/se7enack/randomfiles/raw/main/hospital1.csv")
h03 = Hospital("ACME Medical Center", "https://github.com/se7enack/randomfiles/raw/main/hospital1.csv")
################################################################################################################
def vars(x):
global csv_from_hospital_path
global json_file_path
global csv_file_path
csv_from_hospital_path = f"{x}-original.csv"
csv_file_path = f"{x}-fixed.csv"
json_file_path = f"{x}.json"
def pullfile(url):
# Pull file down from hosptial website
there = os.path.exists(json_file_path)
if there:
old = time.time() - os.path.getmtime(json_file_path) > (3 * 30 * 24 * 60 * 60)
if there == False or old:
print(f"{csv_from_hospital_path} is missing or older than 24hrs, downloading a fresh copy")
try:
r = requests.get(url, verify=False,stream=True)
r.raw.decode_content = True
with open(csv_from_hospital_path, 'wb') as f:
shutil.copyfileobj(r.raw, f)
found = 0
headerrow = "Code"
with open(csv_from_hospital_path, "r") as input:
with open(csv_file_path, "w") as output:
for line in input:
if line.startswith(headerrow):
found = 1
if found == 0:
pass
else:
output.write(line)
remove_file(csv_from_hospital_path)
load_json_from_csv_file_with_headers(csv_file_path, json_file_path)
except:
if there:
print("unable to download a fresh copy at this time, using local copy")
jsonify()
else:
exit(1)
else:
print(f"{csv_from_hospital_path} is newer than 24hrs, skipping download")
jsonify()
def start():
global data
global records
global facility
message = "Choose a facility"
facility = easygui.buttonbox(message, title, facilities)
happy = bool(facility)
if happy == True:
vars(sites[facility])
url = allurls[facility]
pullfile(url)
else:
exit(0)
def load_json_from_csv_file_with_headers(csv_file_path, json_file_path):
with open(csv_file_path, "r") as csv_file:
reader = csv.reader(csv_file)
headers = next(reader)
data = []
for row in reader:
data.append(dict(zip(headers, row)))
with open(json_file_path, "w") as json_file:
json.dump(data, json_file)
remove_file(csv_file_path)
jsonify()
def jsonify():
global records
global data
f = open(json_file_path)
data = json.load(f)
f.close()
records = len(data)
asktype()
def asktype():
message = "What are you looking to do?"
choices = ["Search by CPT", "Search by Description", "Exit"]
output = easygui.buttonbox(message, title, choices)
try:
if output == "Search by CPT":
options = menulevel("Code")
cpt = easygui.choicebox("Pick the item you want cost for:", "CPT Lookup", options)
happy = bool(cpt)
if happy == True:
pass
else:
exit(0)
k = level2("Code", cpt)
elif output == "Search by Description":
options = menulevel("Description")
description = easygui.choicebox("Pick the item you want cost for", "Description Lookup", options)
happy = bool(description)
if happy == True:
pass
else:
exit(0)
k = level2("Description", description)
else:
exit(0)
except:
exit(0)
# k is a list of the column headers
k = list(k)
# Remove the first three columns headers ("Cost", "Description", and "Type") so they aren't in the next menu
# In some cases 'Package/Line_Level' is there, if so it is also removed
if 'Package/Line_Level' in k:
del k[0:4:1]
else:
del k[0:3:1]
message = "Which charge would you like to see?"
choice = easygui.choicebox(message, title, k)
happy = bool(choice)
if happy == True:
pass
else:
exit(0)
try:
# If price is a float make sure it contains 2 decimal points and add "$" prefix
flt = float(data[record][choice])
cash = f"{flt:.2f}"
money = str(f"\n\n\n\n{data[record]['Description']}\n\n\n\nCPT Code: {data[record]['Code']}\n\n\n\n{choice}: ${cash}")
except:
money = data[record][choice]
choices = ["Do another", "Quit"]
p = easygui.buttonbox(money, facility, choices)
if p == "Do another":
start()
def remove_file(file_path):
if os.path.exists(file_path):
os.remove(file_path)
def level2(k, v):
global record
for record in range(records):
if data[record][k] == v:
return data[record].keys()
def menulevel(c):
# Return a list of items in the c column
values = []
for record in range(records):
x = data[record][c]
values.append(x)
return values
start()