Ejemplo n.º 1
0
        [ValidateAntiForgeryToken] // Skyddar mot CSRF attack ( Cross-site Request Forgery )
        public ActionResult Save(Patient patient)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new PatientFormViewModel(patient)
                {
                    MembershipTypes = _context.MembershipTypes.ToList()
                };

                return(View("PatientForm", viewModel));
            }
            if (patient.Id == 0)
            {
                _context.Patients.Add(patient);
            }
            else
            {
                var patientInDb = _context.Patients.Single(c => c.Id == patient.Id);

                patientInDb.Name                     = patient.Name;
                patientInDb.Birthdate                = patient.Birthdate;
                patientInDb.Journal                  = patient.Journal;
                patientInDb.MembershipTypeId         = patient.MembershipTypeId;
                patientInDb.IsSubscirbedToNewsletter = patient.IsSubscirbedToNewsletter;
            }

            _context.SaveChanges();


            return(RedirectToAction("Index", "Patients"));
        }
        public ActionResult Update(PatientFormViewModel patientModel)
        {
            if (patientModel.DateOfBirth.GetCurrentAge() < 18)
            {
                ModelState.AddModelError("Age", "Patient is  not adult!");
            }
            if (!ModelState.IsValid)
            {
                return(View("PatientFormView", patientModel));
            }

            var patient = db.Patients.FirstOrDefault(p => p.Id == patientModel.Id);

            if (patient == null)
            {
                return(HttpNotFound());
            }

            patient.Name            = patientModel.Name;
            patient.Weight          = patientModel.Weight;
            patient.Height          = patientModel.Height;
            patient.DateOfBirth     = patientModel.DateOfBirth;
            patient.BmiCategory     = patientModel.BmiCategory;
            db.Entry(patient).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public void Validate_Pass()
        {
            patient.Name = "Feri";
            var patientFVM = new PatientFormViewModel(patient);

            Assert.IsTrue(patientFVM.PatientValidate());
        }
Ejemplo n.º 4
0
        public ActionResult AddPatient(PatientFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Cities  = _unitofWork.Cities.GetCities();
                viewModel.Heading = "New Patient";

                return(View(viewModel));
            }
            var patient = new Patient()
            {
                Name      = viewModel.Name,
                Address   = viewModel.Address,
                BirthDate = viewModel.GetBirthDate(),
                CityId    = viewModel.City,
                DateTime  = DateTime.Now,
                Sex       = viewModel.Sex,
                DStatus   = true,
                Phone     = viewModel.Phone,
                Height    = viewModel.Height,
                Weight    = viewModel.Weight,
                Token     = DateTime.Now.ToString("ddMMyyyy") + new Random(1000).Next(1000).ToString()
            };

            _unitofWork.Patients.Add(patient);
            _unitofWork.Complete();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public ActionResult Create(PatientFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Cities = _unitOfWork.Cities.GetCities();
                return(View("PatientForm", viewModel));
            }

            var patient = new Patient
            {
                Name      = viewModel.Name,
                Phone     = viewModel.Phone,
                Address   = viewModel.Address,
                DateTime  = DateTime.Now,
                BirthDate = viewModel.GetBirthDate(),
                Height    = viewModel.Height,
                Weight    = viewModel.Weight,
                CityId    = viewModel.City,
                Sex       = viewModel.Sex,
                Token     = (2018 + _unitOfWork.Patients.GetPatients().Count()).ToString().PadLeft(7, '0')
            };

            _unitOfWork.Patients.Add(patient);
            _unitOfWork.Complete();
            return(RedirectToAction("Index", "Patients"));

            // TODO: BUG redirect to detail
            //return RedirectToAction("Details", new { id = viewModel.Id });
        }
Ejemplo n.º 6
0
        public ActionResult Update(PatientFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Cities = _unitOfWork.Cities.GetCities();
                return(View("PatientForm", viewModel));
            }


            var patientInDb = _unitOfWork.Patients.GetPatient(viewModel.Id);

            patientInDb.Id        = viewModel.Id;
            patientInDb.Name      = viewModel.Name;
            patientInDb.Phone     = viewModel.Phone;
            patientInDb.BirthDate = viewModel.GetBirthDate();
            patientInDb.Address   = viewModel.Address;
            patientInDb.Height    = viewModel.Height;
            patientInDb.Weight    = viewModel.Weight;
            patientInDb.Sex       = viewModel.Sex;
            patientInDb.CityId    = viewModel.City;

            _unitOfWork.Complete();
            return(RedirectToAction("Index", "Patients")
                   );
        }
