public async Task <Result <PatientTransferIn> > Handle(GetPatientTransferInCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    RegisterPersonService rs = new RegisterPersonService(_unitOfWork);

                    var Patient = await rs.GetPatientByPersonId(request.PersonId);

                    if (Patient != null)
                    {
                        PatientId = Patient.Id;
                    }
                    var enrollmentVisitType = await _unitOfWork.Repository <LookupItemView>().Get(x => x.MasterName == "VisitType" && x.ItemName == "Enrollment").FirstOrDefaultAsync();

                    int?visitType = enrollmentVisitType != null ? enrollmentVisitType.ItemId : 0;

                    var enrollmentPatientMasterVisit =
                        await _unitOfWork.Repository <Core.Models.PatientMasterVisit>().Get(x =>
                                                                                            x.PatientId == PatientId && x.ServiceId == request.ServiceId && x.VisitType == visitType).ToListAsync();

                    if (enrollmentPatientMasterVisit.Count > 0)
                    {
                        PatientMasterVisitId = enrollmentPatientMasterVisit[0].Id;
                    }
                    var TransferIn = await rs.GetPatientTransferIn(PatientId, PatientMasterVisitId);


                    return(Result <PatientTransferIn> .Valid(TransferIn));
                }
                catch (Exception ex)
                {
                    return(Result <PatientTransferIn> .Invalid(ex.Message));
                }
            }
        }
Esempio n. 2
0
        public async Task <Result <AddPatientTransferInResponse> > Handle(AddPatientTransferInCommand request, CancellationToken cancellationToken)
        {
            try
            {
                using (_unitOfWork)
                {
                    int Id = 0;
                    int PatientMasterVisitId = 0;
                    RegisterPersonService registerPersonService = new RegisterPersonService(_unitOfWork);
                    var enrollmentVisitType = await _unitOfWork.Repository <LookupItemView>().Get(x => x.MasterName == "VisitType" && x.ItemName == "Enrollment").FirstOrDefaultAsync();

                    int?     visitType = enrollmentVisitType != null ? enrollmentVisitType.ItemId : 0;
                    DateTime TreatmentStartDate;
                    if (request.TreatmentStartDate == null)
                    {
                        TreatmentStartDate = request.TransferInDate;
                    }
                    else
                    {
                        TreatmentStartDate = request.TreatmentStartDate;
                    }
                    var enrollmentPatientMasterVisit =
                        await _unitOfWork.Repository <Core.Models.PatientMasterVisit>().Get(x =>
                                                                                            x.PatientId == request.PatientId && x.ServiceId == request.ServiceId && x.VisitType == visitType).ToListAsync();

                    if (enrollmentPatientMasterVisit.Count > 0)
                    {
                        PatientMasterVisitId = enrollmentPatientMasterVisit[0].Id;
                        var previousPatientEnrollment = await _unitOfWork.Repository <PatientEnrollment>().Get(x =>
                                                                                                               x.PatientId == request.PatientId && x.ServiceAreaId == request.ServiceId && x.DeleteFlag == false)
                                                        .ToListAsync();

                        if (previousPatientEnrollment.Count > 0)
                        {
                            previousPatientEnrollment[0].TransferIn = true;

                            _unitOfWork.Repository <PatientEnrollment>().Update(previousPatientEnrollment[0]);
                        }

                        var transferin = await registerPersonService.GetPatientTransferIn(request.PatientId, PatientMasterVisitId);

                        if (transferin != null)
                        {
                            transferin.TransferInDate     = request.TransferInDate;
                            transferin.TransferInNotes    = request.TransferInNotes;
                            transferin.TreatmentStartDate = TreatmentStartDate;
                            transferin.CountyFrom         = request.CountyFrom;
                            transferin.CurrentTreatment   = request.CurrentTreatment;
                            transferin.ServiceAreaId      = request.ServiceId;
                            transferin.MflCode            = request.MflCode;
                            transferin.DeleteFlag         = request.DeleteFlag;
                            transferin.FacilityFrom       = request.FacilityFrom;

                            var results = await registerPersonService.UpdatePatientTransferIn(transferin);

                            Id = results.Id;
                        }
                        else
                        {
                            PatientTransferIn pt = new PatientTransferIn();

                            pt.TransferInDate       = request.TransferInDate;
                            pt.TransferInNotes      = request.TransferInNotes;
                            pt.TreatmentStartDate   = TreatmentStartDate;
                            pt.FacilityFrom         = request.FacilityFrom;
                            pt.CountyFrom           = request.CountyFrom;
                            pt.CurrentTreatment     = request.CurrentTreatment;
                            pt.ServiceAreaId        = request.ServiceId;
                            pt.MflCode              = request.MflCode;
                            pt.PatientId            = request.PatientId;
                            pt.PatientMasterVisitId = PatientMasterVisitId;
                            pt.CreateDate           = DateTime.Now;
                            pt.CreatedBy            = request.CreatedBy;
                            pt.DeleteFlag           = request.DeleteFlag;
                            var results = await registerPersonService.AddPatientTransferIn(pt);

                            Id = results.Id;
                        }
                    }
                    return(Result <AddPatientTransferInResponse> .Valid(new AddPatientTransferInResponse()
                    {
                        TransferInId = Id
                    }));
                }
            }

            catch (Exception ex)
            {
                return(Result <AddPatientTransferInResponse> .Invalid(ex.Message));
            }
        }