public async Task <object> AddDiagnosis([FromBody] AddPatientDiagnosisCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(command));
            }

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

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

            return(BadRequest(result));
        }
Exemple #2
0
        public async Task <Result <AddPatientDiagnosisResponse> > Handle(AddPatientDiagnosisCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var patientDiagnosis = _mapper.Map <PatientDiagnosis>(request);
                await _maternityUnitOfWork.Repository <PatientDiagnosis>().AddAsync(patientDiagnosis);

                await _maternityUnitOfWork.SaveAsync();

                return(Result <AddPatientDiagnosisResponse> .Valid(new AddPatientDiagnosisResponse
                {
                    DiagnosisId = patientDiagnosis.Id
                }));
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"An error occured while adding patient diagnosis for patientId {request.PatientId}");
                return(Result <AddPatientDiagnosisResponse> .Invalid(ex.Message));
            }
        }