private void butOK_Click(object sender, System.EventArgs e) { Patient PatOld = PatCur.Copy(); PatCur.Premed = checkPremed.Checked; PatCur.MedUrgNote = textMedUrgNote.Text; Patients.Update(PatCur, PatOld); PatientNoteCur.Medical = textMedical.Text; PatientNoteCur.Service = textService.Text; PatientNoteCur.MedicalComp = textMedicalComp.Text; PatientNotes.Update(PatientNoteCur, PatCur.Guarantor); DialogResult = DialogResult.OK; }
///<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; }