예제 #1
0
def main_bowel_report(driver, wing: str, age: int):
    """
    Downloads file of bowel reports of specified wing,
    for the previous *age* month in the past i.e, 1 = previous month,
    2 = 2 months ago etc
    :param driver: selenium driver object
    :param wing: area
    :param age: number of months in the past
    :return:
    """
    search_reports(driver, 'bowel_report')

    month = (datetime.datetime.now() - datetime.timedelta(days=30 * age)).month
    year = (datetime.datetime.now() - datetime.timedelta(days=30 * age)).year
    month_spec = downloader_support_functions.date_selector(month, year)
    count = age

    wait = WebDriverWait(driver, 10)
    driver.implicitly_wait(10)
    try:
        driver.find_elements_by_id('generate').click()
    except NoSuchElementException:
        driver.quit()
        return button_functions.popup_error(
            "bowel report not available in the ecase report generator")

    fields = driver.find_elements_by_id('clause-field-0')
    date_from_fields = driver.find_elements_by_xpath(
        '//*[@id="clause-field-0-date"]')
    date_to_fields = driver.find_elements_by_xpath(
        '//*[@id="clause-field-1-date "]')
    fields[0].send_keys(wing)
    date_from_fields[1].click()

    downloader_support_functions.click_previous_month_button(driver, count)
    # finding the first available selectable date, and hovering to it
    first_available_date = wait.until(
        ec.element_to_be_clickable(
            (By.CSS_SELECTOR, f"body > div.Zebra_DatePicker.dp_visible > "
             f"table.dp_daypicker > tbody > tr:nth-child(2)"
             f" > td:nth-child({month_spec[1]})")))

    ActionChains(driver).move_to_element(first_available_date).perform()
    driver.find_element_by_css_selector(
        f"body > div.Zebra_DatePicker.dp_visible >"
        f" table.dp_daypicker > tbody > "
        f"tr:nth-child(2) > td:nth-child({month_spec[1]}) ").click()
    date_to_fields[1].click()

    downloader_support_functions.click_previous_month_button(driver, count)

    driver.find_element_by_css_selector(
        "body > div.Zebra_DatePicker.dp_visible > table.dp_daypicker > "
        f"tbody > tr:nth-child({month_spec[0]}) > td:nth-child({month_spec[2]}) "
    ).click()
    driver.implicitly_wait(10)
    driver.find_element(By.XPATH, '//*[@id="btn-generate"]').click()
예제 #2
0
def ecase_movements(driver):
    """
        Downloads CSV of ‘temp_movements’.
        Handles the selecting of dates within eCase date selector,
        selects from 1 July 2018, till the end of the current month.
    """
    search_reports(driver, 'temp_movements')

    month_spec = downloader_support_functions.date_selector(
        datetime.datetime.now().month,
        datetime.datetime.now().year)

    driver.implicitly_wait(15)
    try:
        buttons = driver.find_elements_by_id('generate')  #.click()
        time.sleep(5)
        for button in buttons:
            button.click()
            time.sleep(2)
    except NoSuchElementException:
        driver.quit()
        return button_functions.popup_error(
            "The Temp movements report is not "
            "available in the ecase report generator")

    date_to_fields = driver.find_elements_by_xpath(
        '//*[@id="clause-field-1-date "]')

    date_to_fields[0].click()

    # clicking the date that we hovered over
    driver.find_element_by_css_selector(
        f"body > div.Zebra_DatePicker.dp_visible >"
        f" table.dp_daypicker > tbody > "
        f"tr:nth-child({month_spec[0]}) > "
        f"td:nth-child({month_spec[2]})").click()

    driver.implicitly_wait(15)
    driver.find_element(By.XPATH, '//*[@id="btn-generate"]').click()
예제 #3
0
 def test_future_month(self):
     self.assertEqual(downloader_support_functions.date_selector(1, 2022),
                      (7, 6, 1))
예제 #4
0
 def test_current_datetime(self):
     self.assertEqual(downloader_support_functions.date_selector(12, 2019),
                      (7, 7, 2))
예제 #5
0
 def test_past_month(self):
     self.assertEqual(downloader_support_functions.date_selector(1, 2019),
                      (6, 2, 4))