Esempio n. 1
0
        /// <summary>
        /// Reschedules the visit.
        /// </summary>
        /// <param name="p">parameters</param>
        public void RescheduleVisit(VisitRescheduleVisitSP p)
        {
            IDoctorScheduleService doctorScheduleService = (IDoctorScheduleService)
                                                           EntityFactory.GetEntityServiceByName(vDoctorSchedule.EntityName, "");

            vVisit visit = GetByIDV(p.VisitID, new GetByIDParameters());

            OwnerPatientOrOwnerDoctorSecurity.Check("reschedule an appointment", visit, vVisit.ColumnNames.PatientUserID, vVisit.ColumnNames.DoctorID);

            DoctorSchedule oldDoctorSchedule = doctorScheduleService.GetByIDT(visit.DoctorScheduleID, new GetByIDParameters());
            DoctorSchedule newDoctorSchedule = doctorScheduleService.GetByIDT(p.NewDoctorScheduleID, new GetByIDParameters());

            // checking business rules
            ((VisitBR)BusinessLogicObject).RescheduleVisit(visit, oldDoctorSchedule, newDoctorSchedule);

            // updating old schedule (it should allow +1 number of patients)
            if (oldDoctorSchedule.NumberOfRegisteredPatients != 0)
            {
                oldDoctorSchedule.NumberOfRegisteredPatients--;
            }
            UpdateParameters updateParameters = new UpdateParameters();

            updateParameters.DetailEntityObjects.Add(new DetailObjectInfo()
            {
                EntityName = vDoctorSchedule.EntityName,
                EntitySet  = oldDoctorSchedule,
                FnName     = RuleFunctionSEnum.Update
            });

            // updating new schedule (it should allow -1 number of patients)
            newDoctorSchedule.NumberOfRegisteredPatients++;
            updateParameters.DetailEntityObjects.Add(new DetailObjectInfo()
            {
                EntityName = vDoctorSchedule.EntityName,
                EntitySet  = newDoctorSchedule,
                FnName     = RuleFunctionSEnum.Update
            });

            // Adding notification for user
            var notification = CreateScheduleNotification(visit);

            notification.NotificationTemplateID = (int)EntityEnums.NotificationTemplateEnum.VisitRescheduled;
            TemplateParams tmpP = new TemplateParams();

            tmpP.AddParameter("FromDate", DateTimeEpoch.ConvertUnixEpochToLocalTime(oldDoctorSchedule.SlotUnixEpoch, visit.PatientWorldTimeZoneID).ToString());
            tmpP.AddParameter("ToDate", DateTimeEpoch.ConvertUnixEpochToLocalTime(newDoctorSchedule.SlotUnixEpoch, visit.PatientWorldTimeZoneID).ToString());
            notification.ParametersValues = tmpP.SerializeToString();
            updateParameters.DetailEntityObjects.Add(new DetailObjectInfo()
            {
                EntityName = vNotification.EntityName,
                EntitySet  = notification,
                FnName     = RuleFunctionSEnum.Insert
            }
                                                     );

            // updating visit changes
            visit.DoctorScheduleID = p.NewDoctorScheduleID;
            Update(visit, updateParameters);
        }
Esempio n. 2
0
        /// <summary>
        /// Cancels a visit
        /// </summary>
        /// <param name="visitId">The visit identifier.</param>
        public void CancelVisit(long visitId)
        {
            vVisit visit = (vVisit)GetByIDV(visitId, new GetByIDParameters());

            ((VisitBR)BusinessLogicObject).CancelVisit(visit);

            OwnerPatientOrOwnerDoctorSecurity.Check("Cancel a visit", visit, vVisit.ColumnNames.PatientUserID, vVisit.ColumnNames.DoctorID);

            visit.VisitStatusID = (int)EntityEnums.VisitStatusEnum.Cancelled;

            // Automated refund removed to allow re-scheduling option to the patient

            //// if it had a payment and it was a completed payment then refund it
            //long paymentID = visit.VisitID;
            //IPaymentService paymentService = (IPaymentService)
            //    EntityFactory.GetEntityServiceByName(Payment.EntityName, "");
            //Payment payment = (Payment) paymentService.GetByID(paymentID, new GetByIDParameters());
            //if (payment != null)
            //{
            //    if (payment.PaymentStatusID == (int) EntityEnums.PaymentStatusEnum.Done)
            //    {
            //        paymentService.RefundPayment(visit.VisitID);
            //    }
            //}

            UpdateParameters updateParameters = new UpdateParameters();

            // Adding notification for user
            var notification = CreateScheduleNotification(visit);

            notification.NotificationTemplateID = (int)EntityEnums.NotificationTemplateEnum.VisitCanceled;
            TemplateParams p = new TemplateParams();

            p.AddParameter("Date", DateTimeEpoch.ConvertUnixEpochToLocalTime(visit.SlotUnixEpoch, visit.PatientWorldTimeZoneID).ToString());
            notification.ParametersValues = p.SerializeToString();
            updateParameters.DetailEntityObjects.Add(new DetailObjectInfo()
            {
                EntityName = vNotification.EntityName,
                EntitySet  = notification,
                FnName     = RuleFunctionSEnum.Insert
            }
                                                     );

            Update(visit, updateParameters);
        }