public void TestSingleValueBinding() { // Setup data for the test var cs = this.tdb.FindOrCreateCodeSystem("Test Code System", "http://test.com/codesystem"); var template1 = this.tdb.GenerateTemplate("http://test.com/composition", "Composition", "Test Composition", this.ig, "Composition", "Composition"); var template2 = this.tdb.GenerateTemplate("http://test.com/section", "List", "Test Section", this.ig, "List", "List"); var sectionConstraint = this.tdb.GenerateConstraint(template1, null, null, "section", "SHALL", "1..1", isBranch: true); this.tdb.GenerateConstraint(template1, sectionConstraint, null, "code", "SHALL", "1..1", null, null, "1234-x", "Test Code", null, cs, isBranchIdentifier: true); this.tdb.GenerateConstraint(template1, sectionConstraint, template2, "content", "SHALL", "1..1"); // Export the templates string export = FHIRExporter.GenerateExport(this.tdb, this.tdb.Templates.ToList(), new IGSettingsManager(this.tdb, this.ig.Id)); XmlDocument doc = new XmlDocument(); doc.LoadXml(export); XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable); nsManager.AddNamespace("fhir", "http://hl7.org/fhir"); nsManager.AddNamespace("atom", "http://www.w3.org/2005/Atom"); var profile = doc.SelectSingleNode("//atom:entry/atom:content/fhir:Profile[fhir:identifier/@value = 'http://test.com/composition']", nsManager); var section = profile.SelectSingleNode("fhir:structure/fhir:element[fhir:path/@value = 'Composition.section']", nsManager); var sectionCode = profile.SelectSingleNode("fhir:structure/fhir:element[fhir:path/@value = 'Composition.section.code']", nsManager); AssertXML.XPathExists(section, nsManager, "fhir:name[@value]"); AssertXML.XPathExists(section, nsManager, "fhir:slicing[fhir:discriminator/@value='code'][fhir:ordered/@value='false'][fhir:rules/@value='open']"); Assert.IsNotNull(sectionCode); AssertXML.XPathExists(sectionCode, nsManager, "fhir:definition/fhir:valueCodeableConcept/fhir:coding[fhir:system/@value = 'http://test.com/codesystem'][fhir:code/@value = '1234-x'][fhir:display/@value = 'Test Code']"); }
public void ExportCategory1() { List <string> categories = new List <string>(); categories.Add("CAT1"); SchematronGenerator generator = new SchematronGenerator(this.tdb, this.ig, this.tdb.Templates.ToList(), true, categories: categories); XmlNamespaceManager nsManager = null; XmlDocument doc = GenerateDocument(generator, out nsManager); XmlNode errorPattern = doc.DocumentElement.SelectSingleNode("//sch:pattern[@id='p-urn-oid-1.2.3.4-errors']", nsManager); XmlNode warningPattern = doc.DocumentElement.SelectSingleNode("//sch:pattern[@id='p-urn-oid-1.2.3.4-warnings']", nsManager); Assert.IsNotNull(errorPattern); Assert.IsNotNull(warningPattern); // Un-categorized AssertXML.XPathExists(errorPattern, nsManager, "sch:rule/sch:assert[@id='a-1-1']", "Did not find assertion for un-categorized constraint"); AssertXML.XPathExists(errorPattern, nsManager, "sch:rule/sch:assert[@id='a-1-1'][text()='SHALL contain exactly one [1..1] code (CONF:1-1).']", "Unexpected narrative for uncategorized constraint"); // Category 2 AssertXML.XPathNotExists(errorPattern, nsManager, "sch:rule/sch:assert[@id='a-1-3']", "Did not find assertion for category 2 constraint"); AssertXML.XPathNotExists(errorPattern, nsManager, "sch:rule/sch:assert[@id='a-1-3'][text()='[CAT2] SHALL contain exactly one [1..1] value (CONF:1-3).']", "Unexpected narrative for category 2 constraint"); // Category 1 AssertXML.XPathExists(warningPattern, nsManager, "sch:rule/sch:assert[@id='a-1-2']", "Did not find assertion for category 2 constraint"); AssertXML.XPathExists(warningPattern, nsManager, "sch:rule/sch:assert[@id='a-1-2'][text()='[CAT1] SHOULD contain zero or one [0..1] value (CONF:1-2).']", "Unexpected narrative for category 1 constraint"); // Category 1 & 2 AssertXML.XPathExists(errorPattern, nsManager, "sch:rule/sch:assert[@id='a-1-13']", "Did not find assertion for category 1&2 constraint"); AssertXML.XPathExists(errorPattern, nsManager, "sch:rule/sch:assert[@id='a-1-13'][text()='[CAT1,CAT2] SHALL contain exactly one [1..1] effectiveTime (CONF:1-13).']", "Unexpected narrative in assertion for category 1&2 constraint"); // First branch (REFR) AssertXML.XPathExists(errorPattern, nsManager, "sch:rule[@id='r-urn-oid-1.2.3.4-errors']/sch:assert[@id='a-1-4']", "Did not find assertion for branch 1 root in main template pattern"); AssertXML.XPathExists(errorPattern, nsManager, "sch:rule[@id='r-urn-oid-1.2.3.4-4-branch-4-errors']/sch:assert[@id='a-1-6-branch-4']", "Did not find child constraint's assertion for branch 1"); // Second branch (SUBJ) AssertXML.XPathExists(errorPattern, nsManager, "sch:rule[@id='r-urn-oid-1.2.3.4-errors']/sch:assert[@id='a-1-7']", "Did not find assertion for branch 2 root in main template pattern"); AssertXML.XPathExists(errorPattern, nsManager, "sch:rule[@id='r-urn-oid-1.2.3.4-7-branch-7-errors']/sch:assert[@id='a-1-9-branch-7']", "Did not find child constraint's assertion for branch 2"); // Third branch (XXXX) AssertXML.XPathNotExists(errorPattern, nsManager, "sch:rule[@id='r-urn-oid-1.2.3.4-errors']/sch:assert[@id='a-1-10']", "Did not find assertion for branch 3 root in main template pattern"); AssertXML.XPathNotExists(errorPattern, nsManager, "sch:rule[@id='r-urn-oid-1.2.3.4-10-branch-10-errors']/sch:assert[@id='a-1-12-branch-10']", "Did not find child constraint's assertion for branch 3"); }