/*! * * 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 TreatmentLog.cpp * author (last) Behrouz NematiPour * date (last) 4/30/2021 * author (original) Behrouz NematiPour * date (original) 4/30/2021 * */ #include "TreatmentLog.h" // Qt #include // Project #include "StorageGlobals.h" #include "FileHandler.h" #include "Logger.h" #include "MSettings.h" using namespace Storage; #define ADDTOLOG(vINDEX) index = vINDEX; logContent += _titles[index] + sep + _values[index] + sep + _units[index] + "\n"; /*! * \brief TreatmentLog::TreatmentLog * The constructor to initial the Treatment Log * \param parent */ TreatmentLog::TreatmentLog(QObject *parent) : QObject(parent) { initConnections(); _treatmentLogPath = QString("%1%2") .arg(Storage::SDCard_Base_Path_Name) .arg(Storage::Treatment_Log_Folder ); } /*! \brief Connection Initializer \details All the class signal/slot connections are defined here. */ void TreatmentLog::initConnections() { connect(&_exportWatcher, SIGNAL(finished()), this , SLOT(onExport())); connect(&_saveWatcher , SIGNAL(finished()), this , SLOT(onSave ())); } /*! * \brief TreatmentLog::initModel * Initializing the model for the constant values. * \param vData - the response model data. */ void TreatmentLog::initModel(const AdjustTreatmentLogResponseData &vData) { // Formatted values QString mStrText = "%1"; // qDebug() << _Settings.groups(); // SRSUI910 : PRS187 : Clinical - Data - Order QString mTreatmentDuration = QTime (0, 0).addSecs(vData.mTreatmentDuration ).toString("HH:mm"); QString mActualTreatmentDuration = QTime (0, 0).addSecs(vData.mActualTreatmentDuration ).toString("HH:mm"); QString mTreatmentDateTime = QDateTime::fromSecsSinceEpoch ( vData.mTreatmentDateTime ).toString("yyyy/MM/dd HH:mm"); quint32 mHeparinConcentration = 1000; // vData.mHeparinConcentration // TODO : The settings needs modification not only to define the category and groups in a common header but also the settings itself needs some mods. // - the category shall become as part of the group // - the structure of the settings should become horizontal which vertical now. QString mAcidConcentrateType = _Settings.key("Acid Concentrate" , vData.mAcidConcentrateType ); QString mBicarbonateConcentrateType = _Settings.key("Bicarbonate Concentrate" , vData.mBicarbonateConcentrateType ); QString mDialyzerType = _Settings.key("Dialyzer Type" , vData.mDialyzerType ); QString mHeparinType = _Settings.key("Heparin Type" , vData.mHeparinType ); QString mWaterSampleTestResult = _Settings.key("Water Sample Result" , vData.mWaterSampleTestResult ); // init/fill/clear the _values _values.clear(); for (int i = 0; i < eTreatmentLogIndexCount; i++) _values << ""; _values[eDeviceID ] = mStrText.arg(vData.mDeviceID ); _values[eBloodFlowRate ] = mStrText.arg(vData.mBloodFlowRate ); _values[eDialysateFlowRate ] = mStrText.arg(vData.mDialysateFlowRate ); _values[eTreatmentDuration ] = mTreatmentDuration ; _values[eActualTreatmentDuration ] = mActualTreatmentDuration ; _values[eAcidConcentrateType ] = mAcidConcentrateType ; _values[eBicarbonateConcentrateType ] = mBicarbonateConcentrateType ; _values[ePotassiumConcentration ] = mStrText.arg(vData.mPotassiumConcentration ); _values[eCalciumConcentration ] = mStrText.arg(vData.mCalciumConcentration ); _values[eBicarbonateConcentration ] = mStrText.arg(vData.mBicarbonateConcentration ); _values[eSodiumConcentration ] = mStrText.arg(vData.mSodiumConcentration ); _values[eDialysateTemperature ] = mStrText.arg(vData.mDialysateTemperature ,0,'f',3); _values[eDialyzerType ] = mDialyzerType ; _values[eHeparinType ] = mHeparinType ; _values[eHeparinConcentration ] = mStrText.arg(mHeparinConcentration ); // Decided to be removed, but has to be here until it is actually removed from the message _values[eHeparinBolusVolume ] = mStrText.arg(vData.mHeparinBolusVolume ,0,'f',3); _values[eHeparinDispenseRate ] = mStrText.arg(vData.mHeparinDispenseRate ,0,'f',3); _values[eHeparinStop ] = mStrText.arg(vData.mHeparinStop ); _values[eHeparinDeliveredVolume ] = mStrText.arg(vData.mHeparinDeliveredVolume ,0,'f',3); _values[eTreatmentDateTime ] = mTreatmentDateTime ; _values[eWaterSampleTestResult ] = mWaterSampleTestResult ; _values[eDialysateVolumeUsed ] = mStrText.arg(vData.mDialysateVolumeUsed ,0,'f',3); _values[eTargetUFVolume ] = mStrText.arg(vData.mTargetUFVolume ,0,'f',3); _values[eActualUFVolume ] = mStrText.arg(vData.mActualUFVolume ,0,'f',3); _values[eTargetUFRate ] = mStrText.arg(vData.mTargetUFRate ,0,'f',3); _values[eActualUFRate ] = mStrText.arg(vData.mActualUFRate ,0,'f',3); _values[eSalineBolusVolume ] = mStrText.arg(vData.mSalineBolusVolume ); _values[eAverageBloodFlow ] = mStrText.arg(vData.mAverageBloodFlow ,0,'f',3); _values[eAverageDialysateFlow ] = mStrText.arg(vData.mAverageDialysateFlow ,0,'f',3); _values[eAverageDialysateTemp ] = mStrText.arg(vData.mAverageDialysateTemp ,0,'f',3); _values[eAverageArterialPressure ] = mStrText.arg(vData.mAverageArterialPressure ,0,'f',3); _values[eAverageVenousPressure ] = mStrText.arg(vData.mAverageVenousPressure ,0,'f',3); _values[eEndTreatmentEarlyAlarm ] = mStrText.arg(vData.mEndTreatmentEarlyAlarm ); } // ----- Save /*! * \brief TreatmentLog::doSave * The save slot to be exposed to the UI to be able to request for save */ void TreatmentLog::doSave() { if (_saveWatcher.isRunning()) return; isIdle(false); saveLogConcurrent(); } /*! * \brief TreatmentLog::saveLogConcurrent * The treatment log save which is using a thread pool to run the save process. */ void TreatmentLog::saveLogConcurrent() { LOG_EVENT("Save Treatment Log Started"); QFuture mFuture = QtConcurrent::run(this, &TreatmentLog::saveLog); _saveWatcher.setFuture(mFuture); } /*! * \brief TreatmentLog::saveLog * The actual treatment log save function which does the save into the treatment log * \return true on successful save and false otherwise. */ bool TreatmentLog::saveLog() { bool ok = (unsigned)_values.count() >= eTreatmentLogIndexCount; if (!ok) return false; QString logContent; QString sep = ","; uint index = 0; logContent += tr("Patient ID") + sep + QString("None") + "\n"; ADDTOLOG( eDeviceID ); ADDTOLOG( eBloodFlowRate ); ADDTOLOG( eDialysateFlowRate ); ADDTOLOG( eTreatmentDuration ); ADDTOLOG( eActualTreatmentDuration ); ADDTOLOG( eAcidConcentrateType ); ADDTOLOG( eBicarbonateConcentrateType ); ADDTOLOG( ePotassiumConcentration ); ADDTOLOG( eCalciumConcentration ); ADDTOLOG( eBicarbonateConcentration ); ADDTOLOG( eSodiumConcentration ); ADDTOLOG( eDialysateTemperature ); ADDTOLOG( eDialyzerType ); ADDTOLOG( eHeparinType ); ADDTOLOG( eHeparinConcentration ); ADDTOLOG( eHeparinBolusVolume ); ADDTOLOG( eHeparinDispenseRate ); ADDTOLOG( eHeparinStop ); ADDTOLOG( eHeparinDeliveredVolume ); ADDTOLOG( eTreatmentDateTime ); ADDTOLOG( eWaterSampleTestResult ); ADDTOLOG( eDialysateVolumeUsed ); ADDTOLOG( eTargetUFVolume ); ADDTOLOG( eActualUFVolume ); ADDTOLOG( eTargetUFRate ); ADDTOLOG( eActualUFRate ); ADDTOLOG( eSalineBolusVolume ); ADDTOLOG( eAverageBloodFlow ); ADDTOLOG( eAverageDialysateFlow ); ADDTOLOG( eAverageDialysateTemp ); ADDTOLOG( eAverageArterialPressure ); ADDTOLOG( eAverageVenousPressure ); ADDTOLOG( eEndTreatmentEarlyAlarm ); QString mDateTime = _values[eTreatmentDateTime]; mDateTime.replace("/", "" ); // remove date separator mDateTime.replace(":", "" ); // remove time separator mDateTime.replace(" ", "_"); // remove spaces QString mDeviceID = _values[eDeviceID]; QString mFileName = QString("%1_%2.log") .arg(mDateTime) .arg(mDeviceID); Storage::FileHandler::makeFolder(_treatmentLogPath); ok = Storage::FileHandler::write(_treatmentLogPath + mFileName, logContent, false); return ok; } /*! * \brief TreatmentLog::onSave * The private save slot which is called after the save process is finished saving. */ void TreatmentLog::onSave() { LOG_EVENT(QString("Save Treatment Log Ended: %1").arg(_saveWatcher.result())); isIdle(true); } // ----- Export /*! * \brief TreatmentLog::doExport * The export treatment log slot to be exposed to the UI to be able to request for the export. */ void TreatmentLog::doExport() { if (_exportWatcher.isRunning()) return; isIdle(false); exportLogConcurrent(); } /*! * \brief TreatmentLog::exportLogConcurrent * The treatment log export which is using a thread pool to run the save process. */ void TreatmentLog::exportLogConcurrent() { LOG_EVENT("Export Treatment Log Started"); QFuture mFuture = QtConcurrent::run(this, &TreatmentLog::exportLog); _exportWatcher.setFuture(mFuture); } /*! * \brief TreatmentLog::exportLog * The actual treatment log export function which does the export of the treatment log into the USB drive. * \return */ bool TreatmentLog::exportLog() { bool ok; QString exportPath = Storage::USB_Mount_Point; Storage::FileHandler::makeFolder(exportPath); ok = FileHandler::copyFolder(_treatmentLogPath , exportPath); return ok; } /*! * \brief TreatmentLog::onExport * The private export slot which is called after the export process is finished exporting. */ void TreatmentLog::onExport() { LOG_EVENT(QString("Export Treatment Log Ended: %1").arg(_exportWatcher.result())); isIdle(true); }