/*! * * 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 VTreatmentCreate.cpp * \author (last) Peter Lucia * \date (last) 15-Oct-2020 * \author (original) Peter Lucia * \date (original) 03-Aug-2020 * */ // Qt // Project #include "ApplicationController.h" #include "VTreatmentCreate.h" #include "FileHandler.h" #include "MsgDefs.h" using namespace Gui; using namespace View; using namespace Storage; VTreatmentCreate::VTreatmentCreate(QObject *parent) : QObject(parent) { ADJUST_VIEW_CONNECTION(AdjustParametersValidationRequestData ) ACTION_VIEW_CONNECTION(AdjustParametersValidationResponseData) ADJUST_VIEW_CONNECTION( AdjustParametersConfirmRequestData) connect(&_ApplicationController , SIGNAL(didSettingsDone()), this , SLOT( onSettingsDone())); } /** * \brief VCreateTreatment::onResetCreateTreatment * Resets the create treatment page to the default values. * Disables the continue button. */ void VTreatmentCreate::doResetCreateTreatment() { reset_bloodFlowRate(); reset_dialysateFlowRate(); reset_duration(); reset_heparinDispensingRate(); reset_heparinBolusVolume(); reset_heparinStopTime(); reset_salineBolusVolume(); reset_heparinType(); reset_acidConcentrate(); reset_bicarbonateConcentrate(); reset_dialyzerType(); reset_dialysateTemp(); reset_arterialPressureLimitLow(); reset_arterialPressureLimitHigh(); reset_venousPressureLimitLow(); reset_venousPressureLimitHigh(); reset_bloodPressureMeasureInterval(); reset_rinsebackFlowRate(); continueEnabled(false); emit resetCreateTreatment(); } /** * \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.heparinType = _heparinType; 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::doValidation * Validates the treatment profile locally, then requests validation of it with FW */ void VTreatmentCreate::doValidation() { setTreatmentData(); if (!validate(treatmentData)) { LOG_DEBUG("Local create treatment validation failed."); return; } // Request that FW validates the selected parameters emit didAdjustment(treatmentData); } /** * \brief VCreateTreatment::doConfirm * \details Emits treatment data to GUI controller, * who emits to application controller * \note Finished create treatment confirm... */ void VTreatmentCreate::doConfirm() { AdjustParametersConfirmRequestData confirmTreatmentRequest; confirmTreatmentRequest.requestedState = AdjustParametersConfirmRequestData::eConfirm; emit didAdjustment(confirmTreatmentRequest); } /** * \brief VCreateTreatment::doCancel * \details Notifies FW the user has canceled confirming the treatment parameters * \note Telling FW user is canceling confirm treatment parameters... */ void VTreatmentCreate::doCancel() { AdjustParametersConfirmRequestData confirmTreatmentRequest; confirmTreatmentRequest.requestedState = AdjustParametersConfirmRequestData::eCancel; emit didAdjustment(confirmTreatmentRequest); } /** * \brief VCreateTreatment::enumToString * Convenience function to convert an enum to a string * \param vEnum - the enum value * \return QString - the enum name */ QString VTreatmentCreate::enumToString(GuiRequestReasons vEnum) { return Gui::enumString(vEnum, "[%1] Unknown Rejection Reason"); } /** * \brief VCreateTreatment::onFWValidationResponse * Slot to handle a validation response from FW * \param actionType The action type must be a create treatment response * \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::onActionReceive(AdjustParametersValidationResponseData data) { bool success = true; if (data.bloodFlowRate != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { 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.heparinType != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { if (success) emit scrollToParameter(GET_VARIABLE_NAME(data.heparinType)); success = false; emit heparinType_ValidationFailed(enumToString(static_cast(data.heparinType))); } 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.mAccepted) { success = false; emit fwValidationFailed(""); } qDebug() << "fw validation success = " << success; if (success) { emit fwValidationSuccess(); } return success; } /** * \brief VCreateTreatment::validate * \details Validates the create new treatment input. * \param vData - the selected TreatmentParametersData * \return true on success, false otherwise. */ bool VTreatmentCreate::validate(const AdjustParametersValidationRequestData &vData) { Q_UNUSED(vData) if (!isbloodFlowRateSet ) return false; if (!isdialysateFlowRateSet ) return false; if (!isdurationSet ) return false; if (!isheparinDispensingRateSet ) return false; if (!isheparinBolusVolumeSet ) return false; if (!isheparinStopTimeSet ) return false; if (!issalineBolusVolumeSet ) return false; if (!isheparinTypeSet ) return false; if (!isacidConcentrateSet ) return false; if (!isbicarbonateConcentrateSet ) return false; if (!isdialyzerTypeSet ) return false; if (!isdialysateTempSet ) return false; if (!isarterialPressureLimitLowSet ) return false; if (!isarterialPressureLimitHighSet ) return false; if (!isvenousPressureLimitLowSet ) return false; if (!isvenousPressureLimitHighSet ) return false; if (!isbloodPressureMeasureIntervalSet ) return false; if (!isrinsebackFlowRateSet ) return false; return true; } /** * \brief VCreateTreatment::doUserModifiedParameters * Manages enabling / disabling the continue button */ void VTreatmentCreate::doUserModifiedParameters() { setTreatmentData(); continueEnabled(validate(treatmentData)); emit continueEnabledChanged(continueEnabled()); } /*! * \brief VCreateTreatment::doGetPrescriptionParameterNames * \details Gets a list of the prescription parameter names. * \return (QStringList) A list of the prescription parameter names */ QStringList VTreatmentCreate::doGetPrescriptionParameterNames() { return QStringList() << "Blood Flow Rate" << "Dialysate Flow Rate" << "Duration" << "Heparin Dispensing Rate" << "Heparin Bolus Volume" << "Heparin Stop Time" << "Saline Bolus Volume"; } /*! * \brief VCreateTreatment::doGetPrescriptionParameterValues * \details Gets a list of the prescription parameter values * \return (QStringList) The list of parameter values with units */ QStringList VTreatmentCreate::doGetPrescriptionParameterValues() { 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); } /*! * \brief VCreateTreatment::doGetOperatingParameterNames * Gets a list of the operating parameter names * \return (QStringList) The list of operating parameter names */ QStringList VTreatmentCreate::doGetOperatingParameterNames() { return QStringList() << "Heparin Type" << "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"; } /*! * \brief VCreateTreatment::doGetOperatingParameterValues * \details Gets the operating parameter values * \return (QStringList) The list of operating parameter values with units where applicable */ QStringList VTreatmentCreate::doGetOperatingParameterValues() { QString heparinType; QString acidConcentrate; QString bicarbConcentrate; QString dialyzerType; if ((heparinTypeOptions().length() - 1 < (int)_heparinType)) heparinType = "None"; else heparinType = heparinTypeOptions().at(_heparinType); if ((acidConcentrateOptions().length() - 1 < (int)_acidConcentrate)) acidConcentrate = "None"; else acidConcentrate = acidConcentrateOptions().at(_acidConcentrate); if ((bicarbonateConcentrateOptions().length() - 1 < (int)_bicarbonateConcentrate)) bicarbConcentrate = "None"; else bicarbConcentrate = bicarbonateConcentrateOptions().at(_bicarbonateConcentrate); if ((dialyzerTypeOptions().length() - 1 < (int)_dialyzerType) || ((int)_dialyzerType < 0)) dialyzerType = "None"; else dialyzerType = dialyzerTypeOptions().at(_dialyzerType); return QStringList() << heparinType << acidConcentrate << bicarbConcentrate << dialyzerType << 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); } /*! * \brief VTreatmentCreate::onSettingsDone * \details fills the items below, read from the settings file, when the reading is notified done by ApplicationController. * acidConcentrateOptions * bicarbonateConcentrateOptions * dialyzerTypeOptions * heparinTypeOptions * */ void VTreatmentCreate::onSettingsDone() { heparinTypeOptions ( _Settings.keys("Heparin Type" )); acidConcentrateOptions ( _Settings.keys("Acid Concentrate" )); bicarbonateConcentrateOptions ( _Settings.keys("Bicarbonate Concentrate" )); dialyzerTypeOptions ( _Settings.keys("Dialyzer Type" )); }