Index: denali.pro.user =================================================================== diff -u -r1c23a7f4c576dd70c2bfb94a85af470b7d641f1e -r388ecba67cdd4402c04df9516b44d714745eef7e --- denali.pro.user (.../denali.pro.user) (revision 1c23a7f4c576dd70c2bfb94a85af470b7d641f1e) +++ denali.pro.user (.../denali.pro.user) (revision 388ecba67cdd4402c04df9516b44d714745eef7e) @@ -1,6 +1,6 @@ - + EnvironmentId Index: sources/gui/qml/dialogs/NotificationDialog.qml =================================================================== diff -u -r27cc308ff5113a9386899d3c8f8b29962a8498e1 -r388ecba67cdd4402c04df9516b44d714745eef7e --- sources/gui/qml/dialogs/NotificationDialog.qml (.../NotificationDialog.qml) (revision 27cc308ff5113a9386899d3c8f8b29962a8498e1) +++ sources/gui/qml/dialogs/NotificationDialog.qml (.../NotificationDialog.qml) (revision 388ecba67cdd4402c04df9516b44d714745eef7e) @@ -171,7 +171,7 @@ horizontalCenter: parent.horizontalCenter rightMargin : spacing leftMargin : spacing - bottomMargin : spacing + bottomMargin : spacing / 2 } // IMPORTANT NOTE : Alarm Dialog buttons Fisheye: Tag 388ecba67cdd4402c04df9516b44d714745eef7e refers to a dead (removed) revision in file `sources/view/VTreatmentCreate (legacy).cpp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 388ecba67cdd4402c04df9516b44d714745eef7e refers to a dead (removed) revision in file `sources/view/VTreatmentCreate (legacy).h'. Fisheye: No comparison available. Pass `N' to diff? Index: sources/view/VTreatmentCreate(legacy).cpp =================================================================== diff -u --- sources/view/VTreatmentCreate(legacy).cpp (revision 0) +++ sources/view/VTreatmentCreate(legacy).cpp (revision 388ecba67cdd4402c04df9516b44d714745eef7e) @@ -0,0 +1,577 @@ +/*! + * + * 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 "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(this, SIGNAL(requestConcurrentSave(QString,QString,bool)), + &_FileSaver, SLOT(onConcurrentSave(QString,QString,bool))); + + loadTreatmentParameterRanges(); +} + +/** + * \brief VCreateTreatment::loadTreatmentParameterRanges + * Loads treatment parameters from a json file + * \return QJsonObject holding the treatment parameters + */ +QJsonObject VTreatmentCreate::loadTreatmentParameterRanges(const QString &path) +{ + QJsonObject obj; + if (!FileHandler::read(path, obj)) + { + // TODO: notify user + LOG_EVENT(tr("Could not load treatment parameter ranges from %1").arg(path)); + return QJsonObject(); + } + + foreach (const QString& key, obj.keys()) + { + QJsonValue value = obj.value(key); + + 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()); + + 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; +} + +/** + * \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_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::jsonArrayToStringList + * Converts a jsonarray of strings to a QStringList + * \param arr (QJsonArray) to convert + * \return (QStringList) The list of strings in the array + */ +QStringList VTreatmentCreate::jsonArrayToStringList(const QJsonArray &arr) +{ + QStringList result; + foreach (const QJsonValue &val, arr) { + result.append(val.toString()); + } + return result; +} + +/** + * \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::doFinishedCreate() { + + 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 didAdjustment(treatmentData); + + LOG_DEBUG("Requesting FW validation of new treatment parameters"); + +} + +/** + * \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) +{ + 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); +} + +/** + * \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.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::onFinishedConfirm + * \details Emits treatment data to gui controller, + * who emits to application controller and the + * application controller will save the data to disk. + * \note Finished create treatment confirm... + */ +void VTreatmentCreate::doFinishedConfirm() { + 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)} + }; + + QString treatmentParameters = QJsonDocument(obj).toJson(QJsonDocument::Indented); + LOG_EVENT(QString("Create Treatment Confirm: %1").arg(treatmentParameters)); + if (saveTreatmentProfile()) + saveNewTreatment(obj); + + // Tell FW we confirm + confirmTreatmentRequest.requestedState = AdjustParametersConfirmRequestData::eConfirm; + emit didAdjustment(confirmTreatmentRequest); +} + +/** + * \brief ApplicationController::saveNewTreatment + * \details Saves a new treatment to the file system. + * \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++; + } + QString filename = QString("%0treatment%1.json").arg(dir).arg(i); + emit requestConcurrentSave(filename, document.toJson(), false); + return filename; +} + +/** + * \brief VCreateTreatment::getParameterRangesDataCSV + * \details Gets the parameter ranges data prepared for CSV file format + * \return QString - the data to write to CSV + */ +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; +} + +/*! + * \brief VCreateTreatment::saveTreatmentRangesCSV + * \details 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 + */ +bool VTreatmentCreate::saveTreatmentRangesCSV(const QString &filename) +{ + QString csvData = getParameterRangesDataCSV(); + return FileHandler::write(filename, csvData); +} + +/** + * \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) +{ + 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 (!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() << "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 aConcentrate; + QString bCarbConcentrate; + QString dType; + if ((acidConcentrateOptions().length() - 1 < (int)_acidConcentrate)) + aConcentrate = "None"; + else + aConcentrate = acidConcentrateOptions().at(acidConcentrate()); + if ((bicarbonateConcentrateOptions().length() - 1 < (int)_bicarbonateConcentrate)) + bCarbConcentrate = "None"; + else + bCarbConcentrate = bicarbonateConcentrateOptions().at(bicarbonateConcentrate()); + if ((dialyzerTypeOptions().length() - 1 < (int)_dialyzerType) || ((int)_dialyzerType < 0)) + dType = "None"; + else + dType = dialyzerTypeOptions().at(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); +} + +/** + * \brief VCreateTreatment::doCancelConfirmParameters + * \details Notifies FW the user has canceled confirming the treatment parameters + * \note Telling FW user is canceling confirm treatment parameters... + */ +void VTreatmentCreate::doCancelConfirmParameters() +{ + confirmTreatmentRequest.requestedState = AdjustParametersConfirmRequestData::eCancel; + emit didAdjustment(confirmTreatmentRequest); +} Index: sources/view/VTreatmentCreate(legacy).h =================================================================== diff -u --- sources/view/VTreatmentCreate(legacy).h (revision 0) +++ sources/view/VTreatmentCreate(legacy).h (revision 388ecba67cdd4402c04df9516b44d714745eef7e) @@ -0,0 +1,258 @@ +#pragma once + +// Qt +#include +#include +#include +#include +#include +#include + +// Project +#include "MPreTreatmentAdjustParametersValidationResponse.h" +#include "GuiController.h" +#include "StorageGlobals.h" +#include "FileSaver.h" + +// forward diclations +class tst_views; + +using namespace Storage; +using namespace Gui; +using namespace Model; + +#define UNSET 9999 + +namespace View { + +/*! + * \brief The VCreateTreatment class + * + * The Create Treatment View manages the pre-treatment parameter selection entry and validation. + * + * \details The Create Treatment View manages data display and translation between the user interface + * and treatment parameter and treatment parameter response models. + * + * Upon HD messaging with confirmation of the current parameter selection, + * the Create Treatment View segues to the Create Treatment confirmation screen. + * + * Upon HD messaging with a list of one or more invalid parameters, the Create Treatment View + * will signal the invalid parameters to the GUI so the user can make adjustments. + * + * The Create Treatment View replicates the validation function used by FW to mitigate + * incompatible parameter selection situations. + * + * When a user modifies treatment parameters: + * - The treatment parameters model is populated with the data + * - The data is validated for correctness and compatibility + * - The continue button is enabled upon success so FW can validate the parameter selection + * + * \sa Model::MAdjustParametersValidationResponse + * \sa Model::MAdjustParametersConfirmReq + * \sa Model::MInitTreatmentReq + * \sa Model::MConfirmTreatmentReq + * \sa Model::MAdjustInitTreatmentResponse + */ +class VTreatmentCreate : public QObject +{ + Q_OBJECT + + // friends + friend class::tst_views; + +public: + explicit VTreatmentCreate(QObject *parent = nullptr); + +private: + + // mL/min + const quint32 bloodFlowRate_Def = 100 ; // PRS 30 + const quint32 bloodFlowRate_Min = 100 ; // PRS 30 + const quint32 bloodFlowRate_Max = 500 ; // PRS 30 + const quint32 bloodFlowRate_Res = 25 ; // PRS 30 + + // mL/min + const quint32 dialysateFlowRate_Def = 100 ; // PRS 345 + const quint32 dialysateFlowRate_Min = 100 ; // PRS 345 + const quint32 dialysateFlowRate_Max = 600 ; // PRS 345 + const quint32 dialysateFlowRate_Res = 50 ; // PRS 345 + + // minutes + const quint32 duration_Def = 60 ; // PRS 346 + const quint32 duration_Min = 60 ; // PRS 346 + const quint32 duration_Max = 480 ; // PRS 346 + const quint32 duration_Res = 15 ; // PRS 346 + + // mL/hr (0 = off) + const qreal heparinDispensingRate_Def = 0.0 ; // PRS 347 + const qreal heparinDispensingRate_Min = 0.0 ; // PRS 347 + const qreal heparinDispensingRate_Max = 1.0 ; // PRS 347 + const qreal heparinDispensingRate_Res = 0.1 ; // PRS 347 + + // mL + const qreal heparinBolusVolume_Def = 0.0 ; // PRS 348 + const qreal heparinBolusVolume_Min = 0.0 ; // PRS 348 + const qreal heparinBolusVolume_Max = 2.0 ; // PRS 348 + const qreal heparinBolusVolume_Res = 0.1 ; // PRS 348 + + // min + const quint32 heparinStopTime_Def = 0 ; // PRS 464 + const quint32 heparinStopTime_Min = 0 ; // PRS 464 + const quint32 heparinStopTime_Max = 480 ; // PRS 464 + const quint32 heparinStopTime_Res = 10 ; // PRS 464 + + // mL + const quint32 salineBolusVolume_Def = 100 ; // PRS 350 + const quint32 salineBolusVolume_Min = 100 ; // PRS 350 + const quint32 salineBolusVolume_Max = 300 ; // PRS 350 + const quint32 salineBolusVolume_Res = 100 ; // PRS 350 + + const quint32 acidConcentrate_Res = 1 ; // PRS 35 + + const quint32 bicarbonateConcentrate_Res = 1 ; // PRS 351 + + const quint32 dialyzerType_Res = 1 ; // PRS 352 + + // Celsius + const qreal dialysateTemp_Def = 37 ; // PRS 353 + const qreal dialysateTemp_Min = 35 ; // PRS 353 + const qreal dialysateTemp_Max = 38 ; // PRS 353 + const qreal dialysateTemp_Res = 0.5 ; // PRS 353 + + // mmHg + const qint32 arterialPressureLimitLow_Min = -300 ; // PRS 354 + const qint32 arterialPressureLimitLow_Max = 0 ; // PRS 354 + const qint32 arterialPressureLimitLow_Res = 10 ; // PRS 354 + const qint32 arterialPressureLimitLow_Def = -300 ; // PRS 354 + + // mmHg + const qint32 arterialPressureLimitHigh_Min = -300 ; // PRS 355 + const qint32 arterialPressureLimitHigh_Max = 0 ; // PRS 355 + const qint32 arterialPressureLimitHigh_Res = 10 ; // PRS 355 + const qint32 arterialPressureLimitHigh_Def = 0 ; // PRS 355 + + // mmHg + const qint32 venousPressureLimitLow_Min = 20 ; // PRS 356 + const qint32 venousPressureLimitLow_Max = 600 ; // PRS 356 + const qint32 venousPressureLimitLow_Res = 10 ; // PRS 356 + const qint32 venousPressureLimitLow_Def = 20 ; // PRS 356 + + // mmHg + const qint32 venousPressureLimitHigh_Min = 20 ; // PRS 357 + const qint32 venousPressureLimitHigh_Max = 600 ; // PRS 357 + const qint32 venousPressureLimitHigh_Res = 10 ; // PRS 357 + const qint32 venousPressureLimitHigh_Def = 400 ; // PRS 357 + + // min + const quint32 bloodPressureMeasureInterval_Def = 30 ; // PRS 358 + const quint32 bloodPressureMeasureInterval_Min = 15 ; // PRS 358 + const quint32 bloodPressureMeasureInterval_Max = 60 ; // PRS 358 + const quint32 bloodPressureMeasureInterval_Res = 5 ; // PRS 358 + + // mL/min + const quint32 rinsebackFlowRate_Def = 75 ; // PRS 359 + const quint32 rinsebackFlowRate_Min = 50 ; // PRS 359 + const quint32 rinsebackFlowRate_Max = 150 ; // PRS 359 + const quint32 rinsebackFlowRate_Res = 25 ; // PRS 359 + + enum ACID_ENUM { + eAcidUnset = -1, + eAcid01 = 0, + eAcid02 , + eAcid03 , + }; + + enum BICARBONATE_ENUM { + eBicarbUnset= -1, + eBicarb01 = 0, + + }; + + enum DIALYZER_ENUM { + eDialyzerUnset = -1, + eDialyzer01 = 0, + eDialyzer02 , + eDialyzer03 , + + }; + +protected: + TREATMENT_PARAMETER(quint32, bloodFlowRate, bloodFlowRate_Def, bloodFlowRate_Min, bloodFlowRate_Max, bloodFlowRate_Res) + TREATMENT_PARAMETER(quint32, dialysateFlowRate, dialysateFlowRate_Def, dialysateFlowRate_Min, dialysateFlowRate_Max, dialysateFlowRate_Res) + TREATMENT_PARAMETER(quint32, duration, duration_Def, duration_Min, duration_Max, duration_Res) + TREATMENT_PARAMETER(qreal, heparinDispensingRate, heparinDispensingRate_Def, heparinDispensingRate_Min, heparinDispensingRate_Max, heparinDispensingRate_Res) + TREATMENT_PARAMETER(qreal, heparinBolusVolume, heparinBolusVolume_Def, heparinBolusVolume_Min, heparinBolusVolume_Max, heparinBolusVolume_Res) + TREATMENT_PARAMETER(quint32, heparinStopTime, heparinStopTime_Def, heparinStopTime_Min, heparinStopTime_Max, heparinStopTime_Res) + TREATMENT_PARAMETER(quint32, salineBolusVolume, salineBolusVolume_Def, salineBolusVolume_Min, salineBolusVolume_Max, salineBolusVolume_Res) + + TREATMENT_PARAMETER(quint32, acidConcentrate, eAcidUnset, eAcid01, eAcid03, acidConcentrate_Res) + TREATMENT_PARAMETER(quint32, bicarbonateConcentrate, eBicarbUnset, eBicarb01, eBicarb01, bicarbonateConcentrate_Res) + TREATMENT_PARAMETER(quint32, dialyzerType, eDialyzerUnset, eDialyzer01, eDialyzer03, dialyzerType_Res) + + TREATMENT_PARAMETER(qreal, dialysateTemp, dialysateTemp_Def, dialysateTemp_Min, dialysateTemp_Max, dialysateTemp_Res) + TREATMENT_PARAMETER(qint32, arterialPressureLimitLow, arterialPressureLimitLow_Def, arterialPressureLimitLow_Min, arterialPressureLimitLow_Max, arterialPressureLimitLow_Res) + TREATMENT_PARAMETER(qint32, arterialPressureLimitHigh, arterialPressureLimitHigh_Def, arterialPressureLimitHigh_Min, arterialPressureLimitHigh_Max, arterialPressureLimitHigh_Res) + TREATMENT_PARAMETER(qint32, venousPressureLimitLow, venousPressureLimitLow_Def, venousPressureLimitLow_Min, venousPressureLimitLow_Max, venousPressureLimitLow_Res) + TREATMENT_PARAMETER(qint32, venousPressureLimitHigh, venousPressureLimitHigh_Def, venousPressureLimitHigh_Min, venousPressureLimitHigh_Max, venousPressureLimitHigh_Res) + TREATMENT_PARAMETER(quint32, bloodPressureMeasureInterval, bloodPressureMeasureInterval_Def, bloodPressureMeasureInterval_Min, bloodPressureMeasureInterval_Max, bloodPressureMeasureInterval_Res) + TREATMENT_PARAMETER(quint32, rinsebackFlowRate, rinsebackFlowRate_Def, rinsebackFlowRate_Min, rinsebackFlowRate_Max, rinsebackFlowRate_Res) + +protected: + + PROPERTY(QStringList, acidConcentrateOptions, + QStringList() << "08-1251-1" + << "08-2251-0" + << "08-3251-9" + ) + PROPERTY(QStringList, bicarbonateConcentrateOptions, + QStringList() << "Dimesol - BC-201" + ) + PROPERTY(QStringList, dialyzerTypeOptions, + QStringList() << "Nipro Elisio-H 17" + << "Nipro Elisio-H 19" + << "Fresenius Optiflux F160NRe" + << "Fresenius Optiflux F180NRe" + ) + + PROPERTY(bool, continueEnabled, false) + PROPERTY(bool, saveTreatmentProfile, false) + + AdjustParametersValidationRequestData treatmentData; // OK + AdjustParametersConfirmRequestData confirmTreatmentRequest; + + bool validate(const AdjustParametersValidationRequestData &vData); + QString saveNewTreatment(const QJsonObject &obj, const QString &dir = Treatment_Profiles_Dir); + QString getParameterRangesDataCSV(); + bool saveTreatmentRangesCSV(const QString &filename); + QJsonObject loadTreatmentParameterRanges(const QString &path = Treatment_Parameter_Ranges_Path_JSON); + QStringList jsonArrayToStringList(const QJsonArray &arr); + void setTreatmentData(); + +private: + QString enumToString(GuiRequestReasons vEnum); + +signals: + void didAdjustment(const AdjustParametersValidationRequestData &data); + void didAdjustment(const AdjustParametersConfirmRequestData &data); + + void resetCreateTreatment(); + void fwValidationFailed(QString reason); + void fwValidationSuccess(); + void scrollToParameter(QString parameter); + void requestConcurrentSave(QString, QString, bool); + +private slots: + bool onActionReceive(AdjustParametersValidationResponseData data); + +public slots: + void doResetCreateTreatment(); + void doFinishedCreate(); + void doFinishedConfirm(); + void doUserModifiedParameters(); + QStringList doGetPrescriptionParameterNames(); + QStringList doGetPrescriptionParameterValues(); + QStringList doGetOperatingParameterNames(); + QStringList doGetOperatingParameterValues(); + void doCancelConfirmParameters(); +}; +}