Index: suite_leahi/tst_patient_vitals/test.py =================================================================== diff -u -rc90bf31bab181ed557249018a610f29a83445655 -rd821a29980219bd4228d724160ac1c353b3407b2 --- suite_leahi/tst_patient_vitals/test.py (.../test.py) (revision c90bf31bab181ed557249018a610f29a83445655) +++ suite_leahi/tst_patient_vitals/test.py (.../test.py) (revision d821a29980219bd4228d724160ac1c353b3407b2) @@ -12,6 +12,15 @@ # - Verify the confirm button is disabled when user enters out of range values in the systolic, diastolic and heart rate parameters # - Verify the vitals interval time with current system time +# Python +import os +import can + +# plugin specific +from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions +from leahi_dialin.protocols import CAN +from leahi_dialin.utils import conversions + import names import time import builtins @@ -24,6 +33,7 @@ import squish td =TD_Messaging() +can_interface = td.can_interface ACID_CONCENTRATE = ["1.0 K, 2.50 Ca, 1 Mg","2.0 K, 2.50 Ca, 1 Mg","3.0 K, 2.50 Ca, 1 Mg"] DIALYZER_TYPE = ["Diacap Pro 13H","Diacap Pro 16H", "Diacap Pro 19H", "Optiflux F160NRe", "Optiflux F180NRe", "Optiflux F200NRe","Optiflux F250NRe"] @@ -194,35 +204,22 @@ hr = waitForObject(names.o_heartRate_TextEntry) mouseClick(hr) erase_entered_value(hr) - -def verify_entered_patient_vitals_in_maintreatment_screen(): + +def verify_the_popup_with_rejectionReason(): """ - Method to verify BP/HR section from patient vitals. - """ - test.startSection("verification of BP/HR section from patient vitals") - test.log("Clearing all fields") - clear_BP_and_HR_settings() - mouseClick(waitForObject(names.o_vitalsButton_VitalsButton)) - verify_valid_vitals_through_keypad(SYSTOLIC,names.o_bloodPressureSystolic_TextEntry,"185","185") #Mid values - verify_valid_vitals_through_keypad(DIASTOLIC,names.o_bloodPressureDiastolic_TextEntry,"140","140") - verify_valid_vitals_through_keypad(HEARTRATE, names.o_heartRate_TextEntry, "130", "130") - mouseClick(waitForObject(names.o_confirm_button)) - test.endSection() - -def verify_the_popup_with_rejectionReason(rejectionReason): - """ Method to check the popup is opened automatically after time interval """ + vitalsrequest = False + # mouseClick(waitForObject(names.o_treatmentHome_editButton_IconButton)) test.startSection("Verify popup is opened automatically after time interval") mouseClick(waitForObject(names.o_vitalsButton_VitalsButton)) mouseClick(names.o_measureVitalsButton_TouchRect) - td.td_vitals( systolic = 80, - diastolic = 60, - heartRate = 140 ) - td.td_vitals_adjustment_response(vRejectionReason=rejectionReason) - verify_vitals_pop_up_is_opened_automatically_after_an_interval(interval=10) - - + test.verify(waitFor("'vitalsrequest == True'", 1000), "UI Sending the request to FW") + td.td_vitals( systolic = 70, + diastolic = 50, + heartRate = 120 ) + td.td_vitals_adjustment_response(vRejectionReason=1) + verify_vitals_pop_up_is_opened_automatically_after_an_interval(interval=5) test.endSection() def validate_time_interval(vital_interval_obj, int_min): @@ -252,62 +249,78 @@ remaining_seconds = 0 # Convert to MM:SS - expected_mm = remaining_seconds // 60 - expected_ss = remaining_seconds % 60 + expected_mm = remaining_seconds // 60 + expected_ss = remaining_seconds % 60 expected_str = f"{expected_mm:02d}:{expected_ss:02d}" #Read UI displayed remaining time (MM:SS) - ui_str = str(waitForObject(vital_interval_obj).text).strip() + utils.waitForGUI(2) #After changing the time interval to update the value in UI + ui_str = str(waitForObject(vital_interval_obj,1000).text).strip() fmt = "%M:%S" expected_time = datetime.strptime(expected_str, fmt) actual_time = datetime.strptime(ui_str, fmt) diff = abs((actual_time - expected_time).total_seconds()) - if diff <= 1: + if diff <= 2: test.log(f"Remaining time is correct: {ui_str}") else: test.fail(f"Remaining time incorrect. Expected {expected_str}, got {ui_str}") -def verify_vitals_data_updated_no_rejection_reason(): + + +# handler for messages from UI to FW +def handle_patient_vitals_request( message, timestamp = 0.0): """ - Method to verify the vitals data updated - with no rejection reason - @param interval - (int) interval in min + Called when the user requests to firmware from UI + @return: None """ + message = message['message'] + index = MsgFieldPositions.START_POS_FIELD_1 + index = conversions.bytearray_to_integer( message, index) + global vitalsrequest + vitalsrequest = True - while True: - # Read time from GUI - remaining_time = str(waitForObject(names.o_vitalCountdown_Text).text).strip() +def verify_automatic_vitals_noRejection_Reason(): + global vitalsrequest + vitalsrequest = False + + MAX_WAIT = 5 * 60 # 5 minutes in seconds + POLL_INTERVAL = 5 # check every 5 seconds - test.log(f"Current Remaining Time: {remaining_time}") - - # When GUI time becomes zero, return - if remaining_time in ("0:00", "00:01"): - test.log(remaining_time) - td.td_vitals( systolic= 80, - diastolic = 60, - heartRate = 140 ) - break - blood_pressure = waitForObjectExists(names.o_treatmentHome_bloodPressure_LabelValue).topText - test.compare("70"+"/"+"50", blood_pressure,"Blood pressure value should be ->"+str("70"+"/"+"50")) - heart_rate = waitForObjectExists(names.o_treatmentHome_heartBeat_LabelValue).topText - test.compare("140", heart_rate,"Heart Rate value should be ->"+str(120)) -def verify_popup_with_no_rejectionReason(): mouseClick(waitForObject(names.o_vitalsButton_VitalsButton)) mouseClick(names.o_measureVitalsButton_TouchRect) + test.verify(waitFor("'vitalsrequest == True'", 1000), "UI Sending the request to FW") td.td_vitals( systolic = 70, - diastolic = 50, - heartRate = 120 ) + diastolic = 50, + heartRate = 120 ) td.td_vitals_adjustment_response(vRejectionReason=0) + start_time = time.time() + + while time.time() - start_time < MAX_WAIT: + if vitalsrequest: + td.td_vitals(systolic = 80, + diastolic = 60, + heartRate = 140 ) + break + time.sleep(POLL_INTERVAL) + else: + test.log("Condition not satisfied within 5 minutes. Exiting loop.") + blood_pressure = waitForObjectExists(names.o_treatmentHome_bloodPressure_LabelValue).topText - test.compare("70"+"/"+"50", blood_pressure,"Blood pressure value should be ->"+str("70"+"/"+"50")) + test.compare("80"+"/"+"60", blood_pressure,"Blood pressure value should be ->"+str("80"+"/"+"60")) heart_rate = waitForObjectExists(names.o_treatmentHome_heartBeat_LabelValue).topText - test.compare("120", heart_rate,"Heart Rate value should be ->"+str(120)) - verify_vitals_data_updated_no_rejection_reason() + test.compare("140", heart_rate,"Heart Rate value should be ->"+str(120)) + def main(): utils.tstStart(__file__) + if can_interface is not None: + channel_id = CAN.DenaliChannels.ui_to_td_ch_id + 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(config.AUT_NAME) td.td_operation_mode(TDOpModes.MODE_STAN.value) @@ -319,7 +332,8 @@ test.startSection("Create the pretreatment values") verify_create_treatment_parameters() test.endSection() - test.startSection("Check the vitals in main treatment screen") + + test.startSection("Verify the minimum values in the vitals popup") td.td_operation_mode(TDOpModes.MODE_TREA.value, 0) td.td_tx_state(TDTreatmentStates.TREATMENT_DIALYSIS_STATE.value , 0 , @@ -331,11 +345,6 @@ 0 , 0 , 0) - - validate_time_interval(names.o_vitalCountdown_Text,5) - test.endSection() - - test.startSection("Verify the minimum values in the vitals popup") mouseClick(waitForObject(names.o_vitalsButton_VitalsButton)) verify_valid_vitals_through_keypad(SYSTOLIC,names.o_bloodPressureSystolic_TextEntry,MIN_SYSTOLIC,MIN_SYSTOLIC) verify_valid_vitals_through_keypad(DIASTOLIC,names.o_bloodPressureDiastolic_TextEntry,MIN_DIASTOLIC,MIN_DIASTOLIC) @@ -389,10 +398,9 @@ test.endSection() test.startSection("Verify the vitals data send automatically populate on popup") - verify_popup_with_no_rejectionReason() - - #With rejection reasom - verify_the_popup_with_rejectionReason(rejectionReason=1) + verify_automatic_vitals_noRejection_Reason() + #With rejection reason + verify_the_popup_with_rejectionReason() test.endSection() test.startSection("Verify the last read time in the UI") @@ -401,12 +409,24 @@ verify_valid_vitals_through_keypad(DIASTOLIC,names.o_bloodPressureDiastolic_TextEntry,MIN_DIASTOLIC,MIN_DIASTOLIC) verify_valid_vitals_through_keypad(HEARTRATE, names.o_heartRate_TextEntry, MIN_HEARTRATE, MIN_HEARTRATE) mouseClick(waitForObject(names.o_confirm_button)) - sys_time = utility.get_current_date_and_time(date_format="%Y/%b/%d - %H:%M:%S") - last_read = waitForObjectExists(names.o_last_read).text + sys_time = utility.get_current_date_and_time(date_format="%Y/%b/%d - %H:%M:%S") + last_read = waitForObjectExists(names.o_last_read).text lastdatetime = str(last_read).split(" ")[3] systime = sys_time.split("-")[1].strip() test.compare(lastdatetime, systime, "Last read time is updated properly") test.endSection() + + test.startSection("Check the vitals in main treatment screen") + mouseClick(waitForObject(names.o_treatmentHome_editButton_IconButton)) + utility.select_different_dropdown(names.o_vitals_Interval_BaseComboBox,VITALS,5) + mouseClick(waitForObject(names.o_confirm_button,1000)) + validate_time_interval(names.o_vitalCountdown_Text,30) + mouseClick(waitForObject(names.o_treatmentHome_editButton_IconButton)) + utility.select_different_dropdown(names.o_vitals_Interval_BaseComboBox,VITALS,1) + mouseClick(waitForObject(names.o_confirm_button,1000)) + validate_time_interval(names.o_vitalCountdown_Text,5) + + test.endSection() utils.tstDone()