/// <summary>
        /// this simply calls out to the FormattedConstraint class to create a message. It's abstracted to be mockable.
        /// </summary>
        /// <param name="tc"></param>
        /// <returns></returns>
        internal string GetAssertionTestMessage(TemplateConstraint tc, string conformance = null)
        {
            List <string> messages = new List <string>();

            IGSettingsManager    igSettings = new IGSettingsManager(rep, ig.Id);
            IFormattedConstraint currentFc  = FormattedConstraintFactory.NewFormattedConstraint(this.rep, igSettings, tc);

            if (!string.IsNullOrEmpty(conformance))
            {
                currentFc.Conformance = conformance;
            }

            // Need to re-parse the properties of the formatted constraint since they have changed
            currentFc.ParseFormattedConstraint();

            messages.Add(currentFc.GetPlainText(false, false, false));

            if (tc.IsBranch || IsBranchDescendent(tc))
            {
                foreach (var child in tc.ChildConstraints)
                {
                    if (child.IsBranchIdentifier)
                    {
                        messages.Add(GetAssertionTestMessage(child));
                    }
                }
            }

            return(string.Join(" ", messages));
        }
        public static IFormattedConstraint NewFormattedConstraint(
            IObjectRepository tdb,
            IGSettingsManager igSettings,
            IIGTypePlugin igTypePlugin,
            IConstraint constraint,
            List <ConstraintReference> references,
            string templateLinkBase      = null,
            string valueSetLinkBase      = null,
            bool linkContainedTemplate   = false,
            bool linkIsBookmark          = false,
            bool createLinksForValueSets = false,
            bool includeCategory         = true,
            ValueSet valueSet            = null,
            CodeSystem codeSystem        = null)
        {
            Type selectedType = null;

            if (igSettings == null || !igSettings.IsPublished)
            {
                var latestVersion = versions.Keys.OrderByDescending(y => y).First();
                selectedType = versions[latestVersion];
            }
            else
            {
                foreach (var versionDate in versions.Keys.OrderByDescending(y => y))
                {
                    if (igSettings.PublishDate > versionDate)
                    {
                        selectedType = versions[versionDate];
                        break;
                    }
                }

                if (selectedType == null)
                {
                    var latestVersion = versions.Keys.OrderByDescending(y => y).Last();
                    selectedType = versions[latestVersion];
                }
            }

            IFormattedConstraint formattedConstraint = (IFormattedConstraint)Activator.CreateInstance(selectedType);

            formattedConstraint.Tdb                    = tdb;
            formattedConstraint.IgSettings             = igSettings;
            formattedConstraint.IncludeCategory        = includeCategory;
            formattedConstraint.TemplateLinkBase       = templateLinkBase;
            formattedConstraint.ValueSetLinkBase       = valueSetLinkBase;
            formattedConstraint.LinkContainedTemplate  = linkContainedTemplate;
            formattedConstraint.LinkIsBookmark         = linkIsBookmark;
            formattedConstraint.CreateLinkForValueSets = createLinksForValueSets;
            formattedConstraint.ConstraintReferences   = references;

            // Set the properties in the FormattedConstraint based on the IConstraint
            formattedConstraint.ParseConstraint(igTypePlugin, constraint, valueSet, codeSystem);

            // Pre-process the constraint so that calls to GetHtml(), GetPlainText(), etc. returns something
            formattedConstraint.ParseFormattedConstraint();

            return(formattedConstraint);
        }
