Example #1
0
        ///<summary>Sets given appt.AptStatus to broken.
        ///Provide procCode that should be charted, can be null but will not chart a broken procedure.
        ///Also considers various broken procedure based prefs.
        ///Makes its own securitylog entries.</summary>
        public static void BreakApptHelper(Appointment appt, Patient pat, ProcedureCode procCode)
        {
            //suppressHistory is true due to below logic creating a log with a specific HistAppointmentAction instead of the generic changed.
            DateTime datePrevious    = appt.DateTStamp;
            bool     suppressHistory = false;

            if (procCode != null)
            {
                suppressHistory = (procCode.ProcCode.In("D9986", "D9987"));
            }
            Appointments.SetAptStatus(appt, ApptStatus.Broken, suppressHistory); //Appointments S-Class handles Signalods
            if (appt.AptStatus != ApptStatus.Complete)                           //seperate log entry for completed appointments.
            {
                SecurityLogs.MakeLogEntry(Permissions.AppointmentEdit, pat.PatNum,
                                          appt.ProcDescript + ", " + appt.AptDateTime.ToString()
                                          + ", Broken from the Appts module.", appt.AptNum, datePrevious);
            }
            else
            {
                SecurityLogs.MakeLogEntry(Permissions.AppointmentCompleteEdit, pat.PatNum,
                                          appt.ProcDescript + ", " + appt.AptDateTime.ToString()
                                          + ", Broken from the Appts module.", appt.AptNum, datePrevious);
            }
            #region HL7
            //If there is an existing HL7 def enabled, send a SIU message if there is an outbound SIU message defined
            if (HL7Defs.IsExistingHL7Enabled())
            {
                //S15 - Appt Cancellation event
                MessageHL7 messageHL7 = MessageConstructor.GenerateSIU(pat, Patients.GetPat(pat.Guarantor), EventTypeHL7.S15, appt);
                //Will be null if there is no outbound SIU message defined, so do nothing
                if (messageHL7 != null)
                {
                    HL7Msg hl7Msg = new HL7Msg();
                    hl7Msg.AptNum    = appt.AptNum;
                    hl7Msg.HL7Status = HL7MessageStatus.OutPending;                  //it will be marked outSent by the HL7 service.
                    hl7Msg.MsgText   = messageHL7.ToString();
                    hl7Msg.PatNum    = pat.PatNum;
                    HL7Msgs.Insert(hl7Msg);
#if DEBUG
                    MessageBox.Show("Appointments", messageHL7.ToString());
#endif
                }
            }
            #endregion
            #region Charting the proc
            if (procCode != null)
            {
                switch (procCode.ProcCode)
                {
                case "D9986":                        //Missed
                    HistAppointments.CreateHistoryEntry(appt.AptNum, HistAppointmentAction.Missed);
                    break;

                case "D9987":                        //Cancelled
                    HistAppointments.CreateHistoryEntry(appt.AptNum, HistAppointmentAction.Cancelled);
                    break;
                }
                Procedure procedureCur = new Procedure();
                procedureCur.PatNum       = pat.PatNum;
                procedureCur.ProvNum      = (procCode.ProvNumDefault > 0 ? procCode.ProvNumDefault : appt.ProvNum);
                procedureCur.CodeNum      = procCode.CodeNum;
                procedureCur.ProcDate     = DateTime.Today;
                procedureCur.DateEntryC   = DateTime.Now;
                procedureCur.ProcStatus   = ProcStat.C;
                procedureCur.ClinicNum    = appt.ClinicNum;
                procedureCur.UserNum      = Security.CurUser.UserNum;
                procedureCur.Note         = Lans.g("AppointmentEdit", "Appt BROKEN for") + " " + appt.ProcDescript + "  " + appt.AptDateTime.ToString();
                procedureCur.PlaceService = (PlaceOfService)PrefC.GetInt(PrefName.DefaultProcedurePlaceService);              //Default proc place of service for the Practice is used.
                List <InsSub>  listInsSubs    = InsSubs.RefreshForFam(Patients.GetFamily(pat.PatNum));
                List <InsPlan> listInsPlans   = InsPlans.RefreshForSubList(listInsSubs);
                List <PatPlan> listPatPlans   = PatPlans.Refresh(pat.PatNum);
                InsPlan        insPlanPrimary = null;
                InsSub         insSubPrimary  = null;
                if (listPatPlans.Count > 0)
                {
                    insSubPrimary  = InsSubs.GetSub(listPatPlans[0].InsSubNum, listInsSubs);
                    insPlanPrimary = InsPlans.GetPlan(insSubPrimary.PlanNum, listInsPlans);
                }
                double procFee;
                long   feeSch;
                if (insPlanPrimary == null || procCode.NoBillIns)
                {
                    feeSch = FeeScheds.GetFeeSched(0, pat.FeeSched, procedureCur.ProvNum);
                }
                else                  //Only take into account the patient's insurance fee schedule if the D9986 procedure is not marked as NoBillIns
                {
                    feeSch = FeeScheds.GetFeeSched(insPlanPrimary.FeeSched, pat.FeeSched, procedureCur.ProvNum);
                }
                procFee = Fees.GetAmount0(procedureCur.CodeNum, feeSch, procedureCur.ClinicNum, procedureCur.ProvNum);
                if (insPlanPrimary != null && insPlanPrimary.PlanType == "p" && !insPlanPrimary.IsMedical)         //PPO
                {
                    double provFee = Fees.GetAmount0(procedureCur.CodeNum, Providers.GetProv(procedureCur.ProvNum).FeeSched, procedureCur.ClinicNum,
                                                     procedureCur.ProvNum);
                    procedureCur.ProcFee = Math.Max(provFee, procFee);
                }
                else
                {
                    procedureCur.ProcFee = procFee;
                }
                if (!PrefC.GetBool(PrefName.EasyHidePublicHealth))
                {
                    procedureCur.SiteNum = pat.SiteNum;
                }
                Procedures.Insert(procedureCur);
                //Now make a claimproc if the patient has insurance.  We do this now for consistency because a claimproc could get created in the future.
                List <Benefit>   listBenefits          = Benefits.Refresh(listPatPlans, listInsSubs);
                List <ClaimProc> listClaimProcsForProc = ClaimProcs.RefreshForProc(procedureCur.ProcNum);
                Procedures.ComputeEstimates(procedureCur, pat.PatNum, listClaimProcsForProc, false, listInsPlans, listPatPlans, listBenefits, pat.Age, listInsSubs);
                FormProcBroken FormPB = new FormProcBroken(procedureCur);
                FormPB.IsNew = true;
                FormPB.ShowDialog();
            }
            #endregion
            #region BrokenApptAdjustment
            if (PrefC.GetBool(PrefName.BrokenApptAdjustment))
            {
                Adjustment AdjustmentCur = new Adjustment();
                AdjustmentCur.DateEntry = DateTime.Today;
                AdjustmentCur.AdjDate   = DateTime.Today;
                AdjustmentCur.ProcDate  = DateTime.Today;
                AdjustmentCur.ProvNum   = appt.ProvNum;
                AdjustmentCur.PatNum    = pat.PatNum;
                AdjustmentCur.AdjType   = PrefC.GetLong(PrefName.BrokenAppointmentAdjustmentType);
                AdjustmentCur.ClinicNum = appt.ClinicNum;
                FormAdjust FormA = new FormAdjust(pat, AdjustmentCur);
                FormA.IsNew = true;
                FormA.ShowDialog();
            }
            #endregion
            #region BrokenApptCommLog
            if (PrefC.GetBool(PrefName.BrokenApptCommLog))
            {
                Commlog CommlogCur = new Commlog();
                CommlogCur.PatNum       = pat.PatNum;
                CommlogCur.CommDateTime = DateTime.Now;
                CommlogCur.CommType     = Commlogs.GetTypeAuto(CommItemTypeAuto.APPT);
                CommlogCur.Note         = Lan.g("Appointment", "Appt BROKEN for") + " " + appt.ProcDescript + "  " + appt.AptDateTime.ToString();
                CommlogCur.Mode_        = CommItemMode.None;
                CommlogCur.UserNum      = Security.CurUser.UserNum;
                FormCommItem FormCI = new FormCommItem();
                FormCI.ShowDialog(new CommItemModel()
                {
                    CommlogCur = CommlogCur
                }, new CommItemController(FormCI)
                {
                    IsNew = true
                });
            }
            #endregion
            AutomationL.Trigger(AutomationTrigger.BreakAppointment, null, pat.PatNum);
            Recalls.SynchScheduledApptFull(appt.PatNum);
        }
        private void butOK_Click(object sender, System.EventArgs e)
        {
            int    feeSched = DefB.Short[(int)DefCat.FeeSchedNames][listFeeSched.SelectedIndex].DefNum;
            string catName  = ""; //string to hold current category name
            Fees   fee      = new Fees();

            Queries.CurReport = new ReportOld();

            Queries.CurReport.Query = "SELECT procedurecode.ProcCode,fee.Amount,'     ',procedurecode.Descript,"
                                      + "procedurecode.AbbrDesc FROM procedurecode,fee "
                                      + "WHERE procedurecode.CodeNum=fee.CodeNum AND fee.FeeSched='" + feeSched.ToString()
                                      + "' ORDER BY procedurecode.ProcCode";
            FormQuery2          = new FormQuery();
            FormQuery2.IsReport = true;
            if (radioCode.Checked == true)
            {
                FormQuery2.SubmitReportQuery();
                Queries.CurReport.Title         = "Procedure Codes";
                Queries.CurReport.SubTitle      = new string[2];
                Queries.CurReport.SubTitle[0]   = ((Pref)PrefB.HList["PracticeTitle"]).ValueString;
                Queries.CurReport.SubTitle[1]   = DefB.GetName(DefCat.FeeSchedNames, feeSched);
                Queries.CurReport.ColPos        = new int[6];
                Queries.CurReport.ColCaption    = new string[5];
                Queries.CurReport.ColAlign      = new HorizontalAlignment[5];
                Queries.CurReport.ColPos[0]     = 60;
                Queries.CurReport.ColPos[1]     = 130;
                Queries.CurReport.ColPos[2]     = 200;
                Queries.CurReport.ColPos[3]     = 220;
                Queries.CurReport.ColPos[4]     = 420;
                Queries.CurReport.ColPos[5]     = 620;
                Queries.CurReport.ColCaption[0] = "Code";
                Queries.CurReport.ColCaption[1] = "Fee Amount";
                Queries.CurReport.ColCaption[2] = " ";              //otherwise, the amount gets bunched up next to the description.
                Queries.CurReport.ColCaption[3] = "Description";
                Queries.CurReport.ColCaption[4] = "Abbr Description";
                //Queries.CurReport.ColCaption[3]="Fee Amount";
                Queries.CurReport.ColAlign[1] = HorizontalAlignment.Right;
                Queries.CurReport.Summary     = new string[0];
                FormQuery2.ShowDialog();
                DialogResult = DialogResult.OK;
            }
            else                      //categories
            {
                Queries.SubmitTemp(); //create TableTemp which is not actually used
                ProcedureCode[] ProcList = ProcedureCodes.GetProcList();
                Queries.TableQ = new DataTable(null);
                for (int i = 0; i < 5; i++)                                   //add columns
                {
                    Queries.TableQ.Columns.Add(new System.Data.DataColumn()); //blank columns
                }
                Queries.CurReport.ColTotal = new double[Queries.TableQ.Columns.Count];
                DataRow row = Queries.TableQ.NewRow();//add first row by hand to get value for temp
                row[0]  = DefB.GetName(DefCat.ProcCodeCats, ProcList[0].ProcCat);
                catName = row[0].ToString();
                row[1]  = ProcList[0].ProcCode;
                row[2]  = ProcList[0].Descript;
                row[3]  = ProcList[0].AbbrDesc;
                row[4]  = ((double)Fees.GetAmount0(ProcList[0].CodeNum, feeSched)).ToString("F");
                Queries.CurReport.ColTotal[4] += PIn.PDouble(row[4].ToString());
                Queries.TableQ.Rows.Add(row);
                for (int i = 1; i < ProcList.Length; i++)          //loop through data rows
                {
                    row    = Queries.TableQ.NewRow();              //create new row called 'row' based on structure of TableQ
                    row[0] = DefB.GetName(DefCat.ProcCodeCats, ProcList[i].ProcCat);
                    if (catName == row[0].ToString())
                    {
                        row[0] = "";
                    }
                    else
                    {
                        catName = row[0].ToString();
                    }
                    row[1] = ProcList[i].ProcCode.ToString();
                    row[2] = ProcList[i].Descript;
                    row[3] = ProcList[i].AbbrDesc.ToString();
                    row[4] = ((double)Fees.GetAmount0(ProcList[i].CodeNum, feeSched)).ToString("F");
                    //Queries.CurReport.ColTotal[4]+=PIn.PDouble(row[4].ToString());
                    Queries.TableQ.Rows.Add(row);
                }
                Queries.CurReport.ColWidth   = new int[Queries.TableQ.Columns.Count];
                Queries.CurReport.ColPos     = new int[Queries.TableQ.Columns.Count + 1];
                Queries.CurReport.ColPos[0]  = 0;
                Queries.CurReport.ColCaption = new string[Queries.TableQ.Columns.Count];
                Queries.CurReport.ColAlign   = new HorizontalAlignment[Queries.TableQ.Columns.Count];
                FormQuery2.ResetGrid();                //this is a method in FormQuery2;

                Queries.CurReport.Title         = "Procedure Codes";
                Queries.CurReport.SubTitle      = new string[5];
                Queries.CurReport.SubTitle[0]   = ((Pref)PrefB.HList["PracticeTitle"]).ValueString;
                Queries.CurReport.SubTitle[1]   = DefB.GetName(DefCat.FeeSchedNames, feeSched);
                Queries.CurReport.ColPos[0]     = 20;
                Queries.CurReport.ColPos[1]     = 120;
                Queries.CurReport.ColPos[2]     = 270;
                Queries.CurReport.ColPos[3]     = 470;
                Queries.CurReport.ColPos[4]     = 620;
                Queries.CurReport.ColPos[5]     = 770;
                Queries.CurReport.ColCaption[0] = "Category";
                Queries.CurReport.ColCaption[1] = "Code";
                Queries.CurReport.ColCaption[2] = "Description";
                Queries.CurReport.ColCaption[3] = "Abbr Description";
                Queries.CurReport.ColCaption[4] = "Fee Amount";
                Queries.CurReport.ColAlign[4]   = HorizontalAlignment.Right;
                Queries.CurReport.Summary       = new string[5];
                FormQuery2.ShowDialog();
                DialogResult = DialogResult.OK;
            }
        }
