Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 468977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:44:10+00:00 2026-05-12T23:44:10+00:00

I want an event notification system that should notify the doctor when the heartbeat

  • 0

I want an event notification system that should notify the doctor when the heartbeat of the patient is greater than 120.I do not know, How to design such system. Just I have implemented the wrong one. Help me in implementing the correct one.

     static void Main()
    {
     Patient[] patList = { new Patient 
     { PatientID = "1", HeartBeat = 100 },
       new Patient { PatientID = "2", HeartBeat = 130 } };

        List<Patient> plist = patList.ToList();
        Console.ReadKey(true);
    }


public  class Doctor
    {
        public event PulseNotifier AbnormalPulseRaised;
        public string Name
        {
            get;
            set;
        }
    }



public   class Patient
    {
        public event PulseNotifier AbnormalPulseRaised;
        static Random rnd = new Random(); 

        public Patient()
        {
            PulseNotifier += new PulseNotifier(OnAbnormalPulseRaised);
        }
        public string PatientID
        {
            get;
            set;
        }

        public int HeartBeat
        {
            get;
            set;
        }

        public void HeartBeatSimulation(List<Patient> patList)
        {
            foreach(Patient p in patList)
            {
                if (p.HeartBeat > 120)
                {
                    if (AbnormalPulseRaised != null)
                    {
                        AbnormalPulseRaised(p);
                    }
                }
            }
        }

        public void OnAbnormalPulseRaised(Patient p)
        {
            Console.WriteLine("Patient Id :{0},Heart beat {1}",
            p.PatientID, p.HeartBeat);
        }
    }

Apart from that, I want to have a common clarification.

What is the best way to remember the publisher and observer pattern?. Because I am quite confusing about where to implement publisher and where to implement

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:44:10+00:00Added an answer on May 12, 2026 at 11:44 pm

    Well, for starters, I usually think it’s an bad Idea to listen to the events of a class in the same class if you have access to it.

    It’s also a good idea to derive from EventArgs, which is recommended by MS.

    The responsibility of raising the event should indeed be in the patient class itself, but here you raise only the event of the class where you call the HardBeatSimulation function itself instead of on the patient that actually has an abnormal pusle 🙂

        static void Main(string[] args) {
            Patient pat1 = new Patient(1, 120);
            Patient pat2 = new Patient(3, 150); // this one can have a 150 bpm hartbeat :)
            Doctor fancyDoctor = new Doctor();
            fancyDoctor.AddPatient(pat1);
            fancyDoctor.AddPatient(pat2);
            Console.ReadKey(true);
    
        }
    
        public class Doctor {
            List<Patient> _patients;
            public event EventHandler Working;
    
    
            public Doctor() {
                _patients = new List<Patient>();
            }
    
            public void AddPatient(Patient p) {
                _patients.Add(p);
                p.AbnormalPulses += new EventHandler<AbnormalPulseEventArgs>(p_AbnormalPulses);
            }
    
            void p_AbnormalPulses(object sender, AbnormalPulseEventArgs e) {
                OnWorking();
                Console.WriteLine("Doctor: Oops, a patient has some strange pulse, giving some valium...");
            }
    
            protected virtual void OnWorking() {
                if (Working != null) {
                    Working(this, EventArgs.Empty);
                }
            }
    
            public void RemovePatient(Patient p) {
                _patients.Remove(p);
                p.AbnormalPulses -= new EventHandler<AbnormalPulseEventArgs>(p_AbnormalPulses);
            }
        }
    
        public class Patient {
            public event EventHandler<AbnormalPulseEventArgs> AbnormalPulses;
    
            static Random rnd = new Random();
            System.Threading.Timer _puseTmr;
            int _hartBeat;
    
            public int HartBeat {
                get { return _hartBeat; }
                set {
                    _hartBeat = value;
                    if (_hartBeat > MaxHartBeat) {
                        OnAbnormalPulses(_hartBeat);
                    }
                }
            }
    
            protected virtual void OnAbnormalPulses(int _hartBeat) {
                Console.WriteLine(string.Format("Abnormal pulsecount ({0}) for patient {1}", _hartBeat, PatientID));
                if (AbnormalPulses != null) {
                    AbnormalPulses(this, new AbnormalPulseEventArgs(_hartBeat));
                }
            }
    
            public Patient(int patientId, int maxHartBeat) {
                PatientID = patientId;
                MaxHartBeat = maxHartBeat;
                _puseTmr = new System.Threading.Timer(_puseTmr_Tick);
    
                _puseTmr.Change(0, 1000);
            }
    
            void _puseTmr_Tick(object state) {
                HartBeat = rnd.Next(30, 230);
            }
    
            public int PatientID {
                get;
                set;
            }
    
            public int MaxHartBeat {
                get;
                set;
            }
        }
    
        public class AbnormalPulseEventArgs : EventArgs {
            public int Pulses { get; private set; }
            public AbnormalPulseEventArgs(int pulses) {
                Pulses = pulses;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to notify user of mobile as particular event take place,Using notification bar
I want to notify my class's event subscribers without delay and simultaneously. Should I
G'day everyone, I have a system (the source) that needs to notify another system
We want to set up a system where administrators of clones receive email notification
I want to handle the System.Windows.Forms.NotifyIcon's BalloonTipClicked. That is to say, I want to
I have a notification system that works with the following codes jQuery: $(document).ready(function(){$.get('/codes/php/nf.php', function(data)
I want to program some sort of notification system. What would be the be
I have a textbox and want an event triggered whenever it is updated, whether
In the evendrop of fullcalendar plugin, I want the event which is dragged, but
I'm running Drupal 7 with JQuery and Node.js. I want an event to happen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.