Exemplo n.º 1
0
        /*
         * ///<summary>Only used in GetSearchResults.  All times between start and stop get set to true in provBarSched.</summary>
         * private static void SetProvBarSched(ref bool[] provBarSched,TimeSpan timeStart,TimeSpan timeStop){
         *      int startI=GetProvBarIndex(timeStart);
         *      int stopI=GetProvBarIndex(timeStop);
         *      for(int i=startI;i<=stopI;i++){
         *              provBarSched[i]=true;
         *      }
         * }
         *
         * private static int GetProvBarIndex(TimeSpan time) {
         *      return (int)(((double)time.Hours*(double)60/(double)PrefC.GetLong(PrefName.AppointmentTimeIncrement)//aptTimeIncr=minutesPerIncr
         +(double)time.Minutes/(double)PrefC.GetLong(PrefName.AppointmentTimeIncrement))
         *(double)ApptDrawing.LineH*ApptDrawing.RowsPerIncr)
         *              /ApptDrawing.LineH;//rounds down
         * }*/

        ///<summary>Used by UI when it needs a recall appointment placed on the pinboard ready to schedule.  This method creates the appointment and attaches all appropriate procedures.  It's up to the calling class to then place the appointment on the pinboard.  If the appointment doesn't get scheduled, it's important to delete it.  If a recallNum is not 0 or -1, then it will create an appt of that recalltype.</summary>
        public static Appointment CreateRecallApt(Patient patCur, List <InsPlan> planList, long recallNum, List <InsSub> subList
                                                  , DateTime aptDateTime = default(DateTime))
        {
            List <Recall> recallList = Recalls.GetList(patCur.PatNum);
            Recall        recallCur  = null;

            if (recallNum > 0)
            {
                recallCur = Recalls.GetRecall(recallNum);
            }
            else
            {
                for (int i = 0; i < recallList.Count; i++)
                {
                    if (recallList[i].RecallTypeNum == RecallTypes.PerioType || recallList[i].RecallTypeNum == RecallTypes.ProphyType)
                    {
                        if (!recallList[i].IsDisabled)
                        {
                            recallCur = recallList[i];
                        }
                        break;
                    }
                }
            }
            if (recallCur == null)
            {
                //Typically never happens because everyone has a recall.  However, it can happen when patients have custom recalls due
                throw new ApplicationException(Lan.g("AppointmentL", "No special type recall is due."));
            }
            if (recallCur.DateScheduled.Date > DateTime.Today)
            {
                throw new ApplicationException(Lan.g("AppointmentL", "Recall has already been scheduled for ") + recallCur.DateScheduled.ToShortDateString());
            }
            Appointment aptCur = new Appointment();

            aptCur.AptDateTime = aptDateTime;
            List <string>    procs     = RecallTypes.GetProcs(recallCur.RecallTypeNum);
            List <Procedure> listProcs = Appointments.FillAppointmentForRecall(aptCur, recallCur, recallList, patCur, procs, planList, subList);

            for (int i = 0; i < listProcs.Count; i++)
            {
                if (Programs.UsingOrion)
                {
                    FormProcEdit FormP = new FormProcEdit(listProcs[i], patCur.Copy(), Patients.GetFamily(patCur.PatNum));
                    FormP.IsNew = true;
                    FormP.ShowDialog();
                    if (FormP.DialogResult == DialogResult.Cancel)
                    {
                        //any created claimprocs are automatically deleted from within procEdit window.
                        try {
                            Procedures.Delete(listProcs[i].ProcNum);                            //also deletes the claimprocs
                        }
                        catch (Exception ex) {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    else
                    {
                        //Do not synch. Recalls based on ScheduleByDate reports in Orion mode.
                        //Recalls.Synch(PatCur.PatNum);
                    }
                }
            }
            return(aptCur);
        }
Exemplo n.º 2
0
        /*
         * ///<summary>Only used in GetSearchResults.  All times between start and stop get set to true in provBarSched.</summary>
         * private static void SetProvBarSched(ref bool[] provBarSched,TimeSpan timeStart,TimeSpan timeStop){
         *      int startI=GetProvBarIndex(timeStart);
         *      int stopI=GetProvBarIndex(timeStop);
         *      for(int i=startI;i<=stopI;i++){
         *              provBarSched[i]=true;
         *      }
         * }
         *
         * private static int GetProvBarIndex(TimeSpan time) {
         *      return (int)(((double)time.Hours*(double)60/(double)PrefC.GetLong(PrefName.AppointmentTimeIncrement)//aptTimeIncr=minutesPerIncr
         +(double)time.Minutes/(double)PrefC.GetLong(PrefName.AppointmentTimeIncrement))
         *(double)ApptDrawing.LineH*ApptDrawing.RowsPerIncr)
         *              /ApptDrawing.LineH;//rounds down
         * }*/

        ///<summary>Used by UI when it needs a recall appointment placed on the pinboard ready to schedule.  This method creates the appointment and attaches all appropriate procedures.  It's up to the calling class to then place the appointment on the pinboard.  If the appointment doesn't get scheduled, it's important to delete it.  If a recallNum is not 0 or -1, then it will create an appt of that recalltype.</summary>
        public static Appointment CreateRecallApt(Patient patCur, List <Procedure> procList, List <InsPlan> planList, long recallNum, List <InsSub> subList)
        {
            List <Recall> recallList = Recalls.GetList(patCur.PatNum);
            Recall        recallCur  = null;

            if (recallNum > 0)
            {
                recallCur = Recalls.GetRecall(recallNum);
            }
            else
            {
                for (int i = 0; i < recallList.Count; i++)
                {
                    if (recallList[i].RecallTypeNum == RecallTypes.PerioType || recallList[i].RecallTypeNum == RecallTypes.ProphyType)
                    {
                        if (!recallList[i].IsDisabled)
                        {
                            recallCur = recallList[i];
                        }
                        break;
                    }
                }
            }
            if (recallCur == null)                                                          // || recallCur.DateDue.Year<1880){
            {
                throw new ApplicationException(Lan.g("AppointmentL", "No recall is due.")); //should never happen because everyone has a recall.
            }
            if (recallCur.DateScheduled.Date >= DateTime.Now.Date)
            {
                throw new ApplicationException(Lan.g("AppointmentL", "Recall has already been scheduled for ") + recallCur.DateScheduled.ToShortDateString());
            }
            Appointment AptCur = new Appointment();

            AptCur.PatNum    = patCur.PatNum;
            AptCur.AptStatus = ApptStatus.UnschedList;          //In all places where this is used, the unsched status with no aptDateTime will cause the appt to be deleted when the pinboard is cleared.
            if (patCur.PriProv == 0)
            {
                AptCur.ProvNum = PrefC.GetLong(PrefName.PracticeDefaultProv);
            }
            else
            {
                AptCur.ProvNum = patCur.PriProv;
            }
            AptCur.ProvHyg = patCur.SecProv;
            if (AptCur.ProvHyg != 0)
            {
                AptCur.IsHygiene = true;
            }
            AptCur.ClinicNum = patCur.ClinicNum;
            //whether perio or prophy:
            List <string> procs         = RecallTypes.GetProcs(recallCur.RecallTypeNum);
            string        recallPattern = RecallTypes.GetTimePattern(recallCur.RecallTypeNum);

            if (RecallTypes.IsSpecialRecallType(recallCur.RecallTypeNum) &&
                patCur.Birthdate.AddYears(12) > ((recallCur.DateDue > DateTime.Today)?recallCur.DateDue:DateTime.Today))                  //if pt's 12th birthday falls after recall date. ie younger than 12.
            {
                for (int i = 0; i < RecallTypeC.Listt.Count; i++)
                {
                    if (RecallTypeC.Listt[i].RecallTypeNum == RecallTypes.ChildProphyType)
                    {
                        List <string> childprocs = RecallTypes.GetProcs(RecallTypeC.Listt[i].RecallTypeNum);
                        if (childprocs.Count > 0)
                        {
                            procs = childprocs;                          //overrides adult procs.
                        }
                        string childpattern = RecallTypes.GetTimePattern(RecallTypeC.Listt[i].RecallTypeNum);
                        if (childpattern != "")
                        {
                            recallPattern = childpattern;                          //overrides adult pattern.
                        }
                    }
                }
            }
            //convert time pattern to 5 minute increment
            StringBuilder savePattern = new StringBuilder();

            for (int i = 0; i < recallPattern.Length; i++)
            {
                savePattern.Append(recallPattern.Substring(i, 1));
                if (PrefC.GetLong(PrefName.AppointmentTimeIncrement) == 10)
                {
                    savePattern.Append(recallPattern.Substring(i, 1));
                }
                if (PrefC.GetLong(PrefName.AppointmentTimeIncrement) == 15)
                {
                    savePattern.Append(recallPattern.Substring(i, 1));
                    savePattern.Append(recallPattern.Substring(i, 1));
                }
            }
            if (savePattern.ToString() == "")
            {
                if (PrefC.GetLong(PrefName.AppointmentTimeIncrement) == 15)
                {
                    savePattern.Append("///XXX///");
                }
                else
                {
                    savePattern.Append("//XX//");
                }
            }
            AptCur.Pattern = savePattern.ToString();
            //Add films------------------------------------------------------------------------------------------------------
            if (RecallTypes.IsSpecialRecallType(recallCur.RecallTypeNum))            //if this is a prophy or perio
            {
                for (int i = 0; i < recallList.Count; i++)
                {
                    if (recallCur.RecallNum == recallList[i].RecallNum)
                    {
                        continue;                        //already handled.
                    }
                    if (recallList[i].IsDisabled)
                    {
                        continue;
                    }
                    if (recallList[i].DateDue.Year < 1880)
                    {
                        continue;
                    }
                    if (recallList[i].DateDue > recallCur.DateDue &&              //if film due date is after prophy due date
                        recallList[i].DateDue > DateTime.Today)                         //and not overdue
                    {
                        continue;
                    }
                    //incomplete: exclude manual recall types
                    procs.AddRange(RecallTypes.GetProcs(recallList[i].RecallTypeNum));
                }
            }
            AptCur.ProcDescript = "";
            for (int i = 0; i < procs.Count; i++)
            {
                if (i > 0)
                {
                    AptCur.ProcDescript += ", ";
                }
                AptCur.ProcDescript += ProcedureCodes.GetProcCode(procs[i]).AbbrDesc;
            }
            Appointments.Insert(AptCur);
            Procedure      ProcCur;
            List <PatPlan> patPlanList = PatPlans.Refresh(patCur.PatNum);
            List <Benefit> benefitList = Benefits.Refresh(patPlanList, subList);
            InsPlan        priplan     = null;
            InsSub         prisub      = null;

            if (patPlanList.Count > 0)
            {
                prisub  = InsSubs.GetSub(patPlanList[0].InsSubNum, subList);
                priplan = InsPlans.GetPlan(prisub.PlanNum, planList);
            }
            double insfee;
            double standardfee;

            for (int i = 0; i < procs.Count; i++)
            {
                ProcCur = new Procedure();              //this will be an insert
                //procnum
                ProcCur.PatNum   = patCur.PatNum;
                ProcCur.AptNum   = AptCur.AptNum;
                ProcCur.CodeNum  = ProcedureCodes.GetCodeNum(procs[i]);
                ProcCur.ProcDate = DateTime.Now;
                ProcCur.DateTP   = DateTime.Now;
                //Check if it's a medical procedure.
                bool isMed = false;
                ProcCur.MedicalCode = ProcedureCodes.GetProcCode(ProcCur.CodeNum).MedicalCode;
                if (ProcCur.MedicalCode != null && ProcCur.MedicalCode != "")
                {
                    isMed = true;
                }
                //Get fee schedule for medical or dental.
                long feeSch;
                if (isMed)
                {
                    feeSch = Fees.GetMedFeeSched(patCur, planList, patPlanList, subList);
                }
                else
                {
                    feeSch = Fees.GetFeeSched(patCur, planList, patPlanList, subList);
                }
                //Get the fee amount for medical or dental.
                if (PrefC.GetBool(PrefName.MedicalFeeUsedForNewProcs) && isMed)
                {
                    insfee = Fees.GetAmount0(ProcedureCodes.GetProcCode(ProcCur.MedicalCode).CodeNum, feeSch);
                }
                else
                {
                    insfee = Fees.GetAmount0(ProcCur.CodeNum, feeSch);
                }
                if (priplan != null && priplan.PlanType == "p")             //PPO
                {
                    standardfee = Fees.GetAmount0(ProcCur.CodeNum, Providers.GetProv(Patients.GetProvNum(patCur)).FeeSched);
                    if (standardfee > insfee)
                    {
                        ProcCur.ProcFee = standardfee;
                    }
                    else
                    {
                        ProcCur.ProcFee = insfee;
                    }
                }
                else
                {
                    ProcCur.ProcFee = insfee;
                }
                //surf
                //toothnum
                //Procedures.Cur.ToothRange="";
                //ProcCur.NoBillIns=ProcedureCodes.GetProcCode(ProcCur.CodeNum).NoBillIns;
                //priority
                ProcCur.ProcStatus = ProcStat.TP;
                ProcCur.Note       = "";
                //Procedures.Cur.PriEstim=
                //Procedures.Cur.SecEstim=
                //claimnum
                ProcCur.ProvNum = patCur.PriProv;
                //Procedures.Cur.Dx=
                ProcCur.ClinicNum = patCur.ClinicNum;
                //nextaptnum
                ProcCur.BaseUnits = ProcedureCodes.GetProcCode(ProcCur.CodeNum).BaseUnits;
                Procedures.Insert(ProcCur);                //no recall synch required
                Procedures.ComputeEstimates(ProcCur, patCur.PatNum, new List <ClaimProc>(), false, planList, patPlanList, benefitList, patCur.Age, subList);
                if (Programs.UsingOrion)
                {
                    FormProcEdit FormP = new FormProcEdit(ProcCur, patCur.Copy(), Patients.GetFamily(patCur.PatNum));
                    FormP.IsNew = true;
                    FormP.ShowDialog();
                    if (FormP.DialogResult == DialogResult.Cancel)
                    {
                        //any created claimprocs are automatically deleted from within procEdit window.
                        try{
                            Procedures.Delete(ProcCur.ProcNum);                            //also deletes the claimprocs
                        }
                        catch (Exception ex) {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    else
                    {
                        //Do not synch. Recalls based on ScheduleByDate reports in Orion mode.
                        //Recalls.Synch(PatCur.PatNum);
                    }
                }
            }
            return(AptCur);
        }