Пример #1
0
        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 <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));
            }
        }
Пример #3
0
        public async Task <Result <GetEncounterResponse> > Handle(GetEncounterCommand request, CancellationToken cancellationToken)
        {
            using (_hTSUnitOfWork)
            {
                try
                {
                    // Get HTS Encounter
                    var result = await _hTSUnitOfWork.Repository <HtsEncounter>().Get(x => x.Id == request.EncounterId).ToListAsync();

                    // Get Patient Global Encounter
                    var patientEncounter = await _unitOfWork.Repository <PatientEncounter>()
                                           .Get(x => x.Id == result[0].PatientEncounterID).ToListAsync();

                    // Get Client Disabilities
                    var disablity = await _hTSUnitOfWork.Repository <ClientDisability>()
                                    .Get(x => x.PersonId == result[0].PersonId).ToListAsync();

                    // Get Consent For Testing
                    var consentType = await _unitOfWork.Repository <LookupItemView>().Get(x => x.MasterName == "ConsentType" && x.ItemName == "ConsentToBeTested").FirstOrDefaultAsync();

                    int consentTypeId = consentType != null ? consentType.ItemId : 0;
                    var consent       = await _unitOfWork.Repository <PatientConsent>().Get(x =>
                                                                                            x.PatientId == patientEncounter[0].PatientId &&
                                                                                            x.PatientMasterVisitId == patientEncounter[0].PatientMasterVisitId && x.ServiceAreaId == 2 &&
                                                                                            x.ConsentType == consentTypeId).ToListAsync();

                    //Get Client Screening for TB
                    var tbScreeningLookup = await _unitOfWork.Repository <LookupItemView>()
                                            .Get(x => x.MasterName == "TbScreening").FirstOrDefaultAsync();

                    int tbScreeningId = tbScreeningLookup != null ? tbScreeningLookup.MasterId : 0;
                    var tbStatus      = await _unitOfWork.Repository <PatientScreening>().Get(x =>
                                                                                              x.ScreeningTypeId == tbScreeningId && x.PatientId == patientEncounter[0].PatientId &&
                                                                                              x.PatientMasterVisitId == patientEncounter[0].PatientMasterVisitId).ToListAsync();


                    return(Result <GetEncounterResponse> .Valid(new GetEncounterResponse()
                    {
                        encounter = result,
                        patientEncounter = patientEncounter,
                        disabilities = disablity,
                        consent = consent,
                        tbStatus = tbStatus
                    }));
                }
                catch (Exception e)
                {
                    return(Result <GetEncounterResponse> .Invalid(e.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));
            }
        }
Пример #5
0
        public async Task <Result <GetTestingResultsResponse> > Handle(GetTestingCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    List <Core.Model.Testing> testings         = new List <Testing>();
                    List <HtsEncounterResult> encounterResults = new List <HtsEncounterResult>();

                    var encounter = await _unitOfWork.Repository <HtsEncounter>()
                                    .Get(x => x.PatientEncounterID == request.PatientEncounterId).ToListAsync();


                    if (encounter.Count > 0)
                    {
                        for (int i = 0; i < encounter.Count; i++)
                        {
                            var resulttestings = await _unitOfWork.Repository <Core.Model.Testing>().Get(x => x.HtsEncounterId == encounter[i].Id)
                                                 .ToListAsync();

                            testings.AddRange(resulttestings);

                            var resultEncounterResults = await _unitOfWork.Repository <HtsEncounterResult>()
                                                         .Get(x => x.HtsEncounterId == encounter[0].Id).ToListAsync();

                            encounterResults.AddRange(resultEncounterResults);
                        }
                    }

                    return(Result <GetTestingResultsResponse> .Valid(new GetTestingResultsResponse()
                    {
                        Encounter = encounter,
                        Testing = testings,
                        EncounterResults = encounterResults
                    }));
                }
                catch (Exception ex)
                {
                    Log.Error(ex.Message + " " + ex.InnerException);
                    return(Result <GetTestingResultsResponse> .Invalid(ex.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 <List <Referral> > > Handle(GetClientReferralCommand request, CancellationToken cancellationToken)
        {
            using (_hTSUnitOfWork)
            {
                try
                {
                    var clientReferral = await _hTSUnitOfWork.Repository <Referral>().Get(x => x.PersonId == request.PersonId && x.DeleteFlag == false).OrderByDescending(y => y.Id).ToListAsync();

                    return(Result <List <Referral> > .Valid(clientReferral));
                }
                catch (Exception e)
                {
                    return(Result <List <Referral> > .Invalid(e.Message));
                }
            }
        }
Пример #8
0
        public async Task <Result <List <HTSEncountersView> > > Handle(GetHtsEncountersCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var results = await _unitOfWork.Repository <HTSEncountersView>()
                              .Get(x => x.PatientId == request.PatientId).ToListAsync();

                _unitOfWork.Dispose();

                return(Result <List <HTSEncountersView> > .Valid(results));
            }
            catch (Exception e)
            {
                return(Result <List <HTSEncountersView> > .Invalid(e.Message));
            }
        }
        public async Task <Result <List <EncountersDetailView> > > Handle(GetHtsEncounterDetailsViewCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    var result = await _unitOfWork.Repository <EncountersDetailView>()
                                 .Get(x => x.EncounterId == request.EncounterId).ToListAsync();

                    return(Result <List <EncountersDetailView> > .Valid(result));
                }
                catch (Exception e)
                {
                    return(Result <List <EncountersDetailView> > .Invalid(e.Message));
                }
            }
        }
        public async Task <Result <List <EncountersDetailView> > > Handle(EncounterDetailsByPersonIdCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    var result = await _unitOfWork.Repository <EncountersDetailView>()
                                 .Get(x => x.PersonId == request.personId).OrderByDescending(x => x.EncounterDate).Take(6).ToListAsync();

                    return(Result <List <EncountersDetailView> > .Valid(result));
                }
                catch (Exception e)
                {
                    return(Result <List <EncountersDetailView> > .Invalid(e.Message));
                }
            }
        }
