Пример #1
0
        /// <summary>
        /// Creates an instance of a HL7 Message
        /// </summary>
        /// <param name="mesg"></param>
        public HL7Message(string mesg)
        {
            if (mesg.Length < 8)
            {
                throw new ArgumentException("Not a complete HL7 message");
            }
            var mesgHeader = mesg.Substring(0, 8);

            if (mesgHeader.Length < 8)
            {
                throw new ArgumentException("Not a valid HL7 message");
            }

            _segments = new HL7Element(mesg, '\r', ValidatedSeparators(mesgHeader), null);
        }
Пример #2
0
        /// <summary>
        /// Creates an instance of a HL7 Message
        /// </summary>
        /// <param name="mesg"></param>
        public HL7Message(string mesg)
        {
            if (mesg.Length < 8)
            {
                throw new ArgumentException("Not a complete HL7 message");
            }
            var mesgHeader = mesg.Substring(0, 8);

            if (mesgHeader.Length < 8)
            {
                throw new ArgumentException("Not a valid HL7 message");
            }
            var lineEndings = mesg.LineEnding();
            var separators  = ValidatedSeparators(mesgHeader);

            if (lineEndings.Length > 0)
            {
                separators = lineEndings[0] + separators.Substring(1);
            }

            _segments = new HL7Element(mesg, separators[0], separators, null);
        }
Пример #3
0
 public int SetField(int index, HL7Element value)
 {
     return(this.SetElement(value, index) - 1);
 }
Пример #4
0
 public HL7Segment(string data, char separator, string separators = Constants.Separators, HL7Element owner = null)
 {
     AddStringElements(data, separator, separators, owner);
 }
Пример #5
0
        /// <summary>
        /// Returns a specific field based on selection Criteria
        /// NOTE: Selection Criteria can be a string such as "MSH.1.16[2]" or an array of Selection Criteria Elements
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public HL7Element Element(SearchCriteria criteria)
        {
            var nullSegment = new HL7Element("", '|');

            // Locate required Segment
            if (criteria == null || criteria.Segment == null)
            {
                return(null);
            }
            var segmentElements = AllSegments(criteria.Segment);
            var targetRow       = (criteria.SegmentRepetition > 0) ? criteria.SegmentRepetition - 1 : 0;

            if (targetRow > segmentElements.Count - 1)
            {
                return(nullSegment);                                       // not found;
            }
            var result = segmentElements[targetRow];

            //Field
            // Does the position need a header Ajustment (Eg MSH,BHS, FSH)
            if (!criteria.Field.Enabled)
            {
                return(segmentElements[targetRow]);                          //wants only the full segment
            }
            var headerAdjustment = (Constants.HeaderTypes.Any(h => h.Equals(criteria.Segment))) ? 1 : 0;

            result = result[criteria.Field.Position - headerAdjustment];
            if (criteria.Field.Repetition == -1)
            {
                return(result);
            }
            if (criteria.Field.Repetition > result.Count)
            {
                return(nullSegment);
            }

            var rep = ((criteria.Field.Repetition < 2) ? 1 : criteria.Field.Repetition) - 1;

            if (rep < result.Count)
            {
                result = result[rep];
            }


            //Component
            if (!criteria.Component.Enabled || criteria.Component.Repetition == -1 ||
                (result.Count == 0 && criteria.Component.Position < 2))
            {
                return(result);
            }
            if (criteria.Component.Position > result.Count)
            {
                return(nullSegment);
            }
            result = result[criteria.Component.Position - 1];

            //SubComponent
            if (!criteria.Subcomponent.Enabled || criteria.Subcomponent.Repetition == -1 ||
                (criteria.Subcomponent.Position < 2 && result.Count == 0))
            {
                return(result);
            }
            if (criteria.Subcomponent.Position > 1 && criteria.Component.Position > result.Count)
            {
                return(nullSegment);
            }
            result = result[criteria.Subcomponent.Position - 1];

            return(result);
        }