public async Task <Result <AddTestingResponse> > Handle(AddTestingCommand request, CancellationToken cancellationToken) { try { using (_unitOfWork) { HtsEncounter encounter = await _unitOfWork.Repository <HtsEncounter>().FindByIdAsync(request.HtsEncounterId); encounter.CoupleDiscordant = request.FinalTestingResult.CoupleDiscordant; encounter.FinalResultGiven = request.FinalTestingResult.FinalResultGiven; _unitOfWork.Repository <HtsEncounter>().Update(encounter); await _unitOfWork.SaveAsync(); // Create Testing instances List <Core.Model.Testing> testings = new List <Core.Model.Testing>(); request.Testing.ForEach(t => testings.Add(new Core.Model.Testing { ExpiryDate = t.ExpiryDate, HtsEncounterId = request.HtsEncounterId, KitId = t.KitId, KitLotNumber = t.KitLotNumber, Outcome = t.Outcome, ProviderId = request.ProviderId, TestRound = t.TestRound, CreateDate = DateTime.Now, DeleteFlag = false })); await _unitOfWork.Repository <Core.Model.Testing>().AddRangeAsync(testings); await _unitOfWork.SaveAsync(); // Create HtsEncounterResult instance HtsEncounterResult hTSEncounterResult = new HtsEncounterResult { FinalResult = request.FinalTestingResult.FinalResult, HtsEncounterId = request.HtsEncounterId, RoundOneTestResult = request.FinalTestingResult.FinalResultHiv1, RoundTwoTestResult = request.FinalTestingResult.FinalResultHiv2 }; await _unitOfWork.Repository <HtsEncounterResult>().AddAsync(hTSEncounterResult); await _unitOfWork.SaveAsync(); _unitOfWork.Dispose(); return(Result <AddTestingResponse> .Valid(new AddTestingResponse() { AddedSuccessfully = true })); } } catch (Exception e) { return(Result <AddTestingResponse> .Invalid(e.Message)); } }
public async Task <Referral> addReferral(int personId, int fromFacilityId, int serviceAreaId, int referredTo, int referralReason, int userId, DateTime dateToBeEnrolled) { try { var referral = new Referral { PersonId = personId, ReferralDate = DateTime.Now, FromFacility = fromFacilityId, FromServicePoint = serviceAreaId, ToServicePoint = serviceAreaId, ToFacility = referredTo, ReferralReason = referralReason, ReferredBy = userId, CreatedBy = userId, ExpectedDate = dateToBeEnrolled, CreateDate = DateTime.Now, DeleteFlag = false }; await _htsunitOfWork.Repository <Referral>().AddAsync(referral); await _htsunitOfWork.SaveAsync(); return(referral); } catch (Exception e) { throw e; } }
public async Task <Result <ReferPatientResponse> > Handle(ReferPatientCommand request, CancellationToken cancellationToken) { try { var referral = new Referral { PersonId = request.PersonId, ReferralDate = DateTime.Now, FromFacility = request.FromFacilityId, FromServicePoint = request.ServiceAreaId, ToServicePoint = request.ServiceAreaId, ToFacility = request.ReferredTo, ReferralReason = request.ReferralReason, ReferredBy = request.UserId, CreatedBy = request.UserId, ExpectedDate = request.DateToBeEnrolled, CreateDate = DateTime.Now, DeleteFlag = false }; await _hTSUnitOfWork.Repository <Referral>().AddAsync(referral); await _hTSUnitOfWork.SaveAsync(); List <Core.Model.Tracing> tracings = new List <Core.Model.Tracing>(); request.Tracing.ForEach(t => tracings.Add(new Core.Model.Tracing { PersonID = request.PersonId, TracingType = t.TracingType, DateTracingDone = t.TracingDate, Mode = t.Mode, Outcome = t.Outcome, Remarks = null, CreatedBy = request.UserId, DeleteFlag = false, CreateDate = DateTime.Now })); await _hTSUnitOfWork.Repository <Core.Model.Tracing>().AddRangeAsync(tracings); await _hTSUnitOfWork.SaveAsync(); _hTSUnitOfWork.Dispose(); return(Result <ReferPatientResponse> .Valid(new ReferPatientResponse { ReferralId = referral.Id })); } catch (Exception ex) { return(Result <ReferPatientResponse> .Invalid(ex.Message)); } }
public async Task <Result <AddLinkageResponse> > Handle(AddLinkageCommand request, CancellationToken cancellationToken) { try { PatientLinkage patientLinkage = new PatientLinkage() { PersonId = request.PersonId, LinkageDate = request.DateEnrolled, CCCNumber = request.CCCNumber, Facility = request.Facility, Enrolled = true, DeleteFlag = false, CreatedBy = request.UserId, CreateDate = DateTime.Now, HealthWorker = request.HealthWorker, Cadre = request.Carde }; await _unitOfWork.Repository <PatientLinkage>().AddAsync(patientLinkage); await _unitOfWork.SaveAsync(); _unitOfWork.Dispose(); return(Result <AddLinkageResponse> .Valid(new AddLinkageResponse { LinkageId = patientLinkage.Id })); } catch (Exception e) { return(Result <AddLinkageResponse> .Invalid(e.Message)); } }
public async Task <Result <AddPnsTracingResponse> > Handle(AddPnsTracingCommand request, CancellationToken cancellationToken) { try { using (_unitOfWork) { Tracing pnstrace = new Tracing() { PersonID = request.PersonId, TracingType = request.TracingType, DateTracingDone = request.TracingDate, Mode = request.TracingMode, Outcome = request.TracingOutcome, Remarks = null, DeleteFlag = false, CreatedBy = request.UserId, CreateDate = DateTime.Now, Consent = request.Consent, DateBookedTesting = request.DateBookedTesting, ReminderDate = request.DateReminded }; await _unitOfWork.Repository <Tracing>().AddAsync(pnstrace); await _unitOfWork.SaveAsync(); _unitOfWork.Dispose(); return(Result <AddPnsTracingResponse> .Valid(new AddPnsTracingResponse() { TracingId = pnstrace.Id })); } } catch (Exception e) { return(Result <AddPnsTracingResponse> .Invalid(e.Message)); } }
public async Task <PatientLinkage> addLinkage(int personId, DateTime dateEnrolled, string cccNumber, string facility, int userId, string healthWorker, string carde) { try { PatientLinkage patientLinkage = new PatientLinkage() { PersonId = personId, LinkageDate = dateEnrolled, CCCNumber = cccNumber, Facility = facility, Enrolled = true, DeleteFlag = false, CreatedBy = userId, CreateDate = DateTime.Now, HealthWorker = healthWorker, Cadre = carde }; await _htsunitOfWork.Repository <PatientLinkage>().AddAsync(patientLinkage); await _htsunitOfWork.SaveAsync(); return(patientLinkage); } catch (Exception e) { throw e; } }
public async Task UpdatePersonLinkage(PatientLinkage patientLinkage) { try { _htsunitOfWork.Repository <PatientLinkage>().Update(patientLinkage); await _htsunitOfWork.SaveAsync(); } catch (Exception e) { Log.Error(e.Message + " " + e.InnerException); throw e; } }
public async Task <Result <AddEncounterResponse> > Handle(AddEncounterCommand request, CancellationToken cancellationToken) { // TODO: use automapper using (var trans = _unitOfWork.Context.Database.BeginTransaction()) { try { // create HtsEncounter instance var htsEncounter = new HtsEncounter { EncounterRemarks = request.Encounter.EncounterRemarks, EverSelfTested = request.Encounter.EverSelfTested, EverTested = request.Encounter.EverTested, GeoLocation = request.Encounter.GeoLocation, MonthSinceSelfTest = request.Encounter.MonthSinceSelfTest, MonthsSinceLastTest = request.Encounter.MonthsSinceLastTest, PatientEncounterID = request.Encounter.PatientEncounterID, PersonId = request.Encounter.PersonId, ProviderId = request.Encounter.ProviderId, TestedAs = request.Encounter.TestedAs, TestEntryPoint = request.Encounter.TestEntryPoint, TestingStrategy = request.Encounter.TestingStrategy, EncounterType = request.Encounter.EncounterType, HivCounsellingDone = request.Encounter.HivCounsellingDone, OtherDisability = request.Encounter.OtherDisability }; await _unitOfWork.Repository <HtsEncounter>().AddAsync(htsEncounter); await _unitOfWork.SaveAsync(); if (request.Encounter.Disabilities.Any()) { List <ClientDisability> clientDisabilities = new List <ClientDisability>(); request.Encounter.Disabilities.ForEach(x => clientDisabilities.Add(new ClientDisability { DisabilityId = x, PatientEncounterId = request.Encounter.PatientEncounterID, PersonId = request.Encounter.PersonId, CreateDate = DateTime.Now, CreatedBy = request.Encounter.ProviderId, DeleteFlag = false })); await _unitOfWork.Repository <ClientDisability>().AddRangeAsync(clientDisabilities); await _unitOfWork.SaveAsync(); } trans.Commit(); _unitOfWork.Dispose(); return(Result <AddEncounterResponse> .Valid(new AddEncounterResponse { HtsEncounterId = htsEncounter.Id })); } catch (Exception ex) { trans.Rollback(); Log.Error(ex.Message); // TODO: log error return(Result <AddEncounterResponse> .Invalid(ex.Message)); } } }
public async Task <Result <UpdateTestingResponse> > Handle(UpdateTestingCommand request, CancellationToken cancellationToken) { using (_unitOfWork) { try { var htsEncounter = await _unitOfWork.Repository <HtsEncounter>().FindByIdAsync(request.HtsEncounterId); if (htsEncounter != null) { htsEncounter.CoupleDiscordant = request.CoupleDiscordant; htsEncounter.FinalResultGiven = request.FinalResultGiven; _unitOfWork.Repository <HtsEncounter>().Update(htsEncounter); await _unitOfWork.SaveAsync(); var htsEncounterResults = await _unitOfWork.Repository <HtsEncounterResult>() .Get(x => x.HtsEncounterId == request.HtsEncounterId).ToListAsync(); if (htsEncounterResults.Count > 0) { htsEncounterResults[0].RoundOneTestResult = request.RoundOneTestResult; htsEncounterResults[0].RoundTwoTestResult = request.RoundTwoTestResult; htsEncounterResults[0].FinalResult = request.FinalResult; htsEncounterResults[0].EncounterResultRemarks = request.FinalResultsRemarks; _unitOfWork.Repository <HtsEncounterResult>().Update(htsEncounterResults[0]); await _unitOfWork.SaveAsync(); } else { HtsEncounterResult htsEncounterResult = new HtsEncounterResult() { EncounterResultRemarks = request.FinalResultsRemarks, FinalResult = request.FinalResult, HtsEncounterId = request.HtsEncounterId, RoundOneTestResult = request.RoundOneTestResult, RoundTwoTestResult = request.RoundTwoTestResult }; await _unitOfWork.Repository <HtsEncounterResult>().AddAsync(htsEncounterResult); await _unitOfWork.SaveAsync(); } return(Result <UpdateTestingResponse> .Valid(new UpdateTestingResponse() { Message = "Successfully updated HtsEncounter" })); } else { return(Result <UpdateTestingResponse> .Invalid($"Could not find Encounter with Id: {request.HtsEncounterId}")); } } catch (Exception e) { Log.Error($"Error updating HIV Testing for HtsEncounterId: {request.HtsEncounterId}", e); return(Result <UpdateTestingResponse> .Invalid(e.Message)); } } }
public async Task <Result <AddLinkageResponse> > Handle(AddLinkageCommand request, CancellationToken cancellationToken) { try { int patientLinkageId = 0; if (request.IsEdit) { var patientLinkage = await _unitOfWork.Repository <PatientLinkage>().FindByIdAsync(request.Id); if (patientLinkage != null) { patientLinkage.LinkageDate = request.DateEnrolled; patientLinkage.CCCNumber = request.CCCNumber; patientLinkage.Facility = request.Facility; patientLinkage.HealthWorker = request.HealthWorker; patientLinkage.Cadre = request.Carde; patientLinkage.ArtStartDate = request.Artstartdate; patientLinkage.Comments = request.Remarks; _unitOfWork.Repository <PatientLinkage>().Update(patientLinkage); await _unitOfWork.SaveAsync(); patientLinkageId = patientLinkage.Id; } } else { PatientLinkage patientLinkage = new PatientLinkage() { PersonId = request.PersonId, LinkageDate = request.DateEnrolled, CCCNumber = request.CCCNumber, Facility = request.Facility, Enrolled = true, DeleteFlag = false, CreatedBy = request.UserId, CreateDate = DateTime.Now, HealthWorker = request.HealthWorker, Cadre = request.Carde, ArtStartDate = request.Artstartdate, Comments = request.Remarks }; await _unitOfWork.Repository <PatientLinkage>().AddAsync(patientLinkage); await _unitOfWork.SaveAsync(); patientLinkageId = patientLinkage.Id; } _unitOfWork.Dispose(); return(Result <AddLinkageResponse> .Valid(new AddLinkageResponse { LinkageId = patientLinkageId })); } catch (Exception e) { Log.Error(e.Message); return(Result <AddLinkageResponse> .Invalid(e.Message)); } }
public async Task <Result <UpdateEncounterResponse> > Handle(UpdateEncounterCommand request, CancellationToken cancellationToken) { using (_unitOfWork) { try { var htsEncounter = await _unitOfWork.Repository <HtsEncounter>().FindByIdAsync(request.encounterId); if (htsEncounter != null) { htsEncounter.EncounterRemarks = request.Encounter.EncounterRemarks; htsEncounter.EverSelfTested = request.Encounter.EverSelfTested; htsEncounter.EverTested = request.Encounter.EverTested; htsEncounter.GeoLocation = request.Encounter.GeoLocation; htsEncounter.MonthSinceSelfTest = request.Encounter.MonthSinceSelfTest; htsEncounter.MonthsSinceLastTest = request.Encounter.MonthsSinceLastTest; htsEncounter.ProviderId = request.Encounter.ProviderId; htsEncounter.TestedAs = request.Encounter.TestedAs; htsEncounter.TestEntryPoint = request.Encounter.TestEntryPoint; htsEncounter.TestingStrategy = request.Encounter.TestingStrategy; htsEncounter.EncounterType = request.Encounter.EncounterType; _unitOfWork.Repository <HtsEncounter>().Update(htsEncounter); await _unitOfWork.SaveAsync(); if (request.Encounter.Disabilities.Any()) { var disabilities = await _unitOfWork.Repository <ClientDisability>().Get(x => x.PersonId == request.Encounter.PersonId).ToAsyncEnumerable().ToList(); foreach (var disability in disabilities) { disability.DeleteFlag = true; _unitOfWork.Repository <ClientDisability>().Update(disability); await _unitOfWork.SaveAsync(); } List <ClientDisability> clientDisabilities = new List <ClientDisability>(); request.Encounter.Disabilities.ForEach(x => clientDisabilities.Add(new ClientDisability { DisabilityId = x, PatientEncounterId = htsEncounter.PatientEncounterID, PersonId = request.Encounter.PersonId, DeleteFlag = false, CreateDate = DateTime.Now, CreatedBy = request.Encounter.ProviderId })); await _unitOfWork.Repository <ClientDisability>().AddRangeAsync(clientDisabilities); await _unitOfWork.SaveAsync(); } } _unitOfWork.Dispose(); return(Result <UpdateEncounterResponse> .Valid(new UpdateEncounterResponse() { IsSuccessFul = true })); } catch (Exception e) { Log.Error(e.Message); return(Result <UpdateEncounterResponse> .Invalid(e.Message)); } } }