class TestBristolStoolObsPage(TestCommon):
    """
    Setup a session and test that a Bristol stool scale
    observation can be submitted
    """
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.patient_list_page.go_to_patient_list()

    def test_bristol_stool_obs(self):
        """
        Test that a Bristol Stool Scale observation can be submitted
        """
        bristol_stool_inputs = BRISTOL_STOOL_DATA

        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)
        PatientPage(self.driver).open_form(
            OPEN_OBS_MENU_BS_SCALE)
        PatientPage(self.driver).enter_obs_data(bristol_stool_inputs)

        success = 'Successfully Submitted Bristol Stool Scale Observation'
        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located((
                SUCCESSFUL_SUBMIT))
        )
        response = self.driver.find_element(*SUCCESSFUL_SUBMIT)
        self.assertEqual(success, response.text,
                         'Bristol Stool Scale observation unsuccessful')
 def setUp(self):
     self.driver.get(MOB_LOGIN)
     self.login_page = LoginPage(self.driver)
     self.task_list_page = ListPage(self.driver)
     self.patient_list_page = ListPage(self.driver)
     self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
     self.task_list_page.go_to_task_list()
class TestPosturalBloodPressurePage(TestCommon):
    """
    Setup a session and test that a postural blood pressure
    observation can be submitted
    """

    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.patient_list_page.go_to_patient_list()

    def test_pbp_obs(self):
        """
        Test that a postural blood pressure observation can be submitted
        """
        postural_pressure_inputs = POSTURAL_BLOOD_PRESSURE_DATA

        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)
        PatientPage(self.driver).open_form(OPEN_OBS_MENU_POSTURAL_PRESSURE)
        PatientPage(self.driver).enter_obs_data(postural_pressure_inputs)

        success = 'Successfully Submitted Postural Blood Pressure Observation'
        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located((
                SUCCESSFUL_SUBMIT))
        )
        response = self.driver.find_element(*SUCCESSFUL_SUBMIT)
        self.assertEqual(success, response.text,
                         'Postural blood pressure observation unsuccessful')
class TestBloodProductObsPage(TestCommon):
    """
    Setup a session and test that a blood product observation can be submitted
    """

    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.patient_list_page.go_to_patient_list()

    def test_blood_product_obs(self):
        """
        Test that a blood product observation can be submitted
        """
        blood_product_inputs = BLOOD_PRODUCT_DATA

        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)
        PatientPage(self.driver).open_form(OPEN_OBS_MENU_BLOOD_PRODUCT)
        PatientPage(self.driver).enter_obs_data(blood_product_inputs)

        success = "Successfully Submitted Blood Product Observation"
        ui.WebDriverWait(self.driver, 5).until(ec.visibility_of_element_located((SUCCESSFUL_SUBMIT)))

        response = self.driver.find_element(*SUCCESSFUL_SUBMIT)
        self.assertEqual(success, response.text, "Blood product observation unsuccessful")
예제 #5
0
class TestPatientPageVisualisationWithNoObsData(TestCommon):
    """
    Test that the No observation data available for patient message
    is shown on no obs being available
    """
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.list_page = ListPage(self.driver)
        self.patient_page = PatientPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.list_page.go_to_patient_list()
        patients = self.list_page.get_list_items()
        patient_to_test = patients[0]
        self.patient_url = patient_to_test.get_attribute('href')
        patient_id = self.patient_url.replace(PATIENT_PAGE, '')
        self.patient_page.remove_observations_for_patient(int(patient_id))
        self.driver.get(self.patient_url)

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(GRAPH_CHART))

    def test_shows_message_when_no_obs(self):
        """
        Test that the No observation data available for patient message is
        shown on no obs being available
        """

        self.assertTrue(self.patient_page.has_no_patient_data(),
                        'No Observation Data Available message not found')
예제 #6
0
class TestNewsPage(TestCommon):
    """
    Setup a session and test that a no risk NEWS observation
    can be submitted
    """
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.patient_list_page.go_to_patient_list()

    def test_news_obs(self):
        """
        Test that a NEWS observation can be submitted
        """
        score = NO_RISK_EWS_DATA

        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)
        PatientPage(self.driver).open_form(OPEN_OBS_MENU_NEWS_ITEM)
        PatientPage(self.driver).enter_obs_data(score)

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(CONFIRM_SUBMIT))
        self.driver.find_element(*CONFIRM_SUBMIT).click()

        success = 'Successfully Submitted NEWS Observation'
        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located((SUCCESSFUL_SUBMIT)))
        response = self.driver.find_element(*SUCCESSFUL_SUBMIT)
        self.assertEqual(success, response.text,
                         'NEWS observation unsuccessful')
class TestWeightObsPage(TestCommon):
    """
    Setup a session and test that a weight observation can be submitted
    """

    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.patient_list_page.go_to_patient_list()

    def test_weight_obs(self):
        """
        Test that a weight observation can be submitted
        """
        weight_input = WEIGHT_DATA

        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)
        PatientPage(self.driver).open_form(OPEN_OBS_MENU_WEIGHT)
        PatientPage(self.driver).enter_obs_data(weight_input)

        success = 'Successfully Submitted Weight Observation'
        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located((
                SUCCESSFUL_SUBMIT))
        )

        response = self.driver.find_element(*SUCCESSFUL_SUBMIT)

        self.assertEqual(success, response.text,
                         'Weight observation unsuccessful')
class TestBloodProductObsPage(TestCommon):
    """
    Setup a session and test that a blood product observation can be submitted
    """
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.patient_list_page.go_to_patient_list()

    def test_blood_product_obs(self):
        """
        Test that a blood product observation can be submitted
        """
        blood_product_inputs = BLOOD_PRODUCT_DATA

        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)
        PatientPage(self.driver).open_form(OPEN_OBS_MENU_BLOOD_PRODUCT)
        PatientPage(self.driver).enter_obs_data(blood_product_inputs)

        success = 'Successfully Submitted Blood Product Observation'
        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located((SUCCESSFUL_SUBMIT)))

        response = self.driver.find_element(*SUCCESSFUL_SUBMIT)
        self.assertEqual(success, response.text,
                         'Blood product observation unsuccessful')
class TestNewsPage(TestCommon):
    """
    Setup a session and test that a no risk NEWS observation
    can be submitted
    """

    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.patient_list_page.go_to_patient_list()

    def test_news_obs(self):
        """
        Test that a NEWS observation can be submitted
        """
        score = NO_RISK_EWS_DATA

        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)
        PatientPage(self.driver).open_form(OPEN_OBS_MENU_NEWS_ITEM)
        PatientPage(self.driver).enter_obs_data(score)

        ui.WebDriverWait(self.driver, 5).until(ec.visibility_of_element_located(CONFIRM_SUBMIT))
        self.driver.find_element(*CONFIRM_SUBMIT).click()

        success = "Successfully Submitted NEWS Observation"
        ui.WebDriverWait(self.driver, 5).until(ec.visibility_of_element_located((SUCCESSFUL_SUBMIT)))
        response = self.driver.find_element(*SUCCESSFUL_SUBMIT)
        self.assertEqual(success, response.text, "NEWS observation unsuccessful")
 def setUp(self):
     self.driver.get(MOB_LOGIN)
     self.login_page = LoginPage(self.driver)
     self.task_list_page = ListPage(self.driver)
     self.patient_list_page = ListPage(self.driver)
     self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
     self.task_list_page.go_to_task_list()
class TestPatientPageVisualisationWithNoObsData(TestCommon):
    """
    Test that the No observation data available for patient message
    is shown on no obs being available
    """
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.list_page = ListPage(self.driver)
        self.patient_page = PatientPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.list_page.go_to_patient_list()
        patients = self.list_page.get_list_items()
        patient_to_test = patients[0]
        self.patient_url = patient_to_test.get_attribute('href')
        patient_id = self.patient_url.replace(
            PATIENT_PAGE, ''
        )
        self.patient_page.remove_observations_for_patient(int(patient_id))
        self.driver.get(self.patient_url)

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(GRAPH_CHART)
        )

    def test_shows_message_when_no_obs(self):
        """
        Test that the No observation data available for patient message is
        shown on no obs being available
        """

        self.assertTrue(self.patient_page.has_no_patient_data(),
                        'No Observation Data Available message not found')
def check_task_list(context):
    patient_name = context.patient_name
    task_page = ListPage(context.browser)
    task_list = [
        task.find_element(*TASK).text for task in task_page.get_list_items()
        if task.find_element(*LIST_ITEM_PATIENT_NAME).text == patient_name
    ]
    for row in context.table:
        assert (row.get('tasks') in task_list)
예제 #13
0
 def setUp(self):
     self.driver.get(MOB_LOGIN)
     self.login_page = LoginPage(self.driver)
     self.list_page = ListPage(self.driver)
     self.task_page = TaskPage(self.driver)
     self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
     self.list_page.go_to_task_list()
     tasks = self.list_page.get_list_items()
     task_to_test = tasks[0]
     self.task_url = task_to_test.get_attribute('href')
     self.driver.get(self.task_url)
def check_no_notifications(context):
    patient_name = context.patient_name
    page_confirm = PageConfirm(context.browser)
    task_page = ListPage(context.browser)
    task_page.go_to_task_list()
    assert (page_confirm.is_task_list_page())
    task_list = [
        task.find_element(*TASK).text for task in task_page.get_list_items()
        if task.find_element(*LIST_ITEM_PATIENT_NAME).text == patient_name
    ]
    assert (len(task_list) == 0)
 def setUp(self):
     self.driver.get(MOB_LOGIN)
     self.login_page = LoginPage(self.driver)
     self.list_page = ListPage(self.driver)
     self.patient_page = PatientPage(self.driver)
     self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
     self.list_page.go_to_patient_list()
     patients = self.list_page.get_list_items()
     patient_to_test = patients[0]
     self.patient_url = patient_to_test.get_attribute('href')
     self.driver.get(self.patient_url)
