Ejemplo n.º 1
0
        /// <summary>
        /// Builds the full context from the given aTemplateConstraint forward. If the given aTemplateConstraint has a parent context then this will be built also,
        /// using the aPerspectiveConstraint. aPerspectiveConstraint is always the constraint we are requesting the context for. This ensures that we only traverse
        /// the perspective's children 1 time.
        /// </summary>
        /// <param name="aPrefix"></param>
        /// <param name="aTemplateConstraint"></param>
        /// <param name="aPerspectiveConstraint"></param>
        /// <param name="aIgnoreParent">Specifies whether to walk the the parent tree</param>
        /// <returns></returns>
        private string CreateFullBranchedParentContext(TemplateConstraint aTemplateConstraint, TemplateConstraint aPerspectiveConstraint = null, bool aIgnoreParent = false, bool isTarget = false)
        {
            string constraintParentContext = string.Empty;

            if (aTemplateConstraint.Parent != null && !aIgnoreParent)
            {
                constraintParentContext = CreateFullBranchedParentContext(aTemplateConstraint.ParentConstraint, aTemplateConstraint);
            }

            DocumentTemplateElement          element   = null;
            DocumentTemplateElementAttribute attribute = null;
            ContextParser parser = new ContextParser(aTemplateConstraint.Context);

            parser.Parse(out element, out attribute);

            if (attribute != null) //we are only looking for attributes
            {
                attribute.SingleValue = aTemplateConstraint.Value;
            }

            if (element != null)
            {
                element.IsBranch           = aTemplateConstraint.IsBranch;
                element.IsBranchIdentifier = aTemplateConstraint.IsBranchIdentifier;
                ConstraintToDocumentElementHelper.AddElementValueAndDataType(this.prefix, element, aTemplateConstraint);
            }

            ContextBuilder builder      = ContextBuilder.CreateFromElementAndAttribute(element, attribute, this.prefix);
            StringBuilder  childStrings = new StringBuilder();

            foreach (var child in aTemplateConstraint.ChildConstraints)
            {
                if (aPerspectiveConstraint == null || aPerspectiveConstraint.Id != child.Id) //since we call ourselves recursively, this ensures we only go down the path of the original caller once.
                {
                    if (child.IsBranchIdentifier == true)
                    {
                        childStrings.Append(CreateFullBranchedParentContext(child, aIgnoreParent: true));
                    }
                }
            }

            string context = builder.GetFullyQualifiedContextString() + childStrings;

            if (element != null && aTemplateConstraint.Parent != null)
            {
                if (element.IsBranchIdentifier)
                {
                    context = "[" + context + "]";
                }
                else
                {
                    context = "/" + context;
                }
            }

            return(constraintParentContext + context);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Helper function which creates an AssertionLineBuilder for an element given the constraint. This function will examine the constraint's value and datatype
        /// and add those to the builder if necessary. Also if aGenerateContext == true then it will add the context of the element.
        /// </summary>
        /// <param name="aElement">Element to base the AssertionLineBuilder from</param>
        /// <param name="aTemplateConstraint">TemplateConstraint which has the necessary properties (e.g. Element Value, Data Type) to add to the AssertionLineBuilder</param>
        /// <param name="aGenerateContext">Flag to determine whether a context should be added as part of the AssertionLineBuilder</param>
        /// <returns>A new AssertionLineBuilder for the aElement passed in</returns>
        private AssertionLineBuilder CreateAssertionLineBuilderForElement(DocumentTemplateElement aElement, IConstraint aTemplateConstraint, ref string aParentContext, bool aGenerateContext = true)
        {
            //add the value and data type
            ConstraintToDocumentElementHelper.AddElementValueAndDataType(this.prefix, aElement, aTemplateConstraint);

            //create builders
            var builder = new AssertionLineBuilder(this.tdb, aElement, this.igType, this.igTypeSchema);

            if (aGenerateContext)
            {
                ContextBuilder contextBuilder = null;

                if (aElement.ParentElement != null)                                           //build the context
                {
                    contextBuilder = new ContextBuilder(aElement.ParentElement, this.prefix); //the context will start from the first parent (or root)
                    builder.WithinContext(string.Format("{0}", contextBuilder.GetFullyQualifiedContextString()));
                }
            }

            var containedTemplates = (from tcr in aTemplateConstraint.References
                                      join t in this.allTemplates on tcr.ReferenceIdentifier equals t.Oid
                                      where tcr.ReferenceType == ConstraintReferenceTypes.Template
                                      select new { Identifier = t.Oid, t.PrimaryContextType });

            foreach (var containedTemplate in containedTemplates)
            {
                builder.ContainsTemplate(containedTemplate.Identifier, containedTemplate.PrimaryContextType);

                if (aTemplateConstraint.Parent != null && aTemplateConstraint.Parent.IsBranch)
                {
                    builder.WithinContext(aParentContext, ContextWrapper.Slash); //put the parent context into the element context, this is a special case where we want the full context within the template assertion
                    aParentContext = string.Empty;                               //clear the parent context b/c we have put it within the element's context
                }
            }

            if (aTemplateConstraint.Parent != null)
            {
                Conformance conformance = ConformanceParser.Parse(aTemplateConstraint.Parent.Conformance);
                if (conformance == Conformance.SHOULD)
                {
                    builder.HasOptionalParentContext();
                }
            }

            //TODO: Refactor this out, hardcoding these special cases for QRDA
            if (this.prefix.ToLower().Contains("cda"))
            {
                aElement.ElementToAttributeOverrideMapping.Add("code", "code");
                aElement.ElementToAttributeOverrideMapping.Add("statusCode", "code");
                aElement.ElementToAttributeOverrideMapping.Add("realmCode", "code");
                aElement.ElementToAttributeOverrideMapping.Add("externalDocument", "classCode");
            }

            return(builder);
        }