public IActionResult Add(Consultation consultation)
        {
            try
            {
                ViewBag.PatientId = consultation.PatientId;
                if (consultation == null)
                {
                    logger.LogError($"При добавлении консультации пациенту с id {consultation.PatientId} произошла ошибка связывания модели.");
                    return(View("Error",
                                new ErrorViewModel
                    {
                        Message = $"При добавлении консультации пациенту с id {consultation.PatientId}" +
                                  $" произошла ошибка связывания модели."
                    }));
                }
                var patient = patientContext.Patients.
                              FromSqlRaw($"SELECT * FROM PATIENTS WHERE PatientId = { consultation.PatientId}");
                if (patient.Count() != 0)
                {
                    if (consultation.Day < DateTime.Parse("01/01/1880") ||
                        consultation.Day > DateTime.Now.AddYears(1))
                    {
                        logger.LogError($"При добавлении новой консультации пациенту с id = {consultation.PatientId} произошла ошибка: " +
                                        $"Недопустимая дата: {consultation.Day}");
                        ModelState.AddModelError("Day", $"День консультации должен быть в промежутке" +
                                                 $" от {DateTime.Parse("01/01/1880").ToString("d")} до {DateTime.Now.AddYears(1).ToString("d")}");
                        return(View(consultation));
                    }

                    patientContext.Consultations.Add(consultation);
                    patientContext.SaveChanges();
                    logger.LogInformation($"Пациенту с id = {consultation.PatientId} была добавлена новая консультация.");
                    return(RedirectToAction("Get", "Patient",
                                            new { id = consultation.PatientId, message = "Консультация успешно добавлена" }));
                }
                else
                {
                    logger.LogError($"При добавлении консультации произошла ошибка: " +
                                    $"Пациент с id = {consultation.PatientId} не найден в базе данных");
                    return(View("Error",
                                new ErrorViewModel
                    {
                        Message = $"При добавлении консультации произошла ошибка: " +
                                  $"Пациент с id = {consultation.PatientId} не найден в базе данных"
                    }));
                }
            }
            catch (Exception e)
            {
                logger.LogCritical($"При добавлении консультации пациенту с id = {consultation.PatientId} произошла ошибка. ", e);
                return(View("Error",
                            new ErrorViewModel
                {
                    Message = $"Произошла ошибка. Не удалось добавить консультацию пациенту" +
                              $" с id = {consultation.PatientId} в базу данных. Обратитесь к администратору."
                }));
            }
        }
Beispiel #2
0
        public IActionResult Add(Patient patient)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (patient == null)
                    {
                        logger.LogError("При добавлении пациента произошла ошибка связывания модели.");
                        return(View("Error",
                                    new ErrorViewModel {
                            Message = "При добавлении пациента произошла ошибка связывания модели"
                        }));
                    }

                    if (patient.BirthDate < DateTime.Parse("01/01/1880") ||
                        patient.BirthDate > DateTime.Now.AddYears(1))
                    {
                        logger.LogError($"При добавлении нового пациента произошла ошибка: " +
                                        $"Недопустимая дата: {patient.BirthDate}");
                        ModelState.AddModelError("BirthDate", $"Дата рождения должна быть в промежутке" +
                                                 $" от {DateTime.Parse("01/01/1880").ToString("d")} до {DateTime.Now.AddYears(1).ToString("d")}");
                        return(View(patient));
                    }

                    patient.PensionNumber = Regex.Replace(patient.PensionNumber, "[^0-9]", "");
                    var result = patientContext.Patients
                                 .Where(x => x.PensionNumber == patient.PensionNumber)
                                 .FirstOrDefault();
                    if (result == null)
                    {
                        patientContext.Patients.Add(patient);
                        patientContext.SaveChanges();
                        logger.LogInformation($"Добавлен новый пациент в базу данных. СНИЛС: {patient.PensionNumber}.");
                        return(RedirectToAction("Index", "Home", new { message = "Пациент успешно добавлен" }));
                    }
                    else
                    {
                        logger.LogError($"При добавлении нового пациента " +
                                        $"обнаружен пациент с идентичным СНИЛС = {patient.PensionNumber}.");
                        ModelState.AddModelError("PensionNumber", "Пациент с таким СНИЛС уже существует");
                    }
                }
                return(View(patient));
            }
            catch (Exception e)
            {
                logger.LogCritical($"При добавлении пациента произошла ошибка. ", e);
                return(View("Error",
                            new ErrorViewModel
                {
                    Message = "Произошла ошибка. Не удалось добавить пациента в базу данных." +
                              " Обратитесь к администратору."
                }));
            }
        }
