///<summary>Gets all claims for the patient selected. Fills gridClaims and tags each row with its corrisponding claim object.</summary> private void FillGridClaims() { int sortByColIdx = gridClaims.SortedByColumnIdx; //Keep previous sorting bool isSortAsc = gridClaims.SortedIsAscending; if (sortByColIdx == -1) { sortByColIdx = 0; isSortAsc = false; } gridClaims.BeginUpdate(); gridClaims.Rows.Clear(); gridClaims.Columns.Clear(); gridClaims.Columns.Add(new UI.ODGridColumn("Date Service", 100, HorizontalAlignment.Center) { SortingStrategy = UI.GridSortingStrategy.DateParse }); gridClaims.Columns.Add(new UI.ODGridColumn("Carrier", 240, HorizontalAlignment.Center) { SortingStrategy = UI.GridSortingStrategy.StringCompare }); gridClaims.Columns.Add(new UI.ODGridColumn("Status", 120, HorizontalAlignment.Center) { SortingStrategy = UI.GridSortingStrategy.StringCompare }); if (!PrefC.GetBool(PrefName.EasyNoClinics)) //Using clinics { gridClaims.Columns.Add(new UI.ODGridColumn("Clinic", 190, HorizontalAlignment.Left) { SortingStrategy = UI.GridSortingStrategy.StringCompare }); } gridClaims.Columns.Add(new UI.ODGridColumn("ClaimFee", 70, HorizontalAlignment.Right) { SortingStrategy = UI.GridSortingStrategy.AmountParse }); List <Claim> listClaims = Claims.Refresh(_patNum); for (int i = 0; i < listClaims.Count; i++) { UI.ODGridRow row = new UI.ODGridRow(); row.Tag = listClaims[i]; row.Cells.Add(listClaims[i].DateService.ToShortDateString()); //DOS row.Cells.Add(Carriers.GetName(InsPlans.RefreshOne(listClaims[i].PlanNum).CarrierNum)); //Carrier row.Cells.Add(Claims.GetClaimStatusString(listClaims[i].ClaimStatus)); //Status if (!PrefC.GetBool(PrefName.EasyNoClinics)) //Using clinics { Clinic clinic = Clinics.GetClinic(listClaims[i].ClinicNum); if (clinic == null) { row.Cells.Add(""); //Clinic } else { row.Cells.Add(clinic.Description); //Clinic } } row.Cells.Add(listClaims[i].ClaimFee.ToString("f")); //Claimfee gridClaims.Rows.Add(row); } gridClaims.EndUpdate(); gridClaims.SortForced(sortByColIdx, isSortAsc); }
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); }
///<summary>All of the code from this method is copied directly from the account module, ContrAccount.FillSummary().</summary> private void FillSummary() { textFamPriMax.Text = ""; textFamPriDed.Text = ""; textFamSecMax.Text = ""; textFamSecDed.Text = ""; textPriMax.Text = ""; textPriDed.Text = ""; textPriDedRem.Text = ""; textPriUsed.Text = ""; textPriPend.Text = ""; textPriRem.Text = ""; textSecMax.Text = ""; textSecDed.Text = ""; textSecDedRem.Text = ""; textSecUsed.Text = ""; textSecPend.Text = ""; textSecRem.Text = ""; if (_patCur == null) { return; } double maxFam = 0; double maxInd = 0; double ded = 0; double dedFam = 0; double dedRem = 0; double remain = 0; double pend = 0; double used = 0; InsPlan PlanCur; InsSub SubCur; List <PatPlan> PatPlanList = PatPlans.Refresh(_patCur.PatNum); if (!PatPlans.IsPatPlanListValid(PatPlanList)) { //PatPlans had invalid references and need to be refreshed. PatPlanList = PatPlans.Refresh(_patCur.PatNum); } List <InsSub> subList = InsSubs.RefreshForFam(_famCur); List <InsPlan> InsPlanList = InsPlans.RefreshForSubList(subList); List <Benefit> BenefitList = Benefits.Refresh(PatPlanList, subList); List <Claim> ClaimList = Claims.Refresh(_patCur.PatNum); List <ClaimProcHist> HistList = ClaimProcs.GetHistList(_patCur.PatNum, BenefitList, PatPlanList, InsPlanList, DateTimeOD.Today, subList); if (PatPlanList.Count > 0) { SubCur = InsSubs.GetSub(PatPlanList[0].InsSubNum, subList); PlanCur = InsPlans.GetPlan(SubCur.PlanNum, InsPlanList); pend = InsPlans.GetPendingDisplay(HistList, DateTimeOD.Today, PlanCur, PatPlanList[0].PatPlanNum, -1, _patCur.PatNum, PatPlanList[0].InsSubNum, BenefitList); used = InsPlans.GetInsUsedDisplay(HistList, DateTimeOD.Today, PlanCur.PlanNum, PatPlanList[0].PatPlanNum, -1, InsPlanList, BenefitList, _patCur.PatNum, PatPlanList[0].InsSubNum); textPriPend.Text = pend.ToString("F"); textPriUsed.Text = used.ToString("F"); maxFam = Benefits.GetAnnualMaxDisplay(BenefitList, PlanCur.PlanNum, PatPlanList[0].PatPlanNum, true); maxInd = Benefits.GetAnnualMaxDisplay(BenefitList, PlanCur.PlanNum, PatPlanList[0].PatPlanNum, false); if (maxFam == -1) { textFamPriMax.Text = ""; } else { textFamPriMax.Text = maxFam.ToString("F"); } if (maxInd == -1) //if annual max is blank { textPriMax.Text = ""; textPriRem.Text = ""; } else { remain = maxInd - used - pend; if (remain < 0) { remain = 0; } //textFamPriMax.Text=max.ToString("F"); textPriMax.Text = maxInd.ToString("F"); textPriRem.Text = remain.ToString("F"); } //deductible: ded = Benefits.GetDeductGeneralDisplay(BenefitList, PlanCur.PlanNum, PatPlanList[0].PatPlanNum, BenefitCoverageLevel.Individual); dedFam = Benefits.GetDeductGeneralDisplay(BenefitList, PlanCur.PlanNum, PatPlanList[0].PatPlanNum, BenefitCoverageLevel.Family); if (ded != -1) { textPriDed.Text = ded.ToString("F"); dedRem = InsPlans.GetDedRemainDisplay(HistList, DateTimeOD.Today, PlanCur.PlanNum, PatPlanList[0].PatPlanNum, -1, InsPlanList, _patCur.PatNum, ded, dedFam); textPriDedRem.Text = dedRem.ToString("F"); } if (dedFam != -1) { textFamPriDed.Text = dedFam.ToString("F"); } } if (PatPlanList.Count > 1) { SubCur = InsSubs.GetSub(PatPlanList[1].InsSubNum, subList); PlanCur = InsPlans.GetPlan(SubCur.PlanNum, InsPlanList); pend = InsPlans.GetPendingDisplay(HistList, DateTimeOD.Today, PlanCur, PatPlanList[1].PatPlanNum, -1, _patCur.PatNum, PatPlanList[1].InsSubNum, BenefitList); textSecPend.Text = pend.ToString("F"); used = InsPlans.GetInsUsedDisplay(HistList, DateTimeOD.Today, PlanCur.PlanNum, PatPlanList[1].PatPlanNum, -1, InsPlanList, BenefitList, _patCur.PatNum, PatPlanList[1].InsSubNum); textSecUsed.Text = used.ToString("F"); //max=Benefits.GetAnnualMaxDisplay(BenefitList,PlanCur.PlanNum,PatPlanList[1].PatPlanNum); maxFam = Benefits.GetAnnualMaxDisplay(BenefitList, PlanCur.PlanNum, PatPlanList[1].PatPlanNum, true); maxInd = Benefits.GetAnnualMaxDisplay(BenefitList, PlanCur.PlanNum, PatPlanList[1].PatPlanNum, false); if (maxFam == -1) { textFamSecMax.Text = ""; } else { textFamSecMax.Text = maxFam.ToString("F"); } if (maxInd == -1) //if annual max is blank { textSecMax.Text = ""; textSecRem.Text = ""; } else { remain = maxInd - used - pend; if (remain < 0) { remain = 0; } //textFamSecMax.Text=max.ToString("F"); textSecMax.Text = maxInd.ToString("F"); textSecRem.Text = remain.ToString("F"); } //deductible: ded = Benefits.GetDeductGeneralDisplay(BenefitList, PlanCur.PlanNum, PatPlanList[1].PatPlanNum, BenefitCoverageLevel.Individual); dedFam = Benefits.GetDeductGeneralDisplay(BenefitList, PlanCur.PlanNum, PatPlanList[1].PatPlanNum, BenefitCoverageLevel.Family); if (ded != -1) { textSecDed.Text = ded.ToString("F"); dedRem = InsPlans.GetDedRemainDisplay(HistList, DateTimeOD.Today, PlanCur.PlanNum, PatPlanList[1].PatPlanNum, -1, InsPlanList, _patCur.PatNum, ded, dedFam); textSecDedRem.Text = dedRem.ToString("F"); } if (dedFam != -1) { textFamSecDed.Text = dedFam.ToString("F"); } } }