public static void ProcessPD1(Patient pat, SegmentHL7 seg) { long provNum = SegmentPID.ProvProcess(seg.GetField(4)); //don't know why both if (provNum != 0) { pat.PriProv = provNum; } }
///<summary>If relationship is self, this loop does nothing. A new pat will later change guarantor to be same as patnum. </summary> public static void ProcessGT1(Patient pat, SegmentHL7 seg, bool useChartNumber) { long guarNum = PIn.Long(seg.GetFieldFullText(2)); if (guarNum == 0) //because we have an example where they sent us this (position 2 is empty): GT1|1||^^||^^^^|||||||| { return; } if (seg.GetFieldFullText(11) == "1") //if relationship is self (according to some of their documentation) { return; } Patient guar = null; Patient guarOld = null; //So guarantor is someone else if (useChartNumber) { //try to find guarantor by using chartNumber guar = Patients.GetPatByChartNumber(guarNum.ToString()); if (guar == null) { //try to find the guarantor by using name and birthdate string lName = seg.GetFieldComponent(3, 0); string fName = seg.GetFieldComponent(3, 1); DateTime birthdate = SegmentPID.DateParse(seg.GetFieldFullText(8)); long guarNumByName = Patients.GetPatNumByNameAndBirthday(lName, fName, birthdate); if (guarNumByName == 0) //guarantor does not exist in OD //so guar will still be null, triggering creation of new guarantor further down. { } else { guar = Patients.GetPat(guarNumByName); guar.ChartNumber = guarNum.ToString(); //from now on, we will be able to find guar by chartNumber } } } else { guar = Patients.GetPat(guarNum); } //we can't necessarily set pat.Guarantor yet, because in Standalone mode, we might not know it yet. bool isNewGuar = guar == null; if (isNewGuar) //then we need to add guarantor to db { guar = new Patient(); if (useChartNumber) { guar.ChartNumber = guarNum.ToString(); } else { guar.PatNum = guarNum; } guar.PriProv = PrefC.GetLong(PrefName.PracticeDefaultProv); guar.BillingType = PrefC.GetLong(PrefName.PracticeDefaultBillType); } else { guarOld = guar.Copy(); } //guar.Guarantor=guarNum; guar.LName = seg.GetFieldComponent(3, 0); guar.FName = seg.GetFieldComponent(3, 1); guar.MiddleI = seg.GetFieldComponent(3, 2); guar.Address = seg.GetFieldComponent(5, 0); guar.Address2 = seg.GetFieldComponent(5, 1); guar.City = seg.GetFieldComponent(5, 2); guar.State = seg.GetFieldComponent(5, 3); guar.Zip = seg.GetFieldComponent(5, 4); guar.HmPhone = PhoneParse(seg.GetFieldFullText(6)); guar.WkPhone = PhoneParse(seg.GetFieldFullText(7)); guar.Birthdate = DateParse(seg.GetFieldFullText(8)); guar.Gender = GenderParse(seg.GetFieldFullText(9)); //11. Guarantor relationship to patient. We can't really do anything with this value guar.SSN = seg.GetFieldFullText(12); if (isNewGuar) { Patients.Insert(guar, true); guarOld = guar.Copy(); guar.Guarantor = guar.PatNum; Patients.Update(guar, guarOld); } else { Patients.Update(guar, guarOld); } pat.Guarantor = guar.PatNum; }
public static void ProcessMessage(MessageHL7 message, bool isStandalone, bool isVerboseLogging) { SegmentHL7 seg = message.GetSegment(SegmentName.PID, true); long patNum = PIn.Long(seg.GetFieldFullText(2)); Patient pat = Patients.GetPat(patNum); Patient patOld = null; bool isNewPat = pat == null; if (isNewPat) { pat = new Patient(); pat.PatNum = patNum; pat.Guarantor = patNum; pat.PriProv = PrefC.GetLong(PrefName.PracticeDefaultProv); pat.BillingType = PrefC.GetLong(PrefName.PracticeDefaultBillType); } else { patOld = pat.Copy(); } SegmentPID.ProcessPID(pat, seg, isStandalone); //PV1-patient visit--------------------------- //seg=message.GetSegment(SegmentName.PV1,false); //if(seg!=null) { // SegmentPID.ProcessPV1(pat,seg); //} //SCH- Schedule Activity Information seg = message.GetSegment(SegmentName.SCH, true); //The documentation is wrong. SCH.01 is not the appointment ID, but is instead a sequence# (always 1) long aptNum = PIn.Long(seg.GetFieldFullText(2)); Appointment apt = Appointments.GetOneApt(aptNum); Appointment aptOld = null; bool isNewApt = apt == null; if (isNewApt) { apt = new Appointment(); apt.AptNum = aptNum; apt.PatNum = pat.PatNum; apt.AptStatus = ApptStatus.Scheduled; } else { aptOld = apt.Clone(); } if (apt.PatNum != pat.PatNum) { EventLog.WriteEntry("OpenDentHL7", "Appointment does not match patient: " + pat.FName + " " + pat.LName + ", apt.PatNum:" + apt.PatNum.ToString() + ", pat.PatNum:" + pat.PatNum.ToString() , EventLogEntryType.Error); return; //we can't process this message because wrong patnum. } apt.Note = seg.GetFieldFullText(7); //apt.Pattern=ProcessDuration(seg.GetFieldFullText(9)); //9 and 10 are not actually available, in spite of the documentation. //11-We need start time and stop time apt.AptDateTime = DateTimeParse(seg.GetFieldComponent(11, 3)); DateTime stopTime = DateTimeParse(seg.GetFieldComponent(11, 4)); apt.Pattern = ProcessPattern(apt.AptDateTime, stopTime); apt.ProvNum = pat.PriProv; //just in case there's not AIG segment. //AIG is optional, but looks like the only way to get provider for the appt----------- //PV1 seems to frequently be sent instead of AIG. SegmentHL7 segAIG = message.GetSegment(SegmentName.AIG, false); SegmentHL7 segPV = message.GetSegment(SegmentName.PV1, false); if (segAIG != null) { long provNum = SegmentPID.ProvProcess(segAIG.GetField(3)); if (provNum != 0) { apt.ProvNum = provNum; pat.PriProv = provNum; } } else if (segPV != null) { long provNum = SegmentPID.ProvProcess(segPV.GetField(7)); if (provNum != 0) { apt.ProvNum = provNum; pat.PriProv = provNum; } } //AIL,AIP seem to be optional, and I'm going to ignore them for now. if (isNewPat) { if (isVerboseLogging) { EventLog.WriteEntry("OpenDentHL7", "Inserted patient: " + pat.FName + " " + pat.LName + ", PatNum:" + pat.PatNum.ToString() , EventLogEntryType.Information); } Patients.Insert(pat, true); } else { if (isVerboseLogging) { EventLog.WriteEntry("OpenDentHL7", "Updated patient: " + pat.FName + " " + pat.LName, EventLogEntryType.Information); } Patients.Update(pat, patOld); } if (isNewApt) { if (isVerboseLogging) { EventLog.WriteEntry("OpenDentHL7", "Inserted appointment for: " + pat.FName + " " + pat.LName, EventLogEntryType.Information); } Appointments.InsertIncludeAptNum(apt, true); } else { if (isVerboseLogging) { EventLog.WriteEntry("OpenDentHL7", "Updated appointment for: " + pat.FName + " " + pat.LName, EventLogEntryType.Information); } Appointments.Update(apt, aptOld); } }
public static void ProcessMessage(MessageHL7 message, bool isStandalone, bool isVerboseLogging) { /*string triggerevent=message.Segments[0].GetFieldComponent(8,1); * switch(triggerevent) { * case "A01"://Admit/Visit Information * * break; * case "A04"://New Patient Information * ProcessNewPatient(message); * break; * case "A08"://Update Patient Information * * break; * case "A28"://Add Patient Information * * break; * case "A31"://Update Patient Information * * break; * }*/ //MSH-Ignore //EVN-Ignore //PID------------------------------------- SegmentHL7 seg = message.GetSegment(SegmentName.PID, true); long patNum = PIn.Long(seg.GetFieldFullText(2)); Patient pat = null; if (isStandalone) { pat = Patients.GetPatByChartNumber(patNum.ToString()); if (pat == null) { //try to find the patient in question by using name and birthdate string lName = seg.GetFieldComponent(5, 0); string fName = seg.GetFieldComponent(5, 1); DateTime birthdate = SegmentPID.DateParse(seg.GetFieldFullText(7)); long patNumByName = Patients.GetPatNumByNameAndBirthday(lName, fName, birthdate); if (patNumByName == 0) //patient does not exist in OD //so pat will still be null, triggering creation of new patient further down. { } else { pat = Patients.GetPat(patNumByName); pat.ChartNumber = patNum.ToString(); //from now on, we will be able to find pat by chartNumber } } } else { pat = Patients.GetPat(patNum); } Patient patOld = null; bool isNewPat = pat == null; if (isNewPat) { pat = new Patient(); if (isStandalone) { pat.ChartNumber = patNum.ToString(); //this line does not work if isStandalone, so moved to end //pat.Guarantor=patNum; } else { pat.PatNum = patNum; pat.Guarantor = patNum; } pat.PriProv = PrefC.GetLong(PrefName.PracticeDefaultProv); pat.BillingType = PrefC.GetLong(PrefName.PracticeDefaultBillType); } else { patOld = pat.Copy(); } SegmentPID.ProcessPID(pat, seg, isStandalone); //PV1-patient visit--------------------------- //seg=message.GetSegment(SegmentName.PV1,false); //if(seg!=null) {//this seg is optional // SegmentPID.ProcessPV1(pat,seg); //} //PD1-additional patient demographics------------ //seg=message.GetSegment(SegmentName.PD1,false); //if(seg!=null) {//this seg is optional // ProcessPD1(pat,seg); //} //GT1-Guarantor------------------------------------- seg = message.GetSegment(SegmentName.GT1, true); SegmentPID.ProcessGT1(pat, seg, isStandalone); //IN1-Insurance------------------------------------- //List<SegmentHL7> segments=message.GetSegments(SegmentName.IN1); //for(int i=0;i<segments.Count;i++) { // ProcessIN1(pat,seg); //} if (isNewPat) { if (isVerboseLogging) { EventLog.WriteEntry("OpenDentHL7", "Inserted patient: " + pat.FName + " " + pat.LName, EventLogEntryType.Information); } Patients.Insert(pat, true); if (pat.Guarantor == 0) { patOld = pat.Copy(); pat.Guarantor = pat.PatNum; Patients.Update(pat, patOld); } } else { if (isVerboseLogging) { EventLog.WriteEntry("OpenDentHL7", "Updated patient: " + pat.FName + " " + pat.LName, EventLogEntryType.Information); } Patients.Update(pat, patOld); } }