public async Task <Result <AddPNCVisitResponse> > Handle(AddPNCVisitCommand request, CancellationToken cancellationToken)
        {
            try
            {
                //PatientMasterVisitService patientMasterVisitService = new PatientMasterVisitService(_commonUnitOfWork);
                //PatientEncounterService patientEncounterService = new PatientEncounterService(_commonUnitOfWork);
                //LookupLogic lookupLogic = new LookupLogic(_commonUnitOfWork);
                VisitDetailsService visitDetailsService = new VisitDetailsService(_unitOfWork);

                //var patientMasterVisit = await patientMasterVisitService.Add(request.PatientId, 1, DateTime.Today, 0, request.VisitDate, request.VisitDate, 0, 0, request.VisitType, 0);

                //var encounterTypeId = await lookupLogic.GetLookupIdbyName(request.EncounterType);

                //var encounter = await patientEncounterService.Add(request.PatientId, encounterTypeId, patientMasterVisit.Id, DateTime.Now, DateTime.Now, request.ServiceAreaId, request.UserId);

                PatientProfile patientProfile = new PatientProfile()
                {
                    PatientId            = request.PatientId,
                    PatientMasterVisitId = request.PatientMasterVisitId,
                    VisitType            = request.VisitType,
                    CreatedBy            = (request.UserId < 1) ? 1 : request.UserId,
                    CreateDate           = DateTime.Now,
                    DaysPostPartum       = request.DaysPostPartum,
                    VisitNumber          = request.VisitNumber,
                    AgeMenarche          = request.AgeMenarche
                };

                var profile = await visitDetailsService.AddPatientProfile(patientProfile);

                return(Result <AddPNCVisitResponse> .Valid(new AddPNCVisitResponse { ProfileId = profile.Id }));
            }
            catch (Exception ex)
            {
                Log.Error("An error occured while adding PNC patient visit details", ex);
                return(Result <AddPNCVisitResponse> .Invalid(ex.Message));
            }
        }
Exemplo n.º 2
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));
                }
            }
        }