cda-schematron-validator 1.1.11 → 2.0.0-preview.1

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.
Files changed (48) hide show
  1. package/LICENSE.md +9 -9
  2. package/README.md +222 -239
  3. package/bin/cda-validate.js +36 -0
  4. package/docs/api.md +134 -0
  5. package/docs/architecture.md +102 -0
  6. package/docs/coverage.md +112 -0
  7. package/docs/deployment.md +126 -0
  8. package/docs/history.md +245 -0
  9. package/docs/legacy-api.md +70 -0
  10. package/lib/checkIfFileOrPath.js +27 -28
  11. package/lib/checkRule.js +97 -98
  12. package/lib/createClient.js +35 -0
  13. package/lib/getAssertionObject.js +23 -23
  14. package/lib/getErrorsAndWarnings.js +41 -41
  15. package/lib/getFailedAssertions.js +24 -25
  16. package/lib/getIgnored.js +27 -27
  17. package/lib/getResults.js +22 -22
  18. package/lib/getReturnObject.js +20 -20
  19. package/lib/getSchematronMap.js +34 -31
  20. package/lib/getSelectXmlChunk.js +27 -27
  21. package/lib/includeExternalDocument.js +113 -107
  22. package/lib/initializeProcess.js +34 -40
  23. package/lib/parseSchematron.js +122 -122
  24. package/lib/processFailedAssertions.js +17 -17
  25. package/lib/processRules.js +20 -20
  26. package/lib/processRulesAsync.js +18 -30
  27. package/lib/testAssertion.js +74 -74
  28. package/package.json +67 -59
  29. package/validateAsync.js +103 -117
  30. package/validateSync.js +51 -55
  31. package/validator.d.ts +87 -0
  32. package/validator.js +17 -16
  33. package/.eslintrc.js +0 -30
  34. package/.github/workflows/codeql-analysis.yml +0 -70
  35. package/.husky/pre-commit +0 -5
  36. package/.jshintrc +0 -96
  37. package/.vscode/launch.json +0 -37
  38. package/Gruntfile.js +0 -28
  39. package/SECURITY.md +0 -21
  40. package/test/CDAR2_IG_CCDA_CLINNOTES_R1_DSTU2.1_2015AUG_Vol2_2019JUNwith_errata.sch +0 -71
  41. package/test/VitalSigns.xml +0 -856
  42. package/test/async.test.js +0 -124
  43. package/test/asyncFileList.test.js +0 -61
  44. package/test/test.sch +0 -47
  45. package/test/test.xml +0 -80
  46. package/test/tests.js +0 -140
  47. package/test/vitalSigns.test.js +0 -34
  48. package/test/voc.xml +0 -44
