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));
            }
        }
Example #2
0
        public async Task <HtsEncounterResult> UpdateHtsEncounterResult(HtsEncounterResult htsEncounter)
        {
            try
            {
                _htsunitOfWork.Repository <HtsEncounterResult>().Update(htsEncounter);
                await _htsunitOfWork.SaveAsync();

                return(htsEncounter);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #3
0
        public async Task <HtsEncounterResult> addHtsEncounterResult(int htsEncounterId, int roundOneTestResult, int?roundTwoTestResult, int?finalResult)
        {
            try
            {
                HtsEncounterResult hTSEncounterResult = new HtsEncounterResult
                {
                    FinalResult        = finalResult,
                    HtsEncounterId     = htsEncounterId,
                    RoundOneTestResult = roundOneTestResult,
                    RoundTwoTestResult = roundTwoTestResult
                };

                await _htsunitOfWork.Repository <HtsEncounterResult>().AddAsync(hTSEncounterResult);

                await _htsunitOfWork.SaveAsync();

                return(hTSEncounterResult);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #4
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));
                }
            }
        }