Esempio n. 1
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            if (DataTypes.Equal(node.ResultType, DataTypes.DateTimeInterval))
            {
                var result = new CREFModel.DateRange();

                var beginOpen = Convert.ToBoolean(node.GetAttribute <string>("beginOpen"));
                var endOpen   = Convert.ToBoolean(node.GetAttribute <string>("endOpen"));
                if (beginOpen || endOpen)
                {
                    throw new NotSupportedException("Translation for open intervals is not supported because CREF only supports closed interval values.");
                }

                foreach (var child in node.Children)
                {
                    result.Items.Add(context.TranslateNode(child));
                }

                return(result);
            }
            else
            {
                throw new NotSupportedException("Translation for intervals with point types other than Timestamp is not supported because CREF does not support generic interval values.");
            }
        }
Esempio n. 2
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new CREFModel.Code();

            result.CodeValue       = node.GetAttribute <string>("code");
            result.CodingSystem    = node.GetAttribute <string>("codeSystemName");
            result.CodeType        = node.GetAttribute <string>("codeSystem");     // TODO: Verify w/ Allscripts
            result.CodeDescription = node.GetAttribute <string>("displayName");

            return(result);
        }
Esempio n. 3
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            // Reject translation for properties with an explicit scope
            var scope = node.GetAttribute <string>("scope", VerificationContext.Current);

            if (scope != VerificationContext.Current)
            {
                throw new NotSupportedException("Property path cannot be translated because it references an explicit scope, which is not supported in CREF.");
            }

            var sourceType = node.GetAttribute <ObjectType>("sourceType");

            // Translate path information
            return(context.TransformModelPath(sourceType, node, node.GetAttribute <string>("path")));
        }
Esempio n. 4
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new CREFModel.ExpressionReference();

            result.Name = node.GetAttribute <string>("name");

            return(result);
        }
Esempio n. 5
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new CREFModel.ParameterExpression();

            result.Name = node.GetAttribute <string>("name");

            // TODO: Default value?

            return(result);
        }
Esempio n. 6
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new CREFModel.ValueSetExpression();

            // TODO: Handle Value Set Mapping
            result.ValueSetID = node.GetAttribute <string>("id");

            var version = node.GetAttribute <string>("version");

            if (!String.IsNullOrEmpty(version))
            {
                result.Version          = Int32.Parse(version);
                result.VersionSpecified = true;
            }

            // TODO: Value Set Authority

            return(result);
        }
Esempio n. 7
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            // Physical quantity is not supported as a value type within CREF, so the literal will need to be transformed to a "unit normalized representation"
            var value = Convert.ToDecimal(node.GetAttribute <string>("value"));
            var unit  = node.GetAttribute <string>("unit");

            switch (unit)
            {
            case "1": break;                      // Do nothing, this is the unity unit in UCUM, value is unadjusted

            // Time units
            case "a": value *= 365.25m; break;    // Year, convert to days

            case "mo": value *= 30.4375m; break;  // Month, convert to days

            case "wk": value *= 7m; break;        // Week, convert to days

            case "d": break;                      // Day

            // These time units are not yet supported
            //"h" : break; // Hour
            //"min" : break; // Minute
            //"Ms" : break; // Megasecond
            //"ks" : break; // Kilosecond
            //"s" : break; // Second
            //"ms" : break; // Millisecond
            //"us" : break; // Microsecond
            //"ns" : break; // Nanosecond
            //"ps" : break; // Picosecond

            default: throw new NotSupportedException(String.Format("Physical quantity unit translation for unit type of '{0}' is not supported.", unit));
            }

            var result = new CREFModel.ValueExpression();

            result.Type          = CREFModel.ValueType.Decimal;
            result.TypeSpecified = true;

            result.Value = Convert.ToString(value);

            return(result);
        }
Esempio n. 8
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            // Ideally, this would be expressed as an InValueSet expression within CREF, but in the absence of such an operator, the translation
            // Can be supporting using: Exists(Filter(ValueSet(ValueSetId), Condition(Current = Operand)))
            var valueSetId        = node.GetAttribute <string>("id");
            var valueSetVersion   = node.GetAttribute <string>("version");
            var valueSetAuthority = node.GetAttribute <string>("authority"); // TODO: Authority resolution?

            var operand = node.Children.FirstOrDefault(c => c.Name == "operand");

            var valueSetExpression = new CREFModel.ValueSetExpression();

            valueSetExpression.ValueSetID = valueSetId;
            if (!String.IsNullOrEmpty(valueSetVersion))
            {
                valueSetExpression.Version          = Convert.ToInt32(valueSetVersion);
                valueSetExpression.VersionSpecified = true;
            }

            var filter = new CREFModel.FilterExpression();

            filter.Items.Add(valueSetExpression);

            var condition = new CREFModel.BinaryExpression();

            condition.Operator          = CREFModel.BinaryOperator.opEqual;
            condition.OperatorSpecified = true;

            // Assumption: A property expression with no path specified is equivalent to a "current" reference
            var property = new CREFModel.PropertyExpression();

            condition.Items.Add(property);
            condition.Items.Add(context.TranslateNode(operand));

            var exists = new CREFModel.UnaryExpression();

            exists.Operator          = CREFModel.UnaryOperator.opExists;
            exists.OperatorSpecified = true;
            exists.Item = filter;

            return(exists);
        }
Esempio n. 9
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new CREFModel.ValueExpression();

            result.Type          = CREFModel.ValueType.String;
            result.TypeSpecified = true;

            result.Value = node.GetAttribute <string>("value");

            return(result);
        }