예제 #16
0
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.list_page = ListPage(self.driver)
        self.patient_page = PatientPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.list_page.go_to_patient_list()
        patients = self.list_page.get_list_items()
        patient_to_test = patients[0]
        self.patient_url = patient_to_test.get_attribute('href')
        patient_id = self.patient_url.replace(PATIENT_PAGE, '')
        self.patient_page.remove_observations_for_patient(int(patient_id))
        self.driver.get(self.patient_url)

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(GRAPH_CHART))
def check_next_ews(context, time, period):
    patient_name = context.patient_name
    page_confirm = PageConfirm(context.browser)
    task_page = ListPage(context.browser)
    task_page.go_to_patient_list()
    assert (page_confirm.is_patient_list_page())
    task_list = [
        task.find_element(*LIST_ITEM_DEADLINE).text
        for task in task_page.get_list_items()
        if task.find_element(*LIST_ITEM_PATIENT_NAME).text == patient_name
    ]
    assert (len(task_list) == 1)
    time_range = range(int(time) - 1, int(time) + 1)
    if period == 'minutes':
        assert (int(task_list[0][3:][:2]) in time_range)
    else:
        assert (int(task_list[0][:2]) in time_range)
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.list_page = ListPage(self.driver)
        self.patient_page = PatientPage(self.driver)
        self.patient_page_graph = PatientPageGraphs(self.driver)

        risk_mapping = {
            'none': self.patient_page.add_no_risk_observation,
            'low': self.patient_page.add_low_risk_observation,
            'medium': self.patient_page.add_medium_risk_observation,
            'high': self.patient_page.add_high_risk_observation,
            '3in1': self.patient_page.add_three_in_one_observation
        }
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.list_page.go_to_patient_list()
        patients = self.list_page.get_list_items()
        patient_to_test = patients[0]
        patient_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, '')

        self.patient_page.remove_observations_for_patient(int(patient_id))
        risk_mapping[self.risk](int(patient_id))
        self.driver.get(patient_to_test.get_attribute('href'))
        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located((By.CSS_SELECTOR, '#chart svg')))

        self.patient_page.change_to_table()
        obs_table = self.patient_page.get_obs_table()
        rows = self.patient_page.get_table_rows(obs_table)[1:]

        self.row_data = []
        for row in rows:
            self.row_data.append(self.patient_page.get_table_data(row))

        self.patient_page_graph.change_to_chart()

        # Focus Graphs
        focus_graphs = self.patient_page_graph.get_focus_graphs()
        self.assertEqual(len(focus_graphs), 5, 'Incorrect number of graphs')
        self.graph_list = []

        for graph in focus_graphs:
            self.graph_list.append(graph)

        self.graph_data = self.get_graph_data()
 def setUp(self):
     self.driver.get(MOB_LOGIN)
     self.login_page = LoginPage(self.driver)
     self.list_page = ListPage(self.driver)
     self.patient_page = PatientPage(self.driver)
     self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
     self.list_page.go_to_patient_list()
     patients = self.list_page.get_list_items()
     patient_to_test = patients[0]
     self.patient_url = patient_to_test.get_attribute('href')
     self.driver.get(self.patient_url)
 def setUp(self):
     self.driver.get(MOB_LOGIN)
     self.login_page = LoginPage(self.driver)
     self.list_page = ListPage(self.driver)
     self.task_page = TaskPage(self.driver)
     self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
     self.list_page.go_to_task_list()
     tasks = self.list_page.get_list_items()
     task_to_test = tasks[0]
     self.task_url = task_to_test.get_attribute('href')
     self.driver.get(self.task_url)
class TestMediumRiskPage(TestCommon):
    """
    Setup a session and test that a medium risk NEWS observation
    can be submitted, and that the correct action triggers
    """

    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.patient_list_page.go_to_patient_list()

    def test_medium_risk_obs(self):
        """
        Test that an 'urgently inform medical team' task
        is triggered after a medium NEWS score
        """
        medium_score = MEDIUM_RISK_SCORE_3_THREE_IN_ONE_EWS_DATA

        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)
        PatientPage(self.driver).open_form(OPEN_OBS_MENU_NEWS_ITEM)
        PatientPage(self.driver).enter_obs_data(medium_score)

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(CONFIRM_SUBMIT)
        )

        self.driver.find_element(*CONFIRM_SUBMIT).click()

        task = 'Urgently inform medical team'
        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(RELATED_TASK)
        )
        response = self.driver.find_element(*RELATED_TASK)

        self.assertEqual(task, response.text,
                         'Incorrect triggered action for medium risk ob')
def submit_observation(context, clinical_risk):

    risk_dict = {
        'no': NO_RISK_EWS_DATA,
        'a low': LOW_RISK_SCORE_1_EWS_DATA,
        'a medium': MEDIUM_RISK_SCORE_5_EWS_DATA,
        'a high': HIGH_RISK_SCORE_7_EWS_DATA
    }
    risk_score = risk_dict.get(clinical_risk)
    if not risk_score:
        raise ValueError('No risk score available')

    page_confirm = PageConfirm(context.browser)
    patient_list_page = ListPage(context.browser)

    patient_list_page.go_to_patient_list()
    assert(page_confirm.is_patient_list_page())
    patients = patient_list_page.get_list_items()

    PatientPage(context.browser).select_patient(patients)
    PatientPage(context.browser).open_form(OPEN_OBS_MENU_NEWS_ITEM)
    ObservationFormPage(context.browser).enter_obs_data(risk_score)
예제 #23
0
class TestMediumRiskPage(TestCommon):
    """
    Setup a session and test that a medium risk NEWS observation
    can be submitted, and that the correct action triggers
    """
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.patient_list_page.go_to_patient_list()

    def test_medium_risk_obs(self):
        """
        Test that an 'urgently inform medical team' task
        is triggered after a medium NEWS score
        """
        medium_score = MEDIUM_RISK_SCORE_3_THREE_IN_ONE_EWS_DATA

        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)
        PatientPage(self.driver).open_form(OPEN_OBS_MENU_NEWS_ITEM)
        PatientPage(self.driver).enter_obs_data(medium_score)

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(CONFIRM_SUBMIT))

        self.driver.find_element(*CONFIRM_SUBMIT).click()

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(RELATED_TASK))
        response = self.driver.find_element(*RELATED_TASK)

        self.assertEqual(MEDIUM_SCORE_RESPONSE, response.text,
                         'Incorrect triggered action for medium risk ob')
예제 #24
0
class TestGcsObsPage(TestCommon):
    """
    Setup a session and test that a gcs observation can be submitted
    """
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.patient_list_page.go_to_patient_list()

    def test_gcs_obs(self):
        """
        Test that a GCS observation can be submitted
        """
        gcs_inputs = GCS_SCORE_15_DATA

        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)
        PatientPage(self.driver).open_form(OPEN_OBS_MENU_GCS)
        PatientPage(self.driver).enter_obs_data(gcs_inputs)

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(CONFIRM_SUBMIT)
        )
        self.driver.find_element(*CONFIRM_SUBMIT).click()

        success = 'Successfully Submitted GCS Observation'
        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located((
                SUCCESSFUL_SUBMIT))
        )
        response = self.driver.find_element(*SUCCESSFUL_SUBMIT)
        self.assertEqual(success, response.text,
                         'GCS observation unsuccessful')
class TestLowRiskPage(TestCommon):
    """
    Setup a session and test that a low risk NEWS observation
    can be submitted, and that the correct action triggers
    """
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.patient_list_page.go_to_patient_list()

    def test_low_risk_obs(self):
        """
        Test that an 'assess patient' task is triggered after a low NEWS score
        """
        low_score = LOW_RISK_SCORE_1_EWS_DATA

        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)
        PatientPage(self.driver).open_form(OPEN_OBS_MENU_NEWS_ITEM)
        PatientPage(self.driver).enter_obs_data(low_score)

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(CONFIRM_SUBMIT)
        )

        self.driver.find_element(*CONFIRM_SUBMIT).click()

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(RELATED_TASK)
        )
        response = self.driver.find_element(*RELATED_TASK)
        self.assertEqual(LOW_SCORE_RESPONSE, response.text,
                         'Incorrect triggered action for low risk ob')
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.list_page = ListPage(self.driver)
        self.patient_page = PatientPage(self.driver)
        self.patient_page_graph = PatientPageGraphs(self.driver)

        risk_mapping = {
            'none': self.patient_page.add_no_risk_observation,
            'low': self.patient_page.add_low_risk_observation,
            'medium':
                self.patient_page.add_medium_risk_observation,
            'high': self.patient_page.add_high_risk_observation,
            '3in1': self.patient_page.add_three_in_one_observation
        }
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.list_page.go_to_patient_list()
        patients = self.list_page.get_list_items()
        patient_to_test = patients[0]
        patient_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )

        self.patient_page.remove_observations_for_patient(int(patient_id))
        risk_mapping[self.risk](int(patient_id))
        self.driver.get(patient_to_test.get_attribute('href'))
        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located((By.CSS_SELECTOR, '#chart svg')))

        self.patient_page.change_to_table()
        obs_table = self.patient_page.get_obs_table()
        rows = self.patient_page.get_table_rows(obs_table)[1:]

        self.row_data = []
        for row in rows:
            self.row_data.append(self.patient_page.get_table_data(row))

        self.patient_page_graph.change_to_chart()

        # Focus Graphs
        focus_graphs = self.patient_page_graph.get_focus_graphs()
        self.assertEqual(len(focus_graphs), 5, 'Incorrect number of graphs')
        self.graph_list = []

        for graph in focus_graphs:
            self.graph_list.append(graph)

        self.graph_data = self.get_graph_data()
