public MobileApplicationViewModel()
        {
            DefaultFontSize = 35;

            SelectedUser = new PatientViewModel(new Patient());
            Patients = new ObservableCollection<PatientViewModel>();

            Patients.CollectionChanged += Patients_CollectionChanged;

            //bool found = false;
            //WardNode.WardNodeFound+=(sender,config)=>
            //{
            //    if(found)return;
            //    found = true;
            //    _wardNode = _wardNode = WardNode.StartWardNodeAsClient(config);

            //    _wardNode.PatientAdded += WardNode_PatientAdded;
            //    _wardNode.PatientRemoved += WardNode_PatientRemoved;
            //    _wardNode.PatientChanged += WardNode_PatientChanged;

            //    Application.Current.Dispatcher.Invoke(() => _wardNode.Patients.ToList().ForEach(p => Patients.Add(new PatientViewModel(p) { RoomNumber = _roomNumber++ })));

            //};
            //WardNode.FindWardNodes();

            _wardNode = WardNode.StartWardNodeAsSystem(WebConfiguration.DefaultWebConfiguration);
            _wardNode.PatientAdded += WardNode_PatientAdded;
            _wardNode.PatientRemoved += WardNode_PatientRemoved;
            _wardNode.PatientChanged += WardNode_PatientChanged;

            Application.Current.Dispatcher.Invoke(() => _wardNode.Patients.ToList().ForEach(p => Patients.Add(new PatientViewModel(p) { RoomNumber = _roomNumber++ })));

            MessageFlag = MessageFlags.Comment.ToString();

            InitializeDevice();
        }
Esempio n. 2
0
        void WardNode_PatientChanged(object sender, Patient e)
        {
            var index = -1;

            //Find patient
            var patient = Patients.FirstOrDefault(t => t.Id == e.Id);

            if (patient == null)
                return;

            index = Patients.IndexOf(patient);

            if (index == -1)
                return;

            Patients[index] = new PatientViewModel(e);
            Patients[index].PatientUpdated += PatientUpdated;
        }
        private void SavePatient()
        {
            //var user = (Patient)FindUserByCid(_hyPrDevice.CurrentRfid);
            var user = (Patient)FindUserByCid(SelectedUser.Cid);
            if (user != null)
            {
                user.UpdateAllProperties(SelectedUser.Patient);
                SelectedUser = new PatientViewModel(user);
                _wardNode.UpdatePatient(user);
            }
            else
            {
                user = new Patient
                    {
                        Name = SelectedUser.Name,
                        Color = SelectedUser.Color,
                        Cid = SelectedUser.Cid,
                        Tag = SelectedUser.Tag
                    };

                _wardNode.AddPatient(user);

                SelectedUser.UpdateAllProperties(user);
            }
        }
        private void InitializeDevice()
        {
            _hyPrDevice = new HyPrDevice();
            _hyPrDevice.RfidDataReceived += (sender, e) =>
            {
                var user = (Patient)FindUserByCid(e.Rfid);
                if (user != null)
                {
                    SelectedUser = new PatientViewModel(user);
                    SendColorToHyPrDevice(user.Color);
                }

                else
                {
                    SelectedUser = new PatientViewModel(new Patient()) { Cid = e.Rfid };
                    SendColorToHyPrDevice(new Rgb(0, 0, 0)); SelectedUser.Cid = e.Rfid;
                }
                if(RFIDLoaded != null)
                    RFIDLoaded(this,new EventArgs());
            };
        }