Esempio n. 1
0
        public async Task <Result <EditPreventiveServiceCommandResult> > Handle(EditPatientPrevemtiveServiceCommand request, CancellationToken cancellationToken)
        {
            using (_pmtctUnitOfWork)
            {
                try
                {
                    PreventiveService _preventiveService = await _pmtctUnitOfWork.Repository <PreventiveService>().FindAsync(x => x.PatientId == request.preventiveService.PatientId && x.Id == request.preventiveService.Id);

                    if (_preventiveService != null)
                    {
                        _preventiveService.PreventiveServiceId   = request.preventiveService.PreventiveServiceId;
                        _preventiveService.PreventiveServiceDate = request.preventiveService.PreventiveServiceDate;
                    }
                    _pmtctUnitOfWork.Repository <PreventiveService>().Update(_preventiveService);
                    await _pmtctUnitOfWork.SaveAsync();

                    _pmtctUnitOfWork.Dispose();

                    return(Result <EditPreventiveServiceCommandResult> .Valid(new EditPreventiveServiceCommandResult()
                    {
                        PreventiveServiceId = 1
                    }));
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                    return(Result <EditPreventiveServiceCommandResult> .Invalid(e.Message));
                }
            }
        }
        public async Task <Result <AddPatientPreventiveServiceCommandResponse> > Handle(PatientPreventiveServiceCommand request, CancellationToken cancellationToken)
        {
            using (_pmtctUnitOfWork)
            {
                try
                {
                    List <PreventiveService> preventiveServices = new List <PreventiveService>();

                    List <PreventiveService> preventiveServicesExist = _pmtctUnitOfWork
                                                                       .Repository <PreventiveService>().Get(x => x.PatientId == request.preventiveService[0].PatientId)
                                                                       .ToList();

                    if (request.preventiveService.Count > 0)
                    {
                        foreach (var item in request.preventiveService)
                        {
                            bool itemExists = preventiveServicesExist.Exists(x =>
                                                                             x.PreventiveServiceId == item.PreventiveServiceId && x.PatientId == item.PatientId &&
                                                                             x.PreventiveServiceDate ==
                                                                             item.PreventiveServiceDate);
                            if (!itemExists)
                            {
                                PreventiveService _preventiveServices = new PreventiveService()
                                {
                                    Id                    = item.Id,
                                    PatientId             = item.PatientId,
                                    PatientMasterVisitId  = item.PatientMasterVisitId,
                                    PreventiveServiceId   = item.PreventiveServiceId,
                                    PreventiveServiceDate = item.PreventiveServiceDate,
                                    Description           = item.Description
                                };
                                preventiveServices.Add(_preventiveServices);
                            }
                        }
                        await _pmtctUnitOfWork.Repository <PreventiveService>().AddRangeAsync(preventiveServices);

                        await _pmtctUnitOfWork.SaveAsync();

                        return(Result <AddPatientPreventiveServiceCommandResponse> .Valid(new AddPatientPreventiveServiceCommandResponse()
                        {
                            PreventiveServiceId = 1
                        }));
                    }
                    else
                    {
                        return(Result <AddPatientPreventiveServiceCommandResponse> .Valid(new AddPatientPreventiveServiceCommandResponse { PreventiveServiceId = 1 }));
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                    return(Result <AddPatientPreventiveServiceCommandResponse> .Invalid(e.Message));
                }
            }
        }
Esempio n. 3
0
        public async Task <Library.Result <PatientPreventiveServiceResponse> > Handle(PatientPreventiveServiceCommand request, CancellationToken cancellationToken)
        {
            int resultTwo   = 0;
            int resultOne   = 0;
            int resultThree = 0;

            using (_unitOfWork)
            {
                try
                {
                    List <PreventiveService> preventiveService = new List <PreventiveService>();
                    PatientPreventiveService _service          = new PatientPreventiveService(_unitOfWork);

                    PatientPartnerTesting partnerTesting = new PatientPartnerTesting()
                    {
                        PatientId            = request.PreventiveService[0].PatientId,
                        PatientMasterVisitId = request.PreventiveService[0].PatientMasterVisitId,
                        PartnerTested        = request.PartnerTestingVisit,
                        PartnerHivResult     = request.FinalHIVResult,
                        DeleteFlag           = 0,
                        CreatedBy            = request.CreatedBy
                    };
                    Result = await _service.AddPatientParterTesting(partnerTesting);

                    List <PreventiveService> preventiveServices = new List <PreventiveService>();

                    List <PreventiveService> preventiveServiceData = _unitOfWork.Repository <PreventiveService>()
                                                                     .Get(x => x.PatientId == request.PreventiveService[0].PatientId && !x.DeleteFlag)
                                                                     .ToList();

                    bool itemAntenatal =
                        preventiveServiceData.Exists(x => x.PreventiveServiceId == request.AntenatalExercise);
                    if (!itemAntenatal)
                    {
                        PreventiveService exercise = new PreventiveService()
                        {
                            PatientId             = request.PreventiveService[0].PatientId,
                            PatientMasterVisitId  = request.PreventiveService[0].PatientMasterVisitId,
                            PreventiveServiceId   = request.AntenatalExercise,
                            PreventiveServiceDate = DateTime.Now,
                            Description           = "Antenatal exercise",
                            CreatedBy             = request.CreatedBy,
                            DeleteFlag            = false
                        };
                        preventiveServices.Add(exercise);
                    }

                    bool itemInsecticide =
                        preventiveServiceData.Exists(x => x.PreventiveServiceId == request.InsecticideTreatedNet);
                    if (!itemInsecticide)
                    {
                        PreventiveService insecticideNet = new PreventiveService()
                        {
                            PatientId             = request.PreventiveService[0].PatientId,
                            PatientMasterVisitId  = request.PreventiveService[0].PatientMasterVisitId,
                            PreventiveServiceId   = request.InsecticideTreatedNet,
                            PreventiveServiceDate = request.InsecticideGivenDate,
                            Description           = request.InsecticideGivenDate.HasValue? "Insecticide treated nets given": "Insecticide Treated Net Not given",
                            CreatedBy             = request.CreatedBy,
                            DeleteFlag            = false
                        };

                        preventiveServices.Add(insecticideNet);
                    }


                    if (preventiveServices.Count > 0)
                    {
                        resultThree = await _service.AddPatientPreventiveService(preventiveServices);
                    }
                    resultThree = 1;

                    //  int resultTwo = await _service.AddPatientPreventiveService(request.PreventiveService);

                    // int

                    var appointmentStatusId = _commonUnitOfWork.Repository <LookupItem>()
                                              .Get(x => x.Name == "Pending").SingleOrDefault()?.Id;

                    foreach (var data in request.PreventiveService)
                    {
                        bool itemExists =
                            preventiveServiceData.Exists(x => x.PreventiveServiceId == data.PreventiveServiceId && Equals(x.PreventiveServiceDate, data.PreventiveServiceDate));
                        if (!itemExists)
                        {
                            PreventiveService rawData = new PreventiveService()
                            {
                                PatientId             = data.PatientId,
                                PatientMasterVisitId  = data.PatientMasterVisitId,
                                PreventiveServiceId   = data.PreventiveServiceId,
                                PreventiveServiceDate = data.PreventiveServiceDate,
                                Description           = data.Description,
                                NextSchedule          = data.NextSchedule,
                                CreatedBy             = data.CreatedBy,
                                DeleteFlag            = data.DeleteFlag
                            };

                            preventiveService.Add(rawData);


                            if (data.NextSchedule.HasValue && !Equals(data.NextSchedule, "1900-01-01T00:00:00"))
                            {
                                PatientAppointment appointment = new PatientAppointment()
                                {
                                    PatientId            = data.PatientId,
                                    PatientMasterVisitId = data.PatientMasterVisitId,
                                    ServiceAreaId        = 3,
                                    AppointmentDate      = data.NextSchedule.Value,
                                    ReasonId             = data.PreventiveServiceId,
                                    Description          = "ANC Preventive Services Schedule",
                                    StatusId             = Int32.Parse(appointmentStatusId.ToString()),
                                    DifferentiatedCareId = 0,
                                    CreatedBy            = request.CreatedBy
                                };

                                await _service.AddPatientAppointment(appointment);
                            }
                        }
                    }

                    if (preventiveService.Count > 0)
                    {
                        resultTwo = await _service.AddPatientPreventiveService(preventiveService);
                    }
                    resultTwo = 1;

                    if (resultThree > 0 && resultTwo > 0)
                    {
                        Result = 1;
                    }

                    return(Library.Result <PatientPreventiveServiceResponse> .Valid(new PatientPreventiveServiceResponse()
                    {
                        Id = Result
                    }));
                }
                catch (Exception e)
                {
                    Log.Error(e.Message + " " + e.InnerException);
                    return(Result <PatientPreventiveServiceResponse> .Invalid(e.Message));
                }
            }
        }