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(SegmentNameHL7.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 = EcwSegmentPID.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(); } List <PatientRace> listPatRaces = new List <PatientRace>(); bool hasNoRaceInStandalone = (isStandalone && (pat == null || pat.PatNum == 0)); EcwSegmentPID.ProcessPID(pat, seg, isStandalone, listPatRaces); //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(SegmentNameHL7.GT1, true); EcwSegmentPID.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 (pat.FName == "" || pat.LName == "") { EventLog.WriteEntry("OpenDentHL7", "Patient demographics not processed due to missing first or last name. PatNum:" + pat.PatNum.ToString() , EventLogEntryType.Information); return; } if (isNewPat) { if (isVerboseLogging) { EventLog.WriteEntry("OpenDentHL7", "Inserted patient: " + pat.FName + " " + pat.LName, EventLogEntryType.Information); } pat.PatNum = Patients.Insert(pat, !isStandalone); //use existing PK if not standalone, standalone will have PatNum=0, so set PatNum here SecurityLogs.MakeLogEntry(Permissions.PatientCreate, pat.PatNum, "Created from HL7 for eCW.", LogSources.HL7); if (hasNoRaceInStandalone) { Patient patientRaceTemp = pat.Copy(); //Make a deep copy so that we do not accidentally override something. seg = message.GetSegment(SegmentNameHL7.PID, true); //We have to process the PID again in order to correct the patient race. Patient race(s) will automatically get inserted if needed. EcwSegmentPID.ProcessPID(patientRaceTemp, seg, isStandalone, listPatRaces); } 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); } //had to move this reconcile here since we might not have a PatNum for new patients until after the insert PatientRaces.Reconcile(pat.PatNum, listPatRaces); }
public static void ProcessMessage(MessageHL7 message, bool isVerboseLogging) { SegmentHL7 seg = message.GetSegment(SegmentNameHL7.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(); } List <PatientRace> listPatRaces = new List <PatientRace>(); EcwSegmentPID.ProcessPID(pat, seg, false, listPatRaces); //IsStandalone=false because should never make it this far. //PV1-patient visit--------------------------- //seg=message.GetSegment(SegmentName.PV1,false); //if(seg!=null) { // SegmentPID.ProcessPV1(pat,seg); //} //SCH- Schedule Activity Information seg = message.GetSegment(SegmentNameHL7.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.Copy(); } 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(SegmentNameHL7.AIG, false); SegmentHL7 segPV = message.GetSegment(SegmentNameHL7.PV1, false); if (segAIG != null) { long provNum = EcwSegmentPID.ProvProcess(segAIG.GetField(3)); if (provNum != 0) { apt.ProvNum = provNum; pat.PriProv = provNum; } } else if (segPV != null) { long provNum = EcwSegmentPID.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 (pat.FName == "" || pat.LName == "") { EventLog.WriteEntry("OpenDentHL7", "Appointment not processed due to missing patient first or last name. PatNum:" + pat.PatNum.ToString() , EventLogEntryType.Information); return; //this will also skip the appt insert. } if (isNewPat) { if (isVerboseLogging) { EventLog.WriteEntry("OpenDentHL7", "Inserted patient: " + pat.FName + " " + pat.LName + ", PatNum:" + pat.PatNum.ToString() , EventLogEntryType.Information); } Patients.Insert(pat, true); SecurityLogs.MakeLogEntry(Permissions.PatientCreate, pat.PatNum, "Created from HL7 for eCW.", LogSources.HL7); } else { if (isVerboseLogging) { EventLog.WriteEntry("OpenDentHL7", "Updated patient: " + pat.FName + " " + pat.LName, EventLogEntryType.Information); } Patients.Update(pat, patOld); } //had to move this reconcile here since we might not have a PatNum for new patients until after the insert PatientRaces.Reconcile(pat.PatNum, listPatRaces); 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(SegmentNameHL7.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 = EcwSegmentPID.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(); } EcwSegmentPID.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(SegmentNameHL7.GT1, true); EcwSegmentPID.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 (pat.FName == "" || pat.LName == "") { EventLog.WriteEntry("OpenDentHL7", "Patient demographics not processed due to missing first or last name. PatNum:" + pat.PatNum.ToString() , EventLogEntryType.Information); return; } 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); } }