Esempio n. 1
0
        void ISearchValueVisitor.Visit(TokenSearchValue token)
        {
            EnsureArg.IsNotNull(token, nameof(token));

            EnsureOnlyEqualComparatorIsSupported();

            if (_modifier == null)
            {
                _outputExpression = BuildEqualityExpression();
            }
            else if (_modifier == SearchModifierCode.Not)
            {
                _outputExpression = Expression.Not(BuildEqualityExpression());
            }
            else if (_modifier == SearchModifierCode.Above ||
                     _modifier == SearchModifierCode.Below ||
                     _modifier == SearchModifierCode.In ||
                     _modifier == SearchModifierCode.NotIn)
            {
                // These modifiers are not supported yet but will be supported eventually.
                ThrowModifierNotSupported();
            }
            else
            {
                ThrowModifierNotSupported();
            }

            Expression BuildEqualityExpression()
            {
                // Based on spec http://hl7.org/fhir/search.html#token,
                // we need to make sure to test if system is missing or not based on how it is supplied.
                if (token.System == null)
                {
                    // If the system is not supplied, then the token code is matched irrespective of the value of system.
                    return(Expression.StringEquals(FieldName.TokenCode, _componentIndex, token.Code, false));
                }
                else if (token.System.Length == 0)
                {
                    // If the system is empty, then the token is matched if there is no system property.
                    return(Expression.And(
                               Expression.Missing(FieldName.TokenSystem, _componentIndex),
                               Expression.StringEquals(FieldName.TokenCode, _componentIndex, token.Code, false)));
                }
                else if (string.IsNullOrWhiteSpace(token.Code))
                {
                    // If the code is empty, then the token is matched if system is matched.
                    return(Expression.StringEquals(FieldName.TokenSystem, _componentIndex, token.System, false));
                }
                else
                {
                    return(Expression.And(
                               Expression.StringEquals(FieldName.TokenSystem, _componentIndex, token.System, false),
                               Expression.StringEquals(FieldName.TokenCode, _componentIndex, token.Code, false)));
                }
            }
        }
        void ISearchValueVisitor.Visit(ReferenceSearchValue reference)
        {
            EnsureArg.IsNotNull(reference, nameof(reference));

            if (_modifier != null)
            {
                ThrowModifierNotSupported();
            }

            EnsureOnlyEqualComparatorIsSupported();

            if (reference.BaseUri != null)
            {
                // The reference is external.
                _outputExpression = Expression.And(
                    Expression.StringEquals(FieldName.ReferenceBaseUri, _componentIndex, reference.BaseUri.ToString(), false),
                    Expression.StringEquals(FieldName.ReferenceResourceType, _componentIndex, reference.ResourceType.Value.ToString(), false),
                    Expression.StringEquals(FieldName.ReferenceResourceId, _componentIndex, reference.ResourceId, false));
            }
            else if (reference.ResourceType == null)
            {
                // Only resource id is specified.
                _outputExpression = Expression.StringEquals(FieldName.ReferenceResourceId, _componentIndex, reference.ResourceId, false);
            }
            else if (reference.Kind == ReferenceKind.Internal)
            {
                // The reference must be internal.
                _outputExpression = Expression.And(
                    Expression.Missing(FieldName.ReferenceBaseUri, _componentIndex),
                    Expression.StringEquals(FieldName.ReferenceResourceType, _componentIndex, reference.ResourceType.Value.ToString(), false),
                    Expression.StringEquals(FieldName.ReferenceResourceId, _componentIndex, reference.ResourceId, false));
            }
            else
            {
                // The reference can be internal or external.
                _outputExpression = Expression.And(
                    Expression.StringEquals(FieldName.ReferenceResourceType, _componentIndex, reference.ResourceType.Value.ToString(), false),
                    Expression.StringEquals(FieldName.ReferenceResourceId, _componentIndex, reference.ResourceId, false));
            }
        }