# Subject/Title: Trends and Screensaver Screens - SW - 02 - Trends Screen - Q&R # # Functionalities: Testing of Trends and Screensaver Screens # # Steps: # 1 Handle vitalsRequest sent messages messages from UI to FW # 2 Start Leahi application and navigate to Main Treatment screen # 3 Navigate to Trends Screen, send Trends Data and Compare it # 4 Click on Vitals Popup Measure Vitals button and verify FW received # 5 Send Normal and Maximum Trends Data and Compare it # 6 Compare Rejection reasons of Vitals Popup import names, re from configuration import utility, config, application_init from leahi_dialin.ui import utils from leahi_dialin.ui.td_messaging import TD_Messaging from leahi_dialin.ui.dd_messaging import DD_Messaging from leahi_dialin.common.td_defs import TDOpModes, TDTreatmentStates from leahi_dialin.common.msg_defs import MsgIds from leahi_dialin.protocols import CAN from configuration.getrejectiontext import ScopedRejectionRepository td_simulator = TD_Messaging() dd_simulator = DD_Messaging() vitalsRequest = None can_interface = td_simulator.can_interface def trends_data( target_rate, volume_delivered, H2_arterial_pressure, H14_venous_pressure, tmp_pressure, cumulative_volume, blood_flow, dialysate_flow, dialysate_temp, D29, ): td_simulator.td_ultrafiltration(0, target_rate, volume_delivered, 0) td_simulator.td_pressure( H2_arterial_pressure, H14_venous_pressure, 0, 0, 0, 0, 0, 0, 0, tmp_pressure, 0, 0, 0, 0, ) td_simulator.td_saline(0, 0, cumulative_volume, 0) td_simulator.td_treatment_set_points(blood_flow, dialysate_flow, dialysate_temp) dd_simulator.dd_conductivity(0, D29, 0, 0, 0) def verify_trends_data_column_wise( systolic, diastolic, heartRate, target_rate, volume_delivered, H2_arterial_pressure, H14_venous_pressure, tmp_pressure, cumulative_volume, blood_flow, dialysate_flow, dialysate_temp, D29, ): parent_object = utility.get_object_from_names( names.o_TreatmentTrends_paramListDelegate_Column ) test.compare( utility.findObjectById(parent_object, "_bloodpressureValue").value, f"{systolic}/{diastolic}", "Bloodpressure Value", ) test.compare( utility.findObjectById(parent_object, "_pulseRateValue").value, str(heartRate), "Pulse Rate Value", ) test.compare( utility.findObjectById(parent_object, "_ufVolumeRemovedValue").value, str(volume_delivered), "UF Volume Value", ) test.compare( utility.findObjectById(parent_object, "_ufRateValue").value, str(target_rate), "UF Rate Value", ) test.compare( utility.findObjectById(parent_object, "_arterialPressureValue").value, str(H2_arterial_pressure), "Arterial Pressure Value", ) test.compare( utility.findObjectById(parent_object, "_venousPressureValue").value, str(H14_venous_pressure), "Venous Pressure Value", ) test.compare( utility.findObjectById(parent_object, "_tmpValue").value, str(tmp_pressure), "TMP Value", ) test.compare( utility.findObjectById(parent_object, "_bolusCumulativeDeliveredValue").value, str(cumulative_volume), "Cumulative Value", ) test.compare( utility.findObjectById(parent_object, "_bloodFlowRateValue").value, str(blood_flow), "Blood Flow Rate Value", ) test.compare( utility.findObjectById(parent_object, "_dialysateFlowRateValue").value, str(dialysate_flow), "Dialysate Flow Rate Value", ) test.compare( utility.findObjectById(parent_object, "_dialysateTemperatureValue").value, str(dialysate_temp), "Dialysate Temperature Value", ) test.compare( utility.findObjectById(parent_object, "_conductivityValue").value, str(D29 / 1000), "Conductivity Value", ) def set_value_based_on_target_patientvitals(obj, target_value): """ obj: dictionary containing object paths Example: { "value_obj": ":mainTreatmentScreen.PressureText", "left_arrow": ":mainTreatmentScreen.LeftArrow", "right_arrow": ":mainTreatmentScreen.RightArrow" } target_value: integer or string number, e.g. 220 """ target_value = target_value # Wait for all objects parent_obj = waitForObjectExists(obj) # change range as per your screen count left_arrow = utility.findObjectById(parent_obj, "_leftArrow") right_arrow = utility.findObjectById(parent_obj, "_rightArrow") # Read current value (supports invisible text too) parent = waitForObject(parent_obj) current_value = utility.findObjectById(parent, "_currentItem") current_value = str(current_value.text) # Determine direction while float(current_value) != float(target_value): if float(current_value) < float(target_value): mouseClick(waitForObject(right_arrow)) elif float(current_value) > float(target_value): mouseClick(waitForObject(left_arrow)) parent = waitForObject(parent_obj) current_value = utility.findObjectById(parent, "_currentItem") current_value = str(current_value.text) 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.keyboard_input["text"] = text return names.keyboard_input else: test.log("Invalid ", text, " for object.") names.o_keyboard_input["text"] = "Q" def verify_valid_vitals_through_keypad( title_name, input_field_obj, expected_value, actual_value ): """ Tests verifies valid patient id set through application keyboard setup . @return: N/A """ input_field = waitForObject(input_field_obj) mouseClick(input_field) for text in expected_value: keyboard_value = keyboard_object_map_helper(text) utils.waitForGUI(0.2) mouseClick(waitForObjectExists(keyboard_value)) utils.waitForGUI(0.2) # handler for messages from UI to FW def handle_patient_vitals_request(message, timestamp=0.0): """ Called when the user requests to firmware from UI @return: None """ global vitalsRequest vitalsRequest = True def verify_vitals_request(): MAX_WAIT = 6 * 60 * 1000 # 5 minutes in seconds test.verify( waitFor(lambda: vitalsRequest == True, MAX_WAIT), "Testing UI -> TD message Vitals Request", ) def main(): utils.tstStart(__file__) if can_interface is None: test.fail("CAN Interface is not available. Stopping tests.") return channel_id = CAN.CanChannels.ui_to_td_ch_id # Register Vitals Request message_id = MsgIds.MSG_ID_UI_BLOOD_PRESSURE_REQUEST.value can_interface.register_receiving_publication_function( channel_id, message_id, handle_patient_vitals_request ) conf_path = application_init.configuration_folder_path() + "Alarms/Rejections.conf" repo = ScopedRejectionRepository(path=conf_path) startApplication(utility.aut("-q")) td_simulator.td_operation_mode(TDOpModes.MODE_PRET.value) td_simulator.td_tx_state( TDTreatmentStates.TREATMENT_START_STATE.value, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) td_simulator.td_tx_state( TDTreatmentStates.TREATMENT_DIALYSIS_STATE.value, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) mouseClick( waitForObject(utility.setObjectText(names.o_listView_Item, config.TRENDS), 3000) ) trends_data(0.01, 0.01, 0, 0, 0, 0, 0, 0, 0.0, 0) td_simulator.td_vitals(0, 0, 0) test.startSection("Verification of Trends Data at Minimum Values") verify_trends_data_column_wise(0, 0, 0, 0.01, 0.01, 0, 0, 0, 0, 0, 0, 0.0, 0) test.endSection() td_simulator.td_operation_mode(TDOpModes.MODE_POST.value) td_simulator.td_operation_mode(TDOpModes.MODE_TREA.value) td_simulator.td_tx_state( TDTreatmentStates.TREATMENT_START_STATE.value, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) td_simulator.td_tx_state( TDTreatmentStates.TREATMENT_DIALYSIS_STATE.value, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) mouseClick( utility.get_object_from_names(names.o_treatmentHome_editButton_IconButton) ) set_value_based_on_target_patientvitals( names.o_bpMeasurementIntervalControl_ValueAdjusterCustom, 5 ) mouseClick(utility.get_object_from_names(names.o_confirm_button)) mouseClick(utility.get_object_from_names(names.o_Vitals_Popup_CloseButton)) mouseClick( waitForObject(utility.setObjectText(names.o_listView_Item, config.TRENDS), 3000) ) trends_data(1.73, 1.26, 160, 250, 190, 170, 144, 147, 13.4, 700) mouseClick(utility.get_object_from_names(names.o_vitalsButton_VitalsButton)) verify_valid_vitals_through_keypad( config.SYSTOLIC, names.o_bloodPressureSystolic_TextEntry, "122", "122" ) verify_valid_vitals_through_keypad( config.DIASTOLIC, names.o_bloodPressureDiastolic_TextEntry, "82", "82" ) verify_valid_vitals_through_keypad( config.HEARTRATE, names.o_heartRate_TextEntry, "72", "72" ) mouseClick(waitForObject(names.o_measureVitalsButton_TouchRect)) mouseClick(utility.get_object_from_names(names.o_confirm_button)) test.startSection("Verify UI the Vitals Request") verify_vitals_request() test.endSection() trends_data(9.99, 7.99, 200, 500, 250, 10000, 900, 900, 100.0, 1000) td_simulator.td_vitals(300, 200, 200) test.startSection("Verification of Trends Data at Normal Values") verify_trends_data_column_wise( 122, 82, 72, 1.73, 1.26, 160, 250, 190, 170, 144, 147, 13.4, 700 ) test.endSection() test.startSection("Verification of Trends Data at Maximum Values") verify_trends_data_column_wise( 300, 200, 200, 9.99, 7.99, 200, 500, 250, 10000, 900, 900, 100.0, 1000 ) test.endSection() test.startSection("Verification of Vitals Popup Rejection Reasons") mouseClick(utility.get_object_from_names(names.o_vitalsButton_VitalsButton)) for rejection_reason in range(1, 60): td_simulator.td_vitals_adjustment_response(vRejectionReason=rejection_reason) REJECT_TEXT = repo.get(str(rejection_reason), "Title") vitals_popup_notification = utility.get_object_from_names( names.o_notification_bar ) vitals_popup_notification_text = str(vitals_popup_notification.text) test.compare( vitals_popup_notification_text, "Rejected Reason: [" + str(rejection_reason) + "] " + REJECT_TEXT, f"Rejection reason number comparison for reason {rejection_reason}", ) test.endSection() utils.tstDone()