Beispiel #3
0
        public void DeleteDrug(int drugId)
        {
            var drug = _patientsContext.Drug.FirstOrDefault(c => c.DrugId == drugId);

            if (drug != null)
            {
                _patientsContext.Drug.Remove(drug);
                _patientsContext.SaveChanges();
            }
        }
Beispiel #4
0
        public ActionResult Add(Patient patient)
        {
            if (ModelState.IsValid)
            {
                patientContext.Add(patient);
                patientContext.SaveChanges();

                logger.LogInformation($"Добавлен новый пациент с id = {patient.PatientId}.");
                return(StatusCode(201, new { isSuccess = true, ErrorMessage = "", StatusCode = 201, Result = patient.PatientId }));
            }
            logger.LogError("При добавлении нового пациента данные не были получены от клиента, или они не прошли валидацию.");
            return(BadRequest(new { isSucces = false, ErrorMessage = "Полученные данные не прошли валидацию.", StatusCode = 400, Result = "" }));
        }
Beispiel #5
0
        public ActionResult Add(Consultation consultation)
        {
            if (ModelState.IsValid)
            {
                patientContext.Consultations.Add(consultation);
                patientContext.SaveChanges();

                logger.LogInformation($"Добавлена новая консультация с id = {consultation.ConsultationId}" +
                                      $" пациенту с id = {consultation.PatientId}.");
                return(StatusCode(201, new { isSuccess = true, ErrorMessage = "", StatusCode = 201, Result = consultation.ConsultationId }));
            }
            logger.LogError("При добавлении новой консультации данные не были получены от клиента, или они не прошли валидацию.");
            return(BadRequest(new { isSucces = false, ErrorMessage = "Полученные данные не прошли валидацию.", StatusCode = 400, Result = "" }));
        }
Beispiel #6
0
 /// <summary>
 /// removes an instance of type Patient with given id from DB
 /// </summary>
 /// <param name="id"></param>
 /// <param name="folderPath"></param>
 public static void RemovePatient(int?id, string folderPath)
 {
     using (var ctx = new PatientsContext())
     {
         Patient      patient = ctx.Patients.Find(id);
         List <Visit> visits  = patient.Visits.ToList();
         foreach (Visit item in visits)
         {
             Visit visit = ctx.Visits.Include(u => u.VisitPictures).Where(p => p.VisitId == item.VisitId).FirstOrDefault();
             ctx.Visits.Remove(visit);
         }
         List <Tooth> teeth = patient.Teeth.ToList();
         foreach (Tooth item in teeth)
         {
             Tooth tooth = ctx.Teeth.Include(u => u.Manipulations).Where(p => p.ToothId == item.ToothId).FirstOrDefault();
             ctx.Teeth.Remove(tooth);
         }
         ctx.Patients.Remove(patient);
         ctx.SaveChanges();
     }
     if (Directory.Exists(folderPath))
     {
         Directory.Delete(folderPath, true);
     }
 }
Beispiel #7
0
 /// <summary>
 /// adds an instance of type Dantist to DB
 /// </summary>
 /// <param name="dantist"></param>
 public static void AddDantist(Dantist dantist)
 {
     using (var ctx = new PatientsContext())
     {
         ctx.Dantists.Add(dantist);
         ctx.SaveChanges();
     }
 }
