예제 #1
0
        private void FormInsSelectSubscr_Load(object sender, System.EventArgs e)
        {
            SubList = InsSubs.GetListForSubscriber(Subscriber);
            List <InsPlan> planList = InsPlans.RefreshForSubList(SubList);
            //PatPlan[] patPlanArray;
            string  str;
            InsPlan plan;

            if (!InsSubs.ValidatePlanNumForList(SubList.Select(x => x.InsSubNum).ToList()))             //If !isValid, any links should have been fixed and we now need to update our list.
            {
                SubList = InsSubs.GetListForSubscriber(Subscriber);
            }
            for (int i = 0; i < SubList.Count; i++)
            {
                plan = InsPlans.GetPlan(SubList[i].PlanNum, planList);
                str  = InsPlans.GetCarrierName(SubList[i].PlanNum, planList);
                if (plan.GroupNum != "")
                {
                    str += Lan.g(this, " group:") + plan.GroupNum;
                }
                int countPatPlans = PatPlans.GetCountBySubNum(SubList[i].InsSubNum);
                if (countPatPlans == 0)
                {
                    str += " " + Lan.g(this, "(not in use)");
                }
                listPlans.Items.Add(str);
            }
        }
예제 #2
0
        ///<summary>Mimics ContrAccount.CreateClaim(...).  Removes items from listProcs until unique diagnosis code count is low enough.</summary>
        private void GetUniqueDiagnosticCodes(List <ProcNotBilled> listProcs, List <Procedure> listPatProcs, List <PatPlan> listPatPlans,
                                              List <InsSub> listInsSubs, List <InsPlan> listInsPlans)
        {
            List <Procedure> listProcedures = new List <Procedure>();

            for (int i = 0; i < listProcs.Count; i++)
            {
                listProcedures.Add(Procedures.GetProcFromList(listPatProcs, listProcs[i].ProcNum));
            }
            //If they have medical insurance and no dental, make the claim type Medical.  This is to avoid the scenario of multiple med ins and no dental.
            bool isMedical = false;

            if (PatPlans.GetOrdinal(PriSecMed.Medical, listPatPlans, listInsPlans, listInsSubs) > 0 &&
                PatPlans.GetOrdinal(PriSecMed.Primary, listPatPlans, listInsPlans, listInsSubs) == 0 &&
                PatPlans.GetOrdinal(PriSecMed.Secondary, listPatPlans, listInsPlans, listInsSubs) == 0)
            {
                isMedical = true;
            }
            while (!isMedical && Procedures.GetUniqueDiagnosticCodes(listProcedures, false).Count > 4)            //dental
            {
                int index = listProcedures.Count - 1;
                listProcedures.RemoveAt(index);
                listProcs.RemoveAt(index);
            }
            while (isMedical && Procedures.GetUniqueDiagnosticCodes(listProcedures, true).Count > 12)            //medical
            {
                int index = listProcedures.Count - 1;
                listProcedures.RemoveAt(index);
                listProcs.RemoveAt(index);
            }
        }
예제 #3
0
 private void FormAutoOrtho_Load(object sender, EventArgs e)
 {
     _tableOutstandingAutoClaims = PatPlans.GetOutstandingOrtho();
     if (!PrefC.HasClinicsEnabled)
     {
         labelClinic.Visible  = false;
         comboClinics.Visible = false;
     }
     else
     {
         if (!Security.CurUser.ClinicIsRestricted)
         {
             comboClinics.Items.Add(Lan.g(this, "All"));
             comboClinics.SelectedIndex = 0;
         }
         _listClinics = Clinics.GetForUserod(Security.CurUser);
         for (int i = 0; i < _listClinics.Count; i++)
         {
             comboClinics.Items.Add(_listClinics[i].Abbr);
             if (_listClinics[i].ClinicNum == Clinics.ClinicNum)
             {
                 comboClinics.SelectedIndex = i;
                 if (!Security.CurUser.ClinicIsRestricted)
                 {
                     comboClinics.SelectedIndex++;                            //add 1 for "All"
                 }
             }
         }
     }
     FillGrid();
 }
예제 #4
0
 ///<summary></summary>
 public FormInsPlanSelect(long patNum)
 {
     InitializeComponent();
     PatNum = patNum;
     //usage: eg. from coverage.  Since can be totally new subscriber, get all plans for them.
     FamCur              = Patients.GetFamily(PatNum);
     PatCur              = FamCur.GetPatient(PatNum);
     SubList             = InsSubs.RefreshForFam(FamCur);
     PlanList            = InsPlans.RefreshForSubList(SubList);
     _listPatCurPatPlans = PatPlans.Refresh(PatNum);
     if (_listPatCurPatPlans.Count == 1)
     {
         try {
             PatRelat     = _listPatCurPatPlans[0].Relationship;
             SelectedSub  = SubList.FirstOrDefault(x => x.InsSubNum == _listPatCurPatPlans[0].InsSubNum);
             SelectedPlan = InsPlans.GetPlan(SelectedSub.PlanNum, PlanList);
             if (SelectedSub == null || SelectedPlan == null)
             {
                 throw new ApplicationException();
             }
         }
         catch {
             PatRelat     = 0;
             SelectedSub  = null;
             SelectedPlan = null;
         }
     }
     //tbPlans.CellDoubleClicked += new OpenDental.ContrTable.CellEventHandler(tbPlans_CellDoubleClicked);
     Lan.F(this);
 }
예제 #5
0
        private void FillPlanData()
        {
            gridMain.BeginUpdate();
            gridMain.Columns.Clear();
            ODGridColumn col;

            //col=new ODGridColumn(Lan.g("TableInsPlans","#"),20);
            //gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableInsPlans", "Subscriber"), 140);
            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableInsPlans", "Ins Carrier"), 100);
            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableInsPlans", "Date Effect."), 90);
            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableInsPlans", "Date Term."), 90);
            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableInsPlans", "Used By"), 90);
            gridMain.Columns.Add(col);
            gridMain.Rows.Clear();
            ODGridRow row;
            //PatPlan[] patPlanArray;
            InsPlan plan;

            for (int i = 0; i < SubList.Count; i++)
            {
                row = new ODGridRow();
                //row.Cells.Add((i+1).ToString());
                row.Cells.Add(FamCur.GetNameInFamLF(SubList[i].Subscriber));
                plan = InsPlans.GetPlan(SubList[i].PlanNum, PlanList);
                row.Cells.Add(Carriers.GetName(plan.CarrierNum));
                if (SubList[i].DateEffective.Year < 1880)
                {
                    row.Cells.Add("");
                }
                else
                {
                    row.Cells.Add(SubList[i].DateEffective.ToString("d"));
                }
                if (SubList[i].DateTerm.Year < 1880)
                {
                    row.Cells.Add("");
                }
                else
                {
                    row.Cells.Add(SubList[i].DateTerm.ToString("d"));
                }
                int countPatPlans = PatPlans.GetCountBySubNum(SubList[i].InsSubNum);
                row.Cells.Add(countPatPlans.ToString());
                gridMain.Rows.Add(row);
            }
            gridMain.EndUpdate();
            listRelat.Items.Clear();
            for (int i = 0; i < Enum.GetNames(typeof(Relat)).Length; i++)
            {
                listRelat.Items.Add(Lan.g("enumRelat", Enum.GetNames(typeof(Relat))[i]));
            }
        }
예제 #6
0
        private void FillGrid()
        {
            SubList = InsSubs.RefreshForFam(FamCur);
            if (!InsSubs.ValidatePlanNumForList(SubList.Select(x => x.InsSubNum).ToList()))
            {
                SubList = InsSubs.RefreshForFam(FamCur);
            }
            PlanList = InsPlans.RefreshForSubList(SubList);
            gridMain.BeginUpdate();
            gridMain.ListGridColumns.Clear();
            GridColumn col;

            //=new ODGridColumn(Lan.g("TableInsPlans","#"),20);
            //gridMain.Columns.Add(col);
            col = new GridColumn(Lan.g("TableInsPlans", "Subscriber"), 140);
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn(Lan.g("TableInsPlans", "Ins Carrier"), 100);
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn(Lan.g("TableInsPlans", "Date Effect."), 90);
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn(Lan.g("TableInsPlans", "Date Term."), 90);
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn(Lan.g("TableInsPlans", "Used By"), 90);
            gridMain.ListGridColumns.Add(col);
            gridMain.ListGridRows.Clear();
            GridRow row;
            //PatPlan[] patPlanArray;
            InsPlan plan;

            for (int i = 0; i < SubList.Count; i++)
            {
                plan = InsPlans.GetPlan(SubList[i].PlanNum, PlanList);
                row  = new GridRow();
                row.Cells.Add(FamCur.GetNameInFamLF(SubList[i].Subscriber));
                row.Cells.Add(Carriers.GetName(plan.CarrierNum));
                if (SubList[i].DateEffective.Year < 1880)
                {
                    row.Cells.Add("");
                }
                else
                {
                    row.Cells.Add(SubList[i].DateEffective.ToString("d"));
                }
                if (SubList[i].DateTerm.Year < 1880)
                {
                    row.Cells.Add("");
                }
                else
                {
                    row.Cells.Add(SubList[i].DateTerm.ToString("d"));
                }
                int countPatPlans = PatPlans.GetCountBySubNum(SubList[i].InsSubNum);
                row.Cells.Add(countPatPlans.ToString());
                gridMain.ListGridRows.Add(row);
            }
            gridMain.EndUpdate();
        }
예제 #7
0
 private void FormClaimCreate_Load(object sender, System.EventArgs e)
 {
     //usage: eg. from coverage.  Since can be totally new subscriber, get all plans for them.
     FamCur              = Patients.GetFamily(PatNum);
     PatCur              = FamCur.GetPatient(PatNum);
     SubList             = InsSubs.RefreshForFam(FamCur);
     PlanList            = InsPlans.RefreshForSubList(SubList);
     _listPatCurPatPlans = PatPlans.Refresh(PatNum);
     FillPlanData();
     //FillClaimForms();
 }
예제 #8
0
        /// <summary>Only used from FormInsPlan. Throws ApplicationException if any dependencies. This is quite complex, because it also must update all claimprocs for all patients affected by the deletion.  Also deletes patplans, benefits, and claimprocs.</summary>
        public static void Delete(InsPlan plan)
        {
            //first, check claims
            string command = "SELECT PatNum FROM claim "
                             + "WHERE plannum = '" + plan.PlanNum.ToString() + "' ";

            if (FormChooseDatabase.DBtype == DatabaseType.Oracle)
            {
                command += "AND ROWNUM<=1";
            }
            else              //Assume MySQL
            {
                command += "LIMIT 1";
            }
            DataTable table = General.GetTable(command);

            if (table.Rows.Count != 0)
            {
                throw new ApplicationException(Lan.g("FormInsPlan", "Not allowed to delete a plan with existing claims."));
            }
            //then, check claimprocs
            command = "SELECT PatNum FROM claimproc "
                      + "WHERE PlanNum = " + POut.PInt(plan.PlanNum)
                      + " AND Status != 6 ";         //ignore estimates
            if (FormChooseDatabase.DBtype == DatabaseType.Oracle)
            {
                command += "AND ROWNUM<=1";
            }
            else              //Assume MySQL
            {
                command += "LIMIT 1";
            }
            table = General.GetTable(command);
            if (table.Rows.Count != 0)
            {
                throw new ApplicationException(Lan.g("FormInsPlan", "Not allowed to delete a plan attached to procedures."));
            }
            //get a list of all patplans with this planNum
            command = "SELECT PatPlanNum FROM patplan "
                      + "WHERE PlanNum = " + plan.PlanNum.ToString();
            table = General.GetTable(command);
            for (int i = 0; i < table.Rows.Count; i++)
            {
                //benefits with this PatPlanNum are also deleted here
                PatPlans.Delete(PIn.PInt(table.Rows[i][0].ToString()));
            }
            command = "DELETE FROM benefit WHERE PlanNum=" + POut.PInt(plan.PlanNum);
            General.NonQ(command);
            command = "DELETE FROM claimproc WHERE PlanNum=" + POut.PInt(plan.PlanNum);        //just estimates
            General.NonQ(command);
            command = "DELETE FROM insplan "
                      + "WHERE PlanNum = '" + plan.PlanNum.ToString() + "'";
            General.NonQ(command);
        }
예제 #9
0
 private void listPlans_DoubleClick(object sender, System.EventArgs e)
 {
     if (listPlans.SelectedIndex == -1)
     {
         return;
     }
     if (PatPlans.GetCountForPatAndInsSub(SubList[listPlans.SelectedIndex].InsSubNum, _patNum) != 0)
     {
         MsgBox.Show(this, "This patient already has this plan attached.  If you would like to add a new plan for the same subscriber and insurance carrier, click new plan.");
         return;
     }
     SelectedInsSubNum = SubList[listPlans.SelectedIndex].InsSubNum;
     DialogResult      = DialogResult.OK;
 }