Пример #11
0
        public async Task <Result <List <ClientDisability> > > Handle(GetClientDisabilityCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    var result = await _unitOfWork.Repository <ClientDisability>()
                                 .Get(x => x.PersonId == request.PersonId).ToListAsync();

                    return(Result <List <ClientDisability> > .Valid(result));
                }
                catch (Exception e)
                {
                    return(Result <List <ClientDisability> > .Invalid(e.Message));
                }
            }
        }
        public async Task <Result <List <TestingSummaryStatistics> > > Handle(TestingSummaryStatisticsQuery request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    var result = await _unitOfWork.Repository <TestingSummaryStatistics>().GetAllAsync();

                    return(Result <List <TestingSummaryStatistics> > .Valid(result.ToList()));
                }
                catch (Exception ex)
                {
                    Log.Error(ex.Message);
                    return(Result <List <TestingSummaryStatistics> > .Invalid(ex.Message));
                }
            }
        }
        public async Task <Result <List <HivPositiveListView> > > Handle(GetHivPositiveListCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    var result = await _unitOfWork.Repository <HivPositiveListView>()
                                 .Get(x => x.PersonId == request.PersonId).ToListAsync();

                    return(Result <List <HivPositiveListView> > .Valid(result));
                }
                catch (Exception e)
                {
                    Log.Error($"Error fetching hiv positive persons list {e.Message} {e.InnerException}");
                    return(Result <List <HivPositiveListView> > .Invalid($"Error fetching hiv positive persons list"));
                }
            }
        }
Пример #14
0
        public async Task <Result <List <PatientLinkage> > > Handle(GetPersonLinkageCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    var result = await _unitOfWork.Repository <PatientLinkage>().Get(x => x.PersonId == request.PersonId)
                                 .ToListAsync();

                    return(Result <List <PatientLinkage> > .Valid(result));
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                    return(Result <List <PatientLinkage> > .Invalid(e.Message));
                }
            }
        }
Пример #15
0
        public async Task <Result <Core.Model.Testing> > Handle(GetLastLotNumberByKitIdCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    var kitTesting = await _unitOfWork.Repository <Core.Model.Testing>()
                                     .Get(x => x.KitId == request.KitId && x.DeleteFlag == false)
                                     .OrderByDescending(y => y.CreateDate).FirstOrDefaultAsync();

                    return(Result <Testing> .Valid(kitTesting));
                }
                catch (Exception e)
                {
                    Log.Error($"Error fetching kits for kitId: {request.KitId}" + e.Message);
                    return(Result <Testing> .Invalid($"Error fetching kits for kitId: {request.KitId}"));
                }
            }
        }
Пример #16
0
        public async Task<Result<List<EncountersDetailView>>> Handle(GetHtsEncounterDetailsViewByVisitDateCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {

                    var result = await _unitOfWork.Repository<EncountersDetailView>()
                    .Get(x => x.PersonId == request.personId && x.EncounterDate.Date.Day == request.VisitDate.Date.Day
                    && x.EncounterDate.Date.Year ==request.VisitDate.Date.Year 
                    && x.EncounterDate.Date.Month==x.EncounterDate.Date.Month ).ToListAsync();

                    return Result<List<EncountersDetailView>>.Valid(result);
                }
                catch (Exception e)
                {
                    return Result<List<EncountersDetailView>>.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 <Result <GetPersonLastHtsEncounterResponse> > Handle(GetPersonLastHtsEncounterCommand request, CancellationToken cancellationToken)
        {
            try
            {
                using (_unitOfWork)
                {
                    var result = await _unitOfWork.Repository <HtsEncounter>().Get(x => x.PersonId == request.PersonId)
                                 .OrderByDescending(x => x.Id).FirstOrDefaultAsync();

                    var patientEncounter = new PatientEncounter();
                    int encounterId      = 0;
                    if (result != null)
                    {
                        patientEncounter = await _commonUnitOfWork.Repository <PatientEncounter>()
                                           .Get(x => x.Id == result.PatientEncounterID).FirstOrDefaultAsync();

                        encounterId = result.Id;
                    }

                    _unitOfWork.Dispose();
                    _commonUnitOfWork.Dispose();

                    var personLastHtsEncounter = new GetPersonLastHtsEncounterResponse()
                    {
                        EncounterId          = encounterId,
                        PatientMasterVisitId = patientEncounter.PatientMasterVisitId,
                        PatientEncounterID   = patientEncounter.Id
                    };

                    return(Result <GetPersonLastHtsEncounterResponse> .Valid(personLastHtsEncounter));
                }
            }
            catch (Exception e)
            {
                return(Result <GetPersonLastHtsEncounterResponse> .Invalid(e.Message));
            }
        }
Пример #19
0
        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 <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));
                }
            }
        }
Пример #21
0
 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;
     }
 }
Пример #22
0
        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 <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));
                }
            }
        }
Пример #24
0
        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));
                }
            }
        }