Beispiel #3
0
        private ConstraintViewModel BuildConstraint(DB.IObjectRepository tdb, string baseLink,
                                                    IGSettingsManager igSettings, DB.TemplateConstraint dbConstraint, int constraintCount, int?aParentConstraintId = null)
        {
            IFormattedConstraint fc         = FormattedConstraintFactory.NewFormattedConstraint(tdb, igSettings, dbConstraint);
            WIKIParser           wikiParser = new WIKIParser(tdb);

            ConstraintViewModel lGreenViewModel = new ConstraintViewModel()
            {
                constraintLabel    = dbConstraint.Label,
                headingDescription = dbConstraint.HeadingDescription,
                id            = dbConstraint.Id,
                order         = dbConstraint.Order,
                isHeading     = dbConstraint.IsHeading,
                isPrimitive   = dbConstraint.IsPrimitive,
                primitiveText = dbConstraint.PrimitiveText,
                templateId    = dbConstraint.TemplateId,
                number        = dbConstraint.Number,
                text          = fc.GetPlainText(false, false, false),
                conformance   = dbConstraint.Conformance,
                value         = dbConstraint.Value
            };

            lGreenViewModel.constraintDescription = GetConstraintDescription(dbConstraint);

            DB.GreenConstraint lGreenConstraint = dbConstraint.GreenConstraints.DefaultIfEmpty(null).FirstOrDefault();

            if (lGreenConstraint != null)
            {
                lGreenViewModel.Use(c =>
                {
                    c.businessName       = lGreenConstraint.Description;
                    c.elementName        = lGreenConstraint.Name;
                    c.xPath              = lGreenConstraint.RootXpath;
                    c.greenConstraintId  = lGreenConstraint.Id;
                    c.hasGreenConstraint = true;

                    if (lGreenConstraint.ImplementationGuideTypeDataTypeId.HasValue)
                    {
                        c.datatype   = lGreenConstraint.ImplementationGuideTypeDataType.DataTypeName;
                        c.datatypeId = lGreenConstraint.ImplementationGuideTypeDataType.Id;
                    }
                });
            }

            if (aParentConstraintId.HasValue)
            {
                lGreenViewModel.parentConstraintId = aParentConstraintId.Value;
            }

            int nextConstraintCount = 0;

            foreach (DB.TemplateConstraint cDbConstraint in dbConstraint.ChildConstraints.Where(cc => cc.IsPrimitive == false).OrderBy(y => y.Order))
            {
                ConstraintViewModel nextNewConstraint
                    = BuildConstraint(tdb, baseLink, igSettings, cDbConstraint, ++nextConstraintCount, dbConstraint.Id);
                lGreenViewModel.children.Add(nextNewConstraint);
            }

            return(lGreenViewModel);
        }
        private RuleDefinition ExportElement(TemplateConstraint constraint)
        {
            IFormattedConstraint formattedConstraint = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.igSettings, constraint, null, null, false, false, false, false);
            RuleDefinition       constraintRule      = new RuleDefinition();

            constraintRule.name = constraint.Context;
            constraintRule.minimumMultiplicity = constraint.CardinalityType.Left.ToString();
            constraintRule.maximumMultiplicity = constraint.CardinalityType.Right == Int32.MaxValue ? "*" : constraint.CardinalityType.Right.ToString();
            constraintRule.isMandatory         = constraint.Conformance == "SHALL";
            constraintRule.text = new string[] { formattedConstraint.GetPlainText(false, false, false) };

            var allItems = this.ExportConstraints(constraint);

            // properties and vocabulary
            constraintRule.Items = allItems.Where(y => y.GetType() == typeof(property) || y.GetType() == typeof(vocabulary)).ToArray();

            // attributes
            List <attribute> attributes = new List <attribute>();

            foreach (var attribute in allItems.Where(y => y.GetType() == typeof(attribute)))
            {
                attributes.Add((attribute)attribute);
            }
            constraintRule.attribute = attributes.ToArray();

            // everything else
            constraintRule.Items1 = allItems.Where(y => y.GetType() != typeof(property) && y.GetType() != typeof(vocabulary) && y.GetType() != typeof(attribute)).ToArray();

            return(constraintRule);
        }
        public void GetPlainText_ConformanceTemplateTest2()
        {
            // Test 1004
            TemplateConstraint   constraint = mockRepo.TemplateConstraints.Single(y => y.Id == 5);
            IFormattedConstraint target     = FormattedConstraintFactory.NewFormattedConstraint(mockRepo, igSettings, igTypePlugin, constraint, linkContainedTemplate: linkContainedTemplate, linkIsBookmark: false);
            string constraintText           = target.GetPlainText();

            Assert.AreEqual("MAY contain zero or one [0..1] Test Template 2 (identifier: 1.2.3.4.5.6.5) (CONF:1-5).", constraintText);
        }