예제 #10
0
 public void RefreshData(Patient pat, SheetField sheetField)
 {
     _listInsPlans = new List <InsPlan>();
     _listInsSubs  = new List <InsSub>();
     _listPatPlans = new List <PatPlan>();
     _listBenefits = new List <Benefit>();
     _pat          = pat;
     if (_pat == null)
     {
         return;
     }
     _listPatPlans = PatPlans.Refresh(_pat.PatNum);
     _listInsSubs  = InsSubs.RefreshForFam(Patients.GetFamily(_pat.PatNum));
     _listInsPlans = InsPlans.RefreshForSubList(_listInsSubs);
     _listBenefits = Benefits.Refresh(_listPatPlans, _listInsSubs);
 }
예제 #11
0
 private PatPlan InsertOrUpdatePatPlan(PatPlan patPlan, InsSub insSub, InsPlan insPlan, Hx834_Member member,
                                       Carrier carrier, List <PatPlan> listOtherPatPlans)
 {
     if (patPlan == null)
     {
         patPlan         = new PatPlan();
         patPlan.Ordinal = 0;
         for (int p = 0; p < listOtherPatPlans.Count; p++)
         {
             if (listOtherPatPlans[p].Ordinal > patPlan.Ordinal)
             {
                 patPlan.Ordinal = listOtherPatPlans[p].Ordinal;
             }
         }
         patPlan.Ordinal++;                //Greatest ordinal for patient.
         patPlan.PatNum       = member.Pat.PatNum;
         patPlan.InsSubNum    = insSub.InsSubNum;
         patPlan.Relationship = member.PlanRelat;
         if (member.PlanRelat != Relat.Self)
         {
             //This is not needed yet.  If we do this in the future, then we need to mimic the Move tool in the Family module.
             //member.Pat.Guarantor=insSubMatch.Subscriber;
             //Patient memberPatOld=member.Pat.Copy();
             //Patients.Update(member.Pat,memberPatOld);
         }
         PatPlans.Insert(patPlan);
         SecurityLogs.MakeLogEntry(Permissions.InsPlanAddPat, patPlan.PatNum,
                                   "Insurance plan added to patient for carrier '" + carrier.CarrierName + "' and groupnum "
                                   + "'" + insPlan.GroupNum + "' and subscriber ID '" + insSub.SubscriberID + "' "
                                   + "from Import Ins Plans 834.", insPlan.PlanNum, LogSources.InsPlanImport834, insPlan.SecDateTEdit);
     }
     else
     {
         PatPlan patPlanOld = patPlan.Copy();
         patPlan.Relationship = member.PlanRelat;
         if (OpenDentBusiness.Crud.PatPlanCrud.UpdateComparison(patPlan, patPlanOld))
         {
             SecurityLogs.MakeLogEntry(Permissions.InsPlanEdit, patPlan.PatNum, "Insurance plan relationship changed from "
                                       + member.PlanRelat + " to " + patPlan.Relationship + " for carrier '" + carrier.CarrierName + "' and groupnum "
                                       + "'" + insPlan.GroupNum + "' from Import Ins Plans 834.", insPlan.PlanNum, LogSources.InsPlanImport834, insPlan.SecDateTEdit);
             PatPlans.Update(patPlan);
         }
     }
     return(patPlan);
 }
예제 #12
0
        ///<summary>Deletes the patplan with the specified patPlanNum.  Rearranges the other patplans for the patient to keep the ordinal sequence contiguous.  Then, recomputes all estimates for this patient because their coverage is now different.  Also sets patient.HasIns to the correct value.</summary>
        public static void Delete(int patPlanNum)
        {
            string    command = "SELECT PatNum FROM patplan WHERE PatPlanNum=" + POut.PInt(patPlanNum);
            DataTable table   = General.GetTable(command);

            if (table.Rows.Count == 0)
            {
                return;
            }
            int patNum = PIn.PInt(table.Rows[0][0].ToString());

            PatPlan[] patPlans    = Refresh(patNum);
            bool      doDecrement = false;

            for (int i = 0; i < patPlans.Length; i++)
            {
                if (doDecrement)                //patPlan has already been deleted, so decrement the rest.
                {
                    command = "UPDATE patplan SET Ordinal=" + POut.PInt(patPlans[i].Ordinal - 1)
                              + " WHERE PatPlanNum=" + POut.PInt(patPlans[i].PatPlanNum);
                    General.NonQ(command);
                    continue;
                }
                if (patPlans[i].PatPlanNum == patPlanNum)
                {
                    command = "DELETE FROM patplan WHERE PatPlanNum=" + POut.PInt(patPlanNum);
                    General.NonQ(command);
                    command = "DELETE FROM benefit WHERE PatPlanNum=" + POut.PInt(patPlanNum);
                    General.NonQ(command);
                    doDecrement = true;
                }
            }
            Family  fam = Patients.GetFamily(patNum);
            Patient pat = fam.GetPatient(patNum);

            ClaimProc[] claimProcs = ClaimProcs.Refresh(patNum);
            Procedure[] procs      = Procedures.Refresh(patNum);
            patPlans = PatPlans.Refresh(patNum);
            InsPlan[] planList = InsPlans.Refresh(fam);
            Benefit[] benList  = Benefits.Refresh(patPlans);
            Procedures.ComputeEstimatesForAll(patNum, claimProcs, procs, planList, patPlans, benList);
            Patients.SetHasIns(patNum);
        }
예제 #13
0
        ///<summary>Used when closing the edit plan window to find all patients using this plan and to update all claimProcs for each patient.  This keeps estimates correct.</summary>
        public static void ComputeEstimatesForPlan(int planNum)
        {
            string    command = "SELECT PatNum FROM patplan WHERE PlanNum=" + POut.PInt(planNum);
            DataTable table   = General.GetTable(command);
            int       patNum  = 0;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                patNum = PIn.PInt(table.Rows[i][0].ToString());
                Family      fam         = Patients.GetFamily(patNum);
                Patient     pat         = fam.GetPatient(patNum);
                ClaimProc[] claimProcs  = ClaimProcs.Refresh(patNum);
                Procedure[] procs       = Procedures.Refresh(patNum);
                InsPlan[]   plans       = InsPlans.Refresh(fam);
                PatPlan[]   patPlans    = PatPlans.Refresh(patNum);
                Benefit[]   benefitList = Benefits.Refresh(patPlans);
                Procedures.ComputeEstimatesForAll(patNum, claimProcs, procs, plans, patPlans, benefitList);
                Patients.SetHasIns(patNum);
            }
        }
예제 #14
0
        ///<summary>Returns false if the insurance plan is effective.  True if today is outside of the insurance effective date range.</summary>
        private static bool InsuranceNotEffectiveComparison(AutomationCondition autoCond, long patNum)
        {
            PatPlan patPlanCur = PatPlans.GetPatPlan(patNum, 1);

            if (patPlanCur == null)
            {
                return(false);
            }
            InsSub insSubCur = InsSubs.GetOne(patPlanCur.InsSubNum);

            if (insSubCur == null)
            {
                return(false);
            }
            if (DateTime.Today >= insSubCur.DateEffective && DateTime.Today <= insSubCur.DateTerm)
            {
                return(false);               //Allen - Not not effective
            }
            return(true);
        }
예제 #15
0
        ///<summary>Runs Procedures.ComputeEstimates for given proc and listClaimProcs.
        ///Does not update existing ClaimProcs or insert new ClaimProcs in the database.
        ///Outs new ClaimProcs added by Procedures.ComputeEstimates, listClaimProcs will contain any added claimProcs.</summary>
        private void RecomputeEstimates(Procedure proc, List <ClaimProc> listClaimProcs, out List <ClaimProc> listNewClaimProcs,
                                        OrthoProcLink orthoProcLink, OrthoCase orthoCase, OrthoSchedule orthoSchedule, List <OrthoProcLink> listOrthoProcLinksForOrthoCase)
        {
            List <ClaimProc> listOrigClaimProcs = new List <ClaimProc>(listClaimProcs);
            Patient          pat          = Patients.GetPat(proc.PatNum);
            List <PatPlan>   listPatPlans = PatPlans.GetPatPlansForPat(pat.PatNum);
            List <InsSub>    listInsSubs  = InsSubs.GetMany(listPatPlans.Select(x => x.InsSubNum).ToList());
            List <InsPlan>   listInsPlans = InsPlans.GetByInsSubs(listInsSubs.Select(x => x.InsSubNum).ToList());
            List <Benefit>   listBenefits = Benefits.Refresh(listPatPlans, listInsSubs);      //Same method used in FormProcEdit.Load()->GetLoadData()
            //FormProcEdit uses GetHistList(....,procDate:DateTimeOD.Today,...)
            List <ClaimProcHist> listHist = ClaimProcs.GetHistList(pat.PatNum, listBenefits, listPatPlans, listInsPlans, DateTimeOD.Today, listInsSubs);
            bool isSaveToDb = false;

            //When isSaveToDb is true any estimates that are missing will be inserted into DB and it refreshes listClaimProcs from the Db.
            //Refreshing the list results in losing the changes to ProvNum and ProcDate.
            Procedures.ComputeEstimates(proc, pat.PatNum, ref listClaimProcs, false, listInsPlans, listPatPlans, listBenefits, listHist,
                                        new List <ClaimProcHist> {
            }, isSaveToDb, pat.Age, listInsSubs
                                        , useProcDateOnProc: true,
                                        orthoProcLink: orthoProcLink, orthoCase: orthoCase, orthoSchedule: orthoSchedule, listOrthoProcLinksForOrthoCase: listOrthoProcLinksForOrthoCase);
            listNewClaimProcs = listClaimProcs.Except(listOrigClaimProcs).ToList();
        }
예제 #16
0
        ///<summary>Gets the fee schedule from the priinsplan, the patient, or the provider in that order.  Either returns a fee schedule (fk to definition.DefNum) or 0.</summary>
        public static int GetFeeSched(Patient pat, InsPlan[] PlanList, PatPlan[] patPlans)
        {
            //there's not really a good place to put this function, so it's here.
            int retVal = 0;

            if (PatPlans.GetPlanNum(patPlans, 1) != 0)
            {
                InsPlan PlanCur = InsPlans.GetPlan(PatPlans.GetPlanNum(patPlans, 1), PlanList);
                if (PlanCur == null)
                {
                    retVal = 0;
                }
                else
                {
                    retVal = PlanCur.FeeSched;
                }
            }
            if (retVal == 0)
            {
                if (pat.FeeSched != 0)
                {
                    retVal = pat.FeeSched;
                }
                else
                {
                    if (pat.PriProv == 0)
                    {
                        retVal = Providers.List[0].FeeSched;
                    }
                    else
                    {
                        //MessageBox.Show(Providers.GetIndex(Patients.Cur.PriProv).ToString());
                        retVal = Providers.ListLong[Providers.GetIndexLong(pat.PriProv)].FeeSched;
                    }
                }
            }
            return(retVal);
        }
예제 #17
0
        private void FormInsSelectSubscr_Load(object sender, System.EventArgs e)
        {
            SubList = InsSubs.GetListForSubscriber(Subscriber);
            List <InsPlan> planList = InsPlans.RefreshForSubList(SubList);
            //PatPlan[] patPlanArray;
            string  str;
            InsPlan plan;

            for (int i = 0; i < SubList.Count; i++)
            {
                plan = InsPlans.GetPlan(SubList[i].PlanNum, planList);
                str  = InsPlans.GetCarrierName(SubList[i].PlanNum, planList);
                if (plan.GroupNum != "")
                {
                    str += Lan.g(this, " group:") + plan.GroupNum;
                }
                int countPatPlans = PatPlans.GetCountBySubNum(SubList[i].InsSubNum);
                if (countPatPlans == 0)
                {
                    str += " " + Lan.g(this, "(not in use)");
                }
                listPlans.Items.Add(str);
            }
        }
예제 #18
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);
        }
