コード例 #1
0
        public async Task <IActionResult> CareEndPatient([FromBody] AddPatientCareEndingCommand addPatientCareEndingCommand)
        {
            var response = await _mediator.Send(addPatientCareEndingCommand, Request.HttpContext.RequestAborted);

            if (response.IsValid)
            {
                return(Ok(response.Value));
            }
            return(BadRequest(response));
        }
コード例 #2
0
        public async Task <Result <AddPatientCareEndingResponse> > Handle(AddPatientCareEndingCommand request, CancellationToken cancellationToken)
        {
            try
            {
                int PatientEnrollmentId;
                var result = await _unitOfWork.Repository <PatientEnrollment>().Get(x =>
                                                                                    x.PatientId == request.PatientId && x.ServiceAreaId == request.ServiceAreaId &&
                                                                                    x.DeleteFlag == false && !x.CareEnded).FirstOrDefaultAsync();

                var PatientCare = await _unitOfWork.Repository <PatientCareEnding>().Get(x => x.PatientMasterVisitId == request.PatientMasterVisitId && x.PatientId == request.PatientId &&
                                                                                         x.DeleteFlag == false).FirstOrDefaultAsync();

                if (PatientCare != null)
                {
                    PatientCare.PatientId            = request.PatientId;
                    PatientCare.PatientMasterVisitId = request.PatientMasterVisitId;
                    PatientCare.ExitReason           = request.DisclosureReason;
                    PatientCare.ExitDate             = request.CareEndedDate;
                    PatientCare.CareEndingNotes      = request.Specify;
                    PatientCare.DateOfDeath          = request.DeathDate;

                    _unitOfWork.Repository <PatientCareEnding>().Update(PatientCare);
                    await _unitOfWork.SaveAsync();

                    if (PatientCare.Id > 0)
                    {
                        Id = PatientCare.Id;
                    }
                    Message += "Patient Information has been updated";
                }
                else
                {
                    if (result != null)
                    {
                        PatientEnrollmentId = result.Id;

                        if (PatientEnrollmentId > 0)
                        {
                            PatientCareEnding pc = new PatientCareEnding()

                            {
                                PatientId            = request.PatientId,
                                PatientMasterVisitId = request.PatientMasterVisitId,
                                PatientEnrollmentId  = PatientEnrollmentId,
                                ExitReason           = request.DisclosureReason,
                                ExitDate             = request.CareEndedDate,
                                CareEndingNotes      = request.Specify,
                                DateOfDeath          = request.DeathDate,
                                Active     = false,
                                DeleteFlag = false,
                                CreatedBy  = request.UserId,
                                CreateDate = DateTime.Now,
                            };

                            await _unitOfWork.Repository <PatientCareEnding>().AddAsync(pc);

                            await _unitOfWork.SaveAsync();


                            if (pc.Id > 0)
                            {
                                Id = Id;
                            }

                            Message += "Patient has been successfully careended";
                        }

                        var patientenrollment = await _unitOfWork.Repository <PatientEnrollment>().Get(x => x.Id == PatientEnrollmentId
                                                                                                       ).FirstOrDefaultAsync();

                        if (patientenrollment != null)
                        {
                            patientenrollment.CareEnded = true;
                            _unitOfWork.Repository <PatientEnrollment>().Update(patientenrollment);
                            await _unitOfWork.SaveAsync();
                        }
                    }

                    else
                    {
                        Message += "Patient has not been successfully careended";
                    }
                }



                return(Result <AddPatientCareEndingResponse> .Valid(new AddPatientCareEndingResponse()
                {
                    Id = Id,
                    Message = Message
                }));
            }
            catch (Exception ex)
            {
                return(Result <AddPatientCareEndingResponse> .Invalid(ex.Message));
            }
        }