Beispiel #8
0
 /// <summary>
 /// saves an instance of type Dantist in DB
 /// </summary>
 /// <param name="dantist"></param>
 public static void SaveDantist(Dantist dantist)
 {
     using (var ctx = new PatientsContext())
     {
         ctx.Entry(dantist).State = EntityState.Modified;
         ctx.SaveChanges();
     }
 }
Beispiel #9
0
 /// <summary>
 /// adds an instance of <Picture> to manipulation list of <Picture> and saves it to DB
 /// </summary>
 /// <param name="manipulationId"></param>
 /// <param name="picture"></param>
 public static void AddManipulationImages(int?manipulationId, Picture picture)
 {
     using (var ctx = new PatientsContext())
     {
         Manipulation manipulation = ctx.Manipulations.Include(m => m.ManipulationPictures).Where(u => u.ManipulationId == manipulationId).FirstOrDefault();
         manipulation.ManipulationPictures.Add(picture);
         ctx.Entry(manipulation).State = EntityState.Modified;
         ctx.SaveChanges();
     }
 }
Beispiel #10
0
 /// <summary>
 /// adds manipulation to tooth with given id and saves it to DB
 /// </summary>
 /// <param name="manipulation">manipulation to add</param>
 /// <param name="toothId">tooth id to which the manipulation is to add</param>
 public static void AddManipulation(Manipulation manipulation, int?toothId)
 {
     using (var ctx = new PatientsContext())
     {
         Tooth tooth = ctx.Teeth.Include(m => m.Manipulations).Where(u => u.ToothId == toothId).FirstOrDefault();
         tooth.Manipulations.Add(manipulation);
         ctx.Entry(tooth).State = EntityState.Modified;
         ctx.SaveChanges();
     }
 }
Beispiel #11
0
 /// <summary>
 /// removes an instance of type Picture with given id from DB
 /// </summary>
 /// <param name="id"></param>
 /// <param name="picturePath"></param>
 public static void RemovePicture(int?id, string picturePath)
 {
     using (var ctx = new PatientsContext())
     {
         Picture picture = ctx.Pictures.Find(id);
         ctx.Pictures.Remove(picture);
         ctx.SaveChanges();
     }
     File.Delete(picturePath);
 }
Beispiel #12
0
 /// <summary>
 /// adds an instance of type Picture to and instance of type Visit
 /// and saves that to DB
 /// </summary>
 /// <param name="visitId"></param>
 /// <param name="picture"></param>
 public static void NewPicture(int?visitId, Picture picture)
 {
     using (var ctx = new PatientsContext())
     {
         Visit visit = ctx.Visits.Find(visitId);
         visit.VisitPictures.Add(picture);
         ctx.Entry(visit).State = EntityState.Modified;
         ctx.SaveChanges();
     }
 }
Beispiel #13
0
 /// <summary>
 /// add an instance of type Patient to an instance of type Dantist
 /// with given id and saves that to DB
 /// </summary>
 /// <param name="dantistId"></param>
 /// <param name="patient"></param>
 public static void AddPatient(int dantistId, Patient patient)
 {
     using (var ctx = new PatientsContext())
     {
         Dantist dantist = ctx.Dantists.Find(dantistId);
         dantist.Patients.Add(patient);
         ctx.Entry(dantist).State = EntityState.Modified;
         ctx.SaveChanges();
     }
 }
Beispiel #14
0
 /// <summary>
 /// removes manipulation with given id from DB
 /// </summary>
 /// <param name="id">manipulation id</param>
 /// <param name="folderPath">manipulation path on a disk</param>
 public static void RemoveManipulation(int?id, string folderPath)
 {
     using (var ctx = new PatientsContext())
     {
         Manipulation manipulation = ctx.Manipulations.Include(u => u.ManipulationPictures).Where(p => p.ManipulationId == id).FirstOrDefault();
         if (folderPath != "")
         {
             Directory.Delete(folderPath, true);
         }
         ctx.Manipulations.Remove(manipulation);
         ctx.SaveChanges();
     }
 }