예제 #19
0
        private void FillGrid()
        {
            gridRemainTimeUnits.BeginUpdate();
            gridRemainTimeUnits.ListGridRows.Clear();
            List <PatPlan> listPatPlans    = PatPlans.Refresh(_patCur.PatNum);
            List <InsSub>  listInsSubs     = InsSubs.GetMany(listPatPlans.Select(x => x.InsSubNum).ToList());
            List <Benefit> listPatBenefits = Benefits.Refresh(listPatPlans, listInsSubs);

            if (listPatBenefits.IsNullOrEmpty())
            {
                gridRemainTimeUnits.EndUpdate();
                return;
            }
            List <InsPlan> listInsPlans = InsPlans.GetByInsSubs(listInsSubs.Select(x => x.InsSubNum).ToList());
            List <Carrier> listCarriers = Carriers.GetCarriers(listInsPlans.Select(x => x.CarrierNum).ToList());
            //Get the LIM information for all potential subscribers.
            List <Patient> listSubscribers = Patients.GetLimForPats(listInsSubs.Select(x => x.Subscriber).ToList());
            GridRow        gridRow;
            //Get the last year of completed procedures because there is no current TimePeriod for benefits that will care about older procedures.
            //A subset of these procedures will be used for each specific benefit in order to correctly represent the time units remaining.
            List <Procedure> listCompletedProcs = Procedures.GetCompletedForDateRange(
                DateTime.Today.AddYears(-1),
                DateTimeOD.Today,
                listPatNums: new List <long> {
                _patCur.PatNum
            });
            //Get all of the claimprocs associated to the completed procedures in order to link procedures to insurance plans.
            List <ClaimProc> listClaimProcs = ClaimProcs.GetForProcs(listCompletedProcs.Select(x => x.ProcNum).ToList());

            foreach (Benefit benefit in listPatBenefits)
            {
                if (benefit.CovCatNum == 0 ||           //no category
                    benefit.BenefitType != InsBenefitType.Limitations ||                     //benefit type is not limitations
                    (benefit.TimePeriod != BenefitTimePeriod.CalendarYear &&                     //neither calendar year, serviceyear, or 12 months
                     benefit.TimePeriod != BenefitTimePeriod.ServiceYear &&
                     benefit.TimePeriod != BenefitTimePeriod.NumberInLast12Months) ||
                    benefit.Quantity < 0 ||                    //quantity is negative (negatives are allowed in FormBenefitEdit)
                    benefit.QuantityQualifier != BenefitQuantity.NumberOfServices ||                    //qualifier us not the number of services
                    (benefit.CoverageLevel != BenefitCoverageLevel.Family &&                     //neither individual nor family coverage level
                     benefit.CoverageLevel != BenefitCoverageLevel.Individual))
                {
                    continue;
                }
                List <Procedure> listProcs;
                //for calendar year, get completed procs from January.01.CurYear ~ Curdate
                if (benefit.TimePeriod == BenefitTimePeriod.CalendarYear)
                {
                    //01/01/CurYear. is there a better way?
                    listProcs = listCompletedProcs.FindAll(x => x.ProcDate >= new DateTime(DateTimeOD.Today.Year, 1, 1));
                }
                else if (benefit.TimePeriod == BenefitTimePeriod.NumberInLast12Months)
                {
                    //today - 12 months - 1 day. Procedures exactly 1 year ago are not counted in the range
                    listProcs = listCompletedProcs.FindAll(x => x.ProcDate >= DateTimeOD.Today.AddYears(-1).AddDays(1));
                }
                else                                                                  //if not calendar year, then it must be service year
                {
                    int monthRenew = InsPlans.RefreshOne(benefit.PlanNum).MonthRenew; //monthrenew only stores the month as an int.
                    if (DateTimeOD.Today.Month >= monthRenew)                         //if the the current date is past the renewal month, use the current year
                    {
                        listProcs = listCompletedProcs.FindAll(x => x.ProcDate >= new DateTime(DateTimeOD.Today.Year, monthRenew, 1));
                    }
                    else                       //otherwise use the previous year
                    {
                        listProcs = listCompletedProcs.FindAll(x => x.ProcDate >= new DateTime(DateTimeOD.Today.Year - 1, monthRenew, 1));
                    }
                }
                Dictionary <long, List <ClaimProc> > dictClaimProcsPerSub;
                if (benefit.PatPlanNum != 0)
                {
                    //The list of benefits that we are looping through was filled via listPatPlans so this will never fail.
                    //If this line fails then it means that there was a valid PlanNum AND a valid PatPlanNum set on the benefit which is invalid ATM.
                    dictClaimProcsPerSub = listClaimProcs.FindAll(x => x.InsSubNum == listPatPlans.First(y => y.PatPlanNum == benefit.PatPlanNum).InsSubNum)
                                           .GroupBy(x => x.InsSubNum)
                                           .ToDictionary(x => x.Key, x => x.ToList());
                }
                else                  //benefit.PatPlanNum was not set so benefit.PlanNum must be set.
                {
                    dictClaimProcsPerSub = listClaimProcs.FindAll(x => x.PlanNum == benefit.PlanNum)
                                           .GroupBy(x => x.InsSubNum)
                                           .ToDictionary(x => x.Key, x => x.ToList());
                }
                foreach (long insSubNum in dictClaimProcsPerSub.Keys)
                {
                    //The insSubNum should have a corresponding entry within listInsSubs.
                    InsSub insSub = listInsSubs.FirstOrDefault(x => x.InsSubNum == insSubNum);
                    if (insSub == null)
                    {
                        continue;                        //If not found then there are claimprocs associated to an inssub that is associated to a dropped or missing plan.
                    }
                    InsPlan insPlan    = listInsPlans.FirstOrDefault(x => x.PlanNum == insSub.PlanNum);
                    Carrier carrier    = listCarriers.FirstOrDefault(x => x.CarrierNum == insPlan.CarrierNum);
                    Patient subscriber = listSubscribers.FirstOrDefault(x => x.PatNum == insSub.Subscriber);
                    CovCat  category   = CovCats.GetCovCat(benefit.CovCatNum);
                    //Filter out any procedures that are not associated to the insurance plan of the current benefit.
                    List <Procedure> listFilterProcs = listProcs.FindAll(x => x.ProcNum.In(dictClaimProcsPerSub[insSubNum].Select(y => y.ProcNum)));
                    //Calculate the amount used for one benefit.
                    double amtUsed   = CovCats.GetAmtUsedForCat(listFilterProcs, category);
                    double amtRemain = benefit.Quantity - amtUsed;
                    gridRow = new GridRow((carrier == null) ? "Unknown" : carrier.CarrierName,
                                          (subscriber == null) ? "Unknown" : subscriber.GetNameFL(),
                                          category.Description.ToString(),
                                          benefit.Quantity.ToString(),
                                          amtUsed.ToString("F"),
                                          (amtRemain > 0) ? amtRemain.ToString("F") : "0");
                    gridRemainTimeUnits.ListGridRows.Add(gridRow);
                }
            }
            gridRemainTimeUnits.EndUpdate();
        }
예제 #20
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;
            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);
            ProcedureCode  procCodeCur = ProcedureCodes.GetProcCode(ProcCur.CodeNum);

            ProcCur.MedicalCode = procCodeCur.MedicalCode;
            if (procCodeCur.IsHygiene && pat.SecProv != 0)
            {
                ProcCur.ProvNum = pat.SecProv;
            }
            else
            {
                ProcCur.ProvNum = pat.PriProv;
            }
            ProcCur.ClinicNum = pat.ClinicNum;
            ProcCur.ProcFee   = Procedures.GetProcFee(pat, patPlanList, subList, planList, ProcCur.CodeNum, ProcCur.ProvNum, ProcCur.ClinicNum, ProcCur.MedicalCode);
            //surf
            //ToothNum
            //Procedures.Cur.ToothRange
            //ProcCur.NoBillIns=ProcedureCodes.GetProcCode(ProcCur.ProcCode).NoBillIns;
            ProcCur.Priority   = 0;
            ProcCur.ProcStatus = ProcStat.TP;
            ProcCur.Note       = "";
            //dx
            //nextaptnum
            ProcCur.DateEntryC     = DateTime.Now;
            ProcCur.BaseUnits      = procCodeCur.BaseUnits;
            ProcCur.SiteNum        = pat.SiteNum;
            ProcCur.RevCode        = procCodeCur.RevenueCodeDefault;
            ProcCur.DiagnosticCode = PrefC.GetString(PrefName.ICD9DefaultForNewProcs);
            ProcCur.PlaceService   = (PlaceOfService)PrefC.GetInt(PrefName.DefaultProcedurePlaceService);        //Default proc place of service for the Practice is used.
            if (Userods.IsUserCpoe(Security.CurUser))
            {
                //This procedure is considered CPOE because the provider is the one that has added it.
                ProcCur.IsCpoe = true;
            }
            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();
        }
