cda-schematron-validator 1.0.0 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,7 +12,7 @@ you can now supply a new option parameter `parsedSchematronMap`. You can create
12
12
  ```javascript
13
13
  const fs = require('fs');
14
14
  const dom = require('@xmldom/xmldom').DOMParser;
15
- const { parseSchematron, validation } = require('cda-schematron-validator');
15
+ const { parseSchematron, validate } = require('cda-schematron-validator');
16
16
  const schematronString = fs.readFileSync('SchematronFilePath', 'utf-8').toString();
17
17
  const schematronDoc = new dom().parseFromString(schematronString);
18
18
  const schematronMap = parseSchematron(schematronDoc);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cda-schematron-validator",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "description": "Fork of Eric Wadkins' javascript implementation of schematron testing for C-CDA XML documents. This includes bug fixes and some house keeping.",
5
5
  "main": "validator.js",
6
6
  "scripts": {
@@ -12,6 +12,10 @@
12
12
  },
13
13
  "author": "Eric Wadkins",
14
14
  "contributors": [
15
+ {
16
+ "name" : "Eric Wadkins",
17
+ "url" : "http://www.ericwadkins.com/"
18
+ },
15
19
  {
16
20
  "name" : "Priyaranjan (Raj) Tokachichu",
17
21
  "email" : "priyaranjan@priyaranjan.com",
package/validator.js CHANGED
@@ -25,7 +25,7 @@ function clearCache() {
25
25
  parsedMap = Object.create({});
26
26
  contextMap = Object.create({});
27
27
  }
28
-
28
+ let namespaceMap, patternRuleMap, ruleAssertionMap, xpathSelect;
29
29
  function validate(xml, schematron, options = {}) {
30
30
  // If not valid xml, it might be a filepath
31
31
  // Adding explicit check to make it clear
@@ -79,13 +79,13 @@ function validate(xml, schematron, options = {}) {
79
79
  }
80
80
 
81
81
  // Extract data from parsed schematron object
82
- let namespaceMap = schematronMap.namespaceMap;
83
- let patternRuleMap = schematronMap.patternRuleMap;
84
- let ruleAssertionMap = schematronMap.ruleAssertionMap;
82
+ namespaceMap = schematronMap.namespaceMap;
83
+ patternRuleMap = schematronMap.patternRuleMap;
84
+ ruleAssertionMap = schematronMap.ruleAssertionMap;
85
85
 
86
86
  // Create selector object, initialized with namespaces
87
87
  // Avoid using 'select' as a variable name as it is overused
88
- const xpathSelect = xpath.useNamespaces(namespaceMap);
88
+ xpathSelect = xpath.useNamespaces(namespaceMap);
89
89
 
90
90
  let errors = [];
91
91
  let warnings = [];
@@ -103,7 +103,7 @@ function validate(xml, schematron, options = {}) {
103
103
  let ruleId = rules[i];
104
104
  let context = ruleAssertionMap[rules[i]].context;
105
105
  let assertionsAndExtensions = ruleAssertionMap[rules[i]].assertionsAndExtensions || [];
106
- let assertionResults = checkRule(xmlDoc, xpathSelect, context, assertionsAndExtensions, options);
106
+ let assertionResults = checkRule(xmlDoc, context, assertionsAndExtensions, options);
107
107
  for (let j = 0; j < assertionResults.length; j++) {
108
108
  let type = assertionResults[j].type;
109
109
  let assertionId = assertionResults[j].assertionId;
@@ -170,7 +170,7 @@ function validate(xml, schematron, options = {}) {
170
170
  }
171
171
 
172
172
  // Take the checkRule function out of validate function, and pass on the variable needed as parameters and options
173
- function checkRule(xmlDoc, xpathSelect, originalContext, assertionsAndExtensions, options) {
173
+ function checkRule(xmlDoc, originalContext, assertionsAndExtensions, options) {
174
174
  // Context cache
175
175
  let includeWarnings = options.includeWarnings === undefined ? true : options.includeWarnings;
176
176
  let resourceDir = options.resourceDir || './';
@@ -222,7 +222,18 @@ function checkRule(xmlDoc, xpathSelect, originalContext, assertionsAndExtensions
222
222
  });
223
223
  }
224
224
  }
225
- // removed recursive call to checkRule as it just returns an emptry array
225
+ else {
226
+ const extensionRule = assertionsAndExtensions[i].rule;
227
+ if (!extensionRule) {
228
+ continue;
229
+ }
230
+ const subAssertionsAndExtensions = ruleAssertionMap[extensionRule] ? ruleAssertionMap[extensionRule].assertionsAndExtensions : null;
231
+ if (!subAssertionsAndExtensions) {
232
+ continue;
233
+ }
234
+ const newContext = ruleAssertionMap[extensionRule].context;
235
+ results = results.concat(checkRule(xmlDoc, newContext, subAssertionsAndExtensions, options));
236
+ }
226
237
  }
227
238
  return results;
228
- }
239
+ }