/*! * * 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 VCommonAdjustmentVitals.cpp * \author (last) Behrouz NematiPour * \date (last) 10-Jan-2024 * \author (original) Behrouz NematiPour * \date (original) 23-Jun-2021 * */ #include "VCommonAdjustmentVitals.h" // Qt #include "QDateTime" // Project #include "GuiController.h" #include "TreatmentLog.h" VIEW_DEF_CLASS(VTreatmentVitals) /*! * \brief Connection Initializer * \details All the class signal/slot connections are defined here. */ void View::VTreatmentVitals::initConnections() { connect(this, SIGNAL( intervalChanged (const quint8 &)), this, SLOT(onIntervalChanged ( ))); ACTION_VIEW_CONNECTION( TreatmentVitalsData ); } /*! * \brief View::VTreatmentVitals::onActionReceive * \details The data handler which gets the data from the integreated Blood Pressure cuff. * \param TreatmentVitalsData - Vital values * \note the accepted and reason in this case should be the integreated Blood Pressure cuff status which may not necessarily comes from the cuff itself. */ void View::VTreatmentVitals::onActionReceive(const TreatmentVitalsData &vData) { update_rt (vData.mSystolic, vData.mDiastolic, vData.mHeartRate); LOG_APPED_UI(tr("Vital received,%1,%2,%3") .arg(vData.mSystolic ) .arg(vData.mDiastolic) .arg(vData.mHeartRate)); emit didTrigger(); } /*! * \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 * \param vHeartRate - Heart Rate */ void View::VTreatmentVitals::doConfirm( quint16 vSystolic, quint16 vDiastolic, quint16 vHeartRate) { update(vSystolic, vDiastolic, vHeartRate); treatmentLog(); LOG_APPED_UI(tr("Vital Confirmed,%1,%2,%3") .arg(_systolic ) .arg(_diastolic) .arg(_heartRate) ); timerStart(); } /*! * \brief View::VTreatmentVitals::doSkip * \details logs the vital entry skip */ void View::VTreatmentVitals::doSkip() { LOG_APPED_UI(tr("Vital Skipped")); } /*! * \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 ); countdown ( ""); totalCount ( 0 ); canStartInterval ( 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(_Settings.getDatetimeFormat())); systolic ( vSystolic ); diastolic ( vDiastolic ); heartRate ( vHeartRate ); } /*! * \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. */ 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 *) { if ( ! _timerId ) return; // No timer started or failed starting if ( ! _canStartInterval ) return; // parameters have not been confirmed yet updateTimer(); } /*! * \brief View::VTreatmentVitals::onIntervalChanged * \details Resets or stops the timer depending on whether an interval * is currently set. */ void View::VTreatmentVitals::onIntervalChanged() { } /*! * \brief View::VTreatmentVitals::start * \details Starts the timer by 1 min interval * \note the vital times are all minutes. */ void View::VTreatmentVitals::timerStart() { if ( _timerId ) killTimer(_timerId); // this typically should not happen. _timerId = startTimer(1000); // 1 sec interval which will used as 1 min in timerEvent (easier to debug) } /*! * \brief View::VTreatmentVitals::updateTimer * \details Update timer from current time with set interval and update UI data */ void View::VTreatmentVitals::updateTimer() { int interval = _interval && _enableBPCuff ? _interval : 15; _now = QDateTime::currentDateTime(); // minutes past last interval mark int past = _now.time().minute() % interval; int currentCount = past * 60 + _now.time().second(); // Seconds since the last interval mark if ( _interval && _enableBPCuff ) { totalCount( currentCount ); } // Seconds until the next interval mark int totalSecLeft = interval * 60 - currentCount; // trigger timeout when timer countdown is done if (totalSecLeft <= 1 ) { timerStop(); emit didTimeout(); } // construct count down string if ( _interval && _enableBPCuff ) { int counter_min = totalSecLeft / 60; int counter_sec = totalSecLeft % 60; countdown( QStringLiteral("%1:%2") .arg(counter_min,2,10,QChar('0')) .arg(counter_sec,2,10,QChar('0')) ); } } /*! * \brief View::VTreatmentVitals::stop * \details stops the timer and resets the interval */ void View::VTreatmentVitals::timerStop() { if ( ! _timerId ) return; // No timer started or failed starting killTimer(_timerId); _timerId = 0; }