cda-schematron-validator 1.0.8 → 1.0.9
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 +3 -0
- package/debug.log +1 -0
- package/package.json +1 -1
- package/validator.js +38 -22
package/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# [cda-schematron-validator](https://github.com/priyaranjan-tokachichu/cda-schematron-validator)
|
|
2
2
|
## Release History
|
|
3
3
|
Starting release history with 1.0.7
|
|
4
|
+
### 1.0.9
|
|
5
|
+
- Fixed the bug introduced in 1.0.8 trying to adjust to different data types of the return value
|
|
6
|
+
- Changed variable names to improve understanding of the process
|
|
4
7
|
### 1.0.8
|
|
5
8
|
- Bug fix identifying the ignored errors
|
|
6
9
|
### 1.0.7
|
package/debug.log
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[0404/083636.694:ERROR:registration_protocol_win.cc(102)] CreateFile: The system cannot find the file specified. (0x2)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cda-schematron-validator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
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": {
|
package/validator.js
CHANGED
|
@@ -108,7 +108,7 @@ function validate(xml, schematron, options = {}) {
|
|
|
108
108
|
for (let j = 0; j < failedAssertions.length; j++) {
|
|
109
109
|
const assertionObject = failedAssertions[j];
|
|
110
110
|
const { type, assertionId, test, simplifiedTest, description, errorMessage, results } = assertionObject;
|
|
111
|
-
if (
|
|
111
|
+
if (Array.isArray(results)) {
|
|
112
112
|
for (let k = 0; k < results.length; k++) {
|
|
113
113
|
const resultObject = results[k];
|
|
114
114
|
const { result, line, path, xml } = resultObject;
|
|
@@ -135,7 +135,7 @@ function validate(xml, schematron, options = {}) {
|
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
else {
|
|
138
|
+
else if (results.ignored) {
|
|
139
139
|
let obj = {
|
|
140
140
|
errorMessage: errorMessage,
|
|
141
141
|
type: type,
|
|
@@ -169,7 +169,7 @@ function checkRule(xmlDoc, originalContext, assertionsAndExtensions, options) {
|
|
|
169
169
|
const includeWarnings = options.includeWarnings === undefined ? true : options.includeWarnings;
|
|
170
170
|
const resourceDir = options.resourceDir || './';
|
|
171
171
|
const xmlSnippetMaxLength = options.xmlSnippetMaxLength === undefined ? 200 : options.xmlSnippetMaxLength;
|
|
172
|
-
let
|
|
172
|
+
let failedAssertions = [];
|
|
173
173
|
const context = options.contextOverride || originalContext;
|
|
174
174
|
// Determine the sections within context, load selected section from cache if possible
|
|
175
175
|
let selected = contextMap[context];
|
|
@@ -194,19 +194,26 @@ function checkRule(xmlDoc, originalContext, assertionsAndExtensions, options) {
|
|
|
194
194
|
|
|
195
195
|
// Extract values from external document and modify test if a document call is made
|
|
196
196
|
let originalTest = test;
|
|
197
|
+
let simplifiedTest = null;
|
|
197
198
|
try {
|
|
198
199
|
test = includeExternalDocument(test, resourceDir);
|
|
199
200
|
}
|
|
200
201
|
catch (err) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
202
|
+
failedAssertions.push({
|
|
203
|
+
type: level,
|
|
204
|
+
assertionId: id,
|
|
205
|
+
test: originalTest,
|
|
206
|
+
simplifiedTest: simplifiedTest,
|
|
207
|
+
description: description,
|
|
208
|
+
results: { ignored: true, errorMessage: err.message }
|
|
209
|
+
});
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
205
212
|
if (originalTest !== test) {
|
|
206
213
|
simplifiedTest = test;
|
|
207
214
|
}
|
|
208
215
|
if (level === 'error' || includeWarnings) {
|
|
209
|
-
|
|
216
|
+
failedAssertions.push({
|
|
210
217
|
type: level,
|
|
211
218
|
assertionId: id,
|
|
212
219
|
test: originalTest,
|
|
@@ -227,10 +234,11 @@ function checkRule(xmlDoc, originalContext, assertionsAndExtensions, options) {
|
|
|
227
234
|
}
|
|
228
235
|
const newRuleObject = ruleAssertionMap[extensionRule];
|
|
229
236
|
const newContext = newRuleObject.context;
|
|
230
|
-
|
|
237
|
+
const failedSubAssertions = checkRule(xmlDoc, newContext, subAssertionsAndExtensions, options);
|
|
238
|
+
failedAssertions.push(...failedSubAssertions);
|
|
231
239
|
}
|
|
232
240
|
}
|
|
233
|
-
return
|
|
241
|
+
return failedAssertions;
|
|
234
242
|
}
|
|
235
243
|
|
|
236
244
|
async function validateAsync(xml, schematron, options = {}) {
|
|
@@ -310,18 +318,17 @@ async function validateAsync(xml, schematron, options = {}) {
|
|
|
310
318
|
}
|
|
311
319
|
const context = _get(ruleObject, 'context');
|
|
312
320
|
const assertionsAndExtensions = _get(ruleObject, 'assertionsAndExtensions') || [];
|
|
313
|
-
let failedAssertions;
|
|
314
321
|
try {
|
|
315
322
|
failedAssertions = await checkRulePromise(xmlDoc, context, assertionsAndExtensions, options);
|
|
316
323
|
}
|
|
317
324
|
catch (errorInRuleCheck) {
|
|
318
325
|
console.log(errorInRuleCheck);
|
|
319
326
|
continue;
|
|
320
|
-
}
|
|
327
|
+
}
|
|
321
328
|
for (let j = 0; j < failedAssertions.length; j++) {
|
|
322
329
|
const assertionObject = failedAssertions[j];
|
|
323
330
|
const { type, assertionId, test, simplifiedTest, description, errorMessage, results } = assertionObject;
|
|
324
|
-
if (
|
|
331
|
+
if (Array.isArray(results)) {
|
|
325
332
|
for (let k = 0; k < results.length; k++) {
|
|
326
333
|
const resultObject = results[k];
|
|
327
334
|
const { result, line, path, xml } = resultObject;
|
|
@@ -348,7 +355,7 @@ async function validateAsync(xml, schematron, options = {}) {
|
|
|
348
355
|
}
|
|
349
356
|
}
|
|
350
357
|
}
|
|
351
|
-
else {
|
|
358
|
+
else if (results.ignored) {
|
|
352
359
|
let obj = {
|
|
353
360
|
errorMessage: errorMessage,
|
|
354
361
|
type: type,
|
|
@@ -381,10 +388,11 @@ function checkRulePromise(xmlDoc, originalContext, assertionsAndExtensions, opti
|
|
|
381
388
|
// Context cache
|
|
382
389
|
const resultCapture = new Promise((resolve, reject) => {
|
|
383
390
|
try {
|
|
391
|
+
// Context cache
|
|
384
392
|
const includeWarnings = options.includeWarnings === undefined ? true : options.includeWarnings;
|
|
385
393
|
const resourceDir = options.resourceDir || './';
|
|
386
394
|
const xmlSnippetMaxLength = options.xmlSnippetMaxLength === undefined ? 200 : options.xmlSnippetMaxLength;
|
|
387
|
-
let
|
|
395
|
+
let failedAssertions = [];
|
|
388
396
|
const context = options.contextOverride || originalContext;
|
|
389
397
|
// Determine the sections within context, load selected section from cache if possible
|
|
390
398
|
let selected = contextMap[context];
|
|
@@ -409,19 +417,26 @@ function checkRulePromise(xmlDoc, originalContext, assertionsAndExtensions, opti
|
|
|
409
417
|
|
|
410
418
|
// Extract values from external document and modify test if a document call is made
|
|
411
419
|
let originalTest = test;
|
|
420
|
+
let simplifiedTest = null;
|
|
412
421
|
try {
|
|
413
422
|
test = includeExternalDocument(test, resourceDir);
|
|
414
423
|
}
|
|
415
424
|
catch (err) {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
425
|
+
failedAssertions.push({
|
|
426
|
+
type: level,
|
|
427
|
+
assertionId: id,
|
|
428
|
+
test: originalTest,
|
|
429
|
+
simplifiedTest: simplifiedTest,
|
|
430
|
+
description: description,
|
|
431
|
+
results: { ignored: true, errorMessage: err.message }
|
|
432
|
+
});
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
420
435
|
if (originalTest !== test) {
|
|
421
436
|
simplifiedTest = test;
|
|
422
437
|
}
|
|
423
438
|
if (level === 'error' || includeWarnings) {
|
|
424
|
-
|
|
439
|
+
failedAssertions.push({
|
|
425
440
|
type: level,
|
|
426
441
|
assertionId: id,
|
|
427
442
|
test: originalTest,
|
|
@@ -442,10 +457,11 @@ function checkRulePromise(xmlDoc, originalContext, assertionsAndExtensions, opti
|
|
|
442
457
|
}
|
|
443
458
|
const newRuleObject = ruleAssertionMap[extensionRule];
|
|
444
459
|
const newContext = newRuleObject.context;
|
|
445
|
-
|
|
460
|
+
const failedSubAssertions = checkRule(xmlDoc, newContext, subAssertionsAndExtensions, options);
|
|
461
|
+
failedAssertions.push(...failedSubAssertions);
|
|
446
462
|
}
|
|
447
463
|
}
|
|
448
|
-
resolve (
|
|
464
|
+
resolve (failedAssertions);
|
|
449
465
|
}
|
|
450
466
|
catch (promiseError) {
|
|
451
467
|
reject (new Error (`Promise Error: ${promiseError}`));
|