コード例 #1
0
        private static string GetMessageType(HL7.Dotnetcore.Message message)
        {
            string messageType = string.Empty;

            if (message.IsComponentized("MSH.9"))
            {
                messageType = message.GetValue("MSH.9.1");
            }
            else
            {
                messageType = message.GetValue("MSH.9");
            }

            return(messageType);
        }
コード例 #2
0
        /// <summary>
        /// Determine the configuration authorization key to use to check authorization.
        /// </summary>
        /// <param name="message">An HL7v2 message.</param>
        /// <returns>Returns the configured authorization scopes, or empty if unknown message.</returns>
        private string[] GetMessageAuthorizationScope(HL7.Dotnetcore.Message message)
        {
            string[] scopesNeeded = Array.Empty <string>();
            string   messageType  = GetMessageType(message); // MSH.9

            foreach (MessageConfig messageConfig in this.hl7AuthConfig.Hl7v2Authorization.MessageConfig)
            {
                if ((messageType == messageConfig.MessageType) && IsConfiguredMessage(messageConfig, message))
                {
                    scopesNeeded = messageConfig.Scope.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                    break;
                }
            }

            return(scopesNeeded);
        }
コード例 #3
0
        /// <summary>
        /// Checks that the message passed has all the fields.
        /// </summary>
        /// <param name="messageConfig">The MessageConfig configuration from app settings.</param>
        /// <param name="message">The HL7v2 message being matched.</param>
        /// <returns>Returns true when the HL7v2 message was found in the configuration.</returns>
        private static bool IsConfiguredMessage(MessageConfig messageConfig, HL7.Dotnetcore.Message message)
        {
            int requiredMatches = messageConfig.MessageSegments.Count;
            int matches         = 0;

            foreach (MessageSegment ms in messageConfig.MessageSegments)
            {
                List <string> segmentValues = new List <string>();

                foreach (HL7.Dotnetcore.Segment segment in message.Segments(ms.SegmentName))
                {
                    bool fieldsMatch = false;
                    bool firstField  = true;

                    foreach (SegmentField sf in ms.SegmentFields)
                    {
                        bool found = segment.FieldAt(sf.Index).Value.Equals(sf.Value, StringComparison.Ordinal);
                        if (firstField == true)
                        {
                            fieldsMatch = found;
                            firstField  = false;
                        }
                        else
                        {
                            fieldsMatch &= found;
                        }
                    }

                    if (fieldsMatch == true)
                    {
                        matches++;
                    }
                }
            }

            return(matches == requiredMatches);
        }
コード例 #4
0
 /// <summary>
 /// Returns the configured scopes needed for the HL7v2 message passed in.
 /// </summary>
 /// <param name="message">The Hl7-v2 message to be checked.</param>
 /// <returns>Returns a string array of scopes needed, or empty array when the message was unknown/not supported.</returns>
 public string[] ScopesNeededForMessage(HL7.Dotnetcore.Message message)
 {
     return(this.GetMessageAuthorizationScope(message));
 }