예제 #21
0
        private void butNewClaims_Click(object sender, EventArgs e)
        {
            if (gridMain.SelectedIndices.Length == 0)           //No selections made.
            {
                MsgBox.Show(this, "Please select at least one procedure.");
                return;
            }
            if (!ContrAccount.CheckClearinghouseDefaults())
            {
                return;
            }
            //Generate List and Table----------------------------------------------------------------------------------------------------------------------
            //List of all procedures being shown.
            //Pulls procedures based off of the PatNum, if the row was selected in gridMain and if it has been attached to a claim.
            List <ProcNotBilled> listNotBilledProcs = new List <ProcNotBilled>();
            List <long>          listPatNums        = new List <long>();
            Patient          patOld            = new Patient();
            List <Claim>     listPatClaims     = new List <Claim>();
            List <ClaimProc> listPatClaimProcs = new List <ClaimProc>();
            List <ClaimProc> listCurClaimProcs = new List <ClaimProc>();
            //Table rows need to be 1:1 with gridMain rows due to logic in ContrAccount.toolBarButIns_Click(...).
            DataTable table = new DataTable();

            //Required columns as mentioned by ContrAccount.toolBarButIns_Click().
            table.Columns.Add("ProcNum");
            table.Columns.Add("chargesDouble");
            table.Columns.Add("ProcNumLab");
            for (int i = 0; i < gridMain.Rows.Count; i++)                         //Loop through gridMain to construct listNotBilledProcs.
            {
                long      procNumCur = PIn.Long(gridMain.Rows[i].Tag.ToString()); //Tag is set to procNum in fillGrid().
                Procedure procCur    = Procedures.GetOneProc(procNumCur, false);
                long      patNumCur  = procCur.PatNum;
                if (patOld.PatNum != patNumCur)               //Procedures in gridMain are ordered by patient, so when the patient changes, we know previous patient is complete.
                {
                    listPatClaims     = Claims.Refresh(patNumCur);
                    listPatClaimProcs = ClaimProcs.Refresh(patNumCur);
                    patOld            = Patients.GetPat(procCur.PatNum);
                }
                listCurClaimProcs = ClaimProcs.GetForProc(listPatClaimProcs, procNumCur);
                bool hasPriClaim = false;
                bool hasSecClaim = false;
                for (int j = 0; j < listCurClaimProcs.Count; j++)
                {
                    ClaimProc claimProcCur = listCurClaimProcs[j];
                    if (claimProcCur.ClaimNum > 0 && claimProcCur.Status != ClaimProcStatus.Preauth && claimProcCur.Status != ClaimProcStatus.Estimate)
                    {
                        Claim claimCur = Claims.GetFromList(listPatClaims, claimProcCur.ClaimNum);
                        switch (claimCur.ClaimType)
                        {
                        case "P":
                            hasPriClaim = true;
                            break;

                        case "S":
                            hasSecClaim = true;
                            break;
                        }
                    }
                }
                bool isSelected = gridMain.SelectedIndices.Contains(i);
                listNotBilledProcs.Add(new ProcNotBilled(patOld, procNumCur, i, isSelected, hasPriClaim, hasSecClaim, procCur.ClinicNum, procCur.PlaceService));
                DataRow row = table.NewRow();
                row["ProcNum"] = procNumCur;
                #region Calculate chargesDouble
                //Logic copied from AccountModules.GetAccount(...) line 857.
                double qty = (procCur.UnitQty + procCur.BaseUnits);
                if (qty == 0)
                {
                    qty = 1;
                }
                double writeOffCapSum = listPatClaimProcs.Where(x => x.Status == ClaimProcStatus.CapComplete).Select(y => y.WriteOff).ToList().Sum();
                row["chargesDouble"] = (procCur.ProcFee * qty) - writeOffCapSum;
                row["ProcNumLab"]    = procCur.ProcNumLab;
                #endregion Calculate chargesDouble
                table.Rows.Add(row);
                if (listPatNums.Contains(patNumCur))
                {
                    continue;
                }
                listPatNums.Add(patNumCur);
            }
            List <List <ProcNotBilled> > listGroupedProcs = new List <List <ProcNotBilled> >();
            Patient          patCur           = null;
            List <PatPlan>   listPatPlans     = null;
            List <InsSub>    listInsSubs      = null;
            List <InsPlan>   listInsPlans     = null;
            List <Procedure> listPatientProcs = null;
            ProcNotBilled    procNotBilled    = new ProcNotBilled();    //When automatically grouping,  this is used as the procedure to group by.
            long             patNumOld        = 0;
            int claimCreatedCount             = 0;
            int patIndex = 0;
            //The procedures show in the grid ordered by patient.  Also listPatNums contains unique patnums which are in the same order as the grid.
            while (patIndex < listPatNums.Count)
            {
                List <ProcNotBilled> listProcs = listNotBilledProcs.Where(x => x.Patient.PatNum == listPatNums[patIndex] && x.IsRowSelected && !x.IsAttached).ToList();
                if (listProcs.Count == 0)
                {
                    patNumOld = listPatNums[patIndex];
                    patIndex++;                    //No procedures were selected for this patient.
                    continue;
                }
                else
                {
                    //Maintain the same patient, in order to create one or more additional claims for the remaining procedures.
                    //Currently will only happen for specific instances;
                    //--Canadian customers who are attempting to create a claim with over 7 procedures.
                    //--When checkAutoGroupProcs is checked and when there are multiple procedure groupings by GroupKey status, ClinicNum, and placeService.
                }
                if (patNumOld != listPatNums[patIndex])               //The patient could repeat if we had to group the procedures for the patinet into multiple claims.
                {
                    patCur           = Patients.GetPat(listPatNums[patIndex]);
                    listPatPlans     = PatPlans.Refresh(patCur.PatNum);
                    listInsSubs      = InsSubs.RefreshForFam(Patients.GetFamily(patCur.PatNum));
                    listInsPlans     = InsPlans.RefreshForSubList(listInsSubs);
                    listPatientProcs = Procedures.Refresh(patCur.PatNum);
                }
                if (checkAutoGroupProcs.Checked)                 //Automatically Group Procedures.
                {
                    procNotBilled = listProcs[0];
                    //Update listProcs to reflect those that match the procNotBilled values.
                    listProcs = listProcs.FindAll(x => x.HasPriClaim == procNotBilled.HasPriClaim && x.HasSecClaim == procNotBilled.HasSecClaim);
                    if (PrefC.HasClinicsEnabled)                     //Group by clinic only if clinics enabled.
                    {
                        listProcs = listProcs.FindAll(x => x.ClinicNum == procNotBilled.ClinicNum);
                    }
                    else if (!PrefC.GetBool(PrefName.EasyHidePublicHealth))                     //Group by Place of Service only if Public Health feature is enabled.
                    {
                        listProcs = listProcs.FindAll(x => x.PlaceService == procNotBilled.PlaceService);
                    }
                }
                GetUniqueDiagnosticCodes(listProcs, listPatientProcs, listPatPlans, listInsSubs, listInsPlans);
                if (listProcs.Count > 7 && CultureInfo.CurrentCulture.Name.EndsWith("CA")) //Canadian. en-CA or fr-CA
                {
                    listProcs = listProcs.Take(7).ToList();                                //Returns first 7 items of the list.
                }
                listProcs.ForEach(x => x.IsAttached = true);                               //This way we can not attach procedures to multiple claims thanks to the logic above.
                if (listProcs.Any(x => listProcs[0].PlaceService != x.PlaceService) || listProcs.Any(x => listProcs[0].ClinicNum != x.ClinicNum))
                {
                    //Regardless if we are automatically grouping or not,
                    //if all procs in our list at this point do not share the same PlaceService or ClinicNum then claims will not be made.
                }
                else                  //Basic validation passed.
                {
                    if (!listProcs[0].HasPriClaim &&                 //Medical claim.
                        PatPlans.GetOrdinal(PriSecMed.Medical, listPatPlans, listInsPlans, listInsSubs) > 0 &&                    //Has medical ins.
                        PatPlans.GetOrdinal(PriSecMed.Primary, listPatPlans, listInsPlans, listInsSubs) == 0 &&                    //Does not have primary dental ins.
                        PatPlans.GetOrdinal(PriSecMed.Secondary, listPatPlans, listInsPlans, listInsSubs) == 0)                       //Does not have secondary dental ins.
                    {
                        claimCreatedCount++;
                    }
                    else                                                                                                                      //Not a medical claim.
                    {
                        if (!listProcs[0].HasPriClaim && PatPlans.GetOrdinal(PriSecMed.Primary, listPatPlans, listInsPlans, listInsSubs) > 0) //Primary claim.
                        {
                            claimCreatedCount++;
                        }
                        if (!listProcs[0].HasSecClaim && PatPlans.GetOrdinal(PriSecMed.Secondary, listPatPlans, listInsPlans, listInsSubs) > 0)                  //Secondary claim.
                        {
                            claimCreatedCount++;
                        }
                    }
                }
                listGroupedProcs.Add(listProcs);
            }
            if (!MsgBox.Show(this, true, "Clicking continue will create up to " + POut.Int(claimCreatedCount) + " claims and cannot be undone, except by manually going to each account.  "
                             + "Some claims may not be created if there are validation issues.  Would you like to proceed?"))
            {
                return;
            }
            //Create Claims--------------------------------------------------------------------------------------------------------------------------------
            claimCreatedCount = 0;
            string claimErrors = "";
            foreach (List <ProcNotBilled> listProcs in listGroupedProcs)
            {
                patCur = listProcs[0].Patient;
                gridMain.SetSelected(false);                //Need to deslect all rows each time so that ContrAccount.toolBarButIns_Click(...) only uses pertinent rows.
                for (int j = 0; j < listProcs.Count; j++)
                {
                    gridMain.SetSelected(listProcs[j].RowIndex, true);                   //Select the pertinent rows so that they will be attached to the claim below.
                }
                ContrAccount.toolBarButIns_Click(false, patCur, Patients.GetFamily(patCur.PatNum), gridMain, table,
                                                 procNotBilled.HasPriClaim, procNotBilled.HasSecClaim);
                string errorTitle = patCur.PatNum + " " + patCur.GetNameLFnoPref() + " - ";
                if (patNumOld == patCur.PatNum && !string.IsNullOrEmpty(ContrAccount.ClaimErrorsCur))
                {
                    claimErrors += "\t\t" + ContrAccount.ClaimErrorsCur + "\r\n";
                }
                else if (!string.IsNullOrEmpty(ContrAccount.ClaimErrorsCur))
                {
                    claimErrors += errorTitle + ContrAccount.ClaimErrorsCur + "\r\n";
                }
                claimCreatedCount += ContrAccount.ClaimCreatedCount;
                patNumOld          = patCur.PatNum;
            }
            FillGrid();
            if (!string.IsNullOrEmpty(claimErrors))
            {
                MsgBoxCopyPaste form = new MsgBoxCopyPaste(claimErrors);
                form.ShowDialog();
            }
            MessageBox.Show(Lan.g(this, "Number of claims created") + ": " + claimCreatedCount);
        }
예제 #22
0
        private void butGenerateClaims_Click(object sender, EventArgs e)
        {
            if (gridMain.SelectedIndices.Count() < 1)
            {
                MsgBox.Show(this, "Please select the rows for which you would like to create procedures and claims.");
                return;
            }
            if (!MsgBox.Show(this, MsgBoxButtons.YesNo, "Are you sure you want to generate claims and procedures for all patients and insurance plans?"))
            {
                return;
            }
            List <long> listPlanNums    = new List <long>();
            List <long> listPatPlanNums = new List <long>();
            List <long> listInsSubNums  = new List <long>();

            for (int i = 0; i < gridMain.SelectedIndices.Count(); i++)
            {
                DataRow rowCur = (DataRow)gridMain.Rows[gridMain.SelectedIndices[i]].Tag;
                listPlanNums.Add(PIn.Long(rowCur["PlanNum"].ToString()));
                listPatPlanNums.Add(PIn.Long(rowCur["PatPlanNum"].ToString()));
                listInsSubNums.Add(PIn.Long(rowCur["InsSubNum"].ToString()));
            }
            List <InsPlan> listSelectedInsPlans = InsPlans.GetPlans(listPlanNums);
            List <PatPlan> listSelectedPatPlans = PatPlans.GetPatPlans(listPatPlanNums);
            List <InsSub>  listSelectedInsSubs  = InsSubs.GetMany(listInsSubNums);
            List <DataRow> rowsSucceeded        = new List <DataRow>();
            int            rowsFailed           = 0;
            List <Benefit> listBenefitsAll      = Benefits.Refresh(listSelectedPatPlans, listSelectedInsSubs);

            for (int i = 0; i < gridMain.SelectedIndices.Count(); i++)
            {
                try {
                    DataRow     rowCur        = (DataRow)gridMain.Rows[gridMain.SelectedIndices[i]].Tag;
                    long        patNumCur     = PIn.Long(rowCur["PatNum"].ToString());
                    Patient     patCur        = Patients.GetPat(patNumCur);
                    PatientNote patNoteCur    = PatientNotes.Refresh(patNumCur, patCur.Guarantor);
                    long        codeNumCur    = PIn.Long(rowCur["AutoCodeNum"].ToString());
                    long        provNumCur    = PIn.Long(rowCur["ProvNum"].ToString());
                    long        clinicNumCur  = PIn.Long(rowCur["ClinicNum"].ToString());
                    long        insPlanNumCur = PIn.Long(rowCur["PlanNum"].ToString());
                    long        patPlanNumCur = PIn.Long(rowCur["PatPlanNum"].ToString());
                    long        insSubNumCur  = PIn.Long(rowCur["InsSubNum"].ToString());
                    int         monthsTreat   = PIn.Int(rowCur["MonthsTreat"].ToString());
                    DateTime    dateDue       = PIn.Date(rowCur["OrthoAutoNextClaimDate"].ToString());
                    //for each selected row
                    //create a procedure
                    //Procedures.CreateProcForPat(patNumCur,codeNumCur,"","",ProcStat.C,provNumCur);
                    Procedure      proc        = Procedures.CreateOrthoAutoProcsForPat(patNumCur, codeNumCur, provNumCur, clinicNumCur, dateDue);
                    InsPlan        insPlanCur  = InsPlans.GetPlan(insPlanNumCur, listSelectedInsPlans);
                    PatPlan        patPlanCur  = listSelectedPatPlans.FirstOrDefault(x => x.PatPlanNum == patPlanNumCur);
                    InsSub         insSubCur   = listSelectedInsSubs.FirstOrDefault(x => x.InsSubNum == insSubNumCur);
                    List <Benefit> benefitList = listBenefitsAll.FindAll(x => x.PatPlanNum == patPlanCur.PatPlanNum || x.PlanNum == insSubCur.PlanNum);
                    //create a claimproc
                    List <ClaimProc> listClaimProcs = new List <ClaimProc>();
                    Procedures.ComputeEstimates(proc, patNumCur, ref listClaimProcs, true, new List <InsPlan> {
                        insPlanCur
                    },
                                                new List <PatPlan> {
                        patPlanCur
                    }, benefitList, null, null, true, patCur.Age, new List <InsSub> {
                        insSubCur
                    }, isForOrtho: true);
                    //make the feebilled == the insplan feebilled or patplan feebilled
                    double feebilled = patPlanCur.OrthoAutoFeeBilledOverride == -1 ? insPlanCur.OrthoAutoFeeBilled : patPlanCur.OrthoAutoFeeBilledOverride;
                    //create a claim with that claimproc
                    string claimType = "";
                    switch (patPlanCur.Ordinal)
                    {
                    case 1:
                        claimType = "P";
                        break;

                    case 2:
                        claimType = "S";
                        break;
                    }
                    DateTimeOD dateTMonthsRem = new DateTimeOD(PIn.Date(rowCur["DateBanding"].ToString()).AddMonths(PIn.Int(rowCur["MonthsTreat"].ToString())), DateTimeOD.Today);
                    Claims.CreateClaimForOrthoProc(claimType, patPlanCur, insPlanCur, insSubCur,
                                                   ClaimProcs.GetForProcWithOrdinal(proc.ProcNum, patPlanCur.Ordinal), proc, feebilled, PIn.Date(rowCur["DateBanding"].ToString()),
                                                   PIn.Int(rowCur["MonthsTreat"].ToString()), ((dateTMonthsRem.YearsDiff * 12) + dateTMonthsRem.MonthsDiff));
                    PatPlans.IncrementOrthoNextClaimDates(patPlanCur, insPlanCur, monthsTreat, patNoteCur);
                    rowsSucceeded.Add(rowCur);
                    SecurityLogs.MakeLogEntry(Permissions.ProcComplCreate, patCur.PatNum
                                              , Lan.g(this, "Automatic ortho procedure and claim generated for") + " " + dateDue.ToShortDateString());
                }
                catch (Exception) {
                    rowsFailed++;
                }
            }
            string message = Lan.g(this, "Done.") + " " + Lan.g(this, "There were") + " " + rowsSucceeded.Count + " "
                             + Lan.g(this, "claim(s) generated and") + " " + rowsFailed + " " + Lan.g(this, "failures") + ".";

            MessageBox.Show(message);
            foreach (DataRow row in rowsSucceeded)
            {
                _tableOutstandingAutoClaims.Rows.Remove(row);
            }
            FillGrid();
        }
예제 #23
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);
        }