Beispiel #6
0
        private void CreateConstraints(IGSettingsManager igManager, IIGTypePlugin igTypePlugin, IEnumerable <TemplateConstraint> constraints, List <ViewDataModel.Constraint> parentList, SimpleSchema templateSchema, SimpleSchema.SchemaObject schemaObject = null)
        {
            foreach (var constraint in constraints.OrderBy(y => y.Order))
            {
                var theConstraint = constraint;

                // TODO: Possible bug? Should schemaObject always be re-set? Remove schemaObject == null from if()
                if (templateSchema != null && schemaObject == null)
                {
                    schemaObject = templateSchema.Children.SingleOrDefault(y => y.Name == constraint.Context);
                }

                IFormattedConstraint fc = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, igManager, igTypePlugin, theConstraint, this.constraintReferences.Cast <ConstraintReference>().ToList(), "#/volume2/", "#/valuesets/#", true, true, true, false);

                var newConstraintModel = new ViewDataModel.Constraint()
                {
                    Number             = string.Format("{0}-{1}", theConstraint.Template.OwningImplementationGuideId, theConstraint.Number),
                    Narrative          = fc.GetHtml(string.Empty, 1, true),
                    Conformance        = theConstraint.Conformance,
                    Cardinality        = theConstraint.Cardinality,
                    Context            = theConstraint.Context,
                    DataType           = theConstraint.DataType,
                    Value              = theConstraint.Value,
                    ValueSetIdentifier = theConstraint.ValueSet != null?theConstraint.ValueSet.GetIdentifier(igTypePlugin) : null,
                                             ValueSetDate = theConstraint.ValueSetDate != null?theConstraint.ValueSetDate.Value.ToShortDateString() : null,
                                                                IsChoice = theConstraint.IsChoice
                };

                newConstraintModel.ContainedTemplates = (from cr in this.constraintReferences
                                                         where cr.TemplateConstraintId == theConstraint.Id
                                                         select new ViewDataModel.TemplateReference()
                {
                    Identifier = cr.Identifier,
                    Bookmark = cr.Bookmark,
                    ImplementationGuide = cr.ImplementationGuide,
                    PublishDate = cr.PublishDate,
                    Name = cr.Name
                }).ToList();

                var isFhir = constraint.Template.ImplementationGuideType.SchemaURI == ImplementationGuideType.FHIR_NS;

                // Check if we're dealing with a FHIR constraint
                if (isFhir && schemaObject != null)
                {
                    newConstraintModel.DataType = schemaObject.DataType;
                }

                parentList.Add(newConstraintModel);

                var nextSchemaObject = schemaObject != null?
                                       schemaObject.Children.SingleOrDefault(y => y.Name == constraint.Context) :
                                           null;

                // Recursively add child constraints
                CreateConstraints(igManager, igTypePlugin, theConstraint.ChildConstraints, newConstraintModel.Constraints, null, nextSchemaObject);
            }
        }
        public void GetPlainText_ConformanceValueCodeSystemTest()
        {
            // Test 1001
            TemplateConstraint   constraint = mockRepo.TemplateConstraints.Single(y => y.Id == 2);
            IFormattedConstraint target     = FormattedConstraintFactory.NewFormattedConstraint(mockRepo, igSettings, igTypePlugin, constraint, linkContainedTemplate: linkContainedTemplate, linkIsBookmark: false);
            string constraintText           = target.GetPlainText();

            Assert.AreEqual("SHALL contain exactly one [1..1] @classCode=\"OBS\" Observation (CodeSystem: HL7ActStatus 113883.5.14) (CONF:1-2).", constraintText);
        }
        public void GetPlainText_ConformanceXpathValueSetTest()
        {
            // Test 1005
            TemplateConstraint   constraint = mockRepo.TemplateConstraints.Single(y => y.Id == 6);
            IFormattedConstraint target     = FormattedConstraintFactory.NewFormattedConstraint(mockRepo, igSettings, igTypePlugin, constraint, linkContainedTemplate: linkContainedTemplate, linkIsBookmark: false);
            string constraintText           = target.GetPlainText();

            Assert.AreEqual("SHALL contain exactly one [1..1] administrativeGenderCode/@code, which MAY be selected from ValueSet GenderCode 11.1 (CONF:1-6).", constraintText);
        }
        public void GetPlainText_ConformanceDataTypeTest()
        {
            // Test 1003
            TemplateConstraint   constraint = mockRepo.TemplateConstraints.Single(y => y.Id == 4);
            IFormattedConstraint target     = FormattedConstraintFactory.NewFormattedConstraint(mockRepo, igSettings, igTypePlugin, constraint, linkContainedTemplate: linkContainedTemplate, linkIsBookmark: false);
            string constraintText           = target.GetPlainText();

            Assert.AreEqual("SHALL contain exactly one [1..1] code with @xsi:type=\"CD\" (CONF:1-4).", constraintText);
        }
        public void GetPlainText_ConformanceTemplateTest1()
        {
            // Test 1002
            TemplateConstraint   constraint = mockRepo.TemplateConstraints.Single(y => y.Id == 3);
            IFormattedConstraint target     = FormattedConstraintFactory.NewFormattedConstraint(mockRepo, igSettings, igTypePlugin, constraint);
            string constraintText           = target.GetPlainText();

            Assert.AreEqual("SHALL contain exactly one [1..1] templateId/@root=\"22.4.47\" (CONF:1-3).", constraintText);
        }
        public string GetNarrative(ConstraintModel constraint)
        {
            IGSettingsManager    igSettings = new IGSettingsManager(this.tdb);
            IFormattedConstraint fc         = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, igSettings, null, constraint, null);

            fc.HasChildren = true;

            return(fc.GetPlainText(false, false, true));
        }
        public void GetPlainText_ContextConformanceTest()
        {
            // Test 1000
            TemplateConstraint   constraint = mockRepo.TemplateConstraints.Single(y => y.Id == 1);
            IFormattedConstraint target     = FormattedConstraintFactory.NewFormattedConstraint(mockRepo, igSettings, constraint, linkContainedTemplate: linkContainedTemplate, linkIsBookmark: false);
            string constraintText           = target.GetPlainText();

            Assert.AreEqual("SHALL contain exactly one [1..1] value (CONF:1-1).", constraintText);
        }
        public void GetPlainText_ConformanceValueCodeSystemTest2()
        {
            // Test 1007
            TemplateConstraint   constraint = mockRepo.TemplateConstraints.Single(y => y.Id == 8);
            IGSettingsManager    igSettings = new IGSettingsManager(this.mockRepo, constraint.Template.OwningImplementationGuideId);
            IFormattedConstraint target     = FormattedConstraintFactory.NewFormattedConstraint(mockRepo, igSettings, constraint, linkContainedTemplate: linkContainedTemplate);
            string constraintText           = target.GetPlainText();

            Assert.AreEqual("SHALL contain exactly one [1..1] code/@code=\"1234-X\" Test Disp, which SHALL be selected from CodeSystem SNOMED CT (6.96) (CONF:1-8).", constraintText);
        }
        public void GetPlainText_ConformanceValueWithConformanceCodeSystemTest()
        {
            // Test 1008
            TemplateConstraint   constraint = mockRepo.TemplateConstraints.Single(y => y.Id == 9);
            IGSettingsManager    igSettings = new IGSettingsManager(this.mockRepo, constraint.Template.OwningImplementationGuideId);
            IFormattedConstraint target     = FormattedConstraintFactory.NewFormattedConstraint(mockRepo, igSettings, igTypePlugin, constraint, linkContainedTemplate: linkContainedTemplate, linkIsBookmark: false);
            string constraintText           = target.GetPlainText();

            Assert.AreEqual("SHALL contain exactly one [1..1] code=\"1234-X\" Test Disp with @xsi:type=\"CD\", where the code SHALL be selected from CodeSystem SNOMED CT (6.96) (CONF:1-9).", constraintText);
        }
        public void GetPlainText_ConformanceValueCodeSystemTest1()
        {
            // Test 1006
            TemplateConstraint   constraint = mockRepo.TemplateConstraints.Single(y => y.Id == 7);
            IGSettingsManager    igSettings = new IGSettingsManager(this.mockRepo, constraint.Template.OwningImplementationGuideId);
            IFormattedConstraint target     = FormattedConstraintFactory.NewFormattedConstraint(mockRepo, igSettings, igTypePlugin, constraint, linkContainedTemplate: linkContainedTemplate);
            string constraintText           = target.GetPlainText();

            Assert.AreEqual("SHALL contain exactly one [1..1] statusCode=\"completed\" Completed (CodeSystem: HL7ActStatus 113883.5.14) (CONF:1-7).", constraintText);
        }
