/*! * * 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) { 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(doActionReceive(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(doActionReceive(StartTreatmentResponseData))); 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::readJSON(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 requestValidateParameters(treatmentData); LOG_DEBUG("Requesting FW validation of new treatment parameters"); } /** * \brief VCreateTreatment::enumToString * Convenience functiont 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::doActionReceive(AdjustTreatmentParametersResponseData 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.requestValid != Gui::GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { success = false; emit fwValidationFailed(enumToString(static_cast(data.requestValid))); } qDebug() << "fw validation success = " << success; if (success) { emit fwValidationSuccess(); goToNextPage(true); } return success; } /** * @brief VCreateTreatment::doActionReceive * 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::doActionReceive(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: { // coco begin validated: Has been manually validated if (forward) { pageToShow = CreateTreatment; emit showCreate(); } break; } // coco end 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; } // coco begin validated: This has been validated manually. default: { LOG_EVENT("Invalid current page."); } } } // coco end /** * \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::doFinishedConfirm() { 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)} }; 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.request = ConfirmTreatmentRequestData::eConfirm; 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++; } QString filename = QString("%0treatment%1.json").arg(dir).arg(i); emit requestConcurrentSave(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 */ 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 * 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); } 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. */ void VTreatmentCreate::doFinishedPrime() { qDebug() << "Finished create treatment prime..."; goToNextPage(true); } /** * \brief VCreateTreatment::start * Called when user is ready to begin a new treatment. */ void VTreatmentCreate::doStartTreatment() { 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::doUserModifiedParameters * Manages enabling / disabling the continue button */ void VTreatmentCreate::doUserModifiedParameters() { setTreatmentData(); continueEnabled(validate(treatmentData)); emit continueEnabledChanged(continueEnabled()); } /*! * \brief VCreateTreatment::doGetPrescriptionParameterNames * 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 * 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 * 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::doSelectParameters * Sends a request to FW to start selecting treatment parameters */ void VTreatmentCreate::doSelectParameters() { qDebug() << "Sending request to FW to select parameters..."; startTreatmentRequest.request = StartTreatmentRequestData::eSelectParams; emit requestSelectParameters(startTreatmentRequest); } /** * @brief VCreateTreatment::doCancelSelectingParameters * Sends a request to FW to cancel selecting parameters */ void VTreatmentCreate::doCancelSelectingParameters() { qDebug() << "Sending request to FW to cancel selecting parameters..."; startTreatmentRequest.request = StartTreatmentRequestData::eCancel; emit requestSelectParameters(startTreatmentRequest); } /** * @brief VCreateTreatment::doCancelConfirmParameters * Notifies FW the user has canceled confirming the treatment parameters */ void VTreatmentCreate::doCancelConfirmParameters() { // Tell FW we cancel confirm qDebug() << "Telling FW user is canceling confirm treatment parameters..."; confirmTreatmentRequest.request = ConfirmTreatmentRequestData::eCancel; emit requestConfirm(confirmTreatmentRequest); goToNextPage(false); } /** * @brief VCreateTreatment::doRequestPop * Navigates backward in the create treatment process. */ void VTreatmentCreate::doRequestPop() { goToNextPage(false); }