예제 #24
0
        private void Import834_Unsafe()
        {
            if (!MsgBox.Show(this, true, "Importing insurance plans is a database intensive operation and can take 10 minutes or more to run.  "
                             + "It is best to import insurance plans after hours or during another time period when database usage is otherwise low.\r\n"
                             + "Click OK to import insurance plans now, or click Cancel."))
            {
                return;
            }
            checkIsPatientCreate.Enabled = false;
            gridInsPlans.Enabled         = false;
            butOK.Enabled     = false;
            butCancel.Enabled = false;
            Cursor            = Cursors.WaitCursor;
            Prefs.UpdateBool(PrefName.Ins834IsPatientCreate, checkIsPatientCreate.Checked);
            int           rowIndex             = 1;
            int           createdPatsCount     = 0;
            int           updatedPatsCount     = 0;
            int           skippedPatsCount     = 0;
            int           createdCarrierCount  = 0;
            int           createdPlanCount     = 0;
            int           droppedPlanCount     = 0;
            int           updatedPlanCount     = 0;
            StringBuilder sbErrorMessages      = new StringBuilder();
            List <int>    listImportedSegments = new List <int> ();      //Used to reconstruct the 834 with imported patients removed.

            for (int i = 0; i < _x834.ListTransactions.Count; i++)
            {
                Hx834_Tran tran = _x834.ListTransactions[i];
                for (int j = 0; j < tran.ListMembers.Count; j++)
                {
                    Hx834_Member member = tran.ListMembers[j];
                    ShowStatus("Progress " + (rowIndex).ToString().PadLeft(6) + "/" + gridInsPlans.Rows.Count.ToString().PadLeft(6)
                               + "  Importing plans for patient " + member.Pat.GetNameLF());
                    //The patient's status is not affected by the maintenance code.  After reviewing all of the possible maintenance codes in
                    //member.MemberLevelDetail.MaintenanceTypeCode, we believe that all statuses suggest either insert or update, except for "Cancel".
                    //Nathan and Derek feel that archiving the patinet in response to a Cancel request is a bit drastic.
                    //Thus we ignore the patient maintenance code and always assume insert/update.
                    //Even if the status was "Cancel", then updating the patient does not hurt.
                    bool isMemberImported = false;
                    bool isMultiMatch     = false;
                    if (member.Pat.PatNum == 0)
                    {
                        //The patient may need to be created below.  However, the patient may have already been inserted in a pervious iteration of this loop
                        //in following scenario: Two different 834s include updates for the same patient and both documents are being imported at the same time.
                        //If the patient was already inserted, then they would show up in _listPatients and also in the database.  Attempt to locate the patient
                        //in _listPatients again before inserting.
                        List <Patient> listPatientMatches = Patients.GetPatientsByNameAndBirthday(member.Pat, _listPatients);
                        if (listPatientMatches.Count == 1)
                        {
                            member.Pat.PatNum = listPatientMatches[0].PatNum;
                        }
                        else if (listPatientMatches.Count > 1)
                        {
                            isMultiMatch = true;
                        }
                    }
                    if (isMultiMatch)
                    {
                        skippedPatsCount++;
                    }
                    else if (member.Pat.PatNum == 0 && checkIsPatientCreate.Checked)
                    {
                        //The code here mimcs the behavior of FormPatientSelect.butAddPt_Click().
                        Patients.Insert(member.Pat, false);
                        Patient memberPatOld = member.Pat.Copy();
                        member.Pat.PatStatus   = PatientStatus.Patient;
                        member.Pat.BillingType = PrefC.GetLong(PrefName.PracticeDefaultBillType);
                        if (!PrefC.GetBool(PrefName.PriProvDefaultToSelectProv))
                        {
                            //Set the patients primary provider to the practice default provider.
                            member.Pat.PriProv = Providers.GetDefaultProvider().ProvNum;
                        }
                        member.Pat.ClinicNum = Clinics.ClinicNum;
                        member.Pat.Guarantor = member.Pat.PatNum;
                        Patients.Update(member.Pat, memberPatOld);
                        int patIdx    = _listPatients.BinarySearch(member.Pat); //Preserve sort order by locating the index in which to insert the newly added patient.
                        int insertIdx = ~patIdx;                                //According to MSDN, the index returned by BinarySearch() is a "bitwise compliment", since not currently in list.
                        _listPatients.Insert(insertIdx, member.Pat);
                        SecurityLogs.MakeLogEntry(Permissions.PatientCreate, member.Pat.PatNum, "Created from Import Ins Plans 834.", LogSources.InsPlanImport834);
                        isMemberImported = true;
                        createdPatsCount++;
                    }
                    else if (member.Pat.PatNum == 0 && !checkIsPatientCreate.Checked)
                    {
                        skippedPatsCount++;
                    }
                    else                                                                                  //member.Pat.PatNum!=0
                    {
                        Patient patDb = _listPatients.FirstOrDefault(x => x.PatNum == member.Pat.PatNum); //Locate by PatNum, in case user selected manually.
                        member.MergePatientIntoDbPatient(patDb);                                          //Also updates the patient to the database and makes log entry.
                        _listPatients.Remove(patDb);                                                      //Remove patient from list so we can add it back in the correct location (in case name or bday changed).
                        int patIdx = _listPatients.BinarySearch(patDb);                                   //Preserve sort order by locating the index in which to insert the newly added patient.
                        //patIdx could be positive if the user manually selected a patient when there were multiple matches found.
                        //If patIdx is negative, then according to MSDN, the index returned by BinarySearch() is a "bitwise compliment".
                        //If there were mult instances of patDb BinarySearch() would return 0, which should not be complimented (OutOfRangeException)
                        int insertIdx = (patIdx >= 0)?patIdx:~patIdx;
                        _listPatients.Insert(insertIdx, patDb);
                        isMemberImported = true;
                        updatedPatsCount++;
                    }
                    if (isMemberImported)
                    {
                        //Import insurance changes for patient.
                        for (int k = 0; k < member.ListHealthCoverage.Count; k++)
                        {
                            Hx834_HealthCoverage healthCoverage = member.ListHealthCoverage[k];
                            if (k > 0)
                            {
                                rowIndex++;
                            }
                            List <Carrier> listCarriers = Carriers.GetByNameAndTin(tran.Payer.Name, tran.Payer.IdentificationCode);
                            if (listCarriers.Count == 0)
                            {
                                Carrier carrier = new Carrier();
                                carrier.CarrierName = tran.Payer.Name;
                                carrier.TIN         = tran.Payer.IdentificationCode;
                                Carriers.Insert(carrier);
                                DataValid.SetInvalid(InvalidType.Carriers);
                                listCarriers.Add(carrier);
                                SecurityLogs.MakeLogEntry(Permissions.CarrierCreate, 0, "Carrier '" + carrier.CarrierName
                                                          + "' created from Import Ins Plans 834.", LogSources.InsPlanImport834);
                                createdCarrierCount++;
                            }
                            //Update insurance plans.  Match based on carrier and SubscriberId.
                            bool isDropping = false;
                            if (healthCoverage.HealthCoverage.MaintenanceTypeCode == "002")
                            {
                                isDropping = true;
                            }
                            //The insPlanNew will only be inserted if necessary.  Created temporarily in order to determine if insert is needed.
                            InsPlan insPlanNew = InsertOrUpdateInsPlan(null, member, listCarriers[0], false);
                            //Since the insurance plans in the 834 do not include very much information, it is likely that many patients will share the same exact plan.
                            //We look for an existing plan being used by any other patinents which match the fields we typically import.
                            List <InsPlan> listInsPlans = InsPlans.GetAllByCarrierNum(listCarriers[0].CarrierNum);
                            InsPlan        insPlanMatch = null;
                            for (int p = 0; p < listInsPlans.Count; p++)
                            {
                                //Set the PlanNums equal so that AreEqualValue() will ignore this field.  We must ignore PlanNum, since we do not know the PlanNum.
                                insPlanNew.PlanNum = listInsPlans[p].PlanNum;
                                if (InsPlans.AreEqualValue(listInsPlans[p], insPlanNew))
                                {
                                    insPlanMatch = listInsPlans[p];
                                    break;
                                }
                            }
                            Family         fam          = Patients.GetFamily(member.Pat.PatNum);
                            List <InsSub>  listInsSubs  = InsSubs.RefreshForFam(fam);
                            List <PatPlan> listPatPlans = PatPlans.Refresh(member.Pat.PatNum);
                            InsSub         insSubMatch  = null;
                            PatPlan        patPlanMatch = null;
                            for (int p = 0; p < listInsSubs.Count; p++)
                            {
                                InsSub insSub = listInsSubs[p];
                                //According to section 1.4.3 of the standard, the preferred method of matching a dependent to a subscriber is to use the subscriberId.
                                if (insSub.SubscriberID.Trim() != member.SubscriberId.Trim())
                                {
                                    continue;
                                }
                                insSubMatch  = insSub;
                                patPlanMatch = PatPlans.GetFromList(listPatPlans, insSub.InsSubNum);
                                break;
                            }
                            if (patPlanMatch == null && isDropping)                           //No plan match and dropping plan.
                            //Nothing to do.  The plan either never existed or is already dropped.
                            {
                            }
                            else if (patPlanMatch == null && !isDropping)                           //No plan match and not dropping plan.  Create the plan.
                            {
                                insPlanMatch = InsertOrUpdateInsPlan(insPlanMatch, member, listCarriers[0]);
                                insSubMatch  = InsertOrUpdateInsSub(insSubMatch, insPlanMatch, member, healthCoverage, listCarriers[0]);
                                patPlanMatch = InsertOrUpdatePatPlan(patPlanMatch, insSubMatch, insPlanMatch, member, listCarriers[0], listPatPlans);
                                createdPlanCount++;
                            }
                            else if (patPlanMatch != null && isDropping)                           //Plan matched and dropping plan.  Drop the plan.
                            //This code mimics the behavior of FormInsPlan.butDrop_Click(), except here we do not care if there are claims for this plan today.
                            //We need this feature to be as streamlined as possible so that it might become an automated process later.
                            //Testing for claims on today's date does not seem that useful anyway, or at least not as useful as checking for any claims
                            //associated to the plan, instead of just today's date.
                            {
                                PatPlans.Delete(patPlanMatch.PatPlanNum);                                //Estimates recomputed within Delete()
                                SecurityLogs.MakeLogEntry(Permissions.InsPlanDropPat, patPlanMatch.PatNum,
                                                          "Insurance plan dropped from patient for carrier '" + listCarriers[0].CarrierName + "' and groupnum "
                                                          + "'" + insPlanMatch.GroupNum + "' and subscriber ID '" + insSubMatch.SubscriberID + "' "
                                                          + "from Import Ins Plans 834.", insPlanMatch.PlanNum, LogSources.InsPlanImport834, insPlanMatch.SecDateTEdit);
                                droppedPlanCount++;
                            }
                            else if (patPlanMatch != null && !isDropping)                            //Plan matched and not dropping plan.  Update the plan.
                            {
                                insPlanMatch = InsertOrUpdateInsPlan(insPlanMatch, member, listCarriers[0]);
                                insSubMatch  = InsertOrUpdateInsSub(insSubMatch, insPlanMatch, member, healthCoverage, listCarriers[0]);
                                patPlanMatch = InsertOrUpdatePatPlan(patPlanMatch, insSubMatch, insPlanMatch, member, listCarriers[0], listPatPlans);
                                updatedPlanCount++;
                            }
                        }                        //end loop k
                        //Remove the member from the X834.
                        int endSegIndex = 0;
                        if (j < tran.ListMembers.Count - 1)
                        {
                            endSegIndex = tran.ListMembers[j + 1].MemberLevelDetail.SegmentIndex - 1;
                        }
                        else
                        {
                            X12Segment segSe = _x834.GetNextSegmentById(member.MemberLevelDetail.SegmentIndex + 1, "SE");                       //SE segment is required.
                            endSegIndex = segSe.SegmentIndex - 1;
                        }
                        for (int s = member.MemberLevelDetail.SegmentIndex; s <= endSegIndex; s++)
                        {
                            listImportedSegments.Add(s);
                        }
                    }
                    rowIndex++;
                }                                                       //end loop j
            }                                                           //end loop i
            if (listImportedSegments.Count > 0 && skippedPatsCount > 0) //Some patients imported, while others did not.
            {
                if (MoveFileToArchiveFolder())
                {
                    //Save the unprocessed members back to the import directory, so the user can try to import them again.
                    File.WriteAllText(_x834.FilePath, _x834.ReconstructRaw(listImportedSegments));
                }
            }
            else if (listImportedSegments.Count > 0)             //All patinets imported.
            {
                MoveFileToArchiveFolder();
            }
            else if (skippedPatsCount > 0)             //No patients imported.  All patients were skipped.
            //Leave the raw file unaltered and where it is, so it can be processed again.
            {
            }
            Cursor = Cursors.Default;
            string msg = Lan.g(this, "Done.");

            if (createdPatsCount > 0)
            {
                msg += "\r\n" + Lan.g(this, "Number of patients created:") + " " + createdPatsCount;
            }
            if (updatedPatsCount > 0)
            {
                msg += "\r\n" + Lan.g(this, "Number of patients updated:") + " " + updatedPatsCount;
            }
            if (skippedPatsCount > 0)
            {
                msg += "\r\n" + Lan.g(this, "Number of patients skipped:") + " " + skippedPatsCount;
                msg += sbErrorMessages.ToString();
            }
            if (createdCarrierCount > 0)
            {
                msg += "\r\n" + Lan.g(this, "Number of carriers created:") + " " + createdCarrierCount;
                msg += sbErrorMessages.ToString();
            }
            if (createdPlanCount > 0)
            {
                msg += "\r\n" + Lan.g(this, "Number of plans created:") + " " + createdPlanCount;
                msg += sbErrorMessages.ToString();
            }
            if (droppedPlanCount > 0)
            {
                msg += "\r\n" + Lan.g(this, "Number of plans dropped:") + " " + droppedPlanCount;
                msg += sbErrorMessages.ToString();
            }
            if (updatedPlanCount > 0)
            {
                msg += "\r\n" + Lan.g(this, "Number of plans updated:") + " " + updatedPlanCount;
                msg += sbErrorMessages.ToString();
            }
            MsgBoxCopyPaste msgBox = new MsgBoxCopyPaste(msg);

            msgBox.ShowDialog();
        }
