@dmptool/utils 1.0.16 → 1.0.19
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/dist/maDMP.js +35 -38
- package/dist/maDMPTypes.d.ts +15 -13
- package/package.json +1 -1
package/dist/maDMP.js
CHANGED
|
@@ -349,7 +349,6 @@ const loadRelatedWorksInfo = async (rdsConnectionParams, planId) => {
|
|
|
349
349
|
* @returns the DMP Tool Narrative extension for the DMP
|
|
350
350
|
*/
|
|
351
351
|
const loadNarrativeTemplateInfo = async (rdsConnectionParams, planId) => {
|
|
352
|
-
var _a, _b, _c, _d, _e, _f;
|
|
353
352
|
// Fetch the template, sections, questions and answers all at once
|
|
354
353
|
const sql = `
|
|
355
354
|
SELECT t.id templateId, t.name templateTitle, t.description templateDescription,
|
|
@@ -372,49 +371,47 @@ const loadNarrativeTemplateInfo = async (rdsConnectionParams, planId) => {
|
|
|
372
371
|
if (resp && Array.isArray(resp.results) && resp.results.length > 0) {
|
|
373
372
|
results = resp.results.filter((row) => !(0, general_1.isNullOrUndefined)(row));
|
|
374
373
|
}
|
|
375
|
-
if (!Array.isArray(results) || results.length === 0
|
|
376
|
-
|| !Array.isArray(results[0].section) || results[0].section.length === 0) {
|
|
374
|
+
if (!Array.isArray(results) || results.length === 0) {
|
|
377
375
|
return undefined;
|
|
378
376
|
}
|
|
379
|
-
|
|
380
|
-
planId,
|
|
381
|
-
nbrRsults: results.length,
|
|
382
|
-
sectionCount: (_b = (_a = results === null || results === void 0 ? void 0 : results[0]) === null || _a === void 0 ? void 0 : _a.section) === null || _b === void 0 ? void 0 : _b.length,
|
|
383
|
-
questionCount: (_f = (_e = (_d = (_c = results === null || results === void 0 ? void 0 : results[0]) === null || _c === void 0 ? void 0 : _c.section) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.question) === null || _f === void 0 ? void 0 : _f.length
|
|
384
|
-
}, 'Loaded narrative information');
|
|
385
|
-
return {
|
|
377
|
+
const narrative = {
|
|
386
378
|
id: results[0].templateId,
|
|
387
379
|
title: results[0].templateTitle,
|
|
388
|
-
description: results[0].templateDescription,
|
|
380
|
+
description: results[0].templateDescription !== null ? results[0].templateDescription : undefined,
|
|
389
381
|
version: results[0].templateVersion,
|
|
390
|
-
section:
|
|
391
|
-
rdsConnectionParams.logger.debug({
|
|
392
|
-
sectionId: section.sectionId,
|
|
393
|
-
questionCount: section.question.length
|
|
394
|
-
}, 'Loaded narrative section information');
|
|
395
|
-
return {
|
|
396
|
-
id: section.sectionId,
|
|
397
|
-
title: section.sectionTitle,
|
|
398
|
-
description: section.sectionDescription,
|
|
399
|
-
order: section.sectionOrder,
|
|
400
|
-
question: section.question.map((question) => {
|
|
401
|
-
rdsConnectionParams.logger.debug({
|
|
402
|
-
questionId: question.questionId,
|
|
403
|
-
answerId: question.answerId
|
|
404
|
-
}, 'Loaded narrative question information');
|
|
405
|
-
return {
|
|
406
|
-
id: question.questionId,
|
|
407
|
-
order: question.questionOrder,
|
|
408
|
-
text: question.questionText,
|
|
409
|
-
answer: {
|
|
410
|
-
id: question.answerId,
|
|
411
|
-
json: question.answerJSON
|
|
412
|
-
}
|
|
413
|
-
};
|
|
414
|
-
})
|
|
415
|
-
};
|
|
416
|
-
})
|
|
382
|
+
section: [],
|
|
417
383
|
};
|
|
384
|
+
results.forEach((row) => {
|
|
385
|
+
// Sections may have several rows in the results, so we need to check if we
|
|
386
|
+
// already have the section defined.
|
|
387
|
+
let curSection = narrative.section.find((s) => {
|
|
388
|
+
return s.id === row.sectionId;
|
|
389
|
+
});
|
|
390
|
+
if (curSection === undefined || curSection === null) {
|
|
391
|
+
curSection = {
|
|
392
|
+
id: row.sectionId,
|
|
393
|
+
title: row.sectionTitle,
|
|
394
|
+
description: row.sectionDescription !== null ? row.sectionDescription : undefined,
|
|
395
|
+
order: row.sectionOrder !== null ? row.sectionOrder : 0,
|
|
396
|
+
question: [],
|
|
397
|
+
};
|
|
398
|
+
narrative.section.push(curSection);
|
|
399
|
+
}
|
|
400
|
+
const hasAnswer = row.answerJson !== undefined && row.answerJson !== null;
|
|
401
|
+
// Every row in the results represents a single question/answer pair
|
|
402
|
+
curSection.question.push({
|
|
403
|
+
id: row.questionId,
|
|
404
|
+
text: row.questionText,
|
|
405
|
+
order: row.questionOrder !== null ? row.questionOrder : 0,
|
|
406
|
+
answer: hasAnswer
|
|
407
|
+
? {
|
|
408
|
+
id: row.answerId,
|
|
409
|
+
json: JSON.parse(row.answerJson)
|
|
410
|
+
}
|
|
411
|
+
: undefined
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
return narrative;
|
|
418
415
|
};
|
|
419
416
|
/**
|
|
420
417
|
* Builds the RDA Common Standard Contact entry for the DMP
|
package/dist/maDMPTypes.d.ts
CHANGED
|
@@ -59,24 +59,26 @@ export interface LoadRelatedWorkInfo {
|
|
|
59
59
|
workType?: string;
|
|
60
60
|
}
|
|
61
61
|
export interface LoadNarrativeQuestionInfo {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
id: number;
|
|
63
|
+
text: string;
|
|
64
|
+
order: number;
|
|
65
|
+
answer: {
|
|
66
|
+
id: number;
|
|
67
|
+
json: AnyAnswerType;
|
|
68
|
+
};
|
|
67
69
|
}
|
|
68
70
|
export interface LoadNarrativeSectionInfo {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
id: number;
|
|
72
|
+
title: string;
|
|
73
|
+
description?: string;
|
|
74
|
+
order: number;
|
|
73
75
|
question: LoadNarrativeQuestionInfo[];
|
|
74
76
|
}
|
|
75
77
|
export interface LoadNarrativeInfo {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
id: number;
|
|
79
|
+
title: string;
|
|
80
|
+
description?: string;
|
|
81
|
+
version?: string;
|
|
80
82
|
section: LoadNarrativeSectionInfo[];
|
|
81
83
|
}
|
|
82
84
|
export interface RDACommonStandardAffiliation {
|
package/package.json
CHANGED