@@ -1,23 +1,23 @@
1
- /**
2
- * @method getAssertionObject A simple wrapper to output assertionObject with the right properties as it is used by
3
- * multiple mthods
4
- * @param {string} level 'error' or 'warning'
5
- * @param {string} id rule id
6
- * @param {string} originalTest test information
7
- * @param {string} simplifiedTest if the originalTest has an addition from an external file
8
- * @param {string} description description of the error or warning
9
- * @returns {object} returns object with the properties type, assertionId, test, simplifiedTest, description
10
- */
11
-
12
- function getAssertionObject(level, id, originalTest, simplifiedTest, description) {
13
- const assertionObject = {
14
- type: level,
15
- assertionId: id,
16
- test: originalTest,
17
- simplifiedTest: simplifiedTest,
18
- description: description
19
- };
20
- return assertionObject;
21
- }
22
-
23
- module.exports = getAssertionObject;
1
+ /**
2
+ * @method getAssertionObject A simple wrapper to output assertionObject with the right properties as it is used by
3
+ * multiple mthods
4
+ * @param {string} level 'error' or 'warning'
5
+ * @param {string} id rule id
6
+ * @param {string} originalTest test information
7
+ * @param {string} simplifiedTest if the originalTest has an addition from an external file
8
+ * @param {string} description description of the error or warning
9
+ * @returns {object} returns object with the properties type, assertionId, test, simplifiedTest, description
10
+ */
11
+
12
+ function getAssertionObject(level, id, originalTest, simplifiedTest, description) {
13
+ const assertionObject = {
14
+ type: level,
15
+ assertionId: id,
16
+ test: originalTest,
17
+ simplifiedTest: simplifiedTest,
18
+ description: description
19
+ };
20
+ return assertionObject;
21
+ }
22
+
23
+ module.exports = getAssertionObject;
@@ -1,41 +1,41 @@
1
- /**
2
- * @method getErrorsAndWarnings Given the information update errors and warnings array in resultInfo
3
- * @param {object} assertionObject Provides the assertion and the results of the test
4
- * @param {object} assertionInfo Information about the assertion
5
- * @param {object} resultInfo Arrays to store error and warning info
6
- */
7
-
8
- function getErrorsAndWarnings(assertionObject, assertionInfo, resultInfo) {
9
- const { type, assertionId, test, simplifiedTest, description, results } = assertionObject;
10
- const { patternId, ruleId, context } = assertionInfo;
11
- const { errors, warnings } = resultInfo;
12
- for (let index = 0; index < results.length; index++) {
13
- const resultObject = results[index];
14
- const { result, line, path, xml } = resultObject;
15
- // If the xpath did not return a result (result=false), then there should be
16
- // and error or warning
17
- if (!result) {
18
- const obj = {
19
- type,
20
- test,
21
- simplifiedTest,
22
- description,
23
- line,
24
- path,
25
- patternId,
26
- ruleId,
27
- assertionId,
28
- context,
29
- xml
30
- };
31
- if (type === 'error') {
32
- errors.push(obj);
33
- }
34
- else {
35
- warnings.push(obj);
36
- }
37
- }
38
- }
39
- }
40
-
41
- module.exports = getErrorsAndWarnings;
1
+ /**
2
+ * @method getErrorsAndWarnings Given the information update errors and warnings array in resultInfo
3
+ * @param {object} assertionObject Provides the assertion and the results of the test
4
+ * @param {object} assertionInfo Information about the assertion
5
+ * @param {object} resultInfo Arrays to store error and warning info
6
+ */
7
+
8
+ function getErrorsAndWarnings(assertionObject, assertionInfo, resultInfo) {
9
+ const { type, assertionId, test, simplifiedTest, description, results } = assertionObject;
10
+ const { patternId, ruleId, context } = assertionInfo;
11
+ const { errors, warnings } = resultInfo;
12
+ for (let index = 0; index < results.length; index++) {
13
+ const resultObject = results[index];
14
+ const { result, line, path, xml } = resultObject;
15
+ // If the xpath did not return a result (result=false), then there should be
16
+ // and error or warning
17
+ if (!result) {
18
+ const obj = {
19
+ type,
20
+ test,
21
+ simplifiedTest,
22
+ description,
23
+ line,
24
+ path,
25
+ patternId,
26
+ ruleId,
27
+ assertionId,
28
+ context,
29
+ xml
30
+ };
31
+ if (type === 'error') {
32
+ errors.push(obj);
33
+ }
34
+ else {
35
+ warnings.push(obj);
36
+ }
37
+ }
38
+ }
39
+ }
40
+
41
+ module.exports = getErrorsAndWarnings;
@@ -1,25 +1,24 @@
1
- const _get = require('lodash.get');
2
- const { checkRule } = require('./checkRule');
3
-
4
- /**
5
- * @method getFailedAssertions Get assertions and extension from the rule object and check the rule against the context
6
- * @param {string} ruleId Rule identifier
7
- * @param {object} assertionInfo Object to store assertion info
8
- * @param {object} options Options passed to the validator and any other variables passed between the methods
9
- * @returns {array} array of failedAssertionObjects
10
- */
11
-
12
- function getFailedAssertions(ruleId, assertionInfo, options) {
13
- let failedAssertions;
14
- assertionInfo.ruleId = ruleId;
15
- const ruleObject = options.schematronMap.ruleAssertionMap[ruleId];
16
- if (!_get(ruleObject, 'abstract')) {
17
- const context = _get(ruleObject, 'context');
18
- assertionInfo.context = context;
19
- const assertionsAndExtensions = _get(ruleObject, 'assertionsAndExtensions') || [];
20
- failedAssertions = checkRule(context, assertionsAndExtensions, options);
21
- }
22
- return failedAssertions;
23
- }
24
-
25
- module.exports = getFailedAssertions;
1
+ const { checkRule } = require('./checkRule');
2
+
3
+ /**
4
+ * @method getFailedAssertions Get assertions and extension from the rule object and check the rule against the context
5
+ * @param {string} ruleId Rule identifier
6
+ * @param {object} assertionInfo Object to store assertion info
7
+ * @param {object} options Options passed to the validator and any other variables passed between the methods
8
+ * @returns {array} array of failedAssertionObjects
9
+ */
10
+
11
+ function getFailedAssertions(ruleId, assertionInfo, options) {
12
+ let failedAssertions;
13
+ assertionInfo.ruleId = ruleId;
14
+ const ruleObject = options.schematronMap.ruleAssertionMap[ruleId];
15
+ if (!ruleObject?.abstract) {
16
+ const context = ruleObject?.context;
17
+ assertionInfo.context = context;
18
+ const assertionsAndExtensions = ruleObject?.assertionsAndExtensions || [];
19
+ failedAssertions = checkRule(context, assertionsAndExtensions, options);
20
+ }
21
+ return failedAssertions;
22
+ }
23
+
24
+ module.exports = getFailedAssertions;
package/lib/getIgnored.js CHANGED
@@ -1,27 +1,27 @@
1
- /**
2
- * @method getIgnored If there ws an erroneous rule, it results in the rule being ignored.
3
- * This method will add the ignored assertion info to the ignored array.
4
- * @param {object} assertionObject Carries the ignored assertion info
5
- * @param {object} assertionInfo carries the assertion info from pattern, rule and context
6
- * @param {object} resultInfo carries the ignored array
7
- */
8
-
9
- function getIgnored(assertionObject, assertionInfo, resultInfo) {
10
- const { type, assertionId, test, simplifiedTest, description, errorMessage } = assertionObject;
11
- const { patternId, ruleId, context } = assertionInfo;
12
- const { ignored } = resultInfo;
13
- const obj = {
14
- errorMessage,
15
- type,
16
- test,
17
- simplifiedTest,
18
- description,
19
- patternId,
20
- ruleId,
21
- assertionId,
22
- context
23
- };
24
- ignored.push(obj);
25
- }
26
-
27
- module.exports = getIgnored;
1
+ /**
2
+ * @method getIgnored If there ws an erroneous rule, it results in the rule being ignored.
3
+ * This method will add the ignored assertion info to the ignored array.
4
+ * @param {object} assertionObject Carries the ignored assertion info
5
+ * @param {object} assertionInfo carries the assertion info from pattern, rule and context
6
+ * @param {object} resultInfo carries the ignored array
7
+ */
8
+
9
+ function getIgnored(assertionObject, assertionInfo, resultInfo) {
10
+ const { type, assertionId, test, simplifiedTest, description, errorMessage } = assertionObject;
11
+ const { patternId, ruleId, context } = assertionInfo;
12
+ const { ignored } = resultInfo;
13
+ const obj = {
14
+ errorMessage,
15
+ type,
16
+ test,
17
+ simplifiedTest,
18
+ description,
19
+ patternId,
20
+ ruleId,
21
+ assertionId,
22
+ context
23
+ };
24
+ ignored.push(obj);
25
+ }
26
+
27
+ module.exports = getIgnored;
package/lib/getResults.js CHANGED
@@ -1,22 +1,22 @@
1
- const getErrorsAndWarnings = require('./getErrorsAndWarnings');
2
- const getIgnored = require('./getIgnored');
3
-
4
- /**
5
- * @method getResults Get the results from the assertionObject and store the information in
6
- * errors, warnings and ignored arrays
7
- * @param {object} assertionObject Object with the assertion check results
8
- * @param {object} assertionInfo Object with the assertion information
9
- * @param {object} resultInfo Object that hosts the errors, warnings and ignored arrays to store the results
10
- */
11
-
12
- function getResults(assertionObject, assertionInfo, resultInfo) {
13
- const { results } = assertionObject;
14
- if (Array.isArray(results)) {
15
- getErrorsAndWarnings(assertionObject, assertionInfo, resultInfo);
16
- }
17
- else if (results.ignored) {
18
- getIgnored(assertionObject, assertionInfo, resultInfo);
19
- }
20
- }
21
-
22
- module.exports = getResults;
1
+ const getErrorsAndWarnings = require('./getErrorsAndWarnings');
2
+ const getIgnored = require('./getIgnored');
3
+
4
+ /**
5
+ * @method getResults Get the results from the assertionObject and store the information in
6
+ * errors, warnings and ignored arrays
7
+ * @param {object} assertionObject Object with the assertion check results
8
+ * @param {object} assertionInfo Object with the assertion information
9
+ * @param {object} resultInfo Object that hosts the errors, warnings and ignored arrays to store the results
10
+ */
11
+
12
+ function getResults(assertionObject, assertionInfo, resultInfo) {
13
+ const { results } = assertionObject;
14
+ if (Array.isArray(results)) {
15
+ getErrorsAndWarnings(assertionObject, assertionInfo, resultInfo);
16
+ }
17
+ else if (results.ignored) {
18
+ getIgnored(assertionObject, assertionInfo, resultInfo);
19
+ }
20
+ }
21
+
22
+ module.exports = getResults;
@@ -1,20 +1,20 @@
1
- /**
2
- * @method getReturnObject Simple method to avoid redundancy of result object representation
3
- * @param {object} resultInfo carrying the arrays errors, warnings and ignored
4
- * @returns result object with information about overall errors, warnings and ignored
5
- */
6
-
7
- function getReturnObject(resultInfo) {
8
- const { errors, warnings, ignored } = resultInfo;
9
- const result = {
10
- errorCount: errors.length,
11
- warningCount: warnings.length,
12
- ignoredCount: ignored.length,
13
- errors: errors,
14
- warnings: warnings,
15
- ignored: ignored
16
- };
17
- return result;
18
- }
19
-
20
- module.exports = getReturnObject;
1
+ /**
2
+ * @method getReturnObject Simple method to avoid redundancy of result object representation
3
+ * @param {object} resultInfo carrying the arrays errors, warnings and ignored
4
+ * @returns result object with information about overall errors, warnings and ignored
5
+ */
6
+
7
+ function getReturnObject(resultInfo) {
8
+ const { errors, warnings, ignored } = resultInfo;
9
+ const result = {
10
+ errorCount: errors.length,
11
+ warningCount: warnings.length,
12
+ ignoredCount: ignored.length,
13
+ errors: errors,
14
+ warnings: warnings,
15
+ ignored: ignored
16
+ };
17
+ return result;
18
+ }
19
+
20
+ module.exports = getReturnObject;
@@ -1,31 +1,34 @@
1
- const Dom = require('@xmldom/xmldom').DOMParser;
2
- const crypto = require('crypto');
3
- const _get = require('lodash.get');
4
- const parseSchematron = require('./parseSchematron');
5
- /**
6
- * @method getSchematronMap A method to get the schematron map from the provided schematron or utilize the data from cache or options object
7
- * @param {string} schematron String data of schematron
8
- * @param {object} options Options passed to the validator and any other variables passed between the methods
9
- * @returns {object} parsed schemtaron map object
10
- */
11
-
12
- function getSchematronMap(schematron, options = {}) {
13
- if (_get(options, 'parsedSchematronMap')) {
14
- return _get(options, 'parsedSchematronMap');
15
- }
16
- const hash = crypto
17
- .createHash('md5')
18
- .update(schematron)
19
- .digest('hex');
20
- if (options.parsedMap[hash]) {
21
- return options.parsedMap[hash];
22
- }
23
- // If not in cache
24
- // Load schematron doc
25
- const schematronDoc = new Dom().parseFromString(schematron);
26
- // Parse schematron
27
- options.parsedMap[hash] = parseSchematron(schematronDoc, options);
28
- return options.parsedMap[hash];
29
- }
30
-
31
- module.exports = getSchematronMap;
1
+ const Dom = require('@xmldom/xmldom').DOMParser;
2
+ const crypto = require('crypto');
3
+ const parseSchematron = require('./parseSchematron');
4
+ /**
5
+ * @method getSchematronMap A method to get the schematron map from the provided schematron or utilize the data from cache or options object
6
+ * @param {string} schematron String data of schematron
7
+ * @param {object} options Options passed to the validator and any other variables passed between the methods
8
+ * @returns {object} parsed schemtaron map object
9
+ */
10
+
11
+ function getSchematronMap(schematron, options = {}) {
12
+ if (options?.parsedSchematronMap) {
13
+ return options?.parsedSchematronMap;
14
+ }
15
+ const hash = crypto
16
+ .createHash('sha256')
17
+ .update(schematron)
18
+ .update(String(Boolean(options.includeWarnings)))
19
+ .digest('hex');
20
+ if (options.parsedMap[hash]) {
21
+ return options.parsedMap[hash];
22
+ }
23
+ // If not in cache
24
+ // Load schematron doc
25
+ const schematronDoc = new Dom().parseFromString(schematron);
26
+ // Parse schematron
27
+ if (Object.keys(options.parsedMap).length >= 32) {
28
+ delete options.parsedMap[Object.keys(options.parsedMap)[0]];
29
+ }
30
+ options.parsedMap[hash] = parseSchematron(schematronDoc, options);
31
+ return options.parsedMap[hash];
32
+ }
33
+
34
+ module.exports = getSchematronMap;
@@ -1,27 +1,27 @@
1
- /**
2
- * @method getSelectXmlChunk Use xpath to get xml chunks from the xml based on the queried context
3
- * @param {string} context Used to query the xml using xpath
4
- * @param {object} options Options passed to the validator and any other variables passed between the methods
5
- * @returns {array} xpath selected xml chunks array
6
- */
7
-
8
- function getSelectXmlChunk(context, options) {
9
- // Determine the sections within context, load selected section from cache if possible
10
- let selectedXml = options.contextMap[context];
11
- let contextModified = context;
12
- if (!selectedXml) {
13
- if (context) {
14
- if (context.indexOf('/')) {
15
- contextModified = '//' + context;
16
- }
17
- selectedXml = options.xpathSelect(contextModified, options.xmlDoc);
18
- }
19
- else {
20
- selectedXml = [options.xmlDoc];
21
- }
22
- options.contextMap[context] = selectedXml;
23
- }
24
- return selectedXml;
25
- }
26
-
27
- module.exports = getSelectXmlChunk;
1
+ /**
2
+ * @method getSelectXmlChunk Use xpath to get xml chunks from the xml based on the queried context
3
+ * @param {string} context Used to query the xml using xpath
4
+ * @param {object} options Options passed to the validator and any other variables passed between the methods
5
+ * @returns {array} xpath selected xml chunks array
6
+ */
7
+
8
+ function getSelectXmlChunk(context, options) {
9
+ // Determine the sections within context, load selected section from cache if possible
10
+ let selectedXml = options.contextMap[context];
11
+ let contextModified = context;
12
+ if (!selectedXml) {
13
+ if (context) {
14
+ if (context.indexOf('/')) {
15
+ contextModified = '//' + context;
16
+ }
17
+ selectedXml = options.xpathSelect(contextModified, options.xmlDoc);
18
+ }
19
+ else {
20
+ selectedXml = [options.xmlDoc];
21
+ }
22
+ options.contextMap[context] = selectedXml;
23
+ }
24
+ return selectedXml;
25
+ }
26
+
27
+ module.exports = getSelectXmlChunk;