/// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>A <see cref="Agatha.Common.Response"/></returns>
        public override Response Handle(DetachProblemFromVisitRequest request)
        {
            var problemDto = request.ProblemDto;
            var visitKey   = request.VisitKey;

            IList <ProblemDto> results = new List <ProblemDto> ();

            var visit = _visitRepository.GetByKey(visitKey);

            if (visit != null)
            {
                var problem = _problemRepository.GetByKey(problemDto.Key);
                if (problem != null)
                {
                    visit.DisassociateProblem(problem);
                }

                var visitDto = Mapper.Map <Visit, VisitDto> (visit);
                results = visitDto.Problems;
            }

            var response = CreateTypedResponse();

            response.ProblemDtos = results;

            return(response);
        }
Example #2
0
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>A <see cref="Agatha.Common.Response"/></returns>
        public override Response Handle(UpdateClinicianAppointmentRequest request)
        {
            var clinicianAppointmentDto = request.ClinicianAppointmentDto;
            var clinicianKey            = request.ClinicianKey;

            var visit = _visitRepository.GetByKey(clinicianAppointmentDto.Key);

            if (visit == null)
            {
                throw new ArgumentException(
                          "Could not find Visit Associated with ClinicianAppoitmentDto with key:" +
                          clinicianAppointmentDto.Key);
            }

            Staff newStaff = null;

            if (clinicianKey != visit.Staff.Key)
            {
                newStaff = _staffRepository.GetByKey(clinicianKey);
                if (newStaff == null)
                {
                    throw new ArgumentException("Could not find Staff with key:" + clinicianKey);
                }
            }

            if (visit.AppointmentDateTimeRange.StartDateTime != clinicianAppointmentDto.AppointmentStartDateTime ||
                visit.AppointmentDateTimeRange.EndDateTime != clinicianAppointmentDto.AppointmentEndDateTime)
            {
                visit.RescheduleAppointment(
                    new DateTimeRange(clinicianAppointmentDto.AppointmentStartDateTime, clinicianAppointmentDto.AppointmentEndDateTime));
            }

            if (newStaff != null)
            {
                visit.ReassignAppointment(newStaff);
            }

            clinicianAppointmentDto = new ClinicianAppointmentDto
            {
                Key                      = visit.Key,
                PatientKey               = visit.ClinicalCase.Patient.Key,
                PatientFirstName         = visit.ClinicalCase.Patient.Name.First,
                PatientLastName          = visit.ClinicalCase.Patient.Name.Last,
                AppointmentEndDateTime   = visit.AppointmentDateTimeRange.EndDateTime,
                AppointmentStartDateTime = visit.AppointmentDateTimeRange.StartDateTime,
                VisitStatus              = new LookupValueDto
                {
                    WellKnownName = visit.VisitStatus.WellKnownName,
                    Key           = visit.VisitStatus.Key,
                    Name          = visit.VisitStatus.Name
                },
                VisitTemplateName = visit.Name
            };

            var response = CreateTypedResponse();

            response.ClinicianAppointmentDto = clinicianAppointmentDto;

            return(response);
        }
Example #3
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key to create.</param>
        /// <returns>A <see cref="Rem.Ria.PatientModule.Web.Common.VisitDto"/></returns>
        public VisitDto CreateKeyedDto(long key)
        {
            var visit    = _visitRepository.GetByKey(key);
            var visitDto = Mapper.Map <Visit, VisitDto> (visit);

            return(visitDto);
        }
        private bool TryGetVisit(VisitDto dto, out Visit visit)
        {
            Check.IsNotNull(dto.Key, "Visit Key is required.");
            visit = _visitRepository.GetByKey(dto.Key);

            if (visit == null)
            {
                dto.AddDataErrorInfo(new DataErrorInfo("Visit not found.", ErrorLevel.Error));
                saveResult = false;
                return(false);
            }

            return(true);
        }
Example #5
0
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>A <see cref="Agatha.Common.Response"/></returns>
        public override Response Handle(DeleteClinicianAppointmentRequest request)
        {
            var clinicianKey = request.ClinicianKey;

            var visit = _visitRepository.GetByKey(clinicianKey);

            if (visit == null)
            {
                throw new ArgumentException("Could not find Visit Associated with ClinicianAppoitmentDto with key:" + clinicianKey);
            }

            ClinicianAppointmentDto clinicanAppointmentDto = null;

            if (visit.VisitStatus.WellKnownName.Equals(VisitStatus.Scheduled))
            {
                _visitFactory.DestroyVisit(visit);
            }
            else
            {
                clinicanAppointmentDto = new ClinicianAppointmentDto
                {
                    Key                      = visit.Key,
                    PatientKey               = visit.ClinicalCase.Patient.Key,
                    PatientFirstName         = visit.ClinicalCase.Patient.Name.First,
                    PatientLastName          = visit.ClinicalCase.Patient.Name.Last,
                    AppointmentEndDateTime   = visit.AppointmentDateTimeRange.EndDateTime,
                    AppointmentStartDateTime = visit.AppointmentDateTimeRange.StartDateTime,
                    VisitStatus              = new LookupValueDto
                    {
                        WellKnownName = visit.VisitStatus.WellKnownName,
                        Key           = visit.VisitStatus.Key,
                        Name          = visit.VisitStatus.Name
                    },
                    VisitTemplateName = visit.Name
                };

                var dataErrorInfo = new DataErrorInfo(
                    string.Format("Cannot remove an appointment with visit status as {0}.", visit.VisitStatus),
                    ErrorLevel.Error);
                clinicanAppointmentDto.AddDataErrorInfo(dataErrorInfo);
            }

            var response = CreateTypedResponse();

            response.ClinicianAppointmentDto = clinicanAppointmentDto;

            return(response);
        }