Example #3
0
        ///<summary>Updates all claimproc estimates and also updates claim totals to db. Must supply procList which includes all procedures that this claim is linked to.  Will also need to refresh afterwards to see the results</summary>
        public static void CalculateAndUpdate(List <Procedure> procList, List <InsPlan> planList, Claim claimCur, List <PatPlan> patPlans, List <Benefit> benefitList, int patientAge, List <InsSub> subList)
        {
            //we need more than just the claimprocs for this claim.
            //in order to run Procedures.ComputeEstimates, we need all claimprocs for all procedures attached to this claim
            List <ClaimProc> ClaimProcsAll      = ClaimProcs.Refresh(claimCur.PatNum);
            List <ClaimProc> ClaimProcsForClaim = ClaimProcs.RefreshForClaim(claimCur.ClaimNum);         //will be ordered by line number.
            double           claimFee           = 0;
            double           dedApplied         = 0;
            double           insPayEst          = 0;
            double           insPayAmt          = 0;
            double           writeoff           = 0;
            InsPlan          plan = InsPlans.GetPlan(claimCur.PlanNum, planList);

            if (plan == null)
            {
                return;
            }
            long patPlanNum = PatPlans.GetPatPlanNum(claimCur.InsSubNum, patPlans);

            //first loop handles totals for received items.
            for (int i = 0; i < ClaimProcsForClaim.Count; i++)
            {
                if (ClaimProcsForClaim[i].Status != ClaimProcStatus.Received)
                {
                    continue;                    //disregard any status except Receieved.
                }
                claimFee   += ClaimProcsForClaim[i].FeeBilled;
                dedApplied += ClaimProcsForClaim[i].DedApplied;
                insPayEst  += ClaimProcsForClaim[i].InsPayEst;
                insPayAmt  += ClaimProcsForClaim[i].InsPayAmt;
                writeoff   += ClaimProcsForClaim[i].WriteOff;
            }
            //loop again only for procs not received.
            //And for preauth.
            Procedure ProcCur;
            //InsPlan plan=InsPlans.GetPlan(claimCur.PlanNum,planList);
            List <ClaimProcHist> histList         = ClaimProcs.GetHistList(claimCur.PatNum, benefitList, patPlans, planList, claimCur.ClaimNum, claimCur.DateService, subList);
            List <ClaimProc>     claimProcListOld = new List <ClaimProc>();    //make a copy

            for (int i = 0; i < ClaimProcsAll.Count; i++)
            {
                claimProcListOld.Add(ClaimProcsAll[i].Copy());
            }
            List <ClaimProcHist> loopList = new List <ClaimProcHist>();

            for (int i = 0; i < ClaimProcsForClaim.Count; i++)       //loop through each proc
            {
                ProcCur = Procedures.GetProcFromList(procList, ClaimProcsForClaim[i].ProcNum);
                //in order for ComputeEstimates to give accurate Writeoff when creating a claim, InsPayEst must be filled for the claimproc with status of NotReceived.
                //So, we must set it here.  We need to set it in the claimProcsAll list.  Find the matching one.
                for (int j = 0; j < ClaimProcsAll.Count; j++)
                {
                    if (ClaimProcsAll[j].ClaimProcNum == ClaimProcsForClaim[i].ClaimProcNum)                  //same claimproc in a different list
                    {
                        if (ClaimProcsForClaim[i].Status == ClaimProcStatus.NotReceived &&
                            ProcCur != null)                             //ignores payments, etc
                        {
                            ClaimProcsAll[j].InsPayEst = ClaimProcs.GetInsEstTotal(ClaimProcsAll[j]);
                        }
                    }
                }
                //When this is the secondary claim, HistList includes the primary estimates, which is something we don't want because the primary calculations gets confused.
                //So, we must remove those bad entries from histList.
                for (int h = histList.Count - 1; h >= 0; h--)         //loop through the histList backwards
                {
                    if (histList[h].ProcNum != ProcCur.ProcNum)
                    {
                        continue;                        //Makes sure we will only be excluding histList entries for procs on this claim.
                    }
                    //we already excluded this claimNum when getting the histList.
                    if (histList[h].Status != ClaimProcStatus.NotReceived)
                    {
                        continue;                        //The only ones that are a problem are the ones on the primary claim not received yet.
                    }
                    histList.RemoveAt(h);
                }
                Procedures.ComputeEstimates(ProcCur, claimCur.PatNum, ref ClaimProcsAll, false, planList, patPlans, benefitList, histList, loopList, false, patientAge, subList);
                //then, add this information to loopList so that the next procedure is aware of it.
                loopList.AddRange(ClaimProcs.GetHistForProc(ClaimProcsAll, ProcCur.ProcNum, ProcCur.CodeNum));
            }
            //save changes in the list to the database
            ClaimProcs.Synch(ref ClaimProcsAll, claimProcListOld);
            ClaimProcsForClaim = ClaimProcs.RefreshForClaim(claimCur.ClaimNum);
            //But ClaimProcsAll has not been refreshed.
            for (int i = 0; i < ClaimProcsForClaim.Count; i++)
            {
                if (ClaimProcsForClaim[i].Status != ClaimProcStatus.NotReceived &&
                    ClaimProcsForClaim[i].Status != ClaimProcStatus.Preauth &&
                    ClaimProcsForClaim[i].Status != ClaimProcStatus.CapClaim)
                {
                    continue;
                }
                ProcCur = Procedures.GetProcFromList(procList, ClaimProcsForClaim[i].ProcNum);
                if (ProcCur.ProcNum == 0)
                {
                    continue;                    //ignores payments, etc
                }
                //fee:
                int qty = ProcCur.UnitQty + ProcCur.BaseUnits;
                if (qty == 0)
                {
                    qty = 1;
                }
                if (plan.ClaimsUseUCR)                 //use UCR for the provider of the procedure
                {
                    long provNum = ProcCur.ProvNum;
                    if (provNum == 0)                   //if no prov set, then use practice default.
                    {
                        provNum = PrefC.GetLong(PrefName.PracticeDefaultProv);
                    }
                    //get the fee based on code and prov fee sched
                    double feebilled = Fees.GetAmount0(ProcCur.CodeNum, ProviderC.ListLong[Providers.GetIndexLong(provNum)].FeeSched);
                    if (feebilled > ProcCur.ProcFee)
                    {
                        ClaimProcsForClaim[i].FeeBilled = qty * feebilled;
                    }
                    else
                    {
                        ClaimProcsForClaim[i].FeeBilled = qty * ProcCur.ProcFee;
                    }
                }
                //else if(claimCur.ClaimType=="Cap") {//Even for capitation, use the proc fee.
                //	ClaimProcsForClaim[i].FeeBilled=0;
                //}
                else                  //don't use ucr.  Use the procedure fee instead.
                {
                    ClaimProcsForClaim[i].FeeBilled = qty * ProcCur.ProcFee;
                }
                claimFee += ClaimProcsForClaim[i].FeeBilled;
                if (claimCur.ClaimType == "PreAuth" || claimCur.ClaimType == "Other" || claimCur.ClaimType == "Cap")
                {
                    //only the fee gets calculated, the rest does not
                    ClaimProcs.Update(ClaimProcsForClaim[i]);
                    continue;
                }
                //ClaimProcs.ComputeBaseEst(ClaimProcsForClaim[i],ProcCur.ProcFee,ProcCur.ToothNum,ProcCur.CodeNum,plan,patPlanNum,benefitList,histList,loopList);
                ClaimProcsForClaim[i].InsPayEst  = ClaimProcs.GetInsEstTotal(ClaimProcsForClaim[i]); //Yes, this is duplicated from further up.
                ClaimProcsForClaim[i].DedApplied = ClaimProcs.GetDedEst(ClaimProcsForClaim[i]);
                if (ClaimProcsForClaim[i].Status == ClaimProcStatus.NotReceived)                     //(vs preauth)
                {
                    ClaimProcsForClaim[i].WriteOff = ClaimProcs.GetWriteOffEstimate(ClaimProcsForClaim[i]);
                    writeoff += ClaimProcsForClaim[i].WriteOff;

                    /*
                     * ClaimProcsForClaim[i].WriteOff=0;
                     * if(claimCur.ClaimType=="P" && plan.PlanType=="p") {//Primary && PPO
                     *      double insplanAllowed=Fees.GetAmount(ProcCur.CodeNum,plan.FeeSched);
                     *      if(insplanAllowed!=-1) {
                     *              ClaimProcsForClaim[i].WriteOff=ProcCur.ProcFee-insplanAllowed;
                     *      }
                     *      //else, if -1 fee not found, then do not show a writeoff. User can change writeoff if they disagree.
                     * }
                     * writeoff+=ClaimProcsForClaim[i].WriteOff;*/
                }
                dedApplied += ClaimProcsForClaim[i].DedApplied;
                insPayEst  += ClaimProcsForClaim[i].InsPayEst;
                ClaimProcsForClaim[i].ProcDate = ProcCur.ProcDate.Date;              //this solves a rare bug. Keeps dates synched.
                //It's rare enough that I'm not goint to add it to the db maint tool.
                ClaimProcs.Update(ClaimProcsForClaim[i]);
                //but notice that the ClaimProcs lists are not refreshed until the loop is finished.
            }            //for claimprocs.forclaim
            claimCur.ClaimFee   = claimFee;
            claimCur.DedApplied = dedApplied;
            claimCur.InsPayEst  = insPayEst;
            claimCur.InsPayAmt  = insPayAmt;
            claimCur.WriteOff   = writeoff;
            //Cur=ClaimCur;
            Claims.Update(claimCur);
        }
