public object Translate(TranslationContext context, ASTNode node) { // As long as this is list containment, it can be translated using an Exists(Filter(Source, Condition(Current = Value))); // TODO: Contains on a date interval could be translated as well var sourceNode = node.Children.FirstOrDefault(c => c.Name == "source"); var elementNode = node.Children.FirstOrDefault(c => c.Name == "element"); if (sourceNode.ResultType is IntervalType) { throw new NotImplementedException("Contains translation with Interval source is not yet supported."); } var filter = new CREFModel.FilterExpression(); filter.Items.Add(context.TranslateNode(sourceNode)); 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(elementNode)); var exists = new CREFModel.UnaryExpression(); exists.Operator = CREFModel.UnaryOperator.opExists; exists.OperatorSpecified = true; exists.Item = filter; return(exists); }
public object Translate(TranslationContext context, ASTNode node) { // As long as this is list containment, it can be translated using an Exists(Filter(Collection, Condition(Current = Element))); var collectionNode = node.Children.FirstOrDefault(c => c.Name == "collection"); var elementNode = node.Children.FirstOrDefault(c => c.Name == "element"); if (elementNode.ResultType is ListType) { throw new NotSupportedException("In translation with an element of type list is not supported because there is no equivalent CREF representation."); } var filter = new CREFModel.FilterExpression(); filter.Items.Add(context.TranslateNode(collectionNode)); 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(elementNode)); var exists = new CREFModel.UnaryExpression(); exists.Operator = CREFModel.UnaryOperator.opExists; exists.OperatorSpecified = true; exists.Item = filter; return(exists); }
private object GetRelatedClinicalStatement(TranslationContext context, ASTNode node, string idPropertyName, CREFModel.PatientQueryType type) { var propertyNode = GetRelatedClinicalStatementPropertyNode(node); if (propertyNode == null) { throw new InvalidOperationException("Could not resolve related clinical statement property access node."); } var id = new CREFModel.PropertyExpression(); var source = propertyNode.Children.FirstOrDefault(); if (source != null) { id.Item = context.TranslateNode(source); } id.Path = idPropertyName; var request = new CREFModel.RequestExpression(); request.Cardinality = CREFModel.RequestCardinality.Multiple; request.CardinalitySpecified = true; request.Type = type; request.TypeSpecified = true; var filter = new CREFModel.FilterExpression(); filter.Items.Add(request); var condition = new CREFModel.BinaryExpression(); condition.Operator = CREFModel.BinaryOperator.opEqual; condition.OperatorSpecified = true; var idReference = new CREFModel.PropertyExpression(); idReference.Path = "ID"; condition.Items.Add(idReference); condition.Items.Add(id); filter.Items.Add(condition); var first = new CREFModel.UnaryExpression(); first.Item = filter; first.Operator = CREFModel.UnaryOperator.opFirst; first.OperatorSpecified = true; return(first); }
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); }
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); }
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; }
public object Translate(TranslationContext context, ASTNode node) { // As long as this is list containment, it can be translated using an Exists(Filter(Collection, Condition(Current = Element))); var collectionNode = node.Children.FirstOrDefault(c => c.Name == "collection"); var elementNode = node.Children.FirstOrDefault(c => c.Name == "element"); if (elementNode.ResultType is ListType) { throw new NotSupportedException("In translation with an element of type list is not supported because there is no equivalent CREF representation."); } var filter = new CREFModel.FilterExpression(); filter.Items.Add(context.TranslateNode(collectionNode)); 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(elementNode)); var exists = new CREFModel.UnaryExpression(); exists.Operator = CREFModel.UnaryOperator.opExists; exists.OperatorSpecified = true; exists.Item = filter; return exists; }
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; }
public object Translate(TranslationContext context, ASTNode node) { // As long as this is list containment, it can be translated using an Exists(Filter(Source, Condition(Current = Value))); // TODO: Contains on a date interval could be translated as well var sourceNode = node.Children.FirstOrDefault(c => c.Name == "source"); var elementNode = node.Children.FirstOrDefault(c => c.Name == "element"); if (sourceNode.ResultType is IntervalType) { throw new NotImplementedException("Contains translation with Interval source is not yet supported."); } var filter = new CREFModel.FilterExpression(); filter.Items.Add(context.TranslateNode(sourceNode)); 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(elementNode)); var exists = new CREFModel.UnaryExpression(); exists.Operator = CREFModel.UnaryOperator.opExists; exists.OperatorSpecified = true; exists.Item = filter; return exists; }
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; }
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); }
private object GetRelatedClinicalStatement(TranslationContext context, ASTNode node, string idPropertyName, CREFModel.PatientQueryType type) { var propertyNode = GetRelatedClinicalStatementPropertyNode(node); if (propertyNode == null) { throw new InvalidOperationException("Could not resolve related clinical statement property access node."); } var id = new CREFModel.PropertyExpression(); var source = propertyNode.Children.FirstOrDefault(); if (source != null) { id.Item = context.TranslateNode(source); } id.Path = idPropertyName; var request = new CREFModel.RequestExpression(); request.Cardinality = CREFModel.RequestCardinality.Multiple; request.CardinalitySpecified = true; request.Type = type; request.TypeSpecified = true; var filter = new CREFModel.FilterExpression(); filter.Items.Add(request); var condition = new CREFModel.BinaryExpression(); condition.Operator = CREFModel.BinaryOperator.opEqual; condition.OperatorSpecified = true; var idReference = new CREFModel.PropertyExpression(); idReference.Path = "ID"; condition.Items.Add(idReference); condition.Items.Add(id); filter.Items.Add(condition); var first = new CREFModel.UnaryExpression(); first.Item = filter; first.Operator = CREFModel.UnaryOperator.opFirst; first.OperatorSpecified = true; return first; }