Example #6
0
        /// <summary>
        /// Schedules the activity.
        /// </summary>
        /// <param name="visitKey">The visit key.</param>
        /// <param name="activityType">Type of the activity.</param>
        /// <returns>An <see cref="Activity"/>. </returns>
        public Activity ScheduleActivity(long visitKey, ActivityType activityType)
        {
            var visit = _visitRepository.GetByKey(visitKey);

            Check.IsNotNull(visit, "Visit was not found to schedule activity of type: " + activityType.Name);

            Activity activity = null;

            if (_activityTypeFactoryDictionary.ContainsKey(activityType.WellKnownName))
            {
                var activityFactoryType = _activityTypeFactoryDictionary[activityType.WellKnownName];
                var activityFactory     = (IActivityFactory)IoC.CurrentContainer.Resolve(activityFactoryType);
                activity = activityFactory.CreateActivity(visit);
            }

            return(activity);
        }
Example #7
0
        /// <summary>
        /// Imports a visit from in the clinical system.
        /// </summary>
        /// <param name="visitKey">The visit key.</param>
        public virtual void ImportVisit(long visitKey)
        {
            var visit   = _visitRepository.GetByKey(visitKey);
            var patient = visit.ClinicalCase.Patient;
            var agency  = patient.Agency;

            var codingContext = _codingContextRepository.GetByVisitKey(visitKey);

            if (codingContext == null)
            {
                throw new ApplicationException("Coding context does not exist.");
            }

            //TODO: needs move this check into rule collections.
            // More rules such as needing primary payor, procedure codes, admin staff

            //var billingOffice = _billingOfficeRepository.GetByAgencyKey ( agency.Key );
            //if ( billingOffice == null )
            //{
            //    // If the billing office does not exist then we need to mark the coding context
            //    // with an error
            //    codingContext.ReportError ( Resource.BillingOfficeNotFoundCannotCreateEncounter );
            //}
            //else
            {
                var patientAccount = _patientAccountSynchronizationService.SynchronizePatientAccount(patient);

                var encounter = _encounterSynchronizationService.SynchronizeEncounter(patientAccount, visit);


                foreach (var procedure in codingContext.Procedures)
                {
                    //TODO: Get the diagnosis correctly. For now we get the diagnosis from the first Problem.
                    var visitProblem = visit.Problems.First();
                    var diagnosis    = visitProblem.Problem.ProblemCodeCodedConcept;

                    _serviceSynchronizationService.SynchronizeService(encounter, procedure, diagnosis);
                }

                var claim      = encounter.GenerateClaim();
                var claimBatch = claim.AssignClaimBatch();

                //var healthCareClaim837Professional = claimBatch.GenerateHealthCareClaim837Professional ();
            }
        }
Example #8
0
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>A <see cref="Agatha.Common.Response"/></returns>
        public override Response Handle(UpdateVisitStatusRequest request)
        {
            var visitStatusUpdateDto = request.VisitStatusUpdateDto;

            var visit = _visitRepository.GetByKey(visitStatusUpdateDto.VisitKey);

            if (visit == null)
            {
                throw new ArgumentException("Cannot find Visit with key:" + visitStatusUpdateDto.VisitKey);
            }

            var wellKnownName = visitStatusUpdateDto.VisitStatus.WellKnownName;

            if (visit.VisitStatus.WellKnownName != wellKnownName)
            {
                if (wellKnownName == VisitStatus.Scheduled)
                {
                    visit.MarkVisitStatusAsScheduled();
                }
                else if (wellKnownName == VisitStatus.CheckedIn)
                {
                    visit.CheckIn(visitStatusUpdateDto.UpdateDateTime);
                }
                else if (wellKnownName == VisitStatus.NoShow)
                {
                    visit.MarkVisitStatusAsNoShow();
                }
                else if (wellKnownName == VisitStatus.Canceled)
                {
                    visit.Cancel();
                }
                else
                {
                    throw new Exception("Invalid Visit Status: " + visitStatusUpdateDto.VisitStatus.Name);
                }
            }

            var response = CreateTypedResponse();

            response.VisitStatusUpdateDto = visitStatusUpdateDto;

            return(response);
        }
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>A <see cref="Agatha.Common.Response"/></returns>
        public override Response Handle(AssociateProblemsWithVisitRequest request)
        {
            var problemDtos = request.ProblemDtos;
            var visitKey    = request.VisitKey;

            IList <ProblemDto> results = new List <ProblemDto> ();

            var visit = _visitRepository.GetByKey(visitKey);

            if (visit != null)
            {
                var problemList = new List <Problem> ();
                foreach (var problemDto in problemDtos)
                {
                    var problem = _problemRepository.GetByKey(problemDto.Key);
                    if (problem != null)
                    {
                        problemList.Add(problem);
                    }
                }

                if (problemDtos.Count > 0)
                {
                    visit.AssociateProblems(problemList);
                }

                var visitDto = Mapper.Map <Visit, VisitDto> (visit);
                results = visitDto.Problems;
            }

            var response = CreateTypedResponse();

            response.ProblemDtos = results;

            return(response);
        }
Example #10
0
        public ActionResult ViewEditVisit(bool?isVisitEditing, int visitId)
        {
            Visit visit = visitRepository.GetByKey(visitId);

            return(ViewEditVisit(isVisitEditing, visit));
        }