Example #1
0
        public async Task <IActionResult> UpdatePatientNextAppointment([FromBody] EditAppointmentCommand editAppointmentCommand)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(editAppointmentCommand));
            }
            var response = await _mediator.Send(editAppointmentCommand, Request.HttpContext.RequestAborted);

            if (response.IsValid)
            {
                return(Ok(response.Value));
            }
            return(BadRequest(response));
        }
        public async Task <Result <EditAppointmentCommandResponse> > Handle(EditAppointmentCommand request, CancellationToken cancellationToken)
        {
            using (_commontUnitOfWork)
            {
                try
                {
                    if (request.AppointmentId.HasValue)
                    {
                        var appointment = await _commontUnitOfWork.Repository <PatientAppointment>()
                                          .FindByIdAsync(request.AppointmentId.Value);

                        if (appointment != null)
                        {
                            appointment.AppointmentDate = request.AppointmentDate;
                            appointment.Description     = request.Description;

                            _commontUnitOfWork.Repository <PatientAppointment>().Update(appointment);
                            await _commontUnitOfWork.SaveAsync();

                            return(Result <EditAppointmentCommandResponse> .Valid(new EditAppointmentCommandResponse()
                            {
                                Message = "Appointment updated successfully"
                            }));
                        }
                        else
                        {
                            return(Result <EditAppointmentCommandResponse> .Invalid("Error updating appointment for appointmentid: " + request.AppointmentId));
                        }
                    }
                    else
                    {
                        PatientAppointment patientAppointment = new PatientAppointment()
                        {
                            PatientId            = request.PatientId,
                            PatientMasterVisitId = request.PatientMasterVisitId,
                            AppointmentDate      = request.AppointmentDate,
                            DeleteFlag           = false,
                            CreateDate           = DateTime.Now,
                            CreatedBy            = request.UserId,
                            Description          = request.Description,
                            DifferentiatedCareId = request.DifferentiatedCareId,
                            ReasonId             = request.ReasonId,
                            ServiceAreaId        = request.ServiceAreaId,
                            StatusDate           = null,
                            StatusId             = request.StatusId
                        };

                        await _commontUnitOfWork.Repository <PatientAppointment>().AddAsync(patientAppointment);

                        await _commontUnitOfWork.SaveAsync();

                        return(Result <EditAppointmentCommandResponse> .Valid(new EditAppointmentCommandResponse()
                        {
                            Message = "Appointment updated successfully"
                        }));
                    }

                    //var appointment = await _commontUnitOfWork.Repository<PatientAppointment>().FindByIdAsync(request.AppointmentId);
                    //if (appointment != null)
                    //{
                    //    appointment.AppointmentDate = request.AppointmentDate;
                    //    appointment.Description = request.Description;

                    //    _commontUnitOfWork.Repository<PatientAppointment>().Update(appointment);
                    //    await _commontUnitOfWork.SaveAsync();

                    //    return Result<EditAppointmentCommandResponse>.Valid(new EditAppointmentCommandResponse()
                    //    {
                    //        Message = "Appointment updated successfully"
                    //    });
                    //}
                    //else
                    //{
                    //    return Result<EditAppointmentCommandResponse>.Invalid("Error updating appointment for appointmentid: " + request.AppointmentId);
                    //}
                }
                catch (Exception e)
                {
                    Log.Error("Error updating patient appointment " + e.Message + " " + e.InnerException);
                    return(Result <EditAppointmentCommandResponse> .Invalid("Error updating patient appointment " + e.Message));
                }
            }
        }