Beispiel #1
0
        internal void SetACK(AckTypes ackType, String messageString, IMessage message)
        {
            if (message == null)
            {
                SetACK(ackType, messageString);
                return;
            }
            Terser   inboundTerser = new Terser(message);
            ISegment inboundHeader = inboundTerser.getSegment("MSH");

            string version = null;

            version = message.Version;
            if (string.IsNullOrEmpty(version))
            {
                try
                {
                    version = Terser.Get(inboundHeader, 12, 0, 1, 1);
                }
                catch (NHapi.Base.HL7Exception he)
                {
                    version = NHapi.Model.V251.Constants.VERSION;
                }
            }

            FillMSHSegment((ISegment)message.GetStructure("MSH"), (ISegment)hl7Ack.Message.GetStructure("MSH"));


            string messageTypeName = message.GetMessageType();
            string acktype         = HL7Parser.GetAckTypeFromRequest(messageTypeName, version);
            string AckID           = HL7Parser.GetMessageIDFromMessageType(acktype, version);

            hl7Ack.SetValue("/MSH(0)-21-1", AckID); //MEssage Code

            if (acktype.Split('_').Length > 1)
            {
                hl7Ack.SetValue("/MSH-9-1-1", acktype.Split('_')[0]); //MEssage Code
                hl7Ack.SetValue("/MSH-9-2-1", acktype.Split('_')[1]); //MEssage Code
            }
            //ackTerser.Set("/MSH-12", NHapi.Model.V251.Constants.VERSION);
            hl7Ack.SetValue("/MSA-1", Enum.GetName(typeof(AckTypes), ackType));

            string code = Terser.Get(inboundHeader, 10, 0, 1, 1);

            hl7Ack.SetValue("/MSA-2", Terser.Get(inboundHeader, 10, 0, 1, 1));
        }
Beispiel #2
0
        private ParserResult SystemExceptionHandler(Exception se, string messageString)
        {
            if (string.IsNullOrEmpty(messageString))
            {
                return(new ParserResult(null, null, false, null, se.Message));
            }

            //Do not handle configuration Exceptions
            if (se is ConfigurationException)
            {
                throw (ConfigurationException)se;
            }

            if (typeof(System.Configuration.ConfigurationException).IsAssignableFrom(se.GetType()))
            {
                throw (ConfigurationException)se;
            }

            _errorMessage.AppendLine(se.Message);

            if (se.InnerException != null)
            {
                _errorMessage.AppendLine(se.InnerException.Message);
            }

            string messageType = null;

            string version = null;

            ISegment criticalSegment = null;

            try
            {
                criticalSegment = TryToRecoverCriticalDataFromMessage(messageString);
                if (criticalSegment == null)
                {
                    version     = TryToRecoverTheVersion(messageString);
                    messageType = TryTorecoverTheMessageType(messageString);
                }
                else
                {
                    version     = Terser.Get(criticalSegment, 12, 0, 1, 1);
                    messageType = $"{Terser.Get(criticalSegment, 9, 0, 1, 1)}" +
                                  $"_{Terser.Get(criticalSegment, 9, 0, 2, 1)}";
                }

                if (messageType == null)
                {
                    return(new ParserResult(null, null, false, null, _errorMessage.ToString()));
                }

                //the messageType is not null!
                if (version == null)
                {
                    version = "2.5.1";
                }


                string responseType = HL7Parser.GetMessageIDFromMessageType(messageType, version);
                if (responseType == null)
                {
                    //the incoming message is an ack, the acknowledgment should not be aknoledged
                    return(new ParserResult(null, null, false, true, _errorMessage.ToString()));
                }


                hl7Ack = hl7Parser.InstantiateMessage(responseType, version);

                ISegment err = (ISegment)hl7Ack.Message.GetStructure("ERR", 0);
                if ((se.InnerException != null) && typeof(HL7Exception).IsAssignableFrom(se.InnerException.GetType()))
                {
                    HL7Exception he = (HL7Exception)se.InnerException;
                    he.populate(err);
                }

                //if (typeof(HL7Exception).IsAssignableFrom(se.GetType()))
                //{
                //    HL7Exception he = (HL7Exception)se;
                //    he.populate(err);
                //    Debug.Print((new PipeParser()).Encode(ack));
                //}

                SetACK(AckTypes.AR, messageString);
            }
            catch (Exception e)
            {
                _errorMessage.AppendLine(e.Message);
                return(new ParserResult(parsedMessage, hl7Ack, false, null, _errorMessage.ToString()));
            }
            return(new ParserResult(parsedMessage, hl7Ack, false, parsedMessage.IsAcknowledge, _errorMessage.ToString()));
        }
Beispiel #3
0
 public Validator(PipeParser contextParser, HL7Parser hl7Parser)
 {
     this.contextParser = contextParser;
     this.hl7Parser     = hl7Parser;
 }
Beispiel #4
0
 public Validator()
 {
     this.hl7Parser = new HL7Parser();
     contextParser  = new PipeParser();
 }