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); }
/// <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)); }
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 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)); }
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_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_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 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); }
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_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_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_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); }
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_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 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); }
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 ComparisonConstraintResult CompareConstraint(IGSettingsManager igSettings, IConstraint oldConstraint, IConstraint newConstraint) { var oldFc = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.igSettings, this.igTypePlugin, oldConstraint, null); var newFc = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.igSettings, this.igTypePlugin, newConstraint, null); var newNarrative = newFc.GetPlainText(); var oldNarrative = oldFc.GetPlainText(); var cResult = new ComparisonConstraintResult { ParentNumber = newConstraint.Parent != null ? string.Format("{0}-{1}", newConstraint.Parent.Template.OwningImplementationGuideId, newConstraint.Parent.Number) : null, Number = string.Format("{0}-{1}", newConstraint.Template.OwningImplementationGuideId, newConstraint.Number.Value), Order = newConstraint.Order, NewNarrative = newNarrative, OldNarrative = oldNarrative }; // If all that changed was the CONF number, then treat as unchanged. if (newNarrative.IndexOf("(CONF") >= 0 && oldNarrative.IndexOf("(CONF") >= 0) { var newNarrativeCompare = newNarrative.Substring(0, newNarrative.IndexOf("(CONF")); var oldNarrativeCompare = oldNarrative.Substring(0, oldNarrative.IndexOf("(CONF")); cResult.Type = newNarrativeCompare != oldNarrativeCompare ? CompareStatuses.Modified : CompareStatuses.Unchanged; } else { cResult.Type = newNarrative != oldNarrative ? CompareStatuses.Modified : CompareStatuses.Unchanged; } if (!oldConstraint.IsPrimitive && cResult.Type != CompareStatuses.Unchanged) { CheckField(cResult, "Description", oldConstraint.Description, newConstraint.Description); CheckField(cResult, "Label", oldConstraint.Label, newConstraint.Label); CheckField(cResult, "Conformance", oldConstraint.Conformance, newConstraint.Conformance); CheckField(cResult, "Cardinality", oldConstraint.Cardinality, newConstraint.Cardinality); CheckField(cResult, "DataType", oldConstraint.DataType, newConstraint.DataType); CheckField(cResult, "Value", oldConstraint.Value, newConstraint.Value); CheckField(cResult, "Display Name", oldConstraint.ValueDisplayName, newConstraint.ValueDisplayName); CheckField(cResult, "ValueSet Date", oldConstraint.ValueSetDate, newConstraint.ValueSetDate); CheckField(cResult, "ValueSet", GetValueSetDisplay(oldConstraint), GetValueSetDisplay(newConstraint)); CheckField(cResult, "Code System", GetCodeSystemDisplay(oldConstraint), GetCodeSystemDisplay(newConstraint)); CheckField(cResult, "Contained Template", GetContainedTemplateDisplay(oldConstraint), GetContainedTemplateDisplay(newConstraint)); } return(cResult); }
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 SingleChild() { var templateType = this.tdb.FindOrCreateTemplateType(this.fhirIg.ImplementationGuideType, "Observation"); var template = this.tdb.CreateTemplate("http://test.com", templateType, "Test Observation", this.fhirIg); var c1 = this.tdb.AddConstraintToTemplate(template, null, null, "effective[x]", "SHALL", "1..1", isChoice: true); var c2 = this.tdb.AddConstraintToTemplate(template, c1, null, "effectiveDateTime"); var c1fc = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.fhirIgSettings, this.fhirIgTypePlugin, c1); var c1Text = c1fc.GetPlainText(); var c2fc = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.fhirIgSettings, this.fhirIgTypePlugin, c2); var c2Text = c2fc.GetPlainText(); Assert.AreEqual("SHALL contain exactly one [1..1] effective[x], where effective[x] is (CONF:2-1)", c1Text); Assert.AreEqual("effectiveDateTime (CONF:2-2)", c2Text); }
public void SingleChildWithSingleValueBinding() { var templateType = this.tdb.FindOrCreateTemplateType(this.fhirIg.ImplementationGuideType, "Extension"); var template = this.tdb.CreateTemplate("http://test.com", templateType, "Test Extension", this.fhirIg); var c1 = this.tdb.AddConstraintToTemplate(template, null, null, "value[x]", "SHALL", "1..1", isChoice: true); var c2 = this.tdb.AddConstraintToTemplate(template, c1, null, "valueCodeableConcept", value: "1234-x", displayName: "Test Value"); var c1fc = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.fhirIgSettings, this.fhirIgTypePlugin, c1); var c1Text = c1fc.GetPlainText(); var c2fc = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.fhirIgSettings, this.fhirIgTypePlugin, c2); var c2Text = c2fc.GetPlainText(); Assert.AreEqual("SHALL contain exactly one [1..1] value[x], where value[x] is (CONF:2-1)", c1Text); Assert.AreEqual("valueCodeableConcept=\"1234-x\" Test Value (CONF:2-2)", c2Text); }
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); }
public void SingleChildWithContainedTemplate() { var templateType = this.tdb.FindOrCreateTemplateType(this.fhirIg.ImplementationGuideType, "Extension"); var templateType2 = this.tdb.FindOrCreateTemplateType(this.fhirIg.ImplementationGuideType, "Observation"); var template = this.tdb.CreateTemplate("http://test.com", templateType, "Test Extension", this.fhirIg); var template2 = this.tdb.CreateTemplate("http://test2.com", templateType2, "Test Observation", this.fhirIg); var c1 = this.tdb.AddConstraintToTemplate(template, null, null, "value[x]", "SHALL", "1..1", isChoice: true); var c2 = this.tdb.AddConstraintToTemplate(template, c1, template2, "valueReference"); var c1fc = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.fhirIgSettings, this.fhirIgTypePlugin, c1); var c1Text = c1fc.GetPlainText(); var c2fc = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.fhirIgSettings, this.fhirIgTypePlugin, c2); var c2Text = c2fc.GetPlainText(); Assert.AreEqual("SHALL contain exactly one [1..1] value[x], where value[x] is (CONF:2-1)", c1Text); Assert.AreEqual("valueReference which includes Test Observation (identifier: http://test2.com) (CONF:2-2)", c2Text); }
public void PrimitiveTextFormattingTest1() { var repo = new MockObjectRepository(); TemplateConstraint newConstraint = new TemplateConstraint() { Number = 1234, IsPrimitive = true, PrimitiveText = "This entry SHALL contain X which SHALL NOT contain Y" }; var formattedConstraint = FormattedConstraintFactory.NewFormattedConstraint(repo, new IGSettingsManager(repo), newConstraint); WIKIParser wikiParser = new WIKIParser(repo); Document newDoc = new Document(); formattedConstraint.AddToDocParagraph(wikiParser, newDoc, 1, 1, ""); }
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); }
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); }
public void PrimitiveTextFormattingTest1() { var repo = new MockObjectRepository(); TemplateConstraint newConstraint = new TemplateConstraint() { Number = 1234, IsPrimitive = true, PrimitiveText = "This entry SHALL contain X which SHALL NOT contain Y" }; IGSettingsManager igSettings = new IGSettingsManager(repo); HyperlinkTracker hyperlinkTracker = new HyperlinkTracker(); var formattedConstraint = FormattedConstraintFactory.NewFormattedConstraint(repo, igSettings, null, newConstraint); using (MemoryStream ms = new MemoryStream()) { var doc = WordprocessingDocument.Create(ms, WordprocessingDocumentType.Document); var mainPart = doc.AddMainDocumentPart(); mainPart.Document = new Document(); formattedConstraint.AddToDocParagraph(mainPart, hyperlinkTracker, mainPart.Document, 1, 1, ""); } }
public void CreateElementDefinition( StructureDefinition strucDef, TemplateConstraint constraint, SimpleSchema.SchemaObject schemaObject) { if (constraint.IsPrimitive) // Skip primitives (for now, at least) { return; } string sliceName = constraint.GetSliceName(); string elementPath = constraint.GetElementPath(strucDef.Type != null ? strucDef.Type.ToString() : null); var igSettings = GetIGSettings(constraint); var constraintFormatter = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, igSettings, this.igTypePlugin, constraint); string definition = constraintFormatter.GetPlainText(false, false, false); if (definition == null) { definition = string.Empty; } ElementDefinition newElementDef = new ElementDefinition() { Short = !string.IsNullOrEmpty(constraint.Label) ? constraint.Label : constraint.Context, Label = !string.IsNullOrEmpty(constraint.Label) ? constraint.Label : null, Comment = !string.IsNullOrEmpty(constraint.Notes) ? constraint.Notes : null, Path = elementPath, SliceName = sliceName, Definition = definition, ElementId = constraint.GetElementId() }; if (constraint.IsChoice) { newElementDef.Slicing = new ElementDefinition.SlicingComponent(); newElementDef.Slicing.Discriminator.Add(new ElementDefinition.DiscriminatorComponent() { Type = ElementDefinition.DiscriminatorType.Type, Path = "$this" }); newElementDef.Slicing.Rules = ElementDefinition.SlicingRules.Open; } else if (constraint.Parent != null && constraint.Parent.IsChoice) { newElementDef.SliceName = constraint.Context; } // Cardinality if (!string.IsNullOrEmpty(constraint.Cardinality)) { newElementDef.Min = constraint.CardinalityType.Left; newElementDef.Max = constraint.CardinalityType.Right == Cardinality.MANY ? "*" : constraint.CardinalityType.Right.ToString(); } // Binding string valueConformance = string.IsNullOrEmpty(constraint.ValueConformance) ? constraint.Conformance : constraint.ValueConformance; bool hasBinding = constraint.References.Any(y => y.ReferenceType == ConstraintReferenceTypes.Template); if (constraint.ValueSet != null && valueConformance.IndexOf("NOT") < 0) { hasBinding = true; newElementDef.Binding = new ElementDefinition.ElementDefinitionBindingComponent() { ValueSet = new ResourceReference() { Reference = constraint.ValueSet.GetIdentifier(ValueSetIdentifierTypes.HTTP), Display = constraint.ValueSet.Name } }; if (valueConformance == "SHALL") { newElementDef.Binding.Strength = BindingStrength.Required; } else if (valueConformance == "SHOULD") { newElementDef.Binding.Strength = BindingStrength.Preferred; } else if (valueConformance == "MAY") { newElementDef.Binding.Strength = BindingStrength.Example; } } // Single-Value Binding if (schemaObject != null && (!string.IsNullOrEmpty(constraint.Value) || !string.IsNullOrEmpty(constraint.DisplayName))) { Element elementBinding = null; hasBinding = true; switch (schemaObject.DataType) { case "CodeableConcept": var codableConceptBinding = new CodeableConcept(); var coding = new Coding(); codableConceptBinding.Coding.Add(coding); if (!string.IsNullOrEmpty(constraint.Value)) { coding.Code = constraint.Value; } if (constraint.CodeSystem != null) { coding.System = constraint.CodeSystem.Oid; } if (!string.IsNullOrEmpty(constraint.DisplayName)) { coding.Display = constraint.DisplayName; } elementBinding = codableConceptBinding; break; case "Coding": var codingBinding = new Coding(); if (!string.IsNullOrEmpty(constraint.Value)) { codingBinding.Code = constraint.Value; } if (constraint.CodeSystem != null) { codingBinding.System = constraint.CodeSystem.Oid; } if (!string.IsNullOrEmpty(constraint.DisplayName)) { codingBinding.Display = constraint.DisplayName; } elementBinding = codingBinding; break; case "code": var codeBinding = new Code(); codeBinding.Value = !string.IsNullOrEmpty(constraint.Value) ? constraint.Value : constraint.DisplayName; elementBinding = codeBinding; break; default: var stringBinding = new FhirString(); stringBinding.Value = !string.IsNullOrEmpty(constraint.Value) ? constraint.Value : constraint.DisplayName; elementBinding = stringBinding; break; } if (constraint.IsFixed) { newElementDef.Fixed = elementBinding; } else { newElementDef.Pattern = elementBinding; } } // Add the type of the element when bound to a value set if (hasBinding && schemaObject != null && !string.IsNullOrEmpty(schemaObject.DataType)) { StructureDefinition profile = GetBaseProfile(constraint.Template); newElementDef.Type = GetProfileDataTypes(profile, constraint); var containedTemplates = (from tcr in constraint.References join t in this.tdb.Templates on tcr.ReferenceIdentifier equals t.Oid where tcr.ReferenceType == ConstraintReferenceTypes.Template select new { Identifier = t.Oid, t.PrimaryContextType }); // If there is a contained template/profile, make sure it supports a "Reference" type, and then output the profile identifier in the type if (containedTemplates.Count() > 0 && newElementDef.Type.Exists(y => y.Code == "Reference" || y.Code == "Extension")) { if (!string.IsNullOrEmpty(newElementDef.SliceName)) { var foundMatchingElement = strucDef.Differential.Element.SingleOrDefault(y => y.Path == newElementDef.Path && y.SliceName == newElementDef.SliceName); if (foundMatchingElement != null) { foundMatchingElement.Definition += " " + definition; newElementDef = foundMatchingElement; } } var containedTypes = new List <ElementDefinition.TypeRefComponent>(); foreach (var containedTemplate in containedTemplates) { bool isExtension = containedTemplate.PrimaryContextType == "Extension" && newElementDef.Type.Exists(y => y.Code == "Extension"); containedTypes.Add(new ElementDefinition.TypeRefComponent() { Code = isExtension ? "Extension" : "Reference", Profile = isExtension ? containedTemplate.Identifier : null, TargetProfile = !isExtension ? containedTemplate.Identifier : null }); } newElementDef.Type = containedTypes; } } // Add the element to the list if it's new if (!strucDef.Differential.Element.Contains(newElementDef)) { strucDef.Differential.Element.Add(newElementDef); } // Children foreach (var childConstraint in constraint.ChildConstraints.OrderBy(y => y.Order)) { var childSchemaObject = schemaObject != null?schemaObject.Children.SingleOrDefault(y => y.Name == childConstraint.Context) : null; CreateElementDefinition(strucDef, childConstraint, childSchemaObject); } }
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()); }
public StructureDefinition Convert(Template template, SimpleSchema schema, SummaryType?summaryType = null) { var fhirStructureDef = new fhir_stu3.Hl7.Fhir.Model.StructureDefinition() { Id = template.FhirId(), Name = template.Name, Description = template.Description != null ? new Markdown(template.Description.RemoveInvalidUtf8Characters()) : null, Kind = template.PrimaryContextType == "Extension" ? StructureDefinition.StructureDefinitionKind.ComplexType : StructureDefinition.StructureDefinitionKind.Resource, Url = template.FhirUrl(), Type = template.TemplateType.RootContextType, Context = new List <string> { template.PrimaryContextType }, ContextType = StructureDefinition.ExtensionContext.Resource, Abstract = false, Derivation = StructureDefinition.TypeDerivationRule.Constraint }; // If this is an extension, determine what uses the extension and list them in the // "context" field so that the extension knows where it can be used. foreach (var extension in template.Extensions) { var fhirExtension = Convert(extension); if (fhirExtension != null) { fhirStructureDef.Extension.Add(fhirExtension); } } // Status if (template.Status == null || template.Status.IsDraft || template.Status.IsBallot) { fhirStructureDef.Status = PublicationStatus.Draft; } else if (template.Status.IsPublished) { fhirStructureDef.Status = PublicationStatus.Active; } else if (template.Status.IsDraft) { fhirStructureDef.Status = PublicationStatus.Retired; } // Publisher and Contact if (template.Author != null) { if (!string.IsNullOrEmpty(template.Author.ExternalOrganizationName)) { fhirStructureDef.Publisher = template.Author.ExternalOrganizationName; } var newContact = new ContactDetail(); newContact.Name = string.Format("{0} {1}", template.Author.FirstName, template.Author.LastName); newContact.Telecom.Add(new ContactPoint() { Value = template.Author.Phone, Use = ContactPoint.ContactPointUse.Work, System = ContactPoint.ContactPointSystem.Phone }); newContact.Telecom.Add(new ContactPoint() { Value = template.Author.Email, Use = ContactPoint.ContactPointUse.Work, System = ContactPoint.ContactPointSystem.Email }); fhirStructureDef.Contact.Add(newContact); } // Base profile if (template.ImpliedTemplate != null) { fhirStructureDef.BaseDefinitionElement = new FhirUri(template.ImpliedTemplate.FhirUrl()); } else { fhirStructureDef.BaseDefinitionElement = new FhirUri(string.Format("http://hl7.org/fhir/StructureDefinition/{0}", template.TemplateType.RootContextType)); } // Constraints if (summaryType == null || summaryType == SummaryType.Data) { var differential = new StructureDefinition.DifferentialComponent(); fhirStructureDef.Differential = differential; // Add base element for resource var rootElement = new ElementDefinition(); rootElement.Path = template.PrimaryContextType; rootElement.ElementId = template.PrimaryContextType; differential.Element.Add(rootElement); var rootConstraints = template.ChildConstraints.Where(y => y.ParentConstraint == null).OrderBy(y => y.Order); foreach (var constraint in rootConstraints) { SimpleSchema.SchemaObject schemaObject = null; if (schema != null) { schemaObject = schema.Children.SingleOrDefault(y => y.Name == constraint.Context); } CreateElementDefinition(fhirStructureDef, constraint, schemaObject); } // Slices var slices = template.ChildConstraints.Where(y => y.IsBranch); var sliceGroups = slices.GroupBy(y => y.GetElementPath(template.TemplateType.RootContextType)); int currentSliceGroupCount = 2; // Adds an element that contains "slicing" information for the branch(es) foreach (var sliceGroup in sliceGroups) { ElementDefinition newElementDef = new ElementDefinition(); //newElementDef.ElementId = string.Format("{0}-{1}", template.Id, currentSliceGroupCount.ToString("00")); newElementDef.Path = sliceGroup.Key; newElementDef.ElementId = sliceGroup.First().GetElementPath(template.PrimaryContextType); foreach (var branchConstraint in sliceGroup) { var igSettings = GetIGSettings(branchConstraint); var constraintFormatter = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, igSettings, this.igTypePlugin, branchConstraint); var branchIdentifiers = branchConstraint.ChildConstraints.Where(y => y.IsBranchIdentifier); newElementDef.Definition = constraintFormatter.GetPlainText(false, false, false); newElementDef.Slicing = new ElementDefinition.SlicingComponent() { Rules = template.IsOpen ? ElementDefinition.SlicingRules.Open : ElementDefinition.SlicingRules.Closed }; if (branchIdentifiers.Count() > 0) { newElementDef.Slicing.Discriminator = (from bi in branchIdentifiers select new ElementDefinition.DiscriminatorComponent() { Type = ElementDefinition.DiscriminatorType.Value, Path = bi.GetElementPath(null, branchConstraint) }).ToList(); } else if (branchConstraint.Context == "extension") { newElementDef.Slicing.Discriminator.Add(new ElementDefinition.DiscriminatorComponent() { Type = ElementDefinition.DiscriminatorType.Value, Path = "url" }); } else // If no discriminators are specified, assume the child SHALL constraints are discriminators { var discriminatorConstraints = branchConstraint.ChildConstraints.Where(y => y.Conformance == "SHALL"); var singleValueDiscriminators = discriminatorConstraints.Where(y => !string.IsNullOrEmpty(y.Value)); // If there are constraints that have specific single-value bindings, prefer those if (singleValueDiscriminators.Count() > 0 && singleValueDiscriminators.Count() != discriminatorConstraints.Count()) { discriminatorConstraints = singleValueDiscriminators; } newElementDef.Slicing.Discriminator = (from d in discriminatorConstraints select new ElementDefinition.DiscriminatorComponent() { Type = ElementDefinition.DiscriminatorType.Value, Path = d.GetElementPath(template.PrimaryContextType, branchConstraint) }).ToList(); } } // Find where to insert the slice in the element list var firstElement = fhirStructureDef.Differential.Element.First(y => y.Path == sliceGroup.Key); var firstElementIndex = fhirStructureDef.Differential.Element.IndexOf(firstElement); differential.Element.Insert(firstElementIndex, newElementDef); currentSliceGroupCount++; } } return(fhirStructureDef); }