Exemple #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;
                }
            }
        }
        public async Task <int> AddPatientReferral(PatientReferral patientReferral)
        {
            try
            {
                await _unitOfWork.Repository <PatientReferral>().AddAsync(patientReferral);

                await _unitOfWork.SaveAsync();

                return(1);
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                throw e;
            }
        }