Beispiel #16
0
        private void AddTemplateConstraint(TemplateConstraint constraint, int level, bool aCreateLinksForValueSets, bool includeNotes)
        {
            // Skip the child constraints if this is a choice there is only one child constraint. This constraint
            // adopts the constraint narrative of the child constraint when there is only one option.
            if (constraint.IsChoice && constraint.ChildConstraints.Count == 1)
            {
                constraint = constraint.ChildConstraints.First();
            }

            // TODO: May be able to make this more efficient
            List <TemplateConstraint> childConstraints = this.AllConstraints
                                                         .Where(y => y.ParentConstraintId == constraint.Id)
                                                         .OrderBy(y => y.Order)
                                                         .ToList();

            this.templateConstraintCount++;

            // All contained template references must exist in the list of templates being exported to be linked
            // TODO: Improve so that not all references have to be in the export for some to be linked
            var containedTemplateReferences = constraint.References.Where(y => y.ReferenceType == ConstraintReferenceTypes.Template);
            var containedTemplatesFound     = (from ct in containedTemplateReferences
                                               join t in this.AllTemplates on ct.ReferenceIdentifier equals t.Oid
                                               select t);
            bool containedTemplateLinked = containedTemplateReferences.Count() > 0 && containedTemplateReferences.Count() == containedTemplatesFound.Count();

            bool includeCategory             = this.IncludeCategory && (!this.HasSelectedCategories || this.SelectedCategories.Count > 1);
            IFormattedConstraint fConstraint = FormattedConstraintFactory.NewFormattedConstraint(this.DataSource, this.IGSettings, this.IGTypePlugin, constraint, this.ConstraintReferences, linkContainedTemplate: containedTemplateLinked, linkIsBookmark: true, createLinksForValueSets: aCreateLinksForValueSets, includeCategory: includeCategory);
            Paragraph            para        = fConstraint.AddToDocParagraph(this.MainPart, this.HyperlinkTracker, this.DocumentBody, level - 1, GenerationConstants.BASE_TEMPLATE_INDEX + (int)this.CurrentTemplate.Id, this.ConstraintHeadingStyle);

            if (!string.IsNullOrEmpty(constraint.Notes) && includeNotes)
            {
                this.CommentManager.AddCommentRange(para, constraint.Notes);
            }

            // Add child constraints
            foreach (TemplateConstraint cConstraint in childConstraints)
            {
                if (this.HasSelectedCategories && !cConstraint.CategoryIsMatch(this.SelectedCategories))
                {
                    continue;
                }

                this.AddTemplateConstraint(cConstraint, level + 1, aCreateLinksForValueSets, includeNotes);
            }

            // Add samples for the constraint if it is a heading and the settings indicate to include samples
            if (constraint.IsHeading && this.IncludeSamples)
            {
                foreach (var cSample in constraint.Samples)
                {
                    this.Figures.AddSample(cSample.Name, cSample.SampleText);
                }
            }
        }
Beispiel #17
0
        public void TestFormattedConstraint_ContainedTemplate2()
        {
            TemplateConstraint ctConstraint = this.mockRepo.TemplateConstraints.Last(y => y.ContainedTemplateId != null);
            IGSettingsManager  igSettings   = new IGSettingsManager(this.mockRepo, ctConstraint.Template.OwningImplementationGuideId);

            IFormattedConstraint fc = FormattedConstraintFactory.NewFormattedConstraint(mockRepo, igSettings, ctConstraint);
            string constraintText   = fc.GetPlainText();

            Assert.IsNotNull(constraintText);
            Assert.AreEqual("This entry SHALL contain exactly one [1..1] Test Template 2 (identifier: 1.2.3.4.5.6) (CONF:1-9).", constraintText);
        }
Beispiel #18
0
        public void TestFormattedConstraint_ContainedTemplate2()
        {
            TemplateConstraint ctConstraint = this.mockRepo.TemplateConstraints.Last(y => y.References.Any(x => x.ReferenceType == ConstraintReferenceTypes.Template));
            IGSettingsManager  igSettings   = new IGSettingsManager(this.mockRepo, ctConstraint.Template.OwningImplementationGuideId);
            IIGTypePlugin      igTypePlugin = ctConstraint.Template.OwningImplementationGuide.ImplementationGuideType.GetPlugin();

            IFormattedConstraint fc = FormattedConstraintFactory.NewFormattedConstraint(mockRepo, igSettings, igTypePlugin, ctConstraint);
            string constraintText   = fc.GetPlainText();

            Assert.IsNotNull(constraintText);
            Assert.AreEqual("This entry SHALL contain exactly one [1..1] Test Template 2 (identifier: 1.2.3.4.5.6) (CONF:1-13).", constraintText);
        }
        private attribute ExportAttribute(TemplateConstraint constraint)
        {
            IFormattedConstraint formattedConstraint = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.igSettings, constraint, null, null, false, false, false, false);
            attribute            constraintAttribute = new attribute();

            constraintAttribute.name       = constraint.Context.Substring(1);
            constraintAttribute.isOptional = constraint.Conformance != "SHALL";

            constraintAttribute.Items = this.ExportConstraints(constraint, true);

            return(constraintAttribute);
        }
        public void GetPlainText_ConformanceValueSetVersionTest()
        {
            // Test 1005
            TemplateConstraint constraint = mockRepo.TemplateConstraints.Single(y => y.Id == 6);

            constraint.Context      = "administrativeGenderCode";
            constraint.ValueSetDate = new DateTime(2012, 5, 1);

            IGSettingsManager    igSettings = new IGSettingsManager(this.mockRepo, constraint.Template.OwningImplementationGuideId);
            IFormattedConstraint target     = FormattedConstraintFactory.NewFormattedConstraint(mockRepo, igSettings, igTypePlugin, constraint, linkContainedTemplate: linkContainedTemplate, linkIsBookmark: false);
            string constraintText           = target.GetPlainText();

            Assert.AreEqual("SHALL contain exactly one [1..1] administrativeGenderCode, which MAY be selected from ValueSet GenderCode 11.1 2012-05-01 (CONF:1-6).", constraintText);
        }
        public void GetPlainText_CategorizedConstraint()
        {
            TemplateConstraint constraint = mockRepo.TemplateConstraints.Single(y => y.Id == 10);

            // Test WITH categories enabled
            IGSettingsManager    igSettings = new IGSettingsManager(this.mockRepo, constraint.Template.OwningImplementationGuideId);
            IFormattedConstraint target     = FormattedConstraintFactory.NewFormattedConstraint(mockRepo, igSettings, igTypePlugin, constraint, linkContainedTemplate: linkContainedTemplate, linkIsBookmark: false, includeCategory: true);
            string constraintText           = target.GetPlainText();

            Assert.AreEqual("[TestCategory] SHALL contain exactly one [1..1] code (CONF:1-10).", constraintText);

            // Test WITHOUT categories enabled
            target         = FormattedConstraintFactory.NewFormattedConstraint(mockRepo, igSettings, igTypePlugin, constraint, linkContainedTemplate: linkContainedTemplate, includeCategory: false);
            constraintText = target.GetPlainText();

            Assert.AreEqual("SHALL contain exactly one [1..1] code (CONF:1-10).", constraintText);
        }
