-
Notifications
You must be signed in to change notification settings - Fork 0
/
UHC_BOT
298 lines (264 loc) · 14.4 KB
/
UHC_BOT
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from Secret import username, password # log in details in an external file
from Data import Data # class file to help store info. Example:
# class Data:
# def __init__(self, name, last_name, us_dob, us_dos, voucher, client):
# self.name = name
# self.last_name = last_name
# self.us_dob = us_dob
# self.us_dos = us_dos
# self.voucher = voucher
# self.client = client
import time
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import xlrd
import csv
from bs4 import BeautifulSoup as soup
# Choose the delay between certain action of the BOT (depending on how fast/slow the system runs)
optimization = 2
# Select how long the bot waits for a page to load, before shutting down
wait_time = 20
# BOT will look for Excel file and save a new file here
loc = 'C://Users/henrikas.budrys/Desktop/UHC BOT/'
# BOT will save claim details here
files_loc = 'C://Users/henrikas.budrys/Desktop/UHC BOT/Downloaded PDFs/'
# Name of Excel the BOT reads
current_file = 'UHC_scrape.xlsx'
# BOT creates new Excel and calls it
new_file = 'UHC_status.csv'
wb = xlrd.open_workbook(loc + current_file)
sheet = wb.sheet_by_index(0)
# Read Excel file
list = []
for i in range(sheet.nrows)[1:]:
name = sheet.row_values(i)[0]
lastname = sheet.row_values(i)[1]
dob = sheet.row_values(i)[2]
dos = sheet.row_values(i)[3]
proper_dob = xlrd.xldate_as_tuple(dob, wb.datemode)
us_dob = str(proper_dob[1]) + '/' + str(proper_dob[2]) + '/' + str(proper_dob[0])
proper_dos = xlrd.xldate_as_tuple(dos, wb.datemode)
us_dos = str(proper_dos[1]) + '/' + str(proper_dos[2]) + '/' + str(proper_dos[0])
voucher = int(sheet.row_values(i)[4])
client = sheet.row_values(i)[5]
list.append(Data(name, lastname, us_dob, us_dos, voucher, client))
# Opens Chrome
driver = webdriver.Chrome('C://Users/henrikas.budrys/ChromeDriver/chromedriver.exe')
driver.get('https://provider.linkhealth.com/apps/secure/dashboards/provider-dashboard/')
# Log in to web by using credentials from Secret.py
def log_in_to_web():
button = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH, '//*[@id="SignIn"]')))
time.sleep(optimization)
driver.find_element_by_xpath('//*[@id="userNameId_input"]').send_keys(username)
driver.find_element_by_xpath('//*[@id="passwdId_input"]').send_keys(password)
button.click()
log_in_to_web()
# Goes to "Claims Link" tab
def open_claims():
claims = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH, '//*[@id="app"]/div/div[1]/div[2]/div[2]/div[5]/div[5]')))
claims.click()
open_claims()
def switch_to_HMG():
button = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH,
'//*[@id="search-provider-changebtn"]')))
button.click()
time.sleep(optimization)
provider = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH,
'//*[@id="change-provider-modal"]/div[2]/fieldset/div[1]/div/div')))
provider.click()
driver.find_element_by_xpath('//*[@id="react-select-provider-select-organizations-option-2"]').click()
time.sleep(optimization)
corporate = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH,
'//*[@id="change-provider-modal"]/div[2]/fieldset/div[2]/div/div/div[1]')))
corporate.click()
driver.find_element_by_xpath('//*[@id="react-select-provider-select-corporates-option-0"]').click()
time.sleep(optimization)
taxid = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH,
'//*[@id="change-provider-modal"]/div[2]/fieldset/div[3]/div/div/div[1]')))
taxid.click()
driver.find_element_by_xpath('//*[@id="react-select-provider-select-taxidnumbers-option-0"]').click()
time.sleep(optimization)
care = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH,
'//*[@id="change-provider-modal"]/div[2]/fieldset/div[4]/div/div/div[1]')))
care.click()
driver.find_element_by_xpath('//*[@id="react-select-provider-select-providers-option-0"]').click()
time.sleep(optimization)
driver.find_element_by_xpath('//*[@id="provider-select-submit"]').click()
time.sleep(optimization + 1)
def switch_to_RDMGA():
button = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH,
'//*[@id="search-provider-changebtn"]')))
button.click()
time.sleep(optimization)
provider = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH,
'//*[@id="change-provider-modal"]/div[2]/fieldset/div[1]/div/div')))
provider.click()
driver.find_element_by_xpath('//*[@id="react-select-provider-select-organizations-option-8"]').click()
time.sleep(optimization)
corporate = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH,
'//*[@id="change-provider-modal"]/div[2]/fieldset/div[2]/div/div/div[1]')))
corporate.click()
driver.find_element_by_xpath('//*[@id="react-select-provider-select-corporates-option-0"]').click()
time.sleep(optimization)
taxid = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH,
'//*[@id="change-provider-modal"]/div[2]/fieldset/div[3]/div/div/div[1]')))
taxid.click()
driver.find_element_by_xpath('//*[@id="react-select-provider-select-taxidnumbers-option-0"]').click()
time.sleep(optimization)
care = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH,
'//*[@id="change-provider-modal"]/div[2]/fieldset/div[4]/div/div/div[1]')))
care.click()
driver.find_element_by_xpath('//*[@id="react-select-provider-select-providers-option-0"]').click()
time.sleep(optimization)
driver.find_element_by_xpath('//*[@id="provider-select-submit"]').click()
time.sleep(optimization + 1)
def switch_to_RDMG():
button = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH,
'//*[@id="search-provider-changebtn"]')))
button.click()
time.sleep(optimization + 1)
provider = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH,
'//*[@id="change-provider-modal"]/div[2]/fieldset/div[1]/div/div')))
provider.click()
driver.find_element_by_xpath('//*[@id="react-select-provider-select-organizations-option-7"]').click()
time.sleep(optimization + 1)
corporate = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH,
'//*[@id="change-provider-modal"]/div[2]/fieldset/div[2]/div/div/div[1]')))
corporate.click()
driver.find_element_by_xpath('//*[@id="react-select-provider-select-corporates-option-5"]').click()
time.sleep(optimization + 1)
taxid = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH,
'//*[@id="change-provider-modal"]/div[2]/fieldset/div[3]/div/div/div[1]')))
taxid.click()
driver.find_element_by_xpath('//*[@id="react-select-provider-select-taxidnumbers-option-0"]').click()
time.sleep(optimization + 1)
care = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH,
'//*[@id="change-provider-modal"]/div[2]/fieldset/div[4]/div/div/div[1]')))
care.click()
driver.find_element_by_xpath('//*[@id="react-select-provider-select-providers-option-0"]').click()
time.sleep(optimization + 1)
driver.find_element_by_xpath('//*[@id="provider-select-submit"]').click()
time.sleep(optimization + 1)
# If the TIN checkbox is not selected, clicks on it
def check_box():
if not driver.find_element_by_xpath('// *[ @ id = "search-provider-tinonly"]').is_selected():
driver.find_element_by_xpath('// *[ @ id = "search-provider-tinonly"]').click()
# Fills in users credentials
def look_up_status():
submit = WebDriverWait(driver, wait_time).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="submit-search-button"]')))
check_box()
time.sleep(optimization)
driver.find_element_by_xpath('//*[@id="select-radio-membername-dob"]').click()
driver.find_element_by_xpath('//*[@id="select-lastname-input"]').send_keys(Keys.CONTROL + "a", Keys.DELETE)
driver.find_element_by_xpath('//*[@id="select-lastname-input"]').send_keys(line.last_name)
driver.find_element_by_xpath('//*[@id="select-firstname-input"]').send_keys(Keys.CONTROL + "a", Keys.DELETE)
driver.find_element_by_xpath('//*[@id="select-firstname-input"]').send_keys(line.name)
time.sleep(optimization/2)
driver.find_element_by_xpath('//*[@id="select-dob-input"]').clear()
driver.find_element_by_xpath('//*[@id="select-dob-input"]').click()
driver.find_element_by_xpath('//*[@id="select-dob-input"]').send_keys(line.us_dob)
time.sleep(optimization/2)
driver.find_element_by_xpath('//*[@id="select-startdate-input"]').clear()
driver.find_element_by_xpath('//*[@id="select-startdate-input"]').click()
driver.find_element_by_xpath('//*[@id="select-startdate-input"]').send_keys(line.us_dos)
submit.click()
# Checks if claim status is found or not
def check_exists_by_xpath(xpath):
try:
driver.find_element_by_xpath(xpath)
except NoSuchElementException:
return False
return True
# Scrape info from primary claim status page
def scrape_primary():
sort_by_age = WebDriverWait(driver, wait_time).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="root"]/div/div[4]/div[2]/div/div/div[2]/div[3]/div/div[2]/div[1]/div[1]/div/div[1]')))
sort_by_age.click()
sort_by_age.click()
time.sleep(optimization)
status = driver.find_element_by_xpath('//*[@id="root"]/div/div[4]/div[2]/div/div/div[2]/div[3]/div/div[2]/div[1]/div[2]/div[1]/div/div[8]/div')
claim_status = status.get_attribute('innerHTML')
return str(claim_status)
# Scrape info from secondary claim status page
def scrape_secondary():
driver.find_element_by_xpath('//*[@id="root"]/div/div[4]/div[2]/div/div/div[2]/div[3]/div/div[2]/div[1]/div[2]/div[1]/div/div[3]').click()
time.sleep(optimization)
select_all_columns = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.XPATH, '// *[ @ id = "toggle-selection-select-all-columns"]')))
select_all_columns.click()
time.sleep(optimization)
claimnr = driver.find_element_by_xpath('//*[@id="summary-data-claimnumber"]')
billed = driver.find_element_by_xpath('//*[@id="root"]/div/div[4]/div[2]/div/div[5]/div[3]/div/div/div[2]/table/tbody[2]/tr[2]/td[7]/div/span')
paid = driver.find_element_by_xpath('//*[@id="root"]/div/div[4]/div[2]/div/div[5]/div[3]/div/div/div[2]/table/tbody[2]/tr[2]/td[8]/div/span')
allowed = driver.find_element_by_xpath('//*[@id="root"]/div/div[4]/div[2]/div/div[5]/div[3]/div/div/div[2]/table/tbody[2]/tr[2]/td[9]/div/span')
pr = driver.find_element_by_xpath('//*[@id="root"]/div/div[4]/div[2]/div/div[5]/div[3]/div/div/div[2]/table/tbody[2]/tr[2]/td[12]/div/span')
claim_number = claimnr.get_attribute('innerHTML')
billed_amount = billed.get_attribute('innerHTML')
paid_amount = paid.get_attribute('innerHTML')
allowed_amount = allowed.get_attribute('innerHTML')
patient_responsibility = pr.get_attribute('innerHTML')
return str(claim_number), str(billed_amount), str(paid_amount), str(allowed_amount), str(patient_responsibility)
# Expands table
def expand_status():
driver.find_element_by_xpath(
'//*[@id="root"]/div/div[4]/div[2]/div/div[5]/div[3]/div/div/div[2]/table/thead/tr/th[1]/div/button').click()
def scrape_all_data():
content = driver.page_source
page_soup = soup(content, 'html.parser')
boxes_main = page_soup.findAll('div', {'class': 'box'})
voucher_number_main = page_soup.findAll('p', {'id': 'summary-data-patientaccountnumber'})
billing_provider = page_soup.findAll('span', {'id': 'providerinfo-label-billingprovider'})
act_billing_provider = page_soup.findAll('p', {'id': 'providerinfo-data-billingprovider'})
claim_number_main = page_soup.findAll('span', {'id': 'claiminfo-label-claimnumber'})
ccnr = page_soup.findAll('p', {'id': 'claiminfo-data-claimnumber'})
table_main = boxes_main[2].table
file = open(files_loc + str(line.voucher) + '_' + str(proper_dos[1]) + '.' + str(proper_dos[2]) + '.' + str(proper_dos[0]) + '.html', 'w')
file.write('Voucher number:\n' + str(voucher_number_main) + str(billing_provider) + str(act_billing_provider)
+ str(claim_number_main) + str(ccnr) + str(table_main) + str(boxes_main[3]))
file.close()
# Main program
with open(loc + new_file, 'w', newline='') as f:
times_checked = 0
writer = csv.writer(f)
writer.writerow(['Name', 'Lastname', 'DOB', 'DOS', 'Voucher number ', 'Client', 'Claim Status', 'CC#', 'Charge',
'Allowed Amount', 'Paid Amount', 'PR'])
f.flush()
current_client = ''
for line in list:
times_checked += 1
time.sleep(optimization)
if current_client != line.client:
if line.client == 'HMG':
switch_to_HMG()
elif line.client == 'RDMG':
switch_to_RDMG()
elif line.client == 'RDMGA':
switch_to_RDMGA()
current_client = line.client
look_up_status()
time.sleep(optimization + 1)
print("\nChecking claim status Nr. " + str(times_checked) + ":")
print(line.client)
if check_exists_by_xpath('//*[@id="search-warning-message"]/div'):
print('Claim status not found')
writer.writerow([line.name, line.last_name, line.us_dob, line.us_dos, line.voucher, line.client,
'Claim status not found'])
f.flush()
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.HOME)
else:
info1 = scrape_primary()
print(info1)
info2 = scrape_secondary()
print(info2)
writer.writerow([line.name, line.last_name, line.us_dob, line.us_dos, line.voucher, line.client, info1,
info2[0], info2[1], info2[2], info2[3], info2[4]])
f.flush()
expand_status()
time.sleep(optimization + 1)
scrape_all_data()
driver.back()
driver.back()