public void GenerateSchematronAssertion_NestedElement_WithAttribute_ConformanceSHALL_CardinalityOneToOne() { var addrElement = new DocumentTemplateElement("addr"); var useAttr = new DocumentTemplateElementAttribute("use", "HP"); addrElement.AddAttribute(useAttr); var element = new DocumentTemplateElement("state"); var cdaDocumentTemplate = new DocumentTemplate("urn:hl7-org:v3") .AddElement(new DocumentTemplateElement("recordTarget") .AddElement(new DocumentTemplateElement("patientRole") .AddElement(addrElement) .AddElement(element))); //need to have cardinality on both parent and child elements? //how do we tell it to generate cda: on context as in below? var cardinality = CardinalityParser.Parse("1..1"); var builder = new AssertionLineBuilder(this.tdb, element, this.igType, this.igTypeSchema).WithCardinality(cardinality).ConformsTo(Conformance.SHALL).WithinContext(@"cda:"); var assertion = builder.ToString(); var expectedAssertion = @"count(cda:state)=1"; Assert.IsTrue(assertion == expectedAssertion, "Assertion string was not correct. Expected '{0}', Actual '{1}'.", expectedAssertion, assertion); var contextBuilder = new ContextBuilder(useAttr, "cda"); var context = contextBuilder.GetRelativeContextString(); var expectedContext = "cda:addr[@use='HP']"; Assert.IsTrue(context == expectedContext, "Context is not correct. Expected '{0}', Actual '{1}'", expectedContext, context); }
public void GenerateSchematronAssertion_NestedElement_WithAttribute_NULLFlavor_ConformanceSHALL_CardinalityOneToOne() { var idElement = new DocumentTemplateElement("id"); var nullFlavorAttribute = new DocumentTemplateElementAttribute("nullFlavor", "NI"); idElement.AddAttribute(nullFlavorAttribute); var cdaDocumentTemplate = new DocumentTemplate("urn:hl7-org:v3"); cdaDocumentTemplate.AddElement(new DocumentTemplateElement("component") .AddElement(new DocumentTemplateElement("section") .AddElement(new DocumentTemplateElement("entry") .AddElement(new DocumentTemplateElement("organizer") .AddElement(new DocumentTemplateElement("performer") .AddElement(new DocumentTemplateElement("assignedEntity") .AddElement(idElement))))))); var builder = new AssertionLineBuilder(this.tdb, nullFlavorAttribute, this.igType, this.igTypeSchema); builder.ConformsTo(ConformanceParser.Parse("SHALL")).WithCardinality(CardinalityParser.Parse("1..1")).WithinContext("cda:"); var assertion = builder.ToString(); var expectedAssertion = @"cda:id[@nullFlavor='NI']"; Assert.IsTrue(assertion == expectedAssertion, "Assertion string was not correct. Expected '{0}', Actual '{1}'.", expectedAssertion, assertion); var contextBuilder = new ContextBuilder(idElement.ParentElement, "cda"); var context = contextBuilder.GetRelativeContextString(); var expectedContext = "cda:assignedEntity"; Assert.IsTrue(context == expectedContext, "Context is not correct. Expected '{0}', Actual '{1}'", expectedContext, context); }
static public void AddElementValueAndDataType(string aPrefix, DocumentTemplateElement aElement, IConstraint aTemplateConstraint) { if (!string.IsNullOrEmpty(aTemplateConstraint.Value)) { if (!string.IsNullOrEmpty(aTemplateConstraint.ValueConformance)) { var valueConformanceType = ConformanceParser.Parse(aTemplateConstraint.ValueConformance); var conformanceType = ConformanceParser.Parse(aTemplateConstraint.Conformance); if (valueConformanceType == conformanceType) { aElement.Value = !string.IsNullOrEmpty(aTemplateConstraint.Value) ? aTemplateConstraint.Value.Trim() : aTemplateConstraint.Value; } } else { aElement.Value = !string.IsNullOrEmpty(aTemplateConstraint.Value) ? aTemplateConstraint.Value.Trim() : aTemplateConstraint.Value; } } // Add the data type attribute if one is present on the constraint if (!string.IsNullOrEmpty(aTemplateConstraint.DataType)) { if (aPrefix == "cda") { if (aElement.ElementName != "code") { DocumentTemplateElementAttribute dataTypeAttr = new DocumentTemplateElementAttribute("xsi:type"); dataTypeAttr.SingleValue = aTemplateConstraint.DataType; aElement.AddAttribute(dataTypeAttr); } } } }
static public DocumentTemplateElement CreateParentElementForAttribute(IConstraint aConstraint, DocumentTemplateElementAttribute aAttribute) { DocumentTemplateElement parentElement = null; // Is there a parent constraint that should be used as a context if (aConstraint.Parent != null && !string.IsNullOrEmpty(aConstraint.Parent.Context) && !aConstraint.Parent.IsBranch) { if ((aAttribute != null) && (aAttribute.Element == null)) //we have an attribute, but no element attached. the parent constraint would then be the element. { parentElement = new DocumentTemplateElement(aConstraint.Parent.Context); if (aConstraint.Parent.IsBranch) { parentElement.AddAttribute(aAttribute); } } else if ((aAttribute != null) && (aAttribute.Element != null) && (aConstraint.Parent.Context != aAttribute.Element.ElementName)) //we have an attribute, with an element attached, but the element does not match the parent context { parentElement = new DocumentTemplateElement(aConstraint.Parent.Context); parentElement.AddElement(aAttribute.Element); } else if (aAttribute != null && aAttribute.Element != null) { parentElement = aAttribute.Element; } } return(parentElement); }
static public void AddCodeSystemToElement(IObjectRepository aTdb, IIGTypePlugin igTypePlugin, DocumentTemplateElement aElement, IConstraint aTemplateConstraint) { if (aTemplateConstraint.ValueCodeSystemId.HasValue && (aElement.ElementName == "value" || aElement.ElementName == "code")) { var codeSystem = aTdb.CodeSystems.Single(y => y.Id == aTemplateConstraint.ValueCodeSystemId); if (codeSystem != null) { var codeSystemIdentifier = igTypePlugin.ParseIdentifier(codeSystem.Oid); aElement.AddAttribute(new DocumentTemplateElementAttribute("codeSystem", codeSystemIdentifier, true)); //TODO: this is cda specific, need to update it } } }
public void GenerateContext_SingleChildElement_2Levels() { var administrativeCodeElement = new DocumentTemplateElement("administrativeGenderCode"); administrativeCodeElement.AddAttribute(new DocumentTemplateElementAttribute("code", "20", string.Empty, "MMG-GENDER-CODE-OID")); var cdaDocumentTemplate = new DocumentTemplate("urn:hl7-org:v3"); cdaDocumentTemplate.AddElement(new DocumentTemplateElement("recordTarget") .AddElement(administrativeCodeElement)); var contextBuilder = new ContextBuilder(administrativeCodeElement, "cda"); var context = contextBuilder.GetFullyQualifiedContextString(); var expected = "cda:recordTarget/cda:administrativeGenderCode[@code='20']"; Assert.IsFalse(string.IsNullOrEmpty(context), "Null or empty string returned by context builder"); Assert.IsTrue(context == expected, "Context string was not correct, expected '{0}', actual '{1}'", expected, context); }
public void GenerateContext_SingleElementChildElement_2Levels_SingleAttribute() { var element = new DocumentTemplateElement("assignedPerson"); var attribute = new DocumentTemplateElementAttribute("classCode", "ASSIGNED"); element.AddAttribute(attribute); var cdaDocumentTemplate = new DocumentTemplate("urn:hl7-org:v3"); cdaDocumentTemplate.AddElement(new DocumentTemplateElement("custodian") .AddElement(element)); var contextBuilder = new ContextBuilder(attribute, "cda"); var context = contextBuilder.GetRelativeContextString(); var expected = "cda:assignedPerson[@classCode='ASSIGNED']"; Assert.IsFalse(string.IsNullOrEmpty(context), "Null or empty string returned by context builder"); Assert.IsTrue(context == expected, "Context string was not correct, expected '{0}', actual '{1}'", expected, context); }
public void Parse(out DocumentTemplateElement aContextElement, out DocumentTemplateElementAttribute aAttribute) { aContextElement = null; //default aAttribute = null; //default var parsedContext = _context.Split('/'); if (parsedContext.Length > 1) //does the context contain a complex element structure (e.g. code/@code) { DocumentTemplateElement parentContextElement = null; for (int i = 0; i < parsedContext.Length; i++) { if (IsAttribute(parsedContext[i])) { aAttribute = new DocumentTemplateElementAttribute(parsedContext[i].Replace("@", "")); aContextElement.AddAttribute(aAttribute); } else { aContextElement = new DocumentTemplateElement(parsedContext[i]); if (parentContextElement != null) { parentContextElement.AddElement(aContextElement); } } parentContextElement = aContextElement; } } else { if (IsAttribute(_context)) { aAttribute = new DocumentTemplateElementAttribute(_context.Replace("@", "")); } else { aContextElement = new DocumentTemplateElement(_context); } } }
/// <summary> /// Helper method which steps through the children for a given constraint (aTemplateConstraint) and attaches any attributes to the /// given element (aElement)). /// </summary> /// <param name="aElement">Element to add the attributes to</param> /// <param name="aTemplateConstraint">Constraint to walk the children to find attributes</param> static private void AddBranchedAttributes(DocumentTemplateElement aElement, IConstraint aTemplateConstraint) { if (aTemplateConstraint.Children != null) { DocumentTemplateElement parsedElement = null; DocumentTemplateElementAttribute parsedAttribute = null; foreach (var child in aTemplateConstraint.Children) { var cp = new ContextParser(child.Context); cp.Parse(out parsedElement, out parsedAttribute); if (parsedElement != null) { parsedElement.IsBranch = child.IsBranch; parsedElement.IsBranchIdentifier = child.IsBranchIdentifier; } if (parsedAttribute != null) //we are only looking for attributes { parsedAttribute.SingleValue = child.Value; aElement.AddAttribute(parsedAttribute); } } } }
public void BuildAdvanceDirectiveObservationDocument_1stLevelOnly() { var sectionCount = 1; var phase = new Phase(); phase.ID = "error"; var document = new SchematronDocument(); document.Phases.Add(phase); var doc = new DocumentTemplate("cda"); doc.AddElement(new DocumentTemplateElement("observation")); doc.ChildElements[0].AddAttribute(new DocumentTemplateElementAttribute("classCode", "OBS")); doc.ChildElements[0].AddAttribute(new DocumentTemplateElementAttribute("moodCode", "EVN")); doc.AddElement(new DocumentTemplateElement("templateId")); doc.ChildElements[1].AddAttribute(new DocumentTemplateElementAttribute("root", "2.16.840.1.113883.10.20.22.4.48")); doc.AddElement(new DocumentTemplateElement("id")); doc.AddElement(new DocumentTemplateElement("code")); doc.ChildElements[doc.ChildElements.Count - 1].AddAttribute(new DocumentTemplateElementAttribute("xsi-type", "CE", "2.16.840.1.113883.1.11.20.2")); doc.AddElement(new DocumentTemplateElement("statusCode")); doc.ChildElements[doc.ChildElements.Count - 1].AddAttribute(new DocumentTemplateElementAttribute("code", "completed", "2.16.840.1.113883.5.14")); var participantElement = new DocumentTemplateElement("participant"); doc.ChildElements[0].AddElement(participantElement); participantElement.AddAttribute(new DocumentTemplateElementAttribute("typeCode", "VRF")); var templateIdElement = new DocumentTemplateElement("templateId"); templateIdElement.AddAttribute(new DocumentTemplateElementAttribute("root", "2.16.840.1.113883.10.20.1.58")); participantElement.AddElement(templateIdElement); var timeElement = new DocumentTemplateElement("time"); timeElement.AddAttribute(new DocumentTemplateElementAttribute("xsi:type", "TS")); participantElement.AddElement(timeElement); var participantRoleElement = new DocumentTemplateElement("participantRole"); participantElement.AddElement(participantRoleElement); var contextBuilder = new ContextBuilder(doc.ChildElements[0], "cda"); var rule = new Rule(); rule.Context = contextBuilder.GetFullyQualifiedContextString(); var assertionBuilder = new AssertionLineBuilder(doc.ChildElements[0].Attributes[0], templateIdentifierXpath, templateVersionIdentifierXpath); //"OBS" rule.Assertions.Add(new Assertion() { AssertionMessage = "SHALL contain 1..1 @classCode='OBS' Observation (CodeSystem: HL7ActClass 2.16.840.1.113883.5.6) (CONF:8648).", Test = assertionBuilder.WithCardinality(CardinalityParser.Parse("1..1")).WithinContext(contextBuilder.GetRelativeContextString()).ConformsTo(Conformance.SHALL).ToString() }); assertionBuilder = new AssertionLineBuilder(doc.ChildElements[0].Attributes[1], templateIdentifierXpath, templateVersionIdentifierXpath); //"EVN" rule.Assertions.Add(new Assertion() { AssertionMessage = "SHALL contain 1..1 @moodCode='EVN' Event (CodeSystem: ActMood 2.16.840.1.113883.5.1001) (CONF:8649).", Test = assertionBuilder.WithCardinality(CardinalityParser.Parse("1..1")).WithinContext(contextBuilder.GetRelativeContextString()).ConformsTo(Conformance.SHALL).ToString() }); var pattern = new Pattern(); pattern.ID = sectionCount.ToString(); pattern.Name = string.Format("pattern-{0}-errors", pattern.ID); pattern.Rules.Add(rule); phase.ActivePatterns.Add(pattern); rule = new Rule(); contextBuilder = new ContextBuilder(doc.ChildElements[1], "cda"); rule.Context = contextBuilder.GetFullyQualifiedContextString(); assertionBuilder = new AssertionLineBuilder(doc.ChildElements[1], templateIdentifierXpath, templateVersionIdentifierXpath); //"templateId[@rootCode]" rule.Assertions.Add(new Assertion() { AssertionMessage = "SHALL contain 1..1 @root='2.16.840.1.113883.10.20.22.4.48' (CONF:10485).", Test = assertionBuilder.WithCardinality(CardinalityParser.Parse("1..1")).WithinContext(contextBuilder.GetRelativeContextString()).ConformsTo(Conformance.SHALL).ToString() }); sectionCount++; pattern = new Pattern(); pattern.ID = sectionCount.ToString(); pattern.Name = string.Format("pattern-{0}-errors", pattern.ID); pattern.Rules.Add(rule); phase.ActivePatterns.Add(pattern); rule = new Rule(); contextBuilder = new ContextBuilder(doc.ChildElements[2], "cda"); rule.Context = contextBuilder.GetFullyQualifiedContextString(); assertionBuilder = new AssertionLineBuilder(doc.ChildElements[2], templateIdentifierXpath, templateVersionIdentifierXpath); //"1..* id" rule.Assertions.Add(new Assertion() { AssertionMessage = "SHALL contain 1..* id (CONF:8654)", Test = assertionBuilder.WithCardinality(CardinalityParser.Parse("1..*")).WithinContext(contextBuilder.GetRelativeContextString()).ConformsTo(Conformance.SHALL).ToString() }); sectionCount++; pattern = new Pattern(); pattern.ID = sectionCount.ToString(); pattern.Name = string.Format("pattern-{0}-errors", pattern.ID); pattern.Rules.Add(rule); phase.ActivePatterns.Add(pattern); rule = new Rule(); contextBuilder = new ContextBuilder(doc.ChildElements[3], "cda"); rule.Context = contextBuilder.GetFullyQualifiedContextString(); assertionBuilder = new AssertionLineBuilder(doc.ChildElements[3], templateIdentifierXpath, templateVersionIdentifierXpath); //"1..1 code @xsi:type='CE' valueset = 2.16.840.1.113883.1.11.20.2" rule.Assertions.Add(new Assertion() { AssertionMessage = "SHALL contain 1..1 code with @xsi:type='CE', where the @code SHOULD be selected from ValueSet AdvanceDirectiveTypeCode 2.16.840.1.113883.1.11.20.2 STATIC 2006-10-17 (CONF:8651).", Test = assertionBuilder.WithCardinality(CardinalityParser.Parse("1..1")).WithinContext(contextBuilder.GetRelativeContextString()).ConformsTo(Conformance.SHALL).ToString() }); sectionCount++; pattern = new Pattern(); pattern.ID = sectionCount.ToString(); pattern.Name = string.Format("pattern-{0}-errors", pattern.ID); pattern.Rules.Add(rule); phase.ActivePatterns.Add(pattern); rule = new Rule(); contextBuilder = new ContextBuilder(doc.ChildElements[3], "cda"); rule.Context = contextBuilder.GetFullyQualifiedContextString(); assertionBuilder = new AssertionLineBuilder(doc.ChildElements[3], templateIdentifierXpath, templateVersionIdentifierXpath); //"1..1 statusCode @code='completed' valueset = 2.16.840.1.113883.1.11.20.2" rule.Assertions.Add(new Assertion() { AssertionMessage = "SHALL contain 1..1 code with @xsi:type='CE', where the @code SHOULD be selected from ValueSet AdvanceDirectiveTypeCode 2.16.840.1.113883.1.11.20.2 STATIC 2006-10-17 (CONF:8651).", Test = assertionBuilder.WithCardinality(CardinalityParser.Parse("1..1")).WithinContext(contextBuilder.GetRelativeContextString()).ConformsTo(Conformance.SHALL).ToString() }); sectionCount++; pattern = new Pattern(); pattern.ID = sectionCount.ToString(); pattern.Name = string.Format("pattern-{0}-errors", pattern.ID); pattern.Rules.Add(rule); phase.ActivePatterns.Add(pattern); rule = new Rule(); contextBuilder = new ContextBuilder(doc.ChildElements[1].Attributes[0], "cda"); rule.Context = contextBuilder.GetFullyQualifiedContextString(); var childtemplateIdElementAssertionBuilder = new AssertionLineBuilder(templateIdElement.Attributes[0], templateIdentifierXpath, templateVersionIdentifierXpath) //templateId/@root .WithCardinality(CardinalityParser.Parse("1..1")) .ConformsTo(Conformance.SHALL) .WithinContext("cda:"); var childParticipantElementAssertionBuilder = new AssertionLineBuilder(participantRoleElement, templateIdentifierXpath, templateVersionIdentifierXpath) .WithCardinality(CardinalityParser.Parse("1..*")) .ConformsTo(Conformance.SHALL) .WithinContext("cda:"); var childTimeElementAssertionBuilder = new AssertionLineBuilder(timeElement, templateIdentifierXpath, templateVersionIdentifierXpath) .WithCardinality(CardinalityParser.Parse("0..1")) .ConformsTo(Conformance.SHOULD) .WithinContext("cda:"); assertionBuilder = new AssertionLineBuilder(participantElement, templateIdentifierXpath, templateVersionIdentifierXpath); //participant rule.Assertions.Add(new Assertion() { AssertionMessage = "should contain 1..* participant (CONF:8662), participant should contain 0..1 time (CONF:8665), the data type of Observation/participant/time in a verification SHALL be TS (time stamp) (CONF:8666), participant shall contain 1..1 participantRole (CONF:8825), participant shall contain 1..1 @typeCode=VRF 'Verifier' (CodeSystem: 2.16.840.1.113883.5.90) (CONF:8663), participant shall contain 1..1 templateId (CONF:8664), templateId shall contain 1..1 @root=2.16.840.1.113883.10.20.1.58 (CONF:10486)", Test = assertionBuilder .WithCardinality(CardinalityParser.Parse("1..*")) .WithinContext("cda:") .ConformsTo(Conformance.SHALL) .WithChildElementBuilder(childTimeElementAssertionBuilder) .WithChildElementBuilder(childParticipantElementAssertionBuilder) .WithChildElementBuilder(childtemplateIdElementAssertionBuilder) .ToString() }); sectionCount++; pattern = new Pattern(); pattern.ID = sectionCount.ToString(); pattern.Name = string.Format("pattern-{0}-errors", pattern.ID); pattern.Rules.Add(rule); phase.ActivePatterns.Add(pattern); var builder = new SchematronDocumentSerializer(); string serializedModel = builder.SerializeDocument(document); Assert.IsFalse(string.IsNullOrEmpty(serializedModel), "No string returned from serialize document"); string[] lModelLines = serializedModel.Split('\n'); Assert.IsNotNull(lModelLines, "The generated string was not split on lines"); Assert.IsTrue(lModelLines.Length > 1, "The generated string was not split on lines"); }
public void GenerateSchematronAssertion_MultipleNestedElement_ConformanceSHALL_AND_SHOULD_CardinalityOneToOne_AND_ZeroToOne_For_Advance_Directive_Number9Constraint() { var doc = new DocumentTemplate("cda"); doc.AddElement(new DocumentTemplateElement("observation")); var participantElement = new DocumentTemplateElement("participant"); participantElement.AddAttribute(new DocumentTemplateElementAttribute("typeCode", "CST")); var participantRoleElement = new DocumentTemplateElement("participantRole"); participantRoleElement.AddAttribute(new DocumentTemplateElementAttribute("classCode", "AGNT")); participantElement.AddElement(participantRoleElement); var addrElement = new DocumentTemplateElement("addr"); participantRoleElement.AddElement(addrElement); var telecomElement = new DocumentTemplateElement("telecom"); participantRoleElement.AddElement(telecomElement); var playingEntityElement = new DocumentTemplateElement("playingEntity"); participantRoleElement.AddElement(playingEntityElement); var nameElement = new DocumentTemplateElement("name"); playingEntityElement.AddElement(nameElement); var participantRoleChildAssertionBuilder = new AssertionLineBuilder(this.tdb, participantRoleElement, this.igType, this.igTypeSchema) .WithinContext("cda:") .WithCardinality(CardinalityParser.Parse("1..1")) .ConformsTo(Conformance.SHALL); var addrChildAssertionBuilder = new AssertionLineBuilder(this.tdb, addrElement, this.igType, this.igTypeSchema) .WithinContext("cda:") .WithCardinality(CardinalityParser.Parse("0..1")) .ConformsTo(Conformance.SHALL); var telecomChildAssertionBuilder = new AssertionLineBuilder(this.tdb, telecomElement, this.igType, this.igTypeSchema) .WithinContext("cda:") .WithCardinality(CardinalityParser.Parse("0..1")) .ConformsTo(Conformance.SHALL); var nameChildAssertionBuilder = new AssertionLineBuilder(this.tdb, nameElement, this.igType, this.igTypeSchema) .WithinContext("cda:") .WithCardinality(CardinalityParser.Parse("1..1")) .ConformsTo(Conformance.SHALL); var playingEntityChildAssertionBuilder = new AssertionLineBuilder(this.tdb, playingEntityElement, this.igType, this.igTypeSchema) .WithinContext("cda:") .WithCardinality(CardinalityParser.Parse("1..1")) .WithChildElementBuilder(nameChildAssertionBuilder) //nested child assertion builder .ConformsTo(Conformance.SHALL); var assertionBuilder = new AssertionLineBuilder(this.tdb, participantElement, this.igType, this.igTypeSchema); //participant var assertion = assertionBuilder .WithCardinality(CardinalityParser.Parse("1..1")) .WithinContext("cda:") .ConformsTo(Conformance.SHALL) .WithChildElementBuilder(participantRoleChildAssertionBuilder) .WithChildElementBuilder(addrChildAssertionBuilder) .WithChildElementBuilder(telecomChildAssertionBuilder) .WithChildElementBuilder(playingEntityChildAssertionBuilder) .ToString(); var expected = "count(cda:participant[@typeCode='CST'][count(cda:participantRole[@classCode='AGNT'])=1][count(cda:addr) < 2][count(cda:telecom) < 2][count(cda:playingEntity[count(cda:name)=1])=1])=1"; Assert.IsTrue(assertion == expected, "Assertion string was not correct. Expected '{0}', Actual '{1}'", expected, assertion); }
private AssertionLineBuilder CreateBranchedRootAssertionLineBuilderFromConstraint(IConstraint aConstraint) { AssertionLineBuilder asb = null; DocumentTemplateElement element = null; DocumentTemplateElementAttribute attribute = null; //parse the context ContextParser contextParser = new ContextParser(aConstraint.Context); contextParser.Parse(out element, out attribute); if (element != null) { if (!string.IsNullOrEmpty(aConstraint.Value)) { element.Value = aConstraint.Value; } asb = new AssertionLineBuilder(this.tdb, element, this.igType, this.igTypeSchema); var containedTemplates = (from tcr in aConstraint.References join t in this.allTemplates on tcr.ReferenceIdentifier equals t.Oid where tcr.ReferenceType == ConstraintReferenceTypes.Template select new { Identifier = t.Oid, t.PrimaryContextType }).ToList(); foreach (var containedTemplate in containedTemplates) { asb.ContainsTemplate(containedTemplate.Identifier, containedTemplate.PrimaryContextType); } } else if (attribute != null) { if (!string.IsNullOrEmpty(aConstraint.Value)) { attribute.SingleValue = aConstraint.Value; } asb = new AssertionLineBuilder(this.tdb, attribute, this.igType, this.igTypeSchema); } else { throw new Exception(); } ConstraintToDocumentElementHelper.AddCardinality(aConstraint, asb); ConstraintToDocumentElementHelper.AddConformance(aConstraint, asb); foreach (var child in aConstraint.Children) { DocumentTemplateElement childElement = null; DocumentTemplateElementAttribute childAttribute = null; ContextParser childContextParser = new ContextParser(child.Context); childContextParser.Parse(out childElement, out childAttribute); if (child.IsBranchIdentifier) { if (childElement != null) { asb.WithChildElementBuilder(CreateBranchedRootAssertionLineBuilderFromConstraint(child)); } else if (childAttribute != null) { if (!string.IsNullOrEmpty(child.Value)) { childAttribute.SingleValue = child.Value; } element.AddAttribute(childAttribute); } } } if (aConstraint.IsBranch) { asb.MarkAsBranchRoot(); } return(asb); }
private AssertionLineBuilder CreateBranchedRootAssertionLineBuilderFromConstraint(IConstraint aConstraint) { AssertionLineBuilder asb = null; DocumentTemplateElement element = null; DocumentTemplateElementAttribute attribute = null; //parse the context ContextParser contextParser = new ContextParser(aConstraint.Context); contextParser.Parse(out element, out attribute); if (element != null) { asb = new AssertionLineBuilder(element, this.igTypePlugin.TemplateIdentifierXpath, this.igTypePlugin.TemplateVersionIdentifierXpath, this.prefix); if (aConstraint.ContainedTemplateId != null) { var containedTemplate = this.tdb.Templates.Single(y => y.Id == aConstraint.ContainedTemplateId.Value); if (containedTemplate != null) { asb.ContainsTemplate(containedTemplate.Oid); } } } else if (attribute != null) { if (!string.IsNullOrEmpty(aConstraint.Value)) { attribute.SingleValue = aConstraint.Value; } asb = new AssertionLineBuilder(attribute, this.igTypePlugin.TemplateIdentifierXpath, this.igTypePlugin.TemplateVersionIdentifierXpath); } else { throw new Exception(); } ConstraintToDocumentElementHelper.AddCardinality(aConstraint, asb); ConstraintToDocumentElementHelper.AddConformance(aConstraint, asb); foreach (var child in aConstraint.Children) { DocumentTemplateElement childElement = null; DocumentTemplateElementAttribute childAttribute = null; ContextParser childContextParser = new ContextParser(child.Context); childContextParser.Parse(out childElement, out childAttribute); if (child.IsBranchIdentifier) { if (childElement != null) { asb.WithChildElementBuilder(CreateBranchedRootAssertionLineBuilderFromConstraint(child)); } else if (childAttribute != null) { if (!string.IsNullOrEmpty(child.Value)) { childAttribute.SingleValue = child.Value; } element.AddAttribute(childAttribute); } } } if (aConstraint.IsBranch) { asb.MarkAsBranchRoot(); } return(asb); }