Beispiel #22
0
        private RuleDefinition ExportElement(TemplateConstraint constraint)
        {
            string context = constraint.Context;

            if (string.IsNullOrEmpty(context) && constraint.References.Count(y => y.ReferenceType == ConstraintReferenceTypes.Template) > 0)
            {
                string firstReferenceIdentifier = constraint.References.First(y => y.ReferenceType == ConstraintReferenceTypes.Template).ReferenceIdentifier;
                var    firstReferenceTemplate   = this.tdb.Templates.Single(y => y.Oid == firstReferenceIdentifier);

                if (firstReferenceTemplate != null)
                {
                    context = firstReferenceTemplate.PrimaryContext;
                }
            }

            IFormattedConstraint formattedConstraint = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.igSettings, this.igTypePlugin, constraint, null, null, null, false, false, false, false);
            RuleDefinition       constraintRule      = new RuleDefinition();

            constraintRule.name = context;
            constraintRule.minimumMultiplicity = constraint.CardinalityType.Left.ToString();
            constraintRule.maximumMultiplicity = constraint.CardinalityType.Right == Int32.MaxValue ? "*" : constraint.CardinalityType.Right.ToString();
            constraintRule.isMandatory         = constraint.Conformance == "SHALL";
            constraintRule.text = new string[] { formattedConstraint.GetPlainText(false, false, false) };

            var allItems = this.ExportConstraints(constraint);

            // properties and vocabulary
            constraintRule.Items = allItems.Where(y => y.GetType() == typeof(property) || y.GetType() == typeof(vocabulary)).ToArray();

            // attributes
            List <attribute> attributes = new List <attribute>();

            foreach (var attribute in allItems.Where(y => y.GetType() == typeof(attribute)))
            {
                attributes.Add((attribute)attribute);
            }
            constraintRule.attribute = attributes.ToArray();

            // everything else
            constraintRule.Items1 = allItems.Where(y => y.GetType() != typeof(property) && y.GetType() != typeof(vocabulary) && y.GetType() != typeof(attribute)).ToArray();

            return(constraintRule);
        }
        public PublishConstraint(TemplateConstraint constraint, IFormattedConstraint fc)
        {
            this.ChildConstraints = new ObservableCollection <PublishConstraint>();
            this.Samples          = new ObservableCollection <ConstraintSample>();
            this.DisplayText      = fc.GetPlainText();

            this.ConstraintDescription = constraint.Description;
            this.ConstraintLabel       = constraint.Label;
            this.HeadingDescription    = constraint.HeadingDescription;
            this.Id            = constraint.Id;
            this.IsHeading     = constraint.IsHeading;
            this.IsPrimitive   = constraint.IsPrimitive;
            this.PrimitiveText = constraint.PrimitiveText;
            this.TemplateId    = constraint.TemplateId;
            this.Context       = constraint.Context;
            this.Conformance   = constraint.Conformance;
            this.Cardinality   = constraint.Cardinality;
            this.Value         = constraint.Value;
        }
        private PublishConstraint BuildConstraint(
            DB.IObjectRepository tdb,
            string baseLink,
            IGSettingsManager igSettings,
            IIGTypePlugin igTypePlugin,
            DB.TemplateConstraint dbConstraint,
            int constraintCount,
            int?aParentConstraintId = null)
        {
            IFormattedConstraint fc = FormattedConstraintFactory.NewFormattedConstraint(tdb, igSettings, igTypePlugin, dbConstraint);

            PublishConstraint newConstraint = new PublishConstraint(dbConstraint, fc);

            foreach (DB.TemplateConstraintSample lSample in dbConstraint.Samples)
            {
                ConstraintSample lSampleView = new ConstraintSample()
                {
                    Id           = lSample.Id,
                    Name         = lSample.Name,
                    SampleText   = lSample.SampleText,
                    ConstraintId = dbConstraint.Id
                };
                newConstraint.Samples.Add(lSampleView);
            }

            if (aParentConstraintId.HasValue)
            {
                newConstraint.ParentConstraintId = aParentConstraintId.Value;
            }

            int nextConstraintCount = 0;

            foreach (DB.TemplateConstraint cDbConstraint in dbConstraint.ChildConstraints.OrderBy(y => y.Order))
            {
                PublishConstraint nextNewConstraint
                    = BuildConstraint(tdb, baseLink, igSettings, igTypePlugin, cDbConstraint, ++nextConstraintCount, dbConstraint.Id);
                newConstraint.ChildConstraints.Add(nextNewConstraint);
            }

            return(newConstraint);
        }