예제 #25
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();
        }
예제 #26
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);
        }
예제 #27
0
        private void butSend_Click(object sender, EventArgs ea)
        {
            if (gridMain.SelectedIndices.Length != 1)
            {
                MsgBox.Show(this, "Exactly one Rx must be selected.");
                return;
            }
            Pharmacy      pharmacy = Pharmacies.GetOne(listRx[gridMain.SelectedIndices[0]].PharmacyNum);
            StringBuilder strb     = new StringBuilder();
            //These characters will be replaced in a production by unprintable characters, but hardcoded for debugging.
            char   f = ':';        //separates fields within a composite element
            char   e = '+';        //(separates composite elements) SureScripts may require an unprintable character here.
            char   d = '.';        //decimal notation
            char   r = '/';        //release indicator
            char   p = '*';        //repetition separator
            string s = "'\r\n";    //segment separator

                        #if DEBUG
            if (true)
            {
                //Set false if you want to use unprintable characters to simulate running in release mode.
            }
            else
            {
                //f=''; we don't know the values for these characters yet.
                //e='';
                //d='';
                //r='';
                //p='';
                //s='';
            }
                        #else
            //f=''; we don't know the values for these characters yet.
            //e='';
            //d='';
            //r='';
            //p='';
            //s='';
                        #endif
            RxPat          rx          = listRx[gridMain.SelectedIndices[0]];
            Patient        pat         = Patients.GetPat(rx.PatNum);
            Provider       prov        = Providers.GetProv(rx.ProvNum);
            PatPlan        patPlan     = PatPlans.GetPatPlan(pat.PatNum, 1);
            Family         fam         = Patients.GetFamily(pat.PatNum);
            List <InsSub>  subList     = InsSubs.RefreshForFam(fam);
            List <InsPlan> planList    = InsPlans.RefreshForSubList(subList);
            InsSub         sub         = InsSubs.GetOne(patPlan.InsSubNum);
            InsPlan        plan        = InsPlans.GetPlan(sub.PlanNum, planList);
            Carrier        car         = Carriers.GetCarrier(plan.CarrierNum);
            DateTime       msgTimeSent = DateTime.Now;
            //Hardcoded values should never change. Ex:Message type, version, release should always be SCRIPT:010:006
            //Hardcoded values allowed to change until released version.
            //UNA:+./*'------------------------------------------------------------------------------------------------
            strb.Append("UNA" + f + e + d + r + p + s);
            //UIB+UNOA:0++1234567+++77777777:C:PASSWORDQ+7701630:P+19971001:081522'------------------------------------
            strb.Append("UIB" + e);                                                                                                //000
            strb.Append("UNOA" + f + "0" + e);                                                                                     //010 Syntax identifier and version
            strb.Append(e);                                                                                                        //020 not used
            strb.Append(Sout(POut.Long(rx.RxNum)) + e);                                                                            //030 Transaction reference (Clinic system trace number.) Sender creates a Unique Trace number for each message sent.
            strb.Append(e);                                                                                                        //040 not used
            strb.Append(e);                                                                                                        //050 not used
            strb.Append("56873771" + f + "C" + f + "PASSWORDQ" + e);                                                               //060 Sender identification (This is the Clinic ID of the sender; C means it is a Clinic.)
            strb.Append(Sout(pharmacy.PharmID) + f + "P" + e);                                                                     //070 Recipient ID (NCPDP Provider ID Number of pharmacy; P means it is a pharmacy.)
            strb.Append(Sout(msgTimeSent.ToString("yyyyMMdd")) + f + Sout(msgTimeSent.ToString("HHmmss")) + s);                    //080 Date of initiation CCYYMMDD:HHMMSS,S
            //UIH+SCRIPT:010:006:NEWRX+110072+++19971001:081522'-------------------------------------------------------
            strb.Append("UIH" + e);                                                                                                //000
            strb.Append("SCRIPT" + f + "010" + f + "006" + f + "NEWRX" + e);                                                       //010 Message type:version:release:function.
            //Clinic's reference number for message. Usually this is the folio number for the patient. However, this is the ID by which the clinic will be able to refer to this prescription.
            strb.Append(Sout(rx.RxNum.ToString()) + e);                                                                            //020 Message reference number (Must match number in UIT segment below, must be unique. Recommend using rx num)
            strb.Append(e);                                                                                                        //030 conditional Dialogue Reference
            strb.Append(e);                                                                                                        //040 not used
            strb.Append(Sout(msgTimeSent.ToString("yyyyMMdd")) + f + Sout(msgTimeSent.ToString("HHmmss")) + s);                    //050 Date of initiation
            //PVD+P1+7701630:D3+++++MAIN STREET PHARMACY++6152205656:TE'-----------------------------------------------
            strb.Append("PVD" + e);                                                                                                //000
            strb.Append("P1" + e);                                                                                                 //010 Provider coded (see external code list pg.109)
            strb.Append(Sout(pharmacy.PharmID) + f + "D3" + e);                                                                    //020 Reference number and qualifier (Pharmacy ID)
            strb.Append(e);                                                                                                        //030 not used
            strb.Append(e);                                                                                                        //040 conditional Provider specialty
            strb.Append(e);                                                                                                        //050 conditional The name of the prescriber or pharmacist or supervisor
            strb.Append(e);                                                                                                        //060 not used
            strb.Append(e);                                                                                                        //070 conditional The clinic or pharmacy name
            strb.Append(Sout(pharmacy.Address) + f + Sout(pharmacy.City) + f + Sout(pharmacy.State) + f + Sout(pharmacy.Zip) + e); //080 Address
            strb.Append(Regex.Replace(Sout(pharmacy.Phone), @"[-()]", string.Empty) + f + "TE" + s);                               //090 Communication number and qualifier
            //PVD+PC+6666666:0B+++JONES:MARK++++6152219800:TE'---------------------------------------------------------
            strb.Append("PVD" + e);                                                                                                //000
            strb.Append("PC" + e);                                                                                                 //010 Provider coded
            strb.Append(Sout(prov.StateRxID) + f + "0B" + e);                                                                      //020 Reference number and qualifier (0B: Provider State License Number)
            strb.Append(e);                                                                                                        //030 not used
            strb.Append(e);                                                                                                        //040 conditional Provider specialty
            strb.Append(Sout(prov.LName) + f + Sout(prov.FName) + e);                                                              //050 The name of the prescriber or pharmacist or supervisor
            strb.Append(e);                                                                                                        //060 not used
            strb.Append(e);                                                                                                        //070 conditional The clinic or pharmacy name
            strb.Append(e);                                                                                                        //080 conditional Address
            strb.Append(Regex.Replace(Sout(PrefC.GetString(PrefName.PracticePhone)), @"[-()]", string.Empty) + f + "TE" + s);      //090 Communication number and qualifier
            //PTT++19541225+SMITH:MARY+F+333445555:SY'-----------------------------------------------------------------
            strb.Append("PTT" + e);                                                                                                //000
            strb.Append(e);                                                                                                        //010 conditional Individual relationship
            strb.Append(Sout(pat.Birthdate.ToString("yyyyMMdd")) + e);                                                             //020 Birth date of patient YYYYMMDD
            strb.Append(Sout(pat.LName) + f + Sout(pat.FName) + e);                                                                //030 Name
            strb.Append(Sout(pat.Gender.ToString().Substring(0, 1)) + e);                                                          //040 Gender (M,F,U)
            strb.Append(Sout(pat.SSN.Replace("-", "")) + f + "SY" + s);                                                            //050 Patient ID and/or SSN and qualifier
            //COO+123456:BO+INSURANCE COMPANY NAME++123456789++AA112'--------------------------------------------------
            strb.Append("COO" + e);                                                                                                //000
            strb.Append(Sout(plan.RxBIN) + f + "BO" + e);                                                                          //010 Payer ID Information and qualifier (Primary Payer's identification number? BO is for BIN Location Number.)
            strb.Append(Sout(car.CarrierName) + e);                                                                                //020 Payer name
            strb.Append(e);                                                                                                        //030 conditional Service type, coded
            strb.Append(Sout(sub.SubscriberID) + e);                                                                               //040 Cardholder ID
            strb.Append(e);                                                                                                        //050 conditional Cardholder name
            strb.Append(Sout(plan.GroupNum) + s);                                                                                  //060 Group ID
            //DRU------------------------------------------------------------------------------------------------------
            //DRU+P:CALAN SR 240MG::::240:::::::AA:C42998:AB:C28253+::60:38:AC:C48542+:1 TID -TAKE ONE TABLET TWO TIMES A DAY UNTIL GONE+85:19971001:102*ZDS:30:804+0+R:1'
            strb.Append("DRU" + e);          //000
            //P means prescribed. Drug prescribed is Calan Sr 240mg.
            //240 is the strength (free text); AA is the Source for NCI Pharmaceutical Dosage Form. C42998 is the code for “Tablet dosing form”.
            //AB is the Source for NCI Units of Presentation. C28253 is the code for “Milligram”. So this means the prescription is for 240mg tablets.
            //There's AA, AB and AC - AC is Potency Unit
            //The definitions for C42998 and C28253 and be found @ http://nciterms.nci.nih.gov/ncitbrowser/pages/vocabulary.jsf?dictionary=NCI_Thesaurus
            strb.Append("P" + f + Sout(rx.Drug) + f + f + f + f + f + f + Sout(rx.RxCui.ToString()) + f + "SBD" + e); //f+f+f+f+"AA"+f+"C42998"+f+"AB"+f+"C28253"+e);//010 Item Description Identification
            //This means dispense 60 tablets. 38 is the code value for Original Qty. AC is the Source for NCI Potency Units. C48542 is the code for “Tablet dosing unit”.
            strb.Append("" + f + f + Sout(rx.Disp) + f + f + "AA" + f + Sout(rx.DosageCode) + e);                     //020 Quantity
            strb.Append(f + Sout(rx.Sig) + e);                                                                        //030 Directions
            //85 qualifier for Date Issued (Written date) 102 is qualifier for CCYYMMDD format.
            //ZDS is the qualifier for Days Supply. 30 is the number of days supply. 804 is the qualifier for Quantity of Days.
            strb.Append("85" + f + Sout(rx.RxDate.ToString("yyyyMMdd")) + f + "102" + e); //+p+"ZDS"+f+"30"+f+"804"+e);//040 Date Note: It is strongly recommended that Days Supply (value “ZDS”) be supported.
            strb.Append("0" + e);                                                         //050 Product/Service substitution, coded
            strb.Append("R" + f + Sout(rx.Refills) + s);                                  //060 Refill and quantity
            //UIT+110072+6'---------------------------------------------------------------------------------------------
            strb.Append("UIT" + e);                                                       //000
            strb.Append(Sout(rx.RxNum.ToString()) + e);                                   //010 Message reference number
            strb.Append("5" + s);                                                         //020 Mandatory field. This is the count of the number of segments in the message including the UIH and UIT
            //UIZ++1'---------------------------------------------------------------------------------------------------
            strb.Append("UIZ" + e);                                                       //000
            strb.Append(e);                                                               //010 not used
            strb.Append("1" + s);                                                         //020 Number of messages per interchange. The count of UIH-UIT occurrences
            //Uncomment if you want to see the message text:
            //MsgBoxCopyPaste msgbox=new MsgBoxCopyPaste(strb.ToString());
            //msgbox.ShowDialog();
            Cursor = Cursors.WaitCursor;
            try {
                                #if EHRTEST
                EHR.EhrEmail.Send("10.6 SCRIPT for NEWRX", "SCRIPT.txt", strb.ToString());
                                #else
                //can't send email unless in debug/ehrtest mode.
                                #endif
            }
            catch (Exception ex) {
                Cursor = Cursors.Default;
                MessageBox.Show(ex.Message);
                return;
            }
            Cursor = Cursors.Default;
            MessageBox.Show("Sent");
            rx.SendStatus = RxSendStatus.SentElect;          //Removes the Rx from the grid.
            RxPats.Update(rx);
            FillGrid();
        }
