static void Main(string[] args) { const string customSegmentBasedHl7Message = "MSH|^~\\&|SUNS1|OVI02|AZIS|CMD|200606221348||ADT^A01|1049691900|P|2.3\r" + "EVN|A01|200803051509||||200803031508\r" + "PID|||5520255^^^PK^PK~ZZZZZZ83M64Z148R^^^CF^CF~ZZZZZZ83M64Z148R^^^SSN^SSN^^20070103^99991231~^^^^TEAM||ZZZ^ZZZ||19830824|F||||||||||||||||||||||N\r" + "ZPV|Some Custom Notes|Additional custom description of the visit goes here"; var enhancedModelClassFactory = new EnhancedModelClassFactory(); var pipeParser = new PipeParser(enhancedModelClassFactory); enhancedModelClassFactory.ValidationContext = pipeParser.ValidationContext; LogToDebugConsole("Attempting to parse message string into HL7 message object..."); var ourHl7Message = pipeParser.Parse(customSegmentBasedHl7Message); LogToDebugConsole("Parsed message into generic ADT_A01 message successfully..."); LogToDebugConsole("Unwrapping payload from our custom ADT_A01 message using GenericMessageWrapper class..."); var wrappedGenericMessage = ourHl7Message as GenericMessageWrapper; var originalMessage = wrappedGenericMessage?.Unwrap(); if (wrappedGenericMessage?.GetSegment <ISegment>("ZPV") != null) { LogToDebugConsole("Casting unwrapped payload into our custom ADT A01 class..."); //casting to our custom class and retrieving the custom segment within it var zpvSegment = ((NHapi.Model.CustomZSegments.Message.ADT_A01)originalMessage).ZPV; LogToDebugConsole($"Custom Notes retrieved from ZPV segment was -> {zpvSegment.CustomNotes.Value}"); LogToDebugConsole($"Custom Description retrieved from ZPV segment was -> {zpvSegment.CustomDescription.Value}"); LogToDebugConsole("Entire parse operation completed successfully..."); } }
private static void ZrtTest() { var txtMessage = "MSH|^~\\&|ABC|DEF|DAL|QUEST|20160907113230||ORM^O01^ORM_O01|201609071132304107|P|2.5.1\rPID|1||[PATIENTID]^^^^MR||[LASTNAME]^[FIRSTNAME]^M^^^^L|SMITH|[DOB]|[GENDER]||2106-3^White^HL70005|123 Main St.^^Fischer^TX^78623^USA^H||^PRN^PH^[email protected]^^704^5551212~^^CP^^^980^5551414|^PRN^PH^^^704^5551313|eng^English^ISO639|S^Single|||123-45-6789|||N^Not Hispanic or Latino^HL70189\rPV1|1|O|^^^ZZZZZ00002^^C^^^Bleeding Edge Trauma Center||||NPIDA^Allthework^Dew^^^Mr^PA^^^^^^NPI^^^^^^^^PA||||||||||||ZZZZZ000EJ^^^^VN|||||||||||||||||||||||||20110511132339-0400\rORC|SN|[PON]||||||||||^Jekyll^Burt^^^^^^NPI^L\rOBR||[PON]||87590^Neisseria gonorrhoeae detection by nucleic acid, direct probe^C4|||201609071108|||||||| ^^^ |^Jekyll^Burt^^^^^^NPI^L||||||||LAB\rDG1|1||I25700^Atherosclerosis of CABG, unsp, w unstable angina pectoris^ICD\rZRT|1|Inbound Processor - Prod|ConfigID=1406;MessageID=16971290;MessageType=ORM;LabOrderID=32271;PatientID=1234;|SPLINTER|"; var emch = new EnhancedModelClassFactory(); var parser = new PipeParser(emch); emch.ValidationContext = parser.ValidationContext; var genericIm = parser.Parse(txtMessage); if (genericIm is GenericMessageWrapper gcw) { var strictIm = gcw.Unwrap(); var structureName = strictIm.GetStructureName(); if (structureName.Contains("ORM_O01")) { var orm = (NHapi.Model.V251.Message.ORM_O01)strictIm; var sex = orm.PATIENT.PID.AdministrativeSex.Value; Console.WriteLine(sex); } XMLParser xmlParser = new DefaultXMLParser(); var xmlMessageStrict = xmlParser.Encode(strictIm); Console.WriteLine(xmlMessageStrict); var xmlMessageGeneric = xmlParser.Encode(genericIm); Console.WriteLine(xmlMessageGeneric); try { var zrt = gcw.GetSegment <ISegment>("ZRT"); //if (zrt is TestApp.CustomImplementation.V251.Segment.ZRT) //{ // Console.WriteLine("Got a ZRT!!!"); //} var numFields = zrt.NumFields(); for (var i = 1; i <= numFields; i++) { var field = zrt.GetField(i, 0); var value = ((Varies)field).Data; Console.WriteLine(value); } } catch (Exception e) { Console.WriteLine(e); } } }
private void init(IModelClassFactory factory) { EnhancedModelClassFactory fact = factory as EnhancedModelClassFactory; if (fact == null) { throw new ArgumentNullException("The GenericMessageWrapper only works with the EnhancedModelClassFactory"); } wrappedMessage = InstantiateMessage(fact); this.addNonstandardSegment("MSH"); }
private IMessage InstantiateMessage(EnhancedModelClassFactory factory) { wrappedMessageType = factory.GetSpecificMessageClass(); IMessage message = (IMessage)wrappedMessageType.GetConstructor(new Type[1] { typeof(IModelClassFactory) }).Invoke(new object[1] { (object)factory }); message.ValidationContext = factory.ValidationContext; return(message); }
public void CanOverrideSegments() { Console.WriteLine("\n==============================================\nTesting parsing to GenericMessageWrapper with different PID implementation (Repeating Alternate Patient ID)."); // Arrange var messageString = "MSH|^~\\&|EPIC|EPICADT|SMS|SMSADT|199912271408|CHARRIS|ADT^A01^ADT_A01|1817457|D|2.3|\rPID|0493575^^^2^ID 1|0493575^^^2^ID 1|454721|0493575^^^2^ID 1~0584484^^^3^ID 2~0584484^^^4^ID 4~0584484^^^5^ID 5|DOE^JOHN^^^^|DOE^JOHN^^^^|19480203|M||B|254 MYSTREET AVE^^MYTOWN^OH^44123^USA||(216)123-4567|||M|NON|400003403~1129086|\rNK1||ROE^MARIE^^^^|SPO||(216)123-4567||EC|||||||||||||||||||||||||||\rPV1||O|168~219^^^^^^^^^||||277^ALLEN MYLASTNAME^BONNIE^^^^|||||||||| ||2688684|||||||||||||||||||||||||199912271408||||||002376853"; var expectedRepetitions = 4; var classFactory = new EnhancedModelClassFactory(); var parser = new PipeParser(classFactory); classFactory.ValidationContext = parser.ValidationContext; var message = parser.Parse(messageString); // Act var messageWrapper = message as GenericMessageWrapper; Assert.NotNull(messageWrapper); var originalMessage = messageWrapper.Unwrap(); var pid = messageWrapper.GetSegment <ISegment>("PID"); var overriddenPid = pid as CustomPID; var segmentOverridden = pid is CustomPID; Assert.IsInstanceOf <CustomPID>(pid); var structure = originalMessage.GetStructureName(); Console.WriteLine( "Parsed {0} (V{1}). Custom PID implementation: {2}. Alternate Patient ID has {3} repetitions.\n", structure, originalMessage.Version, segmentOverridden, overriddenPid?.AlternatePatientIDRepetitionsUsed); Assert.AreEqual(expectedRepetitions, overriddenPid?.AlternatePatientIDRepetitionsUsed); var pid1 = ((ADT_A01)originalMessage).PID; var pid2 = overriddenPid; var comparer = new SegmentEqualityComparer(); Assert.True(comparer.Equals(pid1, pid2)); Console.WriteLine("Compare PID segments."); Console.WriteLine("PID from original message {0} custom PID.", pid1.IsEqual(pid2) ? "is the same as" : "isn't the same as"); Console.WriteLine("\nDone!"); }
public void CanParseCustomSegments() { Output.WriteLine("\n==============================================\nTesting parsing to GenericMessageWrapper with message which contains custom Z segment ZRT\n"); // Arrange var messageString = "MSH|^~\\&|ABC|DEF|DAL|QUEST|20160907113230||ORM^O01^ORM_O01|201609071132304107|P|2.5.1\rPID|1||[PATIENTID]^^^^MR||[LASTNAME]^[FIRSTNAME]^M^^^^L|SMITH|[DOB]|[GENDER]||2106-3^White^HL70005|123 Main St.^^Fischer^TX^78623^USA^H||^PRN^PH^[email protected]^^704^5551212~^^CP^^^980^5551414|^PRN^PH^^^704^5551313|eng^English^ISO639|S^Single|||123-45-6789|||N^Not Hispanic or Latino^HL70189\rPV1|1|O|^^^ZZZZZ00002^^C^^^Bleeding Edge Trauma Center||||NPIDA^Allthework^Dew^^^Mr^PA^^^^^^NPI^^^^^^^^PA||||||||||||ZZZZZ000EJ^^^^VN|||||||||||||||||||||||||20110511132339-0400\rORC|SN|[PON]||||||||||^Jekyll^Burt^^^^^^NPI^L\rOBR||[PON]||87590^Neisseria gonorrhoeae detection by nucleic acid, direct probe^C4|||201609071108|||||||| ^^^ |^Jekyll^Burt^^^^^^NPI^L||||||||LAB\rDG1|1||I25700^Atherosclerosis of CABG, unsp, w unstable angina pectoris^ICD\rZRT|1|Inbound Processor - Prod|ConfigID=1406;MessageID=16971290;MessageType=ORM;LabOrderID=32271;PatientID=1234;|SPLINTER|"; var expectedZrt = new [] { "1", "Inbound Processor - Prod", "ConfigID=1406;MessageID=16971290;MessageType=ORM;LabOrderID=32271;PatientID=1234;", "SPLINTER" }; var classFactory = new EnhancedModelClassFactory(); var parser = new PipeParser(classFactory); classFactory.ValidationContext = parser.ValidationContext; var message = parser.Parse(messageString); var messageWrapper = message as GenericMessageWrapper; Assert.NotNull(messageWrapper); var originalMessage = messageWrapper.Unwrap(); XMLParser xmlParser = new DefaultXMLParser(); var xmlMessageStrict = xmlParser.Encode(originalMessage); var xmlMessageGeneric = xmlParser.Encode(message); Assert.Matches(@"^\<ORM_O01.*\<\/ORM_O01\>$", xmlMessageStrict); Assert.Matches(@"^\<GenericMessageWrapper.*\<\/GenericMessageWrapper\>$", xmlMessageGeneric); var zrt = messageWrapper.GetSegment <ISegment>("ZRT"); var fieldCount = zrt.NumFields(); for (var i = 1; i <= fieldCount; i++) { var field = zrt.GetField(i, 0); var value = ((Varies)field).Data; Assert.Equal(expectedZrt[i - 1], value.ToString()); Output.WriteLine("{0}", value); } }
private static void TestGenericMessageWrapper() { Console.WriteLine("\n==============================================\nTesting parsing to GenericMessageWrapper with different PID implementation (Repeating Alternate Patient ID)."); var txtMessage = "MSH|^~\\&|EPIC|EPICADT|SMS|SMSADT|199912271408|CHARRIS|ADT^A01^ADT_A01|1817457|D|2.3|\rPID|0493575^^^2^ID 1|0493575^^^2^ID 1|454721|0493575^^^2^ID 1~0584484^^^3^ID 2~0584484^^^4^ID 4~0584484^^^5^ID 5|DOE^JOHN^^^^|DOE^JOHN^^^^|19480203|M||B|254 MYSTREET AVE^^MYTOWN^OH^44123^USA||(216)123-4567|||M|NON|400003403~1129086|\rNK1||ROE^MARIE^^^^|SPO||(216)123-4567||EC|||||||||||||||||||||||||||\rPV1||O|168~219^^^^^^^^^||||277^ALLEN MYLASTNAME^BONNIE^^^^|||||||||| ||2688684|||||||||||||||||||||||||199912271408||||||002376853"; var emch = new EnhancedModelClassFactory(); var parser = new PipeParser(emch); emch.ValidationContext = parser.ValidationContext; var im = parser.Parse(txtMessage); var gcw = im as GenericMessageWrapper; if (gcw != null) { var originalMessage = gcw.Unwrap(); var segmentOverridden = false; var pid = gcw.GetSegment <ISegment>("PID"); if (pid is CustomImplementation.V23.Segment.PID) { segmentOverridden = true; } var structure = originalMessage.GetStructureName(); if (segmentOverridden) { Console.WriteLine("Parsed {0} (V{1}). Custom PID implementation: {2}. Alternate Patient ID has {3} repetitions.", structure, originalMessage.Version, segmentOverridden, ((CustomImplementation.V23.Segment.PID)pid).AlternatePatientIDRepetitionsUsed); var pid1 = ((ADT_A01)originalMessage).PID; var pid2 = (CustomImplementation.V23.Segment.PID)pid; Console.WriteLine(""); Console.WriteLine("Compare PID segments."); Console.WriteLine("PID from original message {0} custom PID.", pid1.IsEqual(pid2) ? "is the same as" : "isn't the same as"); } else { Console.WriteLine("Parsed {0} (V{1}). Custom PID implementation: {2}.", structure, originalMessage.Version, segmentOverridden); } } Console.WriteLine("\nDone!"); }