Beispiel #25
0
        private void AddTemplateConstraint(TemplateConstraint constraint, int level, bool aCreateLinksForValueSets, bool includeNotes)
        {
            // TODO: May be able to make this more efficient
            List <TemplateConstraint> childConstraints = allConstraints
                                                         .Where(y => y.ParentConstraintId == constraint.Id)
                                                         .OrderBy(y => y.Order)
                                                         .ToList();

            this.templateConstraintCount++;

            bool containedTemplateLinked     = constraint.ContainedTemplateId != null && this.allTemplates.Exists(y => y.Id == constraint.ContainedTemplateId);
            bool includeCategory             = this.IncludeCategory && (!this.HasSelectedCategories || this.SelectedCategories.Count > 1);
            IFormattedConstraint fConstraint = FormattedConstraintFactory.NewFormattedConstraint(this.dataSource, this.igSettings, constraint, linkContainedTemplate: containedTemplateLinked, linkIsBookmark: true, createLinksForValueSets: aCreateLinksForValueSets, includeCategory: includeCategory);
            Paragraph            para        = fConstraint.AddToDocParagraph(this.wikiParser, this.DocumentBody, level - 1, GenerationConstants.BASE_TEMPLATE_INDEX + (int)currentTemplate.Id, this.constraintHeadingStyle);

            if (!string.IsNullOrEmpty(constraint.Notes) && includeNotes)
            {
                this.CommentManager.AddCommentRange(para, constraint.Notes);
            }

            // Add child constraints
            foreach (TemplateConstraint cConstraint in childConstraints)
            {
                if (this.HasSelectedCategories && !cConstraint.CategoryIsMatch(this.SelectedCategories))
                {
                    continue;
                }

                this.AddTemplateConstraint(cConstraint, level + 1, aCreateLinksForValueSets, includeNotes);
            }

            // Add samples for the constraint if it is a heading and the settings indicate to include samples
            if (constraint.IsHeading && this.IncludeSamples)
            {
                foreach (var cSample in constraint.Samples)
                {
                    figures.AddSample(cSample.Name, cSample.SampleText);
                }
            }
        }
        private ConstraintModel CreateConstraintModel(TemplateConstraint constraint, IGSettingsManager igSettings, IIGTypePlugin igTypePlugin)
        {
            IFormattedConstraint fc = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, igSettings, igTypePlugin, constraint);

            var newConstraintModel = new ConstraintModel()
            {
                Id                 = constraint.Id,
                Number             = constraint.Number.Value,
                DisplayNumber      = constraint.DisplayNumber,
                IsNew              = false,
                Context            = constraint.Context,
                Conformance        = constraint.Conformance,
                Cardinality        = constraint.Cardinality,
                DataType           = constraint.DataType == null ? string.Empty : constraint.DataType,
                IsBranch           = constraint.IsBranch,
                IsBranchIdentifier = constraint.IsBranchIdentifier,
                Description        = constraint.Description,
                Notes              = constraint.Notes,
                Label              = constraint.Label,
                PrimitiveText      = constraint.PrimitiveText,
                Value              = constraint.Value,
                ValueDisplayName   = constraint.ValueDisplayName,
                ValueSetId         = constraint.ValueSetId,
                ValueSetDate       = constraint.ValueSetDate,
                ValueCodeSystemId  = constraint.CodeSystemId,
                IsPrimitive        = constraint.IsPrimitive,
                IsHeading          = constraint.IsHeading,
                HeadingDescription = constraint.HeadingDescription,
                IsInheritable      = constraint.IsInheritable,
                IsSchRooted        = constraint.IsSchRooted,
                ValueConformance   = constraint.ValueConformance,
                Schematron         = constraint.Schematron,
                Category           = constraint.Category,
                IsModifier         = constraint.IsModifier,
                MustSupport        = constraint.MustSupport,
                IsChoice           = constraint.IsChoice,
                IsFixed            = constraint.IsFixed,

                NarrativeProseHtml = fc.GetPlainText(false, false, false)
            };

            newConstraintModel.References = (from tcr in constraint.References
                                             join t in this.tdb.Templates on tcr.ReferenceIdentifier equals t.Oid
                                             where tcr.ReferenceType == ConstraintReferenceTypes.Template
                                             select new ConstraintReferenceModel()
            {
                Id = tcr.Id,
                ReferenceIdentifier = tcr.ReferenceIdentifier,
                ReferenceType = tcr.ReferenceType,
                ReferenceDisplay = t.Name
            }).ToList();

            if (constraint.IsStatic == true)
            {
                newConstraintModel.Binding = "STATIC";
            }
            else if (constraint.IsStatic == false)
            {
                newConstraintModel.Binding = "DYNAMIC";
            }
            else
            {
                newConstraintModel.Binding = "DEFAULT";
            }

            List <ConstraintModel> children = newConstraintModel.Children as List <ConstraintModel>;

            foreach (TemplateConstraint childConstraint in constraint.ChildConstraints.OrderBy(y => y.Order))
            {
                var newChildConstraintModel = CreateConstraintModel(childConstraint, igSettings, igTypePlugin);
                children.Add(newChildConstraintModel);
            }

            return(newConstraintModel);
        }