class TestErrorHandling(TestCommon):
    """
    Setup a session and test that e-Obs error handling works
    """
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.patient_list_page.go_to_patient_list()

    def test_news_error(self):
        """
        Test that entering incorrect data into a NEWS ob will cause an error
        """
        incorrect_score = INCORRECT_EWS_DATA

        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)
        PatientPage(self.driver).open_form(OPEN_OBS_MENU_NEWS_ITEM)
        PatientPage(self.driver).enter_obs_data(incorrect_score)

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(TASK_FORM_INVALID_SUBMIT)
        )

        response = self.driver.find_element(
            *TASK_FORM_INVALID_SUBMIT).is_displayed()

        self.assertEqual(response, True,
                         'Incorrect error handling on NEWS form')

    def test_barcode_error(self):
        """
        Test that entering incorrect data into a barcode scan will
        cause an error
        """
        no_patient_id = self.patient_list_page.patient_scan_helper(99)
        self.patient_list_page.do_barcode_scan(
            no_patient_id['other_identifier'])

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(SERVER_ERROR)
        )

        response = self.driver.find_element(
            *SERVER_ERROR).is_displayed()

        self.assertEqual(response, True,
                         'Incorrect error handling on barcode scan')
class TestErrorHandling(TestCommon):
    """
    Setup a session and test that e-Obs error handling works
    """
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.patient_list_page.go_to_patient_list()

    def test_news_error(self):
        """
        Test that entering incorrect data into a NEWS ob will cause an error
        """
        incorrect_score = INCORRECT_EWS_DATA

        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)
        PatientPage(self.driver).open_form(OPEN_OBS_MENU_NEWS_ITEM)
        PatientPage(self.driver).enter_obs_data(incorrect_score)

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(TASK_FORM_INVALID_SUBMIT)
        )

        response = self.driver.find_element(
            *TASK_FORM_INVALID_SUBMIT).is_displayed()

        self.assertEqual(response, True,
                         'Incorrect error handling on NEWS form')

    def test_barcode_error(self):
        """
        Test that entering incorrect data into a barcode scan will
        cause an error
        """
        no_patient_id = self.patient_list_page.patient_scan_helper(99)
        self.patient_list_page.do_barcode_scan(
            no_patient_id['other_identifier'])

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(SERVER_ERROR)
        )

        response = self.driver.find_element(
            *SERVER_ERROR).is_displayed()

        self.assertEqual(response, True,
                         'Incorrect error handling on barcode scan')
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.list_page = ListPage(self.driver)
        self.patient_page = PatientPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.list_page.go_to_patient_list()
        patients = self.list_page.get_list_items()
        patient_to_test = patients[0]
        self.patient_url = patient_to_test.get_attribute('href')
        patient_id = self.patient_url.replace(
            PATIENT_PAGE, ''
        )
        self.patient_page.remove_observations_for_patient(int(patient_id))
        self.driver.get(self.patient_url)

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(GRAPH_CHART)
        )
def submit_extended_obs(context, risk, stay_duration):

    durations = {
        '1-2': 1,
        '3+': 5
    }
    risk_triggered_acts = {
        'no': [],
        'a low': [
            'nh.clinical.notification.assessment',
            'nh.clinical.notification.hca',
            'nh.clinical.notification.nurse'
        ],
        'a medium': [
            'nh.clinical.notification.hca',
            'nh.clinical.notification.nurse',
            'nh.clinical.notification.shift_coordinator',
            'nh.clinical.notification.medical_team',
            'nh.clinical.notification.ambulance'
        ],
        'a high': [
            'nh.clinical.notification.hca',
            'nh.clinical.notification.nurse',
            'nh.clinical.notification.shift_coordinator',
            'nh.clinical.notification.medical_team',
            'nh.clinical.notification.ambulance'
        ]
    }

    spell_model = context.odoo_client.model('nh.clinical.spell')
    page_confirm = PageConfirm(context.browser)
    patient_list_page = ListPage(context.browser)

    patient_list_page.go_to_patient_list()
    assert(page_confirm.is_patient_list_page())
    patients = patient_list_page.get_list_items()

    patient = patients[0]
    patient_id = patient.get_attribute('href').replace(
        PATIENT_PAGE, ''
    )
    patient_name = patient.find_element(*LIST_ITEM_PATIENT_NAME)
    context.patient_name = patient_name.text
    spell_id = spell_model.get_by_patient_id(int(patient_id))
    tasks_to_cancel = risk_triggered_acts.get(risk)
    if tasks_to_cancel:
        patient_list_page.remove_tasks_for_patient(
            patient_id, tasks_to_cancel, database=context.test_database_name)
    present = datetime.now()
    days_ago = timedelta(days=durations.get(stay_duration))
    new_date = present - days_ago
    new_date_str = new_date.strftime('%Y-%m-%d %H:%M:00')
    spell_model.write(spell_id, {
        'date_started': new_date_str,
        'start_date': new_date_str,
    })
    read_date = spell_model.read(spell_id, ['date_started', 'start_date'])
    assert(read_date['date_started'] == new_date_str)
    assert(read_date['start_date'] == new_date_str)
    time.sleep(1)
    submit_observation(context, risk)
class TestStandInPage(TestCommon):
    """
    Setup a session and test the stand in page
    """
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.patient_list_page.go_to_standin()

    def test_stand_in(self):
        """
        Test that the stand-in function works
        """
        nurse_name = StandInPage(self.driver).submit_stand_in()
        nurse = nurse_name.split(' ', 1)[0].lower()

        response = StandInPage(self.driver).confirm_stand_in(
            nurse, self.patient_list_page).text

        self.patient_list_page.go_to_standin()

        success = 'Successfully accepted stand-in invite'
        self.assertEqual(success, response,
                         'Stand in was unsuccessful')

    def test_stand_in_reject(self):
        """
        Test that a stand-in can be rejected
        """
        nurse_name = StandInPage(self.driver).submit_stand_in()
        nurse = nurse_name.split(' ', 1)[0].lower()
        response = StandInPage(self.driver).reject_stand_in(
            nurse, self.patient_list_page)

        success = 'Successfully rejected stand-in invite'
        self.assertEqual(success, response.text, 'Reject was unsuccessful')

    def test_claim_stand_in(self):
        """
        Test that a stand-in can be claimed back
        """
        nurse_name = StandInPage(self.driver).submit_stand_in()
        nurse = nurse_name.split(' ', 1)[0].lower()
        StandInPage(self.driver).confirm_stand_in(
            nurse, self.patient_list_page)

        self.setUp()

        response = StandInPage(self.driver).claim_stand_in()

        success = 'Patients claimed'
        self.assertEqual(success, response.text, 'Reject was unsuccessful')

    def test_erppeek_stand_in(self):
        """
        Test that accepting a stand-in through the GUI, after doing so through
        erppeek will cause a server error
        """
        task_id = StandInPage.add_stand_in()
        StandInPage(self.driver).go_to_patient_list()
        StandInPage.complete_stand_in(task_id)

        self.driver.find_element(*STAND_IN_ACCEPT_BUTTON).click()
        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(STAND_IN_CONFIRM))
        self.driver.find_element(*STAND_IN_CONFIRM).click()
        response = self.driver.find_element(*STAND_IN_ERROR).text

        success = 'Error accepting patients'
        self.assertEqual(success, response, 'Stand in should not be accepted')
