Building Medical Digital Twins with Pulse: Open Source Simulation Tools for Developers and Researchers
×
SEEventManager.h
1 /* Distributed under the Apache License, Version 2.0.
2  See accompanying NOTICE file for details.*/
3 
4 #pragma once
5 #include "cdm/properties/SEScalarTime.h"
6 
7 // Keep enums in sync with appropriate schema/cdm/Event.proto file !!
8 enum class eEvent
9 {
10  Antidiuresis = 0,
11  Bradycardia = 1,
12  Bradypnea = 2,
13  BrainOxygenDeficit = 3,
14  CardiacArrest = 4,
15  CardiogenicShock = 5,
16  CardiovascularCollapse = 6,
17  CriticalBrainOxygenDeficit = 7,
18  Diuresis = 8,
19  Fasciculation = 9,
20  Fatigue = 10,
21  FunctionalIncontinence = 11,
22  Hypercapnia = 12,
23  Hyperglycemia = 13,
24  Hypernatremia = 14,
25  Hyperthermia = 15,
26  Hypoglycemia = 16,
27  Hyponatremia = 17,
28  Hypothermia = 18,
29  Hypoxia = 19,
30  HypovolemicShock = 20,
31  IntracranialHypertension = 21,
32  IntracranialHypotension = 22,
33  IrreversibleState = 23,
34  Ketoacidosis = 24,
35  LacticAcidosis = 25,
36  MassiveHemothorax = 26,
37  MaximumPulmonaryVentilationRate = 27,
38  MediumHemothorax = 28,
39  MetabolicAcidosis = 29,
40  MetabolicAlkalosis = 30,
41  MildDehydration = 31,
42  MinimalHemothorax = 32,
43  ModerateDehydration = 33,
44  ModerateHyperoxemia = 34,
45  ModerateHypocapnia = 35,
46  MyocardiumOxygenDeficit = 36,
47  Natriuresis = 37,
48  NutritionDepleted = 38,
49  RenalHypoperfusion = 39,
50  RespiratoryAcidosis = 40,
51  RespiratoryAlkalosis = 41,
52  SevereDehydration = 42,
53  SevereHyperoxemia = 43,
54  SevereHypocapnia = 44,
55  Stabilizing = 45,
56  StartOfCardiacCycle = 46,
57  StartOfExhale = 47,
58  StartOfInhale = 48,
59  Tachycardia = 49,
60  Tachypnea = 50,
61 
62  // Supplemental Oxygen
63  SupplementalOxygenBottleExhausted = 1000,
64  NonRebreatherMaskOxygenBagEmpty = 1001,
65 
66  // Anesthesia Machine
67  AnesthesiaMachineOxygenBottleOneExhausted = 2000,
68  AnesthesiaMachineOxygenBottleTwoExhausted = 2001,
69  AnesthesiaMachineReliefValveActive = 2002,
70 
71  // Mechanical Ventilator
72  MechanicalVentilatorReliefValveActive = 3000,
73  // Mechanical Ventilator Alarms
74  ApneaTimeAlarmTriggered = 3001,
75  AutoPositiveEndExpiratoryPressureAlarmTriggered = 3002,
76  CircuitLeakAlarmTriggered = 3003,
77  HighEndTidalCarbonDioxideAlarmTriggered = 3004,
78  HighMinuteVentilationAlarmTriggered = 3005,
79  HighOxygenSaturationAlarmTriggered = 3006,
80  HighPositiveEndExpiratoryPressureAlarmTriggered = 3007,
81  HighPressureAlarmTriggered = 3008,
82  HighRespiratoryRateAlarmTriggered = 3009,
83  HighTidalVolumeAlarmTriggered = 3010,
84  LowEndTidalCarbonDioxideAlarmTriggered = 3011,
85  LowMinuteVentilationAlarmTriggered = 3012,
86  LowOxygenSaturationAlarmTriggered = 3013,
87  LowPositiveEndExpiratoryPressureAlarmTriggered = 3014,
88  LowPressureAlarmTriggered = 3015,
89  LowTidalVolumeAlarmTriggered = 3016,
90  OxygenSupplyFailureAlarmTriggered = 3017
91 };
92 extern CDM_DECL const std::string& eEvent_Name(eEvent m);
93 
94 class CDM_DECL SEEventHandler
95 {
96 public:
98  virtual ~SEEventHandler() {};
99 
100  virtual void HandleEvent(eEvent e, bool active, const SEScalarTime* simTime = nullptr) = 0;
101 };
102 
103 class CDM_DECL SEActiveEvent
104 {
105 public:
106  SEActiveEvent(eEvent e, const SEScalarTime& duration);
107  SEActiveEvent(eEvent e, double duration, const TimeUnit& unit);
108 
109  static bool SerializeToString(std::vector<const SEActiveEvent*>& active, std::string& output, eSerializationFormat m, Logger* logger);
110  static bool SerializeFromString(const std::string& src, std::vector<const SEActiveEvent*>& active, eSerializationFormat m, Logger* logger);
111 
112  eEvent GetEvent() const { return m_Event; }
113  const SEScalarTime& GetDuration() const { return m_Duration; }
114 
115 protected:
116  eEvent m_Event;
118 };
119 
120 class CDM_DECL SEEventChange
121 {
122 public:
123  SEEventChange(eEvent e, bool active, const SEScalarTime* simTime = nullptr);
124 
125  static bool SerializeToString(std::vector<const SEEventChange*>& changes, std::string& output, eSerializationFormat m, Logger* logger);
126  static bool SerializeFromString(const std::string& src, std::vector<const SEEventChange*>& changes, eSerializationFormat m, Logger* logger);
127 
128  eEvent GetEvent() const { return m_Event; }
129  bool GetActive() const { return m_Active; }
130  const SEScalarTime& GetSimTime() const { return m_SimTime; }
131 
132 protected:
133  bool m_Active;
134  eEvent m_Event;
136 };
137 
138 class CDM_DECL SEEventManager : public Loggable
139 {
140 public:
141  SEEventManager(Logger* logger);
142  virtual ~SEEventManager();
143 
144  void Clear();
145  // Essentially a load, this will set the state to active and set its duration
146  virtual void OverrideActiveState(eEvent state, const SEScalarTime& duration);
147 
148  virtual const std::map<eEvent, bool>& GetEventStates() const { return m_EventState; }
149  virtual void SetEvent(eEvent e, bool active, const SEScalarTime& time);
150  virtual bool IsEventActive(eEvent e) const;
151  virtual double GetEventDuration(eEvent e, const TimeUnit& unit) const;
152  virtual void UpdateEvents(const SEScalarTime& timeStep);
153  virtual bool GetActiveEvents(std::vector<const SEActiveEvent*>& active) const;
161  virtual void ForwardEvents(SEEventHandler* handler) const;
162  virtual SEEventHandler* GetEventHandler() { return m_EventHandler; }
163 
164 protected:
165 
166  std::stringstream m_ss;
168  std::map<eEvent, bool> m_EventState;
169  std::map<eEvent, double> m_EventDuration_s;
170 };
Definition: Logger.h:23
Definition: Logger.h:71
Definition: SEEventManager.h:104
SEScalarTime m_Duration
Definition: SEEventManager.h:117
eEvent m_Event
Definition: SEEventManager.h:116
const SEScalarTime & GetDuration() const
Definition: SEEventManager.h:113
eEvent GetEvent() const
Definition: SEEventManager.h:112
Definition: SEEventManager.h:121
eEvent m_Event
Definition: SEEventManager.h:134
const SEScalarTime & GetSimTime() const
Definition: SEEventManager.h:130
SEScalarTime m_SimTime
Definition: SEEventManager.h:135
bool m_Active
Definition: SEEventManager.h:133
bool GetActive() const
Definition: SEEventManager.h:129
eEvent GetEvent() const
Definition: SEEventManager.h:128
Definition: SEEventManager.h:95
virtual void HandleEvent(eEvent e, bool active, const SEScalarTime *simTime=nullptr)=0
virtual ~SEEventHandler()
Definition: SEEventManager.h:98
SEEventHandler()
Definition: SEEventManager.h:97
Definition: SEEventManager.h:139
std::map< eEvent, double > m_EventDuration_s
Definition: SEEventManager.h:169
virtual const std::map< eEvent, bool > & GetEventStates() const
Definition: SEEventManager.h:148
virtual SEEventHandler * GetEventHandler()
Definition: SEEventManager.h:162
std::stringstream m_ss
Definition: SEEventManager.h:166
SEEventHandler * m_EventHandler
Definition: SEEventManager.h:167
std::map< eEvent, bool > m_EventState
Definition: SEEventManager.h:168
Definition: SEScalarTime.h:28
Definition: SEScalarTime.h:8

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.