Beispiel #27
0
        /// <summary>
        /// Compares the previous template to the new template in two stages; first the fields of the templates and then the constraints of the templates.
        /// The comparison between constraints are based on the IConstraint.Number field for matching the constraints together.
        /// </summary>
        /// <remarks>
        /// Template fields: Name, Oid, Description, Is Open, Implied Template
        /// Constraint fields: Description, Label, Conformance, Cardinality, DataType, Value, Display Name, ValueSet Date, Value Set, Code System, Contained Template
        /// </remarks>
        /// <returns>A ComparisonResult instance which contains the differences between the old and new templates fields
        /// and a list of ComparisonConstraintResult instances that represents each modified constraint.</returns>
        public ComparisonResult Compare(ITemplate previousTemplate, ITemplate newTemplate)
        {
            this.result = new ComparisonResult();

            this.CompareTemplate(previousTemplate, newTemplate);

            if (newTemplate.Status != PublishStatus.RETIRED_STATUS)
            {
                // Added constraints
                foreach (var cConstraint in newTemplate.Constraints.Where(b => !previousTemplate.Constraints.Exists(a => a.Number == b.Number)))
                {
                    IFormattedConstraint fc = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.igSettings, this.igTypePlugin, cConstraint, null);

                    ComparisonConstraintResult cResult = new ComparisonConstraintResult()
                    {
                        ParentNumber = cConstraint.Parent != null?
                                       string.Format("{0}-{1}", cConstraint.Template.OwningImplementationGuideId, cConstraint.Parent.Number) :
                                           null,
                                           Number       = string.Format("{0}-{1}", cConstraint.Template.OwningImplementationGuideId, cConstraint.Number.Value),
                                           Order        = cConstraint.Order,
                                           Type         = CompareStatuses.Added,
                                           NewNarrative = fc.GetPlainText()
                    };

                    this.result.ChangedConstraints.Add(cResult);
                }

                // Deleted constraints
                foreach (var cConstraint in previousTemplate.Constraints.Where(a => !newTemplate.Constraints.Exists(b => b.Number == a.Number)))
                {
                    IFormattedConstraint fc = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.igSettings, this.igTypePlugin, cConstraint, null);

                    ComparisonConstraintResult cResult = new ComparisonConstraintResult()
                    {
                        ParentNumber = cConstraint.Parent != null?
                                       string.Format("{0}-{1}", cConstraint.Parent.Template.OwningImplementationGuideId, cConstraint.Parent.Number) :
                                           null,
                                           Number       = string.Format("{0}-{1}", cConstraint.Template.OwningImplementationGuideId, cConstraint.Number),
                                           Order        = cConstraint.Order,
                                           Type         = CompareStatuses.Removed,
                                           OldNarrative = fc.GetPlainText()
                    };

                    this.result.ChangedConstraints.Add(cResult);
                }

                // Modified constraints
                foreach (var oldConstraint in previousTemplate.Constraints.Where(a => newTemplate.Constraints.Exists(b => b.Number == a.Number)))
                {
                    var newConstraint = newTemplate.Constraints.Single(b => b.Number == oldConstraint.Number);

                    ComparisonConstraintResult compareResult = this.CompareConstraint(this.igSettings, oldConstraint, newConstraint);

                    if (compareResult != null)
                    {
                        result.ChangedConstraints.Add(compareResult);
                    }
                }
            }

            return(this.result);
        }
        private object[] ExportConstraints(TemplateConstraint parentConstraint = null, bool isAttribute = false)
        {
            List <object> constraintRules = new List <object>();

            if (parentConstraint != null)
            {
                if (parentConstraint.ValueSet != null || parentConstraint.CodeSystem != null || !string.IsNullOrEmpty(parentConstraint.Value))
                {
                    vocabulary vocabConstraint = new vocabulary();

                    if (parentConstraint.ValueSet != null)
                    {
                        vocabConstraint.valueSet = parentConstraint.ValueSet.Oid;

                        string oid, ext;

                        if (IdentifierHelper.IsIdentifierOID(parentConstraint.ValueSet.Oid))
                        {
                            IdentifierHelper.GetIdentifierOID(parentConstraint.ValueSet.Oid, out oid);
                            vocabConstraint.valueSet = oid;
                        }
                        else if (IdentifierHelper.IsIdentifierII(parentConstraint.ValueSet.Oid))
                        {
                            IdentifierHelper.GetIdentifierII(parentConstraint.ValueSet.Oid, out oid, out ext);
                            vocabConstraint.valueSet = oid;
                        }
                    }

                    if (parentConstraint.CodeSystem != null)
                    {
                        vocabConstraint.codeSystem     = parentConstraint.CodeSystem.Oid;
                        vocabConstraint.codeSystemName = parentConstraint.CodeSystem.Name;

                        string oid, ext;

                        if (IdentifierHelper.IsIdentifierOID(parentConstraint.CodeSystem.Oid))
                        {
                            IdentifierHelper.GetIdentifierOID(parentConstraint.CodeSystem.Oid, out oid);
                            vocabConstraint.codeSystem = oid;
                        }
                        else if (IdentifierHelper.IsIdentifierII(parentConstraint.CodeSystem.Oid))
                        {
                            IdentifierHelper.GetIdentifierII(parentConstraint.CodeSystem.Oid, out oid, out ext);
                            vocabConstraint.codeSystem = oid;
                        }
                    }

                    if (!string.IsNullOrEmpty(parentConstraint.Value))
                    {
                        vocabConstraint.code = parentConstraint.Value;
                    }

                    if (!string.IsNullOrEmpty(parentConstraint.DisplayName))
                    {
                        vocabConstraint.displayName = parentConstraint.DisplayName;
                    }

                    if (parentConstraint.IsStatic == true && parentConstraint.ValueSetDate != null)
                    {
                        vocabConstraint.flexibility = parentConstraint.ValueSetDate.Value.ToString("yyyy-MM-ddThh:mm:ss");
                    }
                    else if (parentConstraint.IsStatic == false)
                    {
                        vocabConstraint.flexibility = "dynamic";
                    }

                    constraintRules.Add(vocabConstraint);
                }
            }

            foreach (var constraint in this.template.ChildConstraints.Where(y => y.ParentConstraintId == (parentConstraint != null ? parentConstraint.Id : (int?)null)))
            {
                if (!constraint.IsPrimitive)
                {
                    if (isAttribute)
                    {
                        continue;       // Can't export child elements/attributes of an attribute constraint
                    }
                    if (constraint.Context.StartsWith("@"))
                    {
                        constraintRules.Add(this.ExportAttribute(constraint));
                    }
                    else
                    {
                        constraintRules.Add(this.ExportElement(constraint));
                    }
                }
                else
                {
                    IFormattedConstraint formattedConstraint = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.igSettings, constraint, null, null, false, false, false, false);

                    XmlNode[] anyField = new XmlNode[] { this.dom.CreateTextNode(formattedConstraint.GetPlainText(false, false, false)) };
                    constraintRules.Add(new FreeFormMarkupWithLanguage()
                    {
                        Any = anyField
                    });
                }
            }

            return(constraintRules.ToArray());
        }
