Index: sources/view/VTreatmentCreate.cpp =================================================================== diff -u -r6e4cc1f67e9290035b4e3a5be2eac04a85ae0c9a -r2ef03b2ce51b4dc507f66e9671953a8e0824bde9 --- sources/view/VTreatmentCreate.cpp (.../VTreatmentCreate.cpp) (revision 6e4cc1f67e9290035b4e3a5be2eac04a85ae0c9a) +++ sources/view/VTreatmentCreate.cpp (.../VTreatmentCreate.cpp) (revision 2ef03b2ce51b4dc507f66e9671953a8e0824bde9) @@ -1,214 +1,102 @@ -#include "VTreatmentCreate.h" +/*! + * + * Copyright (c) 2020-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 VTreatmentCreate.cpp + * \author (last) Behrouz NematiPour + * \date (last) 21-Nov-2023 + * \author (original) Peter Lucia + * \date (original) 22-Sep-2020 + * + */ // Qt // Project -#include "filehandler.h" +#include "ApplicationController.h" +#include "VTreatmentCreate.h" +#include "FileHandler.h" #include "MsgDefs.h" +#include "TreatmentLog.h" using namespace Gui; using namespace View; using namespace Storage; - VTreatmentCreate::VTreatmentCreate(QObject *parent) : QObject(parent) { - connect(&_FileSaver, SIGNAL(fileSaved(bool)), - this, SLOT(onFinishedSaveNewTreatment(bool))); - - connect(this, SIGNAL(requestValidateParameters(AdjustTreatmentParametersRequestData)), - &_GuiController, SLOT(doAdjustment(AdjustTreatmentParametersRequestData))); - - connect(&_GuiController, SIGNAL(didActionReceive(AdjustTreatmentParametersResponseData)), - this, SLOT(onFWValidationResponse(AdjustTreatmentParametersResponseData))); - - connect(this, SIGNAL(requestSelectParameters(StartTreatmentRequestData)), - &_GuiController, SLOT(doAdjustment(StartTreatmentRequestData))); - - connect(this, SIGNAL(requestConfirm(ConfirmTreatmentRequestData)), - &_GuiController, SLOT(doAdjustment(ConfirmTreatmentRequestData))); - - connect(&_GuiController, SIGNAL(didActionReceive(StartTreatmentResponseData)), - this, SLOT(onStartTreatmentResponse(StartTreatmentResponseData))); - - loadTreatmentParameterRanges(); + ADJUST_VIEW_CONNECTION(AdjustParametersValidationRequestData ) + ACTION_VIEW_CONNECTION(AdjustParametersValidationResponseData ) + ADJUST_VIEW_CONNECTION(AdjustParametersConfirmRequestData ) + ACTION_VIEW_CONNECTION(AdjustSerialNumberHDResponseData ) } + /** - * \brief VCreateTreatment::loadTreatmentParameterRanges - * Loads treatment parameters from a json file - * \return QJsonObject holding the treatment parameters + * \brief VCreateTreatment::doValidation + * Validates the treatment profile locally, then requests validation of it with FW */ -QJsonObject VTreatmentCreate::loadTreatmentParameterRanges(const QString &path) -{ - QJsonObject obj; - if (!FileHandler::readJSON(path, obj)) - { - // TODO: notify user - LOG_EVENT(tr("Could not load treatment parameter ranges from %0").arg(path)); - return QJsonObject(); - } +void VTreatmentCreate::doValidation() { - foreach (const QString& key, obj.keys()) - { - QJsonValue value = obj.value(key); + AdjustParametersValidationRequestData data; - if (key == GET_VARIABLE_NAME(bloodFlowRateMin)) _bloodFlowRateMin = value.toInt(); - else if (key == GET_VARIABLE_NAME(bloodFlowRateMax)) _bloodFlowRateMax = value.toInt(); - else if (key == GET_VARIABLE_NAME(dialysateFlowRateMin)) _dialysateFlowRateMin = value.toInt(); - else if (key == GET_VARIABLE_NAME(dialysateFlowRateMax)) _dialysateFlowRateMax = value.toInt(); - else if (key == GET_VARIABLE_NAME(durationMin)) _durationMin = value.toInt(); - else if (key == GET_VARIABLE_NAME(durationMax)) _durationMax = value.toInt(); - else if (key == GET_VARIABLE_NAME(heparinDispensingRateMin)) _heparinDispensingRateMin = value.toInt(); - else if (key == GET_VARIABLE_NAME(heparinDispensingRateMax)) _heparinDispensingRateMax = value.toInt(); - else if (key == GET_VARIABLE_NAME(heparinBolusVolumeMin)) _heparinBolusVolumeMin = value.toInt(); - else if (key == GET_VARIABLE_NAME(heparinBolusVolumeMax)) _heparinBolusVolumeMax = value.toInt(); - else if (key == GET_VARIABLE_NAME(heparinStopTimeMin)) _heparinStopTimeMin = value.toInt(); - else if (key == GET_VARIABLE_NAME(heparinStopTimeMax)) _heparinStopTimeMax = value.toInt(); - else if (key == GET_VARIABLE_NAME(salineBolusVolumeMin)) _salineBolusVolumeMin = value.toInt(); - else if (key == GET_VARIABLE_NAME(salineBolusVolumeMax)) _salineBolusVolumeMax = value.toInt(); - // options - else if (key == GET_VARIABLE_NAME(acidConcentrateOptions)) _acidConcentrateOptions = jsonArrayToStringList(value.toArray()); - else if (key == GET_VARIABLE_NAME(bicarbonateConcentrateOptions)) _bicarbonateConcentrateOptions = jsonArrayToStringList(value.toArray()); - else if (key == GET_VARIABLE_NAME(dialyzerTypeOptions)) _dialyzerTypeOptions = jsonArrayToStringList(value.toArray()); + data.mBloodFlowRate = _bloodFlowRate ; + data.mDialysateFlowRate = _dialysateFlowRate ; + data.mTreatmentDuration = _treatmentDuration ; + data.mHeparinDispensingRate = _heparinDispensingRate ; + data.mHeparinBolusVolume = _heparinBolusVolume ; + data.mHeparinStopTime = _heparinStopTime ; + data.mSalineBolus = _salineBolusVolume ; + data.mHeparinType = _heparinType ; + data.mAcidConcentrate = _acidConcentrate ; + data.mBicarbonateConcentrate = _bicarbonateConcentrate ; + data.mDialyzerType = _dialyzerType ; + data.mDialysateTemp = _dialysateTemp ; + data.mArterialPressureLimitWindow = _arterialPressureLimitWindow ; + data.mVenousPressureLimitWindow = _venousPressureLimitWindow ; + data.mVenousPressureLimitAsymtrc = _venousPressureLimitAsymtrc ; + data.mBloodPressureMeasureInterval = _bloodPressureMeasureInterval ; + data.mRinsebackFlowRate = _rinsebackFlowRate ; - else if (key == GET_VARIABLE_NAME(dialysateTempMin)) _dialysateTempMin = value.toInt(); - else if (key == GET_VARIABLE_NAME(dialysateTempMax)) _dialysateTempMax = value.toInt(); - // arterial - else if (key == GET_VARIABLE_NAME(arterialPressureLimitLowMin)) _arterialPressureLimitLowMin = value.toInt(); - else if (key == GET_VARIABLE_NAME(arterialPressureLimitLowMax)) _arterialPressureLimitLowMax = value.toInt(); - else if (key == GET_VARIABLE_NAME(arterialPressureLimitHighMin)) _arterialPressureLimitHighMin = value.toInt(); - else if (key == GET_VARIABLE_NAME(arterialPressureLimitHighMax)) _arterialPressureLimitHighMax = value.toInt(); - // venous - else if (key == GET_VARIABLE_NAME(venousPressureLimitLowMin)) _venousPressureLimitLowMin = value.toInt(); - else if (key == GET_VARIABLE_NAME(venousPressureLimitLowMax)) _venousPressureLimitLowMax = value.toInt(); - else if (key == GET_VARIABLE_NAME(venousPressureLimitHighMin)) _venousPressureLimitHighMin = value.toInt(); - else if (key == GET_VARIABLE_NAME(venousPressureLimitHighMax)) _venousPressureLimitHighMax = value.toInt(); - - else if (key == GET_VARIABLE_NAME(bloodPressureMeasureIntervalMin)) _bloodPressureMeasureIntervalMin = value.toInt(); - else if (key == GET_VARIABLE_NAME(bloodPressureMeasureIntervalMax)) _bloodPressureMeasureIntervalMax = value.toInt(); - - else if (key == GET_VARIABLE_NAME(rinsebackFlowRateMin)) _rinsebackFlowRateMin = value.toInt(); - else if (key == GET_VARIABLE_NAME(rinsebackFlowRateMax)) _rinsebackFlowRateMax = value.toInt(); - else - { - qDebug() << "Invalid treatment parameter range: " << key; - LOG_EVENT(tr("Invalid treatment parameter found: %0").arg(key)); - } - } - - return obj; + emit didAdjustment(data); } /** - * \brief VCreateTreatment::onResetCreateTreatment - * Resets the create treatment page to the default values. - * Disables the continue button. + * \brief VCreateTreatment::doConfirm + * \details Emits treatment data to GUI controller, + * who emits to application controller + * \note Finished create treatment confirm... */ -void VTreatmentCreate::onResetCreateTreatment() -{ - reset_bloodFlowRate(); - reset_dialysateFlowRate(); - reset_duration(); - reset_heparinDispensingRate(); - reset_heparinBolusVolume(); - reset_heparinStopTime(); - reset_salineBolusVolume(); - reset_acidConcentrate(); - reset_bicarbonateConcentrate(); - reset_dialyzerType(); - reset_dialysateTemp(); - reset_arterialPressureLimitLow(); - reset_arterialPressureLimitHigh(); - reset_venousPressureLimitLow(); - reset_venousPressureLimitHigh(); - reset_bloodPressureMeasureInterval(); - reset_rinsebackFlowRate(); - - continueEnabled(false); - - emit resetCreateTreatment(); +void VTreatmentCreate::doConfirm() { + AdjustParametersConfirmRequestData confirmTreatmentRequest; + confirmTreatmentRequest.requestedState = AdjustParametersConfirmRequestData::eConfirm; + emit didAdjustment(confirmTreatmentRequest); } - /** - * \brief VCreateTreatment::jsonArrayToStringList - * Converts a jsonarray of strings to a QStringList - * \param arr (QJsonArray) to convert - * \return (QStringList) The list of strings in the array + * \brief VCreateTreatment::doCancel + * \details Notifies FW the user has canceled confirming the treatment parameters + * \note Telling FW user is canceling confirm treatment parameters... */ -QStringList VTreatmentCreate::jsonArrayToStringList(const QJsonArray &arr) +void VTreatmentCreate::doCancel() { - QStringList result; - foreach (const QJsonValue &val, arr) { - result.append(val.toString()); - } - return result; + AdjustParametersConfirmRequestData confirmTreatmentRequest; + confirmTreatmentRequest.requestedState = AdjustParametersConfirmRequestData::eCancel; + emit didAdjustment(confirmTreatmentRequest); } /** - * \brief VCreateTreatment::setTreatmentData - * Assigns treatment parameters to the treatment data structure. - */ -void VTreatmentCreate::setTreatmentData() { - - treatmentData.bloodFlowRate = _bloodFlowRate; - treatmentData.dialysateFlowRate = _dialysateFlowRate; - treatmentData.duration = _duration; - treatmentData.heparinDispensingRate = _heparinDispensingRate; - treatmentData.heparinBolusVolume = _heparinBolusVolume; - treatmentData.heparinStopTime = _heparinStopTime; - treatmentData.salineBolus = _salineBolusVolume; - - treatmentData.acidConcentrate = _acidConcentrate; - treatmentData.bicarbonateConcentrate = _bicarbonateConcentrate; - treatmentData.dialyzerType = _dialyzerType; - treatmentData.dialysateTemp = _dialysateTemp; - treatmentData.arterialPressureLimitLow = _arterialPressureLimitLow; - treatmentData.arterialPressureLimitHigh = _arterialPressureLimitHigh; - treatmentData.venousPressureLimitLow = _venousPressureLimitLow; - treatmentData.venousPressureLimitHigh = _venousPressureLimitHigh; - treatmentData.bloodPressureMeasureInterval = _bloodPressureMeasureInterval; - treatmentData.rinsebackFlowRate = _rinsebackFlowRate; -} - -/** - * \brief VCreateTreatment::onFinishedCreate - * Validates the treatment profile locally, then requests validation of it with FW - */ -void VTreatmentCreate::onFinishedCreate() { - - setTreatmentData(); - - if (!validate(treatmentData)) - { - qDebug() << "Local create treatment validation failed."; - LOG_EVENT("Local create treatment validation failed."); - return; - } - - // Request that FW validates the selected parameters - emit requestValidateParameters(treatmentData); - - LOG_DEBUG("Requesting FW validation of new treatment parameters"); - -} - -/** * \brief VCreateTreatment::enumToString - * Convenience functiont to convert an enum to a string + * Convenience function to convert an enum to a string * \param vEnum - the enum value * \return QString - the enum name */ QString VTreatmentCreate::enumToString(GuiRequestReasons vEnum) { - const QMetaObject *mo = qt_getEnumMetaObject(vEnum); - int enumIdx = mo->indexOfEnumerator(qt_getEnumName(vEnum)); - QString mText = mo->enumerator(enumIdx).valueToKey(vEnum); - if ( ! mText.isEmpty() ) { - return mText; - } - return QString("[%1] Unknown Rejection Reason").arg(vEnum); + return Gui::enumString(vEnum, "[%1] Unknown Rejection Reason"); } /** @@ -218,655 +106,119 @@ * \param messageData The message data must contain the reject reason codes for all parameters * \returns True if FW OK's treatment parameters, false otherwise */ -bool VTreatmentCreate::onFWValidationResponse(AdjustTreatmentParametersResponseData data) { +void VTreatmentCreate::onActionReceive(const AdjustParametersValidationResponseData &data) { + if (! data.mAccepted) { + bloodFlowRateRejectReason (data.mBloodFlowRate ); + dialysateFlowRateRejectReason (data.mDialysateFlowRate ); + treatmentDurationRejectReason (data.mDuration ); + heparinDispensingRateRejectReason (data.mHeparinDispensingRate ); + heparinBolusVolumeRejectReason (data.mHeparinBolusVolume ); + heparinStopTimeRejectReason (data.mHeparinStopTime ); + salineBolusVolumeRejectReason (data.mSalineBolus ); - bool success = true; - if (data.bloodFlowRate != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.bloodFlowRate)); - success = false; - emit bloodFlowRate_ValidationFailed(enumToString(static_cast(data.bloodFlowRate))); - } - if (data.dialysateFlowRate != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.dialysateFlowRate)); - success = false; - emit dialysateFlowRate_ValidationFailed(enumToString(static_cast(data.dialysateFlowRate))); - } - if (data.duration != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.duration)); - success = false; - emit duration_ValidationFailed(enumToString(static_cast(data.duration))); - } - if (data.heparinDispensingRate != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.heparinDispensingRate)); - success = false; - emit heparinDispensingRate_ValidationFailed(enumToString(static_cast(data.heparinDispensingRate))); - } - if (data.heparinBolusVolume != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.heparinBolusVolume)); - success = false; - emit heparinBolusVolume_ValidationFailed(enumToString(static_cast(data.heparinBolusVolume))); - } - if (data.heparinStopTime != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.heparinStopTime)); - success = false; - emit heparinStopTime_ValidationFailed(enumToString(static_cast(data.heparinStopTime))); - } - if (data.salineBolus != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.salineBolus)); - success = false; - emit salineBolusVolume_ValidationFailed(enumToString(static_cast(data.salineBolus))); - } - if (data.acidConcentrate != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.acidConcentrate)); - success = false; - emit acidConcentrate_ValidationFailed(enumToString(static_cast(data.acidConcentrate))); - } - if (data.bicarbonateConcentrate != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.bicarbonateConcentrate)); - success = false; - emit bicarbonateConcentrate_ValidationFailed(enumToString(static_cast(data.bicarbonateConcentrate))); - } - if (data.dialyzerType != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.dialyzerType)); - success = false; - emit dialyzerType_ValidationFailed(enumToString(static_cast(data.dialyzerType))); - } - if (data.dialysateTemp != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.dialysateTemp)); - success = false; - emit dialysateTemp_ValidationFailed(enumToString(static_cast(data.dialysateTemp))); - } - if (data.arterialPressureLimitLow != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.arterialPressureLimitLow)); - success = false; - emit arterialPressureLimitLow_ValidationFailed(enumToString(static_cast(data.arterialPressureLimitLow))); - } - if (data.arterialPressureLimitHigh != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.arterialPressureLimitHigh)); - success = false; - emit arterialPressureLimitHigh_ValidationFailed(enumToString(static_cast(data.arterialPressureLimitHigh))); - } - if (data.venousPressureLimitLow != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.venousPressureLimitLow)); - success = false; - emit venousPressureLimitLow_ValidationFailed(enumToString(static_cast(data.venousPressureLimitLow))); - } - if (data.venousPressureLimitHigh != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.venousPressureLimitHigh)); - success = false; - emit venousPressureLimitHigh_ValidationFailed(enumToString(static_cast(data.venousPressureLimitHigh))); - } - if (data.bloodPressureMeasureInterval != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.bloodPressureMeasureInterval)); - success = false; - emit bloodPressureMeasureInterval_ValidationFailed(enumToString(static_cast(data.bloodPressureMeasureInterval))); - } - if (data.rinsebackFlowRate != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.rinsebackFlowRate)); - success = false; - emit rinsebackFlowRate_ValidationFailed(enumToString(static_cast(data.rinsebackFlowRate))); - } - if (data.requestValid != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { - success = false; - emit fwValidationFailed(enumToString(static_cast(data.requestValid))); - } + heparinTypeRejectReason (data.mHeparinType ); + acidConcentrateRejectReason (data.mAcidConcentrate ); + bicarbonateConcentrateRejectReason (data.mBicarbonateConcentrate ); + dialyzerTypeRejectReason (data.mDialyzerType ); - qDebug() << "fw validation success = " << success; + dialysateTempRejectReason (data.mDialysateTemp ); + arterialPressureLimitWindowRejectReason (data.mArterialPressureLimitWindow ); + venousPressureLimitWindowRejectReason (data.mVenousPressureLimitWindow ); + venousPressureLimitAsymtrcRejectReason (data.mVenousPressureLimitAsymtrc ); + bloodPressureMeasureIntervalRejectReason (data.mBloodPressureMeasureInterval); + rinsebackFlowRateRejectReason (data.mRinsebackFlowRate ); - if (success) - goToNextPage(true); - - return success; -} - -/** - * @brief VCreateTreatment::onStartTreatmentResponse - * Called when we receive a response back from firmware after requesting - * to start selecting treatment parameters, cancel, or start the treatment - * @param messageData - */ -void VTreatmentCreate::onStartTreatmentResponse(const StartTreatmentResponseData &messageData) -{ - qDebug() << "Received response after start treatment request: " << messageData.startTreatmentResponse; - if (messageData.startTreatmentResponse != 1) - return; - - if (startTreatmentRequest.request == StartTreatmentRequestData::eCancel) - goToNextPage(false); - else - goToNextPage(true); -} - -/** - * @brief VCreateTreatment::getNextPage - * Updates the current page to the next page after - * moving forward or backward - * @param forward - (bool) true if moving forward, if false pop the page - */ -void VTreatmentCreate::goToNextPage(bool forward) -{ - qDebug() << __FUNCTION__ << pageToShow; - - switch (pageToShow) - { - case None: { - if (forward) { - pageToShow = CreateTreatment; - emit showCreate(); - } - else { - emit pop(); - } - break; - } - case CreateTreatment: { - if (forward) { - pageToShow = ConfirmTreatment; - emit showConfirm(); - } - else { - pageToShow = None; - emit pop(); - } - break; - } - case ConfirmTreatment: { - if (forward) { - pageToShow = Priming; - emit showPrime(); - } else { - pageToShow = CreateTreatment; - emit pop(); - } - break; - } - case Priming: { - if (forward) { - pageToShow = BeginTreatment; - emit showBegin(); - } else { - pageToShow = ConfirmTreatment; // TODO: won't be able to go back eventually - emit pop(); - } - break; - } - case BeginTreatment: { - if (forward) { - // reset for next time a treatment is created - pageToShow = None; - emit showTreatmentStart(); - } else { - pageToShow = Priming; - emit pop(); - } - break; - } - default: { - LOG_DEBUG("Invalid current page."); - } + emit didValidationFail(); } -} - -/** - * \brief VCreateTreatment::onFinishedConfirm - * Emits treatment data to gui controller, - * who emits to application controller and the - * application controller will save the data to disk. - */ -void VTreatmentCreate::onFinishedConfirm() { - qDebug() << "Finished create treatment confirm..."; - - - QJsonObject obj { - {"bloodFlowRate", QString::number(treatmentData.bloodFlowRate)}, - {"dialysateFlowRate", QString::number(treatmentData.dialysateFlowRate)}, - {"duration", QString::number(treatmentData.duration)}, - {"heparinDispensingRate", QString::number(treatmentData.heparinDispensingRate)}, - {"heparinBolusVolume", QString::number(treatmentData.heparinBolusVolume)}, - {"heparinStopTime", QString::number(treatmentData.heparinStopTime)}, - {"acidConcentrate", QString::number(treatmentData.acidConcentrate)}, - {"bicarbonateConcentrate", QString::number(treatmentData.bicarbonateConcentrate)}, - {"dialyzerType", QString::number(treatmentData.dialyzerType)}, - {"dialysateTemp", QString::number(treatmentData.dialysateTemp)}, - {"arterialPressureLimitLow", QString::number(treatmentData.arterialPressureLimitLow)}, - {"arterialPressureLimitHigh", QString::number(treatmentData.arterialPressureLimitHigh)}, - {"venousPressureLimitLow", QString::number(treatmentData.venousPressureLimitLow)}, - {"venousPressureLimitHigh", QString::number(treatmentData.venousPressureLimitHigh)}, - {"bloodPressureMeasureInterval",QString::number(treatmentData.bloodPressureMeasureInterval)}, - {"rinsebackFlowRate", QString::number(treatmentData.rinsebackFlowRate)} - }; - - if (saveTreatmentProfile()) - saveNewTreatment(obj); - - // Tell FW we confirm - emit requestConfirm(confirmTreatmentRequest); - - // no FW response required - goToNextPage(true); -} - -/** - * \brief ApplicationController::saveNewTreatment - * Saves a new treatment to the filesystem. - * \param doc - QJsonDocument containing the new treatment parameters. - * \returns QString - the file to be written to - * - */ -QString VTreatmentCreate::saveNewTreatment(const QJsonObject &obj, const QString &dir) -{ - QJsonDocument document(obj); - int i = 0; - while (QFile(QString("%0treatment%1.json").arg(dir).arg(i)).exists()) - { - i++; + else { + generateTxCode(); + emit didValidationPass(); } - QString filename = QString("%0treatment%1.json").arg(dir).arg(i); - _FileSaver.concurrentSave(filename, document.toJson(), false); - return filename; } -/** - * @brief VCreateTreatment::getParameterRangesDataCSV - * Gets the parameter ranges data prepared for CSV file format - * @return QString - the data to write to CSV +/*! + * \brief VTreatmentCreate::onActionReceive + * \details This message is received from the HD in POST through the applicationController and GuiController. + * This class keeps the serial for any treatment Code (txCode) generation + * \param data - the message model data */ -QString VTreatmentCreate::getParameterRangesDataCSV() -{ - QString csvData; - QString sep = ","; - - csvData += QString("bloodFlowRateMin,%0\n").arg(bloodFlowRateMin()); - csvData += QString("bloodFlowRateMax,%0\n").arg(bloodFlowRateMax()); - csvData += QString("dialysateFlowRateMin,%0\n").arg(dialysateFlowRateMin()); - csvData += QString("dialysateFlowRateMax,%0\n").arg(dialysateFlowRateMax()); - csvData += QString("durationMin,%0\n").arg(durationMin()); - csvData += QString("durationMax,%0\n").arg(durationMax()); - csvData += QString("heparinDispensingRateMin,%0\n").arg(heparinDispensingRateMin()); - csvData += QString("heparinDispensingRateMax,%0\n").arg(heparinDispensingRateMax()); - csvData += QString("heparinBolusVolumeMin,%0\n").arg(heparinBolusVolumeMin()); - csvData += QString("heparinBolusVolumeMax,%0\n").arg(heparinBolusVolumeMax()); - csvData += QString("heparinStopTimeMin,%0\n").arg(heparinStopTimeMin()); - csvData += QString("heparinStopTimeMax,%0\n").arg(heparinStopTimeMax()); - csvData += QString("salineBolusVolumeMin,%0\n").arg(salineBolusVolumeMin()); - csvData += QString("salineBolusVolumeMax,%0\n").arg(salineBolusVolumeMax()); - csvData += QString("acidConcentrateOptions,%0\n").arg(acidConcentrateOptions().join(sep)); - csvData += QString("bicarbonateConcentrateOptions,%0\n").arg(bicarbonateConcentrateOptions().join(sep)); - csvData += QString("dialyzerTypeOptions,%0\n").arg(dialyzerTypeOptions().join(sep)); - csvData += QString("dialysateTempMin,%0\n").arg(dialysateTempMin()); - csvData += QString("dialysateTempMax,%0\n").arg(dialysateTempMax()); - csvData += QString("arterialPressureLimitLowMin,%0\n").arg(arterialPressureLimitLowMin()); - csvData += QString("arterialPressureLimitLowMax,%0\n").arg(arterialPressureLimitLowMax()); - csvData += QString("arterialPressureLimitHighMin,%0\n").arg(arterialPressureLimitHighMin()); - csvData += QString("arterialPressureLimitHighMax,%0\n").arg(arterialPressureLimitHighMax()); - csvData += QString("venousPressureLimitLowMin,%0\n").arg(venousPressureLimitLowMin()); - csvData += QString("venousPressureLimitLowMax,%0\n").arg(venousPressureLimitLowMax()); - csvData += QString("venousPressureLimitHighMin,%0\n").arg(venousPressureLimitHighMin()); - csvData += QString("venousPressureLimitHighMax,%0\n").arg(venousPressureLimitHighMax()); - csvData += QString("bloodPressureMeasureIntervalMin,%0\n").arg(bloodPressureMeasureIntervalMin()); - csvData += QString("bloodPressureMeasureIntervalMax,%0\n").arg(bloodPressureMeasureIntervalMax()); - csvData += QString("rinsebackFlowRateMin,%0\n").arg(rinsebackFlowRateMin()); - csvData += QString("rinsebackFlowRateMax,%0\n").arg(rinsebackFlowRateMax()); - - return csvData; +void VTreatmentCreate::onActionReceive(const AdjustSerialNumberHDResponseData &data) { + _HDSerialNumber = data.mSerialNumber; } /*! - * \brief VCreateTreatment::saveTreatmentRangesCSV - * Saves the treatment ranges to a CSV file - * \param filename - the csv file to save the ranges to - * \return bool - true if successful, false otherwise + * \brief VTreatmentCreate::generateTxCode + * \details Generates the txCode by combination of the HD serial number and date and time in yyyyMMddHHmmss + * And updates the TreatmenLog class to be saved in the Tx Report. */ -bool VTreatmentCreate::saveTreatmentRangesCSV(const QString &filename) -{ - QString csvData = getParameterRangesDataCSV(); - - return FileHandler::write(filename, csvData); +void VTreatmentCreate::generateTxCode() { + QDateTime datetime = QDateTime::currentDateTime(); + QString today = datetime.toString("yyyyMMddHHmmss"); + txCode(_HDSerialNumber + today); + _TreatmentLog.gTxCode(_txCode); + LOG_APPED_UI(QString("Generated Treatment Code is %1").arg(_txCode)); } -void VTreatmentCreate::onFinishedSaveNewTreatment(bool success) -{ - if (success) { - qDebug() << "------------------> Saved a new treatment."; - } else { - qDebug() << "------------------> Failed to save new treatment."; - } -} - -/** - * \brief VCreateTreatment::onFnishedPrime - * Called when priming qml selections are complete. - * TODO: Placed here for now. Likely will be moved eventually. +/*! + * \brief VCreateTreatment::doGetPrescriptionParameterValues + * \details Gets a list of the prescription parameter values + * \return (QStringList) The list of parameter values with units */ -void VTreatmentCreate::onFinishedPrime() { - qDebug() << "Finished create treatment prime..."; - - goToNextPage(true); +QStringList VTreatmentCreate::doGetPrescriptionParameterValues() { + return QStringList() << QString("%1 mL/min" ).arg(_bloodFlowRate ) + << QString("%1 mL/min" ).arg(_dialysateFlowRate ) + << QString("%1 min" ).arg(_treatmentDuration ) + << ( _heparinDispensingRate ? QString("%1 mL/hr" ).arg(_heparinDispensingRate) : tr("OFF") ) + << ( _heparinBolusVolume ? QString("%1 mL" ).arg(_heparinBolusVolume ) : tr("OFF") ) + << ( _heparinDispensingRate ? QString("%1 min" ).arg(_heparinStopTime ) : tr("OFF") ) + << QString("%1 mL" ).arg(_salineBolusVolume ) ; } -/** - * \brief VCreateTreatment::start - * Called when user is ready to begin a new treatment. - */ -void VTreatmentCreate::onStartTreatment() { - qDebug() << "Requesting to start a treatment..."; - startTreatmentRequest.request = StartTreatmentRequestData::eStartTreatment; - emit requestSelectParameters(startTreatmentRequest); -} - -/** - * \brief VCreateTreatment::validate - * Validates the create new treatment input. - * \param vData - the selected TreatmentParametersData - * \return true on success, false otherwise. - */ -bool VTreatmentCreate::validate(const AdjustTreatmentParametersRequestData &vData) -{ - bool success = true; - - if (!isbloodFlowRateSet) - success = false; - - if (!isdialysateFlowRateSet) - success = false; - - if (!isdurationSet) - success = false; - - if (!isheparinDispensingRateSet) - success = false; - - if (!isheparinBolusVolumeSet) - success = false; - - if (!isheparinStopTimeSet) - success = false; - - if (!issalineBolusVolumeSet) - success = false; - - if (!isacidConcentrateSet) - success = false; - - if (!isbicarbonateConcentrateSet) - success = false; - - if (!isdialyzerTypeSet) - success = false; - - if (!isdialysateTempSet) - success = false; - - if (!isarterialPressureLimitLowSet) - success = false; - - if (!isarterialPressureLimitHighSet) - success = false; - - if (!isvenousPressureLimitLowSet) - success = false; - - if (!isvenousPressureLimitHighSet) - success = false; - - if (!isbloodPressureMeasureIntervalSet) - success = false; - - if (!isrinsebackFlowRateSet) - success = false; - - if (!success) { - return false; - } - if (vData.bloodFlowRate < _bloodFlowRateMin || - vData.bloodFlowRate > _bloodFlowRateMax) - { - emit bloodFlowRate_ValidationFailed(uiRejections.value(OUT_OF_RANGE)); - success = false; - } - if (vData.dialysateFlowRate < _dialysateFlowRateMin || - vData.dialysateFlowRate > _dialysateFlowRateMax ) - { - emit dialysateFlowRate_ValidationFailed(uiRejections.value(OUT_OF_RANGE)); - success = false; - } - if (vData.duration < _durationMin || vData.duration > _durationMax) - { - emit duration_ValidationFailed(uiRejections.value(OUT_OF_RANGE)); - success = false; - } - if (vData.heparinDispensingRate < _heparinDispensingRateMin || - vData.heparinDispensingRate > _heparinDispensingRateMax) - { - emit heparinDispensingRate_ValidationFailed(uiRejections.value(OUT_OF_RANGE)); - success = false; - } - if (vData.heparinBolusVolume < _heparinBolusVolumeMin || - vData.heparinBolusVolume > _heparinBolusVolumeMax) - { - emit heparinBolusVolume_ValidationFailed(uiRejections.value(OUT_OF_RANGE)); - success = false; - } - - if (vData.heparinStopTime < _heparinStopTimeMin || - vData.heparinStopTime > _heparinStopTimeMax) - { - emit heparinStopTime_ValidationFailed(uiRejections.value(OUT_OF_RANGE)); - success = false; - } - - if (vData.salineBolus < _salineBolusVolumeMin || - vData.salineBolus > _salineBolusVolumeMax) - { - emit salineBolusVolume_ValidationFailed(uiRejections.value(OUT_OF_RANGE)); - success = false; - } - if (!indexInItems(vData.acidConcentrate, _acidConcentrateOptions)) - { - emit acidConcentrate_ValidationFailed(uiRejections.value(OUT_OF_RANGE)); - success = false; - } - if (!indexInItems(vData.bicarbonateConcentrate, _bicarbonateConcentrateOptions)) - { - emit bicarbonateConcentrate_ValidationFailed(uiRejections.value(OUT_OF_RANGE)); - success = false; - } - if (!indexInItems(vData.dialyzerType, _dialyzerTypeOptions)) - { - emit dialyzerType_ValidationFailed(uiRejections.value(OUT_OF_RANGE)); - success = false; - } - if (vData.dialysateTemp < _dialysateTempMin || - vData.dialysateTemp > _dialysateTempMax) - { - emit dialysateTemp_ValidationFailed(uiRejections.value(OUT_OF_RANGE)); - success = false; - } - if (vData.arterialPressureLimitLow < _arterialPressureLimitLowMin || - vData.arterialPressureLimitLow > _arterialPressureLimitLowMax || - vData.arterialPressureLimitLow > vData.arterialPressureLimitHigh) - { - emit arterialPressureLimitLow_ValidationFailed(uiRejections.value(LOW_HIGH_INCOMPATIBLE)); - success = false; - } - if (vData.arterialPressureLimitHigh < _arterialPressureLimitHighMin || - vData.arterialPressureLimitHigh > _arterialPressureLimitHighMax || - vData.arterialPressureLimitHigh < vData.arterialPressureLimitLow) - { - emit arterialPressureLimitHigh_ValidationFailed(uiRejections.value(LOW_HIGH_INCOMPATIBLE)); - success = false; - } - if (vData.venousPressureLimitLow < _venousPressureLimitLowMin || - vData.venousPressureLimitLow > _venousPressureLimitLowMax || - vData.venousPressureLimitLow > vData.venousPressureLimitHigh) - { - emit venousPressureLimitLow_ValidationFailed(uiRejections.value(LOW_HIGH_INCOMPATIBLE)); - success = false; - } - if (vData.venousPressureLimitHigh < _venousPressureLimitHighMin || - vData.venousPressureLimitHigh > _venousPressureLimitHighMax || - vData.venousPressureLimitHigh < vData.venousPressureLimitLow) - { - emit venousPressureLimitHigh_ValidationFailed(uiRejections.value(LOW_HIGH_INCOMPATIBLE)); - success = false; - } - if (vData.bloodPressureMeasureInterval < _bloodPressureMeasureIntervalMin || - vData.bloodPressureMeasureInterval > _bloodPressureMeasureIntervalMax) - { - emit bloodPressureMeasureInterval_ValidationFailed(uiRejections.value(OUT_OF_RANGE)); - success = false; - } - if (vData.rinsebackFlowRate < _rinsebackFlowRateMin || - vData.rinsebackFlowRate > _rinsebackFlowRateMax) - { - emit rinsebackFlowRate_ValidationFailed(uiRejections.value(OUT_OF_RANGE)); - success = false; - } - - return success; -} - -/** - * \brief VCreateTreatment::indexInItems - * Checks if the index is in the QStringList - * \param idx (int) the index - * \param items (QStringList) The list of strings to check - * \return True if it is in the list, false otherwise - */ -bool VTreatmentCreate::indexInItems(quint32 idx, const QStringList &items) -{ - if (idx > (quint32)items.size() - 1) - return false; - else - return true; -} - -/** - * \brief VCreateTreatment::onUserModifiedParameters - * Manages enabling / disabling the continue button - */ -void VTreatmentCreate::onUserModifiedParameters() -{ - setTreatmentData(); - - continueEnabled(validate(treatmentData)); - emit continueEnabledChanged(continueEnabled()); -} - /*! - * \brief VCreateTreatment::getPrescriptionParameterNames - * Gets a list of the prescription parameter names. - * \return (QStringList) A list of the prescription parameter names + * \brief VCreateTreatment::doGetOperatingParameterValues + * \details Gets the operating parameter values + * \return (QStringList) The list of operating parameter values with units where applicable */ -QStringList VTreatmentCreate::getPrescriptionParameterNames() +QStringList VTreatmentCreate::doGetOperatingParameterValues() { - return QStringList() << "Blood Flow Rate" - << "Dialysate Flow Rate" - << "Duration" - << "Heparin Dispensing Rate" - << "Heparin Bolus Volume" - << "Heparin Stop Time" - << "Saline Bolus Volume"; + QString mHeparinType ; + QString mAcidConcentrate ; + QString mBicarbonateConcentrate ; + QString mDialyzerType ; -} + QStringList mHeparinTypeOptions ; + QStringList mAcidConcentrateOptions ; + QStringList mBicarbonateConcentrateOptions ; + QStringList mDialyzerTypeOptions ; -/*! - * \brief VCreateTreatment::getPrescriptionParameterValues - * Gets a list of the prescription parameter values - * \return (QStringList) The list of parameter values with units - */ -QStringList VTreatmentCreate::getPrescriptionParameterValues() -{ - return QStringList() << QString("%0 mL/min").arg(_bloodFlowRate) - << QString("%0 mL/min").arg(_dialysateFlowRate) - << QString("%0 min").arg(_duration) - << QString("%0 mL/hr").arg(_heparinDispensingRate) - << QString("%0 mL").arg(_heparinBolusVolume) - << QString("%0 min").arg(_heparinStopTime) - << QString("%0 mL").arg(_salineBolusVolume); -} + QString mCategory = Storage::Settings_Category_ConfigurationsDataList; -/*! - * \brief VCreateTreatment::getOperatingParameterNames - * Gets a list of the operating parameter names - * \return (QStringList) The list of operating parameter names - */ -QStringList VTreatmentCreate::getOperatingParameterNames() -{ - return QStringList() << "Acid Concentrate" - << "Bicarbonate Concentrate" - << "Dialyzer Type" - << "Dialysate Temperature" - << "Arterial Pressure Limit Low" - << "Arterial Pressure Limit High" - << "Venous Pressure Limit Low" - << "Venous Pressure Limit High" - << "Blood Pressure Measure Interval" - << "Rinseback Rate"; -} + if ( heparinTypeSet () ) { // this is managed on UI with heparinTypeSet() // && ( _heparinDispensingRate || _heparinBolusVolume ) + mHeparinTypeOptions = _Settings.keys(mCategory, "Heparin Type Options" ); + if ((int) _heparinType < mHeparinTypeOptions .length()) mHeparinType = mHeparinTypeOptions .at( _heparinType ); + } else { mHeparinType = tr("NONE"); } -/*! - * \brief VCreateTreatment::getOperatingParameterValues - * Gets the operating parameter values - * \return (QStringList) The list of operating parameter values with units where applicable - */ -QStringList VTreatmentCreate::getOperatingParameterValues() -{ - QString aConcentrate; - QString bCarbConcentrate; - QString dType; - if ((acidConcentrateOptions().length() - 1 < (int)_acidConcentrate) || ((int)_acidConcentrate < 0)) - aConcentrate = "None"; - else - aConcentrate = acidConcentrateOptions().at(get_acidConcentrate()); - if ((bicarbonateConcentrateOptions().length() - 1 < (int)_bicarbonateConcentrate) || ((int)_bicarbonateConcentrate < 0)) - bCarbConcentrate = "None"; - else - bCarbConcentrate = bicarbonateConcentrateOptions().at(get_bicarbonateConcentrate()); - if ((dialyzerTypeOptions().length() - 1 < (int)_dialyzerType) || ((int)_dialyzerType < 0)) - dType = "None"; - else - dType = dialyzerTypeOptions().at(get_dialyzerType()); - return QStringList() << aConcentrate - << bCarbConcentrate - << dType - << QString("%0 C").arg(_dialysateTemp) - << QString("%0 mmHg").arg(_arterialPressureLimitLow) - << QString("%0 mmHg").arg(_arterialPressureLimitHigh) - << QString("%0 mmHg").arg(_venousPressureLimitLow) - << QString("%0 mmHg").arg(_venousPressureLimitHigh) - << QString("%0 min").arg(_bloodPressureMeasureInterval) - << QString("%0 min").arg(_rinsebackFlowRate); -} + if ( acidConcentrateSet () ) { + mAcidConcentrateOptions = _Settings.keys(mCategory, "Acid Concentrate Options" ); + if ((int) _acidConcentrate < mAcidConcentrateOptions .length()) mAcidConcentrate = mAcidConcentrateOptions .at( _acidConcentrate ); + } else { mAcidConcentrate = tr("NONE"); } -/** - * @brief VCreateTreatment::onSelectingParameters - * Sends a request to FW to start selecting treatment parameters - */ -void VTreatmentCreate::onSelectingParameters() -{ - qDebug() << "Sending request to FW to select parameters..."; - startTreatmentRequest.request = StartTreatmentRequestData::eSelectParams; - emit requestSelectParameters(startTreatmentRequest); -} + if ( bicarbonateConcentrateSet () ) { + mBicarbonateConcentrateOptions = _Settings.keys(mCategory, "Bicarbonate Concentrate Options" ); + if ((int) _bicarbonateConcentrate < mBicarbonateConcentrateOptions .length()) mBicarbonateConcentrate = mBicarbonateConcentrateOptions .at( _bicarbonateConcentrate ); + } else { mBicarbonateConcentrate = tr("NONE"); } + if ( dialyzerTypeSet () ) { + mDialyzerTypeOptions = _Settings.keys(mCategory, "Dialyzer Type Options" ); + if ((int) _dialyzerType < mDialyzerTypeOptions .length()) mDialyzerType = mDialyzerTypeOptions .at( _dialyzerType ); + } else { mDialyzerType = tr("NONE"); } -/** - * @brief VCreateTreatment::onCancelSelectingParameters - * Sends a request to FW to cancel selecting parameters - */ -void VTreatmentCreate::onCancelSelectingParameters() -{ - qDebug() << "Sending request to FW to cancel selecting parameters..."; - startTreatmentRequest.request = StartTreatmentRequestData::eCancel; - emit requestSelectParameters(startTreatmentRequest); -} -/** - * @brief VCreateTreatment::onRequestPop - * Navigates backward in the create treatment process. - */ -void VTreatmentCreate::onRequestPop() -{ - goToNextPage(false); + return QStringList() << mHeparinType + << mAcidConcentrate + << mBicarbonateConcentrate + << mDialyzerType + << QString("%0 °C" ).arg(_dialysateTemp ) + << ( _bloodPressureMeasureInterval ? QString("%0 min").arg(_bloodPressureMeasureInterval) : tr("OFF") ) + ; }