Ejemplo n.º 7
0
        public ActionResult Save(Patient patient)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new PatientFormViewModel
                {
                    Patient = patient,
                    Genders = _context.Genders.ToList()
                };
                return(View("New", viewModel));
            }
            if (patient.PatientId == 0)
            {
                _context.Patients.Add(patient);
            }

            else
            {
                var patientInDb = _context.Patients.Single(p => p.PatientId == patient.PatientId);

                patientInDb.PatientFirstName = patient.PatientFirstName;
                patientInDb.PatientSurname   = patient.PatientSurname;
                patientInDb.Address1         = patient.Address1;
                patientInDb.Address2         = patient.Address2;
                patientInDb.PostCode         = patient.PostCode;
                patientInDb.DOB      = patient.DOB;
                patientInDb.GenderId = patient.GenderId;
            }
            _context.SaveChanges();

            return(RedirectToAction("Index", "Patient"));
        }
Ejemplo n.º 8
0
        public ActionResult Save(PatientOccupancy patientOccupancy)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new PatientFormViewModel
                {
                    PatientOccupancy = patientOccupancy,
                    Patients         = _context.Patients.ToList(),
                    Wards            = _context.Wards.ToList(),
                    Beds             = _context.Beds.ToList()
                };
                return(View("New", viewModel));
            }

            if (patientOccupancy.Id == 0)
            {
                _context.PatientOccupancies.Add(patientOccupancy);
            }

            else
            {
                var occupancyInDb = _context.PatientOccupancies.Single(p => p.Id == patientOccupancy.Id);
                var bedInDb       = _context.Beds.Single(p => p.BedId == patientOccupancy.BedId);

                occupancyInDb.PatientId     = patientOccupancy.PatientId;
                occupancyInDb.DateAdmitted  = patientOccupancy.DateAdmitted;
                occupancyInDb.WardId        = patientOccupancy.WardId;
                occupancyInDb.BedId         = patientOccupancy.BedId;
                occupancyInDb.DischargeDate = patientOccupancy.DischargeDate;
                bedInDb.IsAvailable         = false;
            }
            _context.SaveChanges();

            return(RedirectToAction("Index", "PatientOccupancy"));
        }
        // GET: Patients/Create
        public ActionResult Create()
        {
            var patientModel = new PatientFormViewModel {
                Heading = "Add a patient"
            };

            return(View("PatientFormView", patientModel));
        }
Ejemplo n.º 10
0
        public ActionResult Create()
        {
            var viewModel = new PatientFormViewModel
            {
                Cities  = _unitOfWork.Cities.GetCities(),
                Heading = "New Patient"
            };

            return(View("PatientForm", viewModel));
        }
Ejemplo n.º 11
0
        public ActionResult New()
        {
            var membershiptypes = _context.MembershipTypes.ToList();
            var viewModel       = new PatientFormViewModel
            {
                MembershipTypes = membershiptypes
            };

            return(View("PatientForm", viewModel));
        }
Ejemplo n.º 12
0
        public ActionResult New()
        {
            var gender = _context.Genders.ToList();

            var viewModel = new PatientFormViewModel
            {
                Patient = new Patient(),
                Genders = gender
            };

            return(View("New", viewModel));
        }
Ejemplo n.º 13
0
        public void NewPatientTestRight()
        {
            var pfvm = new PatientFormViewModel();

            pfvm.Patient           = new Patient();
            pfvm.Patient.TAJ       = "123456789";
            pfvm.Patient.Name      = "Tatai Sándor";
            pfvm.Patient.BornPlace = "Budapest";
            bool result = pfvm.Validate();

            Assert.IsTrue(result);
        }
Ejemplo n.º 14
0
        public void NewPatientTestWrong()
        {
            var pfvm = new PatientFormViewModel();

            pfvm.Patient      = new Patient();
            pfvm.Patient.TAJ  = "1";
            pfvm.Patient.Name = "x";
            pfvm.Patient.Born = "x";
            bool result = pfvm.Validate();

            Assert.IsFalse(result);
        }
        /// <summary>
        /// GET: /Patients/Register
        /// </summary>
        /// <returns></returns>
        public ActionResult Register()
        {
            var bloodGroups = _context.BloodGroups.ToList();
            var genders     = _context.Genders.ToList();
            var viewModel   = new PatientFormViewModel()
            {
                Patients    = new Patient(),
                Genders     = genders,
                BloodGroups = bloodGroups
            };

            return(View("PatientForm", viewModel));
        }
