########################################################################### # # Copyright (c) 2021-2024 Diality Inc. - All Rights Reserved. # # 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 blood_pressure.py # # @author (last) Zoltan Miskolci # @date (last) 06-Jul-2026 # @author (original) Zoltan Miskolci # @date (original) 06-Jul-2026 # ############################################################################ # Module imports from logging import Logger import time # Project imports from leahi_dialin.common.generic_defs import DataTypes from leahi_dialin.common.msg_defs import MsgIds from leahi_dialin.protocols.CAN import CanMessenger, CanChannels from leahi_dialin.utils.abstract_classes import AbstractSubSystem from leahi_dialin.utils.base import publish from leahi_dialin.td.proxies.ui_proxy import UIProxy class TDBloodPressure(AbstractSubSystem): """ @brief Treatment Device (TD) Dialin API sub-class for TD patient vitals related commands. """ def __init__(self, can_interface: CanMessenger, logger: Logger): """ TDBloodPressure constructor """ super().__init__() self.can_interface = can_interface self.logger = logger if self.can_interface is not None: self.can_interface.register_receiving_publication_function(channel_id = CanChannels.td_sync_broadcast_ch_id, message_id = MsgIds.MSG_ID_TD_BLOOD_PRESSURE_DATA.value, function = self._handler_bp_sync) self.can_interface.register_receiving_publication_function(channel_id = CanChannels.td_sync_broadcast_ch_id, message_id = MsgIds.MSG_ID_TD_BLOOD_PRESSURE_RESPONSE.value, function = self._handler_bp_rr_sync) self.blood_pressure_timestamp = 0.0 #: The timestamp of the latest message self.rr_timestamp = 0.0 #: The timestamp of the latest reject reason message self.ack = 0 #: The Measure blood pressure requests acknowledgement response self.reject_reason = 0 #: The Measure blood pressure requests reject reason self.systolic = 0 #: The Patient's systolic blood pressure in mmHg self.diastolic = 0 #: The Patient's diastolic blood pressure in mmHg self.heart_rate = 0 #: The Patient's heart rate in PBM self.handler_bp_time = [] self.handler_bp_rr_time = [] @publish(["msg_id_td_blood_pressure_data", "systolic", "diastolic", "heart_rate", "blood_pressure_timestamp"]) def _handler_bp_sync(self, message, timestamp=0.0): """ Handles published TD Blood Pressure data messages. Blood Pressure data are captured for reference. @param message: published data message @return: none """ start = time.perf_counter() msg_list =[] msg_list.append(('self.systolic', DataTypes.U32)) msg_list.append(('self.diastolic', DataTypes.U32)) msg_list.append(('self.heart_rate', DataTypes.U32)) self.process_into_vars(decoder_list = msg_list, message = message) self.blood_pressure_timestamp = timestamp self.handler_bp_time.append((timestamp, message, time.perf_counter() - start)) @publish(["msg_id_td_blood_pressure_response", "ack", "reject_reason", "rr_timestamp"]) def _handler_bp_rr_sync(self, message, timestamp=0.0): """ Handles published TD Blood Pressure Reject Reason data messages. Blood Pressure Reject Reason data are captured for reference. @param message: published data message @return: none """ start = time.perf_counter() msg_list =[] msg_list.append(('self.ack', DataTypes.U32)) msg_list.append(('self.reject_reason', DataTypes.U32)) self.process_into_vars(decoder_list = msg_list, message = message) self.rr_timestamp = timestamp self.handler_bp_rr_time.append((timestamp, message, time.perf_counter() - start)) def cmd_send_ui_blood_pressure_request(self) -> None: """ Constructs and sends a UI request to measure blood pressure. :return: none """ return UIProxy(can_interface = self.can_interface, logger = self.logger).cmd_send_ui_blood_pressure_request()