Beispiel #15
0
 /// <summary>
 /// adds an instance of type Visit to a patient with
 /// given id and saves that to DB
 /// </summary>
 /// <param name="PatientId"></param>
 /// <param name="visit"></param>
 public static void AddVisit(int PatientId, Visit visit)
 {
     using (var ctx = new PatientsContext())
     {
         Patient patient = ctx.Patients.Find(PatientId);
         patient.LastVisitDate = visit.VisitDate;
         patient.Visits.Add(visit);
         List <Visit> visits = patient.Visits.OrderByDescending(m => m.VisitDate).ToList();
         patient.LastVisitDate    = visits[0].VisitDate;
         ctx.Entry(patient).State = EntityState.Modified;
         ctx.SaveChanges();
     }
 }
Beispiel #16
0
 /// <summary>
 /// removes an instance of type Dantist from DB
 /// </summary>
 /// <param name="id"></param>
 public static void DeleteDantist(int?id, string folderPath)
 {
     using (var ctx = new PatientsContext())
     {
         Dantist dantist = ctx.Dantists.Find(id);
         ctx.Dantists.Remove(dantist);
         ctx.SaveChanges();
     }
     if (Directory.Exists(folderPath))
     {
         Directory.Delete(folderPath, true);
     }
 }
Beispiel #17
0
 /// <summary>
 /// removes an instance of type Visit with given id from DB
 /// </summary>
 /// <param name="id"></param>
 /// <param name="folderPath"></param>
 public static void RemoveVisit(int?id, string folderPath)
 {
     using (var ctx = new PatientsContext())
     {
         Visit visit = ctx.Visits.Include(u => u.VisitPictures).Where(p => p.VisitId == id).FirstOrDefault();
         if (folderPath != "")
         {
             Directory.Delete(folderPath, true);
         }
         ctx.Visits.Remove(visit);
         ctx.SaveChanges();
     }
 }
Beispiel #18
0
        public void DeleteConsultation(int consultationId)
        {
            var prescriptions = _patientsContext.Prescription.Where(p => p.ConsultationId == consultationId).ToList();

            foreach (var prescription in prescriptions)
            {
                _patientsContext.Prescription.Remove(prescription);
            }

            var prescriptionsImages = _patientsContext.PrescriptionImages.Where(p => p.ConsultationId == consultationId).ToList();

            foreach (var prescriptionImage in prescriptionsImages)
            {
                _patientsContext.PrescriptionImages.Remove(prescriptionImage);
            }

            var consultation = _patientsContext.Consultation.FirstOrDefault(c => c.ConsultationId == consultationId);

            if (consultation != null)
            {
                _patientsContext.Consultation.Remove(consultation);
                _patientsContext.SaveChanges();
            }
        }
Beispiel #19
0
 /// <summary>
 /// Saves changes DB in list of instance of type Tooth for
 /// certain patient with given id
 /// </summary>
 /// <param name="patientId"></param>
 /// <param name="conditions">list of new conditions</param>
 public static void SaveTeeth(int patientId, List <string> conditions)
 {
     using (var ctx = new PatientsContext())
     {
         Patient patient = ctx.Patients.Find(patientId);
         if (patient.Teeth.Count == conditions.Count)
         {
             List <Tooth> teeth = patient.Teeth.ToList();
             for (int i = 0; i < conditions.Count; i++)
             {
                 teeth[i].Description = conditions[i];
             }
             patient.Teeth            = teeth;
             ctx.Entry(patient).State = EntityState.Modified;
             ctx.SaveChanges();
         }
     }
 }
Beispiel #20
0
 private void Save()
 {
     _patientsContext.SaveChanges();
 }