Update() private method

private Update ( ) : void
return void
Ejemplo n.º 1
0
        public void DebePoderActualizarUnPaciente()
        {
            var paciente = new Paciente()
            {
                TipoDocumento   = TipoDocumento.DNI,
                NumeroDocumento = "148574957",
                Nombres         = "Pedro",
                Apellidos       = "Huaman",
                Edad            = "18",
                Correo          = "*****@*****.**",
                Direccion       = "Los anders 294",
                TipoGenero      = Genero.Masculino,
                Celular         = "958857223"
            };

            ModelStateDictionary modelState = new ModelStateDictionary();
            var iPacienteService            = new Mock <IPacienteService>();

            iPacienteService.Setup(a => a.UpdatePaciente(paciente));

            var iPacienteValidacion = new Mock <IPacienteValidacion>();

            iPacienteValidacion.Setup(o => o.IsValid()).Returns(true);

            var controller = new PatientController(iPacienteService.Object, iPacienteValidacion.Object);
            var result     = controller.Update(paciente);

            Assert.IsInstanceOf <RedirectToRouteResult>(result);
            iPacienteValidacion.Verify(o => o.validateUpdate(paciente, modelState));
            iPacienteValidacion.Verify(o => o.IsValid());
            iPacienteService.Verify(o => o.UpdatePaciente(paciente), Times.AtLeastOnce);
        }
        public void Potvrda_Click(object sender, RoutedEventArgs e)
        {
            List <Question> pitanja  = new List <Question>();
            String          alergije = "";

            Boolean guest = false;
            Boolean sekr  = false;
            List <ModelNotification> notifications = new List <ModelNotification>();

            if ((LozinkaBox.Text.Equals(PotvLozinkaBox.Text)))
            {
                PatientController  secContr = new PatientController();
                List <PatientUser> lista    = secContr.GetAll();
                int id = 0;
                foreach (PatientUser sec in lista)
                {
                    if (sec.id.ToString().Equals(idPacijenta.Text))
                    {
                        id = sec.id;

                        alergije = sec.allergie;

                        guest = sec.guest;

                        sekr          = sec.isRegisteredBySecretary;
                        notifications = sec.notifications;
                    }
                }

                PatientController rpcontroller = new PatientController();
                if (notifications == null)
                {
                    notifications = new List <ModelNotification>();
                }

                PatientUser rp = new PatientUser(id, ImeBox.Text, PrezimeBox.Text, JMBGBox.Text, DatumRodjBox.Text,
                                                 BrojTelefonaBox.Text, KnjizicaBox.Text, alergije, AdresaBox.Text, false, EmailBox.Text, LozinkaBox.Text, sekr, notifications);

                MessageBox.Show("Uspijesno izmenjeni podaci/registrovan guest pacijent!", "OK", MessageBoxButton.OK);


                Boolean isPatientUpdateOk = secContr.Update(rp);
                if (isPatientUpdateOk == false)
                {
                    MessageBox.Show("Fields must be unique.\nCity must be in format : City, Street number, postal code, Country.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("Lozinke se moraju poklapati!", "Upozorenje", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }



            Panel.Children.Clear();
            UserControl usc = new RegistrovaniPacijenti();

            Panel.Children.Add(usc);
        }
Ejemplo n.º 3
0
        private void isporuci_Click(object sender, RoutedEventArgs e)
        {
            String idPacijent    = sender.ToString();
            int    idPacijentInt = (int)pacijentid.SelectedValue;

            Console.WriteLine(idPacijentInt);
            if (odg.Text.Equals("") || idPacijent.Equals(""))
            {
                MessageBox.Show("Popunite sva polja!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);

                return;
            }

            // int idPacijentInt = int.Parse(idPacijent);
            PatientUser izabranPacijent = new PatientUser();

            foreach (PatientUser pacijent in lista)
            {
                if (pacijent.id == idPacijentInt)
                {
                    izabranPacijent = pacijent;
                }
            }
            if (izabranPacijent.notifications == null)
            {
                izabranPacijent.notifications = new List <ModelNotification>();
            }
            List <ModelNotification> pacijentObavestenja = izabranPacijent.notifications;

            pacijentObavestenja.Add(new ModelNotification("Doctor  " + lekar.firstName + " " + lekar.secondName + "  - answer  -" + odg.Text));
            izabranPacijent.notifications = pacijentObavestenja;
            cont.Update(izabranPacijent);
        }
        private void Prescription_Click(object sender, RoutedEventArgs e)
        {
            if (DrugsComboBox.SelectedItem != null && BeginDatePicker.Text != "" && EndDatePicker.Text != "")
            {
                if (_patientController.IsAllergic((Medicine)DrugsComboBox.SelectedItem, selected))
                {
                    MessageBox.Show("Pacijent je alergičan na izabrani lek.", "Alergičan");
                    return;
                }

                prescription = new Prescription((Medicine)DrugsComboBox.SelectedItem, DateTime.Parse(BeginDatePicker.Text), parent.Doctor);
                selected.MedicalRecord.AddRecept(prescription);

                _patientController.Update(selected.Username, selected);
            }
        }
Ejemplo n.º 5
0
        public async Task Update_ReturnsBadRequestResult_WhenModelStateIsInvalid()
        {
            var mockService = new Mock <IPatientViewModelService>();

            mockService.Setup(service => service.Update(It.IsAny <PatientViewModel>()));
            var controller = new PatientController(mockService.Object);

            controller.ModelState.AddModelError("Name", "Error Massage");
            var patientViewModel = GetPatientViewModel();
            var crudModel        = new Syncfusion.EJ2.Base.CRUDModel <PatientViewModel>();

            crudModel.Value = patientViewModel;

            var result = await controller.Update(crudModel);

            Assert.IsType <BadRequestObjectResult>(result);
        }
Ejemplo n.º 6
0
        public async Task Update_UpdatePatientAndReturnsIndex_WhenModelStateIsValid()
        {
            var mockService = new Mock <IPatientViewModelService>();

            mockService.Setup(service => service.Update(It.IsAny <PatientViewModel>()))
            .Returns(Task.CompletedTask)
            .Verifiable();
            var controller = new PatientController(mockService.Object);
            var crudModel  = new Syncfusion.EJ2.Base.CRUDModel <PatientViewModel>();

            crudModel.Value = GetPatientViewModel();

            var result = await controller.Update(crudModel);

            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Equal("Index", viewResult.ViewName);
        }
Ejemplo n.º 7
0
        public void NoDebePoderActualizarUnPaciente()
        {
            var paciente = new Paciente()
            {
            };

            ModelStateDictionary modelState = new ModelStateDictionary();

            var iPacienteValidacion = new Mock <IPacienteValidacion>();

            iPacienteValidacion.Setup(o => o.validateUpdate(paciente, modelState));
            iPacienteValidacion.Setup(o => o.IsValid()).Returns(false);
            var controller = new PatientController(null, iPacienteValidacion.Object);
            var result     = controller.Update(paciente);

            Assert.IsInstanceOf <ViewResult>(result);
            iPacienteValidacion.Verify(o => o.validateUpdate(paciente, modelState));
            iPacienteValidacion.Verify(o => o.IsValid());
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Boolean temporary = checkCondition();

            if (temporary)
            {
                _patient.Name        = imeTextBox.Text;
                _patient.Surname     = prezimeTextBox.Text;
                _patient.Email       = emailTextBox.Text;
                _patient.PhoneNumber = kontaktTextBox.Text;
                _patientController.Update(_patient.Username, _patient);

                MessageBoxResult result = MessageBox.Show(
                    "Izmene su izvršene uspešno!", "Uspeh",
                    MessageBoxButton.OK);
                if (result == MessageBoxResult.OK)
                {
                    SetInformationsInComponents();
                }
            }
        }
Ejemplo n.º 9
0
        private void Confirm_Click(object sender, RoutedEventArgs e)
        {
            UInt64 JMBGRes;
            char   genderRes;

            if (!UInt64.TryParse(JMBG, out JMBGRes) || JMBG.Length != 13)
            {
                MessageBox.Show("JMBG se mora sastojati iz 13 cifara", "Nedostatak informacija", MessageBoxButton.OK);
                return;
            }
            if (Username == null || Username.Length == 0)
            {
                MessageBox.Show("Korisničko ime ne sme biti prazno", "Nevalidan unos", MessageBoxButton.OK);
                return;
            }
            ResidentialAddress residentialAddress = new ResidentialAddress(ResidentialAddress, new City(City, PostalCode, new Country(Country)));
            Patient            patient            = new Patient(LegalName, Surname, JMBG, char.Parse(Gender), TelephoneNumber, EmailAddress, DateOfBirth, Username, Password, residentialAddress, Guest, SocialSecurityNumber, new MedicalRecord(_patientController.GetAll().Count.ToString()), false);

            patient.MedicalRecord = _initialPatient.MedicalRecord;
            _initialPatient.MedicalRecord.patient = patient;
            _patientController.Update(_initialPatient.Username, patient);
            _parent.UpdateTable();
            this.Close();
        }
Ejemplo n.º 10
0
        private void Zakazi_click(object sender, RoutedEventArgs e)
        {
            String b = bingPathToAppDir(@"JsonFiles\appointments.json");
            String c = bingPathToAppDir(@"JsonFiles\refferal.json");
            String d = bingPathToAppDir(@"JsonFiles\patients.json");
            String m = bingPathToAppDir(@"JsonFiles\doctors.json");


            PatientsRepository patientRepo  = new PatientsRepository(d);
            List <PatientUser> patientLista = patientRepo.GetAll();

            PatientUser ovajPacijent = new PatientUser();

            foreach (PatientUser r1 in patientLista)
            {
                if (r1.medicalIdNumber.Equals(KnjizicaBox.Text.ToString()))
                {
                    ovajPacijent     = r1;
                    KnjizicaBox.Text = r1.medicalIdNumber;
                }
            }



            DoctorRepository  docRepo = new DoctorRepository(m);
            List <DoctorUser> doktori = docRepo.GetAll();
            DoctorUser        drOvaj  = new DoctorUser();

            foreach (DoctorUser d1 in doktori)
            {
                if (d1.email.Equals(emailLekarBox.Text.ToString()))
                {
                    drOvaj = d1;
                }
            }
            if (!Regex.Match(Time1Box.Text, "^[0-9]{2}:[0-9]{2}$").Success || !Regex.Match(Time2Box.Text, "^[0-9]{2}:[0-9]{2}$").Success)
            {
                MessageBox.Show("Vreme mora biti u formatu 00:00", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            String[] startParts    = Time1Box.Text.Split(':');
            String[] endParts      = Time2Box.Text.Split(':');
            int      startIntPart1 = int.Parse(startParts[0]);
            int      startIntPart2 = int.Parse(startParts[1]);
            int      ensIntPart1   = int.Parse(endParts[0]);
            int      endtIntPart2  = int.Parse(endParts[1]);


            if (startIntPart1 > 23 || startIntPart2 > 60 || ensIntPart1 > 23 || endtIntPart2 > 60 || startIntPart1 > ensIntPart1)
            {
                MessageBox.Show("Najveca vrednost za vreme je 23:59", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            TimeSpan vremee  = new TimeSpan(startIntPart1, startIntPart2, 00);
            TimeSpan vremee2 = new TimeSpan(ensIntPart1, endtIntPart2, 00);

            int broj = getNextid();

            DoctorAppointment drap = new DoctorAppointment(broj, vremee, DatumBox.Text.ToString(), ovajPacijent, drOvaj, null, ordinacijaBox.Text);

            AppointmentRepository    arepo  = new AppointmentRepository(b);
            List <DoctorAppointment> lista2 = new List <DoctorAppointment>();
            PatientController        regPat = new PatientController();
            List <PatientUser>       pac    = new List <PatientUser>();

            pac = regPat.GetAll();
            if (arepo.GetAll() != null)
            {
                lista2 = arepo.GetAll();
            }


            String    o     = bingPathToAppDir(@"JsonFiles\operations.json");
            int       broj1 = getNextid1();
            Operation op    = new Operation(broj1, ovajPacijent, DatumBox.Text.ToString(), vremee, vremee2, drOvaj, ordinacijaBox.Text, null);

            OperationRepository opRep  = new OperationRepository(o);
            List <Operation>    lista3 = new List <Operation>();

            if (opRep.GetAll() != null)
            {
                lista3 = opRep.GetAll();
            }

            if (pregled == true)
            {
                String   datum   = DatumBox.Text;
                String[] delovi2 = datum.Split('/');
                int      mesec   = int.Parse(delovi2[1]);
                int      dan     = int.Parse(delovi2[0]);
                int      godina  = int.Parse(delovi2[2]);

                DateTime dt1 = new DateTime(godina, mesec, dan, 0, 0, 0);

                DateTime dt2 = DateTime.Now;

                if (dt1 < dt2)
                {
                    MessageBox.Show("Molimo vas da unesete datum koji tek predstoji", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                String x = bingPathToAppDir(@"JsonFiles\appointments.json");
                AppointmentRepository    apc           = new AppointmentRepository(x);
                List <DoctorAppointment> listaPregleda = apc.GetAll();


                /* foreach (DoctorAppointment dd in listaPregleda)
                 * {
                 *   DoctorUser dr = dd.doctor;
                 *   if (dr.id == drOvaj.id)
                 *   {
                 *       if (dd.Date.Equals(DatumBox.Text))
                 *       {
                 *           TimeSpan krajPr = dd.Time + new TimeSpan(0, 15, 0);
                 *           int result = TimeSpan.Compare(vremee, dd.Time);
                 *           int result1 = TimeSpan.Compare(vremee, krajPr);
                 *           if ((result == 1 && result1 == -1) || result == 0)
                 *           {
                 *               MessageBox.Show("Izvinjavamo se! Trazeni termin je vec zauzet!", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *               return;
                 *           }
                 *       }
                 *
                 *
                 *
                 *
                 *   }
                 * }*/
                /*  String pre = bingPathToAppDir(@"JsonFiles\operations.json");
                 * OperationRepository apc1 = new OperationRepository(pre);
                 * List<Operation> listaPregleda1 = apc1.GetAll();
                 * foreach (Operation dd in listaPregleda1)
                 * {
                 *    DoctorUser dr = dd.isResponiable;
                 *    if (dr.id == drOvaj.id)
                 *    {
                 *        if (dd.Date.Equals(DatumBox.Text))
                 *        {
                 *            int result = TimeSpan.Compare(vremee, dd.Start);
                 *            int result1 = TimeSpan.Compare(vremee, dd.End);
                 *            if ((result == 1 && result1 == -1)||result==0 ||result1==0)
                 *            {
                 *
                 *                MessageBox.Show("Izvinjavamo se! Trazeni termin je vec zauzet!", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *                return;
                 *            }
                 *
                 *        }
                 *
                 *
                 *
                 *
                 *    }
                 * }*/



                EmployeesScheduleController schCon         = new EmployeesScheduleController();
                List <Schedule>             listaRasporeda = schCon.GetAll();
                Shift smena = schCon.getShiftForDoctorForSpecificDay(DatumBox.Text, drOvaj);
                if (smena == null || smena.startTime == null || smena.endTime == null)
                {
                    MessageBox.Show("Trazeni termin nije dostupan.Lekar ne radi tog dana.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);

                    return;
                }
                AppointmentController appointmentController = new AppointmentController();
                Boolean notAvaible = appointmentController.isTermNotAvailable(drOvaj, vremee, DatumBox.Text, ovajPacijent);
                if (notAvaible == true)
                {
                    MessageBox.Show("Izvinjavamo se! Trazeni termin je vec zauzet!", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                /* foreach (Schedule s in listaRasporeda)
                 * {
                 *
                 *   if (s.employeeid.Equals(drOvaj.id.ToString()))
                 *   {
                 *       if (s.Date.Equals(DatumBox.Text))
                 *       {
                 *           smena = s.shift;
                 *       }
                 *   }
                 * }
                 * if(smena.StartTime==null || smena.EndTime == null)
                 * {
                 *
                 * }*/

                bool slobodan = schCon.isDoctorWorkingAtSpecifiedTime(DatumBox.Text, drOvaj, vremee);
                if (slobodan == false)
                {
                    MessageBox.Show("Trazeni termin nije dostupan.Lekar ne radi u to vreme.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);

                    return;
                }

                /* String pocetak = smena.StartTime;
                 * String kraj = smena.EndTime;
                 * String[] deloviPocetak = pocetak.Split(':');
                 * String[] deloviKraj = kraj.Split(':');
                 *
                 * TimeSpan pocetakTime = new TimeSpan(int.Parse(deloviPocetak[0]), int.Parse(deloviPocetak[1]), 0);
                 * TimeSpan krajTime = new TimeSpan(int.Parse(deloviKraj[0]), int.Parse(deloviKraj[1]), 0);
                 * int result3 = TimeSpan.Compare(vremee, pocetakTime);
                 * int result4 = TimeSpan.Compare(krajTime, vremee);
                 *
                 * if (result3 != 1 || result4 != 1)
                 * {
                 *   MessageBox.Show("Trazeni termin nije dostupan.Lekar ne radi u to vreme.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *
                 *   return;
                 *
                 * }*/


                AppointmentController apCon = new AppointmentController();
                apCon.New(drap, null);
                int             id1       = 0;
                String          ime       = "";
                String          prezime   = "";
                String          jmbg      = "";
                String          datumRodj = "";
                String          brojTel   = "";
                String          brKnj     = "";
                List <Question> pitanja   = new List <Question>();
                String          alergije  = "";
                String          grad      = "";
                Boolean         guest     = false;
                String          email     = "";
                String          password  = "";
                Boolean         sekr      = false;

                //  foreach (PatientUser pat in lista)
                // {
                // if (pat.id.Equals(d.patient.id))
                // {
                id1       = drap.patient.id;
                ime       = drap.patient.firstName;
                prezime   = drap.patient.secondName;
                jmbg      = drap.patient.uniqueCitizensidentityNumber;
                datumRodj = drap.patient.dateOfBirth;
                brKnj     = drap.patient.medicalIdNumber;
                brojTel   = drap.patient.phoneNumber;

                alergije = drap.patient.allergie;
                grad     = drap.patient.city;
                email    = drap.patient.email;
                guest    = drap.patient.guest;
                password = drap.patient.password;
                sekr     = drap.patient.isRegisteredBySecretary;
                if (drap.patient.notifications == null)
                {
                    drap.patient.notifications = new List <ModelNotification>();
                }
                List <ModelNotification> notifications = drap.patient.notifications;
                // }

                notifications.Add(new ModelNotification("Postovani, zakazana vam je novi pregled datuma : " + drap.date + " u " + drap.time + " h kod lekara " + drap.doctor.firstName + " " + drap.doctor.secondName + ". Ordinacija: " + drap.roomid));
                drap.patient.notifications = notifications;
                // PatientUser rp = new PatientUser(id1, ime, prezime, jmbg, datumRodj, brojTel, brKnj, pitanja, alergije, grad, guest, email, password, sekr, notifications);


                PatientController pCon = new PatientController();
                pCon.Update(drap.patient);
                Panel.Children.Clear();
                UserControl usc = new RezervisaniiTermini();
                Panel.Children.Add(usc);
            }
            else if (operacija == true)
            {
                String   datum   = DatumBox.Text;
                String[] delovi2 = datum.Split('/');
                int      mesec   = int.Parse(delovi2[1]);
                int      dan     = int.Parse(delovi2[0]);
                int      godina  = int.Parse(delovi2[2]);

                DateTime dt1 = new DateTime(godina, mesec, dan, 0, 0, 0);

                DateTime dt2 = DateTime.Now;

                if (dt2 > dt1)
                {
                    MessageBox.Show("Molimo vas da unesete termin koji tek predstoji", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                String x = bingPathToAppDir(@"JsonFiles\appointments.json");
                AppointmentRepository apc = new AppointmentRepository(x);

                /*  List<DoctorAppointment> listaPregleda = apc.GetAll();
                 * foreach (DoctorAppointment dd in listaPregleda)
                 * {
                 *    DoctorUser dr = dd.doctor;
                 *    if (dr.id == drOvaj.id)
                 *    {
                 *        if (dd.Date.Equals(DatumBox.Text))
                 *        {
                 *            TimeSpan krajPr = dd.Time + new TimeSpan(0, 15, 0);
                 *            int result = TimeSpan.Compare(vremee, dd.Time);
                 *            int result1 = TimeSpan.Compare(vremee, krajPr);
                 *            if ((result == 1 && result1 == -1) || result == 0)
                 *            {
                 *                MessageBox.Show("Izvinjavamo se! Trazeni termin je vec zauzet!", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *                return;
                 *            }
                 *            int rezultat = TimeSpan.Compare(vremee2, dd.Time);
                 *            int rezultat1 = TimeSpan.Compare(vremee2, krajPr);
                 *            if ((rezultat == 1 && rezultat1 == -1) || rezultat == 0)
                 *            {
                 *
                 *                MessageBox.Show("Izvinjavamo se! Trazeni termin je vec zauzet!", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *                return;
                 *            }
                 *        }
                 *
                 *
                 *
                 *
                 *    }
                 * }*/
                /*String pre = bingPathToAppDir(@"JsonFiles\operations.json");
                 * OperationRepository apc1 = new OperationRepository(pre);
                 * List<Operation> listaPregleda1 = apc1.GetAll();
                 * foreach (Operation dd in listaPregleda1)
                 * {
                 *  DoctorUser dr = dd.isResponiable;
                 *  if (dr.id == drOvaj.id)
                 *  {
                 *      if (dd.Date.Equals(DatumBox.Text))
                 *      {
                 *          int result = TimeSpan.Compare(vremee, dd.Start);
                 *          int result1 = TimeSpan.Compare(vremee, dd.End);
                 *          if ((result == 1 && result1 == -1) || result == 0)
                 *          {
                 *
                 *              MessageBox.Show("Izvinjavamo se! Trazeni termin je vec zauzet!", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *              return;
                 *          }
                 *          int rezultat = TimeSpan.Compare(vremee2, dd.Start);
                 *          int rezultat1 = TimeSpan.Compare(vremee2, dd.End);
                 *          if ((rezultat == 1 && rezultat1 == -1) || rezultat == 0)
                 *          {
                 *
                 *              MessageBox.Show("Izvinjavamo se! Trazeni termin je vec zauzet!", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *              return;
                 *          }
                 *      }
                 *
                 *
                 *
                 *
                 *  }
                 * }*/



                OperationController opCon = new OperationController();

                bool zauzetTermin = opCon.isTermNotAvailable(drOvaj, vremee, vremee2, DatumBox.Text, ovajPacijent);
                if (zauzetTermin == true)
                {
                    MessageBox.Show("Trazeni termin nije dostupan.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);

                    return;
                }

                EmployeesScheduleController schCon         = new EmployeesScheduleController();
                List <Schedule>             listaRasporeda = schCon.GetAll();
                Shift smena = schCon.getShiftForDoctorForSpecificDay(DatumBox.Text, drOvaj);
                if (smena == null || smena.startTime == null || smena.endTime == null)
                {
                    MessageBox.Show("Trazeni termin nije dostupan.Lekar ne radi tog dana.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);

                    return;
                }

                bool slobodan = schCon.isDoctorWorkingAtSpecifiedTime(DatumBox.Text, drOvaj, vremee);
                if (slobodan == false)
                {
                    MessageBox.Show("Trazeni termin nije dostupan.Lekar ne radi u to vreme.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);

                    return;
                }


                String   pocetak       = smena.startTime;
                String   kraj          = smena.endTime;
                String[] deloviPocetak = pocetak.Split(':');
                String[] deloviKraj    = kraj.Split(':');

                TimeSpan pocetakTime = new TimeSpan(int.Parse(deloviPocetak[0]), int.Parse(deloviPocetak[1]), int.Parse("00"));
                TimeSpan krajTime    = new TimeSpan(int.Parse(deloviKraj[0]), int.Parse(deloviKraj[1]), int.Parse("00"));
                int      result3     = TimeSpan.Compare(vremee2, pocetakTime);
                int      result4     = TimeSpan.Compare(krajTime, vremee2);

                if (result3 != 1 || result4 != 1)
                {
                    MessageBox.Show("Trazeni termin nije dostupan.Lekar ne radi u to vreme.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);

                    return;
                }


                /* EmployeesScheduleController schCon = new EmployeesScheduleController();
                 * List<Schedule> listaRasporeda = schCon.GetAll();
                 * Shift smena = new Shift();
                 * foreach (Schedule s in listaRasporeda)
                 * {
                 *
                 *   if (s.employeeid.Equals(drOvaj.id.ToString()))
                 *   {
                 *       if (s.Date.Equals(DatumBox.Text))
                 *       {
                 *           smena = s.shift;
                 *       }
                 *   }
                 * }
                 * if (smena.StartTime == null || smena.EndTime == null)
                 * {
                 *   MessageBox.Show("Trazeni termin nije dostupan.Lekar ne radi tog dana.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *
                 *   return;
                 * }*/
                /* String pocetak = smena.StartTime;
                 * String kraj = smena.EndTime;
                 * String[] deloviPocetak = pocetak.Split(':');
                 * String[] deloviKraj = kraj.Split(':');
                 *
                 * TimeSpan pocetakTime = new TimeSpan(int.Parse(deloviPocetak[0]), int.Parse(deloviPocetak[1]), int.Parse("00"));
                 * TimeSpan krajTime = new TimeSpan(int.Parse(deloviKraj[0]), int.Parse(deloviKraj[1]), int.Parse("00"));
                 * int result3 = TimeSpan.Compare(vremee, pocetakTime);
                 * int result4 = TimeSpan.Compare(krajTime, vremee);
                 *
                 * if (result3 != 1 || result4 != 1)
                 * {
                 *   MessageBox.Show("Trazeni termin nije dostupan.Lekar ne radi u to vreme.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *
                 *   return;
                 *
                 * }*/


                opCon.New(null, op);
                PatientController  pCon      = new PatientController();
                List <PatientUser> pacijenti = pCon.GetAll();

                int                      id1           = 0;
                String                   ime           = "";
                String                   prezime       = "";
                String                   jmbg          = "";
                String                   datumRodj     = "";
                String                   brojTel       = "";
                String                   brKnj         = "";
                List <Question>          pitanja       = new List <Question>();
                String                   alergije      = "";
                String                   grad          = "";
                Boolean                  guest         = false;
                String                   email         = "";
                String                   password      = "";
                Boolean                  sekr          = false;
                List <ModelNotification> notifications = new List <ModelNotification>();
                //  foreach (PatientUser pat in lista)
                // {
                // if (pat.id.Equals(d.patient.id))
                // {
                id1       = op.patient.id;
                ime       = op.patient.firstName;
                prezime   = op.patient.secondName;
                jmbg      = op.patient.uniqueCitizensidentityNumber;
                datumRodj = op.patient.dateOfBirth;
                brojTel   = op.patient.phoneNumber;

                alergije      = op.patient.allergie;
                grad          = op.patient.city;
                email         = op.patient.email;
                guest         = op.patient.guest;
                password      = op.patient.password;
                sekr          = op.patient.isRegisteredBySecretary;
                notifications = op.patient.notifications;
                // }
                if (notifications == null)
                {
                    notifications = new List <ModelNotification>();
                }
                notifications.Add(new ModelNotification("Postovani, zakazana Vam je nova operacija datuma : " + op.date + " u " + op.start + " h, kod lekara " + op.isResponiable.firstName + " " + op.isResponiable.secondName + " Sala " + op.idRoom));

                PatientUser rp = new PatientUser(id1, ime, prezime, jmbg, datumRodj, brojTel, brKnj, alergije, grad, guest, email, password, sekr, notifications);



                pCon.Update(rp);


                Panel.Children.Clear();
                UserControl usc = new RezervisaniiTermini();
                Panel.Children.Add(usc);
            }
        }
Ejemplo n.º 11
0
        private void Zakazi_click(object sender, RoutedEventArgs e)
        {
            String b = bingPathToAppDir(@"JsonFiles\appointments.json");
            String c = bingPathToAppDir(@"JsonFiles\refferal.json");
            String d = bingPathToAppDir(@"JsonFiles\patients.json");
            String m = bingPathToAppDir(@"JsonFiles\doctors.json");


            PatientsRepository patientRepo  = new PatientsRepository(d);
            List <PatientUser> patientLista = patientRepo.GetAll();

            PatientUser ovajPacijent = new PatientUser();

            foreach (PatientUser r1 in patientLista)
            {
                if (r1.medicalIdNumber.Equals(KnjizicaBox.Text.ToString()))
                {
                    ovajPacijent     = r1;
                    KnjizicaBox.Text = r1.medicalIdNumber;
                }
            }



            DoctorRepository  docRepo = new DoctorRepository(m);
            List <DoctorUser> doktori = docRepo.GetAll();
            DoctorUser        drOvaj  = new DoctorUser();

            foreach (DoctorUser d1 in doktori)
            {
                if (d1.email.Equals(emailLekarBox.Text.ToString()))
                {
                    drOvaj = d1;
                }
            }



            String konacnoVreme = "";
            String vreme        = TimeText;

            Console.WriteLine(vreme);
            String[]      deliciVreme = vreme.Split(' ');
            String[]      satIminut   = deliciVreme[0].Split(':');
            String        sat         = satIminut[0];
            String        minut       = satIminut[1];
            String        kada        = deliciVreme[1];
            StringBuilder sb          = new StringBuilder();

            if (kada.Equals("AM"))
            {
                sb.Append(deliciVreme[0]);
                sb.Append(":00");
            }
            else
            {
                if (sat.Equals("1"))
                {
                    sb.Append("13:");
                    sb.Append(minut);
                    sb.Append(":00");
                }
                else if (sat.Equals("2"))
                {
                    sb.Append("14:");
                    sb.Append(minut);
                    sb.Append(":00");
                }
                else if (sat.Equals("3"))
                {
                    sb.Append("15:");
                    sb.Append(minut);
                    sb.Append(":00");
                }
                else if (sat.Equals("4"))
                {
                    sb.Append("16:");
                    sb.Append(minut);
                    sb.Append(":00");
                }
                else if (sat.Equals("5"))
                {
                    sb.Append("17:");
                    sb.Append(minut);
                    sb.Append(":00");
                }
                else if (sat.Equals("6"))
                {
                    sb.Append("18:");
                    sb.Append(minut);
                    sb.Append(":00");
                }
                else if (sat.Equals("7"))
                {
                    sb.Append("19:");
                    sb.Append(minut);
                    sb.Append(":00");
                }
                else if (sat.Equals("8"))
                {
                    sb.Append("20:");
                    sb.Append(minut);
                    sb.Append(":00");
                }
                else if (sat.Equals("9"))
                {
                    sb.Append("21:");
                    sb.Append(minut);
                    sb.Append(":00");
                }
                else if (sat.Equals("10"))
                {
                    sb.Append("22:");
                    sb.Append(minut);
                    sb.Append(":00");
                }
                else if (sat.Equals("11"))
                {
                    sb.Append("23:");
                    sb.Append(minut);
                    sb.Append(":00");
                }
                else
                {
                    sb.Append("00:");
                    sb.Append(minut);
                    sb.Append(":00");
                }
            }
            konacnoVreme = sb.ToString();
            Console.WriteLine(konacnoVreme);
            String[] zaTs        = konacnoVreme.Split(':');
            int      minutiVreme = int.Parse(zaTs[1]);
            TimeSpan ts          = new TimeSpan(int.Parse(zaTs[0]), minutiVreme, int.Parse(zaTs[2]));



            String konacnoVreme1 = "";
            String vreme1        = TimeText1;

            Console.WriteLine(vreme);
            String[]      deliciVreme1 = vreme1.Split(' ');
            String[]      satIminut1   = deliciVreme1[0].Split(':');
            String        sat1         = satIminut1[0];
            String        minut1       = satIminut1[1];
            String        kada1        = deliciVreme1[1];
            StringBuilder sb1          = new StringBuilder();

            if (kada1.Equals("AM"))
            {
                sb1.Append(deliciVreme1[0]);
                sb1.Append(":00");
            }
            else
            {
                if (sat1.Equals("1"))
                {
                    sb1.Append("13:");
                    sb1.Append(minut1);
                    sb1.Append(":00");
                }
                else if (sat1.Equals("2"))
                {
                    sb1.Append("14:");
                    sb1.Append(minut1);
                    sb1.Append(":00");
                }
                else if (sat1.Equals("3"))
                {
                    sb1.Append("15:");
                    sb1.Append(minut1);
                    sb1.Append(":00");
                }
                else if (sat1.Equals("4"))
                {
                    sb1.Append("16:");
                    sb1.Append(minut1);
                    sb1.Append(":00");
                }
                else if (sat1.Equals("5"))
                {
                    sb1.Append("17:");
                    sb1.Append(minut1);
                    sb1.Append(":00");
                }
                else if (sat1.Equals("6"))
                {
                    sb1.Append("18:");
                    sb1.Append(minut1);
                    sb1.Append(":00");
                }
                else if (sat1.Equals("7"))
                {
                    sb1.Append("19:");
                    sb1.Append(minut1);
                    sb1.Append(":00");
                }
                else if (sat1.Equals("8"))
                {
                    sb1.Append("20:");
                    sb1.Append(minut1);
                    sb1.Append(":00");
                }
                else if (sat1.Equals("9"))
                {
                    sb1.Append("21:");
                    sb1.Append(minut1);
                    sb1.Append(":00");
                }
                else if (sat1.Equals("10"))
                {
                    sb1.Append("22:");
                    sb1.Append(minut1);
                    sb1.Append(":00");
                }
                else if (sat1.Equals("11"))
                {
                    sb1.Append("23:");
                    sb1.Append(minut1);
                    sb1.Append(":00");
                }
                else
                {
                    sb1.Append("00:");
                    sb1.Append(minut1);
                    sb1.Append(":00");
                }
            }
            konacnoVreme1 = sb1.ToString();
            Console.WriteLine(konacnoVreme);
            Console.WriteLine(konacnoVreme1);
            String[] zaTs1        = konacnoVreme1.Split(':');
            int      minutiVreme1 = int.Parse(zaTs1[1]);
            TimeSpan ts1          = new TimeSpan(int.Parse(zaTs1[0]), minutiVreme1, int.Parse(zaTs1[2]));



            String[] deloviVreme = vreme.Split(':');
            //String[] deloviVreme2 = vreme2.Split(':');

// TimeSpan vremee = new TimeSpan(int.Parse(deloviVreme[0]), int.Parse(deloviVreme[1]), 0);
            //  TimeSpan vremee2 = new TimeSpan(int.Parse(deloviVreme2[0]), int.Parse(deloviVreme2[1]), 0);

            int broj = getNextid();

            DoctorAppointment drap = new DoctorAppointment(0, ts, DatumBox.Text.ToString(), ovajPacijent, drOvaj, null, ordinacijaBox.Text);

            AppointmentRepository    arepo  = new AppointmentRepository(b);
            List <DoctorAppointment> lista2 = new List <DoctorAppointment>();
            PatientController        regPat = new PatientController();
            List <PatientUser>       pac    = new List <PatientUser>();

            pac = regPat.GetAll();
            if (arepo.GetAll() != null)
            {
                lista2 = arepo.GetAll();
            }


            String    o     = bingPathToAppDir(@"JsonFiles\operations.json");
            int       broj1 = getNextid1();
            Operation op    = new Operation(0, ovajPacijent, DatumBox.Text.ToString(), ts, ts1, drOvaj, ordinacijaBox.Text, null);

            OperationRepository opRep  = new OperationRepository(o);
            List <Operation>    lista3 = new List <Operation>();

            if (opRep.GetAll() != null)
            {
                lista3 = opRep.GetAll();
            }

            if (pregled == true)
            {
                String   datum   = DatumBox.Text;
                String[] delovi2 = datum.Split('/');
                int      mesec   = int.Parse(delovi2[1]);
                int      dan     = int.Parse(delovi2[0]);
                int      godina  = int.Parse(delovi2[2]);

                DateTime dt1 = new DateTime(godina, mesec, dan, 0, 0, 0);

                DateTime dt2 = DateTime.Now;

                if (dt1 < dt2)
                {
                    MessageBox.Show("Molimo vas da unesete datum koji tek predstoji", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                String x = bingPathToAppDir(@"JsonFiles\appointments.json");
                AppointmentRepository    apc           = new AppointmentRepository(x);
                List <DoctorAppointment> listaPregleda = apc.GetAll();


                /* foreach (DoctorAppointment dd in listaPregleda)
                 * {
                 *   DoctorUser dr = dd.doctor;
                 *   if (dr.id == drOvaj.id)
                 *   {
                 *       if (dd.Date.Equals(DatumBox.Text))
                 *       {
                 *           TimeSpan krajPr = dd.Time + new TimeSpan(0, 15, 0);
                 *           int result = TimeSpan.Compare(vremee, dd.Time);
                 *           int result1 = TimeSpan.Compare(vremee, krajPr);
                 *           if ((result == 1 && result1 == -1) || result == 0)
                 *           {
                 *               MessageBox.Show("Izvinjavamo se! Trazeni termin je vec zauzet!", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *               return;
                 *           }
                 *       }
                 *
                 *
                 *
                 *
                 *   }
                 * }*/
                /*  String pre = bingPathToAppDir(@"JsonFiles\operations.json");
                 * OperationRepository apc1 = new OperationRepository(pre);
                 * List<Operation> listaPregleda1 = apc1.GetAll();
                 * foreach (Operation dd in listaPregleda1)
                 * {
                 *    DoctorUser dr = dd.isResponiable;
                 *    if (dr.id == drOvaj.id)
                 *    {
                 *        if (dd.Date.Equals(DatumBox.Text))
                 *        {
                 *            int result = TimeSpan.Compare(vremee, dd.Start);
                 *            int result1 = TimeSpan.Compare(vremee, dd.End);
                 *            if ((result == 1 && result1 == -1)||result==0 ||result1==0)
                 *            {
                 *
                 *                MessageBox.Show("Izvinjavamo se! Trazeni termin je vec zauzet!", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *                return;
                 *            }
                 *
                 *        }
                 *
                 *
                 *
                 *
                 *    }
                 * }*/



                EmployeesScheduleController schCon         = new EmployeesScheduleController();
                List <Schedule>             listaRasporeda = schCon.GetAll();
                Shift smena = schCon.getShiftForDoctorForSpecificDay(DatumBox.Text, drOvaj);
                if (smena == null || smena.startTime == null || smena.endTime == null)
                {
                    MessageBox.Show("Trazeni termin nije dostupan.Lekar ne radi tog dana.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);

                    return;
                }
                AppointmentController appointmentController = new AppointmentController();
                Boolean notAvaible = appointmentController.isTermNotAvailable(drOvaj, ts, DatumBox.Text, ovajPacijent);
                if (notAvaible == true)
                {
                    MessageBox.Show("Izvinjavamo se! Trazeni termin je vec zauzet!", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                /* foreach (Schedule s in listaRasporeda)
                 * {
                 *
                 *   if (s.employeeid.Equals(drOvaj.id.ToString()))
                 *   {
                 *       if (s.Date.Equals(DatumBox.Text))
                 *       {
                 *           smena = s.shift;
                 *       }
                 *   }
                 * }
                 * if(smena.StartTime==null || smena.EndTime == null)
                 * {
                 *
                 * }*/

                bool slobodan = schCon.isDoctorWorkingAtSpecifiedTime(DatumBox.Text, drOvaj, ts);
                if (slobodan == false)
                {
                    MessageBox.Show("Trazeni termin nije dostupan.Lekar ne radi u to vreme.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);

                    return;
                }

                /* String pocetak = smena.StartTime;
                 * String kraj = smena.EndTime;
                 * String[] deloviPocetak = pocetak.Split(':');
                 * String[] deloviKraj = kraj.Split(':');
                 *
                 * TimeSpan pocetakTime = new TimeSpan(int.Parse(deloviPocetak[0]), int.Parse(deloviPocetak[1]), 0);
                 * TimeSpan krajTime = new TimeSpan(int.Parse(deloviKraj[0]), int.Parse(deloviKraj[1]), 0);
                 * int result3 = TimeSpan.Compare(vremee, pocetakTime);
                 * int result4 = TimeSpan.Compare(krajTime, vremee);
                 *
                 * if (result3 != 1 || result4 != 1)
                 * {
                 *   MessageBox.Show("Trazeni termin nije dostupan.Lekar ne radi u to vreme.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *
                 *   return;
                 *
                 * }*/


                AppointmentController apCon = new AppointmentController();
                apCon.New(drap, null);
                int             id1       = 0;
                String          ime       = "";
                String          prezime   = "";
                String          jmbg      = "";
                String          datumRodj = "";
                String          brojTel   = "";
                String          brKnj     = "";
                List <Question> pitanja   = new List <Question>();
                String          alergije  = "";
                String          grad      = "";
                Boolean         guest     = false;
                String          email     = "";
                String          password  = "";
                Boolean         sekr      = false;

                //  foreach (PatientUser pat in lista)
                // {
                // if (pat.id.Equals(d.patient.id))
                // {
                id1       = drap.patient.id;
                ime       = drap.patient.firstName;
                prezime   = drap.patient.secondName;
                jmbg      = drap.patient.uniqueCitizensidentityNumber;
                datumRodj = drap.patient.dateOfBirth;
                brKnj     = drap.patient.medicalIdNumber;
                brojTel   = drap.patient.phoneNumber;

                alergije = drap.patient.allergie;
                grad     = drap.patient.city;
                email    = drap.patient.email;
                guest    = drap.patient.guest;
                password = drap.patient.password;
                sekr     = drap.patient.isRegisteredBySecretary;
                if (drap.patient.notifications == null)
                {
                    drap.patient.notifications = new List <ModelNotification>();
                }
                List <ModelNotification> notifications = drap.patient.notifications;
                // }

                notifications.Add(new ModelNotification("Postovani, zakazana vam je novi pregled datuma : " + drap.date + " u " + drap.time + " h kod lekara " + drap.doctor.firstName + " " + drap.doctor.secondName + ". Ordinacija: " + drap.roomid));
                drap.patient.notifications = notifications;
                // PatientUser rp = new PatientUser(id1, ime, prezime, jmbg, datumRodj, brojTel, brKnj, pitanja, alergije, grad, guest, email, password, sekr, notifications);


                PatientController pCon = new PatientController();
                pCon.Update(drap.patient);
                Panel.Children.Clear();
                UserControl usc = new PopunjeniTermini();
                Panel.Children.Add(usc);
            }
            else if (operacija == true)
            {
                String   datum   = DatumBox.Text;
                String[] delovi2 = datum.Split('/');
                int      mesec   = int.Parse(delovi2[1]);
                int      dan     = int.Parse(delovi2[0]);
                int      godina  = int.Parse(delovi2[2]);

                DateTime dt1 = new DateTime(godina, mesec, dan, 0, 0, 0);

                DateTime dt2 = DateTime.Now;

                if (dt2 > dt1)
                {
                    MessageBox.Show("Molimo vas da unesete termin koji tek predstoji", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                String x = bingPathToAppDir(@"JsonFiles\appointments.json");
                AppointmentRepository apc = new AppointmentRepository(x);

                /*  List<DoctorAppointment> listaPregleda = apc.GetAll();
                 * foreach (DoctorAppointment dd in listaPregleda)
                 * {
                 *    DoctorUser dr = dd.doctor;
                 *    if (dr.id == drOvaj.id)
                 *    {
                 *        if (dd.Date.Equals(DatumBox.Text))
                 *        {
                 *            TimeSpan krajPr = dd.Time + new TimeSpan(0, 15, 0);
                 *            int result = TimeSpan.Compare(vremee, dd.Time);
                 *            int result1 = TimeSpan.Compare(vremee, krajPr);
                 *            if ((result == 1 && result1 == -1) || result == 0)
                 *            {
                 *                MessageBox.Show("Izvinjavamo se! Trazeni termin je vec zauzet!", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *                return;
                 *            }
                 *            int rezultat = TimeSpan.Compare(vremee2, dd.Time);
                 *            int rezultat1 = TimeSpan.Compare(vremee2, krajPr);
                 *            if ((rezultat == 1 && rezultat1 == -1) || rezultat == 0)
                 *            {
                 *
                 *                MessageBox.Show("Izvinjavamo se! Trazeni termin je vec zauzet!", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *                return;
                 *            }
                 *        }
                 *
                 *
                 *
                 *
                 *    }
                 * }*/
                /*String pre = bingPathToAppDir(@"JsonFiles\operations.json");
                 * OperationRepository apc1 = new OperationRepository(pre);
                 * List<Operation> listaPregleda1 = apc1.GetAll();
                 * foreach (Operation dd in listaPregleda1)
                 * {
                 *  DoctorUser dr = dd.isResponiable;
                 *  if (dr.id == drOvaj.id)
                 *  {
                 *      if (dd.Date.Equals(DatumBox.Text))
                 *      {
                 *          int result = TimeSpan.Compare(vremee, dd.Start);
                 *          int result1 = TimeSpan.Compare(vremee, dd.End);
                 *          if ((result == 1 && result1 == -1) || result == 0)
                 *          {
                 *
                 *              MessageBox.Show("Izvinjavamo se! Trazeni termin je vec zauzet!", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *              return;
                 *          }
                 *          int rezultat = TimeSpan.Compare(vremee2, dd.Start);
                 *          int rezultat1 = TimeSpan.Compare(vremee2, dd.End);
                 *          if ((rezultat == 1 && rezultat1 == -1) || rezultat == 0)
                 *          {
                 *
                 *              MessageBox.Show("Izvinjavamo se! Trazeni termin je vec zauzet!", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *              return;
                 *          }
                 *      }
                 *
                 *
                 *
                 *
                 *  }
                 * }*/



                OperationController opCon = new OperationController();

                bool zauzetTermin = opCon.isTermNotAvailable(drOvaj, ts, ts1, DatumBox.Text, ovajPacijent);
                if (zauzetTermin == true)
                {
                    MessageBox.Show("Trazeni termin nije dostupan.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);

                    return;
                }

                EmployeesScheduleController schCon         = new EmployeesScheduleController();
                List <Schedule>             listaRasporeda = schCon.GetAll();
                Shift smena = schCon.getShiftForDoctorForSpecificDay(DatumBox.Text, drOvaj);
                if (smena == null || smena.startTime == null || smena.endTime == null)
                {
                    MessageBox.Show("Trazeni termin nije dostupan.Lekar ne radi tog dana.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);

                    return;
                }

                bool slobodan = schCon.isDoctorWorkingAtSpecifiedTime(DatumBox.Text, drOvaj, ts);
                if (slobodan == false)
                {
                    MessageBox.Show("Trazeni termin nije dostupan.Lekar ne radi u to vreme.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);

                    return;
                }


                int ispravno = TimeSpan.Compare(ts1, ts);
                if (ispravno == -1 || ispravno == 0)
                {
                    MessageBox.Show("Operacija mora imati trajanje!", "Greska", MessageBoxButton.OK);
                    return;
                }

                /*  String pocetak = smena.StartTime;
                 * String kraj = smena.EndTime;
                 * String[] deloviPocetak = pocetak.Split(':');
                 * String[] deloviKraj = kraj.Split(':');
                 *
                 * TimeSpan pocetakTime = new TimeSpan(int.Parse(deloviPocetak[0]), int.Parse(deloviPocetak[1]), int.Parse("00"));
                 * TimeSpan krajTime = new TimeSpan(int.Parse(deloviKraj[0]), int.Parse(deloviKraj[1]), int.Parse("00"));
                 * int result3 = TimeSpan.Compare(vremee2, pocetakTime);
                 * int result4 = TimeSpan.Compare(krajTime, vremee2);
                 *
                 * if (result3 != 1 || result4 != 1)
                 * {
                 *    MessageBox.Show("Trazeni termin nije dostupan.Lekar ne radi u to vreme.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *
                 *    return;
                 *
                 * }*/

                /* EmployeesScheduleController schCon = new EmployeesScheduleController();
                 * List<Schedule> listaRasporeda = schCon.GetAll();
                 * Shift smena = new Shift();
                 * foreach (Schedule s in listaRasporeda)
                 * {
                 *
                 *   if (s.employeeid.Equals(drOvaj.id.ToString()))
                 *   {
                 *       if (s.Date.Equals(DatumBox.Text))
                 *       {
                 *           smena = s.shift;
                 *       }
                 *   }
                 * }
                 * if (smena.StartTime == null || smena.EndTime == null)
                 * {
                 *   MessageBox.Show("Trazeni termin nije dostupan.Lekar ne radi tog dana.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *
                 *   return;
                 * }*/
                /* String pocetak = smena.StartTime;
                 * String kraj = smena.EndTime;
                 * String[] deloviPocetak = pocetak.Split(':');
                 * String[] deloviKraj = kraj.Split(':');
                 *
                 * TimeSpan pocetakTime = new TimeSpan(int.Parse(deloviPocetak[0]), int.Parse(deloviPocetak[1]), int.Parse("00"));
                 * TimeSpan krajTime = new TimeSpan(int.Parse(deloviKraj[0]), int.Parse(deloviKraj[1]), int.Parse("00"));
                 * int result3 = TimeSpan.Compare(vremee, pocetakTime);
                 * int result4 = TimeSpan.Compare(krajTime, vremee);
                 *
                 * if (result3 != 1 || result4 != 1)
                 * {
                 *   MessageBox.Show("Trazeni termin nije dostupan.Lekar ne radi u to vreme.", "Greska", MessageBoxButton.OK, MessageBoxImage.Error);
                 *
                 *   return;
                 *
                 * }*/


                opCon.New(null, op);
                PatientController  pCon      = new PatientController();
                List <PatientUser> pacijenti = pCon.GetAll();

                int             id1       = 0;
                String          ime       = "";
                String          prezime   = "";
                String          jmbg      = "";
                String          datumRodj = "";
                String          brojTel   = "";
                String          brKnj     = "";
                List <Question> pitanja   = new List <Question>();
                String          alergije  = "";
                String          grad      = "";
                Boolean         guest     = false;
                String          email     = "";
                String          password  = "";
                Boolean         sekr      = false;
                // List<String> notifications = new List<String>();
                //  foreach (PatientUser pat in lista)
                // {
                // if (pat.id.Equals(d.patient.id))
                // {
                id1       = op.patient.id;
                ime       = op.patient.firstName;
                prezime   = op.patient.secondName;
                jmbg      = op.patient.uniqueCitizensidentityNumber;
                datumRodj = op.patient.dateOfBirth;
                brojTel   = op.patient.phoneNumber;

                alergije = op.patient.allergie;
                grad     = op.patient.city;
                email    = op.patient.email;
                guest    = op.patient.guest;
                password = op.patient.password;
                sekr     = op.patient.isRegisteredBySecretary;

                // }



                // PatientUser rp = new PatientUser(id1, ime, prezime, jmbg, datumRodj, brojTel, brKnj, pitanja, alergije, grad, guest, email, password, sekr, notifications);

                if (op.patient.notifications == null)
                {
                    op.patient.notifications = new List <ModelNotification>();
                }
                List <ModelNotification> notifications = drap.patient.notifications;
                // }
                notifications.Add(new ModelNotification("Postovani, zakazana Vam je nova operacija datuma : " + op.date + " u " + op.start + " h, kod lekara " + op.isResponiable.firstName + " " + op.isResponiable.secondName + " Sala " + op.idRoom));

                op.patient.notifications = notifications;


                pCon.Update(op.patient);


                Panel.Children.Clear();
                UserControl usc = new PopunjeniTermini();
                Panel.Children.Add(usc);
            }
        }
Ejemplo n.º 12
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Lista  ss    = (Lista)dataGridTermini.Items.GetItemAt(dataGridTermini.SelectedIndex);
            string name1 = sender.ToString();

            string[] words = name1.Split(':');

            string[] words1 = name1.Split(' ');
            string   id     = words1[2];


            string sMessageBoxText = "Da li ste sigurni da zelite da otkazete ovaj termin?" + id;
            string sCaption        = "Otkazivanje termina.";

            MessageBoxButton btnMessageBox  = MessageBoxButton.YesNoCancel;
            MessageBoxImage  icnMessageBox  = MessageBoxImage.Warning;
            MessageBoxResult rsltMessageBox = MessageBox.Show(sMessageBoxText, sCaption, btnMessageBox, icnMessageBox);

            switch (rsltMessageBox)
            {
            case MessageBoxResult.Yes:
                PatientUser ovajPacijent = new PatientUser();

                String o = bingPathToAppDir(@"JsonFiles\operations.json");
                String b = bingPathToAppDir(@"JsonFiles\appointments.json");

                AppointmentList = new List <DoctorAppointment>();
                operationList   = new List <Operation>();

                OperationRepository   oprep = new OperationRepository(o);
                AppointmentRepository epr   = new AppointmentRepository(b);
                operationList   = oprep.GetAll();
                AppointmentList = epr.GetAll();


                foreach (DoctorAppointment d in AppointmentList)
                {
                    if (d.id.ToString().Equals(id) && ss.Pregled == true)
                    {
                        Console.WriteLine(id);
                        AppointmentList.Remove(d);
                        //patientController.update(ovajPacijent);
                        epr.Delete(d.id);
                        PatientController patContr = new PatientController();


                        if (d.patient.notifications == null)
                        {
                            d.patient.notifications = new List <ModelNotification>();
                        }
                        List <ModelNotification> notifications1 = d.patient.notifications;
                        // }

                        notifications1.Add(new ModelNotification("Postovani, pregled zakazan za datum: " + d.date + " i vreme " + d.time + " je otkazan."));
                        d.patient.notifications = notifications1;



                        PatientController pCon = new PatientController();
                        pCon.Update(d.patient);

                        if (d.doctor.specialNotifications == null)
                        {
                            d.doctor.specialNotifications = new List <DoctorNotification>();
                        }
                        List <DoctorNotification> obavestenja = d.doctor.specialNotifications;
                        obavestenja.Add(new DoctorNotification("Postovani, pregled zakazan za datum: " + d.date + " i vreme " + d.time + " je otkazan."));
                        d.doctor.specialNotifications = obavestenja;



                        DoctorController docContr1 = new DoctorController();

                        docContr1.Update(d.doctor);
                        var s = new PopunjeniTermini();
                        Panel.Children.Clear();
                        Panel.Children.Add(s);

                        break;
                    }
                }

                foreach (Operation d in operationList)
                {
                    if (d.id.ToString().Equals(id) && ss.Operacija == true)
                    {
                        operationList.Remove(d);
                        oprep.Delete(d.id);

                        if (d.patient.notifications == null)
                        {
                            d.patient.notifications = new List <ModelNotification>();
                        }
                        List <ModelNotification> notifications1 = d.patient.notifications;


                        notifications1.Add(new ModelNotification("Postovani, operacija zakazana za datum: " + d.date + " i vreme " + d.start + " je otkazana."));
                        d.patient.notifications = notifications1;



                        PatientController pCon = new PatientController();
                        pCon.Update(d.patient);



                        if (d.isResponiable.specialNotifications == null)
                        {
                            d.isResponiable.specialNotifications = new List <DoctorNotification>();
                        }
                        List <DoctorNotification> obavestenja = d.isResponiable.specialNotifications;
                        obavestenja.Add(new DoctorNotification("Postovani,operacija zakazana za datum: " + d.date + " i vreme " + d.start + " je otkazana."));
                        d.isResponiable.specialNotifications = obavestenja;



                        DoctorController docContr1 = new DoctorController();

                        docContr1.Update(d.isResponiable);
                        var s = new PopunjeniTermini();
                        Panel.Children.Clear();
                        Panel.Children.Add(s);
                        break;
                    }
                }


                break;


            case MessageBoxResult.No:

                break;

            case MessageBoxResult.Cancel:

                break;
            }
        }