/*! * * 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 VAdjustmentAlarmVolume.h * \author (last) Behrouz NematiPour * \date (last) 06-Jun-2021 * \author (original) Behrouz NematiPour * \date (original) 06-Jun-2021 * */ #include "VCommonAdjustmentVitals.h" // Qt #include "QDateTime" // Project #include "GuiController.h" #include "TreatmentLog.h" #include "BluetoothInterface.h" VIEW_DEF_CLASS_ADJUSTMENT(VTreatmentVitals) /*! * \brief Connection Initializer * \details All the class signal/slot connections are defined here. */ void View::VTreatmentVitals::initConnections() { ACTION_RECEIVE_BRIDGE_CONNECTION(_BluetoothInterface, UIBloodPressureData); connect(this, SIGNAL( enabledChanged(const bool &)), this, SLOT(onTimerChanged ( ))); connect(this, SIGNAL( intervalChanged(const quint8 &)), this, SLOT(onTimerChanged ( ))); } /*! * \brief View::VTreatmentVitals::onActionReceive * \details The data handler which gets the data form GuiControl and GuiController will get the data from BtCuff controller. * \param vData - Vital values * \note the accepted and reason in this case should be the BtCuff status which may not necessarily comes front BtCuff itself, * and the intermediate controller like the GuiController or the BtCuffController can report from BtCuff behalf if it is connected or not responsive. */ void View::VTreatmentVitals::onActionReceive(const UIBloodPressureData &vData) { if ( ! ( _enableDialog || _enableUpdate ) ) { // if the vitals is disabled it means Gui is probably in an incorrect state and is unable to handle the vital information. LOG_EVENT_UI(tr("Measured vital values ignored due to incorrect state [%1,%2,%3]") .arg(vData.mSystolic ) .arg(vData.mDiastolic) .arg(vData.mPulseRate)); return; } // Not used yet. // adjustment_Accepted ( vData.mAccepted ); // adjustment_Reason ( vData.mReason ); if ( _enableDialog ) { emit didTrigger(vData.mSystolic, vData.mDiastolic, vData.mPulseRate); } if ( _enableUpdate ) { update (vData.mSystolic, vData.mDiastolic, vData.mPulseRate); } } /*! * \brief View::VPostTreatmentAdjustmentTreatmentLog::doVitalReceive * \details Append the user measured BP/HR in to the list of the Treatment Log Average data * \param vSystolic - Blood Pressure Systolic * \param vDiastolic - Blood Pressure Diastolic * \param vHeartRate - Heart Rate */ void View::VTreatmentVitals::doConfirm( quint16 vSystolic, quint16 vDiastolic, quint16 vHeartRate) { adjustment_Accepted ( true ); adjustment_Reason ( 0 ); update(vSystolic, vDiastolic, vHeartRate); treatmentLog(); LOG_EVENT_UI(tr("User Vital Confirmation,%1,%2,%3") .arg(_systolic ) .arg(_diastolic) .arg(_heartRate) ); timerReset(); } /*! * \brief View::VTreatmentVitals::doSkip * \details logs the vital entry skip */ void View::VTreatmentVitals::doSkip() { LOG_EVENT_UI(tr("User Skipped Vital Entry")); } /*! * \brief View::VTreatmentVitals::doTimeout * \details logs the vital entry timeout */ void View::VTreatmentVitals::doTimeout() { LOG_EVENT_UI(tr("User Vital Entry Timed out")); } /*! * \brief View::VTreatmentVitals::doReset * \details reset the previously read vital values * \param vEnabled - Disable or enable the vitals. * \note it's still unknown that how to stop in case of the treatment ended by alarm or system fault. */ void View::VTreatmentVitals::doReset() { epoch ( 0 ); lastRead ( ""); systolic ( 0 ); diastolic ( 0 ); heartRate ( 0 ); enableDialog ( 0 ); enableUpdate ( 0 ); // force notify the Gui emit epochChanged ( 0 ); emit lastReadChanged ( ""); emit systolicChanged ( 0 ); emit diastolicChanged ( 0 ); emit heartRateChanged ( 0 ); } /*! * \brief View::VTreatmentVitals::update * \details updating the properties and set the timestamp * \param vSystolic - Blood Pressure Systolic * \param vDiastolic - Blood Pressure Diastolic * \param vHeartRate - Heart Rate */ void View::VTreatmentVitals::update(quint16 vSystolic, quint16 vDiastolic, quint16 vHeartRate) { QDateTime currentDateTime = QDateTime::currentDateTime(); epoch (currentDateTime.toSecsSinceEpoch()); lastRead (currentDateTime.toString(_datetimeFormat)); systolic ( vSystolic ); diastolic ( vDiastolic ); heartRate ( vHeartRate ); // *** has to be the last to let the information to be set and then emit the signal *** // *** otherwise will use the previous values before being set. *** adjustment(true); } /*! * \brief View::VTreatmentVitals::treatmentLog * \details Appends the vitals values to the treatment log list (for later store in the TxLog at the end of Tx) * \note the method update has to be called before calling this method to update the property values used in this method. */ void View::VTreatmentVitals::treatmentLog() { TreatmentLogAvrgeData data ; data.mTimeStamp = _epoch ; data.mSystolic = _systolic ; data.mDiastolic = _diastolic; data.mHeartRate = _heartRate; _TreatmentLog.append(data) ; } /*! * \brief View::VTreatmentVitals::timerEvent * \details The override method to handle the timer for the vital measurement interval */ void View::VTreatmentVitals::timerEvent(QTimerEvent *) { // TODO: Change the logic of the timer to count down instead of count up and reset to interval on 0. qDebug() << __FUNCTION__ << _timerCounter; if ( _interval == _timerCounter ) { timerReset(); emit didTrigger(); } _timerCounter++; } void View::VTreatmentVitals::onTimerChanged() { if ( _interval && _enableDialog ) timerStart(); else timerStop (); } /*! * \brief View::VTreatmentVitals::start * \details Starts the timer by 1 min interval * \note the vital times are all minutes. */ void View::VTreatmentVitals::timerStart() { _timerId = startTimer(60000); // 1 min interval } void View::VTreatmentVitals::timerReset() { _timerCounter = 1; } /*! * \brief View::VTreatmentVitals::stop * \details stops the timer */ void View::VTreatmentVitals::timerStop() { killTimer(_timerId); _timerId = 0; timerReset(); }