/************************************************************************** * * Copyright (c) 2019-2024 Diality Inc. - All Rights Reserved. * * 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 ModeTreatment.h * * @author (last) Dara Navaei * @date (last) 18-Jul-2023 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 * ***************************************************************************/ #ifndef __MODE_TREATMENT_H__ #define __MODE_TREATMENT_H__ #include "HDCommon.h" #include "HDDefs.h" #include "Dialysis.h" #include "TaskGeneral.h" /** * @defgroup HDTreatmentMode HDTreatmentMode * @brief The HDTreatmentMode module manages the treatment mode state machine and treatment related commands and requests. * * @addtogroup HDTreatmentMode * @{ */ // ********** public definitions ********** /// Payload record structure for a treatment time status message. typedef struct { U32 treatmentTimePrescribedinSec; ///< Treatment time prescribed in seconds. U32 treatmentTimeElapsedinSec; ///< Treatment time elapsed in seconds. U32 treatmentTimeRemaininginSec; ///< Treatment time remaining in seconds. } TREATMENT_TIME_DATA_T; /// Payload record structure for a treatment state message. typedef struct { U32 treatmentSubMode; ///< Treatment submode. U32 uFState; ///< Ultrafiltration state. U32 salineBolusState; ///< Saline bolus state. U32 heparinState; ///< Heparin state. U32 rinsebackState; ///< Rinse back state. U32 txRecircState; ///< Treatment recirc state. U32 bldPrimeState; ///< Blood prime state. U32 txEndState; ///< Treatment end state. U32 txStopState; ///< Treatment stop state. U32 dialysisState; ///< Dialysis state. } TREATMENT_STATE_DATA_T; /// Payload record structure for an ultrafiltration volume change confirmation message. typedef struct { F32 volume_mL; /// Volume in mL. U32 adjustType; ///< Adjust type. } UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T; /// Payload record structure for the in-line pressure limits change request. typedef struct { S32 artPresLimitWindowmmHg; ///< Arterial pressure limit window in mmHg. S32 venPresLimitWindowmmHg; ///< Venous pressure limit window in mmHg. S32 venPresLimitAsymmetricmmHg; ///< Venous pressure limit asymmetric in mmHg. } PRESSURE_LIMIT_CHANGE_REQUEST_T; /// Payload record structure for the in-line pressure limits change response. typedef struct { BOOL accepted; ///< Accepted. U32 rejReasonCode; ///< Rejection reason code number. S32 artPresLimitWindowmmHg; ///< Arterial pressure limit window in mmHg. S32 venPresLimitWindowmmHg; ///< Venous pressure limit window in mmHg. S32 venPresLimitAsymmetricmmHg; ///< Venous pressure limit asymmetric in mmHg. } PRESSURE_LIMIT_CHANGE_RESPONSE_T; /// Payload record structure for the treatment log 30 minutes periodic data. typedef struct { F32 avgBloodFlowRate; ///< Average blood flow rate in mL/min. F32 avgDialysateFlowRate; ///< Average dialysate flow rate in mL/min. F32 avgUFRate; ///< Average ultrafiltration rate. F32 avgArterialPressure; ///< Average arterial pressure in mmHg. F32 avgVenousPressure; ///< Average venous pressure in mmHg. } TREATMENT_LOG_DATA_PERIODIC_T; /// Maximum time in this mode before blood sitting alarm given (in general task intervals). #define MAX_TIME_BLOOD_SITTING ( ( 5 * SEC_PER_MIN * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) /// Maximum time in this mode before blood sitting warning given (in general task intervals). #define WARN_TIME_BLOOD_SITTING ( ( 4 * SEC_PER_MIN * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) // ********** public function prototypes ********** void initTreatmentMode( void ); // Initialize this module U32 transitionToTreatmentMode( void ); // Prepares for transition to treatment mode U32 execTreatmentMode( void ); // Execute the treatment mode state machine (call from OperationModes) void signalAlarmActionToTreatmentMode( ALARM_ACTION_T action ); // Execute alarm action as appropriate for Treatment mode void signalGoToTreatmentStopped( void ); // Rinseback or Re-circ sub-mode is signaling to return to treatment stopped sub-mode void signalGoToRinseback( void ); // Requesting transition to rinseback sub-mode from other sub-mode void signalEndTreatment( void ); // Requesting transition to post-treatment mode void signalBloodPrimeToDialysis( void ); // Blood prime sub-mode is signaling to move on to dialysis sub-mode void signalRinsebackToRecirc( void ); // Rinseback sub-mode is signaling to move on to re-circ sub-mode TREATMENT_STATE_T getTreatmentState( void ); // Determine the current treatment sub-mode (state) BOOL isTreatmentCompleted( void ); // Determine whether the treatment has completed BOOL isTreatmentResumeBlocked( void ); // Determine whether the treatment is not allowed to be resumed. U32 getTreatmentTimeRemainingSecs( void ); // Determine number of seconds remaining in the treatment U32 getActualTreatmentTimeSecs( void ); // Determine the actual treatment duration in seconds BOOL getRinsebackCompleted( void ); // Determine whether a rinseback has been completed void setRinsebackIsCompleted( BOOL flag ); // Set whether a rinseback has been completed (T blocks rinseback option) BOOL getBloodIsPrimed( void ); // Determine whether the blood-side circuit of the dialyzer has been primed with blood void setBloodIsPrimed( BOOL flag ); // Set whether the blood-side circuit of the dialyzer has been primed with blood (F causes Tx start/resume to do blood prime first) F32 getCurrentUFSetRate( void ); // Get the currently set target ultrafiltration rate (in mL/min). F32 getTreatmentAvgBloodFlowRate( void ); // Get the average blood flow rate during treatment F32 getTreatmentAvgDialysateFlowRate( void ); // Get the average dialysate flow rate during treatment F32 getTreatmentAvgDialysateTemp( void ); // Get the average dialysate temperature during treatment F32 getTreatmentAvgArterialPressure( void ); // Get the average arterial pressure during treatment F32 getTreatmentAvgVenousPressure( void ); // Get the average venous pressure during treatment U32 getTreatmentStartTimeStamp( void ); // Get the treatment start time stamp U32 getTreatmentEndTimeStamp( void ); // Get the treatment end time stamp void broadcastTreatmentTimeAndState( void ); // Broadcast the times and states of this treatment BOOL verifyTreatmentDurationSettingChange( U32 treatmentTime ); BOOL verifyUFSettingsChange( F32 uFVolume ); BOOL verifyUFSettingsConfirmation( F32 uFVolume, U32 adjustment ); BOOL verifyBloodAndDialysateRateSettingsChange( U32 bloodRate, U32 dialRate ); BOOL verifyPressureLimitsChange( PRESSURE_LIMIT_CHANGE_REQUEST_T *data ); BOOL testSetTreatmentTimeRemainingOverride( U32 value ); BOOL testSetTreatmentTimePublishIntervalOverride( U32 ms ); BOOL testResetTreatmentTimePublishIntervalOverride( void ); BOOL testSetTreatmentStatePublishIntervalOverride( U32 ms ); BOOL testResetTreatmentStatePublishIntervalOverride( void ); BOOL testSetTreatmentParamRangesPublishIntervalOverride( U32 ms ); BOOL testResetTreatmentParamRangesPublishIntervalOverride( void ); /**@}*/ #endif