private void CreateAndPopulateElementAssertionString(StringBuilder sb)
        {
            //generate the element assertion
            var elementAssert = _element.GetAssertionStringIdentifier();

            if (!string.IsNullOrEmpty(elementAssert))
            {
                elementAssert = this.GetFormattedPrefix() + elementAssert;
            }
            else if (string.IsNullOrEmpty(elementAssert) && this.containedTemplates.Count > 0)
            {
                elementAssert = "*";
            }

            List <string> containedTemplateContexts = new List <string>();

            foreach (var containedTemplate in this.containedTemplates)
            {
                TemplateContextBuilder tcb      = new TemplateContextBuilder(this._tdb, this._igType, this._igTypeSchema, this._prefix);
                string containedTemplateContext = tcb.BuildContextString(containedTemplate.Key);
                containedTemplateContexts.Add(containedTemplateContext);
            }

            if (containedTemplateContexts.Count == 1)
            {
                elementAssert += "[" + containedTemplateContexts[0] + "]";
            }
            else if (containedTemplateContexts.Count > 1)
            {
                elementAssert += "[(" + string.Join(") or (", containedTemplateContexts) + ")]";
            }

            sb.Replace(Sentinels.ELEMENT_TOKEN, elementAssert);
        }
示例#2
0
        public string GenerateDocumentLevelTemplateConstraints(ImplementationGuide aImplementationGuide, Phase aErrorPhase)
        {
            var firstTemplateType = aImplementationGuide.ImplementationGuideType.TemplateTypes.OrderBy(y => y.OutputOrder).FirstOrDefault();

            if (firstTemplateType == null)
            {
                return(string.Empty);
            }

            var documentLevelTemplates = this.templates.Where(y => y.TemplateTypeId == firstTemplateType.Id);

            string lDeprecatedStatus = Shared.PublishStatuses.Deprecated.ToString();

            documentLevelTemplates.ToList().RemoveAll(t => t.Status != null && t.Status.Status == lDeprecatedStatus);

            List <string>          requiredTemplates = new List <string>();
            TemplateContextBuilder tcb = new TemplateContextBuilder(this.rep, aImplementationGuide.ImplementationGuideType, this.igTypeSchema);

            foreach (var template in documentLevelTemplates)
            {
                string xpath = tcb.BuildContextString(template);
                requiredTemplates.Add(xpath);
            }

            return(string.Join(" or ", requiredTemplates));
        }
示例#3
0
        /// <summary>
        /// Creates a rule context for a template where the template does not have the identifier element
        /// </summary>
        /// <remarks>
        /// Example: Where the "AD" type template does not have "templateId" on it.
        /// Example: Where a profiled FHIR element does not have "meta/profile" on it.
        /// </remarks>
        /// <param name="template"></param>
        /// <returns></returns>
        private string BuildContextWithoutIdentifierElement(Template template)
        {
            var containingConstraints = (from tcr in this.tdb.TemplateConstraintReferences
                                         join tc in this.tdb.TemplateConstraints on tcr.TemplateConstraintId equals tc.Id
                                         where tcr.ReferenceType == ConstraintReferenceTypes.Template &&
                                         tcr.ReferenceIdentifier == template.Oid
                                         select tc);

            if (containingConstraints.Count() == 0)
            {
                if (!template.PrimaryContext.Contains(":"))
                {
                    return(string.Format("{0}:{1}", this.prefix, template.PrimaryContext));
                }

                return(template.PrimaryContext);
            }

            List <string> containmentContexts = new List <string>();

            foreach (var containingConstraint in containingConstraints)
            {
                if (string.IsNullOrEmpty(containingConstraint.Context))
                {
                    continue;
                }

                string containmentContext = string.Empty;
                var    currentConstraint  = containingConstraint;

                while (currentConstraint != null)
                {
                    if (!string.IsNullOrEmpty(containmentContext))
                    {
                        containmentContext = "/" + containmentContext;
                    }

                    string constraintContext = currentConstraint.Context;

                    if (!constraintContext.Contains(":"))
                    {
                        constraintContext = string.Format("{0}:{1}", this.prefix, constraintContext);
                    }

                    containmentContext = constraintContext + containmentContext;
                    currentConstraint  = currentConstraint.ParentConstraint;
                }

                // TODO: Enhance performance
                TemplateContextBuilder tcb = new TemplateContextBuilder(this.tdb, containingConstraint.Template.ImplementationGuideType, this.igTypeSchema);
                string templateContext     = tcb.BuildContextString(containingConstraint.Template);

                if (!string.IsNullOrEmpty(templateContext))
                {
                    containmentContext = templateContext + "/" + containmentContext;
                }

                containmentContexts.Add(containmentContext);
            }

            return(string.Join(" | ", containmentContexts.Distinct()));
        }