Example #4
0
        ///<summary>Sets given appt.AptStatus to broken.
        ///Provide procCode that should be charted, can be null but will not chart a broken procedure.
        ///Also considers various broken procedure based prefs.
        ///Makes its own securitylog entries.</summary>
        public static void BreakApptHelper(Appointment appt, Patient pat, ProcedureCode procCode)
        {
            //suppressHistory is true due to below logic creating a log with a specific HistAppointmentAction instead of the generic changed.
            DateTime datePrevious    = appt.DateTStamp;
            bool     suppressHistory = false;

            if (procCode != null)
            {
                suppressHistory = (procCode.ProcCode.In("D9986", "D9987"));
            }
            Appointments.SetAptStatus(appt, ApptStatus.Broken, suppressHistory); //Appointments S-Class handles Signalods
            if (appt.AptStatus != ApptStatus.Complete)                           //seperate log entry for completed appointments.
            {
                SecurityLogs.MakeLogEntry(Permissions.AppointmentEdit, pat.PatNum,
                                          appt.ProcDescript + ", " + appt.AptDateTime.ToString()
                                          + ", Broken from the Appts module.", appt.AptNum, datePrevious);
            }
            else
            {
                SecurityLogs.MakeLogEntry(Permissions.AppointmentCompleteEdit, pat.PatNum,
                                          appt.ProcDescript + ", " + appt.AptDateTime.ToString()
                                          + ", Broken from the Appts module.", appt.AptNum, datePrevious);
            }
            #region HL7
            //If there is an existing HL7 def enabled, send a SIU message if there is an outbound SIU message defined
            if (HL7Defs.IsExistingHL7Enabled())
            {
                //S15 - Appt Cancellation event
                MessageHL7 messageHL7 = MessageConstructor.GenerateSIU(pat, Patients.GetPat(pat.Guarantor), EventTypeHL7.S15, appt);
                //Will be null if there is no outbound SIU message defined, so do nothing
                if (messageHL7 != null)
                {
                    HL7Msg hl7Msg = new HL7Msg();
                    hl7Msg.AptNum    = appt.AptNum;
                    hl7Msg.HL7Status = HL7MessageStatus.OutPending;                  //it will be marked outSent by the HL7 service.
                    hl7Msg.MsgText   = messageHL7.ToString();
                    hl7Msg.PatNum    = pat.PatNum;
                    HL7Msgs.Insert(hl7Msg);
#if DEBUG
                    MessageBox.Show("Appointments", messageHL7.ToString());
#endif
                }
            }
            #endregion
            List <Procedure> listProcedures = new List <Procedure>();
            //splits should only exist on procs if they are using tp pre-payments
            List <PaySplit> listSplitsForApptProcs = new List <PaySplit>();
            bool            isNonRefundable        = false;
            double          brokenProcAmount       = 0;
            Procedure       brokenProcedure        = new Procedure();
            bool            wasBrokenProcDeleted   = false;
            if (PrefC.GetYN(PrefName.PrePayAllowedForTpProcs))
            {
                listProcedures = Procedures.GetProcsForSingle(appt.AptNum, false);
                if (listProcedures.Count > 0)
                {
                    listSplitsForApptProcs = PaySplits.GetPaySplitsFromProcs(listProcedures.Select(x => x.ProcNum).ToList());
                }
            }
            #region Charting the proc
            if (procCode != null)
            {
                switch (procCode.ProcCode)
                {
                case "D9986":                        //Missed
                    HistAppointments.CreateHistoryEntry(appt.AptNum, HistAppointmentAction.Missed);
                    break;

                case "D9987":                        //Cancelled
                    HistAppointments.CreateHistoryEntry(appt.AptNum, HistAppointmentAction.Cancelled);
                    break;
                }
                brokenProcedure.PatNum       = pat.PatNum;
                brokenProcedure.ProvNum      = (procCode.ProvNumDefault > 0 ? procCode.ProvNumDefault : appt.ProvNum);
                brokenProcedure.CodeNum      = procCode.CodeNum;
                brokenProcedure.ProcDate     = DateTime.Today;
                brokenProcedure.DateEntryC   = DateTime.Now;
                brokenProcedure.ProcStatus   = ProcStat.C;
                brokenProcedure.ClinicNum    = appt.ClinicNum;
                brokenProcedure.UserNum      = Security.CurUser.UserNum;
                brokenProcedure.Note         = Lans.g("AppointmentEdit", "Appt BROKEN for") + " " + appt.ProcDescript + "  " + appt.AptDateTime.ToString();
                brokenProcedure.PlaceService = (PlaceOfService)PrefC.GetInt(PrefName.DefaultProcedurePlaceService);              //Default proc place of service for the Practice is used.
                List <InsSub>  listInsSubs    = InsSubs.RefreshForFam(Patients.GetFamily(pat.PatNum));
                List <InsPlan> listInsPlans   = InsPlans.RefreshForSubList(listInsSubs);
                List <PatPlan> listPatPlans   = PatPlans.Refresh(pat.PatNum);
                InsPlan        insPlanPrimary = null;
                InsSub         insSubPrimary  = null;
                if (listPatPlans.Count > 0)
                {
                    insSubPrimary  = InsSubs.GetSub(listPatPlans[0].InsSubNum, listInsSubs);
                    insPlanPrimary = InsPlans.GetPlan(insSubPrimary.PlanNum, listInsPlans);
                }
                double procFee;
                long   feeSch;
                if (insPlanPrimary == null || procCode.NoBillIns)
                {
                    feeSch = FeeScheds.GetFeeSched(0, pat.FeeSched, brokenProcedure.ProvNum);
                }
                else                  //Only take into account the patient's insurance fee schedule if the D9986 procedure is not marked as NoBillIns
                {
                    feeSch = FeeScheds.GetFeeSched(insPlanPrimary.FeeSched, pat.FeeSched, brokenProcedure.ProvNum);
                }
                procFee = Fees.GetAmount0(brokenProcedure.CodeNum, feeSch, brokenProcedure.ClinicNum, brokenProcedure.ProvNum);
                if (insPlanPrimary != null && insPlanPrimary.PlanType == "p" && !insPlanPrimary.IsMedical)         //PPO
                {
                    double provFee = Fees.GetAmount0(brokenProcedure.CodeNum, Providers.GetProv(brokenProcedure.ProvNum).FeeSched, brokenProcedure.ClinicNum,
                                                     brokenProcedure.ProvNum);
                    brokenProcedure.ProcFee = Math.Max(provFee, procFee);
                }
                else if (listSplitsForApptProcs.Count > 0 && PrefC.GetBool(PrefName.TpPrePayIsNonRefundable) && procCode.ProcCode == "D9986")
                {
                    //if there are pre-payments, non-refundable pre-payments is turned on, and the broken appointment is a missed code then auto-fill
                    //the window with the sum of the procs for the appointment. Transfer money below after broken procedure is confirmed by the user.
                    brokenProcedure.ProcFee = listSplitsForApptProcs.Sum(x => x.SplitAmt);
                    isNonRefundable         = true;
                }
                else
                {
                    brokenProcedure.ProcFee = procFee;
                }
                if (!PrefC.GetBool(PrefName.EasyHidePublicHealth))
                {
                    brokenProcedure.SiteNum = pat.SiteNum;
                }
                Procedures.Insert(brokenProcedure);
                //Now make a claimproc if the patient has insurance.  We do this now for consistency because a claimproc could get created in the future.
                List <Benefit>   listBenefits          = Benefits.Refresh(listPatPlans, listInsSubs);
                List <ClaimProc> listClaimProcsForProc = ClaimProcs.RefreshForProc(brokenProcedure.ProcNum);
                Procedures.ComputeEstimates(brokenProcedure, pat.PatNum, listClaimProcsForProc, false, listInsPlans, listPatPlans, listBenefits, pat.Age, listInsSubs);
                FormProcBroken FormPB = new FormProcBroken(brokenProcedure, isNonRefundable);
                FormPB.IsNew = true;
                FormPB.ShowDialog();
                brokenProcAmount     = FormPB.AmountTotal;
                wasBrokenProcDeleted = FormPB.IsProcDeleted;
            }
            #endregion
            #region BrokenApptAdjustment
            if (PrefC.GetBool(PrefName.BrokenApptAdjustment))
            {
                Adjustment AdjustmentCur = new Adjustment();
                AdjustmentCur.DateEntry = DateTime.Today;
                AdjustmentCur.AdjDate   = DateTime.Today;
                AdjustmentCur.ProcDate  = DateTime.Today;
                AdjustmentCur.ProvNum   = appt.ProvNum;
                AdjustmentCur.PatNum    = pat.PatNum;
                AdjustmentCur.AdjType   = PrefC.GetLong(PrefName.BrokenAppointmentAdjustmentType);
                AdjustmentCur.ClinicNum = appt.ClinicNum;
                FormAdjust FormA = new FormAdjust(pat, AdjustmentCur);
                FormA.IsNew = true;
                FormA.ShowDialog();
            }
            #endregion
            #region BrokenApptCommLog
            if (PrefC.GetBool(PrefName.BrokenApptCommLog))
            {
                Commlog commlogCur = new Commlog();
                commlogCur.PatNum       = pat.PatNum;
                commlogCur.CommDateTime = DateTime.Now;
                commlogCur.CommType     = Commlogs.GetTypeAuto(CommItemTypeAuto.APPT);
                commlogCur.Note         = Lan.g("Appointment", "Appt BROKEN for") + " " + appt.ProcDescript + "  " + appt.AptDateTime.ToString();
                commlogCur.Mode_        = CommItemMode.None;
                commlogCur.UserNum      = Security.CurUser.UserNum;
                commlogCur.IsNew        = true;
                FormCommItem FormCI = new FormCommItem(commlogCur);
                FormCI.ShowDialog();
            }
            #endregion
            #region Transfer money from TP Procedures if necessary
            //Note this MUST come after FormProcBroken since clicking cancel in that window will delete the procedure.
            if (isNonRefundable && !wasBrokenProcDeleted && listSplitsForApptProcs.Count > 0)
            {
                //transfer what the user specified in the broken appointment window.
                //transfer up to the amount specified by the user
                foreach (Procedure proc in listProcedures)
                {
                    if (brokenProcAmount == 0)
                    {
                        break;
                    }
                    List <PaySplit> listSplitsForAppointmentProcedure = listSplitsForApptProcs.FindAll(x => x.ProcNum == proc.ProcNum);
                    foreach (PaySplit split in listSplitsForAppointmentProcedure)
                    {
                        if (brokenProcAmount == 0)
                        {
                            break;
                        }
                        double amt = Math.Min(brokenProcAmount, split.SplitAmt);
                        Payments.CreateTransferForTpProcs(proc, new List <PaySplit> {
                            split
                        }, brokenProcedure, amt);
                        double amtPaidOnApt = listSplitsForApptProcs.Sum(x => x.SplitAmt);
                        if (amtPaidOnApt > amt)
                        {
                            //If the original prepayment amount is greater than the amt being specified for the appointment break, transfer
                            //the difference to an Unallocated Unearned Paysplit on the account.
                            double remainingAmt = amtPaidOnApt - amt;
                            //We have to create a new transfer payment here to correlate to the split.
                            Payment txfrPayment = new Payment();
                            txfrPayment.PayAmt    = 0;
                            txfrPayment.PayDate   = DateTime.Today;
                            txfrPayment.ClinicNum = split.ClinicNum;
                            txfrPayment.PayNote   = "Automatic transfer from treatment planned procedure prepayment.";
                            txfrPayment.PatNum    = split.PatNum;                       //ultimately where the payment ends up.
                            txfrPayment.PayType   = 0;
                            Payments.Insert(txfrPayment);
                            PaymentEdit.IncomeTransferData transferData = PaymentEdit.IncomeTransferData.CreateTransfer(split, txfrPayment.PayNum, true, remainingAmt);
                            PaySplit offset         = transferData.ListSplitsCur.FirstOrDefault(x => x.FSplitNum != 0);
                            long     offsetSplitNum = PaySplits.Insert(offset);                      //Get the FSplitNum from the offset
                            PaySplit allocation     = transferData.ListSplitsCur.FirstOrDefault(x => x.FSplitNum == 0);
                            allocation.FSplitNum = offsetSplitNum;
                            PaySplits.Insert(allocation);                            //Insert so the split is now up to date
                            SecurityLogs.MakeLogEntry(Permissions.PaymentCreate, txfrPayment.PatNum, "Automatic transfer of funds for treatment plan procedure pre-payments.");
                        }
                        brokenProcAmount -= amt;
                    }
                }
            }
            //if broken appointment procedure was deleted (user cancelled out of the window) just keep money on the original procedure.
            #endregion
            AppointmentEvent.Fire(ODEventType.AppointmentEdited, appt);
            AutomationL.Trigger(AutomationTrigger.BreakAppointment, null, pat.PatNum);
            Recalls.SynchScheduledApptFull(appt.PatNum);
        }
