コード例 #1
0
        public bool Match(IMessage message)
        {
            bool result = false;

            result = Compare(Hl7Version, message.Version);
            if (result)
            {
                // Dib0 20150125: Changed the compare. This method doesn't work with messages
                // that are parsed as generic messages
                //result = Compare(Structurename, message.GetStructureName());

                Terser terser      = new Terser(message);
                string messageType = string.Format("{0}_{1}", terser.Get("MSH-9-1"), terser.Get("MSH-9-2"));

                result = Compare(Structurename, messageType);
            }

            // Check the field filter
            if (result)
            {
                result = CheckFieldFilter(message);
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Create an Ack message based on a received message
        /// </summary>
        /// <param name="inboundMessage">received message</param>
        /// <param name="ackCode">Should be "AE" or "AR", can be "AA".</param>
        /// <param name="errorMessage">The reason the message was rejected or an error. If "AA" was supplied as ackCode the errorMessage should be null.</param>
        /// <returns>Created ACK message</returns>
        public static IMessage MakeACK(IMessage inboundMessage, string ackCode, string errorMessage)
        {
            IMessage ackMessage = null;
            // Get an object from the right ACK class
            string ackClassType = string.Format("NHapi.Model.V{0}.Message.ACK, NHapi.Model.V{0}", inboundMessage.Version.Remove(inboundMessage.Version.IndexOf('.'), 1));
            Type   x            = Type.GetType(ackClassType);

            ackMessage = (IMessage)Activator.CreateInstance(x);

            Terser   inboundTerser = new Terser(inboundMessage);
            ISegment inboundHeader = null;

            inboundHeader = inboundTerser.getSegment("MSH");

            // Find the HL7 version of the inbound message:
            //
            string version = null;

            try
            {
                version = Terser.Get(inboundHeader, 12, 0, 1, 1);
            }
            catch (NHapi.Base.HL7Exception)
            {
                // I'm not happy to proceed if we can't identify the inbound
                // message version.
                throw new NHapi.Base.HL7Exception("Failed to get valid HL7 version from inbound MSH-12-1");
            }

            // Create a Terser instance for the outbound message (the ACK).
            Terser terser = new Terser(ackMessage);

            // Populate outbound MSH fields using data from inbound message
            ISegment outHeader = (ISegment)terser.getSegment("MSH");

            DeepCopy.copy(inboundHeader, outHeader);

            // Now set the message type, HL7 version number, acknowledgement code
            // and message control ID fields:
            string sendingApp = terser.Get("/MSH-3");
            string sendingEnv = terser.Get("/MSH-4");

            terser.Set("/MSH-3", CommunicationName);
            terser.Set("/MSH-4", EnvironmentIdentifier);
            terser.Set("/MSH-5", sendingApp);
            terser.Set("/MSH-6", sendingEnv);
            terser.Set("/MSH-7", DateTime.Now.ToString("yyyyMMddmmhh"));
            terser.Set("/MSH-9", "ACK");
            terser.Set("/MSH-12", version);
            terser.Set("/MSA-1", ackCode == null ? "AA" : ackCode);
            terser.Set("/MSA-2", Terser.Get(inboundHeader, 10, 0, 1, 1));

            // Set error message
            if (errorMessage != null)
            {
                terser.Set("/ERR-7", errorMessage);
            }

            return(ackMessage);
        }
コード例 #3
0
        public void ProcessA01(string sHL7)
        {
            var parser        = new NHapi.Base.Parser.PipeParser();
            var parsedMessage = parser.Parse(sHL7);
            var a01           = parsedMessage as ADT_A01;

            string sPtName = "";

            //Terser terser;

            Terser terser = new Terser(parsedMessage);


            sPtName = terser.Get("/PID-5");
            string sFName = terser.Get("/PID-5-2");
            string sLName = terser.Get("/PID-5-1");

            //attempt parsing of a field that does not exist in transaction
            string sPatientID = terser.Get("/PID-1");

            Console.WriteLine("Patient First Name = {0}", sFName);
            Console.WriteLine("Patient Last Name = {0}", sLName);



            //var patientMR = a01.PID.PatientID.IDNumber.Value;
            //var patientAcctNo= a01.PID.PatientAccountNumber.IDNumber.Value;
            //var patientName = a01.PID.GetPatientName(0);
            //string sLName = patientName.FamilyName.Surname.Value;
            //string sFName = patientName.GivenName.Value;

            //Console.WriteLine("Patient FName = {0}", sFName);
        }
コード例 #4
0
        /// Create an Ack message based on a received message///
        /// received message///
        /// Acknowlegde code///
        /// Message to be created///
        /// Created message
        public string MakeACK(string AckHead, string version, string ackCode, IMessage ackMessage)
        {
            // Create a Terser instance for the outbound message (the ACK).
            Terser terser = new Terser(ackMessage);

            // Populate outbound MSH fields using data from inbound message


            // Now set the message type, HL7 version number, acknowledgement code
            // and message control ID fields:
            string sendingApp = terser.Get("/MSH-3");
            string sendingEnv = terser.Get("/MSH-4");
            string CommunicationNameOfThisApplication     = string.Empty;
            string EnvironmentIdentifierOfThisApplication = string.Empty;

            terser.Set("/MSH-3", CommunicationNameOfThisApplication);
            terser.Set("/MSH-4", EnvironmentIdentifierOfThisApplication);
            terser.Set("/MSH-5", sendingApp);
            terser.Set("/MSH-6", sendingEnv);
            terser.Set("/MSH-7", DateTime.Now.ToString("yyyyMMddmmhh"));
            terser.Set("/MSH-9", "ACK");
            terser.Set("/MSH-12", version);
            // The ackCode should be "AA" if the message was correctly handled and "AE" if there was an error
            terser.Set("/MSA-1", ackCode == null ? "AA" : ackCode);
            terser.Set("/MSA-2", AckHead);


            return(PipeParser.Encode(ackMessage, new EncodingCharacters('|', '^', '~', '\\', '&')));
        }
コード例 #5
0
        public static String GetHL7Event(String message)
        {
            var parser        = new NHapi.Base.Parser.PipeParser();
            var parsedMessage = parser.Parse(message);

            //Terse it!
            Terser terser = new Terser(parsedMessage);

            //Grab RequiredFields

            string sEventType   = terser.Get("/MSH-9-1");
            string sMessageType = terser.Get("/MSH-9-2");


            //Get the message type and trigger event
            var msgType = parsedMessage.GetStructureName();

            //Console.WriteLine("msg type = {0}", sMessageType); // = ADT_EVENT

            //Get the message in raw, pipe-delimited format
            var pipeDelimitedMessage = parser.Encode(parsedMessage);


            //Console.WriteLine("msg = {0}", pipeDelimitedMessage);

            return(sMessageType); //msgType; //pipeDelimitedMessage;
        }
コード例 #6
0
        public void Parse_UnknownMessageType_ReturnsGenericMessage(string version, Type expectedType)
        {
            // Arrange
            // a valid ORU_R01 message in which MSH-9 has been changed
            var input = $"MSH|^~\\&|LABGL1||DMCRES||19951002185200||ZZZ^ZZZ|LABGL1199510021852632|P|{version}\r"
                        + "PID|||T12345||TEST^PATIENT^P||19601002|M||||||||||123456\r"
                        + "PV1|||NER|||||||GSU||||||||E||||||||||||||||||||||||||19951002174900|19951006\r"
                        + "OBR|1||09527539437000040|7000040^ETHANOL^^^ETOH|||19951002180500|||||||19951002182500||||1793561||0952753943||19951002185200||100|F||^^^^^RT\r"
                        + "OBX||NM|7000040^ETHANOL^^^ETOH|0001|224|mg/dL|||||F|||19951002185200||182\r"
                        + "NTE|||          Reference Ranges\r" + "NTE|||          ****************\r"
                        + "NTE|||           Normal:              Negative\r"
                        + "NTE|||           Toxic Concentration: >80 mg/dL\r";

            var expectedMsh5 = "DMCRES";
            var expectedObx2 = "NM";

            var sut = new PipeParser();

            // Act
            var message = sut.Parse(input);

            sut.Encode(message);

            var terser = new Terser(message);

            // Assert
            Assert.AreEqual(expectedType, message.GetType());
            Assert.AreEqual(expectedMsh5, terser.Get("/MSH-5"));
            Assert.AreEqual(expectedObx2, terser.Get("/OBX-2"));
        }
コード例 #7
0
        /// <param name="message">a parsed message to validate (note that MSH-9-1 and MSH-9-2 must be valued).
        /// </param>
        /// <returns> true if the message is OK.
        /// </returns>
        /// <throws>  HL7Exception if there is at least one error and this validator is set to fail on errors. </throws>
        public virtual bool Validate(IMessage message)
        {
            var t     = new Terser(message);
            var rules = myContext.getMessageRules(message.Version, t.Get("MSH-9-1"), t.Get("MSH-9-2"));

            ValidationException toThrow = null;
            var result = true;

            for (var i = 0; i < rules.Length; i++)
            {
                var ex = rules[i].test(message);
                for (var j = 0; j < ex.Length; j++)
                {
                    result = false;
                    OurLog.Error("Invalid message", ex[j]);
                    if (failOnError && toThrow == null)
                    {
                        toThrow = ex[j];
                    }
                }
            }

            if (toThrow != null)
            {
                throw new HL7Exception("Invalid message", toThrow);
            }

            return(result);
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: dib0/NHapiExampleApp
        public static void MakeACK(ISegment inboundHeader, string ackCode, IMessage ackMessage, string errorMessage)
        {
            if (!inboundHeader.GetStructureName().Equals("MSH"))
            {
                throw new NHapi.Base.HL7Exception("Need an MSH segment to create a response ACK (got " + inboundHeader.GetStructureName() + ")");
            }

            // Find the HL7 version of the inbound message:
            string version = null;

            try
            {
                version = Terser.Get(inboundHeader, 12, 0, 1, 1);
            }
            catch (NHapi.Base.HL7Exception)
            {
                // I'm not happy to proceed if we can't identify the inbound
                // message version.
                throw new NHapi.Base.HL7Exception("Failed to get valid HL7 version from inbound MSH-12-1");
            }

            // Create a Terser instance for the outbound message (the ACK).
            Terser terser = new Terser(ackMessage);

            // Populate outbound MSH fields using data from inbound message
            ISegment outHeader = (ISegment)terser.getSegment("MSH");

            DeepCopy.copy(inboundHeader, outHeader);

            // Now set the message type, HL7 version number, acknowledgement code
            // and message control ID fields:
            string sendingApp = terser.Get("/MSH-3");
            string sendingEnv = terser.Get("/MSH-4");

            // Make sure you fill the MSH-3 and MSH-4 with the correct values
            // for you application, preferably with configuration
            terser.Set("/MSH-3", "HL7Client");
            terser.Set("/MSH-4", "EnvironmentIdentifier");
            terser.Set("/MSH-5", sendingApp);
            terser.Set("/MSH-6", sendingEnv);
            terser.Set("/MSH-7", DateTime.Now.ToString("yyyyMMddmmhh"));
            terser.Set("/MSH-9", "ACK");
            terser.Set("/MSH-12", version);
            terser.Set("/MSA-1", ackCode == null ? "AA" : ackCode);
            terser.Set("/MSA-2", Terser.Get(inboundHeader, 10, 0, 1, 1));

            // Set error message
            if (errorMessage != null)
            {
                terser.Set("/ERR-7", errorMessage);
            }
        }
コード例 #9
0
        public static IMessage MakeACK(ISegment inboundHeader, string ackCode)
        {
            if (!inboundHeader.GetStructureName().Equals("MSH"))
            {
                throw new NHapi.Base.HL7Exception(
                          "Need an MSH segment to create a response ACK (got " + inboundHeader.GetStructureName() + ")");
            }

            // Find the HL7 version of the inbound message:
            //
            string version = null;

            try
            {
                version = Terser.Get(inboundHeader, 12, 0, 1, 1);
            }
            catch (NHapi.Base.HL7Exception)
            {
                // I'm not happy to proceed if we can't identify the inbound
                // message version.
                throw new NHapi.Base.HL7Exception("Failed to get valid HL7 version from inbound MSH-12-1");
            }

            IMessage ackMessage = new ACK();
            // Create a Terser instance for the outbound message (the ACK).
            Terser terser = new Terser(ackMessage);

            // Populate outbound MSH fields using data from inbound message
            ISegment outHeader = (ISegment)terser.getSegment("MSH");

            DeepCopy.copy(inboundHeader, outHeader);

            // Now set the message type, HL7 version number, acknowledgement code
            // and message control ID fields:
            string sendingApp = terser.Get("/MSH-3");
            string sendingEnv = terser.Get("/MSH-4");

            terser.Set("/MSH-3", CommunicationName);
            terser.Set("/MSH-4", EnvironmentIdentifier);
            terser.Set("/MSH-5", sendingApp);
            terser.Set("/MSH-6", sendingEnv);
            terser.Set("/MSH-7", DateTime.Now.ToString("yyyyMMddmmhh"));
            terser.Set("/MSH-9", "ACK");
            terser.Set("/MSH-12", version);
            terser.Set("/MSA-1", ackCode == null ? "AA" : ackCode);
            terser.Set("/MSA-2", Terser.Get(inboundHeader, 10, 0, 1, 1));

            return(ackMessage);
        }
コード例 #10
0
ファイル: TerserTests.cs プロジェクト: nHapiNET/nHapi
        public void TestPatientId()
        {
            var msgString = "MSH|^~\\&|XYZ|a1510aae-cbcd-43d0-b0e2-4ad082f03775|HU|7d15ac56-8b12-4a07-8b10-3d2ae367f407|20100831104406||RSP^K23|20100831104406208095|P|2.5\r"
                            + "MSA|AA|20100831104406208095\r"
                            + "QAK||OK\r"
                            + "QPD|QRY_1001^Query for Corresponding Identifiers^ICDO|QRY10502106|QBPQ231176^^^57f31a9b-8eff-4736-84c4-6fafd6f25039\r"
                            + "PID|||QBPQ231177^^^DD95666A-76BA-444E-8FE8-C4E6BFC83E2D";

            var qryMsg   = (RSP_K23) new PipeParser().Parse(msgString);
            var terser   = new Terser(qryMsg);
            var expected = "QBPQ231177";

            Assert.AreEqual(expected, terser.Get("/.PID-3-1"));
            Assert.AreEqual(expected, terser.Get("/QUERY_RESPONSE(0)/.PID-3-1"));
        }
コード例 #11
0
ファイル: Validator.cs プロジェクト: Oliamster/HL7Interface
        private void FillMSHSegment(ISegment mshIn, ISegment mshOut)
        {
            if (mshOut == null)
            {
                throw new System.Exception("mshout");
            }

            Guid g = Guid.NewGuid();

            Terser.Set(mshIn, 7, 0, 1, 1, DateTime.Now.ToString("yyyyMMddHHmmss"));
            Terser.Set(mshIn, 7, 0, 1, 1, DateTime.Now.ToString("yyyyMMddHHmmss"));

            if (mshIn == null)
            {
                Terser.Set(mshIn, 3, 0, 1, 1, "");
                Terser.Set(mshIn, 4, 0, 1, 1, "");
                Terser.Set(mshIn, 5, 0, 1, 1, "");
                Terser.Set(mshIn, 6, 0, 1, 1, "");
                Terser.Set(mshIn, 9, 0, 1, 1, "ACK");
            }
            else
            {
                Terser.Set(mshIn, 3, 0, 1, 1, Terser.Get(mshIn, 5, 0, 1, 1));
                Terser.Set(mshIn, 4, 0, 1, 1, Terser.Get(mshIn, 6, 0, 1, 1));
                Terser.Set(mshIn, 5, 0, 1, 1, Terser.Get(mshIn, 3, 0, 1, 1));
                Terser.Set(mshIn, 6, 0, 1, 1, Terser.Get(mshIn, 4, 0, 1, 1));
                Terser.Set(mshIn, 9, 0, 1, 1, Terser.Get(mshIn, 9, 0, 1, 1));
                Terser.Set(mshIn, 9, 0, 2, 1, Terser.Get(mshIn, 9, 0, 2, 1));
            }
        }
コード例 #12
0
        public override bool Send(IMessage msg)
        {
            bool result = true;

            EditMessageHeader(msg);

            try
            {
                PipeParser    parser     = new PipeParser();
                string        res        = SendRequest(parser.Encode(msg));
                IMessage      response   = parser.Parse(res);
                HLMessageToDB hl7message = new HLMessageToDB();
                hl7message.HL7MessageToDB(Convert.ToString(msg));
                Terser terser  = new Terser(response);
                string ackCode = terser.Get("/MSA-1");
                result = (ackCode == "AA");
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("Error in delivering message '{0}' to Http endpoint with uri '{1}'. Error: {2}", msg.GetStructureName(), serverUri, ex.Message);
                result = false;
            }

            return(result);
        }
コード例 #13
0
ファイル: TerserTests.cs プロジェクト: nHapiNET/nHapi
        public void TestMultiArg()
        {
            var msh  = suiS12.MSH;
            var test = Terser.Get(msh, 9, 0, 2, 1);

            Assert.AreEqual("a", test);
        }
コード例 #14
0
ファイル: TerserTests.cs プロジェクト: nHapiNET/nHapi
        public void Get_RepIsLessThan0_ThrowsArgumentOutOfRangeException()
        {
            var segment = suiS12.MSH;

            Assert.Throws <ArgumentOutOfRangeException>(
                () => Terser.Get(segment, 0, -1, 0, 0));
        }
コード例 #15
0
        internal IHL7Message DoParse(IMessage message)
        {
            if (message == null)
            {
                throw new HL7apiException("Cannot parse an invalid message");
            }

            IHL7Message ret = null;

            Terser t = new Terser(message);


            string messageID = t.Get("/MSH-21(0)-1-1");

            if (string.IsNullOrEmpty(messageID))
            {
                messageID = GetMessageIDFromMessageType(message.GetMessageType(), message.Version);
                if (string.IsNullOrEmpty(messageID))
                {
                    throw new HL7apiException("Invalid Message type");
                }
            }

            ret = (IHL7Message)InstantiateMessage(messageID, message.Version, message);

            return(ret);
        }
コード例 #16
0
        /// <summary>
        ///实现处理的接口
        /// </summary>
        /// <param name="message">传入的消息字符</param>
        /// <returns></returns>
        public string Process(string message)
        {
            IMessage m = null;

            try
            {
                m = parser.Parse(message);
            }
            catch (Exception ex)
            {
                //MediII.Common.LogHelper.LogError(string.Format("消息消息失败,传入消息为:\n\r{0}",message),LogCatagories.AdapterBiz);
                string sendingApp = System.Configuration.ConfigurationManager.AppSettings["SedingApplication"];
                string recvApp    = "MediII";
                string ackMsg     = MediII.Common.MessageHelper.SetACK("ACK", "", "", sendingApp, sendingApp,
                                                                       recvApp, recvApp, "123456789", ex.Message);
                return(ackMsg);
            }
            ISegment msh       = (ISegment)m.GetStructure("MSH");
            string   messageID = Terser.Get(msh, 10, 0, 1, 1);
            string   guid      = MediII.Common.GUIDHelper.NewGUID();

            OnProcessing(guid, messageID, message);
            string ack = DoProcess(m);

            OnProcessed(guid, parser.GetAckID(ack), ack, true);
            return(ack);
        }
コード例 #17
0
        public void UnEscapesData()
        {
            // Arrange
            const string content = @"MSH|^~\&|TestSys|432^testsys practice|TEST||201402171537||MDM^T02|121906|P|2.3.1||||||||
OBX|1|TX|PROBLEM FOCUSED^PROBLEM FOCUSED^test|1|\T\#39;Thirty days have September,\X000d\April\X0A\June,\X0A\and November.\X0A\When short February is done,\E\X0A\E\all the rest have\T\nbsp;31.\T\#39";

            var parser = new PipeParser();
            var msg    = parser.Parse(content);


            // Act
            var segment     = msg.GetStructure("OBX") as ISegment;
            var idx         = Terser.getIndices("OBX-5");
            var segmentData = Terser.Get(segment, idx[0], idx[1], idx[2], idx[3]);

            // Assert

            // verify that data was properly unescaped by NHapi
            // \E\X0A\E\ should be escaped to \X0A\
            // \X0A\ should be unescaped to \n
            // \X000d\ should be unescaped to \r
            // \t\ should be unescaped to &


            const string expectedResult =
                "&#39;Thirty days have September,\rApril\nJune,\nand November.\nWhen short February is done,\\X0A\\all the rest have&nbsp;31.&#39";

            Assert.AreEqual(expectedResult, segmentData);
        }
コード例 #18
0
ファイル: Validator.cs プロジェクト: Oliamster/HL7Interface
        private void SetACK(AckTypes ackType, String messageString)
        {
            Terser   terser          = new Terser(hl7Ack.Message);
            ISegment err             = terser.getSegment("/ERR(0)");
            ISegment criticalSegment = TryToRecoverCriticalDataFromMessage(messageString);


            try
            {
                FillMSHSegment((ISegment)hl7Ack.Message.GetStructure("MSH"), criticalSegment);

                if (criticalSegment == null)
                {
                    terser.Set("/MSA-1", Enum.GetName(typeof(AckTypes), ackType));
                    terser.Set("/MSA-2", "");
                }
                else
                {
                    terser.Set("/MSA-1", Enum.GetName(typeof(AckTypes), ackType));
                    terser.Set("/MSA-2", Terser.Get(criticalSegment, 10, 0, 1, 1));
                }
            }
            catch (HL7Exception he)
            {
                _errorMessage.Append(he.Message);
                return; //do not throw exceptions;
            }
            //terser.Set("ERR(0)-7", _errorMessage);
            terser.Set("/ERR(0)-7-1-1", _errorMessage.ToString());
        }
コード例 #19
0
        /// <summary>
        /// Test
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public override ValidationException[] test(NHapi.Base.Model.IMessage msg)
        {
            ValidationException[] result = new ValidationException[0];

            foreach (MessageFieldMandatoryRuleElement rule in mandatoryRules)
            {
                bool flag1 = (rule.Version == "*") || (msg.Version == rule.Version);

                string   structureName = msg.GetStructureName();
                string[] sNames        = structureName.Split('_');
                bool     flag2         = (rule.MessageType == "*") || (sNames[0] == rule.MessageType);
                bool     flag3         = (rule.TriggerEvent == "*") || (sNames[1] == rule.TriggerEvent);

                if (flag1 && flag2 && flag3)
                {
                    Terser terser = new Terser(msg);
                    string value  = terser.Get(rule.FieldIndicator);
                    if (string.IsNullOrEmpty(value))
                    {
                        result = new ValidationException[1] {
                            new ValidationException(string.Format("Field '{1}' is mandatory.", value, rule.FieldIndicator))
                        };
                    }
                }

                if (result.Length > 0)
                {
                    break;
                }
            }

            return(result);
        }
コード例 #20
0
        private EncodingCharacters GetValidEncodingCharacters(char fieldSep, ISegment msh)
        {
            var encCharString = Terser.Get(msh, 2, 0, 1, 1);

            if (encCharString == null)
            {
                // cdc: This was breaking when trying to construct a blank message, and there is no way to set the EncChars, so fill in a default
                // throw new HL7Exception("Can't encode message: MSH-2 (encoding characters) is missing");
                encCharString = @"^~\&";
                Terser.Set(msh, 2, 0, 1, 1, encCharString);
            }

            var version27 = "2.7";

            if (string.CompareOrdinal(version27, msh.Message.Version) > 0 && encCharString.Length != 4)
            {
                throw new HL7Exception(
                          $"Encoding characters (MSH-2) value '{encCharString}' invalid -- must be 4 characters", ErrorCode.DATA_TYPE_ERROR);
            }

            if (encCharString.Length != 4 && encCharString.Length != 5)
            {
                throw new HL7Exception(
                          $"Encoding characters (MSH-2) value '{encCharString}' invalid -- must be 4 or 5 characters", ErrorCode.DATA_TYPE_ERROR);
            }

            return(new EncodingCharacters(fieldSep, encCharString));
        }
コード例 #21
0
        public static string GetMessageType(this IMessage message)
        {
            ISegment msh         = (ISegment)message.GetStructure("MSH");
            string   messageType = $"{Terser.Get(msh, 9, 0, 1, 1)}" +
                                   $"_{Terser.Get(msh, 9, 0, 2, 1)}";

            return(messageType);
        }
コード例 #22
0
        /// <summary>
        /// Create an MSH in the specified terser
        /// </summary>
        public static void UpdateMSH(Terser terser, IMessage inboundMsh, ISystemConfigurationService config)
        {
            Terser inboundTerser = new Terser(inboundMsh);

            terser.Set("/MSH-10", Guid.NewGuid().ToString());
            terser.Set("/MSH-3", config.DeviceName);
            terser.Set("/MSH-4", config.JurisdictionData.Name);
            terser.Set("/MSH-5", inboundTerser.Get("/MSH-3"));
            terser.Set("/MSH-6", inboundTerser.Get("/MSH-4"));
            terser.Set("/MSH-7", DateTime.Now.ToString("yyyyMMddHHmm"));
            terser.Set("/MSA-2", inboundTerser.Get("/MSH-10"));
            if (String.IsNullOrEmpty(terser.Get("/MSH-9-2")))
            {
                terser.Set("/MSH-9-2", inboundTerser.Get("/MSH-9-2"));
            }
            terser.Set("/MSH-11", inboundTerser.Get("/MSH-11"));
        }
コード例 #23
0
        public override bool Send(IMessage msg)
        {
            EditMessageHeader(msg);
            IMessage response = mllpClient.SendHL7Message(msg);

            Terser terser  = new Terser(response);
            string ackCode = terser.Get("/MSA-1");

            return(ackCode == "AA");
        }
コード例 #24
0
ファイル: OurTerserHelper.cs プロジェクト: cprafael10/HL7
        public string GetData(string terserExpression)
        {
            if (string.IsNullOrEmpty(terserExpression))
            {
                throw new ArgumentNullException(nameof(terserExpression),
                                                "Terser expression must be supplied for data retrieval operation");
            }

            return(_terser.Get(terserExpression));
        }
コード例 #25
0
        /// <summary>
        /// Adds a method to check equality between to message objects
        /// </summary>
        /// <param name="a">First message</param>
        /// <param name="b">Second message</param>
        /// <param name="completeCompare">Besides checking the structure name, version, event type and message ID, if this is true the complete textual version of the two messages will be compared.</param>
        /// <returns>True if the messages are equal</returns>
        public static bool IsEqual(this IMessage a, IMessage b, bool completeCompare)
        {
            bool result = true;

            if (a.GetStructureName() != b.GetStructureName())
            {
                result = false;
            }

            if (result && (a.Version != b.Version))
            {
                result = false;
            }

            if (result)
            {
                Terser terserA = new Terser(a);
                Terser terserB = new Terser(b);

                string eventTypeA = terserA.Get("MSH-9-2");
                string eventTypeB = terserB.Get("MSH-9-2");
                result = (eventTypeA == eventTypeB);

                if (result)
                {
                    string messageIdA = terserA.Get("MSH-10-1");
                    string messageIdB = terserB.Get("MSH-10-1");
                    result = (messageIdA == messageIdB);
                }
            }

            if (result && completeCompare)
            {
                PipeParser p    = new PipeParser();
                string     msgA = p.Encode(a);
                string     msgB = p.Encode(b);

                result = (string.Compare(msgA, msgB) == 0);
            }

            return(result);
        }
コード例 #26
0
ファイル: HL7Message.cs プロジェクト: Oliamster/HL7Interface
 public string GetValue(string path)
 {
     try
     {
         return(m_Terser.Get(path));
     }
     catch (HL7Exception he)
     {
         throw new HL7apiException($"Unable to get value form path: {path}", he);
     }
 }
コード例 #27
0
        /// <inheritdoc />
        protected internal override string DoEncode(IMessage source)
        {
            // get encoding characters ...
            var msh            = (ISegment)source.GetStructure("MSH");
            var fieldSepString = Terser.Get(msh, 1, 0, 1, 1);

            if (fieldSepString == null)
            {
                // cdc: This was breaking when trying to construct a blank message, and there is no way to set the fieldSeperator, so fill in a default
                // throw new HL7Exception("Can't encode message: MSH-1 (field separator) is missing");
                fieldSepString = "|";
                Terser.Set(msh, 1, 0, 1, 1, fieldSepString);
            }

            var fieldSep = fieldSepString.Length > 0
                ? fieldSepString[0]
                : '|';

            var encodingCharacters = GetValidEncodingCharacters(fieldSep, msh);

            var version = Terser.Get(msh, 12, 0, 1, 1);

            if (version == null)
            {
                // Put in the message version
                Terser.Set(msh, 12, 0, 1, 1, source.Version);
            }

            var msgStructure = Terser.Get(msh, 9, 0, 1, 1);

            if (msgStructure == null)
            {
                // Create the MsgType and Trigger Event if not there
                var messageTypeFullname = source.GetStructureName();
                var i = messageTypeFullname.IndexOf("_");
                if (i > 0)
                {
                    var type         = messageTypeFullname.Substring(0, i);
                    var triggerEvent = messageTypeFullname.Substring(i + 1);
                    Terser.Set(msh, 9, 0, 1, 1, type);
                    Terser.Set(msh, 9, 0, 2, 1, triggerEvent);
                }
                else
                {
                    Terser.Set(msh, 9, 0, 1, 1, messageTypeFullname);
                }
            }

            // pass down to group encoding method which will operate recursively on
            // children ...
            return(Encode(source, encodingCharacters));
        }
コード例 #28
0
        public ValidationException[] test(IMessage msg)
        {
            var validationResults = new ValidationException[0];
            var terser            = new Terser(msg);
            var value             = terser.Get("EVN-4");

            if (string.IsNullOrEmpty(value))
            {
                validationResults = new[] { new ValidationException(Description) };
            }

            return(validationResults);
        }
コード例 #29
0
        public void Step10()
        {
            IMessage request = ResourceUtil.GetRequestMessage("OHIE-CR-01-10");

            base.SetRequestMessageParams(request);
            IMessage response     = this.m_handler.HandleMessage(new Hl7MessageReceivedEventArgs(request, new Uri("http://anonymous"), new Uri("llp://test"), DateTime.Now));
            Terser   assertTerser = new Terser(response);

            Assert.IsTrue(new List <String>()
            {
                "AE", "AR"
            }.Contains(assertTerser.Get("/MSA-1")), "Receiver did not respond with AE or AR");

            // Assertion
        }
コード例 #30
0
        private bool CheckFieldFilter(IMessage message)
        {
            bool result = true;

            if (string.IsNullOrWhiteSpace(FieldFilter) && string.IsNullOrWhiteSpace(FieldFilterValue))
            {
                return(result);
            }

            Terser terser        = new Terser(message);
            string msgFieldValue = terser.Get(FieldFilter);

            result = Compare(FieldFilterValue, msgFieldValue);

            return(result);
        }