Advertisement
andriitereshchenko

New

Aug 17th, 2022
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. import time
  2. import json
  3. import requests
  4.  
  5. from datetime import datetime
  6. from selenium import webdriver
  7. from selenium.webdriver.support.ui import WebDriverWait
  8. from selenium.webdriver.support import expected_conditions as EC
  9. from selenium.webdriver.common.by import By
  10. from selenium.webdriver.support.select import Select
  11.  
  12. def parse_appointments(driver):
  13. driver.execute_script("document.getElementById('schedule').style.display = 'none';")
  14. divs = driver.find_elements(By.CSS_SELECTOR, 'div[apptid]')
  15. appointments = list()
  16.  
  17. for div in divs:
  18. try:
  19. label = div.find_element(By.TAG_NAME, 'dl')
  20. label.click()
  21. time.sleep(1)
  22. block = driver.find_element(By.ID, 'apptInfo')
  23. start_date = block.find_element(By.ID, 'APPT_DATE').text
  24. start_time = block.find_element(By.ID, 'APPT_TIME').text
  25. new_datetime = f'{start_date} {start_time}'
  26. print(f'New datetime: {new_datetime}')
  27. start_datetime = datetime.strptime(new_datetime.strip(), '%m/%d/%y %I:%M %p')
  28. start_datetime = start_datetime.isoformat()
  29.  
  30. appt_type = block.find_element(By.ID, 'APPT_TYPE').text
  31. appt_data = appt_type.split('-', maxsplit=1)
  32. appt_type = 'appointment' if appt_data[0].strip() != 'BLOCK' else 'break'
  33. duration = int(appt_data[1].split()[0])
  34.  
  35. provider = block.find_element(By.ID, 'APPT_PROVIDER').text
  36. patient = block.find_element(By.ID, 'APPT_PATIENT').text
  37. print(start_datetime)
  38. print(appt_type)
  39. print(provider)
  40. exit = block.find_element(By.CLASS_NAME, 'pm_blueX')
  41. exit.click()
  42. time.sleep(1)
  43. appointments.append({'start_datetime': start_datetime, 'duration': duration,
  44. 'type': appt_type, 'provider': provider, 'patient': patient})
  45.  
  46. print('------------------------')
  47. except Exception as e:
  48. print(f'Exception: {e}')
  49. exit = block.find_element(By.CLASS_NAME, 'pm_blueX')
  50. exit.click()
  51. time.sleep(1)
  52.  
  53. return appointments
  54.  
  55.  
  56. def send_appointments_to_server(driver, provider_id):
  57. print(provider_id)
  58. API_KEY = 'KEY'
  59.  
  60. # select the Forest Hills location
  61. time.sleep(1)
  62. driver.get('https://www.google.com/')
  63. time.sleep(2)
  64. driver.get("https://txn3.healthfusionclaims.com/electronic/pm_schedule/week_view.jsp")
  65. time.sleep(2)
  66. select_location = Select(driver.find_element(By.NAME, 'FILTER_LOCATION'))
  67. time.sleep(1)
  68. select_location.select_by_value('1275017')
  69. time.sleep(2)
  70.  
  71. select_provider = Select(driver.find_element(By.NAME, 'FILTER_RESOURCE'))
  72. time.sleep(1)
  73. select_provider.select_by_value(provider_id)
  74. time.sleep(2)
  75.  
  76. driver.execute_script("document.getElementById('schedule').style.display = 'none';")
  77. divs = driver.find_elements(By.CSS_SELECTOR, 'div[apptid]')
  78. appointments = list()
  79.  
  80. new_appointments = parse_appointments(driver)
  81. appointments.extend(new_appointments)
  82. for i in range(2):
  83. driver.execute_script("document.getElementById('schedule').style.display = 'block';")
  84. next_link = driver.find_elements(By.CLASS_NAME, 'monthNav')[-1]
  85. next_link.click()
  86. time.sleep(2)
  87. new_appointments = parse_appointments(driver)
  88. appointments.extend(new_appointments)
  89. url = 'https://2323-176-105-201-148.ngrok.io/api/v1/receive-booked-appointments/'
  90. data = {"data": appointments, "api_key": API_KEY, 'ehr':'Viva Eve'}
  91. response = requests.post(url, data=json.dumps(data), headers={"Content-Type": "application/json"})
  92. print(response.json())
  93. print('End')
  94.  
  95. # Credentials
  96. username = "USER"
  97. password = "PASS"
  98.  
  99. # initialize the Chrome driver
  100. driver = webdriver.Chrome("chromedriver")
  101.  
  102. # login into VivaEve EHR system
  103. driver.get("https://login.healthfusion.com/")
  104. frame_0 = driver.find_element(By.ID, 'loginIframe')
  105. driver.switch_to.frame(frame_0)
  106. driver.find_element(By.ID,'username').send_keys(username)
  107. driver.find_element(By.ID, 'password').send_keys(password)
  108. time.sleep(1)
  109. driver.find_element(By.NAME, 'userloginsubmit').click()
  110. time.sleep(3)
  111.  
  112. provider_ids = ['68621', '176979', '188990', '205553', '200631', '204703', '211957', '212148']
  113. for provider_id in provider_ids:
  114. send_appointments_to_server(driver, provider_id)
  115.  
  116. html = driver.page_source
  117. driver.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement