public async Task <Result <PatientScreeningResponse> > Handle(PatientScreeningCommand request, CancellationToken cancellationToken) { try { using (_unitOfWork) { HtsScreeningOptions htsScreeningOptions = new HtsScreeningOptions() { PersonId = request.PersonId, Occupation = request.Occupation, ScreeningDate = request.ScreeningDate, BookingDate = request.BookingDate }; await _unitOfWork.Repository <HtsScreeningOptions>().AddAsync(htsScreeningOptions); await _unitOfWork.SaveAsync(); List <PatientScreening> screenings = new List <PatientScreening>(); foreach (var t in request.Screening) { if (t.ScreeningValueId != 0) { screenings.Add(new PatientScreening { PatientId = request.PatientId, PatientMasterVisitId = request.PatientMasterVisitId, ScreeningTypeId = t.ScreeningTypeId, ScreeningDone = true, ScreeningDate = request.ScreeningDate, ScreeningCategoryId = t.ScreeningCategoryId, ScreeningValueId = t.ScreeningValueId, Comment = null, Active = true, DeleteFlag = false, CreatedBy = request.UserId, CreateDate = DateTime.Now, VisitDate = request.ScreeningDate }); } } await _unitOfWork.Repository <PatientScreening>().AddRangeAsync(screenings); await _unitOfWork.SaveAsync(); List <HtsScreening> htsScreenings = new List <HtsScreening>(); foreach (var screening in screenings) { HtsScreening htsScreening = new HtsScreening() { PersonId = request.PersonId, PatientScreeningId = screening.Id, HtsScreeningOptionsId = htsScreeningOptions.Id }; htsScreenings.Add(htsScreening); } await _unitOfWork.Repository <HtsScreening>().AddRangeAsync(htsScreenings); await _unitOfWork.SaveAsync(); _unitOfWork.Dispose(); return(Result <PatientScreeningResponse> .Valid(new PatientScreeningResponse() { ScreeningDone = true })); } } catch (Exception e) { return(Result <PatientScreeningResponse> .Invalid(e.Message)); } }
public async Task <List <HtsScreening> > AddPartnerScreening(int personId, int patientId, int patientMasterVisitId, string occupation, DateTime screeningDate, DateTime bookingDate, List <Screening> partnerScreenings, int userId) { try { HtsScreeningOptions htsScreeningOptions = new HtsScreeningOptions() { PersonId = personId, Occupation = occupation, ScreeningDate = screeningDate, BookingDate = bookingDate }; await _unitOfWork.Repository <HtsScreeningOptions>().AddAsync(htsScreeningOptions); await _unitOfWork.SaveAsync(); List <PatientScreening> screenings = new List <PatientScreening>(); foreach (var t in partnerScreenings) { if (t.ScreeningValueId != 0) { screenings.Add(new PatientScreening { PatientId = patientId, PatientMasterVisitId = patientMasterVisitId, ScreeningTypeId = t.ScreeningTypeId, ScreeningDone = true, ScreeningDate = screeningDate, ScreeningCategoryId = t.ScreeningCategoryId, ScreeningValueId = t.ScreeningValueId, Comment = null, Active = true, DeleteFlag = false, CreatedBy = userId, CreateDate = DateTime.Now, VisitDate = screeningDate }); } } await _unitOfWork.Repository <PatientScreening>().AddRangeAsync(screenings); await _unitOfWork.SaveAsync(); List <HtsScreening> htsScreenings = new List <HtsScreening>(); foreach (var screening in screenings) { HtsScreening htsScreening = new HtsScreening() { PersonId = personId, PatientScreeningId = screening.Id, HtsScreeningOptionsId = htsScreeningOptions.Id }; htsScreenings.Add(htsScreening); } await _unitOfWork.Repository <HtsScreening>().AddRangeAsync(htsScreenings); await _unitOfWork.SaveAsync(); return(htsScreenings); } catch (Exception e) { throw e; } }