///<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); }
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(); }
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); }
///<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); }
///<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); } }
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(); }
///<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; }
///<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); }
///<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); }
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(); }
///<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"); } } }
/* * ///<summary>Only used in GetSearchResults. All times between start and stop get set to true in provBarSched.</summary> * private static void SetProvBarSched(ref bool[] provBarSched,TimeSpan timeStart,TimeSpan timeStop){ * int startI=GetProvBarIndex(timeStart); * int stopI=GetProvBarIndex(timeStop); * for(int i=startI;i<=stopI;i++){ * provBarSched[i]=true; * } * } * * private static int GetProvBarIndex(TimeSpan time) { * return (int)(((double)time.Hours*(double)60/(double)PrefC.GetLong(PrefName.AppointmentTimeIncrement)//aptTimeIncr=minutesPerIncr +(double)time.Minutes/(double)PrefC.GetLong(PrefName.AppointmentTimeIncrement)) *(double)ApptDrawing.LineH*ApptDrawing.RowsPerIncr) * /ApptDrawing.LineH;//rounds down * }*/ ///<summary>Used by UI when it needs a recall appointment placed on the pinboard ready to schedule. This method creates the appointment and attaches all appropriate procedures. It's up to the calling class to then place the appointment on the pinboard. If the appointment doesn't get scheduled, it's important to delete it. If a recallNum is not 0 or -1, then it will create an appt of that recalltype.</summary> public static Appointment CreateRecallApt(Patient patCur, List <Procedure> procList, List <InsPlan> planList, long recallNum, List <InsSub> subList) { List <Recall> recallList = Recalls.GetList(patCur.PatNum); Recall recallCur = null; if (recallNum > 0) { recallCur = Recalls.GetRecall(recallNum); } else { for (int i = 0; i < recallList.Count; i++) { if (recallList[i].RecallTypeNum == RecallTypes.PerioType || recallList[i].RecallTypeNum == RecallTypes.ProphyType) { if (!recallList[i].IsDisabled) { recallCur = recallList[i]; } break; } } } if (recallCur == null) // || recallCur.DateDue.Year<1880){ { throw new ApplicationException(Lan.g("AppointmentL", "No recall is due.")); //should never happen because everyone has a recall. } if (recallCur.DateScheduled.Date >= DateTime.Now.Date) { throw new ApplicationException(Lan.g("AppointmentL", "Recall has already been scheduled for ") + recallCur.DateScheduled.ToShortDateString()); } Appointment AptCur = new Appointment(); AptCur.PatNum = patCur.PatNum; AptCur.AptStatus = ApptStatus.UnschedList; //In all places where this is used, the unsched status with no aptDateTime will cause the appt to be deleted when the pinboard is cleared. if (patCur.PriProv == 0) { AptCur.ProvNum = PrefC.GetLong(PrefName.PracticeDefaultProv); } else { AptCur.ProvNum = patCur.PriProv; } AptCur.ProvHyg = patCur.SecProv; if (AptCur.ProvHyg != 0) { AptCur.IsHygiene = true; } AptCur.ClinicNum = patCur.ClinicNum; //whether perio or prophy: List <string> procs = RecallTypes.GetProcs(recallCur.RecallTypeNum); string recallPattern = RecallTypes.GetTimePattern(recallCur.RecallTypeNum); if (RecallTypes.IsSpecialRecallType(recallCur.RecallTypeNum) && patCur.Birthdate.AddYears(12) > ((recallCur.DateDue > DateTime.Today)?recallCur.DateDue:DateTime.Today)) //if pt's 12th birthday falls after recall date. ie younger than 12. { for (int i = 0; i < RecallTypeC.Listt.Count; i++) { if (RecallTypeC.Listt[i].RecallTypeNum == RecallTypes.ChildProphyType) { List <string> childprocs = RecallTypes.GetProcs(RecallTypeC.Listt[i].RecallTypeNum); if (childprocs.Count > 0) { procs = childprocs; //overrides adult procs. } string childpattern = RecallTypes.GetTimePattern(RecallTypeC.Listt[i].RecallTypeNum); if (childpattern != "") { recallPattern = childpattern; //overrides adult pattern. } } } } //convert time pattern to 5 minute increment StringBuilder savePattern = new StringBuilder(); for (int i = 0; i < recallPattern.Length; i++) { savePattern.Append(recallPattern.Substring(i, 1)); if (PrefC.GetLong(PrefName.AppointmentTimeIncrement) == 10) { savePattern.Append(recallPattern.Substring(i, 1)); } if (PrefC.GetLong(PrefName.AppointmentTimeIncrement) == 15) { savePattern.Append(recallPattern.Substring(i, 1)); savePattern.Append(recallPattern.Substring(i, 1)); } } if (savePattern.ToString() == "") { if (PrefC.GetLong(PrefName.AppointmentTimeIncrement) == 15) { savePattern.Append("///XXX///"); } else { savePattern.Append("//XX//"); } } AptCur.Pattern = savePattern.ToString(); //Add films------------------------------------------------------------------------------------------------------ if (RecallTypes.IsSpecialRecallType(recallCur.RecallTypeNum)) //if this is a prophy or perio { for (int i = 0; i < recallList.Count; i++) { if (recallCur.RecallNum == recallList[i].RecallNum) { continue; //already handled. } if (recallList[i].IsDisabled) { continue; } if (recallList[i].DateDue.Year < 1880) { continue; } if (recallList[i].DateDue > recallCur.DateDue && //if film due date is after prophy due date recallList[i].DateDue > DateTime.Today) //and not overdue { continue; } //incomplete: exclude manual recall types procs.AddRange(RecallTypes.GetProcs(recallList[i].RecallTypeNum)); } } AptCur.ProcDescript = ""; for (int i = 0; i < procs.Count; i++) { if (i > 0) { AptCur.ProcDescript += ", "; } AptCur.ProcDescript += ProcedureCodes.GetProcCode(procs[i]).AbbrDesc; } Appointments.Insert(AptCur); Procedure ProcCur; List <PatPlan> patPlanList = PatPlans.Refresh(patCur.PatNum); List <Benefit> benefitList = Benefits.Refresh(patPlanList, subList); InsPlan priplan = null; InsSub prisub = null; if (patPlanList.Count > 0) { prisub = InsSubs.GetSub(patPlanList[0].InsSubNum, subList); priplan = InsPlans.GetPlan(prisub.PlanNum, planList); } double insfee; double standardfee; for (int i = 0; i < procs.Count; i++) { ProcCur = new Procedure(); //this will be an insert //procnum ProcCur.PatNum = patCur.PatNum; ProcCur.AptNum = AptCur.AptNum; ProcCur.CodeNum = ProcedureCodes.GetCodeNum(procs[i]); ProcCur.ProcDate = DateTime.Now; ProcCur.DateTP = DateTime.Now; //Check if it's a medical procedure. bool isMed = false; ProcCur.MedicalCode = ProcedureCodes.GetProcCode(ProcCur.CodeNum).MedicalCode; if (ProcCur.MedicalCode != null && ProcCur.MedicalCode != "") { isMed = true; } //Get fee schedule for medical or dental. long feeSch; if (isMed) { feeSch = Fees.GetMedFeeSched(patCur, planList, patPlanList, subList); } else { feeSch = Fees.GetFeeSched(patCur, planList, patPlanList, subList); } //Get the fee amount for medical or dental. if (PrefC.GetBool(PrefName.MedicalFeeUsedForNewProcs) && isMed) { insfee = Fees.GetAmount0(ProcedureCodes.GetProcCode(ProcCur.MedicalCode).CodeNum, feeSch); } else { insfee = Fees.GetAmount0(ProcCur.CodeNum, feeSch); } if (priplan != null && priplan.PlanType == "p") //PPO { standardfee = Fees.GetAmount0(ProcCur.CodeNum, Providers.GetProv(Patients.GetProvNum(patCur)).FeeSched); if (standardfee > insfee) { ProcCur.ProcFee = standardfee; } else { ProcCur.ProcFee = insfee; } } else { ProcCur.ProcFee = insfee; } //surf //toothnum //Procedures.Cur.ToothRange=""; //ProcCur.NoBillIns=ProcedureCodes.GetProcCode(ProcCur.CodeNum).NoBillIns; //priority ProcCur.ProcStatus = ProcStat.TP; ProcCur.Note = ""; //Procedures.Cur.PriEstim= //Procedures.Cur.SecEstim= //claimnum ProcCur.ProvNum = patCur.PriProv; //Procedures.Cur.Dx= ProcCur.ClinicNum = patCur.ClinicNum; //nextaptnum ProcCur.BaseUnits = ProcedureCodes.GetProcCode(ProcCur.CodeNum).BaseUnits; Procedures.Insert(ProcCur); //no recall synch required Procedures.ComputeEstimates(ProcCur, patCur.PatNum, new List <ClaimProc>(), false, planList, patPlanList, benefitList, patCur.Age, subList); if (Programs.UsingOrion) { FormProcEdit FormP = new FormProcEdit(ProcCur, patCur.Copy(), Patients.GetFamily(patCur.PatNum)); FormP.IsNew = true; FormP.ShowDialog(); if (FormP.DialogResult == DialogResult.Cancel) { //any created claimprocs are automatically deleted from within procEdit window. try{ Procedures.Delete(ProcCur.ProcNum); //also deletes the claimprocs } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { //Do not synch. Recalls based on ScheduleByDate reports in Orion mode. //Recalls.Synch(PatCur.PatNum); } } } return(AptCur); }
private void butOK_Click(object sender, System.EventArgs e) { RepeatCharge[] chargeList = RepeatCharges.Refresh(0); //Gets all repeating charges for all patients, they may be disabled int countAdded = 0; int claimsAdded = 0; DateTime startDate; Procedure proc; for (int i = 0; i < chargeList.Length; i++) { if (!chargeList[i].IsEnabled) //first make sure it is not disabled { continue; } if (chargeList[i].DateStart > DateTime.Today) //not started yet { continue; } //if(chargeList[i].DateStop.Year>1880//not blank // && chargeList[i].DateStop<DateTime.Today)//but already ended //{ // continue; //} //get a list dates of all completed procedures with this Code and patNum ArrayList ALdates = RepeatCharges.GetDates(ProcedureCodes.GetCodeNum(chargeList[i].ProcCode), chargeList[i].PatNum); startDate = chargeList[i].DateStart; //This is the repeating date using the old methodology. It is necessary for checking if the repeating procedure was already added using the old methodology. DateTime possibleDateOld = startDate; //This is a more accurate repeating date which will allow procedures to be added on the 28th and later. DateTime possibleDateNew = startDate; int countMonths = 0; //start looping through possible dates, beginning with the start date of the repeating charge while (possibleDateNew <= DateTime.Today) { //Only allow back dating up to one month and 20 days. if (possibleDateNew < DateTime.Today.AddDays(-50)) { possibleDateOld = possibleDateOld.AddMonths(1); countMonths++; possibleDateNew = startDate.AddMonths(countMonths); continue; //don't go back more than one month and 20 days } //check to see if the possible date is present in the list if (ALdates.Contains(possibleDateNew) || ALdates.Contains(possibleDateOld)) { possibleDateOld = possibleDateOld.AddMonths(1); countMonths++; possibleDateNew = startDate.AddMonths(countMonths); continue; } if (chargeList[i].DateStop.Year > 1880 && //not blank chargeList[i].DateStop < possibleDateNew) //but already ended { break; } //otherwise, insert a procedure to db proc = new Procedure(); proc.CodeNum = ProcedureCodes.GetCodeNum(chargeList[i].ProcCode); proc.DateEntryC = DateTimeOD.Today; proc.PatNum = chargeList[i].PatNum; proc.ProcDate = possibleDateNew; proc.DateTP = possibleDateNew; proc.ProcFee = chargeList[i].ChargeAmt; proc.ProcStatus = ProcStat.C; proc.ProvNum = PrefC.GetLong(PrefName.PracticeDefaultProv); proc.MedicalCode = ProcedureCodes.GetProcCode(proc.CodeNum).MedicalCode; proc.BaseUnits = ProcedureCodes.GetProcCode(proc.CodeNum).BaseUnits; proc.DiagnosticCode = PrefC.GetString(PrefName.ICD9DefaultForNewProcs); //Check if the repeating charge has been flagged to copy it's note into the billing note of the procedure. if (chargeList[i].CopyNoteToProc) { proc.BillingNote = chargeList[i].Note; } Procedures.Insert(proc); //no recall synch needed because dental offices don't use this feature countAdded++; possibleDateOld = possibleDateOld.AddMonths(1); countMonths++; possibleDateNew = startDate.AddMonths(countMonths); if (chargeList[i].CreatesClaim && !ProcedureCodes.GetProcCode(chargeList[i].ProcCode).NoBillIns) { List <PatPlan> patPlanList = PatPlans.Refresh(chargeList[i].PatNum); List <InsSub> subList = InsSubs.RefreshForFam(Patients.GetFamily(chargeList[i].PatNum)); List <InsPlan> insPlanList = InsPlans.RefreshForSubList(subList);; List <Benefit> benefitList = Benefits.Refresh(patPlanList, subList); Claim claimCur; List <Procedure> procCurList = new List <Procedure>(); procCurList.Add(proc); if (patPlanList.Count == 0) //no current insurance, do not create a claim { continue; } //create the claimprocs Procedures.ComputeEstimates(proc, proc.PatNum, new List <ClaimProc>(), true, insPlanList, patPlanList, benefitList, Patients.GetPat(proc.PatNum).Age, subList); //get claimprocs for this proc, may be more than one List <ClaimProc> claimProcList = ClaimProcs.GetForProc(ClaimProcs.Refresh(proc.PatNum), proc.ProcNum); string claimType = "P"; if (patPlanList.Count == 1 && PatPlans.GetOrdinal(PriSecMed.Medical, patPlanList, insPlanList, subList) > 0) //if there's exactly one medical plan { claimType = "Med"; } claimCur = CreateClaim(claimType, patPlanList, insPlanList, claimProcList, proc, subList); claimProcList = ClaimProcs.Refresh(proc.PatNum); if (claimCur.ClaimNum == 0) { continue; } claimsAdded++; ClaimL.CalculateAndUpdate(procCurList, insPlanList, claimCur, patPlanList, benefitList, Patients.GetPat(proc.PatNum).Age, subList); if (PatPlans.GetOrdinal(PriSecMed.Secondary, patPlanList, insPlanList, subList) > 0 && //if there exists a secondary plan !CultureInfo.CurrentCulture.Name.EndsWith("CA")) //and not canada (don't create secondary claim for canada) { claimCur = CreateClaim("S", patPlanList, insPlanList, claimProcList, proc, subList); if (claimCur.ClaimNum == 0) { continue; } claimsAdded++; claimProcList = ClaimProcs.Refresh(proc.PatNum); claimCur.ClaimStatus = "H"; ClaimL.CalculateAndUpdate(procCurList, insPlanList, claimCur, patPlanList, benefitList, Patients.GetPat(proc.PatNum).Age, subList); } } } } //MessageBox.Show(countAdded.ToString()+" "+Lan.g(this,"procedures added.")); MessageBox.Show(countAdded.ToString() + " " + Lan.g(this, "procedures added.") + "\r\n" + claimsAdded.ToString() + " " + Lan.g(this, "claims added.")); DialogResult = DialogResult.OK; }
///<summary>Used by UI when it needs a recall appointment placed on the pinboard ready to schedule. This method creates the appointment and attaches all appropriate procedures. It's up to the calling class to then place the appointment on the pinboard. If the appointment doesn't get scheduled, it's important to delete it.</summary> public static Appointment CreateRecallApt(Patient patCur, Procedure[] procList, Recall recallCur, InsPlan[] planList) { Appointment AptCur = new Appointment(); AptCur.PatNum = patCur.PatNum; AptCur.AptStatus = ApptStatus.Scheduled; //convert time pattern to 5 minute increment StringBuilder savePattern = new StringBuilder(); for (int i = 0; i < PrefB.GetString("RecallPattern").Length; i++) { savePattern.Append(PrefB.GetString("RecallPattern").Substring(i, 1)); savePattern.Append(PrefB.GetString("RecallPattern").Substring(i, 1)); if (PrefB.GetInt("AppointmentTimeIncrement") == 15) { savePattern.Append(PrefB.GetString("RecallPattern").Substring(i, 1)); } } AptCur.Pattern = savePattern.ToString(); if (patCur.PriProv == 0) { AptCur.ProvNum = PrefB.GetInt("PracticeDefaultProv"); } else { AptCur.ProvNum = patCur.PriProv; } AptCur.ProvHyg = patCur.SecProv; if (AptCur.ProvHyg != 0) { AptCur.IsHygiene = true; } AptCur.ClinicNum = patCur.ClinicNum; string[] procs = PrefB.GetString("RecallProcedures").Split(','); if (PrefB.GetString("RecallBW") != "") //BWs { bool dueBW = true; //DateTime dueDate=PIn.PDate(listFamily.Items[ for (int i = 0; i < procList.Length; i++) //loop through all procedures for this pt. //if any BW found within last year, then dueBW=false. { if (PrefB.GetString("RecallBW") == procList[i].ADACode && recallCur.DateDue.Year > 1880 && procList[i].ProcDate > recallCur.DateDue.AddYears(-1)) { dueBW = false; } } if (dueBW) { string[] procs2 = new string[procs.Length + 1]; procs.CopyTo(procs2, 0); procs2[procs2.Length - 1] = PrefB.GetString("RecallBW"); procs = new string[procs2.Length]; procs2.CopyTo(procs, 0); } } AptCur.ProcDescript = ""; for (int i = 0; i < procs.Length; i++) { if (i > 0) { AptCur.ProcDescript += ", "; } AptCur.ProcDescript += ProcedureCodes.GetProcCode(procs[i]).AbbrDesc; } Appointments.InsertOrUpdate(AptCur, null, true); Procedure ProcCur; PatPlan[] patPlanList = PatPlans.Refresh(patCur.PatNum); Benefit[] benefitList = Benefits.Refresh(patPlanList); //ClaimProc[] claimProcs=ClaimProcs.Refresh(Patients.Cur.PatNum); for (int i = 0; i < procs.Length; i++) { ProcCur = new Procedure(); //this will be an insert //procnum ProcCur.PatNum = patCur.PatNum; ProcCur.AptNum = AptCur.AptNum; ProcCur.ADACode = procs[i]; ProcCur.ProcDate = DateTime.Now; ProcCur.ProcFee = Fees.GetAmount0(ProcCur.ADACode, Fees.GetFeeSched(patCur, planList, patPlanList)); //ProcCur.OverridePri=-1; //ProcCur.OverrideSec=-1; //surf //toothnum //Procedures.Cur.ToothRange=""; //ProcCur.NoBillIns=ProcedureCodes.GetProcCode(ProcCur.ADACode).NoBillIns; //priority ProcCur.ProcStatus = ProcStat.TP; ProcCur.Note = ""; //Procedures.Cur.PriEstim= //Procedures.Cur.SecEstim= //claimnum ProcCur.ProvNum = patCur.PriProv; //Procedures.Cur.Dx= ProcCur.ClinicNum = patCur.ClinicNum; //nextaptnum ProcCur.MedicalCode = ProcedureCodes.GetProcCode(ProcCur.ADACode).MedicalCode; Procedures.Insert(ProcCur); //no recall synch required Procedures.ComputeEstimates(ProcCur, patCur.PatNum, new ClaimProc[0], false, planList, patPlanList, benefitList); } return(AptCur); }
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(); }
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); }
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(); }
///<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; } }
private void FillGrid() { gridRemainTimeUnits.BeginUpdate(); gridRemainTimeUnits.Rows.Clear(); List <Benefit> listPatBenefits = Benefits.Refresh(PatPlans.Refresh(_patCur.PatNum), InsSubs.GetListForSubscriber(_patCur.PatNum)); ODGridRow gridRow; List <Procedure> listProcs; double amtUsed; int monthRenew; if (listPatBenefits.Count > 0) { for (int i = 0; i < listPatBenefits.Count; i++) { if (listPatBenefits[i].CovCatNum == 0 || //no category listPatBenefits[i].BenefitType != InsBenefitType.Limitations || //benefit type is not limitations (listPatBenefits[i].TimePeriod != BenefitTimePeriod.CalendarYear && //neither calendar year nor serviceyear listPatBenefits[i].TimePeriod != BenefitTimePeriod.ServiceYear) || listPatBenefits[i].Quantity < 0 || //quantity is negative (negatives are allowed in FormBenefitEdit) listPatBenefits[i].QuantityQualifier != BenefitQuantity.NumberOfServices || //qualifier us not the number of services (listPatBenefits[i].CoverageLevel != BenefitCoverageLevel.Family && //neither individual nor family coverage level listPatBenefits[i].CoverageLevel != BenefitCoverageLevel.Individual)) { continue; } //for calendar year, get completed procs from January.01.CurYear ~ Curdate List <long> listPatNums = new List <long> { _patCur.PatNum }; //for current patient. if (listPatBenefits[i].TimePeriod == BenefitTimePeriod.CalendarYear) { //01/01/CurYear. is there a better way? listProcs = Procedures.GetCompletedForDateRange(new DateTime(DateTimeOD.Today.Year, 1, 1), DateTimeOD.Today, null, listPatNums); } else //if not calendar year, then it must be service year { monthRenew = InsPlans.RefreshOne(listPatBenefits[i].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 = Procedures.GetCompletedForDateRange(new DateTime(DateTimeOD.Today.Year, monthRenew, 1), DateTimeOD.Today, null, listPatNums); } else //otherwise use the previous year { listProcs = Procedures.GetCompletedForDateRange(new DateTime(DateTimeOD.Today.Year - 1, monthRenew, 1), DateTimeOD.Today, null, listPatNums); } } //Calculate the amount used for one benefit. amtUsed = GetAmtUsedForCat(listProcs, CovCats.GetCovCat(listPatBenefits[i].CovCatNum)); gridRow = new ODGridRow(); gridRow.Cells.Add(CovCats.GetCovCat(listPatBenefits[i].CovCatNum).EbenefitCat.ToString()); //Coverage Category gridRow.Cells.Add(listPatBenefits[i].Quantity.ToString()); //Quantity gridRow.Cells.Add(amtUsed.ToString("F")); //Used double amtRemain = listPatBenefits[i].Quantity - amtUsed; if (amtRemain > 0) { gridRow.Cells.Add(amtRemain.ToString("F")); //quantity-used. } else //if less then 0, just 0. { gridRow.Cells.Add("0"); } gridRemainTimeUnits.Rows.Add(gridRow); } } gridRemainTimeUnits.EndUpdate(); }