private void FillGrid()
 {
     Employers.Refresh();
     listEmp.Items.Clear();
     for (int i = 0; i < Employers.List.Length; i++)
     {
         listEmp.Items.Add(Employers.List[i].EmpName);
         //if(IsSelectMode && Employers.List[i].EmployerNum==Employers.Cur.EmployerNum){
         //	listEmp.SetSelected(i,true);
         //}
     }
 }
Beispiel #2
0
        ///<summary>Makes the "Before" and "After" columns human-readable for certain logs.</summary>
        private void TranslateBeforeAndAfter()
        {
            foreach (InsEditLog logCur in _listLogs)
            {
                long beforeKey = PIn.Long(logCur.OldValue, false);
                long afterKey  = PIn.Long(logCur.NewValue, false);
                switch (logCur.FieldName)
                {
                case "CarrierNum":
                    if (logCur.LogType == InsEditLogType.Carrier)
                    {
                        break;
                    }
                    logCur.OldValue = beforeKey == 0 ? logCur.OldValue : Carriers.GetCarrier(beforeKey).CarrierName;
                    logCur.NewValue = afterKey == 0 ? logCur.NewValue : Carriers.GetCarrier(afterKey).CarrierName;
                    break;

                case "EmployerNum":
                    if (logCur.LogType == InsEditLogType.Employer)
                    {
                        break;
                    }
                    logCur.OldValue = beforeKey == 0 ? logCur.OldValue : Employers.GetName(beforeKey);
                    logCur.NewValue = afterKey == 0 ? logCur.NewValue : Employers.GetName(afterKey);
                    break;

                case "FeeSched":
                case "CopayFeeSched":
                case "AllowedFeeSched":
                    logCur.OldValue = beforeKey == 0 ? logCur.OldValue : FeeScheds.GetDescription(beforeKey);
                    logCur.NewValue = afterKey == 0 ? logCur.NewValue : FeeScheds.GetDescription(afterKey);
                    break;

                case "BenefitType":
                    logCur.OldValue = beforeKey == 0 ? logCur.OldValue : Enum.GetName(typeof(InsBenefitType), beforeKey);
                    logCur.NewValue = afterKey == 0 ? logCur.NewValue : Enum.GetName(typeof(InsBenefitType), afterKey);
                    break;

                case "CovCatNum":
                    logCur.OldValue = beforeKey == 0 ? logCur.OldValue : CovCats.GetDesc(beforeKey);
                    logCur.NewValue = afterKey == 0 ? logCur.NewValue : CovCats.GetDesc(afterKey);
                    break;

                case "CodeNum":
                    logCur.OldValue = beforeKey == 0 ? logCur.OldValue : ProcedureCodes.GetStringProcCode(beforeKey);
                    logCur.NewValue = afterKey == 0 ? logCur.NewValue : ProcedureCodes.GetStringProcCode(afterKey);
                    break;

                default:
                    break;
                }
            }
        }
 private void butOK_Click(object sender, System.EventArgs e)
 {
     EmployerCur.EmpName = textEmp.Text;
     if (IsNew)
     {
         Employers.Insert(EmployerCur);
     }
     else
     {
         Employers.Update(EmployerCur);
     }
     DialogResult = DialogResult.OK;
 }
Beispiel #4
0
 private void FillGrid()
 {
     Employers.RefreshCache();
     ListEmployers.Clear();
     foreach (Employer employer in Employers.GetListDeep())
     {
         ListEmployers.Add(employer);
     }
     ListEmployers.Sort(CompareEmployers);
     listEmp.Items.Clear();
     for (int i = 0; i < ListEmployers.Count; i++)
     {
         listEmp.Items.Add(ListEmployers[i].EmpName);
         //if(IsSelectMode && ListEmployers[i].EmployerNum==Employers.Cur.EmployerNum){
         //	listEmp.SetSelected(i,true);
         //}
     }
 }
