# -*- coding: utf-8 -*- ## # Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. # copyright # THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, # IN PART OR IN WHOLE, # WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # # file tst_create_patient_ID # date 2022/01/18 # author Joseph varghese # # NOTE: # This test is intended to be used to verify patient id in application. . import names from dialin.ui import utils from dialin.ui.hd_simulator import HDSimulator from configuration import utility, config def keyboard_object_map_helper(text): """ Method for setting custom object property's for keyboard keys @return: required object property's for keys """ if text is not None: names.keboard_input["text"] = text return names.keboard_input else: test.log(f"Invalid \"text\": {text} for object.") names.keyboard_input["text"] = "Q" def validation_of_confirm_button_without_patient_id(): pass def keyboard_switching_section(text): """ Tests to automate keyboard based on user input @return: key text (text displayed on keyboard) """ keyboard_value = keyboard_object_map_helper(text) object_status = object.exists(keyboard_value) if object_status is True: return text else: #Tests to get status of keys in keyboard layout object_status = object.exists(keyboard_object_map_helper(config.KEYBOARD_SWITCH[1])) if object_status is True: keyboard_value = keyboard_object_map_helper(config.KEYBOARD_SWITCH[1]) utils.waitForGUI(.3) mouseClick(waitForObject(keyboard_value)) keyboard_value = keyboard_object_map_helper(text) object_status = object.exists(keyboard_value) if object_status is True: return text object_status = object.exists(keyboard_object_map_helper(config.KEYBOARD_SWITCH[0])) if object_status is True: keyboard_value = keyboard_object_map_helper(config.KEYBOARD_SWITCH[0]) mouseClick(waitForObject(keyboard_value)) keyboard_value = keyboard_object_map_helper(text) object_status = object.exists(keyboard_value) if object_status is True: return text object_status = object.exists(names.keyboard_switch) if object_status is True: keyboard_value = waitForObject(names.keyboard_switch) mouseClick(keyboard_value) text = text.lower() keyboard_value = keyboard_object_map_helper(text) object_status = object.exists(keyboard_value) if object_status is True: return text object_status = object.exists(names.keyboard_switch2) if object_status is True: keyboard_value = waitForObject(names.keyboard_switch_2) mouseClick(keyboard_value) text = text.lower() keyboard_value = keyboard_object_map_helper(text) object_status = object.exists(keyboard_value) if object_status is True: return text def user_input_clear_option(): """ Tests to clear retained patient id @return: N/A """ patient_id_input = waitForObject(names.input_patient_id) patient_id = str(patient_id_input.text) patient_id_length = len(patient_id) while (patient_id_length != 0): type(waitForObject(names.input_patient_id), "") type(waitForObject(names.input_patient_id), "") patient_id_length = patient_id_length - 1 def validation_of_valid_patient_id_through_keypad(expected_value): """ Tests verifies valid patient id set through application keyboard setup . @return: N/A """ patient_id_input = waitForObject(names.input_patient_id) mouseClick(patient_id_input) patient_id = list(expected_value) for text in patient_id: keyword_state = keyboard_switching_section(text) if keyword_state is not None: keyboard_value = keyboard_object_map_helper(keyword_state) mouseClick(waitForObject(keyboard_value)) utils.waitForGUI(.2) test.compare(expected_value, (patient_id_input.text)) test.log(f"Patient id should be -> {expected_value}") verify_confirm_button_based_on_patient_id(expected_value) mouseClick(waitForObject(names.confirm_button)) custom_treatment = waitForObject(names.custom_treatment) test.compare("Create a Custom Treatment", custom_treatment.text) test.log(f"user successfully authenticated through patient id -> {expected_value} using keypad.") mouseClick(waitForObject(names.back_button)) def validation_of_valid_patient_id_through_user_input(expected_value): """ Tests verifies valid patient id set through user's input. @return: N/A """ patient_id_input = waitForObject(names.input_patient_id) mouseClick(waitForObject(patient_id_input)) type(waitForObject(names.input_patient_id), expected_value) test.compare(expected_value, (patient_id_input.text)) test.log(f"Patient id should be -> {expected_value}") verify_confirm_button_based_on_patient_id(expected_value) mouseClick(waitForObject(names.confirm_button)) custom_treatment = waitForObject(names.custom_treatment) test.compare("Create a Custom Treatment", custom_treatment.text) test.log(f"user successfully authenticated through patient id -> {expected_value}.") mouseClick(waitForObject(names.back_button)) def verify_confirm_button_based_on_patient_id(patient_id): """ Tests verifies confirm button based on patient id. @input : patient id to be set @return: N/A """ utils.waitForGUI(1) if patient_id is None: patient_id_input = waitForObject(names.input_patient_id) mouseClick(waitForObject(patient_id_input)) type(patient_id_input, " ") confirm_button_status = waitForObject(names.confirm_button) if confirm_button_status.enabled == False: test.passes("confirm button disabled without patient id") else: test.xfail("confirm button enabled without patient id") else: confirm_button_status = waitForObject(names.confirm_button) if confirm_button_status.enabled == True: test.passes(f"confirm button enabled with patient id -> {patient_id}") else: test.fail(f"confirm button disabled with patient id -> {patient_id}") def validation_of_invalid_patient_id_through_user_input(expected_value): """ Tests verifies invalid patient id set through user's input. @return: N/A """ patient_id_input = waitForObject(names.input_patient_id) mouseClick(waitForObject(patient_id_input)) type(waitForObject(names.input_patient_id), expected_value) if expected_value is not patient_id_input.text or patient_id_input.text is None: test.passes(f"Patient ID -> {expected_value} should be invalid") else: test.xfail(f"Patient ID {expected_value} is valid") user_input_clear_option() def main(): utils.tstStart("tst_patient_id") utility.start_application("validation of patient ID") utils.waitForGUI(2) hd = HDSimulator() hd.cmd_send_power_on_self_test_version_request() hd._handler_ui_first_check_in(message = None) mouseClick(waitForObject(names.input_patient_id)) for patient_id in config.CHARACTER_PATIENT_ID: validation_of_valid_patient_id_through_keypad(patient_id) validation_of_valid_patient_id_through_user_input(patient_id) hd.cmd_send_hd_operation_mode(3) hd._handler_ui_first_check_in(message = None) for patient_id in config.ALPHANUMERIC_PATIENT_ID: validation_of_valid_patient_id_through_keypad(patient_id) validation_of_valid_patient_id_through_user_input(patient_id) #verification of confirm button without giving patient id verify_confirm_button_based_on_patient_id(patient_id = None) utils.tstDone()