Index: sources/view/hd/adjustment/common/VCommonAdjustmentVitals.cpp =================================================================== diff -u -r36261904932c6f05bc28a2a93d44becb4f76c4ac -r2ef03b2ce51b4dc507f66e9671953a8e0824bde9 --- sources/view/hd/adjustment/common/VCommonAdjustmentVitals.cpp (.../VCommonAdjustmentVitals.cpp) (revision 36261904932c6f05bc28a2a93d44becb4f76c4ac) +++ sources/view/hd/adjustment/common/VCommonAdjustmentVitals.cpp (.../VCommonAdjustmentVitals.cpp) (revision 2ef03b2ce51b4dc507f66e9671953a8e0824bde9) @@ -1,15 +1,15 @@ /*! * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * Copyright (c) 2021-2024 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 + * \file VCommonAdjustmentVitals.cpp * \author (last) Behrouz NematiPour - * \date (last) 06-Jun-2021 + * \date (last) 10-Jan-2024 * \author (original) Behrouz NematiPour - * \date (original) 06-Jun-2021 + * \date (original) 23-Jun-2021 * */ #include "VCommonAdjustmentVitals.h" @@ -31,10 +31,8 @@ void View::VTreatmentVitals::initConnections() { ACTION_RECEIVE_BRIDGE_CONNECTION(_BluetoothInterface, UIBloodPressureData); - connect(this, SIGNAL( enableDialogChanged (const bool &)), - this, SLOT(onTimerChanged ( ))); - connect(this, SIGNAL( intervalChanged (const quint8 &)), - this, SLOT(onTimerChanged ( ))); + connect(this, SIGNAL( intervalChanged (const quint8 &)), + this, SLOT(onIntervalChanged ( ))); } /*! @@ -46,25 +44,21 @@ */ 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); } + update_rt (vData.mSystolic, vData.mDiastolic, vData.mPulseRate); + emit didTrigger(vData.mSystolic, vData.mDiastolic, vData.mPulseRate); + // if the vitals is disabled it means Gui is probably in an incorrect state and is unable to handle the vital information. + LOG_APPED_UI(tr("Vital received,%1,%2,%3") + .arg(vData.mSystolic ) + .arg(vData.mDiastolic) + .arg(vData.mPulseRate)); } /*! - * \brief View::VPostTreatmentAdjustmentTreatmentLog::doVitalReceive + * \brief View::VTreatmentVitals::doConfirm * \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 @@ -78,7 +72,7 @@ update(vSystolic, vDiastolic, vHeartRate); treatmentLog(); - LOG_EVENT_UI(tr("User Vital Confirmation,%1,%2,%3") + LOG_APPED_UI(tr("Vital Confirmed,%1,%2,%3") .arg(_systolic ) .arg(_diastolic) .arg(_heartRate) @@ -92,19 +86,11 @@ */ void View::VTreatmentVitals::doSkip() { - LOG_EVENT_UI(tr("User Skipped Vital Entry")); + LOG_APPED_UI(tr("Vital Skipped")); + timerReset(); } /*! - * \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. @@ -117,8 +103,8 @@ systolic ( 0 ); diastolic ( 0 ); heartRate ( 0 ); + enableDialog ( 0 ); - enableUpdate ( 0 ); // force notify the Gui emit epochChanged ( 0 ); @@ -139,7 +125,7 @@ { QDateTime currentDateTime = QDateTime::currentDateTime(); epoch (currentDateTime.toSecsSinceEpoch()); - lastRead (currentDateTime.toString(_datetimeFormat)); + lastRead (currentDateTime.toString(_Settings.getDatetimeFormat())); systolic ( vSystolic ); diastolic ( vDiastolic ); heartRate ( vHeartRate ); @@ -150,6 +136,21 @@ } /*! + * \brief View::VTreatmentVitals::update_rt + * \details The vital properties will only be updated if the user confirms the read values. + * But this ones are for debugging purposes and will be updated all the time in Real Time when the vitals received. + * \param vSystolic - Blood Pressure Systolic + * \param vDiastolic - Blood Pressure Diastolic + * \param vHeartRate - Heart Rate + */ +void View::VTreatmentVitals::update_rt(quint16 vSystolic, quint16 vDiastolic, quint16 vHeartRate) +{ + systolic__rt ( vSystolic ); + diastolic_rt ( vDiastolic ); + heartRate_rt ( vHeartRate ); +} + +/*! * \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. @@ -170,19 +171,34 @@ */ 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(); + if ( ! _timerId ) return; // No timer started or failed starting + if ( ! _interval ) return; // if interval is 0/OFF return + + // DEBUG: qDebug() << __FUNCTION__ << _counter_sec << _counter_min << _interval << _timerId; + _counter_sec++; + + min_left(_counter_min ); + sec_left(60 - _counter_sec); + + countdown(QString("%1:%2").arg(_min_left,2,10,QChar('0')).arg(_sec_left,2,10,QChar('0'))); + + if ( _counter_sec % 60 ) return; // only check every minute + + if ( ! _counter_min ) { + timerStop(); emit didTrigger(); } - _timerCounter++; + else { + _counter_min--; + _counter_sec = 0; + } } -void View::VTreatmentVitals::onTimerChanged() +void View::VTreatmentVitals::onIntervalChanged() { - if ( _interval && _enableDialog ) timerStart(); - else timerStop (); + // DEBUG: qDebug() << __FUNCTION__ << _counter_sec << _counter_min << _interval << _timerId; + if ( _interval ) timerReset(); + else timerStop (); // Timer stop is resetting timer too. } /*! @@ -192,21 +208,35 @@ */ void View::VTreatmentVitals::timerStart() { - _timerId = startTimer(60000); // 1 min interval + if ( _timerId ) killTimer(_timerId); // this typically should not happen. + if ( ! _interval ) return; // if interval is 0/OFF return + // DEBUG: qDebug() << __FUNCTION__ << _counter_sec << _counter_min << _interval << _timerId; + timerReset(); + _timerId = startTimer(1000); // 1 sec interval which will used as 1 min in timerEvent (easier to debug) } void View::VTreatmentVitals::timerReset() { - _timerCounter = 1; + if ( _interval ) { + // ( -1 ) :the interval is 0 based but if as an example we set the counter to 5 then 5 itself gets a minute to pass which makes it 6 min. + _counter_min = _interval - 1; + } + else { // if _interval == 0, counter should set to 0 too not to -1 + _counter_min = 0; + } + _counter_sec = 0; + // DEBUG: qDebug() << __FUNCTION__ << _counter_sec << _counter_min << _interval << _timerId; } /*! * \brief View::VTreatmentVitals::stop - * \details stops the timer + * \details stops the timer and resets the interval */ void View::VTreatmentVitals::timerStop() { + if ( ! _timerId ) return; // No timer started or failed starting + // DEBUG: qDebug() << __FUNCTION__ << _counter_sec << _counter_min << _interval << _timerId; killTimer(_timerId); _timerId = 0; timerReset();