Beispiel #5
0
        private void butOK_Click(object sender, System.EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(textEmp.Text))
            {
                MsgBox.Show(this, "Please enter an employer name.");
                return;
            }
            Employer empOld = EmployerCur.Copy();

            EmployerCur.EmpName = textEmp.Text;
            if (IsNew)
            {
                Employers.Insert(EmployerCur);
            }
            else
            {
                Employers.Update(EmployerCur, empOld);
            }
            DialogResult = DialogResult.OK;
        }
 private void butCombine_Click(object sender, System.EventArgs e)
 {
     if (listEmp.SelectedIndices.Count < 2)
     {
         MessageBox.Show(Lan.g(this, "Please select multiple items first while holding down the control key."));
         return;
     }
     if (MessageBox.Show(Lan.g(this, "Combine all these employers into a single employer? This will affect all patients using these employers."), ""
                         , MessageBoxButtons.OKCancel) != DialogResult.OK)
     {
         return;
     }
     int[] employerNums = new int[listEmp.SelectedIndices.Count];
     for (int i = 0; i < listEmp.SelectedIndices.Count; i++)
     {
         employerNums[i] = Employers.List[listEmp.SelectedIndices[i]].EmployerNum;
     }
     Employers.Combine(employerNums);
     FillGrid();
 }
        private void FormTrojanCollect_Load(object sender, EventArgs e)
        {
            patCur  = Patients.GetPat(PatNum);
            guarCur = Patients.GetPat(patCur.Guarantor);
            if (guarCur.EmployerNum == 0)
            {
                empCur = null;
            }
            else
            {
                empCur = Employers.GetEmployer(guarCur.EmployerNum);
            }
            if (guarCur.LName.Length == 0)
            {
                MessageBox.Show("Missing guarantor last name.");
                DialogResult = DialogResult.Cancel;
                return;
            }
            if (guarCur.FName.Length == 0)
            {
                MessageBox.Show("Missing guarantor first name.");
                DialogResult = DialogResult.Cancel;
                return;
            }
            if (!Regex.IsMatch(guarCur.SSN, @"^\d{9}$"))
            {
                MessageBox.Show("Guarantor SSN must be exactly 9 digits.");
                DialogResult = DialogResult.Cancel;
                return;
            }
            if (guarCur.Address.Length == 0)
            {
                MessageBox.Show("Missing guarantor address.");
                DialogResult = DialogResult.Cancel;
                return;
            }
            if (guarCur.City.Length == 0)
            {
                MessageBox.Show("Missing guarantor city.");
                DialogResult = DialogResult.Cancel;
                return;
            }
            if (guarCur.State.Length != 2)
            {
                MessageBox.Show("Guarantor state must be 2 characters.");
                DialogResult = DialogResult.Cancel;
                return;
            }
            if (guarCur.Zip.Length < 5)
            {
                MessageBox.Show("Invalid guarantor zip.");
                DialogResult = DialogResult.Cancel;
                return;
            }
            labelGuarantor.Text = guarCur.GetNameFL();
            labelAddress.Text   = guarCur.Address;
            if (guarCur.Address2 != "")
            {
                labelAddress.Text += ", " + guarCur.Address2;
            }
            labelCityStZip.Text = guarCur.City + ", " + guarCur.State + " " + guarCur.Zip;
            labelSSN.Text       = guarCur.SSN.Substring(0, 3) + "-" + guarCur.SSN.Substring(3, 2) + "-" + guarCur.SSN.Substring(5, 4);
            if (guarCur.Birthdate.Year < 1880)
            {
                labelDOB.Text = "";
            }
            else
            {
                labelDOB.Text = guarCur.Birthdate.ToString("MM/dd/yyyy");
            }
            labelPhone.Text = Clip(guarCur.HmPhone, 13);
            if (empCur == null)
            {
                labelEmployer.Text = "";
                labelEmpPhone.Text = "";
            }
            else
            {
                labelEmployer.Text = empCur.EmpName;
                labelEmpPhone.Text = empCur.Phone;
            }
            labelPatient.Text = patCur.GetNameFL();
            string    command = @"SELECT MAX(ProcDate) FROM procedurelog,patient
				WHERE patient.PatNum=procedurelog.PatNum
				AND patient.Guarantor="                 + POut.PInt(guarCur.PatNum);
            DataTable table   = General.GetTable(command);
            DateTime  lastProcDate;

            if (table.Rows.Count == 0)
            {
                lastProcDate = DateTime.MinValue;              //this should never happen
            }
            else
            {
                lastProcDate = PIn.PDate(table.Rows[0][0].ToString());
            }
            command = @"SELECT MAX(DatePay) FROM paysplit,patient
				WHERE patient.PatNum=paysplit.PatNum
				AND patient.Guarantor="                 + POut.PInt(guarCur.PatNum);
            table   = General.GetTable(command);
            DateTime lastPayDate;

            if (table.Rows.Count == 0)
            {
                lastPayDate = DateTime.MinValue;
            }
            else
            {
                lastPayDate = PIn.PDate(table.Rows[0][0].ToString());
            }
            if (lastPayDate > lastProcDate)
            {
                textDate.Text = lastPayDate.ToString("MM/dd/yyyy");
            }
            else
            {
                textDate.Text = lastProcDate.ToString("MM/dd/yyyy");
            }
            textAmount.Text   = guarCur.BalTotal.ToString("F2");
            textPassword.Text = PrefB.GetString("TrojanExpressCollectPassword");
        }