class TestPatientListPage(TestCommon):
    """
    Setup a session and test that the task list page works correctly
    """

    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.patient_list_page.go_to_patient_list()

    def test_can_logout(self):
        """
        Test that the title of the login page is Open-eObs
        """
        self.patient_list_page.logout()
        self.assertTrue(PageConfirm(self.driver).is_login_page(),
                        'Did not get to the logout page correctly')

    def test_can_go_task_list_page(self):
        """
        Test that can go to task list page
        """
        self.patient_list_page.go_to_task_list()
        self.assertTrue(PageConfirm(self.driver).is_task_list_page(),
                        'Did not get to the task list page correctly')

    def test_patient_list_page(self):
        """
        Test that can go to the patient list page
        """
        self.patient_list_page.go_to_patient_list()
        self.assertTrue(PageConfirm(self.driver).is_patient_list_page(),
                        'Did not get to patient list page correctly')

    def test_can_go_stand_in_page(self):
        """
        Test that can navigate to the stand in page
        """
        self.patient_list_page.go_to_standin()
        self.assertTrue(PageConfirm(self.driver).is_stand_in_page(),
                        'Did not get to stand in page correctly')

    def test_can_do_barcode_scan(self):
        """
        Test that can do a barcode scan
        """
        patients = self.patient_list_page.get_list_items()
        patient_to_test = patients[0]
        patient_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )
        id_to_use = self.patient_list_page.patient_scan_helper(int(patient_id))
        self.patient_list_page.do_barcode_scan(id_to_use['other_identifier'])

    def test_view_patient_details(self):
        """
        Test that clicking on a work item tasks user to carry out the task
        """
        patients = self.patient_list_page.get_list_items()
        patient_to_test = patients[0]
        patient_url = patient_to_test.get_attribute('href')
        patient_to_test.click()
        self.assertTrue(PageConfirm(self.driver).is_patient_page(),
                        'Did not get to patient page correctly')
        self.assertEqual(self.driver.current_url, patient_url,
                         'Incorrect url')

    def test_patient_name_in_list(self):
        """
        Test that the patient name is in the list item
        """
        patients = self.patient_list_page.get_list_items()
        patient_to_test = patients[0]
        task_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )
        task_data = self.patient_list_page.patient_helper(task_id)[0]
        name_to_use = task_data['full_name']
        patient_name = self.driver.find_element(
            *list_page_locators.LIST_ITEM_PATIENT_NAME
        )
        self.assertEqual(patient_name.text, name_to_use.strip(),
                         'Incorrect name')

    def test_patient_location_in_list(self):
        """
        Test that the patient name is in the list item
        """
        patients = self.patient_list_page.get_list_items()
        patient_to_test = patients[0]
        task_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )
        task_data = self.patient_list_page.patient_helper(task_id)[0]
        location = task_data['location']
        parent_location = task_data['parent_location']
        bed_to_use = '{0}, {1}'.format(location, parent_location)
        patient_location = self.driver.find_element(
            *list_page_locators.LIST_ITEM_PATIENT_LOCATION
        )
        self.assertEqual(bed_to_use, patient_location.text,
                         'Incorrect location')

    def test_score_and_trend_in_list(self):
        """
        Test that the score and trend are present in list item
        """
        tasks = self.patient_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )
        task_data = self.patient_list_page.patient_helper(task_id)[0]
        score = task_data['ews_score']
        trend = task_data['ews_trend']
        score_str = '({0} )'.format(score)
        patient_trend = self.driver.find_element(
            *list_page_locators.LIST_ITEM_PATIENT_TREND
        )
        trend_str = 'icon-{0}-arrow'.format(trend)
        self.assertEqual(patient_trend.get_attribute('class'), trend_str,
                         'Incorrect trend')
        self.assertIn(score_str, patient_to_test.text, 'Incorrect score')

    def test_down_trend(self):
        """
        Test that the trend is lowered after submitting a high risk ob,
        followed by a low risk ob
        """
        tasks = self.patient_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )

        PatientPage(self.driver).add_high_risk_observation(int(task_id))
        PatientPage(self.driver).add_low_risk_observation(int(task_id))
        self.driver.refresh()

        patient_trend = self.driver.find_element(
            *list_page_locators.LIST_ITEM_PATIENT_TREND
        )

        self.assertEqual(patient_trend.get_attribute('class'),
                         'icon-down-arrow',
                         'Incorrect trend')

    def test_up_trend(self):
        """
        Test that the trend is increased after submitting a low risk ob,
        followed by a high risk ob
        """
        tasks = self.patient_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )

        PatientPage(self.driver).add_low_risk_observation(int(task_id))
        PatientPage(self.driver).add_high_risk_observation(int(task_id))
        self.driver.refresh()

        patient_trend = self.driver.find_element(
            *list_page_locators.LIST_ITEM_PATIENT_TREND
        )

        self.assertEqual(patient_trend.get_attribute('class'), 'icon-up-arrow',
                         'Incorrect trend')

    def test_same_trend(self):
        """
        Test that the trend stays the same after submitting two of the same ob
        """
        tasks = self.patient_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )

        PatientPage(self.driver).add_medium_risk_observation(int(task_id))
        PatientPage(self.driver).add_medium_risk_observation(int(task_id))
        self.driver.refresh()

        patient_trend = self.driver.find_element(
            *list_page_locators.LIST_ITEM_PATIENT_TREND
        )

        self.assertEqual(patient_trend.get_attribute('class'),
                         'icon-same-arrow',
                         'Incorrect trend')

    def test_task_deadline_in_list(self):
        """
        Test that the patient name is in the list item
        """
        tasks = self.patient_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )
        task_data = self.patient_list_page.patient_helper(task_id)[0]
        deadline = task_data['next_ews_time']
        task_deadline = self.driver.find_element(
            *list_page_locators.LIST_ITEM_DEADLINE
        )
        self.assertEqual(deadline, task_deadline.text,
                         'Incorrect deadline')

    def test_shows_patients(self):
        """
        Test that the patient list shows patients for the user
        """
        patient_list = []
        for patient in self.patient_list_page.get_list_items():
            patient_list.append(patient)

        self.assertNotEquals(patient_list, [],
                             'Patient list not showing patients')

    def test_shows_patient_data(self):
        """
        Test that a patient record shows data (graph/table) for the patient
        """
        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)

        ui.WebDriverWait(self.driver, 1).until(
            ec.visibility_of_element_located(patient_page_locators.GRAPH_CHART)
        )

        patient_graph = self.driver.find_element(*
                                                 patient_page_locators
                                                 .GRAPH_CHART)

        self.assertEqual(patient_graph.is_displayed(), True, 'Graph not found')

        self.driver.find_element(*patient_page_locators
                                 .TABLE_TAB_BUTTON).click()

        ui.WebDriverWait(self.driver, 1).until(
            ec.visibility_of_element_located
            (patient_page_locators.TABLE_CONTAINER_TABLE))

        patient_table = self.driver.find_element(*
                                                 patient_page_locators
                                                 .TABLE_CONTAINER_TABLE)
        self.assertEqual(patient_table.is_displayed(), True, 'Table not found')
class TestTaskListPage(TestCommon):
    """
    Setup a session and test that the task list page works correctly
    """

    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.task_list_page = ListPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.task_list_page.go_to_task_list()

    def test_can_logout(self):
        """
        Test that the title of the login page is Open-eObs
        """
        self.task_list_page.logout()
        self.assertTrue(PageConfirm(self.driver).is_login_page(),
                        'Did not get to the logout page correctly')

    def test_can_go_to_task_list_page(self):
        """
        Test that can go to task list page
        """
        self.task_list_page.go_to_task_list()
        self.assertTrue(PageConfirm(self.driver).is_task_list_page(),
                        'Did not get to the task list page correctly')

    def test_go_to_patient_list_page(self):
        """
        Test that can go to the patient list page
        """
        self.task_list_page.go_to_patient_list()
        self.assertTrue(PageConfirm(self.driver).is_patient_list_page(),
                        'Did not get to patient list page correctly')

    def test_can_go_to_stand_in_page(self):
        """
        Test that can navigate to the stand in page
        """
        self.task_list_page.go_to_standin()
        self.assertTrue(PageConfirm(self.driver).is_stand_in_page(),
                        'Did not get to stand in page correctly')

    def test_can_carry_out_barcode_scan(self):
        """
        Test that can do a barcode scan
        """
        tasks = self.task_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            TASK_PAGE, ''
        )
        id_to_use = self.task_list_page.task_scan_helper(task_id)
        self.task_list_page.do_barcode_scan(id_to_use['other_identifier'])

    def test_click_list_item(self):
        """
        Test that clicking on a work item tasks user to carry out the task
        """
        tasks = self.task_list_page.get_list_items()
        task_to_test = tasks[0]
        task_url = task_to_test.get_attribute('href')
        task_to_test.click()
        self.assertTrue(PageConfirm(self.driver).is_task_page(),
                        'Did not get to task page correctly')
        self.assertEqual(self.driver.current_url, task_url,
                         'Incorrect url')

    def test_list_item_patient_name(self):
        """
        Test that the patient name is in the list item
        """
        tasks = self.task_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            TASK_PAGE, ''
        )
        task_data = self.task_list_page.task_helper(task_id)[0]
        name_to_use = task_data['full_name']
        patient_name = self.driver.find_element(
            *list_page_locators.LIST_ITEM_PATIENT_NAME
        )
        self.assertEqual(patient_name.text, name_to_use.strip(),
                         'Incorrect name')

    def test_list_item_patient_location(self):
        """
        Test that the patient name is in the list item
        """
        tasks = self.task_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            TASK_PAGE, ''
        )
        task_data = self.task_list_page.task_helper(task_id)[0]
        location = task_data['location']
        parent_location = task_data['parent_location']
        bed_to_use = '{0}, {1}'.format(location, parent_location)
        patient_location = self.driver.find_element(
            *list_page_locators.LIST_ITEM_PATIENT_LOCATION
        )
        self.assertEqual(bed_to_use, patient_location.text,
                         'Incorrect location')

    def test_list_item_score_trend(self):
        """
        Test that the score and trend are present in list item
        """
        tasks = self.task_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            TASK_PAGE, ''
        )
        task_data = self.task_list_page.task_helper(task_id)[0]
        score = task_data['ews_score']
        trend = task_data['ews_trend']
        score_str = '({0} )'.format(score)
        patient_trend = self.driver.find_elements(
            *list_page_locators.LIST_ITEM_PATIENT_TREND
        )
        for item in patient_trend:
            if item.get_attribute('class') == 'icon-alert':
                patient_trend.remove(item)

        trend_str = 'icon-{0}-arrow'.format(trend)
        self.assertEqual(patient_trend[0].get_attribute('class'), trend_str,
                         'Incorrect trend')
        self.assertIn(score_str, patient_to_test.text, 'Incorrect score')

    def test_list_item_task_deadline(self):
        """
        Test that the patient name is in the list item
        """
        tasks = self.task_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            TASK_PAGE, ''
        )
        task_data = self.task_list_page.task_helper(task_id)[0]
        deadline = task_data['deadline_time']
        task_deadline = self.driver.find_element(
            *list_page_locators.LIST_ITEM_DEADLINE
        )
        self.assertEqual(deadline, task_deadline.text,
                         'Incorrect deadline')

    def test_list_item_task_summary(self):
        """
        Test that the patient name is in the list item
        """
        tasks = self.task_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            TASK_PAGE, ''
        )
        task_data = self.task_list_page.task_helper(task_id)[0]
        summary = task_data['summary']
        task_summary = self.driver.find_element(
            *list_page_locators.LIST_ITEM_TITLE
        )
        self.assertEqual(summary, task_summary.text,
                         'Incorrect summary')

    def test_shows_tasks(self):
        """
        Test that the task list shows tasks for the user
        """
        task_list = []
        for patient in self.task_list_page.get_list_items():
            task_list.append(patient)

        self.assertNotEquals(task_list, [], 'Task list not showing tasks')

    def test_take_task_news_obs(self):
        """
        Submit adhoc observation which creates News observation task
        and Take task NEWS Observation from task list, submit news score
        """

        # Enter high risk observation to create News Observation task in task
        # list
        self.patient_list_page.go_to_patient_list()
        high_score = HIGH_RISK_SCORE_9_EWS_DATA
        no_risk = NO_RISK_EWS_DATA
        news_task = []
        success = 'Successfully Submitted NEWS Observation'

        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)
        PatientPage(self.driver).open_form(OPEN_OBS_MENU_NEWS_ITEM)
        PatientPage(self.driver).enter_obs_data(high_score)

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(CONFIRM_SUBMIT)
        )
        self.driver.find_element(*CONFIRM_SUBMIT).click()

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located((
                SUCCESSFUL_SUBMIT))
        )
        response = self.driver.find_element(*SUCCESSFUL_SUBMIT)
        self.assertEqual(success, response.text,
                         'NEWS observation unsuccessful')

        self.driver.find_element(*GO_TO_MY_TASK).click()

        # Click on the first news score task from Task list
        self.task_list_page.go_to_task_list()

        self.driver.refresh()
        for task in self.task_list_page.get_list_task():
            # print(task.text)
            if task.text == 'NEWS Observation':
                news_task.append(task)
        news_task[0].click()

        # enter low risk observation
        PatientPage(self.driver).enter_obs_data(no_risk)

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(CONFIRM_SUBMIT)
        )

        self.driver.find_element(*CONFIRM_SUBMIT).click()

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located((
                SUCCESSFUL_SUBMIT))
        )
        response = self.driver.find_element(*SUCCESSFUL_SUBMIT)
        self.assertEqual(success, response.text,
                         'NEWS observation unsuccessful')
        # print(news_task)

    def test_confirm_clinical(self):
        """
        Test that a clinical notification can be confirmed
        """
        self.patient_list_page.go_to_patient_list()
        tasks = self.patient_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )
        PatientPage(self.driver).remove_observations_for_patient(int(task_id))
        TaskPage(self.driver).open_clinical(task_id, self.patient_list_page)

        success = 'Submission successful'
        response = TaskPage(self.driver).confirm_clinical()
        self.assertEqual(success, response, 'Error confirming clinical')

    def test_cancel_clinical(self):
        """
        Test that a clinical notification can be cancelled
        """
        self.patient_list_page.go_to_patient_list()
        tasks = self.patient_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )
        PatientPage(self.driver).remove_observations_for_patient(int(task_id))
        TaskPage(self.driver).open_clinical(task_id, self.patient_list_page)

        success = 'Cancellation successful'
        response = TaskPage(self.driver).cancel_clinical()
        self.assertEqual(success, response, 'Error cancelling clinical')
