Exemplo n.º 1
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="sequenceNumber">Segment Sequence Number in HL7 message.</param>
 /// <param name="name">Enumerated Segment Name</param>
 public Hl7Segment(int sequenceNumber, Hl7SegmentEnum name)
 {
     _sequenceNumber = sequenceNumber;
     _segmentId      = new Hl7SegmentId(name);
     _values         = new ArrayList();
     System.String val = SegmentNames.Name(name);
     _values.Insert(0, val);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="sequenceNumber">Segment Sequence Number in HL7 message.</param>
 /// <param name="name">Enumerated Segment Name</param>
 public Hl7Segment(int sequenceNumber, Hl7SegmentEnum name)
 {
     _sequenceNumber = sequenceNumber;
     _segmentId = new Hl7SegmentId(name);
     _values = new ArrayList();
     System.String val = SegmentNames.Name(name);
     _values.Insert(0, val);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Set the value at the indexed segment.
        /// </summary>
        /// <param name="name">Segment Name.</param>
        /// <param name="fieldIndex">Field Index.</param>
        /// <param name="val">Field Value.</param>
        public void AddValue(Hl7SegmentEnum name, int fieldIndex, System.String val)
        {
            Hl7SegmentId segmentId  = new Hl7SegmentId(name);
            Hl7Segment   hl7Segment = (Hl7Segment)_segments[segmentId.Id];

            if (hl7Segment != null)
            {
                hl7Segment[fieldIndex] = val;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Set the OBX value given at the segment/field index.
        /// </summary>
        /// <param name="segmentIndex">OBX Segment Index.</param>
        /// <param name="fieldIndex">OBX Field Index (within Segment).</param>
        /// <param name="stringValue">Value to set.</param>
        public void obxSeg(int segmentIndex, int fieldIndex, System.String stringValue)
        {
            Hl7Segment segment = null;

            if (segmentIndex > 0)
            {
                Hl7SegmentId segmentId = new Hl7SegmentId(Hl7SegmentEnum.OBX, segmentIndex);
                segment = (Hl7Segment)Segments[segmentId.Id];
                if (segment == null)
                {
                    segment = new Hl7Segment(0, Hl7SegmentEnum.OBX);
                    segment.SegmentId.SegmentIndex = segmentIndex;
                    AddSegment(segment);
                }
            }
            segment[fieldIndex] = stringValue;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Decode the segment. The HL7 message delimiters has been set to the correct value before calling this method.
        /// </summary>
        /// <param name="segmentString">Encoded segment string.</param>
        /// <param name="messageDelimiters">HL7 message delimiters to use to encode the message.</param>
        public void Decode(System.String segmentString, Hl7MessageDelimiters messageDelimiters)
        {
            int index = 0;

            System.String val   = System.String.Empty;
            int           i     = 0;
            bool          isVal = false;

            while (i < segmentString.Length)
            {
                if (segmentString.Substring(i, 1) == messageDelimiters.FieldDelimiter)
                {
                    _values.Insert(index, val);
                    index++;

                    if ((index == 1) &&
                        ((System.String)_values[0] == "MSH"))
                    {
                        // special insert for the field delimiter itself.
                        _values.Insert(index, messageDelimiters.FieldDelimiter);
                        index++;
                    }

                    val   = System.String.Empty;
                    isVal = false;
                }
                else
                {
                    val  += segmentString[i];
                    isVal = true;
                }
                i++;
            }

            if (isVal == true)
            {
                _values.Insert(index, val);
            }

            if (_values.Count > 0)
            {
                // use segment index 0 here - the correct value will be determined when the segment is added to the message
                _segmentId = new Hl7SegmentId(SegmentNames.NameEnum((System.String)_values[0]), 0);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Class constructor.
 /// </summary>
 /// <param name="segment">Enumerated Segment Name.</param>
 /// <param name="fieldIndex">Zero-based segment field index.</param>
 public Hl7Tag(Hl7SegmentEnum segment, int fieldIndex)
 {
     _segmentId = new Hl7SegmentId(segment);
     _fieldIndex = fieldIndex;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Set the OBX value given at the segment/field index.
 /// </summary>
 /// <param name="segmentIndex">OBX Segment Index.</param>
 /// <param name="fieldIndex">OBX Field Index (within Segment).</param>
 /// <param name="stringValue">Value to set.</param>
 public void obxSeg(int segmentIndex, int fieldIndex, System.String stringValue)
 {
     Hl7Segment segment = null;
     if (segmentIndex > 0)
     {
         Hl7SegmentId segmentId = new Hl7SegmentId(Hl7SegmentEnum.OBX, segmentIndex);
         segment = (Hl7Segment)Segments[segmentId.Id];
         if (segment == null)
         {
             segment = new Hl7Segment(0, Hl7SegmentEnum.OBX);
             segment.SegmentId.SegmentIndex = segmentIndex;
             AddSegment(segment);
         }
     }
     segment[fieldIndex] = stringValue;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Set the value at the indexed segment.
 /// </summary>
 /// <param name="name">Segment Name.</param>
 /// <param name="fieldIndex">Field Index.</param>
 /// <param name="val">Field Value.</param>
 public void AddValue(Hl7SegmentEnum name, int fieldIndex, System.String val)
 {
     Hl7SegmentId segmentId = new Hl7SegmentId(name);
     Hl7Segment hl7Segment = (Hl7Segment)_segments[segmentId.Id];
     if (hl7Segment != null)
     {
         hl7Segment[fieldIndex] = val;
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Class constructor
 /// </summary>
 public Hl7Segment()
 {
     _sequenceNumber = 0;
     _segmentId = new Hl7SegmentId(Hl7SegmentEnum.Unknown);
     _values = new ArrayList();
 }
Exemplo n.º 10
0
        /// <summary>
        /// Decode the segment. The HL7 message delimiters has been set to the correct value before calling this method.
        /// </summary>
        /// <param name="segmentString">Encoded segment string.</param>
        /// <param name="messageDelimiters">HL7 message delimiters to use to encode the message.</param>
        public void Decode(System.String segmentString, Hl7MessageDelimiters messageDelimiters)
        {
            int index = 0;
            System.String val = System.String.Empty;
            int i = 0;
            bool isVal = false;
            while (i < segmentString.Length)
            {
                if (segmentString.Substring(i,1) == messageDelimiters.FieldDelimiter)
                {
                    _values.Insert(index, val);
                    index++;

                    if ((index == 1) &&
                        ((System.String)_values[0] == "MSH"))
                    {
                        // special insert for the field delimiter itself.
                        _values.Insert(index, messageDelimiters.FieldDelimiter);
                        index++;
                    }

                    val = System.String.Empty;
                    isVal = false;
                }
                else
                {
                    val += segmentString[i];
                    isVal = true;
                }
                i++;
            }

            if (isVal == true)
            {
                _values.Insert(index, val);
            }

            if (_values.Count > 0)
            {
                // use segment index 0 here - the correct value will be determined when the segment is added to the message
                _segmentId = new Hl7SegmentId(SegmentNames.NameEnum((System.String)_values[0]), 0);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Create a correctly typed HL7 message instance based on the incoming Hl7 message.
        /// </summary>
        /// <param name="inHl7Message">Incoming HL7 message.</param>
        /// <param name="messageDelimiters">HL7 message delimiters.</param>
        /// <returns>Correctly typed HL7 message instance.</returns>
        public static Hl7Message CreateHl7Message(Hl7Message inHl7Message, Hl7MessageDelimiters messageDelimiters)
        {
            Hl7SegmentId segmentId  = new Hl7SegmentId(Hl7SegmentEnum.MSH);
            Hl7Segment   mshSegment = (Hl7Segment)inHl7Message.Segments[segmentId.Id];

            // can not determine what kind of message we have - so return the inHl7Message
            if (mshSegment == null)
            {
                return(inHl7Message);
            }
            System.String messageType = mshSegment[9];

            Hl7Message hl7Message = null;

            // check for ACK message
            if (messageType == "ACK")
            {
                // now try to get the ORC segment
                segmentId = new Hl7SegmentId(Hl7SegmentEnum.ORC);
                Hl7Segment orcSegment = (Hl7Segment)inHl7Message.Segments[segmentId.Id];
                if (orcSegment != null)
                {
                    hl7Message = new OrrMessage();
                }
                else
                {
                    hl7Message = new AckMessage();
                }
            }
            else
            {
                System.String [] messageTypeComponent = new System.String[3];
                messageTypeComponent = messageType.Split(messageDelimiters.ComponentDelimiter[0]);
                System.String messageMainType = System.String.Empty;
                if (messageTypeComponent.Length > 0)
                {
                    messageMainType = messageTypeComponent[0];
                }

                switch (messageMainType)
                {
                case "ADR":
                    // ADR message
                    hl7Message = new AdrMessage();
                    break;

                case "ADT":
                    // ADT message
                    hl7Message = new AdtMessage();
                    break;

                case "ORM":
                    // ORM message
                    hl7Message = new OrmMessage();
                    break;

                case "ORU":
                    // ORU message
                    hl7Message = new OruMessage();
                    break;

                case "QRY":
                    // QRY message
                    hl7Message = new QryMessage();
                    break;

                default:
                    // do not know what kind of HL7 message this is - simply return it
                    return(inHl7Message);
                }
            }

            // add the segments from the inMessage to the new hl7Message
            ICollection segments = inHl7Message.Segments.Values;

            foreach (Hl7Segment segment in segments)
            {
                hl7Message.CopySegment(segment);
            }

            return(hl7Message);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Create a correctly typed HL7 message instance based on the incoming Hl7 message.
        /// </summary>
        /// <param name="inHl7Message">Incoming HL7 message.</param>
        /// <param name="messageDelimiters">HL7 message delimiters.</param>
        /// <returns>Correctly typed HL7 message instance.</returns>
        public static Hl7Message CreateHl7Message(Hl7Message inHl7Message, Hl7MessageDelimiters messageDelimiters)
        {
            Hl7SegmentId segmentId = new Hl7SegmentId(Hl7SegmentEnum.MSH);
            Hl7Segment mshSegment = (Hl7Segment)inHl7Message.Segments[segmentId.Id];

            // can not determine what kind of message we have - so return the inHl7Message
            if (mshSegment == null)
            {
                return inHl7Message;
            }
            System.String messageType = mshSegment[9];

            Hl7Message hl7Message = null;

            // check for ACK message
            if (messageType == "ACK")
            {
                // now try to get the ORC segment
                segmentId = new Hl7SegmentId(Hl7SegmentEnum.ORC);
                Hl7Segment orcSegment = (Hl7Segment)inHl7Message.Segments[segmentId.Id];
                if (orcSegment != null)
                {
                    hl7Message = new OrrMessage();
                }
                else
                {
                    hl7Message = new AckMessage();
                }
            }
            else
            {
                System.String []messageTypeComponent = new System.String[3];
                messageTypeComponent = messageType.Split(messageDelimiters.ComponentDelimiter[0]);
                System.String messageMainType = System.String.Empty;
                if (messageTypeComponent.Length > 0)
                {
                    messageMainType = messageTypeComponent[0];
                }

                switch (messageMainType)
                {
                    case "ADR" :
                        // ADR message
                        hl7Message = new AdrMessage();
                        break;
                    case "ADT" :
                        // ADT message
                        hl7Message = new AdtMessage();
                        break;
                    case "ORM" :
                        // ORM message
                        hl7Message = new OrmMessage();
                        break;
                    case "ORU" :
                        // ORU message
                        hl7Message = new OruMessage();
                        break;
                    case "QRY" :
                        // QRY message
                        hl7Message = new QryMessage();
                        break;
                    default:
                        // do not know what kind of HL7 message this is - simply return it
                        return inHl7Message;
                }
            }

            // add the segments from the inMessage to the new hl7Message
            ICollection segments = inHl7Message.Segments.Values;
            foreach (Hl7Segment segment in segments)
            {
                hl7Message.CopySegment(segment);
            }

            return hl7Message;
        }
Exemplo n.º 13
0
 /// <summary>
 /// Class constructor
 /// </summary>
 public Hl7Segment()
 {
     _sequenceNumber = 0;
     _segmentId      = new Hl7SegmentId(Hl7SegmentEnum.Unknown);
     _values         = new ArrayList();
 }