Beispiel #1
0
        public async Task <Result <AddPregnancyCommandResult> > Handle(AddPregnancyCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var visitDetailsService = new VisitDetailsService(_unitOfWork);

                var patientPregnancy = new PatientPregnancy
                {
                    PatientId            = request.PatientId,
                    PatientMasterVisitId = request.PatientMasterVisitId,
                    CreateDate           = DateTime.Now,
                    CreatedBy            = request.CreatedBy,
                    DeleteFlag           = false,
                    Lmp           = request.Lmp,
                    Edd           = request.Edd,
                    Gestation     = request.Gestation,
                    Gravidae      = request.Gravidae,
                    Parity        = request.Parity,
                    Parity2       = request.Parity2,
                    AgeAtMenarche = request.AgeAtMenarche
                };

                var pregnancyResult = await visitDetailsService.AddPatientPregnancy(patientPregnancy);

                return(Result <AddPregnancyCommandResult> .Valid(new AddPregnancyCommandResult()
                {
                    PregnancyId = pregnancyResult.Id
                }));
            }
            catch (Exception e)
            {
                Log.Error(e.Message + " " + e.InnerException);
                return(Result <AddPregnancyCommandResult> .Invalid(e.Message));
            }
        }
Beispiel #2
0
        public async Task <Result <PatientProfile> > Handle(GetCurrentVisitDetailsCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    PatientPregnancy pregnancy = _unitOfWork.Repository <PatientPregnancy>()
                                                 .Get(x => x.Outcome == null && !x.DateOfOutcome.HasValue && !x.DeleteFlag).FirstOrDefault();

                    PatientProfile patientProfile = new PatientProfile();



                    if (pregnancy != null)
                    {
                        patientProfile = await _unitOfWork.Repository <PatientProfile>()
                                         .Get(x => x.PatientId == request.PatientId && !x.DeleteFlag && x.PregnancyId == pregnancy.Id)
                                         .FirstOrDefaultAsync();
                    }
                    else
                    {
                        patientProfile = await _unitOfWork.Repository <PatientProfile>()
                                         .Get(x => x.PatientId == request.PatientId && !x.DeleteFlag)
                                         .FirstOrDefaultAsync();
                    }

                    return(Result <PatientProfile> .Valid(patientProfile));
                }
                catch (Exception e)
                {
                    Log.Error(e.Message + " " + e.InnerException);
                    return(Result <PatientProfile> .Invalid(e.Message + " " + e.InnerException));
                }
            }
        }
        public async Task <Result <PregnancyViewModel> > Handle(GetPregnancyCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    PatientPregnancy result = await _unitOfWork.Repository <PatientPregnancy>().Get(x => x.PatientId == request.PatientId).OrderByDescending(x => x.Id).FirstOrDefaultAsync();

                    PregnancyViewModel pregnancyView = new PregnancyViewModel();;
                    if (result != null)
                    {
                        pregnancyView.Id                   = result.Id;
                        pregnancyView.PatientId            = result.PatientId;
                        pregnancyView.PatientMasterVisitId = result.PatientMasterVisitId;
                        pregnancyView.Lmp                  = result.Lmp;
                        pregnancyView.Edd                  = result.Edd;
                        pregnancyView.Gestation            = result.Gestation;
                        pregnancyView.Gravidae             = result.Gravidae;
                        pregnancyView.Parity               = result.Parity;
                        pregnancyView.Parity2              = result.Parity2;
                        pregnancyView.Outcome              = result.Outcome;
                        pregnancyView.DateOfOutcome        = result.DateOfOutcome;
                        pregnancyView.AgeAtMenarche        = result.AgeAtMenarche;
                    }

                    return(Result <PregnancyViewModel> .Valid(pregnancyView));
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                    return(Result <PregnancyViewModel> .Invalid(e.Message));
                }
            }
        }
Beispiel #4
0
 public PatientPregnancy GetActivePregnancy(int patientId)
 {
     try
     {
         PatientPregnancy activePregnancy = _unitOfWork.Repository <PatientPregnancy>()
                                            .Get(x => x.PatientId == patientId && !x.Outcome.HasValue).FirstOrDefault();
         return(activePregnancy);
     }
     catch (Exception e)
     {
         Log.Error(e.Message);
         throw e;
     }
 }
Beispiel #5
0
        public async Task <PatientPregnancy> GetPatientPregnancy(int PatientId)
        {
            try
            {
                PatientPregnancy _patientPregnancy = await _unitOfWork.Repository <PatientPregnancy>().Get(x => x.PatientId == PatientId).FirstOrDefaultAsync();

                return(_patientPregnancy);
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                throw e;
            }
        }