예제 #34
0
class TestTaskPagePatientInfo(TestCommon):
    """
    Setup a session and test that the patient info is correct
    """
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.list_page = ListPage(self.driver)
        self.task_page = TaskPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.list_page.go_to_task_list()
        tasks = self.list_page.get_list_items()
        task_to_test = tasks[0]
        self.task_url = task_to_test.get_attribute('href')
        self.driver.get(self.task_url)

    def test_can_logout(self):
        """
        Test that the title of the login page is Open-eObs
        """
        self.task_page.logout()
        self.assertTrue(
            PageConfirm(self.driver).is_login_page(),
            'Did not get to the logout page correctly')

    def test_can_go_to_task_list_page(self):
        """
        Test that can go to task list page
        """
        self.task_page.go_to_task_list()
        self.assertTrue(
            PageConfirm(self.driver).is_task_list_page(),
            'Did not get to the task list page correctly')

    def test_go_to_patient_list_page(self):
        """
        Test that can go to the patient list page
        """
        self.task_page.go_to_patient_list()
        self.assertTrue(
            PageConfirm(self.driver).is_patient_list_page(),
            'Did not get to patient list page correctly')

    def test_can_go_to_stand_in_page(self):
        """
        Test that can navigate to the stand in page
        """
        self.task_page.go_to_standin()
        self.assertTrue(
            PageConfirm(self.driver).is_stand_in_page(),
            'Did not get to stand in page correctly')

    def test_can_carry_out_barcode_scan(self):
        """
        Test that can do a barcode scan
        """
        task_id = self.task_url.replace(TASK_PAGE, '')
        id_to_use = self.task_page.task_scan_helper(int(task_id))
        self.task_page.do_barcode_scan(id_to_use['other_identifier'])

    def test_patient_info_name(self):
        """
        Test that can get the patient info popup on pressing patient name
        """
        patient_name_button = self.driver.find_element(*PATIENT_NAME_LINK)
        patient_id = patient_name_button.get_attribute('patient-id')

        popup = self.task_page.open_patient_info()
        popup_header = popup.find_element(*PATIENT_INFO_POPUP_TITLE)
        patient_data = self.task_page.patient_helper(int(patient_id))[0]
        popup_title = '{0} {1}'.format(patient_data['full_name'],
                                       patient_data['gender'])

        self.assertEqual(popup_title, popup_header.text.replace('\n', ' '),
                         'Incorrect popup name')

    def test_patient_info_button(self):
        """
        Test that can get the patient info popup on pressing patient name
        """
        patient_name_button = self.driver.find_element(*PATIENT_NAME_INFO)
        patient_id = patient_name_button.get_attribute('patient-id')

        popup = self.task_page.open_patient_info()
        popup_header = popup.find_element(*PATIENT_INFO_POPUP_TITLE)
        patient_data = self.task_page.patient_helper(int(patient_id))[0]
        popup_title = '{0} {1}'.format(patient_data['full_name'],
                                       patient_data['gender'])
        self.assertEqual(popup_title, popup_header.text.replace('\n', ' '),
                         'Incorrect popup name')

    def test_press_obs_data_button(self):
        """
        Test that pressing the 'View Patient Observation Data' shows the
        patient page in a fullscreen modal
        """
        patient_name_button = self.driver.find_element(*PATIENT_NAME_INFO)
        patient_id = patient_name_button.get_attribute('patient-id')
        fullscreen = self.task_page.open_full_patient_obs_data()
        iframe = fullscreen.find_element(*PATIENT_INFO_FULLSCREEN_IFRAME)
        iframe_url = iframe.get_attribute('src')
        patient_url = PATIENT_PAGE + '{0}'.format(patient_id)
        self.assertEqual(iframe_url, patient_url, 'Incorrect iframe src url')

    def test_close_full_obs_modal(self):
        """
        Test that can close the fullscreen modal
        """
        fullscreen = self.task_page.open_full_patient_obs_data()
        close_button = fullscreen.find_element(*PATIENT_INFO_FULLSCREEN_CLOSE)
        close_button.click()
        self.assertTrue(self.task_page.fullscreen_not_open(),
                        'Fullscreen did not close')
class TestTaskPagePatientInfo(TestCommon):
    """
    Setup a session and test that the patient info is correct
    """
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.list_page = ListPage(self.driver)
        self.task_page = TaskPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.list_page.go_to_task_list()
        tasks = self.list_page.get_list_items()
        task_to_test = tasks[0]
        self.task_url = task_to_test.get_attribute('href')
        self.driver.get(self.task_url)

    def test_can_logout(self):
        """
        Test that the title of the login page is Open-eObs
        """
        self.task_page.logout()
        self.assertTrue(PageConfirm(self.driver).is_login_page(),
                        'Did not get to the logout page correctly')

    def test_can_go_to_task_list_page(self):
        """
        Test that can go to task list page
        """
        self.task_page.go_to_task_list()
        self.assertTrue(PageConfirm(self.driver).is_task_list_page(),
                        'Did not get to the task list page correctly')

    def test_go_to_patient_list_page(self):
        """
        Test that can go to the patient list page
        """
        self.task_page.go_to_patient_list()
        self.assertTrue(PageConfirm(self.driver).is_patient_list_page(),
                        'Did not get to patient list page correctly')

    def test_can_go_to_stand_in_page(self):
        """
        Test that can navigate to the stand in page
        """
        self.task_page.go_to_standin()
        self.assertTrue(PageConfirm(self.driver).is_stand_in_page(),
                        'Did not get to stand in page correctly')

    def test_can_carry_out_barcode_scan(self):
        """
        Test that can do a barcode scan
        """
        task_id = self.task_url.replace(
            TASK_PAGE, ''
        )
        id_to_use = self.task_page.task_scan_helper(int(task_id))
        self.task_page.do_barcode_scan(id_to_use['other_identifier'])

    def test_patient_info_name(self):
        """
        Test that can get the patient info popup on pressing patient name
        """
        patient_name_button = self.driver.find_element(
            *PATIENT_NAME_LINK
        )
        patient_id = patient_name_button.get_attribute('patient-id')

        popup = self.task_page.open_patient_info()
        popup_header = popup.find_element(
            *PATIENT_INFO_POPUP_TITLE
        )
        patient_data = self.task_page.patient_helper(int(patient_id))[0]
        popup_title = '{0} {1}'.format(patient_data['full_name'],
                                       patient_data['gender'])

        self.assertEqual(popup_title, popup_header.text.replace('\n', ' '),
                         'Incorrect popup name')

    def test_patient_info_button(self):
        """
        Test that can get the patient info popup on pressing patient name
        """
        patient_name_button = self.driver.find_element(
            *PATIENT_NAME_INFO
        )
        patient_id = patient_name_button.get_attribute('patient-id')

        popup = self.task_page.open_patient_info()
        popup_header = popup.find_element(
            *PATIENT_INFO_POPUP_TITLE
        )
        patient_data = self.task_page.patient_helper(int(patient_id))[0]
        popup_title = '{0} {1}'.format(patient_data['full_name'],
                                       patient_data['gender'])
        self.assertEqual(popup_title, popup_header.text.replace('\n', ' '),
                         'Incorrect popup name')

    def test_press_obs_data_button(self):
        """
        Test that pressing the 'View Patient Observation Data' shows the
        patient page in a fullscreen modal
        """
        patient_name_button = self.driver.find_element(
            *PATIENT_NAME_INFO
        )
        patient_id = patient_name_button.get_attribute('patient-id')
        fullscreen = self.task_page.open_full_patient_obs_data()
        iframe = fullscreen.find_element(
            *PATIENT_INFO_FULLSCREEN_IFRAME
        )
        iframe_url = iframe.get_attribute('src')
        patient_url = PATIENT_PAGE+'{0}'.format(
            patient_id
        )
        self.assertEqual(iframe_url, patient_url, 'Incorrect iframe src url')

    def test_close_full_obs_modal(self):
        """
        Test that can close the fullscreen modal
        """
        fullscreen = self.task_page.open_full_patient_obs_data()
        close_button = fullscreen.find_element(
            *PATIENT_INFO_FULLSCREEN_CLOSE
        )
        close_button.click()
        self.assertTrue(self.task_page.fullscreen_not_open(),
                        'Fullscreen did not close')
