Exemplo n.º 1
0
 /// <summary>
 /// Parses a particular message and returns the encoded structure.
 /// </summary>
 /// <param name="message">The message to encode.</param>
 /// <param name="string">The string to parse.</param>
 /// <param name="parserOptions">Contains configuration that will be applied when parsing.</param>
 /// <exception cref="HL7Exception">If there is a problem encoding.</exception>
 /// <exception cref="ArgumentNullException">If <paramref name="parserOptions"/> is null.</exception>
 public abstract void Parse(IMessage message, string @string, ParserOptions parserOptions);
Exemplo n.º 2
0
 /// <summary>
 /// Called by <see cref="Parse(string, string)"/> to perform implementation-specific parsing work.
 /// </summary>
 /// <param name="message">a String that contains an HL7 message.</param>
 /// <param name="version">the name of the HL7 version to which the message belongs (eg "2.5").</param>
 /// <param name="parserOptions">Contains configuration that will be applied when parsing.</param>
 /// <returns>A HAPI Message object parsed from the given String.</returns>
 /// <exception cref="HL7Exception">Thrown if the data fields in the message do not permit encoding (e.g. required fields are null).</exception>
 /// <exception cref="EncodingNotSupportedException">Thrown if the requested encoding is not supported by this parser.</exception>
 /// <exception cref="ArgumentNullException">If <paramref name="parserOptions"/> is null.</exception>
 protected internal abstract IMessage DoParse(string message, string version, ParserOptions parserOptions);
Exemplo n.º 3
0
 public override void Parse(IMessage message, string @string, ParserOptions parserOptions)
 {
 }
Exemplo n.º 4
0
 public override IMessage ParseDocument(XmlDocument xmlMessage, string version, ParserOptions parserOptions)
 {
     return(null);
 }
Exemplo n.º 5
0
 /// <summary> <p>Creates and populates a Message object from an XML Document that contains an XML-encoded HL7 message.</p>
 /// <p>The easiest way to implement this method for a particular message structure is as follows:
 /// <ol><li>Create an instance of the Message type you are going to handle with your subclass
 /// of XMLParser</li>
 /// <li>Go through the given Document and find the Elements that represent the top level of
 /// each message segment. </li>
 /// <li>For each of these segments, call <code>parse(Segment segmentObject, Element segmentElement)</code>,
 /// providing the appropriate Segment from your Message object, and the corresponding Element.</li></ol>
 /// At the end of this process, your Message object should be populated with data from the XML
 /// Document.</p>
 /// </summary>
 /// <throws>  HL7Exception if the message is not correctly formatted. </throws>
 /// <throws>  EncodingNotSupportedException if the message encoded. </throws>
 /// <summary>      is not supported by this parser.
 /// </summary>
 public abstract IMessage ParseDocument(XmlDocument xmlMessage, string version, ParserOptions parserOptions);
        /// <summary> <p>Creates and populates a Message object from an XML Document that contains an XML-encoded HL7 message.</p>
        /// <p>The easiest way to implement this method for a particular message structure is as follows:
        /// <ol><li>Create an instance of the Message type you are going to handle with your subclass
        /// of XMLParser</li>
        /// <li>Go through the given Document and find the Elements that represent the top level of
        /// each message segment. </li>
        /// <li>For each of these segments, call <code>parse(Segment segmentObject, Element segmentElement)</code>,
        /// providing the appropriate Segment from your Message object, and the corresponding Element.</li></ol>
        /// At the end of this process, your Message object should be populated with data from the XML
        /// Document.</p>
        /// </summary>
        /// <throws>  HL7Exception if the message is not correctly formatted. </throws>
        /// <throws>  EncodingNotSupportedException if the message encoded. </throws>
        /// <summary>     is not supported by this parser.
        /// </summary>
        public override IMessage ParseDocument(XmlDocument xmlMessage, string version, ParserOptions parserOptions)
        {
            if (parserOptions is null)
            {
                throw new ArgumentNullException(nameof(parserOptions));
            }

            var messageName = xmlMessage.DocumentElement.Name;
            var message     = InstantiateMessage(messageName, version, true);

            Parse(message, xmlMessage.DocumentElement, parserOptions);
            return(message);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Parses a segment string and populates the given Segment object.  Unexpected fields are
        /// added as Varies' at the end of the segment.
        /// </summary>
        /// <throws>  HL7Exception if the given string does not contain the. </throws>
        /// <summary>      given segment or if the string is not encoded properly.
        /// </summary>
        public virtual void Parse(ISegment destination, string segment, EncodingCharacters encodingChars, ParserOptions parserOptions)
        {
            parserOptions = parserOptions ?? DefaultParserOptions;

            var fieldOffset = 0;

            if (IsDelimDefSegment(destination.GetStructureName()))
            {
                fieldOffset = 1;

                // set field 1 to fourth character of string
                Terser.Set(destination, 1, 0, 1, 1, Convert.ToString(encodingChars.FieldSeparator));
            }

            var fields = Split(segment, Convert.ToString(encodingChars.FieldSeparator));

            for (var i = 1; i < fields.Length; i++)
            {
                var reps = Split(fields[i], Convert.ToString(encodingChars.RepetitionSeparator));
                if (Log.DebugEnabled)
                {
                    Log.Debug(reps.Length + "reps delimited by: " + encodingChars.RepetitionSeparator);
                }

                // MSH-2 will get split incorrectly so we have to fudge it ...
                var isMSH2 = IsDelimDefSegment(destination.GetStructureName()) && i + fieldOffset == 2;
                if (isMSH2)
                {
                    reps    = new string[1];
                    reps[0] = fields[i];
                }

                for (var j = 0; j < reps.Length; j++)
                {
                    try
                    {
                        var statusMessage = $"Parsing field {i + fieldOffset} repetition {j}";
                        Log.Debug(statusMessage);

                        var field = destination.GetField(i + fieldOffset, j);
                        if (isMSH2)
                        {
                            Terser.GetPrimitive(field, 1, 1).Value = reps[j];
                        }
                        else
                        {
                            Parse(field, reps[j], encodingChars);
                        }
                    }
                    catch (HL7Exception e)
                    {
                        // set the field location and throw again ...
                        e.FieldPosition     = i + fieldOffset;
                        e.SegmentRepetition = Util.MessageIterator.GetIndex(destination.ParentStructure, destination).Rep;
                        e.SegmentName       = destination.GetStructureName();
                        throw;
                    }
                }
            }

            // set data type of OBX-5
            if (destination.GetType().FullName.IndexOf("OBX") >= 0)
            {
                Varies.FixOBX5(destination, Factory, parserOptions);
            }
        }