@@ -13,13 +13,20 @@ const getPageByAnswerId = (ctx, answerId) =>
13
13
14
14
const getValueSource = ( ctx , sourceId ) => {
15
15
const page = getPageByAnswerId ( ctx , sourceId ) ;
16
- if ( page ) {
17
- if ( page . pageType === "CalculatedSummaryPage" ) {
16
+ if ( page && page . pageType === "CalculatedSummaryPage" ) {
17
+ const calcSumAnswers = flatMap ( page . summaryAnswers , ( answerId ) =>
18
+ getPageByAnswerId ( ctx , answerId )
19
+ ) ;
20
+ if ( some ( calcSumAnswers , { pageType : "CalculatedSummaryPage" } ) ) {
18
21
return {
19
22
identifier : page . id ,
20
- source : "calculated_summary " ,
23
+ source : "grand_calculated_summary " ,
21
24
} ;
22
25
}
26
+ return {
27
+ identifier : page . id ,
28
+ source : "calculated_summary" ,
29
+ } ;
23
30
}
24
31
return {
25
32
identifier : `answer${ sourceId } ` ,
@@ -28,18 +35,22 @@ const getValueSource = (ctx, sourceId) => {
28
35
} ;
29
36
30
37
const getSupplementaryValueSource = ( ctx , sourceId ) => {
31
- const suplementaryField = find ( flatMap ( ctx . questionnaireJson . supplementaryData . data , "schemaFields" ) , { id : sourceId } ) ;
38
+ const suplementaryField = find (
39
+ flatMap ( ctx . questionnaireJson . supplementaryData . data , "schemaFields" ) ,
40
+ { id : sourceId }
41
+ ) ;
32
42
const source = {
33
43
source : "supplementary_data" ,
34
- identifier : suplementaryField . identifier
35
- }
44
+ identifier : suplementaryField . identifier ,
45
+ } ;
36
46
if ( suplementaryField . selector ) {
37
- source . selectors = [ suplementaryField . selector ]
47
+ source . selectors = [ suplementaryField . selector ] ;
38
48
}
39
-
49
+
40
50
return source ;
41
- }
51
+ } ;
42
52
43
53
module . exports = {
44
- getValueSource, getSupplementaryValueSource
54
+ getValueSource,
55
+ getSupplementaryValueSource,
45
56
} ;
0 commit comments