Exercise: Patient Vitals Monitor
Problem statement
You are writing software for an intensive care unit (ICU) patient monitor. The monitor constantly checks the patient's heart rate and oxygen saturation (SpO2). If the heart rate drops below 50 or exceeds 120, or if the SpO2 drops below 90, the system must broadcast an emergency alert containing the exact vitals. You must build a complete utility that simulates reading a stream of patient data and triggers the alerts appropriately.
Task requirements
Create a
VitalsArgsclass that inherits fromEventArgsand holdsHeartRateandSpO2integer properties.In
VitalsMonitor, create a public event using the built-inEventHandler<T>delegate.Implement the
RecordVitalsmethod to check the safety thresholds and raise the event if the patient is in danger.Instantiate the monitor and subscribe an alert system that prints
"CRITICAL: HR is {HeartRate}, SpO2 is {SpO2}".
Constraints
You must strictly follow the standard .NET event pattern (
EventHandler<TEventArgs>).RecordVitalsshould raise the event passingthisas the sender and a new instance ofVitalsArgs.
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
Custom event argument classes simply hold data. They need read-only properties and a constructor to set those properties.
The standard signature for a subscriber of
EventHandler<T>requires two parameters, typically namedsenderande.Inside your lambda expression, you will access the data using
e.HeartRateande.SpO2.
Exercise: Patient Vitals Monitor
Problem statement
You are writing software for an intensive care unit (ICU) patient monitor. The monitor constantly checks the patient's heart rate and oxygen saturation (SpO2). If the heart rate drops below 50 or exceeds 120, or if the SpO2 drops below 90, the system must broadcast an emergency alert containing the exact vitals. You must build a complete utility that simulates reading a stream of patient data and triggers the alerts appropriately.
Task requirements
Create a
VitalsArgsclass that inherits fromEventArgsand holdsHeartRateandSpO2integer properties.In
VitalsMonitor, create a public event using the built-inEventHandler<T>delegate.Implement the
RecordVitalsmethod to check the safety thresholds and raise the event if the patient is in danger.Instantiate the monitor and subscribe an alert system that prints
"CRITICAL: HR is {HeartRate}, SpO2 is {SpO2}".
Constraints
You must strictly follow the standard .NET event pattern (
EventHandler<TEventArgs>).RecordVitalsshould raise the event passingthisas the sender and a new instance ofVitalsArgs.
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
Custom event argument classes simply hold data. They need read-only properties and a constructor to set those properties.
The standard signature for a subscriber of
EventHandler<T>requires two parameters, typically namedsenderande.Inside your lambda expression, you will access the data using
e.HeartRateande.SpO2.