Beispiel #8
0
        ///<summary>Only gets run once.</summary>
        private void FillGrid()
        {
            Cursor = Cursors.WaitCursor;
            //ListAll: Set externally before loading.
            gridMain.BeginUpdate();
            gridMain.Columns.Clear();
            ODGridColumn col = new ODGridColumn("Employer", 100);

            gridMain.Columns.Add(col);
            col = new ODGridColumn("Carrier", 100);
            gridMain.Columns.Add(col);
            col = new ODGridColumn("Phone", 82);
            gridMain.Columns.Add(col);
            col = new ODGridColumn("Address", 100);
            gridMain.Columns.Add(col);
            col = new ODGridColumn("City", 80);
            gridMain.Columns.Add(col);
            col = new ODGridColumn("ST", 25);
            gridMain.Columns.Add(col);
            col = new ODGridColumn("Zip", 50);
            gridMain.Columns.Add(col);
            col = new ODGridColumn("Group#", 70);
            gridMain.Columns.Add(col);
            col = new ODGridColumn("Group Name", 90);
            gridMain.Columns.Add(col);
            //col=new ODGridColumn("noE",35);
            //gridMain.Columns.Add(col);
            //col=new ODGridColumn("ElectID",45);
            //gridMain.Columns.Add(col);
            col = new ODGridColumn("Plans", 40);
            gridMain.Columns.Add(col);
            col = new ODGridColumn("Plan Note", 180);
            gridMain.Columns.Add(col);
            //TrojanID and PlanNote not shown
            gridMain.Rows.Clear();
            ODGridRow row;
            Carrier   carrier;

            for (int i = 0; i < ListAll.Length; i++)
            {
                row = new ODGridRow();
                row.Cells.Add(Employers.GetName(ListAll[i].EmployerNum));
                carrier = Carriers.GetCarrier(ListAll[i].CarrierNum);
                row.Cells.Add(carrier.CarrierName);
                row.Cells.Add(carrier.Phone);
                row.Cells.Add(carrier.Address);
                row.Cells.Add(carrier.City);
                row.Cells.Add(carrier.State);
                row.Cells.Add(carrier.Zip);
                row.Cells.Add(ListAll[i].GroupNum);
                row.Cells.Add(ListAll[i].GroupName);
                //if(carrier.NoSendElect)
                //	row.Cells.Add("X");
                //else
                //	row.Cells.Add("");
                //row.Cells.Add(carrier.ElectID);
                row.Cells.Add(ListAll[i].NumberPlans.ToString());
                row.Cells.Add(ListAll[i].PlanNote);
                gridMain.Rows.Add(row);
            }
            gridMain.EndUpdate();
            gridMain.SetSelected(0, true);
            Cursor = Cursors.Default;
        }
