@dmptool/utils 1.0.15 → 1.0.18
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 -45
- 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,57 +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
|
-
// Sort the questions by display order
|
|
386
|
-
results[0].section.forEach((section) => {
|
|
387
|
-
section.question.sort((a, b) => a.questionOrder - b.questionOrder);
|
|
388
|
-
});
|
|
389
|
-
// Sort the sections by display order
|
|
390
|
-
results[0].section.sort((a, b) => {
|
|
391
|
-
return a.sectionOrder - b.sectionOrder;
|
|
392
|
-
});
|
|
393
|
-
return {
|
|
377
|
+
const narrative = {
|
|
394
378
|
id: results[0].templateId,
|
|
395
379
|
title: results[0].templateTitle,
|
|
396
380
|
description: results[0].templateDescription,
|
|
397
381
|
version: results[0].templateVersion,
|
|
398
|
-
section:
|
|
399
|
-
rdsConnectionParams.logger.debug({
|
|
400
|
-
sectionId: section.sectionId,
|
|
401
|
-
questionCount: section.question.length
|
|
402
|
-
}, 'Loaded narrative section information');
|
|
403
|
-
return {
|
|
404
|
-
id: section.sectionId,
|
|
405
|
-
title: section.sectionTitle,
|
|
406
|
-
description: section.sectionDescription,
|
|
407
|
-
order: section.sectionOrder,
|
|
408
|
-
question: section.question.map((question) => {
|
|
409
|
-
rdsConnectionParams.logger.debug({
|
|
410
|
-
questionId: question.questionId,
|
|
411
|
-
answerId: question.answerId
|
|
412
|
-
}, 'Loaded narrative question information');
|
|
413
|
-
return {
|
|
414
|
-
id: question.questionId,
|
|
415
|
-
order: question.questionOrder,
|
|
416
|
-
text: question.questionText,
|
|
417
|
-
answer: {
|
|
418
|
-
id: question.answerId,
|
|
419
|
-
json: question.answerJSON
|
|
420
|
-
}
|
|
421
|
-
};
|
|
422
|
-
})
|
|
423
|
-
};
|
|
424
|
-
})
|
|
382
|
+
section: [],
|
|
425
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,
|
|
395
|
+
order: row.sectionOrder,
|
|
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,
|
|
406
|
+
answer: hasAnswer
|
|
407
|
+
? {
|
|
408
|
+
id: row.answerId,
|
|
409
|
+
json: JSON.parse(row.answerJson)
|
|
410
|
+
}
|
|
411
|
+
: undefined
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
return narrative;
|
|
426
415
|
};
|
|
427
416
|
/**
|
|
428
417
|
* Builds the RDA Common Standard Contact entry for the DMP
|
|
@@ -549,6 +538,7 @@ const buildDMPToolExtensions = async (rdsConnectionParams, applicationName, doma
|
|
|
549
538
|
};
|
|
550
539
|
// Generate the DMP Narrative
|
|
551
540
|
const narrative = await loadNarrativeTemplateInfo(rdsConnectionParams, plan.id);
|
|
541
|
+
rdsConnectionParams.logger.debug({ narrative }, 'Loaded narrative information');
|
|
552
542
|
// Fetch the research domain if one was specified
|
|
553
543
|
const research_domain = project.dmptool_research_domain
|
|
554
544
|
? { name: project.dmptool_research_domain }
|
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