# Subject/Title: import names, re from configuration import utility, config 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.ui_defs import TXStates from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions from leahi_dialin.protocols import CAN from leahi_dialin.utils import conversions 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, cumulative_volume, 0, 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( systolic, diastolic, heartRate, target_rate, volume_delivered, H2_arterial_pressure, H14_venous_pressure, tmp_pressure, cumulative_volume, blood_flow, dialysate_flow, dialysate_temp, D29, ): test.compare( utility.get_object_value(names.o_TreatmentTrends_bloodpressureValue_ValueText), f"{systolic}/{diastolic}", "Bloodpressure Value", ) test.compare( utility.get_object_value(names.o_TreatmentTrends_pulseRateValue_ValueText), str(heartRate), "Pulse Rate Value", ) test.compare( utility.get_object_value( names.o_TreatmentTrends_ufVolumeRemovedValue_ValueText ), str(volume_delivered), "UF Volume Value", ) test.compare( utility.get_object_value(names.o_TreatmentTrends_ufRateValue_ValueText), str(target_rate), "UF Rate Value", ) test.compare( utility.get_object_value( names.o_TreatmentTrends_arterialPressureValue_ValueText ), str(H2_arterial_pressure), "Arterial Pressure Value", ) test.compare( utility.get_object_value(names.o_TreatmentTrends_venousPressureValue_ValueText), str(H14_venous_pressure), "Venous Pressure Value", ) test.compare( utility.get_object_value(names.o_TreatmentTrends_tmpValue_ValueText), str(tmp_pressure), "TMP Value", ) test.compare( utility.get_object_value( names.o_TreatmentTrends_bolusCumulativeDeliveredValue_ValueText ), str(cumulative_volume), "Cumulative Value", ) test.compare( utility.get_object_value(names.o_TreatmentTrends_bloodFlowRateValue_ValueText), str(blood_flow), "Blood Flow Rate Value", ) test.compare( utility.get_object_value( names.o_TreatmentTrends_dialysateFlowRateValue_ValueText ), str(dialysate_flow), "Dialysate Flow Rate Value", ) test.compare( utility.get_object_value( names.o_TreatmentTrends_dialysateTemperatureValue_ValueText ), str(dialysate_temp), "Dialysate Temperature Value", ) test.compare( utility.get_object_value(names.o_TreatmentTrends_conductivityValue_ValueText), 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) test.log(f"Updated value: {current_value}") test.log(f"✅ Target value reached: {current_value}") 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) # check the title title = waitForObjectExists( utility.setObjectText(text=title_name, obj=names.o_title_Text) ) test.compare(title_name, title.text, "Title text should be -> " + str(title_name)) for text in expected_value: keyboard_value = keyboard_object_map_helper(text) utils.waitForGUI(0.2) mouseClick(waitForObjectExists(keyboard_value)) utils.waitForGUI(0.2) test.compare( actual_value, (input_field.text), "Value should be -> " + str(actual_value) ) test.log( "User successfully authenticated through patient id -> " + expected_value + "using keypad." ) # 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_automatic_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 ) startApplication(utility.aut("-q")) td_simulator.td_operation_mode(TDOpModes.MODE_PRET.value) 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(1.65, 1.18, 150, 240, 200, 150, 132, 167, 15.3, 600) td_simulator.td_vitals(121, 81, 71) verify_trends_data(121, 81, 71, 1.65, 1.18, 150, 240, 200, 150, 132, 167, 15.3, 600) 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)) # verify_automatic_vitals_request() 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(utility.get_object_from_names(names.o_confirm_button)) verify_trends_data(122, 82, 72, 1.73, 1.26, 160, 250, 190, 170, 144, 147, 13.4, 700) verify_automatic_vitals_request()