示例#4
0
        /// <summary>
        /// Creates a new instance of SchematronGenerator.
        /// </summary>
        /// <param name="rep">The repository (object context) to get the data from.</param>
        /// <param name="ig">The implementation guide to export schematron for.</param>
        /// <param name="includeInferred">Indicates whether or not to include inferred templates, in addition to the templates directly owned by the implementation guide</param>
        public SchematronGenerator(IObjectRepository rep,
                                   ImplementationGuide ig,
                                   List <Template> templates,
                                   bool includeCustom,
                                   VocabularyOutputType vocabularyOutputType = VocabularyOutputType.Default,
                                   string vocFileName       = "voc.xml",
                                   List <string> categories = null,
                                   string defaultSchematron = "not(.)")
        {
            var templateIds = templates.Select(y => y.Id).ToList();

            this.rep        = rep;
            this.ig         = ig;
            this.igSettings = new IGSettingsManager(rep, ig.Id);
            this.templates  = rep.Templates.Where(y => templateIds.Contains(y.Id))
                              .Include(y => y.ImpliedTemplate)
                              .Include("ChildConstraints")
                              .Include("ChildConstraints.ValueSet")
                              .Include("ChildConstraints.CodeSystem")
                              .Include("ChildConstraints.References")
                              .Include("ChildConstraints.ChildConstraints")
                              .Include("ChildConstraints.ChildConstraints.ValueSet")
                              .Include("ChildConstraints.ChildConstraints.CodeSystem")
                              .Include("ChildConstraints.ChildConstraints.References")
                              .Include("ChildConstraints.ChildConstraints.ChildConstraints")
                              .Include("ChildConstraints.ChildConstraints.ChildConstraints.ValueSet")
                              .Include("ChildConstraints.ChildConstraints.ChildConstraints.CodeSystem")
                              .Include("ChildConstraints.ChildConstraints.ChildConstraints.References")
                              .Include("ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints")
                              .Include("ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.ValueSet")
                              .Include("ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.CodeSystem")
                              .Include("ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.References")
                              .Include("ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints")
                              .Include("ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.ValueSet")
                              .Include("ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.CodeSystem")
                              .Include("ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.References")
                              .Include("ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints")
                              .Include("ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.ValueSet")
                              .Include("ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.CodeSystem")
                              .Include("ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.ChildConstraints.References")
                              .ToList();
            this.constraintReferences = (from tcr in this.rep.TemplateConstraintReferences                                      // all constraint references
                                         join t in this.rep.Templates on tcr.ReferenceIdentifier equals t.Oid                   // get the template the reference is point to
                                         join stc in this.rep.TemplateConstraints on tcr.TemplateConstraintId equals stc.Id     // get the constraint that the reference is on
                                         join stid in templateIds on stc.TemplateId equals stid                                 // limit constraints to only templates being included in the ig/export
                                         select new ConstraintReference()
            {
                Bookmark = t.Bookmark,
                Identifier = t.Oid,
                Name = t.Name,
                TemplateConstraintId = tcr.TemplateConstraintId
            }).ToList();
            this.vocabularyOutputType = vocabularyOutputType;
            this.includeCustom        = includeCustom;
            this.vocFileName          = vocFileName;
            this.categories           = categories;
            this.defaultSchematron    = defaultSchematron;

            this.igTypePlugin           = this.ig.ImplementationGuideType.GetPlugin();
            this.igTypeSchema           = ig.ImplementationGuideType.GetSimpleSchema();
            this.templateContextBuilder = new TemplateContextBuilder(this.rep, ig.ImplementationGuideType, this.igTypeSchema);

            var allConstraint = (from t in templates
                                 from tc in t.ChildConstraints
                                 select new { tc.Id, tc.Template.OwningImplementationGuideId, tc.Number.Value })
                                .Distinct();

            this.constraintNumbers = allConstraint.ToDictionary(y => y.Id, y => string.Format("{0}-{1}", y.OwningImplementationGuideId, y.Value));

            this.schemaPrefix = ig.ImplementationGuideType.SchemaPrefix;

            if (!this.schemaPrefix.EndsWith(":"))
            {
                this.schemaPrefix += ":";
            }
        }