コード例 #1
0
        void ISearchValueVisitor.Visit(DateTimeSearchValue dateTime)
        {
            EnsureArg.IsNotNull(dateTime, nameof(dateTime));

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

            // Based on spec here: http://hl7.org/fhir/STU3/search.html#prefix
            switch (_comparator)
            {
            case SearchComparator.Eq:
                _outputExpression = Expression.And(
                    Expression.GreaterThanOrEqual(FieldName.DateTimeStart, _componentIndex, dateTime.Start),
                    Expression.LessThanOrEqual(FieldName.DateTimeEnd, _componentIndex, dateTime.End));
                break;

            case SearchComparator.Ne:
                _outputExpression = Expression.Or(
                    Expression.LessThan(FieldName.DateTimeStart, _componentIndex, dateTime.Start),
                    Expression.GreaterThan(FieldName.DateTimeEnd, _componentIndex, dateTime.End));
                break;

            case SearchComparator.Lt:
                _outputExpression = Expression.LessThan(FieldName.DateTimeStart, _componentIndex, dateTime.Start);
                break;

            case SearchComparator.Gt:
                _outputExpression = Expression.GreaterThan(FieldName.DateTimeEnd, _componentIndex, dateTime.End);
                break;

            case SearchComparator.Le:
                _outputExpression = Expression.LessThanOrEqual(FieldName.DateTimeStart, _componentIndex, dateTime.End);
                break;

            case SearchComparator.Ge:
                _outputExpression = Expression.GreaterThanOrEqual(FieldName.DateTimeEnd, _componentIndex, dateTime.Start);
                break;

            case SearchComparator.Sa:
                _outputExpression = Expression.GreaterThan(FieldName.DateTimeStart, _componentIndex, dateTime.End);
                break;

            case SearchComparator.Eb:
                _outputExpression = Expression.LessThan(FieldName.DateTimeEnd, _componentIndex, dateTime.Start);
                break;

            case SearchComparator.Ap:
                var startTicks = dateTime.Start.UtcTicks;
                var endTicks   = dateTime.End.UtcTicks;

                var differenceTicks = (long)((Clock.UtcNow.Ticks - Math.Max(startTicks, endTicks)) * ApproximateDateTimeRangeMultiplier);

                var approximateStart = dateTime.Start.AddTicks(-differenceTicks);
                var approximateEnd   = dateTime.End.AddTicks(differenceTicks);

                _outputExpression = Expression.And(
                    Expression.GreaterThanOrEqual(FieldName.DateTimeStart, _componentIndex, approximateStart),
                    Expression.LessThanOrEqual(FieldName.DateTimeEnd, _componentIndex, approximateEnd));
                break;

            default:
                ThrowComparatorNotSupported();
                break;
            }
        }