Beispiel #9
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;
        }
        private void FormTrojanCollect_Load(object sender, EventArgs e)
        {
            if (_patCur == null)
            {
                MsgBox.Show(this, "Please select a patient first.");
                DialogResult = DialogResult.Cancel;
                return;
            }
            _guarCur = Patients.GetPat(_patCur.Guarantor);
            if (_guarCur.EmployerNum > 0)
            {
                _empCur = Employers.GetEmployer(_guarCur.EmployerNum);
            }
            if (_guarCur.LName.Length == 0)
            {
                MsgBox.Show(this, "Missing guarantor last name.");
                DialogResult = DialogResult.Cancel;
                return;
            }
            if (_guarCur.FName.Length == 0)
            {
                MsgBox.Show(this, "Missing guarantor first name.");
                DialogResult = DialogResult.Cancel;
                return;
            }
            if (!Regex.IsMatch(_guarCur.SSN, @"^\d{9}$"))
            {
                MsgBox.Show(this, "Guarantor SSN must be exactly 9 digits.");
                DialogResult = DialogResult.Cancel;
                return;
            }
            if (_guarCur.Address.Length == 0)
            {
                MsgBox.Show(this, "Missing guarantor address.");
                DialogResult = DialogResult.Cancel;
                return;
            }
            if (_guarCur.City.Length == 0)
            {
                MsgBox.Show(this, "Missing guarantor city.");
                DialogResult = DialogResult.Cancel;
                return;
            }
            if (_guarCur.State.Length != 2)
            {
                MsgBox.Show(this, "Guarantor state must be 2 characters.");
                DialogResult = DialogResult.Cancel;
                return;
            }
            if (_guarCur.Zip.Length < 5)
            {
                MsgBox.Show(this, "Invalid guarantor zip.");
                DialogResult = DialogResult.Cancel;
                return;
            }
            labelGuarantor.Text = _guarCur.GetNameFL();
            labelAddress.Text   = _guarCur.Address;
            if (!string.IsNullOrEmpty(_guarCur.Address2))
            {
                labelAddress.Text += ", " + _guarCur.Address2;
            }
            labelCityStZip.Text = _guarCur.City + ", " + _guarCur.State + " " + _guarCur.Zip;
            labelSSN.Text       = _guarCur.SSN.Substring(0, 3) + "-" + _guarCur.SSN.Substring(3, 2) + "-" + _guarCur.SSN.Substring(5, 4);
            labelDOB.Text       = _guarCur.Birthdate.Year < 1880?"":_guarCur.Birthdate.ToShortDateString();
            labelPhone.Text     = Clip(_guarCur.HmPhone, 13);
            labelEmployer.Text  = _empCur?.EmpName ?? "";
            labelEmpPhone.Text  = _empCur?.Phone ?? "";
            labelPatient.Text   = _patCur.GetNameFL();
            DateTime lastProcDate = TrojanQueries.GetMaxProcedureDate(_guarCur.PatNum);
            DateTime lastPayDate  = TrojanQueries.GetMaxPaymentDate(_guarCur.PatNum);

            textDate.Text   = (lastPayDate > lastProcDate?lastPayDate:lastProcDate).ToShortDateString();
            textAmount.Text = _guarCur.BalTotal.ToString("F2");
        }
        private void butMerge_Click(object sender, EventArgs e)
        {
            if (gridMain.SelectedIndices.Length < 2)
            {
                MessageBox.Show(Lan.g(this, "Please select at least two items first."));
                return;
            }
            InsPlan[] listSelected = new InsPlan[gridMain.SelectedIndices.Length];
            for (int i = 0; i < listSelected.Length; i++)
            {
                listSelected[i] = InsPlans.GetPlan(PIn.PInt(table.Rows[gridMain.SelectedIndices[i]]["PlanNum"].ToString()), null);
            }
            FormInsPlansMerge FormI = new FormInsPlansMerge();

            FormI.ListAll = listSelected;
            FormI.ShowDialog();
            if (FormI.DialogResult != DialogResult.OK)
            {
                return;
            }
            //Do the merge.
            InsPlan        planToMergeTo = FormI.PlanToMergeTo.Copy();
            List <Benefit> benList       = Benefits.RefreshForAll(planToMergeTo);

            Cursor = Cursors.WaitCursor;
            List <int> planNums;

            for (int i = 0; i < listSelected.Length; i++)      //loop through each selected plan group
            //skip the planToMergeTo, because it's already correct
            {
                if (planToMergeTo.PlanNum == listSelected[i].PlanNum)
                {
                    continue;
                }
                planNums = new List <int>(InsPlans.GetPlanNumsOfSamePlans(Employers.GetName(listSelected[i].EmployerNum),
                                                                          listSelected[i].GroupName, listSelected[i].GroupNum, listSelected[i].DivisionNo,
                                                                          Carriers.GetName(listSelected[i].CarrierNum),
                                                                          listSelected[i].IsMedical, listSelected[i].PlanNum, false));//remember that planNum=0
                //First plan info
                InsPlans.UpdateForLike(listSelected[i], planToMergeTo);
                //for(int j=0;j<planNums.Count;j++) {
                //InsPlans.ComputeEstimatesForPlan(planNums[j]);
                //Eliminated in 5.0 for speed.
                //}
                //then benefits
                Benefits.UpdateListForIdentical(new List <Benefit>(), benList, planNums);             //there will always be changes
                //Then PlanNote.  This is much simpler than the usual synch, because user has seen all versions of note.
                InsPlans.UpdateNoteForPlans(planNums, planToMergeTo.PlanNote);
            }
            FillGrid();
            //highlight the merged plan
            for (int i = 0; i < table.Rows.Count; i++)
            {
                for (int j = 0; j < listSelected.Length; j++)
                {
                    if (table.Rows[i]["PlanNum"].ToString() == listSelected[j].PlanNum.ToString())
                    {
                        gridMain.SetSelected(i, true);
                    }
                }
            }
            Cursor = Cursors.Default;
        }
        ///<summary></summary>
        private void FillGrid()
        {
            Cursor = Cursors.WaitCursor;
            int indexSelected = 0;

            if (gridMain.SelectedIndices.Length > 0)
            {
                indexSelected = gridMain.GetSelectedIndex();
            }
            //ListAll: Set externally before loading.
            gridMain.BeginUpdate();
            gridMain.ListGridColumns.Clear();
            GridColumn col = new GridColumn("Employer", 100);

            gridMain.ListGridColumns.Add(col);
            col = new GridColumn("Carrier", 100);
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn("Phone", 82);
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn("Address", 100);
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn("City", 80);
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn("ST", 25);
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn("Zip", 50);
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn("Group#", 70);
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn("Group Name", 90);
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn("Subs", 40);
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn("Plan Note", 180);
            gridMain.ListGridColumns.Add(col);
            //TrojanID and PlanNote not shown
            gridMain.ListGridRows.Clear();
            GridRow row;
            Carrier carrier;

            for (int i = 0; i < ListAll.Length; i++)
            {
                row = new GridRow();
                row.Cells.Add(Employers.GetName(ListAll[i].EmployerNum));
                carrier = Carriers.GetCarrier(ListAll[i].CarrierNum);
                row.Cells.Add(carrier.CarrierName);
                row.Cells.Add(carrier.Phone);
                row.Cells.Add(carrier.Address);
                row.Cells.Add(carrier.City);
                row.Cells.Add(carrier.State);
                row.Cells.Add(carrier.Zip);
                row.Cells.Add(ListAll[i].GroupNum);
                row.Cells.Add(ListAll[i].GroupName);
                row.Cells.Add(ListAll[i].NumberSubscribers.ToString());
                row.Cells.Add(ListAll[i].PlanNote);
                gridMain.ListGridRows.Add(row);
            }
            gridMain.EndUpdate();
            gridMain.SetSelected(indexSelected, true);
            Cursor = Cursors.Default;
        }