Beispiel #6
0
        public async Task <PatientPregnancy> EditPatientPregnancy(PatientPregnancy patientPregnancy)
        {
            try
            {
                _unitOfWork.Repository <PatientPregnancy>().Update(patientPregnancy);
                await _unitOfWork.SaveAsync();

                return(patientPregnancy);
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                throw e;
            }
        }
Beispiel #7
0
        public async Task <PatientPregnancy> EditPatientPreganancy(PatientPregnancy patientPregnancy)
        {
            try
            {
                PatientPregnancy _patientPregnancy = _unitOfWork.Repository <PatientPregnancy>().FindById(patientPregnancy.Id);
                _patientPregnancy.Lmp           = patientPregnancy.Lmp;
                _patientPregnancy.Edd           = patientPregnancy.Edd;
                _patientPregnancy.DateOfOutcome = patientPregnancy.DateOfOutcome;
                _patientPregnancy.Parity        = patientPregnancy.Parity;
                _patientPregnancy.Gravidae      = patientPregnancy.Parity;

                _unitOfWork.Repository <PatientPregnancy>().Update(_patientPregnancy);
                await _unitOfWork.SaveAsync();

                return(patientPregnancy);
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                throw e;
            }
        }
Beispiel #8
0
        public async Task <PatientPregnancy> AddPatientPregnancy(PatientPregnancy patientPregnancy)
        {
            try
            {
                var _activePregnancy = GetActivePregnancy(patientPregnancy.PatientId);
                if (_activePregnancy == null)
                {
                    await _unitOfWork.Repository <PatientPregnancy>().AddAsync(patientPregnancy);

                    await _unitOfWork.SaveAsync();

                    return(patientPregnancy);
                }
                else
                {
                    return(_activePregnancy);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                throw e;
            }
        }
Beispiel #9
0
        public async Task <Library.Result <VisitDetailsCommandResult> > Handle(VisitDetailsCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                int profileId = 0;

                try
                {
                    VisitDetailsService visitDetailsService      = new VisitDetailsService(_unitOfWork);
                    PregnancyServices   patientPregnancyServices = new PregnancyServices(_unitOfWork);

                    PatientPregnancy pregnancyData = patientPregnancyServices.GetActivePregnancy(request.PatientId);
                    if (pregnancyData != null)
                    {
                        this.PregnancyId = pregnancyData.Id;
                        VisitNumber      = visitDetailsService.GetNumberOfVisit(request.PatientId, pregnancyData.Id);
                        // check if the details have changed
                        if (pregnancyData.Lmp != request.Lmp || pregnancyData.Parity != request.ParityOne ||
                            pregnancyData.Parity2 != request.ParityTwo)
                        {
                            // TODO: insert into a tracking table
                        }
                    }
                    else
                    {
                        PatientPregnancy patientPregnancy = new PatientPregnancy()
                        {
                            PatientId            = request.PatientId,
                            PatientMasterVisitId = request.PatientMasterVisitId,
                            Lmp        = request.Lmp,
                            Edd        = request.Edd,
                            Parity     = request.ParityOne,
                            Parity2    = request.ParityTwo,
                            Gestation  = request.Gestation,
                            Gravidae   = request.Gravidae,
                            CreatedBy  = request.UserId,
                            CreateDate = DateTime.Now
                        };
                        this.Pregnancy = await visitDetailsService.AddPatientPregnancy(patientPregnancy);

                        this.PregnancyId = this.Pregnancy.Id;
                    }


                    PatientProfile patientProfile = new PatientProfile()
                    {
                        PatientId            = request.PatientId,
                        PatientMasterVisitId = request.PatientMasterVisitId,
                        AgeMenarche          = request.AgeAtMenarche,
                        PregnancyId          = this.PregnancyId,
                        VisitNumber          = (this.VisitNumber + 1),
                        VisitType            = request.VisitType,
                        CreatedBy            = (request.UserId < 1) ? 1 : request.UserId,
                        CreateDate           = DateTime.Now,
                    };
                    var profile = visitDetailsService.AddPatientProfile(patientProfile);
                    profileId = profile.Id;


                    return(Library.Result <VisitDetailsCommandResult> .Valid(new VisitDetailsCommandResult()
                    {
                        PregancyId = (this.VisitNumber >= 1)?this.PregnancyId:this.Pregnancy.Id,
                        ProfileId = profileId
                    }));
                }

                catch (Exception e)
                {
                    Log.Error(e.Message + " " + e.InnerException);
                    return(Library.Result <VisitDetailsCommandResult> .Invalid(e.Message));
                }
            }
        }