public async Task <ApiResponse> Delete(PatientDeleteModel model)
        {
            try
            {
                var result = await _objControllerHelper.Delete(model.externalIds);

                if (result == PatientUpdateStatus.Success)
                {
                    return(new ApiResponse("The record has been deleted successfully"));
                }
                return(new ApiResponse(404, result));
            }
            catch (Exception ex)
            {
                throw new ApiException(ex);
            }
        }
Ejemplo n.º 2
0
        public ActionResult DeletePatient(long id, string cancelRedirectUrl)
        {
            ViewBag.MenuItem = CurrentMenuItem;

            TempData["cancelRedirectUrl"] = cancelRedirectUrl;
            ViewBag.CancelRedirectUrl     = cancelRedirectUrl;

            var patient = unitOfWork.Repository <Patient>().Queryable().SingleOrDefault(u => u.Id == id);

            PatientDeleteModel model = new PatientDeleteModel()
            {
                PatientId = patient.Id, PatientFullName = patient.FullName
            };

            ViewData.Model = model;

            ViewBag.Id           = id;
            ViewBag.AlertMessage = patient.HasClinicalData() ? "You are about to delete this record which has associated clinical data, appointments or encounters. This action is not reversible...." : "You are about to delete this record. This action is not reversible....";

            return(View());
        }
Ejemplo n.º 3
0
        public ActionResult DeletePatient(PatientDeleteModel model)
        {
            ViewBag.MenuItem = CurrentMenuItem;

            var cancelRedirectUrl = (TempData["cancelRedirectUrl"] ?? string.Empty).ToString();

            ViewBag.cancelRedirectUrl = cancelRedirectUrl;

            ArrayList errors = new ArrayList();

            if (ModelState.IsValid)
            {
                var patient     = unitOfWork.Repository <Patient>().Queryable().SingleOrDefault(u => u.Id == model.PatientId);
                var currentUser = GetCurrentUser();

                try
                {
                    var reason       = model.ArchiveReason.Trim() == "" ? "** NO REASON SPECIFIED ** " : model.ArchiveReason;
                    var archivedDate = DateTime.Now;

                    foreach (var appointment in patient.Appointments.Where(x => !x.Archived))
                    {
                        appointment.Archived       = true;
                        appointment.ArchivedDate   = archivedDate;
                        appointment.ArchivedReason = reason;
                        appointment.AuditUser      = currentUser;
                        unitOfWork.Repository <Appointment>().Update(appointment);
                    }

                    foreach (var attachment in patient.Attachments.Where(x => !x.Archived))
                    {
                        attachment.Archived       = true;
                        attachment.ArchivedDate   = archivedDate;
                        attachment.ArchivedReason = reason;
                        attachment.AuditUser      = currentUser;
                        unitOfWork.Repository <Attachment>().Update(attachment);
                    }

                    foreach (var enrolment in patient.CohortEnrolments.Where(x => !x.Archived))
                    {
                        enrolment.Archived       = true;
                        enrolment.ArchivedDate   = archivedDate;
                        enrolment.ArchivedReason = reason;
                        enrolment.AuditUser      = currentUser;
                        unitOfWork.Repository <CohortGroupEnrolment>().Update(enrolment);
                    }

                    foreach (var encounter in patient.Encounters.Where(x => !x.Archived))
                    {
                        encounter.Archived       = true;
                        encounter.ArchivedDate   = archivedDate;
                        encounter.ArchivedReason = reason;
                        encounter.AuditUser      = currentUser;
                        unitOfWork.Repository <Encounter>().Update(encounter);
                    }

                    foreach (var clinicalEvent in patient.PatientClinicalEvents.Where(x => !x.Archived))
                    {
                        clinicalEvent.Archived       = true;
                        clinicalEvent.ArchivedDate   = archivedDate;
                        clinicalEvent.ArchivedReason = reason;
                        clinicalEvent.AuditUser      = currentUser;
                        unitOfWork.Repository <PatientClinicalEvent>().Update(clinicalEvent);
                    }

                    foreach (var condition in patient.PatientConditions.Where(x => !x.Archived))
                    {
                        condition.Archived       = true;
                        condition.ArchivedDate   = archivedDate;
                        condition.ArchivedReason = reason;
                        condition.AuditUser      = currentUser;
                        unitOfWork.Repository <PatientCondition>().Update(condition);
                    }

                    foreach (var facility in patient.PatientFacilities.Where(x => !x.Archived))
                    {
                        facility.Archived       = true;
                        facility.ArchivedDate   = archivedDate;
                        facility.ArchivedReason = reason;
                        facility.AuditUser      = currentUser;
                        unitOfWork.Repository <PatientFacility>().Update(facility);
                    }

                    foreach (var labTest in unitOfWork.Repository <PatientLabTest>().Queryable().Include(plt => plt.Patient).Include(plt => plt.LabTest).Include(plt => plt.TestUnit).Where(x => x.Patient.Id == patient.Id && !x.Archived))
                    {
                        labTest.Archived       = true;
                        labTest.ArchivedDate   = archivedDate;
                        labTest.ArchivedReason = reason;
                        labTest.AuditUser      = currentUser;
                        unitOfWork.Repository <PatientLabTest>().Update(labTest);
                    }

                    foreach (var medication in patient.PatientMedications.Where(x => !x.Archived))
                    {
                        medication.Archived       = true;
                        medication.ArchivedDate   = archivedDate;
                        medication.ArchivedReason = reason;
                        medication.AuditUser      = currentUser;
                        unitOfWork.Repository <PatientMedication>().Update(medication);
                    }

                    foreach (var status in patient.PatientStatusHistories.Where(x => !x.Archived))
                    {
                        status.Archived       = true;
                        status.ArchivedDate   = archivedDate;
                        status.ArchivedReason = reason;
                        status.AuditUser      = currentUser;
                        unitOfWork.Repository <PatientStatusHistory>().Update(status);
                    }

                    patient.Archived       = true;
                    patient.ArchivedDate   = archivedDate;
                    patient.ArchivedReason = reason;
                    patient.AuditUser      = currentUser;

                    unitOfWork.Repository <Patient>().Update(patient);
                    unitOfWork.Complete();
                }
                catch (DbUpdateException ex)
                {
                    errors.Add("Unable to archive patient. " + ex.Message);
                }
                catch (DbEntityValidationException ex)
                {
                    var err = string.Empty;
                    foreach (var eve in ex.EntityValidationErrors)
                    {
                        foreach (var ve in eve.ValidationErrors)
                        {
                            err += String.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    errors.Add(err);
                }
                if (errors.Count == 0)
                {
                    HttpCookie cookie = new HttpCookie("PopUpMessage");
                    cookie.Value = "Patient record deleted successfully";
                    Response.Cookies.Add(cookie);

                    return(Redirect("/Patient/PatientSearch.aspx"));
                }
                else
                {
                    AddErrors(errors);
                }
            }

            return(View(model));
        }