Esempio n. 10
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new CREFModel.ValueExpression();

            result.Type          = CREFModel.ValueType.Boolean;
            result.TypeSpecified = true;

            result.Value = node.GetAttribute <string>("value"); // TODO: This assumes boolean representation will translate...

            return(result);
        }
Esempio n. 11
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new CREFModel.ValueExpression();

            if (DataTypes.Equal(node.ResultType, DataTypes.String))
            {
                result.Type          = Model.ValueType.String;
                result.TypeSpecified = true;
                result.Value         = node.GetAttribute <string>("value");
            }
            else if (DataTypes.Equal(node.ResultType, DataTypes.Integer))
            {
                result.Type          = Model.ValueType.Int32;
                result.TypeSpecified = true;
                result.Value         = node.GetAttribute <string>("value");
            }
            else if (DataTypes.Equal(node.ResultType, DataTypes.Boolean))
            {
                result.Type          = Model.ValueType.Boolean;
                result.TypeSpecified = true;
                result.Value         = node.GetAttribute <string>("value");
            }
            else if (DataTypes.Equal(node.ResultType, DataTypes.Decimal))
            {
                result.Type          = Model.ValueType.Decimal;
                result.TypeSpecified = true;
                result.Value         = node.GetAttribute <string>("value");
            }
            else if (DataTypes.Equal(node.ResultType, DataTypes.DateTime))
            {
                result.Type          = Model.ValueType.Date;
                result.TypeSpecified = true;
                result.Value         = node.GetAttribute <string>("value");        // TODO: Convert to format expected by CREF
            }
            else
            {
                throw new NotSupportedException(String.Format("Unsupported literal type: {0}.", node.ResultType.Name));
            }

            return(result);
        }
Esempio n. 12
0
        private ASTNode GetRelatedClinicalStatementPropertyNode(ASTNode node)
        {
            if (node.NodeType.GetLocalName() == "Property" && node.GetAttribute <string>("path") == "relatedClinicalStatement")
            {
                return(node);
            }

            foreach (var child in node.Children)
            {
                return(GetRelatedClinicalStatementPropertyNode(child));
            }

            return(null);
        }
Esempio n. 13
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var scope = node.GetAttribute <string>("scope", VerificationContext.Current);

            if (scope != VerificationContext.Current)
            {
                throw new NotSupportedException("Translation of filter expression is not supported because it involves a named scope reference, which is not supported in CREF.");
            }

            var source    = node.Children[0];
            var condition = node.Children[1];

            var result = new CREFModel.FilterExpression();

            result.Items.Add(context.TranslateNode(source));
            result.Items.Add(context.TranslateNode(condition));

            return(result);
        }
Esempio n. 14
0
        public void Verify(VerificationContext context, ASTNode node)
        {
            var valuesetDef = context.ResolveValueSetRef(node.GetAttribute <String>("libraryName"), node.GetAttribute <String>("name"));

            node.ResultType = DataTypes.CodeList;
        }
Esempio n. 15
0
        public void Verify(VerificationContext context, ASTNode node)
        {
            var codesystemDef = context.ResolveCodeSystemRef(node.GetAttribute <String>("libraryName"), node.GetAttribute <String>("name"));

            node.ResultType = DataTypes.CodeList;
        }
Esempio n. 16
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            // Model mapping
            var result = new CREFModel.RequestExpression();

            if (node.ResultType == null)
            {
                throw new InvalidOperationException("Clinical request expression has no result type.");
            }

            var cardinality = (RequestCardinality)Enum.Parse(typeof(RequestCardinality), node.Attributes["cardinality"].ToString(), true);

            result.Cardinality          = cardinality == RequestCardinality.Single ? CREFModel.RequestCardinality.Single : CREFModel.RequestCardinality.Multiple;
            result.CardinalitySpecified = true;

            var requestListType = node.ResultType as ListType;
            var requestType     = (requestListType == null ? node.ResultType : requestListType.ElementType) as ObjectType;

            if (requestType == null)
            {
                throw new InvalidOperationException(String.Format("Unable to determine request type from source type: '{0}'.", node.ResultType.Name));
            }

            result.Type          = GetQueryType(context.TransformModelType(requestType));
            result.TypeSpecified = true;

            // Translate Codes
            var codes = node.Children.Where(n => n.Name == "codes").FirstOrDefault();

            if (codes != null)
            {
                var codesResult = context.TranslateNode(codes);
                result.Items.Add(codesResult);
            }

            // Translate DateRange
            var dateRange = node.Children.Where(n => n.Name == "dateRange").FirstOrDefault();

            if (dateRange != null)
            {
                var dateRangeResult = context.TranslateNode(dateRange);
                result.Items.Add(dateRangeResult);
            }

            // Validate idProperty, dateProperty, and codeProperty
            ValidateIdProperty(requestType, node.GetAttribute <string>("idProperty"));
            ValidateDateProperty(requestType, node.GetAttribute <string>("dateProperty"));
            ValidateCodeProperty(requestType, node.GetAttribute <string>("codeProperty"));

            // Add status filters if necessary
            var filterValue = GetStatusFilterValue(requestType);

            if (!String.IsNullOrEmpty(filterValue))
            {
                var filter = new CREFModel.FilterExpression();

                filter.Items.Add(result);

                var condition = new CREFModel.BinaryExpression();
                condition.Operator          = CREFModel.BinaryOperator.opEqual;
                condition.OperatorSpecified = true;

                condition.Items.Add(new CREFModel.PropertyExpression()
                {
                    Path = "Status"
                });
                condition.Items.Add(new CREFModel.ValueExpression()
                {
                    Type = CREFModel.ValueType.String, TypeSpecified = true, Value = filterValue
                });

                filter.Items.Add(condition);

                return(filter);
            }

            return(result);
        }