Example #5
0
        ///<summary>Updates all claimproc estimates and also updates claim totals to db. Must supply all claimprocs for this patient (or for this plan if fam max or ded).  Must supply procList which includes all procedures that this claim is linked to.  Will also need to refresh afterwards to see the results</summary>
        public static void CalculateAndUpdate(ClaimProc[] ClaimProcList, Procedure[] procList, InsPlan[] PlanList, Claim ClaimCur, PatPlan[] patPlans, Benefit[] benefitList)
        {
            ClaimProc[] ClaimProcsForClaim = ClaimProcs.GetForClaim(ClaimProcList, ClaimCur.ClaimNum);
            double      claimFee           = 0;
            double      dedApplied         = 0;
            double      insPayEst          = 0;
            double      insPayAmt          = 0;
            double      writeoff           = 0;
            InsPlan     PlanCur            = InsPlans.GetPlan(ClaimCur.PlanNum, PlanList);

            if (PlanCur == null)
            {
                return;
            }
            int    provNum;
            double dedRem;
            int    patPlanNum = PatPlans.GetPatPlanNum(patPlans, ClaimCur.PlanNum);
            //this next line has to be done outside the loop.  Takes annual max into consideration
            double insRem;            //no changes get made to insRem in the loop.

            if (patPlanNum == 0)      //patient does not have current coverage
            {
                insRem = 0;
            }
            else
            {
                insRem = InsPlans.GetInsRem(ClaimProcList, ClaimProcsForClaim[0].ProcDate, ClaimCur.PlanNum,
                                            patPlanNum, ClaimCur.ClaimNum, PlanList, benefitList);
            }
            //first loop handles totals for received items.
            for (int i = 0; i < ClaimProcsForClaim.Length; i++)
            {
                if (ClaimProcsForClaim[i].Status != ClaimProcStatus.Received)
                {
                    continue;                    //disregard any status except Receieved.
                }
                claimFee   += ClaimProcsForClaim[i].FeeBilled;
                dedApplied += ClaimProcsForClaim[i].DedApplied;
                insPayEst  += ClaimProcsForClaim[i].InsPayEst;
                insPayAmt  += ClaimProcsForClaim[i].InsPayAmt;
            }
            //loop again only for procs not received.
            //And for preauth.
            Procedure ProcCur;

            for (int i = 0; i < ClaimProcsForClaim.Length; i++)
            {
                if (ClaimProcsForClaim[i].Status != ClaimProcStatus.NotReceived &&
                    ClaimProcsForClaim[i].Status != ClaimProcStatus.Preauth)
                {
                    continue;
                }
                ProcCur = Procedures.GetProc(procList, ClaimProcsForClaim[i].ProcNum);
                if (ProcCur.ProcNum == 0)
                {
                    continue;                    //ignores payments, etc
                }
                //fee:
                int qty = ProcCur.UnitQty + ProcCur.BaseUnits;
                if (qty == 0)
                {
                    qty = 1;
                }
                if (PlanCur.ClaimsUseUCR)                //use UCR for the provider of the procedure
                {
                    provNum = ProcCur.ProvNum;
                    if (provNum == 0)                  //if no prov set, then use practice default.
                    {
                        provNum = PrefB.GetInt("PracticeDefaultProv");
                    }
                    ClaimProcsForClaim[i].FeeBilled = qty * (Fees.GetAmount0(                //get the fee based on code and prov fee sched
                                                                 ProcCur.CodeNum, Providers.ListLong[Providers.GetIndexLong(provNum)].FeeSched));
                }
                else                 //don't use ucr.  Use the procedure fee instead.
                {
                    ClaimProcsForClaim[i].FeeBilled = qty * ProcCur.ProcFee;
                }
                claimFee += ClaimProcsForClaim[i].FeeBilled;
                if (ClaimCur.ClaimType == "PreAuth" || ClaimCur.ClaimType == "Other")
                {
                    //only the fee gets calculated, the rest does not
                    ClaimProcs.Update(ClaimProcsForClaim[i]);
                    continue;
                }
                //deduct:
                if (patPlanNum == 0)              //patient does not have current coverage
                {
                    dedRem = 0;
                }
                else
                {
                    dedRem = InsPlans.GetDedRem(ClaimProcList, ClaimProcsForClaim[i].ProcDate, ClaimCur.PlanNum, patPlanNum,
                                                ClaimCur.ClaimNum, PlanList, benefitList, ProcedureCodes.GetStringProcCode(ProcCur.CodeNum))
                             - dedApplied;                  //subtracts deductible amounts already applied on this claim
                    if (dedRem < 0)
                    {
                        dedRem = 0;
                    }
                }
                if (dedRem > ClaimProcsForClaim[i].FeeBilled)                //if deductible is more than cost of procedure
                {
                    ClaimProcsForClaim[i].DedApplied = ClaimProcsForClaim[i].FeeBilled;
                }
                else
                {
                    ClaimProcsForClaim[i].DedApplied = dedRem;
                }
                if (ClaimCur.ClaimType == "P")                                                                                 //primary
                {
                    ClaimProcs.ComputeBaseEst(ClaimProcsForClaim[i], ProcCur, PriSecTot.Pri, PlanList, patPlans, benefitList); //handles dedBeforePerc
                    ClaimProcsForClaim[i].InsPayEst = Procedures.GetEst(ProcCur, ClaimProcList, PriSecTot.Pri, patPlans, true);
                }
                else if (ClaimCur.ClaimType == "S")              //secondary
                {
                    ClaimProcs.ComputeBaseEst(ClaimProcsForClaim[i], ProcCur, PriSecTot.Sec, PlanList, patPlans, benefitList);
                    ClaimProcsForClaim[i].InsPayEst = Procedures.GetEst(ProcCur, ClaimProcList, PriSecTot.Sec, patPlans, true);
                }
                if (ClaimCur.ClaimType == "P" || ClaimCur.ClaimType == "S")
                {
                    if (ClaimProcsForClaim[i].DedBeforePerc)
                    {
                        int percent = 100;
                        if (ClaimProcsForClaim[i].Percentage != -1)
                        {
                            percent = ClaimProcsForClaim[i].Percentage;
                        }
                        if (ClaimProcsForClaim[i].PercentOverride != -1)
                        {
                            percent = ClaimProcsForClaim[i].PercentOverride;
                        }
                        ClaimProcsForClaim[i].InsPayEst -= ClaimProcsForClaim[i].DedApplied * (double)percent / 100d;
                    }
                    else
                    {
                        ClaimProcsForClaim[i].InsPayEst -= ClaimProcsForClaim[i].DedApplied;
                    }
                }
                //claimtypes other than P and S only changed manually
                if (ClaimProcsForClaim[i].InsPayEst < 0)
                {
                    //example: if inspayest = 19 - 50(ded) for total of -31.
                    ClaimProcsForClaim[i].DedApplied += ClaimProcsForClaim[i].InsPayEst;                  //eg. 50+(-31)=19
                    ClaimProcsForClaim[i].InsPayEst   = 0;
                    //so only 19 of deductible gets applied, and inspayest is 0
                }
                if (insRem - insPayEst < 0)             //total remaining ins-Estimated so far on this claim
                {
                    ClaimProcsForClaim[i].InsPayEst = 0;
                }
                else if (ClaimProcsForClaim[i].InsPayEst > insRem - insPayEst)
                {
                    ClaimProcsForClaim[i].InsPayEst = insRem - insPayEst;
                }
                if (ClaimProcsForClaim[i].Status == ClaimProcStatus.NotReceived)
                {
                    ClaimProcsForClaim[i].WriteOff = 0;
                    if (ClaimCur.ClaimType == "P" && PlanCur.PlanType == "p")                //Primary && PPO
                    {
                        double insplanAllowed = Fees.GetAmount(ProcCur.CodeNum, PlanCur.FeeSched);
                        if (insplanAllowed != -1)
                        {
                            ClaimProcsForClaim[i].WriteOff = ProcCur.ProcFee - insplanAllowed;
                        }
                        //else, if -1 fee not found, then do not show a writeoff. User can change writeoff if they disagree.
                    }
                    writeoff += ClaimProcsForClaim[i].WriteOff;
                }
                dedApplied += ClaimProcsForClaim[i].DedApplied;
                insPayEst  += ClaimProcsForClaim[i].InsPayEst;
                ClaimProcs.Update(ClaimProcsForClaim[i]);
                //but notice that the ClaimProcs lists are not refreshed until the loop is finished.
            }            //for claimprocs.forclaim
            ClaimCur.ClaimFee   = claimFee;
            ClaimCur.DedApplied = dedApplied;
            ClaimCur.InsPayEst  = insPayEst;
            ClaimCur.InsPayAmt  = insPayAmt;
            ClaimCur.WriteOff   = writeoff;
            //Cur=ClaimCur;
            Update(ClaimCur);
        }