class TestPatientListPage(TestCommon):
    """
    Setup a session and test that the task list page works correctly
    """

    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.patient_list_page.go_to_patient_list()

    def test_can_logout(self):
        """
        Test that the title of the login page is Open-eObs
        """
        self.patient_list_page.logout()
        self.assertTrue(PageConfirm(self.driver).is_login_page(),
                        'Did not get to the logout page correctly')

    def test_can_go_task_list_page(self):
        """
        Test that can go to task list page
        """
        self.patient_list_page.go_to_task_list()
        self.assertTrue(PageConfirm(self.driver).is_task_list_page(),
                        'Did not get to the task list page correctly')

    def test_patient_list_page(self):
        """
        Test that can go to the patient list page
        """
        self.patient_list_page.go_to_patient_list()
        self.assertTrue(PageConfirm(self.driver).is_patient_list_page(),
                        'Did not get to patient list page correctly')

    def test_can_go_stand_in_page(self):
        """
        Test that can navigate to the stand in page
        """
        self.patient_list_page.go_to_standin()
        self.assertTrue(PageConfirm(self.driver).is_stand_in_page(),
                        'Did not get to stand in page correctly')

    def test_can_do_barcode_scan(self):
        """
        Test that can do a barcode scan
        """
        patients = self.patient_list_page.get_list_items()
        patient_to_test = patients[0]
        patient_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )
        id_to_use = self.patient_list_page.patient_scan_helper(int(patient_id))
        self.patient_list_page.do_barcode_scan(id_to_use['other_identifier'])

    def test_view_patient_details(self):
        """
        Test that clicking on a work item tasks user to carry out the task
        """
        patients = self.patient_list_page.get_list_items()
        patient_to_test = patients[0]
        patient_url = patient_to_test.get_attribute('href')
        patient_to_test.click()
        self.assertTrue(PageConfirm(self.driver).is_patient_page(),
                        'Did not get to patient page correctly')
        self.assertEqual(self.driver.current_url, patient_url,
                         'Incorrect url')

    def test_patient_name_in_list(self):
        """
        Test that the patient name is in the list item
        """
        patients = self.patient_list_page.get_list_items()
        patient_to_test = patients[0]
        task_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )
        task_data = self.patient_list_page.patient_helper(task_id)[0]
        name_to_use = task_data['full_name']
        patient_name = self.driver.find_element(
            *list_page_locators.LIST_ITEM_PATIENT_NAME
        )
        self.assertEqual(patient_name.text, name_to_use.strip(),
                         'Incorrect name')

    def test_patient_location_in_list(self):
        """
        Test that the patient name is in the list item
        """
        patients = self.patient_list_page.get_list_items()
        patient_to_test = patients[0]
        task_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )
        task_data = self.patient_list_page.patient_helper(task_id)[0]
        location = task_data['location']
        parent_location = task_data['parent_location']
        bed_to_use = '{0}, {1}'.format(location, parent_location)
        patient_location = self.driver.find_element(
            *list_page_locators.LIST_ITEM_PATIENT_LOCATION
        )
        self.assertEqual(bed_to_use, patient_location.text,
                         'Incorrect location')

    def test_score_and_trend_in_list(self):
        """
        Test that the score and trend are present in list item
        """
        tasks = self.patient_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )
        task_data = self.patient_list_page.patient_helper(task_id)[0]
        score = task_data['ews_score']
        trend = task_data['ews_trend']
        score_str = '({0} )'.format(score)
        patient_trend = self.driver.find_element(
            *list_page_locators.LIST_ITEM_PATIENT_TREND
        )
        trend_str = 'icon-{0}-arrow'.format(trend)
        self.assertEqual(patient_trend.get_attribute('class'), trend_str,
                         'Incorrect trend')
        self.assertIn(score_str, patient_to_test.text, 'Incorrect score')

    def test_down_trend(self):
        """
        Test that the trend is lowered after submitting a high risk ob,
        followed by a low risk ob
        """
        tasks = self.patient_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )

        PatientPage(self.driver).add_high_risk_observation(int(task_id))
        PatientPage(self.driver).add_low_risk_observation(int(task_id))
        self.driver.refresh()

        patient_trend = self.driver.find_element(
            *list_page_locators.LIST_ITEM_PATIENT_TREND
        )

        self.assertEqual(patient_trend.get_attribute('class'),
                         'icon-down-arrow',
                         'Incorrect trend')

    def test_up_trend(self):
        """
        Test that the trend is increased after submitting a low risk ob,
        followed by a high risk ob
        """
        tasks = self.patient_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )

        PatientPage(self.driver).add_low_risk_observation(int(task_id))
        PatientPage(self.driver).add_high_risk_observation(int(task_id))
        self.driver.refresh()

        patient_trend = self.driver.find_element(
            *list_page_locators.LIST_ITEM_PATIENT_TREND
        )

        self.assertEqual(patient_trend.get_attribute('class'), 'icon-up-arrow',
                         'Incorrect trend')

    def test_same_trend(self):
        """
        Test that the trend stays the same after submitting two of the same ob
        """
        tasks = self.patient_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )

        PatientPage(self.driver).add_medium_risk_observation(int(task_id))
        PatientPage(self.driver).add_medium_risk_observation(int(task_id))
        self.driver.refresh()

        patient_trend = self.driver.find_element(
            *list_page_locators.LIST_ITEM_PATIENT_TREND
        )

        self.assertEqual(patient_trend.get_attribute('class'),
                         'icon-same-arrow',
                         'Incorrect trend')

    def test_task_deadline_in_list(self):
        """
        Test that the patient name is in the list item
        """
        tasks = self.patient_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )
        task_data = self.patient_list_page.patient_helper(task_id)[0]
        deadline = task_data['next_ews_time']
        task_deadline = self.driver.find_element(
            *list_page_locators.LIST_ITEM_DEADLINE
        )
        self.assertEqual(deadline, task_deadline.text,
                         'Incorrect deadline')

    def test_shows_patients(self):
        """
        Test that the patient list shows patients for the user
        """
        patient_list = []
        for patient in self.patient_list_page.get_list_items():
            patient_list.append(patient)

        self.assertNotEquals(patient_list, [],
                             'Patient list not showing patients')

    def test_shows_patient_data(self):
        """
        Test that a patient record shows data (graph/table) for the patient
        """
        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)

        ui.WebDriverWait(self.driver, 1).until(
            ec.visibility_of_element_located(patient_page_locators.GRAPH_CHART)
        )

        patient_graph = self.driver.find_element(*
                                                 patient_page_locators
                                                 .GRAPH_CHART)

        self.assertEqual(patient_graph.is_displayed(), True, 'Graph not found')

        self.driver.find_element(*patient_page_locators
                                 .TABLE_TAB_BUTTON).click()

        ui.WebDriverWait(self.driver, 1).until(
            ec.visibility_of_element_located
            (patient_page_locators.TABLE_CONTAINER_TABLE))

        patient_table = self.driver.find_element(*
                                                 patient_page_locators
                                                 .TABLE_CONTAINER_TABLE)
        self.assertEqual(patient_table.is_displayed(), True, 'Table not found')
