public async Task <IActionResult> AddPregnancyIndicator([FromBody] AddPregnancyIndicatorCommand addPregnancyIndicatorCommand) { var result = await _mediator.Send(addPregnancyIndicatorCommand, Request.HttpContext.RequestAborted); if (result.IsValid) { return(Ok(result.Value)); } return(BadRequest(result)); }
public async Task <Result <PregnancyIndicatorResult> > Handle(AddPregnancyIndicatorCommand request, CancellationToken cancellationToken) { using (_maternityUnitOfWork) { try { var result = await _maternityUnitOfWork.Repository <PregnancyIndicator>().Get(x => x.PatientId == request.PatientId && x.PatientMasterVisitId == request.PatientMasterVisitId && x.DeleteFlag == false).ToListAsync(); if (result.Count > 0) { result[0].LMP = request.LMP; result[0].EDD = request.EDD; result[0].PregnancyStatusId = request.PregnancyStatusId; result[0].ANCProfile = request.ANCProfile; result[0].ANCProfileDate = request.ANCProfileDate; result[0].VisitDate = request.VisitDate; result[0].PregnancyPlanned = request.PregnancyPlanned; result[0].PlanningToGetPregnant = request.PlanningToGetPregnant; result[0].BreastFeeding = request.BreastFeeding; _maternityUnitOfWork.Repository <PregnancyIndicator>().Update(result[0]); await _maternityUnitOfWork.SaveAsync(); return(Result <PregnancyIndicatorResult> .Valid(new PregnancyIndicatorResult() { Message = "Successfully updated patient pregnancy indicator" })); } PregnancyIndicator pregnancyIndicator = new PregnancyIndicator() { PatientId = request.PatientId, PatientMasterVisitId = request.PatientMasterVisitId, LMP = request.LMP, EDD = request.EDD, PregnancyStatusId = request.PregnancyStatusId, PregnancyPlanned = request.PregnancyPlanned, PlanningToGetPregnant = request.PlanningToGetPregnant, ANCProfile = request.ANCProfile, ANCProfileDate = request.ANCProfileDate, VisitDate = request.VisitDate, Active = request.Active, DeleteFlag = request.DeleteFlag, CreateDate = request.CreateDate, CreatedBy = request.CreatedBy, AuditData = request.AuditData, BreastFeeding = request.BreastFeeding }; await _maternityUnitOfWork.Repository <PregnancyIndicator>().AddAsync(pregnancyIndicator); await _maternityUnitOfWork.SaveAsync(); return(Result <PregnancyIndicatorResult> .Valid(new PregnancyIndicatorResult() { Message = "Successfully added patient pregnancy indicator" })); } catch (Exception ex) { Log.Error($"Could not save pregnancy indicator for pregnancy result. Exception: {ex.Message}, InnerException: {ex.InnerException}"); return(Result <PregnancyIndicatorResult> .Invalid($"Could not save pregnancy indicator for pregnancy result")); } } }