private void OpenFile() { EmailAttach emailAttach = _listEmailAttachDisplayed[gridAttachments.SelectedIndices[0]]; string strFilePathAttach = FileAtoZ.CombinePaths(EmailAttaches.GetAttachPath(), emailAttach.ActualFileName); try { if (EhrCCD.IsCcdEmailAttachment(emailAttach)) { string strTextXml = FileAtoZ.ReadAllText(strFilePathAttach); if (EhrCCD.IsCCD(strTextXml)) { Patient patEmail = null; //Will be null for most email messages. if (_emailMessage.SentOrReceived == EmailSentOrReceived.ReadDirect || _emailMessage.SentOrReceived == EmailSentOrReceived.ReceivedDirect) { patEmail = _patCur; //Only allow reconcile if received via Direct. } string strAlterateFilPathXslCCD = ""; //Try to find a corresponding stylesheet. This will only be used in the event that the default stylesheet cannot be loaded from the EHR dll. for (int i = 0; i < _listEmailAttachDisplayed.Count; i++) { if (Path.GetExtension(_listEmailAttachDisplayed[i].ActualFileName).ToLower() == ".xsl") { strAlterateFilPathXslCCD = FileAtoZ.CombinePaths(EmailAttaches.GetAttachPath(), _listEmailAttachDisplayed[i].ActualFileName); break; } } FormEhrSummaryOfCare.DisplayCCD(strTextXml, patEmail, strAlterateFilPathXslCCD); return; } } else if (IsORU_R01message(strFilePathAttach)) { if (DataConnection.DBtype == DatabaseType.Oracle) { MsgBox.Show(this, "Labs not supported with Oracle. Opening raw file instead."); } else { FormEhrLabOrderImport FormELOI = new FormEhrLabOrderImport(); FormELOI.Hl7LabMessage = FileAtoZ.ReadAllText(strFilePathAttach); FormELOI.ShowDialog(); return; } } FileAtoZ.OpenFile(FileAtoZ.CombinePaths(EmailAttaches.GetAttachPath(), emailAttach.ActualFileName), emailAttach.DisplayedFileName); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
///<summary>Attempts to parse message and detects if it is an ORU_R01 HL7 message. Returns false if it fails, or does not detect message type.</summary> private bool IsORU_R01message(string strFilePathAttach) { if(Path.GetExtension(strFilePathAttach) != "txt") { return false; } try { string[] ArrayMSHFields=FileAtoZ.ReadAllText(strFilePathAttach).Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)[0].Split('|'); if(ArrayMSHFields[8]!="ORU^R01^ORU_R01") { return false; } } catch(Exception ex) { ex.DoNothing(); return false; } return true; }