Esempio n. 1
0
        public async Task <Library.Result <ReferralAppointmentCommandResponse> > Handle(ReferralAppointmentServiceCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    int statusId = _commonUnitOfWork.Repository <LookupItem>().Get(x => x.Name == "pending")
                                   .Select(x => x.Id).FirstOrDefault();
                    int reasonId = _commonUnitOfWork.Repository <LookupItem>().Get(x => x.Name == "ANC Follow-up")
                                   .Select(x => x.Id).FirstOrDefault();

                    PatientReferral referralData = new PatientReferral()
                    {
                        PatientMasterVisitId = request.PatientReferral.PatientMasterVisitId,
                        ReferredFrom         = request.PatientReferral.ReferredFrom,
                        ReferredTo           = request.PatientReferral.ReferredTo,
                        ReferralReason       = request.PatientReferral.ReferralReason,
                        ReferralDate         = request.PatientReferral.ReferralDate,
                        ReferredBy           = request.PatientReferral.ReferredBy,
                        CreateBy             = request.CreatedBy,
                        PatientId            = request.PatientReferral.PatientId
                    };

                    PatientAppointment appointmentData = new PatientAppointment()
                    {
                        PatientMasterVisitId = request.PatientAppointment.PatientMasterVisitId,
                        PatientId            = request.PatientAppointment.PatientId,
                        ServiceAreaId        = request.PatientAppointment.ServiceAreaId,
                        AppointmentDate      = request.PatientAppointment.AppointmentDate,
                        ReasonId             = reasonId,
                        Description          = request.PatientAppointment.Description,
                        StatusDate           = DateTime.Now,
                        StatusId             = statusId,
                        CreatedBy            = request.CreatedBy
                    };

                    ReferralAppointmentService _service = new ReferralAppointmentService(_unitOfWork);
                    int result1 = await _service.AddPatientAppointment(appointmentData);

                    int result2 = await _service.AddPatientReferral(referralData);

                    if (result1 > 0 & result2 > 0)
                    {
                        result = 1;
                    }
                    return(Library.Result <ReferralAppointmentCommandResponse> .Valid(new ReferralAppointmentCommandResponse()
                    {
                        ReferralAppointmentId = result
                    }));
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                    throw e;
                }
            }
        }
Esempio n. 2
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));
                }
            }
        }