Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import json
- import requests
- from datetime import datetime
- from selenium import webdriver
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.select import Select
- def parse_appointments(driver):
- driver.execute_script("document.getElementById('schedule').style.display = 'none';")
- divs = driver.find_elements(By.CSS_SELECTOR, 'div[apptid]')
- appointments = list()
- for div in divs:
- try:
- label = div.find_element(By.TAG_NAME, 'dl')
- label.click()
- time.sleep(1)
- block = driver.find_element(By.ID, 'apptInfo')
- start_date = block.find_element(By.ID, 'APPT_DATE').text
- start_time = block.find_element(By.ID, 'APPT_TIME').text
- new_datetime = f'{start_date} {start_time}'
- print(f'New datetime: {new_datetime}')
- start_datetime = datetime.strptime(new_datetime.strip(), '%m/%d/%y %I:%M %p')
- start_datetime = start_datetime.isoformat()
- appt_type = block.find_element(By.ID, 'APPT_TYPE').text
- appt_data = appt_type.split('-', maxsplit=1)
- appt_type = 'appointment' if appt_data[0].strip() != 'BLOCK' else 'break'
- duration = int(appt_data[1].split()[0])
- provider = block.find_element(By.ID, 'APPT_PROVIDER').text
- patient = block.find_element(By.ID, 'APPT_PATIENT').text
- print(start_datetime)
- print(appt_type)
- print(provider)
- exit = block.find_element(By.CLASS_NAME, 'pm_blueX')
- exit.click()
- time.sleep(1)
- appointments.append({'start_datetime': start_datetime, 'duration': duration,
- 'type': appt_type, 'provider': provider, 'patient': patient})
- print('------------------------')
- except Exception as e:
- print(f'Exception: {e}')
- exit = block.find_element(By.CLASS_NAME, 'pm_blueX')
- exit.click()
- time.sleep(1)
- return appointments
- def send_appointments_to_server(driver, provider_id):
- print(provider_id)
- API_KEY = 'KEY'
- # select the Forest Hills location
- time.sleep(1)
- driver.get('https://www.google.com/')
- time.sleep(2)
- driver.get("https://txn3.healthfusionclaims.com/electronic/pm_schedule/week_view.jsp")
- time.sleep(2)
- select_location = Select(driver.find_element(By.NAME, 'FILTER_LOCATION'))
- time.sleep(1)
- select_location.select_by_value('1275017')
- time.sleep(2)
- select_provider = Select(driver.find_element(By.NAME, 'FILTER_RESOURCE'))
- time.sleep(1)
- select_provider.select_by_value(provider_id)
- time.sleep(2)
- driver.execute_script("document.getElementById('schedule').style.display = 'none';")
- divs = driver.find_elements(By.CSS_SELECTOR, 'div[apptid]')
- appointments = list()
- new_appointments = parse_appointments(driver)
- appointments.extend(new_appointments)
- for i in range(2):
- driver.execute_script("document.getElementById('schedule').style.display = 'block';")
- next_link = driver.find_elements(By.CLASS_NAME, 'monthNav')[-1]
- next_link.click()
- time.sleep(2)
- new_appointments = parse_appointments(driver)
- appointments.extend(new_appointments)
- url = 'https://2323-176-105-201-148.ngrok.io/api/v1/receive-booked-appointments/'
- data = {"data": appointments, "api_key": API_KEY, 'ehr':'Viva Eve'}
- response = requests.post(url, data=json.dumps(data), headers={"Content-Type": "application/json"})
- print(response.json())
- print('End')
- # Credentials
- username = "USER"
- password = "PASS"
- # initialize the Chrome driver
- driver = webdriver.Chrome("chromedriver")
- # login into VivaEve EHR system
- driver.get("https://login.healthfusion.com/")
- frame_0 = driver.find_element(By.ID, 'loginIframe')
- driver.switch_to.frame(frame_0)
- driver.find_element(By.ID,'username').send_keys(username)
- driver.find_element(By.ID, 'password').send_keys(password)
- time.sleep(1)
- driver.find_element(By.NAME, 'userloginsubmit').click()
- time.sleep(3)
- provider_ids = ['68621', '176979', '188990', '205553', '200631', '204703', '211957', '212148']
- for provider_id in provider_ids:
- send_appointments_to_server(driver, provider_id)
- html = driver.page_source
- driver.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement