///<summary></summary> public void butOK_Click(object sender, System.EventArgs e) //this is public for NewPatientForm bridge { 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 = PrefB.GetInt("PracticeDefaultProv"); pat.BillingType = PrefB.GetInt("PracticeDefaultBillType"); guar = new Patient(); guar.PriProv = PrefB.GetInt("PracticeDefaultProv"); guar.BillingType = PrefB.GetInt("PracticeDefaultBillType"); subsc = new Patient(); subsc.PriProv = PrefB.GetInt("PracticeDefaultProv"); subsc.BillingType = PrefB.GetInt("PracticeDefaultBillType"); plan = new InsPlan(); plan.ReleaseInfo = true; plan.AssignBen = true; 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 (plan.SubscriberID == "") { warnings += "PolicyNumber/SubscriberID missing.\r\n"; plan.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------------------------------------------------------------------------------------- string command; DataTable table; command = "SELECT PatNum FROM patient WHERE " + "LName='" + POut.PString(pat.LName) + "' " + "AND FName='" + POut.PString(pat.FName) + "' " + "AND Birthdate=" + POut.PDate(pat.Birthdate) + " " + "AND PatStatus!=4"; //not deleted table = General.GetTable(command); Patient existingPat = null; existingPatOld = null; //we will need this to do an update. if (table.Rows.Count > 0) //a patient already exists, so only add missing fields { existingPat = Patients.GetPat(PIn.PInt(table.Rows[0][0].ToString())); 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); 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 command = "SELECT PatNum FROM patient WHERE " + "LName='" + POut.PString(guar.LName) + "' " + "AND FName='" + POut.PString(guar.FName) + "' " + "AND Birthdate=" + POut.PDate(guar.Birthdate) + " " + "AND PatStatus!=4"; //not deleted table = General.GetTable(command); if (table.Rows.Count > 0) //a guar already exists, so simply attach. Make no other changes { existingPatOld = pat.Copy(); pat.Guarantor = PIn.PInt(table.Rows[0][0].ToString()); if (guarRelat == "parent") { pat.Position = PatientPosition.Child; } Patients.Update(pat, existingPatOld); } else //we need to completely create guar, then attach { Patients.Insert(guar, false); //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") { plan.Subscriber = pat.PatNum; } else //we need to find or add the subscriber { command = "SELECT PatNum FROM patient WHERE " + "LName='" + POut.PString(subsc.LName) + "' " + "AND FName='" + POut.PString(subsc.FName) + "' " + "AND Birthdate=" + POut.PDate(subsc.Birthdate) + " " + "AND PatStatus!=4"; //not deleted table = General.GetTable(command); if (table.Rows.Count > 0) //a subsc already exists, so simply attach. Make no other changes { plan.Subscriber = PIn.PInt(table.Rows[0][0].ToString()); } else //need to create and attach a subscriber { Patients.Insert(subsc, false); //set guar to same guar as patient existingPatOld = subsc.Copy(); subsc.Guarantor = pat.Guarantor; Patients.Update(subsc, existingPatOld); plan.Subscriber = subsc.PatNum; } } //carrier------------------------------------------------------------------------------------------------- //Carriers.Cur=carrier; Carriers.GetCurSame(carrier); //this automatically finds or creates a carrier //plan------------------------------------------------------------------------------------------------------ plan.EmployerNum = Employers.GetEmployerNum(InsEmp); plan.CarrierNum = carrier.CarrierNum; InsPlans.Insert(plan); //Then attach plan PatPlan[] PatPlanList = PatPlans.Refresh(pat.PatNum); PatPlan patplan = new PatPlan(); patplan.Ordinal = PatPlanList.Length + 1; //so the ordinal of the first entry will be 1, NOT 0. patplan.PatNum = pat.PatNum; patplan.PlanNum = plan.PlanNum; 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 && CovCatB.ListShort.Length > 0) { Benefit ben = new Benefit(); ben.BenefitType = InsBenefitType.Limitations; ben.CovCatNum = CovCatB.ListShort[0].CovCatNum; ben.MonetaryAmt = annualMax; ben.PlanNum = plan.PlanNum; ben.TimePeriod = BenefitTimePeriod.CalendarYear; Benefits.Insert(ben); } if (deductible != -1 && CovCatB.ListShort.Length > 0) { Benefit ben = new Benefit(); ben.BenefitType = InsBenefitType.Deductible; ben.CovCatNum = CovCatB.ListShort[0].CovCatNum; ben.MonetaryAmt = deductible; ben.PlanNum = plan.PlanNum; ben.TimePeriod = BenefitTimePeriod.CalendarYear; Benefits.Insert(ben); } MsgBox.Show(this, "Done"); DialogResult = DialogResult.OK; }