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.
- package/LICENSE.md +9 -9
- package/README.md +222 -239
- package/bin/cda-validate.js +36 -0
- package/docs/api.md +134 -0
- package/docs/architecture.md +102 -0
- package/docs/coverage.md +112 -0
- package/docs/deployment.md +126 -0
- package/docs/history.md +245 -0
- package/docs/legacy-api.md +70 -0
- package/lib/checkIfFileOrPath.js +27 -28
- package/lib/checkRule.js +97 -98
- package/lib/createClient.js +35 -0
- package/lib/getAssertionObject.js +23 -23
- package/lib/getErrorsAndWarnings.js +41 -41
- package/lib/getFailedAssertions.js +24 -25
- package/lib/getIgnored.js +27 -27
- package/lib/getResults.js +22 -22
- package/lib/getReturnObject.js +20 -20
- package/lib/getSchematronMap.js +34 -31
- package/lib/getSelectXmlChunk.js +27 -27
- package/lib/includeExternalDocument.js +113 -107
- package/lib/initializeProcess.js +34 -40
- package/lib/parseSchematron.js +122 -122
- package/lib/processFailedAssertions.js +17 -17
- package/lib/processRules.js +20 -20
- package/lib/processRulesAsync.js +18 -30
- package/lib/testAssertion.js +74 -74
- package/package.json +67 -59
- package/validateAsync.js +103 -117
- package/validateSync.js +51 -55
- package/validator.d.ts +87 -0
- package/validator.js +17 -16
- package/.eslintrc.js +0 -30
- package/.github/workflows/codeql-analysis.yml +0 -70
- package/.husky/pre-commit +0 -5
- package/.jshintrc +0 -96
- package/.vscode/launch.json +0 -37
- package/Gruntfile.js +0 -28
- package/SECURITY.md +0 -21
- package/test/CDAR2_IG_CCDA_CLINNOTES_R1_DSTU2.1_2015AUG_Vol2_2019JUNwith_errata.sch +0 -71
- package/test/VitalSigns.xml +0 -856
- package/test/async.test.js +0 -124
- package/test/asyncFileList.test.js +0 -61
- package/test/test.sch +0 -47
- package/test/test.xml +0 -80
- package/test/tests.js +0 -140
- package/test/vitalSigns.test.js +0 -34
- package/test/voc.xml +0 -44
package/lib/processRulesAsync.js
CHANGED
|
@@ -1,30 +1,18 @@
|
|
|
1
|
-
const getFailedAssertions = require('./getFailedAssertions');
|
|
2
|
-
const processFailedAssertions = require('./processFailedAssertions');
|
|
3
|
-
/**
|
|
4
|
-
* @method processRulesAsync Entry method to start processing schematron rules. Calls methods `getFailedAssertions` and `processFailedAssertions`
|
|
5
|
-
* This method is same as `processRules` except that this is an Async method wrapping a promise, and returning the promise
|
|
6
|
-
* @param {Array} rules Array of ruleIds
|
|
7
|
-
* @param {object} resultInfo Object that hosts the errors, warnings and ignored arrays to store the results
|
|
8
|
-
* @param {object} options Passing on the options object passed to the `validate` or `validateAsync` methods
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
async function processRulesAsync(rules, assertionInfo, resultInfo, options) {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
processFailedAssertions(failedAssertions, assertionInfo, resultInfo);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
catch (promiseError) {
|
|
24
|
-
reject (new Error (`Promise Error: ${promiseError}`));
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
return rulesProcessed;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
module.exports = processRulesAsync;
|
|
1
|
+
const getFailedAssertions = require('./getFailedAssertions');
|
|
2
|
+
const processFailedAssertions = require('./processFailedAssertions');
|
|
3
|
+
/**
|
|
4
|
+
* @method processRulesAsync Entry method to start processing schematron rules. Calls methods `getFailedAssertions` and `processFailedAssertions`
|
|
5
|
+
* This method is same as `processRules` except that this is an Async method wrapping a promise, and returning the promise
|
|
6
|
+
* @param {Array} rules Array of ruleIds
|
|
7
|
+
* @param {object} resultInfo Object that hosts the errors, warnings and ignored arrays to store the results
|
|
8
|
+
* @param {object} options Passing on the options object passed to the `validate` or `validateAsync` methods
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
async function processRulesAsync(rules, assertionInfo, resultInfo, options) {
|
|
12
|
+
for (const ruleId of rules) {
|
|
13
|
+
const failedAssertions = getFailedAssertions(ruleId, assertionInfo, options);
|
|
14
|
+
if (failedAssertions) processFailedAssertions(failedAssertions, assertionInfo, resultInfo);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = processRulesAsync;
|
package/lib/testAssertion.js
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
// jshint node:true
|
|
2
|
-
// jshint shadow:true
|
|
3
|
-
module.exports = testAssertion;
|
|
4
|
-
|
|
5
|
-
function testAssertion(test, selected, select, xmlDoc, resourceDir, xmlSnippetMaxLength) {
|
|
6
|
-
const results = [];
|
|
7
|
-
|
|
8
|
-
for (let i = 0; i < selected.length; i++) {
|
|
9
|
-
try {
|
|
10
|
-
const result = select('boolean(' + test + ')', selected[i]);
|
|
11
|
-
let lineNumber = null;
|
|
12
|
-
let xmlSnippet = null;
|
|
13
|
-
if (selected[i].lineNumber) {
|
|
14
|
-
lineNumber = selected[i].lineNumber;
|
|
15
|
-
xmlSnippet = selected[i].toString();
|
|
16
|
-
}
|
|
17
|
-
const maxLength = (xmlSnippetMaxLength || 1e308);
|
|
18
|
-
if (xmlSnippet && xmlSnippet.length > maxLength) {
|
|
19
|
-
xmlSnippet = xmlSnippet.slice(0, maxLength) + '...';
|
|
20
|
-
}
|
|
21
|
-
results.push({ result: result, line: lineNumber, path: getXPath(selected[i]), xml: xmlSnippet });
|
|
22
|
-
}
|
|
23
|
-
catch (err) {
|
|
24
|
-
return { ignored: true, errorMessage: err.message };
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
for (let i = 0; i < results.length; i++) {
|
|
29
|
-
if (results[i].result !== true && results[i].result !== false) {
|
|
30
|
-
return { ignored: true, errorMessage: 'Test returned non-boolean result' };
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return results;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function getXPath(node, path) {
|
|
37
|
-
const top = !path ? true : false;
|
|
38
|
-
path = path || [];
|
|
39
|
-
if (node.parentNode) {
|
|
40
|
-
path = getXPath(node.parentNode, path);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
let count = 1;
|
|
44
|
-
if (node.previousSibling) {
|
|
45
|
-
let sibling = node.previousSibling;
|
|
46
|
-
do {
|
|
47
|
-
if (sibling.nodeType === 1 && sibling.nodeName === node.nodeName) {
|
|
48
|
-
count++;
|
|
49
|
-
}
|
|
50
|
-
sibling = sibling.previousSibling;
|
|
51
|
-
} while (sibling);
|
|
52
|
-
if (count === 1) {
|
|
53
|
-
count = null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
else if (node.nextSibling) {
|
|
57
|
-
let sibling = node.nextSibling;
|
|
58
|
-
do {
|
|
59
|
-
if (sibling.nodeType === 1 && sibling.nodeName === node.nodeName) {
|
|
60
|
-
count = 1;
|
|
61
|
-
sibling = null;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
count = null;
|
|
65
|
-
sibling = sibling.previousSibling;
|
|
66
|
-
}
|
|
67
|
-
} while (sibling);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (node.nodeType === 1) {
|
|
71
|
-
path.push(node.nodeName + ('[' + (count || 1) + ']'));
|
|
72
|
-
}
|
|
73
|
-
return top ? '/' + path.join('/') : path;
|
|
74
|
-
}
|
|
1
|
+
// jshint node:true
|
|
2
|
+
// jshint shadow:true
|
|
3
|
+
module.exports = testAssertion;
|
|
4
|
+
|
|
5
|
+
function testAssertion(test, selected, select, xmlDoc, resourceDir, xmlSnippetMaxLength) {
|
|
6
|
+
const results = [];
|
|
7
|
+
|
|
8
|
+
for (let i = 0; i < selected.length; i++) {
|
|
9
|
+
try {
|
|
10
|
+
const result = select('boolean(' + test + ')', selected[i]);
|
|
11
|
+
let lineNumber = null;
|
|
12
|
+
let xmlSnippet = null;
|
|
13
|
+
if (selected[i].lineNumber) {
|
|
14
|
+
lineNumber = selected[i].lineNumber;
|
|
15
|
+
xmlSnippet = selected[i].toString();
|
|
16
|
+
}
|
|
17
|
+
const maxLength = (xmlSnippetMaxLength || 1e308);
|
|
18
|
+
if (xmlSnippet && xmlSnippet.length > maxLength) {
|
|
19
|
+
xmlSnippet = xmlSnippet.slice(0, maxLength) + '...';
|
|
20
|
+
}
|
|
21
|
+
results.push({ result: result, line: lineNumber, path: getXPath(selected[i]), xml: xmlSnippet });
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
return { ignored: true, errorMessage: err.message };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < results.length; i++) {
|
|
29
|
+
if (results[i].result !== true && results[i].result !== false) {
|
|
30
|
+
return { ignored: true, errorMessage: 'Test returned non-boolean result' };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return results;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getXPath(node, path) {
|
|
37
|
+
const top = !path ? true : false;
|
|
38
|
+
path = path || [];
|
|
39
|
+
if (node.parentNode) {
|
|
40
|
+
path = getXPath(node.parentNode, path);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let count = 1;
|
|
44
|
+
if (node.previousSibling) {
|
|
45
|
+
let sibling = node.previousSibling;
|
|
46
|
+
do {
|
|
47
|
+
if (sibling.nodeType === 1 && sibling.nodeName === node.nodeName) {
|
|
48
|
+
count++;
|
|
49
|
+
}
|
|
50
|
+
sibling = sibling.previousSibling;
|
|
51
|
+
} while (sibling);
|
|
52
|
+
if (count === 1) {
|
|
53
|
+
count = null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else if (node.nextSibling) {
|
|
57
|
+
let sibling = node.nextSibling;
|
|
58
|
+
do {
|
|
59
|
+
if (sibling.nodeType === 1 && sibling.nodeName === node.nodeName) {
|
|
60
|
+
count = 1;
|
|
61
|
+
sibling = null;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
count = null;
|
|
65
|
+
sibling = sibling.previousSibling;
|
|
66
|
+
}
|
|
67
|
+
} while (sibling);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (node.nodeType === 1) {
|
|
71
|
+
path.push(node.nodeName + ('[' + (count || 1) + ']'));
|
|
72
|
+
}
|
|
73
|
+
return top ? '/' + path.join('/') : path;
|
|
74
|
+
}
|
package/package.json
CHANGED
|
@@ -1,59 +1,67 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "cda-schematron-validator",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "validator.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
},
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
{
|
|
21
|
-
"name": "
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
},
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "cda-schematron-validator",
|
|
3
|
+
"version": "2.0.0-preview.1",
|
|
4
|
+
"description": "Self-hosted CDA validation API and UI with pinned HL7 profiles, detailed findings, and a compatible legacy Schematron API.",
|
|
5
|
+
"main": "validator.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "node --test --test-concurrency=1 --test-reporter=spec test/*.test.js test/tests.js",
|
|
8
|
+
"assets": "python3 scripts/prepare-assets.py",
|
|
9
|
+
"service:build": "npm run assets && mvn -B -f service/pom.xml package",
|
|
10
|
+
"service:start": "java -Xmx1g -jar service/target/cda-validator-service.jar",
|
|
11
|
+
"service:test": "npm run assets && mvn -B -f service/pom.xml verify",
|
|
12
|
+
"benchmark": "python3 scripts/benchmark.py"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/priyaranjan-tokachichu/cda-schematron-validator.git"
|
|
17
|
+
},
|
|
18
|
+
"author": "Eric Wadkins",
|
|
19
|
+
"contributors": [
|
|
20
|
+
{
|
|
21
|
+
"name": "Eric Wadkins",
|
|
22
|
+
"url": "http://www.ericwadkins.com/"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "Priyaranjan (Raj) Tokachichu",
|
|
26
|
+
"email": "priyaranjan@priyaranjan.com",
|
|
27
|
+
"url": "https://github.com/priyaranjan-tokachichu"
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/priyaranjan-tokachichu/cda-schematron-validator/issues"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/priyaranjan-tokachichu/cda-schematron-validator#readme",
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@xmldom/xmldom": "0.8.15",
|
|
37
|
+
"xpath": "0.0.36"
|
|
38
|
+
},
|
|
39
|
+
"directories": {
|
|
40
|
+
"test": "test"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"C-CDA",
|
|
44
|
+
"HL7",
|
|
45
|
+
"Schematron",
|
|
46
|
+
"CCD",
|
|
47
|
+
"XML"
|
|
48
|
+
],
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=22.12.0"
|
|
51
|
+
},
|
|
52
|
+
"bin": {
|
|
53
|
+
"cda-validate": "bin/cda-validate.js"
|
|
54
|
+
},
|
|
55
|
+
"files": [
|
|
56
|
+
"validator.js",
|
|
57
|
+
"validateSync.js",
|
|
58
|
+
"validateAsync.js",
|
|
59
|
+
"lib/",
|
|
60
|
+
"bin/",
|
|
61
|
+
"LICENSE.md",
|
|
62
|
+
"README.md",
|
|
63
|
+
"validator.d.ts",
|
|
64
|
+
"docs/"
|
|
65
|
+
],
|
|
66
|
+
"types": "validator.d.ts"
|
|
67
|
+
}
|
package/validateAsync.js
CHANGED
|
@@ -1,117 +1,103 @@
|
|
|
1
|
-
// crypto is now built-in node
|
|
2
|
-
const initializeProcess = require('./lib/initializeProcess');
|
|
3
|
-
const processRulesAsync = require('./lib/processRulesAsync');
|
|
4
|
-
const getReturnObject = require('./lib/getReturnObject');
|
|
5
|
-
|
|
6
|
-
// Parsed object cache
|
|
7
|
-
let parsedMap = Object.create(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* @
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
console.log(`Number of files processed: ${resultInfo.length}`);
|
|
105
|
-
console.log(`Processed file info: ${xmlFileInfo}`);
|
|
106
|
-
})
|
|
107
|
-
).then(() => {
|
|
108
|
-
return resultInfo;
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
module.exports = {
|
|
113
|
-
validateAsync,
|
|
114
|
-
validateFileListAsync,
|
|
115
|
-
validateFileObjectAsync,
|
|
116
|
-
clearCache
|
|
117
|
-
};
|
|
1
|
+
// crypto is now built-in node
|
|
2
|
+
const initializeProcess = require('./lib/initializeProcess');
|
|
3
|
+
const processRulesAsync = require('./lib/processRulesAsync');
|
|
4
|
+
const getReturnObject = require('./lib/getReturnObject');
|
|
5
|
+
|
|
6
|
+
// Parsed object cache
|
|
7
|
+
let parsedMap = Object.create(null);
|
|
8
|
+
|
|
9
|
+
function clearCache() {
|
|
10
|
+
parsedMap = Object.create(null);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @method validateAsync The entry method called to validate an xml with schematron. Calls `initializeProcess` and `processRulesAsync` methods, and gets the results.
|
|
15
|
+
* This is similar to `validate` method except that it uses asynchronous `processRulesAsync` method.
|
|
16
|
+
* @param {string} xml string content of an xml file or path to an xml file
|
|
17
|
+
* @param {string} schematron string content of a schematron file or path to a schematron file
|
|
18
|
+
* @param {object} options object that takes parameters
|
|
19
|
+
* `resourceDir`: Where additional documents with added rules such as value set restrictions are present. Default value is the same directory of the code being executed './'.,
|
|
20
|
+
* `xmlSnippetMaxLength`: Restrict the length of the xpath mapped xml snippet when returning the error/warning data to the user. Default value is 200 characters.,
|
|
21
|
+
* `includeWarnings`: User can choose to look for warnings and include them in the report. The default value is false.,
|
|
22
|
+
* `parsedSchematronMap`: User can choose to supply the schematron map instead of a schematron file avoiding the parsing of the schematron file for multiple xml files or check for cache.
|
|
23
|
+
* @returns Calls `getReturnObject` and gets the results (errors, warning, and ignored) as javascript objects
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
async function validateAsync(xml, schematron, options = {}) {
|
|
27
|
+
options = Object.assign({}, options);
|
|
28
|
+
const resultInfo = {
|
|
29
|
+
errors: [],
|
|
30
|
+
warnings: [],
|
|
31
|
+
ignored: []
|
|
32
|
+
};
|
|
33
|
+
options.parsedMap = parsedMap;
|
|
34
|
+
options.contextMap = Object.create(null);
|
|
35
|
+
initializeProcess(xml, schematron, options);
|
|
36
|
+
return Promise.all(
|
|
37
|
+
Object.keys(options.schematronMap.patternRuleMap).map(async (patternId) => {
|
|
38
|
+
if (Object.hasOwn(options.schematronMap.patternRuleMap, patternId)) {
|
|
39
|
+
const assertionInfo = Object.create(null);
|
|
40
|
+
assertionInfo.patternId = patternId;
|
|
41
|
+
const rules = options.schematronMap.patternRuleMap[patternId];
|
|
42
|
+
await processRulesAsync(rules, assertionInfo, resultInfo, options);
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
).then(() => {
|
|
46
|
+
return getReturnObject(resultInfo);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @method validateFileListAsync Run the validateAsync method on each xml file of the array provided, and combine the results into an array and return it.
|
|
52
|
+
* It is important to know that the results could be in a different order than the submitted files. We can't reliably identify which error belongs to which file.
|
|
53
|
+
* The property `fileIndex` of each result object will provide the index of the xml data to which the error belongs to.
|
|
54
|
+
* @param {array} xmlArray array of string content of an xml file or path to an xml file
|
|
55
|
+
* @param {string} schematron string content of a schematron file or path to a schematron file
|
|
56
|
+
* @param {object} options object that takes parameters
|
|
57
|
+
* `resourceDir`: Where additional documents with added rules such as value set restrictions are present. Default value is the same directory of the code being executed './'.,
|
|
58
|
+
* `xmlSnippetMaxLength`: Restrict the length of the xpath mapped xml snippet when returning the error/warning data to the user. Default value is 200 characters.,
|
|
59
|
+
* `includeWarnings`: User can choose to look for warnings and include them in the report. The default value is false.,
|
|
60
|
+
* `parsedSchematronMap`: User can choose to supply the schematron map instead of a schematron file avoiding the parsing of the schematron file for multiple xml files or check for cache.
|
|
61
|
+
* @returns {array} gets array of return objects with results
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
async function validateFileListAsync(xmlArray, schematron, options = {}) {
|
|
65
|
+
return Promise.all(
|
|
66
|
+
xmlArray.map(async (xml, index) => {
|
|
67
|
+
const resultObject = await validateAsync(xml, schematron, options);
|
|
68
|
+
resultObject.fileIndex = index;
|
|
69
|
+
return resultObject;
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @method validateFileObjectAsync Run the validateAsync method on each xml file of the xml data object provided, and combine the results into an array and return it.
|
|
76
|
+
* It is important to know that the results could be in a different order than the submitted files. We can't reliably identify which error belongs to which file.
|
|
77
|
+
* The property `fileInfo` of each result object will provide the information (probably an identifier or the name of the xml) the xml data to which the error belongs to.
|
|
78
|
+
* @param {object} xmlDataObject object with key identifying the xml and value to be the xml file data or xml file path
|
|
79
|
+
* @param {string} schematron string content of a schematron file or path to a schematron file
|
|
80
|
+
* @param {object} options object that takes parameters
|
|
81
|
+
* `resourceDir`: Where additional documents with added rules such as value set restrictions are present. Default value is the same directory of the code being executed './'.,
|
|
82
|
+
* `xmlSnippetMaxLength`: Restrict the length of the xpath mapped xml snippet when returning the error/warning data to the user. Default value is 200 characters.,
|
|
83
|
+
* `includeWarnings`: User can choose to look for warnings and include them in the report. The default value is false.,
|
|
84
|
+
* `parsedSchematronMap`: User can choose to supply the schematron map instead of a schematron file avoiding the parsing of the schematron file for multiple xml files or check for cache.
|
|
85
|
+
* @returns {array} gets array of return objects with results
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
async function validateFileObjectAsync(xmlDataObject, schematron, options = {}) {
|
|
89
|
+
return Promise.all(
|
|
90
|
+
Object.entries(xmlDataObject).map(async ([xmlFileInfo, xml]) => {
|
|
91
|
+
const resultObject = await validateAsync(xml, schematron, options);
|
|
92
|
+
resultObject.fileInfo = xmlFileInfo;
|
|
93
|
+
return resultObject;
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports = {
|
|
99
|
+
validateAsync,
|
|
100
|
+
validateFileListAsync,
|
|
101
|
+
validateFileObjectAsync,
|
|
102
|
+
clearCache
|
|
103
|
+
};
|