Beispiel #29
0
        public static ExportConstraint Export(this TemplateConstraint constraint, IObjectRepository tdb, IGSettingsManager igSettings, IIGTypePlugin igTypePlugin, bool isVerbose = false, List <string> categories = null)
        {
            ExportConstraint exportConstraint = new ExportConstraint()
            {
                number             = constraint.Number != null ? constraint.Number.Value : 0,
                numberSpecified    = constraint.Number != null,
                displayNumber      = constraint.DisplayNumber,
                context            = constraint.Context,
                conformance        = GetExportConformance(constraint.Conformance),
                cardinality        = !string.IsNullOrEmpty(constraint.Cardinality) ? constraint.Cardinality : null,
                dataType           = !string.IsNullOrEmpty(constraint.DataType) ? constraint.DataType : null,
                isBranch           = constraint.IsBranch,
                isBranchIdentifier = constraint.IsBranchIdentifier,
                isSchRooted        = constraint.IsSchRooted,
                isPrimitive        = constraint.IsPrimitive,
                isStatic           = constraint.IsStatic == true,
                isStaticSpecified  = constraint.IsStatic != null,
                isInheritable      = constraint.IsInheritable,
                SchematronTest     = !string.IsNullOrEmpty(constraint.Schematron) ? constraint.Schematron : null,
                isVerbose          = isVerbose,
                mustSupport        = constraint.MustSupport,
                isModifier         = constraint.IsModifier,
                isHeading          = constraint.IsHeading,
                HeadingDescription = constraint.HeadingDescription,
                Notes = constraint.Notes,
                Label = constraint.Label
            };

            var containedTemplates = (from tcr in constraint.References
                                      join t in tdb.Templates on tcr.ReferenceIdentifier equals t.Oid
                                      where tcr.ReferenceType == ConstraintReferenceTypes.Template
                                      select t);

            foreach (var containedTemplate in containedTemplates)
            {
                exportConstraint.ContainedTemplate.Add(new Shared.ImportExport.Model.ConstraintTypeContainedTemplate()
                {
                    identifier = containedTemplate.Oid,
                    type       = containedTemplate.PrimaryContextType
                });
            }

            if (!string.IsNullOrEmpty(constraint.Category))
            {
                exportConstraint.Category = (from c in constraint.Category.Split(',')
                                             select new ExportCategory()
                {
                    name = c
                }).ToList();
            }

            if (!string.IsNullOrEmpty(constraint.Value))
            {
                ExportSingleValueCode exportSVC = new ExportSingleValueCode()
                {
                    code        = constraint.Value,
                    displayName = constraint.DisplayName
                };
                exportConstraint.Item = exportSVC;
            }
            else if (constraint.ValueSet != null)
            {
                ExportValueSet exportValueSet = new ExportValueSet()
                {
                    name              = constraint.ValueSet.Name,
                    isStatic          = constraint.IsStatic == true,
                    isStaticSpecified = constraint.IsStatic != null,
                    identifier        = constraint.ValueSet.GetIdentifier(igTypePlugin),
                    date              = constraint.ValueSetDate.HasValue ? constraint.ValueSetDate.Value : DateTime.MinValue,
                    dateSpecified     = constraint.ValueSetDate.HasValue
                };
                exportConstraint.Item = exportValueSet;
            }

            if (constraint.CodeSystem != null)
            {
                exportConstraint.CodeSystem = new ExportCodeSystem()
                {
                    identifier = constraint.CodeSystem.Oid,
                    name       = constraint.CodeSystem.Name
                };
            }
            else
            {
                exportConstraint.CodeSystem = null;
            }

            if (!string.IsNullOrEmpty(constraint.Description))
            {
                exportConstraint.Description = constraint.Description;
            }

            if (!string.IsNullOrEmpty(constraint.Label))
            {
                exportConstraint.Label = constraint.Label;
            }

            if (!constraint.IsPrimitive)
            {
                IFormattedConstraint fc = FormattedConstraintFactory.NewFormattedConstraint(tdb, igSettings, igTypePlugin, constraint);

                // Only include the generated narrative, as Description and Label are already exported in separate fields.
                exportConstraint.NarrativeText = fc.GetPlainText(false, false, false);
            }
            else
            {
                exportConstraint.NarrativeText = constraint.PrimitiveText;
            }

            // Get all child constraints and build a new export-version of the constraint
            var childConstraints = constraint.ChildConstraints.Where(y => y.ParentConstraintId == constraint.Id).OrderBy(y => y.Order);

            foreach (var cChildConstraint in childConstraints)
            {
                if (!cChildConstraint.CategoryIsMatch(categories))
                {
                    continue;
                }

                exportConstraint.Constraint.Add(cChildConstraint.Export(tdb, igSettings, igTypePlugin, isVerbose, categories));
            }

            return(exportConstraint);
        }