class TestVisualisationCommon(TestCommon):
    """
    Setup a session and ensure that patient data displays correctly
    """
    risk = 'none'

    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.list_page = ListPage(self.driver)
        self.patient_page = PatientPage(self.driver)
        self.patient_page_graph = PatientPageGraphs(self.driver)

        risk_mapping = {
            'none': self.patient_page.add_no_risk_observation,
            'low': self.patient_page.add_low_risk_observation,
            'medium':
                self.patient_page.add_medium_risk_observation,
            'high': self.patient_page.add_high_risk_observation,
            '3in1': self.patient_page.add_three_in_one_observation
        }
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.list_page.go_to_patient_list()
        patients = self.list_page.get_list_items()
        patient_to_test = patients[0]
        patient_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, ''
        )

        self.patient_page.remove_observations_for_patient(int(patient_id))
        risk_mapping[self.risk](int(patient_id))
        self.driver.get(patient_to_test.get_attribute('href'))
        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located((By.CSS_SELECTOR, '#chart svg')))

        self.patient_page.change_to_table()
        obs_table = self.patient_page.get_obs_table()
        rows = self.patient_page.get_table_rows(obs_table)[1:]

        self.row_data = []
        for row in rows:
            self.row_data.append(self.patient_page.get_table_data(row))

        self.patient_page_graph.change_to_chart()

        # Focus Graphs
        focus_graphs = self.patient_page_graph.get_focus_graphs()
        self.assertEqual(len(focus_graphs), 5, 'Incorrect number of graphs')
        self.graph_list = []

        for graph in focus_graphs:
            self.graph_list.append(graph)

        self.graph_data = self.get_graph_data()

    def get_graph_data(self):
        """
        Helper function to get an dict of the focus chart data
        :return: dict of strings from focus chart data
        """
        rr_mes = \
            self.patient_page_graph.get_graph_measurement(self.graph_list[0])
        os_mes = \
            self.patient_page_graph.get_graph_measurement(self.graph_list[1])
        bt_mes = \
            self.patient_page_graph.get_graph_measurement(self.graph_list[2])
        hr_mes = \
            self.patient_page_graph.get_graph_measurement(self.graph_list[3])
        bp_mes = \
            self.patient_page_graph.get_graph_measurements(self.graph_list[4])

        return {
            'resp_rate': rr_mes,
            'oxy_sat': os_mes,
            'body_temp': bt_mes,
            'pulse_rate': hr_mes,
            'blood_press': bp_mes
        }

    def get_focus_chart_labels(self):
        """
        Helper function to get an dict of the focus chart labels
        :return: dict of strings from focus chart labels
        """
        rr_label = self.patient_page_graph.get_graph_label(self.graph_list[0])
        os_label = self.patient_page_graph.get_graph_label(self.graph_list[1])
        bt_label = self.patient_page_graph.get_graph_label(self.graph_list[2])
        hr_label = self.patient_page_graph.get_graph_label(self.graph_list[3])
        bp_label = self.patient_page_graph.get_graph_label(self.graph_list[4])
        return {
            'resp_rate': rr_label,
            'oxy_sat': os_label,
            'body_temp': bt_label,
            'pulse_rate': hr_label,
            'blood_press': bp_label
        }

    def get_tabular_values_value(self, row, column):
        """
        Helper function to get the value from a row and column in the tabular
        values table
        :param row: Row to get value from
        :param column: Column to get value from
        :return: String from row/column combo
        """
        tabular_values_table = self.patient_page.get_tabular_values()

        tabular_values_rows = \
            self.patient_page.get_table_rows(tabular_values_table)

        tabular_values = \
            self.patient_page.get_table_data(tabular_values_rows[row])
        self.assertEqual(len(tabular_values), 4, 'Incorrect number of data')
        return tabular_values[column]
class TestPatientPageAdhocObs(TestCommon):
    """
    Test to ensure that the adhoc observation work correctly
    """
    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.list_page = ListPage(self.driver)
        self.patient_page = PatientPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.list_page.go_to_patient_list()
        patients = self.list_page.get_list_items()
        patient_to_test = patients[0]
        self.patient_url = patient_to_test.get_attribute('href')
        self.driver.get(self.patient_url)

    def test_can_logout(self):
        """
        Test that the title of the login page is Open-eObs
        """
        self.patient_page.logout()
        self.assertTrue(
            PageConfirm(self.driver).is_login_page(),
            'Did not get to the logout page correctly')

    def test_can_go_to_task_list_page(self):
        """
        Test that can go to task list page
        """
        self.patient_page.go_to_task_list()
        self.assertTrue(
            PageConfirm(self.driver).is_task_list_page(),
            'Did not get to the task list page correctly')

    def test_go_to_patient_list_page(self):
        """
        Test that can go to the patient list page
        """
        self.patient_page.go_to_patient_list()
        self.assertTrue(
            PageConfirm(self.driver).is_patient_list_page(),
            'Did not get to patient list page correctly')

    def test_can_go_to_stand_in_page(self):
        """
        Test that can navigate to the stand in page
        """
        self.patient_page.go_to_standin()
        self.assertTrue(
            PageConfirm(self.driver).is_stand_in_page(),
            'Did not get to stand in page correctly')

    def test_can_carry_out_barcode_scan(self):
        """
        Test that can do a barcode scan
        """
        task_id = self.patient_url.replace(PATIENT_PAGE, '')
        id_to_use = self.patient_page.patient_scan_helper(int(task_id))
        self.patient_page.do_barcode_scan(id_to_use['other_identifier'])

    def test_can_open_adhoc_menu(self):
        """
        Test that can see and open a menu to select an adhoc observation to
        carry out for the patient
        """
        menu = self.patient_page.open_adhoc_obs_menu()
        menu_title = menu.find_element(*OPEN_OBS_MENU_TITLE)
        observations = menu.find_elements(*OPEN_OBS_MENU_LIST_ITEMS)
        self.assertGreater(len(observations), 0,
                           'Incorrect number of adhoc obs')
        task_id = self.patient_url.replace(PATIENT_PAGE, '')
        data = self.patient_page.patient_helper(int(task_id))[0]
        patient_name = data['full_name']
        self.assertEqual(menu_title.text,
                         'Pick an observation for {0}'.format(patient_name),
                         'Incorrect menu title')

    def test_adhoc_news_ob_deadline(self):
        """
        Test that the NEWS observation in the adhoc observation list shows
        the deadline to the next scheduled NEWS observation
        """
        menu = self.patient_page.open_adhoc_obs_menu()
        news_item = menu.find_element(*OPEN_OBS_MENU_NEWS_ITEM)
        deadline = news_item.find_element(*OPEN_OBS_MENU_NEWS_DEADLINE)
        task_id = self.patient_url.replace(PATIENT_PAGE, '')
        data = self.patient_page.patient_helper(int(task_id))[0]
        ews_deadline = data['next_ews_time']
        self.assertEqual(deadline.text, ews_deadline,
                         'Incorrect NEWS deadline')
class TestTaskListPage(TestCommon):
    """
    Setup a session and test that the task list page works correctly
    """

    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.task_list_page = ListPage(self.driver)
        self.patient_list_page = ListPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.task_list_page.go_to_task_list()

    def test_can_logout(self):
        """
        Test that the title of the login page is Open-eObs
        """
        self.task_list_page.logout()
        self.assertTrue(PageConfirm(self.driver).is_login_page(),
                        'Did not get to the logout page correctly')

    def test_can_go_to_task_list_page(self):
        """
        Test that can go to task list page
        """
        self.task_list_page.go_to_task_list()
        self.assertTrue(PageConfirm(self.driver).is_task_list_page(),
                        'Did not get to the task list page correctly')

    def test_go_to_patient_list_page(self):
        """
        Test that can go to the patient list page
        """
        self.task_list_page.go_to_patient_list()
        self.assertTrue(PageConfirm(self.driver).is_patient_list_page(),
                        'Did not get to patient list page correctly')

    def test_can_go_to_stand_in_page(self):
        """
        Test that can navigate to the stand in page
        """
        self.task_list_page.go_to_standin()
        self.assertTrue(PageConfirm(self.driver).is_stand_in_page(),
                        'Did not get to stand in page correctly')

    def test_can_carry_out_barcode_scan(self):
        """
        Test that can do a barcode scan
        """
        tasks = self.task_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            TASK_PAGE, ''
        )
        id_to_use = self.task_list_page.task_scan_helper(task_id)
        self.task_list_page.do_barcode_scan(id_to_use['other_identifier'])

    def test_click_list_item(self):
        """
        Test that clicking on a work item tasks user to carry out the task
        """
        tasks = self.task_list_page.get_list_items()
        task_to_test = tasks[0]
        task_url = task_to_test.get_attribute('href')
        task_to_test.click()
        self.assertTrue(PageConfirm(self.driver).is_task_page(),
                        'Did not get to task page correctly')
        self.assertEqual(self.driver.current_url, task_url,
                         'Incorrect url')

    def test_list_item_patient_name(self):
        """
        Test that the patient name is in the list item
        """
        tasks = self.task_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            TASK_PAGE, ''
        )
        task_data = self.task_list_page.task_helper(task_id)[0]
        name_to_use = task_data['full_name']
        patient_name = self.driver.find_element(
            *list_page_locators.LIST_ITEM_PATIENT_NAME
        )
        self.assertEqual(patient_name.text, name_to_use.strip(),
                         'Incorrect name')

    def test_list_item_patient_location(self):
        """
        Test that the patient name is in the list item
        """
        tasks = self.task_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            TASK_PAGE, ''
        )
        task_data = self.task_list_page.task_helper(task_id)[0]
        location = task_data['location']
        parent_location = task_data['parent_location']
        bed_to_use = '{0}, {1}'.format(location, parent_location)
        patient_location = self.driver.find_element(
            *list_page_locators.LIST_ITEM_PATIENT_LOCATION
        )
        self.assertEqual(bed_to_use, patient_location.text,
                         'Incorrect location')

    def test_list_item_score_trend(self):
        """
        Test that the score and trend are present in list item
        """
        tasks = self.task_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            TASK_PAGE, ''
        )
        task_data = self.task_list_page.task_helper(task_id)[0]
        score = task_data['ews_score']
        trend = task_data['ews_trend']
        score_str = '({0} )'.format(score)
        patient_trend = self.driver.find_elements(
            *list_page_locators.LIST_ITEM_PATIENT_TREND
        )
        for item in patient_trend:
            if item.get_attribute('class') == 'icon-alert':
                patient_trend.remove(item)

        trend_str = 'icon-{0}-arrow'.format(trend)
        self.assertEqual(patient_trend[0].get_attribute('class'), trend_str,
                         'Incorrect trend')
        self.assertIn(score_str, patient_to_test.text, 'Incorrect score')

    def test_list_item_task_deadline(self):
        """
        Test that the patient name is in the list item
        """
        tasks = self.task_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            TASK_PAGE, ''
        )
        task_data = self.task_list_page.task_helper(task_id)[0]
        deadline = task_data['deadline_time']
        task_deadline = self.driver.find_element(
            *list_page_locators.LIST_ITEM_DEADLINE
        )
        self.assertEqual(deadline, task_deadline.text,
                         'Incorrect deadline')

    def test_list_item_task_summary(self):
        """
        Test that the patient name is in the list item
        """
        tasks = self.task_list_page.get_list_items()
        patient_to_test = tasks[0]
        task_id = patient_to_test.get_attribute('href').replace(
            TASK_PAGE, ''
        )
        task_data = self.task_list_page.task_helper(task_id)[0]
        summary = task_data['summary']
        task_summary = self.driver.find_element(
            *list_page_locators.LIST_ITEM_TITLE
        )
        self.assertEqual(summary, task_summary.text,
                         'Incorrect summary')

    def test_shows_tasks(self):
        """
        Test that the task list shows tasks for the user
        """
        task_list = []
        for patient in self.task_list_page.get_list_items():
            task_list.append(patient)

        self.assertNotEquals(task_list, [], 'Task list not showing tasks')

    def test_take_task_news_obs(self):
        """
        Submit adhoc observation which creates News observation task
        and Take task NEWS Observation from task list, submit news score
        """

        # Enter high risk observation to create News Observation task in task
        # list
        self.patient_list_page.go_to_patient_list()
        high_score = HIGH_RISK_SCORE_9_EWS_DATA
        no_risk = NO_RISK_EWS_DATA
        news_task = []
        success = 'Successfully Submitted NEWS Observation'

        patients = self.patient_list_page.get_list_items()

        PatientPage(self.driver).select_patient(patients)
        PatientPage(self.driver).open_form(OPEN_OBS_MENU_NEWS_ITEM)
        PatientPage(self.driver).enter_obs_data(high_score)

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(CONFIRM_SUBMIT)
        )
        self.driver.find_element(*CONFIRM_SUBMIT).click()

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located((
                SUCCESSFUL_SUBMIT))
        )
        response = self.driver.find_element(*SUCCESSFUL_SUBMIT)
        self.assertEqual(success, response.text,
                         'NEWS observation unsuccessful')

        self.driver.find_element(*GO_TO_MY_TASK).click()

        # Click on the first news score task from Task list
        self.task_list_page.go_to_task_list()

        self.driver.refresh()
        for task in self.task_list_page.get_list_task():
            # print(task.text)
            if task.text == 'NEWS Observation':
                news_task.append(task)
        news_task[0].click()

        # enter low risk observation
        PatientPage(self.driver).enter_obs_data(no_risk)

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located(CONFIRM_SUBMIT)
        )

        self.driver.find_element(*CONFIRM_SUBMIT).click()

        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located((
                SUCCESSFUL_SUBMIT))
        )
        response = self.driver.find_element(*SUCCESSFUL_SUBMIT)
        self.assertEqual(success, response.text,
                         'NEWS observation unsuccessful')