Example #6
0
        private void butAdd_Click(object sender, EventArgs e)
        {
            FormProcCodes FormP = new FormProcCodes();

            FormP.IsSelectionMode = true;
            FormP.ShowDialog();
            if (FormP.DialogResult != DialogResult.OK)
            {
                return;
            }
            Procedure ProcCur;

            ProcCur         = new Procedure();  //going to be an insert, so no need to set Procedures.CurOld
            ProcCur.CodeNum = FormP.SelectedCodeNum;
            //procnum
            ProcCur.PatNum = AptCur.PatNum;
            //aptnum
            //proccode
            //ProcCur.CodeNum=ProcedureCodes.GetProcCode(ProcCur.OldCode).CodeNum;//already set
            ProcCur.ProcDate = DateTime.Today;
            ProcCur.DateTP   = ProcCur.ProcDate;
            //int totUnits = ProcCur.BaseUnits + ProcCur.UnitQty;
            InsPlan        priplan     = null;
            InsSub         prisub      = null;
            Family         fam         = Patients.GetFamily(AptCur.PatNum);
            Patient        pat         = fam.GetPatient(AptCur.PatNum);
            List <InsSub>  subList     = InsSubs.RefreshForFam(fam);
            List <InsPlan> planList    = InsPlans.RefreshForSubList(subList);
            List <PatPlan> patPlanList = PatPlans.Refresh(pat.PatNum);

            if (patPlanList.Count > 0)
            {
                prisub  = InsSubs.GetSub(patPlanList[0].InsSubNum, subList);
                priplan = InsPlans.GetPlan(prisub.PlanNum, planList);
            }
            //Check if it's a medical procedure.
            double insfee;
            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(pat, planList, patPlanList, subList);
            }
            else
            {
                feeSch = Fees.GetFeeSched(pat, 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
            {
                double standardfee = Fees.GetAmount0(ProcCur.CodeNum, Providers.GetProv(Patients.GetProvNum(pat)).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.ProcCode).NoBillIns;
            ProcCur.Priority   = 0;
            ProcCur.ProcStatus = ProcStat.TP;
            if (ProcedureCodes.GetProcCode(ProcCur.CodeNum).IsHygiene &&
                pat.SecProv != 0)
            {
                ProcCur.ProvNum = pat.SecProv;
            }
            else
            {
                ProcCur.ProvNum = pat.PriProv;
            }
            ProcCur.Note      = "";
            ProcCur.ClinicNum = pat.ClinicNum;
            //dx
            //nextaptnum
            ProcCur.DateEntryC     = DateTime.Now;
            ProcCur.BaseUnits      = ProcedureCodes.GetProcCode(ProcCur.CodeNum).BaseUnits;
            ProcCur.SiteNum        = pat.SiteNum;
            ProcCur.RevCode        = ProcedureCodes.GetProcCode(ProcCur.CodeNum).RevenueCodeDefault;
            ProcCur.DiagnosticCode = PrefC.GetString(PrefName.ICD9DefaultForNewProcs);
            Procedures.Insert(ProcCur);
            List <Benefit> benefitList = Benefits.Refresh(patPlanList, subList);

            Procedures.ComputeEstimates(ProcCur, pat.PatNum, new List <ClaimProc>(), true, planList, patPlanList, benefitList, pat.Age, subList);
            FormProcEdit FormPE = new FormProcEdit(ProcCur, pat.Copy(), fam);

            FormPE.IsNew = true;
            FormPE.ShowDialog();
            if (FormPE.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 if (Programs.UsingOrion)
            {
                //No need to synch with Orion mode.
            }
            else
            {
                //Default is set to TP, so Synch is usually not needed.
                if (ProcCur.ProcStatus == ProcStat.C || ProcCur.ProcStatus == ProcStat.EC || ProcCur.ProcStatus == ProcStat.EO)
                {
                    Recalls.Synch(pat.PatNum);
                }
            }
            FillGrid();
        }
        private void butYes_Click(object sender, System.EventArgs e)
        {
            //Customers have been complaining about procedurelog entries changing their CodeNum column to 0.
            //Based on a security log provided by a customer, we were able to determine that this is one of two potential violators.
            //The following code is here simply to try and get the user to call us so that we can have proof and hopefully find the core of the issue.
            try {
                if (_verifyCode < 1)
                {
                    throw new ApplicationException("Invalid Verify Code");
                }
            }
            catch (ApplicationException ae) {
                string error = "Please notify support with the following information.\r\n"
                               + "Error: " + ae.Message + "\r\n"
                               + "_verifyCode: " + _verifyCode.ToString() + "\r\n"
                               + "_procCur.CodeNum: " + (_procCur == null ? "NULL" : _procCur.CodeNum.ToString()) + "\r\n"
                               + "_procCodeCur.CodeNum: " + (_procCodeCur == null ? "NULL" : _procCodeCur.CodeNum.ToString()) + "\r\n"
                               + "\r\n"
                               + "StackTrace:\r\n" + ae.StackTrace;
                MsgBoxCopyPaste MsgBCP = new MsgBoxCopyPaste(error);
                MsgBCP.Text = "Fatal Error!!!";
                MsgBCP.Show();                //Use .Show() to make it easy for the user to keep this window open while they call in.
                return;
            }
            //Moved from FormProcEdit.SaveAndClose() in version 16.3+
            Procedure procOld = _procCur.Copy();

            _procCur.CodeNum = _verifyCode;
            if (new[] { ProcStat.TP, ProcStat.C, ProcStat.TPi }.Contains(_procCur.ProcStatus))           //Only change the fee if Complete or TP
            {
                InsSub  prisub  = null;
                InsPlan priplan = null;
                if (_listPatPlans.Count > 0)
                {
                    prisub  = InsSubs.GetSub(_listPatPlans[0].InsSubNum, _listInsSubs);
                    priplan = InsPlans.GetPlan(prisub.PlanNum, _listInsPlans);
                }
                _procCur.ProcFee = Fees.GetAmount0(_procCur.CodeNum, FeeScheds.GetFeeSched(_patCur, _listInsPlans, _listPatPlans, _listInsSubs, _procCur.ProvNum),
                                                   _procCur.ClinicNum, _procCur.ProvNum);
                if (priplan != null && priplan.PlanType == "p")             //PPO
                {
                    double standardfee = Fees.GetAmount0(_procCur.CodeNum, Providers.GetProv(Patients.GetProvNum(_patCur)).FeeSched, _procCur.ClinicNum,
                                                         _procCur.ProvNum);
                    _procCur.ProcFee = Math.Max(_procCur.ProcFee, standardfee);
                }
            }
            Procedures.Update(_procCur, procOld);
            //Compute estimates required, otherwise if adding through quick add, it could have incorrect WO or InsEst if code changed.
            Procedures.ComputeEstimates(_procCur, _patCur.PatNum, _listClaimProcs, false, _listInsPlans, _listPatPlans, _listBenefits, _patCur.Age, _listInsSubs);
            Recalls.Synch(_procCur.PatNum);
            if (_procCur.ProcStatus.In(ProcStat.C, ProcStat.EO, ProcStat.EC))
            {
                string logText = _procCodeCur.ProcCode + " (" + _procCur.ProcStatus + "), ";
                if (_teethText != null && _teethText.Trim() != "")
                {
                    logText += Lan.g(this, "Teeth") + ": " + _teethText + ", ";
                }
                logText += Lan.g(this, "Fee") + ": " + _procCur.ProcFee.ToString("F") + ", " + _procCodeCur.Descript;
                Permissions perm = Permissions.ProcComplEdit;
                if (_procCur.ProcStatus.In(ProcStat.EO, ProcStat.EC))
                {
                    perm = Permissions.ProcExistingEdit;
                }
                SecurityLogs.MakeLogEntry(perm, _patCur.PatNum, logText);
            }
            DialogResult = DialogResult.OK;
        }
Example #8
0
        ///<summary>Updates all claimproc estimates and also updates claim totals to db. Must supply all claimprocs for this patient.  Must supply procList which includes all procedures that this claim is linked to.  Will also need to refresh afterwards to see the results</summary>
        public static void CalculateAndUpdate(ClaimProc[] ClaimProcList, Procedure[] procList, InsPlan[] PlanList, Claim ClaimCur, PatPlan[] patPlans, Benefit[] benefitList)
        {
            //Remember that this can be called externally also
            //ClaimProcList=claimProcList;
            ClaimProc[] ClaimProcsForClaim = ClaimProcs.GetForClaim(ClaimProcList, ClaimCur.ClaimNum);
            double      claimFee           = 0;
            double      dedApplied         = 0;
            double      insPayEst          = 0;
            double      insPayAmt          = 0;
            InsPlan     PlanCur            = InsPlans.GetPlan(ClaimCur.PlanNum, PlanList);

            if (PlanCur == null)
            {
                return;
            }
            //InsPlans.Cur=(InsPlan)InsPlans.HList[ClaimCur.PlanNum];
            int    provNum;
            double dedRem;
            int    patPlanNum = PatPlans.GetPatPlanNum(patPlans, ClaimCur.PlanNum);
            //this next line has to be done outside the loop.  Takes annual max into consideration
            double insRem;            //no changes get made to insRem in the loop.

            if (patPlanNum == 0)      //patient does not have current coverage
            {
                insRem = 0;
            }
            else
            {
                insRem = InsPlans.GetInsRem(ClaimProcList, ClaimProcsForClaim[0].ProcDate, ClaimCur.PlanNum,
                                            patPlanNum, ClaimCur.ClaimNum, PlanList, benefitList);
            }
            //first loop handles totals for received items.
            for (int i = 0; i < ClaimProcsForClaim.Length; i++)
            {
                if (ClaimProcsForClaim[i].Status != ClaimProcStatus.Received)
                {
                    continue;                    //disregard any status except Receieved.
                }
                claimFee   += ClaimProcsForClaim[i].FeeBilled;
                dedApplied += ClaimProcsForClaim[i].DedApplied;
                insPayEst  += ClaimProcsForClaim[i].InsPayEst;
                insPayAmt  += ClaimProcsForClaim[i].InsPayAmt;
            }
            //loop again only for procs not received.
            //And for preauth.
            Procedure ProcCur;

            for (int i = 0; i < ClaimProcsForClaim.Length; i++)
            {
                if (ClaimProcsForClaim[i].Status != ClaimProcStatus.NotReceived &&
                    ClaimProcsForClaim[i].Status != ClaimProcStatus.Preauth)
                {
                    continue;
                }
                ProcCur = Procedures.GetProc(procList, ClaimProcsForClaim[i].ProcNum);
                if (ProcCur.ProcNum == 0)
                {
                    continue;                    //ignores payments, etc
                }
                //fee:
                if (PlanCur.ClaimsUseUCR)                //use UCR for the provider of the procedure
                {
                    provNum = ProcCur.ProvNum;
                    if (provNum == 0)                  //if no prov set, then use practice default.
                    {
                        provNum = PrefB.GetInt("PracticeDefaultProv");
                    }
                    ClaimProcsForClaim[i].FeeBilled = Fees.GetAmount0(                  //get the fee based on ada and prov fee sched
                        ProcCur.ADACode
                        , Providers.ListLong[Providers.GetIndexLong(provNum)].FeeSched);
                }
                else                 //don't use ucr.  Use the procedure fee instead.
                {
                    ClaimProcsForClaim[i].FeeBilled = ProcCur.ProcFee;
                }
                claimFee += ClaimProcsForClaim[i].FeeBilled;
                if (ClaimCur.ClaimType == "PreAuth" || ClaimCur.ClaimType == "Other")
                {
                    //only the fee gets calculated, the rest does not
                    ClaimProcs.Update(ClaimProcsForClaim[i]);
                    continue;
                }
                //deduct:
                if (patPlanNum == 0)              //patient does not have current coverage
                {
                    dedRem = 0;
                }
                else
                {
                    dedRem = InsPlans.GetDedRem(ClaimProcList, ClaimProcsForClaim[i].ProcDate, ClaimCur.PlanNum, patPlanNum,
                                                ClaimCur.ClaimNum, PlanList, benefitList, ProcCur.ADACode)
                             - dedApplied;                  //subtracts deductible amounts already applied on this claim
                    if (dedRem < 0)
                    {
                        dedRem = 0;
                    }
                }
                if (dedRem > ClaimProcsForClaim[i].FeeBilled)                //if deductible is more than cost of procedure
                {
                    ClaimProcsForClaim[i].DedApplied = ClaimProcsForClaim[i].FeeBilled;
                }
                else
                {
                    ClaimProcsForClaim[i].DedApplied = dedRem;
                }
                //??obsolete: if dedApplied is too big, it might be adjusted in the next few lines.??
                //insest:
                //Unlike deductible, we do not need to take into account any of the received claimprocs when calculating insest.  So insRem takes care of annual max rather than received+est.
                //if(patPlanNum==0){//patient does not have current coverage
                //	insRem=0;
                //}
                //else{
                //insRem-=insPayEst;//subtracts insest amounts already applied on this claim
                //insRem=InsPlans.GetInsRem(ClaimProcList,ClaimProcsForClaim[i].ProcDate,ClaimCur.PlanNum,
                //	patPlanNum,ClaimCur.ClaimNum,PlanList,benefitList)
                //	-insPayEst;//subtracts insest amounts already applied on this claim
                //	if(insRem<0) {
                //		insRem=0;
                //	}
                //}
                if (ClaimCur.ClaimType == "P")                                                                                 //primary
                {
                    ClaimProcs.ComputeBaseEst(ClaimProcsForClaim[i], ProcCur, PriSecTot.Pri, PlanList, patPlans, benefitList); //handles dedBeforePerc
                    ClaimProcsForClaim[i].InsPayEst = Procedures.GetEst(ProcCur, ClaimProcList, PriSecTot.Pri, patPlans, true);
                    //ClaimProcsForClaim[i].BaseEst;
                    if (!ClaimProcsForClaim[i].DedBeforePerc)
                    {
                        ClaimProcsForClaim[i].InsPayEst -= ClaimProcsForClaim[i].DedApplied;
                    }
                }
                else if (ClaimCur.ClaimType == "S")              //secondary
                {
                    ClaimProcs.ComputeBaseEst(ClaimProcsForClaim[i], ProcCur, PriSecTot.Sec, PlanList, patPlans, benefitList);
                    ClaimProcsForClaim[i].InsPayEst = Procedures.GetEst(ProcCur, ClaimProcList, PriSecTot.Sec, patPlans, true);
                    //ClaimProcsForClaim[i].BaseEst;
                    if (!ClaimProcsForClaim[i].DedBeforePerc)
                    {
                        ClaimProcsForClaim[i].InsPayEst -= ClaimProcsForClaim[i].DedApplied;
                    }
                }
                //other claimtypes only changed manually
                if (ClaimProcsForClaim[i].InsPayEst < 0)
                {
                    //example: if inspayest = 19 - 50(ded) for total of -31.
                    ClaimProcsForClaim[i].DedApplied += ClaimProcsForClaim[i].InsPayEst;                  //eg. 50+(-31)=19
                    ClaimProcsForClaim[i].InsPayEst   = 0;
                    //so only 19 of deductible gets applied, and inspayest is 0
                }
                if (insRem - insPayEst < 0)             //total remaining ins-Estimated so far on this claim
                {
                    ClaimProcsForClaim[i].InsPayEst = 0;
                }
                else if (ClaimProcsForClaim[i].InsPayEst > insRem - insPayEst)
                {
                    ClaimProcsForClaim[i].InsPayEst = insRem - insPayEst;
                }
                dedApplied += ClaimProcsForClaim[i].DedApplied;
                insPayEst  += ClaimProcsForClaim[i].InsPayEst;
                ClaimProcs.Update(ClaimProcsForClaim[i]);
                //but notice that the ClaimProcs lists are not refreshed until the loop is finished.
            }            //for claimprocs.forclaim
            ClaimCur.ClaimFee   = claimFee;
            ClaimCur.DedApplied = dedApplied;
            ClaimCur.InsPayEst  = insPayEst;
            ClaimCur.InsPayAmt  = insPayAmt;
            //Cur=ClaimCur;
            Update(ClaimCur);
        }
Example #9
0
        private void butOK_Click(object sender, System.EventArgs e)
        {
            long             feeSched = FeeSchedC.ListShort[listFeeSched.SelectedIndex].FeeSchedNum;
            string           catName  = ""; //string to hold current category name
            Fees             fee      = new Fees();
            ReportSimpleGrid report   = new ReportSimpleGrid();

            report.Query = "SELECT procedurecode.ProcCode,fee.Amount,'     ',procedurecode.Descript,"
                           + "procedurecode.AbbrDesc FROM procedurecode,fee "
                           + "WHERE procedurecode.CodeNum=fee.CodeNum AND fee.FeeSched='" + feeSched.ToString()
                           + "' ORDER BY procedurecode.ProcCode";
            FormQuery2          = new FormQuery(report);
            FormQuery2.IsReport = true;
            if (radioCode.Checked == true)
            {
                FormQuery2.SubmitReportQuery();
                report.Title = "Procedure Codes";
                report.SubTitle.Add(PrefC.GetString(PrefName.PracticeTitle));
                report.SubTitle.Add(FeeScheds.GetDescription(feeSched));
                report.SetColumn(this, 0, "Code", 70);
                report.SetColumn(this, 1, "Fee Amount", 70, HorizontalAlignment.Right);
                report.SetColumn(this, 2, " ", 80);             //otherwise, the amount gets bunched up next to the description.
                report.SetColumn(this, 3, "Description", 200);
                report.SetColumn(this, 4, "Abbr Description", 200);
                FormQuery2.ShowDialog();
                DialogResult = DialogResult.OK;
            }
            else              //categories
            //report.SubmitTemp();//create TableTemp which is not actually used
            {
                ProcedureCode[] ProcList = ProcedureCodes.GetProcList();
                report.TableQ = new DataTable(null);
                for (int i = 0; i < 5; i++)                                  //add columns
                {
                    report.TableQ.Columns.Add(new System.Data.DataColumn()); //blank columns
                }
                report.InitializeColumns();
                DataRow row = report.TableQ.NewRow();//add first row by hand to get value for temp
                row[0]              = DefC.GetName(DefCat.ProcCodeCats, ProcList[0].ProcCat);
                catName             = row[0].ToString();
                row[1]              = ProcList[0].ProcCode;
                row[2]              = ProcList[0].Descript;
                row[3]              = ProcList[0].AbbrDesc;
                row[4]              = ((double)Fees.GetAmount0(ProcList[0].CodeNum, feeSched)).ToString("F");
                report.ColTotal[4] += PIn.Decimal(row[4].ToString());
                report.TableQ.Rows.Add(row);
                for (int i = 1; i < ProcList.Length; i++)          //loop through data rows
                {
                    row    = report.TableQ.NewRow();               //create new row called 'row' based on structure of TableQ
                    row[0] = DefC.GetName(DefCat.ProcCodeCats, ProcList[i].ProcCat);
                    if (catName == row[0].ToString())
                    {
                        row[0] = "";
                    }
                    else
                    {
                        catName = row[0].ToString();
                    }
                    row[1] = ProcList[i].ProcCode.ToString();
                    row[2] = ProcList[i].Descript;
                    row[3] = ProcList[i].AbbrDesc.ToString();
                    row[4] = ((double)Fees.GetAmount0(ProcList[i].CodeNum, feeSched)).ToString("F");
                    //report.ColTotal[4]+=PIn.PDouble(row[4].ToString());
                    report.TableQ.Rows.Add(row);
                }
                FormQuery2.ResetGrid();                //this is a method in FormQuery2;
                report.Title = "Procedure Codes";
                report.SubTitle.Add(PrefC.GetString(PrefName.PracticeTitle));
                report.SubTitle.Add(FeeScheds.GetDescription(feeSched));
                report.ColPos[0]     = 20;
                report.ColPos[1]     = 120;
                report.ColPos[2]     = 270;
                report.ColPos[3]     = 470;
                report.ColPos[4]     = 620;
                report.ColPos[5]     = 770;
                report.ColCaption[0] = "Category";
                report.ColCaption[1] = "Code";
                report.ColCaption[2] = "Description";
                report.ColCaption[3] = "Abbr Description";
                report.ColCaption[4] = "Fee Amount";
                report.ColAlign[4]   = HorizontalAlignment.Right;
                FormQuery2.ShowDialog();
                DialogResult = DialogResult.OK;
            }
        }
Example #10
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);
        }
Example #11
0
        ///<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.</summary>
        public static Appointment CreateRecallApt(Patient patCur, Procedure[] procList, Recall recallCur, InsPlan[] planList)
        {
            Appointment AptCur = new Appointment();

            AptCur.PatNum    = patCur.PatNum;
            AptCur.AptStatus = ApptStatus.Scheduled;
            //convert time pattern to 5 minute increment
            StringBuilder savePattern = new StringBuilder();

            for (int i = 0; i < PrefB.GetString("RecallPattern").Length; i++)
            {
                savePattern.Append(PrefB.GetString("RecallPattern").Substring(i, 1));
                savePattern.Append(PrefB.GetString("RecallPattern").Substring(i, 1));
                if (PrefB.GetInt("AppointmentTimeIncrement") == 15)
                {
                    savePattern.Append(PrefB.GetString("RecallPattern").Substring(i, 1));
                }
            }
            AptCur.Pattern = savePattern.ToString();
            if (patCur.PriProv == 0)
            {
                AptCur.ProvNum = PrefB.GetInt("PracticeDefaultProv");
            }
            else
            {
                AptCur.ProvNum = patCur.PriProv;
            }
            AptCur.ProvHyg = patCur.SecProv;
            if (AptCur.ProvHyg != 0)
            {
                AptCur.IsHygiene = true;
            }
            AptCur.ClinicNum = patCur.ClinicNum;
            string[] procs = PrefB.GetString("RecallProcedures").Split(',');
            if (PrefB.GetString("RecallBW") != "")          //BWs
            {
                bool dueBW = true;
                //DateTime dueDate=PIn.PDate(listFamily.Items[
                for (int i = 0; i < procList.Length; i++)          //loop through all procedures for this pt.
                //if any BW found within last year, then dueBW=false.
                {
                    if (PrefB.GetString("RecallBW") == procList[i].ADACode &&
                        recallCur.DateDue.Year > 1880 &&
                        procList[i].ProcDate > recallCur.DateDue.AddYears(-1))
                    {
                        dueBW = false;
                    }
                }
                if (dueBW)
                {
                    string[] procs2 = new string[procs.Length + 1];
                    procs.CopyTo(procs2, 0);
                    procs2[procs2.Length - 1] = PrefB.GetString("RecallBW");
                    procs = new string[procs2.Length];
                    procs2.CopyTo(procs, 0);
                }
            }
            AptCur.ProcDescript = "";
            for (int i = 0; i < procs.Length; i++)
            {
                if (i > 0)
                {
                    AptCur.ProcDescript += ", ";
                }
                AptCur.ProcDescript += ProcedureCodes.GetProcCode(procs[i]).AbbrDesc;
            }
            Appointments.InsertOrUpdate(AptCur, null, true);
            Procedure ProcCur;

            PatPlan[] patPlanList = PatPlans.Refresh(patCur.PatNum);
            Benefit[] benefitList = Benefits.Refresh(patPlanList);
            //ClaimProc[] claimProcs=ClaimProcs.Refresh(Patients.Cur.PatNum);
            for (int i = 0; i < procs.Length; i++)
            {
                ProcCur = new Procedure();              //this will be an insert
                //procnum
                ProcCur.PatNum   = patCur.PatNum;
                ProcCur.AptNum   = AptCur.AptNum;
                ProcCur.ADACode  = procs[i];
                ProcCur.ProcDate = DateTime.Now;
                ProcCur.ProcFee  = Fees.GetAmount0(ProcCur.ADACode, Fees.GetFeeSched(patCur, planList, patPlanList));
                //ProcCur.OverridePri=-1;
                //ProcCur.OverrideSec=-1;
                //surf
                //toothnum
                //Procedures.Cur.ToothRange="";
                //ProcCur.NoBillIns=ProcedureCodes.GetProcCode(ProcCur.ADACode).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.MedicalCode = ProcedureCodes.GetProcCode(ProcCur.ADACode).MedicalCode;
                Procedures.Insert(ProcCur);                //no recall synch required
                Procedures.ComputeEstimates(ProcCur, patCur.PatNum, new ClaimProc[0], false, planList, patPlanList, benefitList);
            }
            return(AptCur);
        }