예제 #28
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);
        }
예제 #29
0
        ///<summary>raised for each page to be printed.  One page per appointment.</summary>
        private void pd_PrintPage(object sender, PrintPageEventArgs ev)
        {
            if (ApptNum != 0)           //just for one appointment
            {
                date = Appointments.DateSelected;
            }
            Graphics   g = ev.Graphics;
            float      y = 50;
            float      x = 0;
            string     str;
            float      sizeW;       //used when measuring text for placement
            Font       fontTitle   = new Font(FontFamily.GenericSansSerif, 11, FontStyle.Bold);
            Font       fontHeading = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold);
            Font       font        = new Font(FontFamily.GenericSansSerif, 8);
            SolidBrush brush       = new SolidBrush(Color.Black);

            //Title----------------------------------------------------------------------------------------------------------
            str   = Lan.g(this, "Routing Slip");
            sizeW = g.MeasureString(str, fontTitle).Width;
            x     = 425 - sizeW / 2;
            g.DrawString(str, fontTitle, brush, x, y);
            y += 35;
            x  = 75;
            //Today's appointment, including procedures-----------------------------------------------------------------------
            Family  fam = Patients.GetFamily(Appts[pagesPrinted].PatNum);
            Patient pat = fam.GetPatient(Appts[pagesPrinted].PatNum);

            str = pat.GetNameFL();
            g.DrawString(str, fontHeading, brush, x, y);
            y  += 18;
            str = Appts[pagesPrinted].AptDateTime.ToShortTimeString() + "  " + Appts[pagesPrinted].AptDateTime.ToShortDateString();
            g.DrawString(str, fontHeading, brush, x, y);
            y  += 18;
            str = (Appts[pagesPrinted].Pattern.Length * 5).ToString() + " " + Lan.g(this, "minutes");
            g.DrawString(str, font, brush, x, y);
            y  += 15;
            str = Providers.GetAbbr(Appts[pagesPrinted].ProvNum);
            g.DrawString(str, font, brush, x, y);
            y += 15;
            if (Appts[pagesPrinted].ProvHyg != 0)
            {
                str = Providers.GetAbbr(Appts[pagesPrinted].ProvHyg);
                g.DrawString(str, font, brush, x, y);
                y += 15;
            }
            str = Lan.g(this, "Procedures:");
            g.DrawString(str, font, brush, x, y);
            y += 15;
            Procedure[] procsAll = Procedures.Refresh(pat.PatNum);
            Procedure[] procsApt = Procedures.GetProcsOneApt(Appts[pagesPrinted].AptNum, procsAll);
            for (int i = 0; i < procsApt.Length; i++)
            {
                str = "   " + Procedures.GetDescription(procsApt[i]);
                g.DrawString(str, font, brush, x, y);
                y += 15;
            }
            str = Lan.g(this, "Note:") + " " + Appts[pagesPrinted].Note;
            g.DrawString(str, font, brush, x, y);
            y += 25;
            //Patient/Family Info---------------------------------------------------------------------------------------------
            g.DrawLine(Pens.Black, 75, y, 775, y);
            str = Lan.g(this, "Patient Info");
            g.DrawString(str, fontHeading, brush, x, y);
            y  += 18;
            str = Lan.g(this, "PatNum:") + " " + pat.PatNum.ToString();
            g.DrawString(str, font, brush, x, y);
            y  += 15;
            str = Lan.g(this, "Age:") + " ";
            if (pat.Age > 0)
            {
                str += pat.Age.ToString();
            }
            g.DrawString(str, font, brush, x, y);
            y  += 15;
            str = Lan.g(this, "Date of First Visit:") + " ";
            if (pat.DateFirstVisit.Year < 1880)
            {
                str += "?";
            }
            else if (pat.DateFirstVisit == Appts[pagesPrinted].AptDateTime.Date)
            {
                str += Lan.g(this, "New Patient");
            }
            else
            {
                str += pat.DateFirstVisit.ToShortDateString();
            }
            g.DrawString(str, font, brush, x, y);
            y  += 15;
            str = Lan.g(this, "Billing Type:") + " " + DefB.GetName(DefCat.BillingTypes, pat.BillingType);
            g.DrawString(str, font, brush, x, y);
            y += 15;
            Recall[] recallList = Recalls.GetList(new int[] { pat.PatNum });
            str = Lan.g(this, "Recall Due Date:") + " ";
            if (recallList.Length > 0)
            {
                str += recallList[0].DateDue.ToShortDateString();
            }
            g.DrawString(str, font, brush, x, y);
            y  += 15;
            str = Lan.g(this, "Medical notes:") + " " + pat.MedUrgNote;
            g.DrawString(str, font, brush, x, y);
            y += 25;
            //Other Family Members
            str = Lan.g(this, "Other Family Members");
            g.DrawString(str, fontHeading, brush, x, y);
            y += 18;
            for (int i = 0; i < fam.List.Length; i++)
            {
                if (fam.List[i].PatNum == pat.PatNum)
                {
                    continue;
                }
                str = fam.List[i].GetNameFL();
                if (fam.List[i].Age > 0)
                {
                    str += ",   " + fam.List[i].Age.ToString();
                }
                g.DrawString(str, font, brush, x, y);
                y += 15;
            }
            y += 10;
            //Insurance Info--------------------------------------------------------------------------------------------------
            g.DrawLine(Pens.Black, 75, y, 775, y);
            str = Lan.g(this, "Insurance");
            g.DrawString(str, fontHeading, brush, x, y);
            y += 18;
            PatPlan[]   patPlanList   = PatPlans.Refresh(pat.PatNum);
            InsPlan[]   plans         = InsPlans.Refresh(fam);
            ClaimProc[] claimProcList = ClaimProcs.Refresh(pat.PatNum);
            Benefit[]   benefits      = Benefits.Refresh(patPlanList);
            InsPlan     plan;
            Carrier     carrier;
            string      subscriber;
            double      max;
            double      deduct;

            if (patPlanList.Length == 0)
            {
                str = Lan.g(this, "none");
                g.DrawString(str, font, brush, x, y);
                y += 15;
            }
            for (int i = 0; i < patPlanList.Length; i++)
            {
                plan    = InsPlans.GetPlan(patPlanList[i].PlanNum, plans);
                carrier = Carriers.GetCarrier(plan.CarrierNum);
                str     = carrier.CarrierName;
                g.DrawString(str, fontHeading, brush, x, y);
                y         += 18;
                subscriber = fam.GetNameInFamFL(plan.Subscriber);
                if (subscriber == "")               //subscriber from another family
                {
                    subscriber = Patients.GetLim(plan.Subscriber).GetNameLF();
                }
                str = Lan.g(this, "Subscriber:") + " " + subscriber;
                g.DrawString(str, font, brush, x, y);
                y += 15;
                bool isFamMax = Benefits.GetIsFamMax(benefits, plan.PlanNum);
                str = "";
                if (isFamMax)
                {
                    str += Lan.g(this, "Family ");
                }
                str += Lan.g(this, "Annual Max:") + " ";
                max  = Benefits.GetAnnualMax(benefits, plan.PlanNum, patPlanList[i].PatPlanNum);
                if (max != -1)
                {
                    str += max.ToString("n0") + " ";
                }
                str += "   ";
                bool isFamDed = Benefits.GetIsFamDed(benefits, plan.PlanNum);
                if (isFamDed)
                {
                    str += Lan.g(this, "Family ");
                }
                str   += Lan.g(this, "Deductible:") + " ";
                deduct = Benefits.GetDeductible(benefits, plan.PlanNum, patPlanList[i].PatPlanNum);
                if (deduct != -1)
                {
                    str += deduct.ToString("n0");
                }
                g.DrawString(str, font, brush, x, y);
                y  += 15;
                str = "";
                for (int j = 0; j < benefits.Length; j++)
                {
                    if (benefits[j].PlanNum != plan.PlanNum)
                    {
                        continue;
                    }
                    if (benefits[j].BenefitType != InsBenefitType.Percentage)
                    {
                        continue;
                    }
                    if (str != "")
                    {
                        str += ",  ";
                    }
                    str += CovCats.GetDesc(benefits[j].CovCatNum) + " " + benefits[j].Percent.ToString() + "%";
                }
                if (str != "")
                {
                    g.DrawString(str, font, brush, x, y);
                    y += 15;
                }
                double pend = 0;
                double used = 0;
                if (isFamMax || isFamDed)
                {
                    ClaimProc[] claimProcsFam = ClaimProcs.RefreshFam(plan.PlanNum);
                    used = InsPlans.GetInsUsed(claimProcsFam, date, plan.PlanNum, patPlanList[i].PatPlanNum, -1, plans, benefits);
                    pend = InsPlans.GetPending(claimProcsFam, date, plan, patPlanList[i].PatPlanNum, -1, benefits);
                }
                else
                {
                    used = InsPlans.GetInsUsed(claimProcList, date, plan.PlanNum, patPlanList[i].PatPlanNum, -1, plans, benefits);
                    pend = InsPlans.GetPending(claimProcList, date, plan, patPlanList[i].PatPlanNum, -1, benefits);
                }
                str = Lan.g(this, "Ins Used:") + " " + used.ToString("n");
                g.DrawString(str, font, brush, x, y);
                y  += 15;
                str = Lan.g(this, "Ins Pending:") + " " + pend.ToString("n");
                g.DrawString(str, font, brush, x, y);
                y += 15;
            }
            y += 10;
            //Account Info---------------------------------------------------------------------------------------------------
            g.DrawLine(Pens.Black, 75, y, 775, y);
            str = Lan.g(this, "Account Info");
            g.DrawString(str, fontHeading, brush, x, y);
            y  += 18;
            str = Lan.g(this, "Guarantor:") + " " + fam.List[0].GetNameFL();
            g.DrawString(str, font, brush, x, y);
            y  += 15;
            str = Lan.g(this, "Balance:") + (fam.List[0].BalTotal - fam.List[0].InsEst).ToString("c");
            if (fam.List[0].InsEst > .01)
            {
                str += "  (" + fam.List[0].BalTotal.ToString("c") + " - "
                       + fam.List[0].InsEst.ToString("c") + " " + Lan.g(this, "InsEst") + ")";
            }
            g.DrawString(str, font, brush, x, y);
            y  += 15;
            str = Lan.g(this, "Aging:")
                  + "  0-30:" + fam.List[0].Bal_0_30.ToString("c")
                  + "  31-60:" + fam.List[0].Bal_31_60.ToString("c")
                  + "  61-90:" + fam.List[0].Bal_61_90.ToString("c")
                  + "  90+:" + fam.List[0].BalOver90.ToString("c");
            g.DrawString(str, font, brush, x, y);
            y  += 15;
            str = Lan.g(this, "Fam Urgent Fin Note:")
                  + fam.List[0].FamFinUrgNote;
            g.DrawString(str, font, brush, x, y);
            y += 15;
            y += 10;
            //Treatment Plan--------------------------------------------------------------------------------------------------
            g.DrawLine(Pens.Black, 75, y, 775, y);
            str = Lan.g(this, "Treatment Plan");
            g.DrawString(str, fontHeading, brush, x, y);
            y += 18;
            for (int i = 0; i < procsAll.Length; i++)
            {
                if (procsAll[i].ProcStatus != ProcStat.TP)
                {
                    continue;
                }
                str = Procedures.GetDescription(procsAll[i]);
                g.DrawString(str, font, brush, x, y);
                y += 15;
            }
            pagesPrinted++;
            if (pagesPrinted == Appts.Length)
            {
                ev.HasMorePages = false;
                pagesPrinted    = 0;
            }
            else
            {
                ev.HasMorePages = true;
            }
        }