class TestPatientPageAdhocObs(TestCommon):
    """
    Test to ensure that the adhoc observation work correctly
    """

    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.list_page = ListPage(self.driver)
        self.patient_page = PatientPage(self.driver)
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.list_page.go_to_patient_list()
        patients = self.list_page.get_list_items()
        patient_to_test = patients[0]
        self.patient_url = patient_to_test.get_attribute('href')
        self.driver.get(self.patient_url)

    def test_can_logout(self):
        """
        Test that the title of the login page is Open-eObs
        """
        self.patient_page.logout()
        self.assertTrue(PageConfirm(self.driver).is_login_page(),
                        'Did not get to the logout page correctly')

    def test_can_go_to_task_list_page(self):
        """
        Test that can go to task list page
        """
        self.patient_page.go_to_task_list()
        self.assertTrue(PageConfirm(self.driver).is_task_list_page(),
                        'Did not get to the task list page correctly')

    def test_go_to_patient_list_page(self):
        """
        Test that can go to the patient list page
        """
        self.patient_page.go_to_patient_list()
        self.assertTrue(PageConfirm(self.driver).is_patient_list_page(),
                        'Did not get to patient list page correctly')

    def test_can_go_to_stand_in_page(self):
        """
        Test that can navigate to the stand in page
        """
        self.patient_page.go_to_standin()
        self.assertTrue(PageConfirm(self.driver).is_stand_in_page(),
                        'Did not get to stand in page correctly')

    def test_can_carry_out_barcode_scan(self):
        """
        Test that can do a barcode scan
        """
        task_id = self.patient_url.replace(
            PATIENT_PAGE, ''
        )
        id_to_use = self.patient_page.patient_scan_helper(int(task_id))
        self.patient_page.do_barcode_scan(id_to_use['other_identifier'])

    def test_can_open_adhoc_menu(self):
        """
        Test that can see and open a menu to select an adhoc observation to
        carry out for the patient
        """
        menu = self.patient_page.open_adhoc_obs_menu()
        menu_title = menu.find_element(
            *OPEN_OBS_MENU_TITLE
        )
        observations = menu.find_elements(
            *OPEN_OBS_MENU_LIST_ITEMS
        )
        self.assertGreater(len(observations), 0,
                           'Incorrect number of adhoc obs')
        task_id = self.patient_url.replace(
            PATIENT_PAGE, ''
        )
        data = self.patient_page.patient_helper(int(task_id))[0]
        patient_name = data['full_name']
        self.assertEqual(menu_title.text,
                         'Pick an observation for {0}'.format(patient_name),
                         'Incorrect menu title')

    def test_adhoc_news_ob_deadline(self):
        """
        Test that the NEWS observation in the adhoc observation list shows
        the deadline to the next scheduled NEWS observation
        """
        menu = self.patient_page.open_adhoc_obs_menu()
        news_item = menu.find_element(
            *OPEN_OBS_MENU_NEWS_ITEM
        )
        deadline = news_item.find_element(
            *OPEN_OBS_MENU_NEWS_DEADLINE
        )
        task_id = self.patient_url.replace(
            PATIENT_PAGE, ''
        )
        data = self.patient_page.patient_helper(int(task_id))[0]
        ews_deadline = data['next_ews_time']
        self.assertEqual(deadline.text, ews_deadline,
                         'Incorrect NEWS deadline')
class TestVisualisationCommon(TestCommon):
    """
    Setup a session and ensure that patient data displays correctly
    """
    risk = 'none'

    def setUp(self):
        self.driver.get(MOB_LOGIN)
        self.login_page = LoginPage(self.driver)
        self.list_page = ListPage(self.driver)
        self.patient_page = PatientPage(self.driver)
        self.patient_page_graph = PatientPageGraphs(self.driver)

        risk_mapping = {
            'none': self.patient_page.add_no_risk_observation,
            'low': self.patient_page.add_low_risk_observation,
            'medium': self.patient_page.add_medium_risk_observation,
            'high': self.patient_page.add_high_risk_observation,
            '3in1': self.patient_page.add_three_in_one_observation
        }
        self.login_page.login(NURSE_USERNM1, NURSE_PWD1)
        self.list_page.go_to_patient_list()
        patients = self.list_page.get_list_items()
        patient_to_test = patients[0]
        patient_id = patient_to_test.get_attribute('href').replace(
            PATIENT_PAGE, '')

        self.patient_page.remove_observations_for_patient(int(patient_id))
        risk_mapping[self.risk](int(patient_id))
        self.driver.get(patient_to_test.get_attribute('href'))
        ui.WebDriverWait(self.driver, 5).until(
            ec.visibility_of_element_located((By.CSS_SELECTOR, '#chart svg')))

        self.patient_page.change_to_table()
        obs_table = self.patient_page.get_obs_table()
        rows = self.patient_page.get_table_rows(obs_table)[1:]

        self.row_data = []
        for row in rows:
            self.row_data.append(self.patient_page.get_table_data(row))

        self.patient_page_graph.change_to_chart()

        # Focus Graphs
        focus_graphs = self.patient_page_graph.get_focus_graphs()
        self.assertEqual(len(focus_graphs), 5, 'Incorrect number of graphs')
        self.graph_list = []

        for graph in focus_graphs:
            self.graph_list.append(graph)

        self.graph_data = self.get_graph_data()

    def get_graph_data(self):
        """
        Helper function to get an dict of the focus chart data
        :return: dict of strings from focus chart data
        """
        rr_mes = \
            self.patient_page_graph.get_graph_measurement(self.graph_list[0])
        os_mes = \
            self.patient_page_graph.get_graph_measurement(self.graph_list[1])
        bt_mes = \
            self.patient_page_graph.get_graph_measurement(self.graph_list[2])
        hr_mes = \
            self.patient_page_graph.get_graph_measurement(self.graph_list[3])
        bp_mes = \
            self.patient_page_graph.get_graph_measurements(self.graph_list[4])

        return {
            'resp_rate': rr_mes,
            'oxy_sat': os_mes,
            'body_temp': bt_mes,
            'pulse_rate': hr_mes,
            'blood_press': bp_mes
        }

    def get_focus_chart_labels(self):
        """
        Helper function to get an dict of the focus chart labels
        :return: dict of strings from focus chart labels
        """
        rr_label = self.patient_page_graph.get_graph_label(self.graph_list[0])
        os_label = self.patient_page_graph.get_graph_label(self.graph_list[1])
        bt_label = self.patient_page_graph.get_graph_label(self.graph_list[2])
        hr_label = self.patient_page_graph.get_graph_label(self.graph_list[3])
        bp_label = self.patient_page_graph.get_graph_label(self.graph_list[4])
        return {
            'resp_rate': rr_label,
            'oxy_sat': os_label,
            'body_temp': bt_label,
            'pulse_rate': hr_label,
            'blood_press': bp_label
        }

    def get_tabular_values_value(self, row, column):
        """
        Helper function to get the value from a row and column in the tabular
        values table
        :param row: Row to get value from
        :param column: Column to get value from
        :return: String from row/column combo
        """
        tabular_values_table = self.patient_page.get_tabular_values()

        tabular_values_rows = \
            self.patient_page.get_table_rows(tabular_values_table)

        tabular_values = \
            self.patient_page.get_table_data(tabular_values_rows[row])
        self.assertEqual(len(tabular_values), 4, 'Incorrect number of data')
        return tabular_values[column]