public async Task <Result <AddPatientAppointmentResponse> > Handle(AddPatientAppointmentCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var appointmentStatusId = _commontUnitOfWork.Repository <LookupItem>()
                                          .Get(x => x.Name == "Pending").SingleOrDefault()?.Id;

                int?appointmentReasonId = _commontUnitOfWork.Repository <LookupItem>()
                                          .Get(x => x.Name == request.AppointmentReason).SingleOrDefault()?.Id;

                var patientAppointment = new PatientAppointment(request.PatientId, request.PatientMasterVisitId, request.ServiceAreaId, request.AppointmentDate, (int)appointmentReasonId, (int)appointmentStatusId, request.DifferentiatedCareId, request.StatusDate, request.CreatedBy, request.Description);

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

                await _commontUnitOfWork.SaveAsync();

                return(Result <AddPatientAppointmentResponse> .Valid(new AddPatientAppointmentResponse
                {
                    AppointmentId = patientAppointment.Id
                }));
            }
            catch (Exception ex)
            {
                Log.Error(ex, $"An error occured while adding patient referral information for patientId {request.PatientId}");
                return(Result <AddPatientAppointmentResponse> .Invalid(ex.Message));
            }
        }
Ejemplo n.º 2
0
        public async Task <object> AddPatientNextAppointment([FromBody] AddPatientAppointmentCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(command));
            }

            var response = await _mediator.Send(command, HttpContext.RequestAborted);

            if (response.IsValid)
            {
                return(Ok(response.Value));
            }

            return(BadRequest(response));
        }