예제 #30
0
        ///<summary></summary>
        private void butOK_Click(object sender, System.EventArgs e)
        {
            if (textMain.Text == "")
            {
                MsgBox.Show(this, "Please paste the text generated by the other program into the large box first.");
                return;
            }
            pat               = new Patient();
            pat.PriProv       = PrefC.GetLong(PrefName.PracticeDefaultProv);
            pat.BillingType   = PrefC.GetLong(PrefName.PracticeDefaultBillType);
            guar              = new Patient();
            guar.PriProv      = PrefC.GetLong(PrefName.PracticeDefaultProv);
            guar.BillingType  = PrefC.GetLong(PrefName.PracticeDefaultBillType);
            subsc             = new Patient();
            subsc.PriProv     = PrefC.GetLong(PrefName.PracticeDefaultProv);
            subsc.BillingType = PrefC.GetLong(PrefName.PracticeDefaultBillType);
            sub               = new InsSub();
            sub.ReleaseInfo   = true;
            sub.AssignBen     = true;
            plan              = new InsPlan();
            carrier           = new Carrier();
            insRelat          = "self"; //this is the default if not included
            guarRelat         = "self";
            InsEmp            = "";
            GuarEmp           = "";
            NoteMedicalComp   = "";
            insPresent        = false;
            annualMax         = -1;
            deductible        = -1;
            XmlTextReader reader = new XmlTextReader(new StringReader(textMain.Text));

            reader.WhitespaceHandling = WhitespaceHandling.None;
            string element     = "";
            string textValue   = "";
            string rootElement = "";
            string segment     = "";    //eg PatientIdentification
            string field       = "";    //eg NameLast
            string endelement  = "";

            warnings = "";
            try{
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        element = reader.Name;
                        if (rootElement == "")                              //should be the first node
                        {
                            if (element == "Message")
                            {
                                rootElement = "Message";
                            }
                            else
                            {
                                throw new Exception(element + " should not be the first element.");
                            }
                        }
                        else if (segment == "")                              //expecting a new segment
                        {
                            segment = element;
                            if (segment != "MessageHeader" &&
                                segment != "PatientIdentification" &&
                                segment != "Guarantor" &&
                                segment != "Insurance")
                            {
                                throw new Exception(segment + " is not a recognized segment.");
                            }
                        }
                        else                                 //expecting a new field
                        {
                            field = element;
                        }
                        if (segment == "Insurance")
                        {
                            insPresent = true;
                        }
                        break;

                    case XmlNodeType.Text:
                        textValue = reader.Value;
                        if (field == "")
                        {
                            throw new Exception("Unexpected text: " + textValue);
                        }
                        break;

                    case XmlNodeType.EndElement:
                        endelement = reader.Name;
                        if (field == "")                              //we're not in a field, so we must be closing a segment or rootelement
                        {
                            if (segment == "")                        //we're not in a segment, so we must be closing the rootelement
                            {
                                if (rootElement == "Message")
                                {
                                    rootElement = "";
                                }
                                else
                                {
                                    throw new Exception("Message closing element expected.");
                                }
                            }
                            else                                     //must be closing a segment
                            {
                                segment = "";
                            }
                        }
                        else                                 //closing a field
                        {
                            field     = "";
                            textValue = "";
                        }
                        break;
                    }                    //switch
                    if (rootElement == "")
                    {
                        break;                        //this will ignore anything after the message endelement
                    }
                    if (field != "" && textValue != "")
                    {
                        if (segment == "MessageHeader")
                        {
                            ProcessMSH(field, textValue);
                        }
                        else if (segment == "PatientIdentification")
                        {
                            ProcessPID(field, textValue);
                        }
                        else if (segment == "Guarantor")
                        {
                            ProcessGT(field, textValue);
                        }
                        else if (segment == "Insurance")
                        {
                            ProcessINS(field, textValue);
                        }
                    }
                }                //while
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
                //MsgBox.Show(this,"Error in the XML format.");
                reader.Close();
                return;
            }
            finally{
                reader.Close();
            }
            //Warnings and errors-----------------------------------------------------------------------------
            if (pat.LName == "" || pat.FName == "" || pat.Birthdate.Year < 1880)
            {
                MsgBox.Show(this, "Patient first and last name and birthdate are required.  Could not import.");
                return;
            }
            //if guarRelat is not self, and name and birthdate not supplied, no error.  Just make guar self.
            if (guarRelat != "self")
            {
                if (guar.LName == "" || guar.FName == "" || guar.Birthdate.Year < 1880)
                {
                    warnings += "Guarantor information incomplete.  Guarantor will be self.\r\n";
                    guarRelat = "self";
                }
            }
            if (insPresent)
            {
                if (carrier.CarrierName == "")
                {
                    warnings  += "Insurance CompanyName is missing. No insurance info will be imported.\r\n";
                    insPresent = false;
                }
                else if (insRelat != "self")
                {
                    if (subsc.LName == "" || subsc.FName == "" || subsc.Birthdate.Year < 1880)
                    {
                        warnings  += "Subscriber name or birthdate is missing. No insurance info will be imported.\r\n";
                        insPresent = false;
                    }
                }
                else if (sub.SubscriberID == "")
                {
                    warnings        += "PolicyNumber/SubscriberID missing.\r\n";
                    sub.SubscriberID = " ";
                }
            }
            if (warnings != "")
            {
                if (MessageBox.Show("It's safe to import, but you should be aware of the following issues:\r\n" + warnings + "\r\nContinue with Import?", "Warnings", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }
            }

            //Patient-------------------------------------------------------------------------------------
            //DataTable table;
            long    patNum      = Patients.GetPatNumByNameAndBirthday(pat.LName, pat.FName, pat.Birthdate);
            Patient existingPat = null;

            existingPatOld = null;      //we will need this to do an update.
            if (patNum != 0)            //a patient already exists, so only add missing fields
            {
                existingPat    = Patients.GetPat(patNum);
                existingPatOld = existingPat.Copy();
                if (existingPat.MiddleI == "")              //only alter existing if blank
                {
                    existingPat.MiddleI = pat.MiddleI;
                }
                if (pat.Gender != PatientGender.Unknown)
                {
                    existingPat.Gender = pat.Gender;
                }
                if (existingPat.Preferred == "")
                {
                    existingPat.Preferred = pat.Preferred;
                }
                if (existingPat.Address == "")
                {
                    existingPat.Address = pat.Address;
                }
                if (existingPat.Address2 == "")
                {
                    existingPat.Address2 = pat.Address2;
                }
                if (existingPat.City == "")
                {
                    existingPat.City = pat.City;
                }
                if (existingPat.State == "")
                {
                    existingPat.State = pat.State;
                }
                if (existingPat.Zip == "")
                {
                    existingPat.Zip = pat.Zip;
                }
                if (existingPat.HmPhone == "")
                {
                    existingPat.HmPhone = pat.HmPhone;
                }
                if (existingPat.Email == "")
                {
                    existingPat.Email = pat.Email;
                }
                if (existingPat.WkPhone == "")
                {
                    existingPat.WkPhone = pat.WkPhone;
                }
                if (existingPat.Position == PatientPosition.Single)
                {
                    existingPat.Position = pat.Position;
                }
                if (existingPat.SSN == "")
                {
                    existingPat.SSN = pat.SSN;
                }
                existingPat.AddrNote += pat.AddrNote;              //concat
                Patients.Update(existingPat, existingPatOld);
                PatientNote PatientNoteCur = PatientNotes.Refresh(existingPat.PatNum, existingPat.Guarantor);
                PatientNoteCur.MedicalComp += NoteMedicalComp;
                PatientNotes.Update(PatientNoteCur, existingPat.Guarantor);
                //guarantor will not be altered in any way
            }            //if patient already exists
            else         //patient is new, so insert
            {
                Patients.Insert(pat, false);
                SecurityLogs.MakeLogEntry(Permissions.PatientCreate, pat.PatNum, "Created from Import Patient XML tool.");
                existingPatOld = pat.Copy();
                pat.Guarantor  = pat.PatNum;             //this can be changed later.
                Patients.Update(pat, existingPatOld);
                PatientNote PatientNoteCur = PatientNotes.Refresh(pat.PatNum, pat.Guarantor);
                PatientNoteCur.MedicalComp += NoteMedicalComp;
                PatientNotes.Update(PatientNoteCur, pat.Guarantor);
            }
            //guar-----------------------------------------------------------------------------------------------------
            if (existingPat == null)          //only add or alter guarantor for new patients
            {
                if (guarRelat == "self")
                {
                    //pat is already set with guar as self
                    //ignore all guar fields except EmployerName
                    existingPatOld  = pat.Copy();
                    pat.EmployerNum = Employers.GetEmployerNum(GuarEmp);
                    Patients.Update(pat, existingPatOld);
                }
                else
                {
                    //if guarRelat is not self, and name and birthdate not supplied, a warning was issued, and relat was changed to self.
                    //add guarantor or attach to an existing guarantor
                    long guarNum = Patients.GetPatNumByNameAndBirthday(guar.LName, guar.FName, guar.Birthdate);
                    if (guarNum != 0)                    //a guar already exists, so simply attach. Make no other changes
                    {
                        existingPatOld = pat.Copy();
                        pat.Guarantor  = guarNum;
                        if (guarRelat == "parent")
                        {
                            pat.Position = PatientPosition.Child;
                        }
                        Patients.Update(pat, existingPatOld);
                    }
                    else                     //we need to completely create guar, then attach
                    {
                        Patients.Insert(guar, false);
                        SecurityLogs.MakeLogEntry(Permissions.PatientCreate, guar.PatNum, "Created from Import Patient XML tool.");
                        //set guar for guar
                        existingPatOld   = guar.Copy();
                        guar.Guarantor   = guar.PatNum;
                        guar.EmployerNum = Employers.GetEmployerNum(GuarEmp);
                        Patients.Update(guar, existingPatOld);
                        //set guar for pat
                        existingPatOld = pat.Copy();
                        pat.Guarantor  = guar.PatNum;
                        if (guarRelat == "parent")
                        {
                            pat.Position = PatientPosition.Child;
                        }
                        Patients.Update(pat, existingPatOld);
                    }
                }
            }
            //subsc--------------------------------------------------------------------------------------------------
            if (!insPresent)
            {
                //this takes care of missing carrier name or subscriber info.
                MsgBox.Show(this, "Done");
                DialogResult = DialogResult.OK;
            }
            if (insRelat == "self")
            {
                sub.Subscriber = pat.PatNum;
            }
            else             //we need to find or add the subscriber
            {
                patNum = Patients.GetPatNumByNameAndBirthday(subsc.LName, subsc.FName, subsc.Birthdate);
                if (patNum != 0)                //a subsc already exists, so simply attach. Make no other changes
                {
                    sub.Subscriber = patNum;
                }
                else                 //need to create and attach a subscriber
                {
                    Patients.Insert(subsc, false);
                    SecurityLogs.MakeLogEntry(Permissions.PatientCreate, subsc.PatNum, "Created from Import Patient XML tool.");
                    //set guar to same guar as patient
                    existingPatOld  = subsc.Copy();
                    subsc.Guarantor = pat.Guarantor;
                    Patients.Update(subsc, existingPatOld);
                    sub.Subscriber = subsc.PatNum;
                }
            }
            //carrier-------------------------------------------------------------------------------------------------
            //Carriers.Cur=carrier;
            carrier = Carriers.GetIdentical(carrier);          //this automatically finds or creates a carrier
            //plan------------------------------------------------------------------------------------------------------
            plan.EmployerNum = Employers.GetEmployerNum(InsEmp);
            plan.CarrierNum  = carrier.CarrierNum;
            InsPlans.Insert(plan);
            //Attach plan to subscriber
            sub.PlanNum = plan.PlanNum;
            InsSubs.Insert(sub);
            //Then attach plan
            List <PatPlan> PatPlanList = PatPlans.Refresh(pat.PatNum);
            PatPlan        patplan     = new PatPlan();

            patplan.Ordinal   = (byte)(PatPlanList.Count + 1);      //so the ordinal of the first entry will be 1, NOT 0.
            patplan.PatNum    = pat.PatNum;
            patplan.InsSubNum = sub.InsSubNum;
            switch (insRelat)
            {
            case "self":
                patplan.Relationship = Relat.Self;
                break;

            case "parent":
                patplan.Relationship = Relat.Child;
                break;

            case "spouse":
                patplan.Relationship = Relat.Spouse;
                break;

            case "guardian":
                patplan.Relationship = Relat.Dependent;
                break;
            }
            PatPlans.Insert(patplan);
            //benefits
            if (annualMax != -1 && CovCats.GetCount(true) > 0)
            {
                Benefit ben = new Benefit();
                ben.BenefitType = InsBenefitType.Limitations;
                ben.CovCatNum   = CovCats.GetFirst(true).CovCatNum;
                ben.MonetaryAmt = annualMax;
                ben.PlanNum     = plan.PlanNum;
                ben.TimePeriod  = BenefitTimePeriod.CalendarYear;
                Benefits.Insert(ben);
            }
            if (deductible != -1 && CovCats.GetCount(true) > 0)
            {
                Benefit ben = new Benefit();
                ben.BenefitType = InsBenefitType.Deductible;
                ben.CovCatNum   = CovCats.GetFirst(true).CovCatNum;
                ben.MonetaryAmt = deductible;
                ben.PlanNum     = plan.PlanNum;
                ben.TimePeriod  = BenefitTimePeriod.CalendarYear;
                Benefits.Insert(ben);
            }
            MsgBox.Show(this, "Done");
            DialogResult = DialogResult.OK;
        }