Ejemplo n.º 16
0
        public ActionResult New()
        {
            var patient = new Patient();

            patient.Id = GenerateUniqueID();

            var viewModel = new PatientFormViewModel
            {
                patient   = patient,
                Detection = _spec.GetRecords
            };

            return(View("PatientForm", viewModel));
        }
Ejemplo n.º 17
0
        public ActionResult New()
        {
            var membershipTypes = _context.MembershipTypes.ToList();
            var viewModel       = new PatientFormViewModel
            {
                Patient = new PatientMaster
                {
                    AddressMaster = new AddressMaster()
                },
                MembershipTypes = membershipTypes
            };

            return(View("PatientForm", viewModel));
        }
Ejemplo n.º 18
0
        public ActionResult Edit(int id)
        {
            var patient = _context.Patients.SingleOrDefault(c => c.Id == id);

            if (patient == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new PatientFormViewModel(patient)
            {
                MembershipTypes = _context.MembershipTypes.ToList()
            };

            return(View("PatientForm", viewModel));
        }
Ejemplo n.º 19
0
        public ActionResult Create()
        {
            var patient = _context.Patients.ToList();
            var ward    = _context.Wards.ToList();
            var bed     = _context.Beds.ToList();

            var viewModel = new PatientFormViewModel
            {
                PatientOccupancy = new PatientOccupancy(),
                Patients         = patient,
                Wards            = ward,
                Beds             = bed
            };

            return(View("Create", viewModel));
        }
Ejemplo n.º 20
0
        //New Patient Action
        public ActionResult New()
        {
            //Get List of membership types
            var patients = _context.Patients.ToList();
            //var triageLevel = _context.TriageLevels.ToList();
            //var triageType = _context.TriageType.ToList();

            var viewModel = new PatientFormViewModel
            {
                //add Patient details to the ViewModel
                Patient = new Patient(),
                //TriageLevel = triageLevel
            };

            return(View("PatientForm", viewModel));
        }
Ejemplo n.º 21
0
        [ValidateAntiForgeryToken] //Use this along with the Html Anti forgery helper on the View
        public ActionResult Save(PatientFormViewModel formViewModel)
        {
            if (!ModelState.IsValid)//Use Model State when implementing validation.  You can use ModelState to chnage the flow of the application.
            {
                var viewModel = new PatientFormViewModel
                {
                    Patient = formViewModel.Patient
                };
                return(View("PatientForm", viewModel));
            }

            if (formViewModel.Patient.Id == Guid.Empty)
            {
                //if creating new patient if does not exist, need to create new patient record
                var patientRecord = new PatientRecord();

                //need to add PatientRecordID to new patient object
                formViewModel.Patient.PatientRecordId = patientRecord.Id;

                //Write the new patient data to the database
                _context.Patients.Add(formViewModel.Patient);
                _context.PatientRecords.Add(patientRecord);

                _context.SaveChanges();

                //Get New PaientId to pass to PatientRecords
                var patientId = formViewModel.Patient.PatientRecordId;

                return(RedirectToAction("Edit", "PatientRecords", new { id = patientId }));
            }
            else
            {
                //Patient exists - updating records
                var patientInDb = _context.Patients.Single(c => c.Id == formViewModel.Patient.Id);

                //Mapper.Map(customer, customerInDB)
                patientInDb.Name         = formViewModel.Patient.Name;
                patientInDb.DateOfBirth  = formViewModel.Patient.DateOfBirth;
                patientInDb.HasInsuracne = formViewModel.Patient.HasInsuracne;
                //patientInDb.TriageLevelId = formViewModel.Patient.TriageLevelId;

                _context.SaveChanges();

                return(RedirectToAction("Index", "Patients"));
            }
        }
        /// <summary>
        /// Patients/Edit
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Edit(int id)
        {
            var patient = _context.Patients.SingleOrDefault(p => p.Id == id);

            if (patient == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new PatientFormViewModel()
            {
                Patients    = patient,
                Genders     = _context.Genders.ToList(),
                BloodGroups = _context.BloodGroups.ToList()
            };

            return(View("PatientForm", viewModel));
        }
Ejemplo n.º 23
0
        public ActionResult Edit(string id)
        {
            var patient = _context.LoadRecordByIdProperity <Patient>(_table, id);

            if (patient == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new PatientFormViewModel
            {
                patient   = patient,
                Detection = _spec.GetRecords
            };

            return(View("PatientForm", viewModel));
        }
        public ActionResult Create([Bind(Include = "Name,Height,Weight,DateOfBirth")] PatientFormViewModel patientModel)
        {
            if (patientModel.DateOfBirth.GetCurrentAge() < 18)
            {
                ModelState.AddModelError("Age", "Patient is  not adult!");
            }

            if (!ModelState.IsValid)
            {
                return(View("PatientFormView", patientModel));
            }

            var patient = Mapper.Map <Patient>(patientModel);

            db.Patients.Add(patient);
            db.SaveChanges();
            return(RedirectToAction("Report"));
        }
Ejemplo n.º 25
0
        public ActionResult Edit(int id)
        {
            var patient = _context.PatientOccupancies.SingleOrDefault(p => p.Id == id);

            if (patient == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new PatientFormViewModel
            {
                PatientOccupancy = patient,
                Patients         = _context.Patients.ToList(),
                Wards            = _context.Wards.ToList(),
                Beds             = _context.Beds.ToList()
            };

            return(View("Create", viewModel));
        }
Ejemplo n.º 26
0
        //Edit Patient
        public ActionResult Edit(Guid id)
        {
            var patient = _context.Patients.SingleOrDefault(p => p.Id == id);

            //var triageLevel = _context.TriageLevels.ToList();

            if (patient == null)
            {
                return(HttpNotFound());
            }
            else
            {
                var viewModel = new PatientFormViewModel
                {
                    Patient = patient,
                    //TriageLevel = triageLevel
                };
                return(View("PatientForm", viewModel));
            }
        }
Ejemplo n.º 27
0
        public ActionResult Details(int id)
        {
            var patient      = _context.Patients.Include(p => p.Gender).SingleOrDefault(p => p.PatientId == id);
            var occupancy    = _context.PatientOccupancies.Include(p => p.Patient).Include(p => p.Ward).Include(p => p.Bed).SingleOrDefault(p => p.PatientId == id);
            var prescription = _context.Prescriptions.Include(p => p.Drug).SingleOrDefault(p => p.PatientId == id);

            if (patient == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new PatientFormViewModel
            {
                Patient          = patient,
                PatientOccupancy = occupancy,
                Prescription     = prescription
            };

            return(View(viewModel));
        }
        /// <summary>
        /// GET: /Patients/Details
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Details(int id)
        {
            var patient = _context.Patients
                          .Include(p => p.Gender)
                          .Include(p => p.BloodGroup)
                          .SingleOrDefault(p => p.Id == id);

            if (patient == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new PatientFormViewModel
            {
                Patients    = patient,
                Genders     = _context.Genders.ToList(),
                BloodGroups = _context.BloodGroups.ToList()
            };

            return(View(viewModel));
        }
        public IActionResult Create(PatientFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Cities = _unitOfWork.Cities.GetCities();
                return(View("PatientForm", viewModel));
            }
            var user    = userManager.Users.FirstOrDefault(x => x.Email == User.Identity.Name);
            var patient = new Patient
            {
                Name      = User.Identity.Name,
                Phone     = viewModel.Phone,
                Address   = viewModel.Address,
                DateTime  = DateTime.Now,
                BirthDate = viewModel.GetBirthDate(),
                Height    = viewModel.Height,
                Weight    = viewModel.Weight,
                CityId    = viewModel.City,
                Sex       = viewModel.Sex,
                Token     = (2018 + _unitOfWork.Patients.GetPatients().Count()).ToString().PadLeft(7, '0'),
                UserId    = user.Id
            };

            //var userU = new ApplicationUser
            //{
            //    PhoneNumber = viewModel.Phone

            //};

            // var result = userManager.cre(userU);

            _unitOfWork.Patients.Add(patient);
            _unitOfWork.Complete();
            return(RedirectToAction("Index", "Account"));

            // TODO: BUG redirect to detail
            //return RedirectToAction("Details", new { id = viewModel.Id });
        }
Ejemplo n.º 30
0
        public ActionResult Edit(int id)
        {
            var patient = _unitOfWork.Patients.GetPatient(id);

            var viewModel = new PatientFormViewModel
            {
                Heading = "Edit Patient",
                Id      = patient.Id,
                Name    = patient.Name,
                Phone   = patient.Phone,
                Date    = patient.DateTime,
                //Date = patient.DateTime.ToString("d MMM yyyy"),
                BirthDate = patient.BirthDate.ToString("dd/MM/yyyy"),
                Address   = patient.Address,
                Height    = patient.Height,
                Weight    = patient.Weight,
                Sex       = patient.Sex,
                City      = patient.CityId,
                Cities    = _unitOfWork.Cities.GetCities()
            };

            return(View("PatientForm", viewModel));
        }