/*! * * 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"; 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 ())); } 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"); //// 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(vData.mHeparinConcentration ); _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 void TreatmentLog::doSave() { if (_saveWatcher.isRunning()) return; isIdle(false); saveLogConcurrent(); } void TreatmentLog::saveLogConcurrent() { LOG_EVENT("Save Treatment Log Started"); QFuture mFuture = QtConcurrent::run(this, &TreatmentLog::saveLog); _saveWatcher.setFuture(mFuture); } 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(eBloodFlowRate); ADDTOLOG(eDialysateFlowRate); ADDTOLOG(eTreatmentDuration); 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); 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; } void TreatmentLog::onSave() { LOG_EVENT(QString("Save Treatment Log Ended: %1").arg(_saveWatcher.result())); isIdle(true); } // ----- Export void TreatmentLog::doExport() { if (_exportWatcher.isRunning()) return; isIdle(false); exportLogConcurrent(); } void TreatmentLog::exportLogConcurrent() { LOG_EVENT("Export Treatment Log Started"); QFuture mFuture = QtConcurrent::run(this, &TreatmentLog::exportLog); _exportWatcher.setFuture(mFuture); } bool TreatmentLog::exportLog() { bool ok; QString exportPath = Storage::USB_Mount_Point; Storage::FileHandler::makeFolder(exportPath); ok = FileHandler::copyFolder(_treatmentLogPath , exportPath); return ok; } void TreatmentLog::onExport() { LOG_EVENT(QString("Export Treatment Log Ended: %1").arg(_exportWatcher.result())); isIdle(true); }