@@ -21,42 +21,53 @@ engine.weight = function (coll) {
21
21
const res = [ ] ;
22
22
23
23
const questionnaire = this . vars . questionnaire || this . processedVars . questionnaire ?. data ;
24
- coll . forEach ( ( answer ) => {
25
- if ( answer ?. data ) {
26
- const valueCoding = answer . data . valueCoding ;
24
+ coll . forEach ( ( item ) => {
25
+ if ( item ?. data ) {
26
+ const valueCoding = item . data . valueCoding ;
27
27
let value = valueCoding ;
28
28
if ( ! value ) {
29
- const prop = Object . keys ( answer . data ) . find ( p => p . startsWith ( 'value' ) ) ;
30
- value = prop ? answer . data [ prop ] : null ;
29
+ const prop = Object . keys ( item . data ) . find ( p => p . length > 5 && p . startsWith ( 'value' ) ) ;
30
+ // if we found a child value[x] property
31
+ value = prop
32
+ // we use it to get a score extension
33
+ ? item . data [ prop ]
34
+ // otherwise, if the source item has a simple data type
35
+ : item . _data ?. extension
36
+ // we get the extension from the adjacent property starting with
37
+ // an underscore
38
+ ? item . _data
39
+ // otherwise we get the extension from the source item
40
+ // (e.g. 'item' is a Coding)
41
+ : item . data ;
31
42
}
32
43
const score = value ?. extension ?. find ( checkExtUrl ) ?. valueDecimal ;
33
44
if ( score !== undefined ) {
34
45
// if we have a score extension in the source item, use it.
35
46
res . push ( score ) ;
36
- } else if ( questionnaire ) {
37
- if ( valueCoding ) {
38
- const qItem = getQItemByLinkIds (
39
- questionnaire , getLinkIds ( answer . parentResNode )
40
- ) ;
41
- const answerOption = qItem ?. answerOption ?. find ( o =>
42
- o . valueCoding . code === valueCoding . code
43
- && o . valueCoding . system === valueCoding . system
44
- ) ;
45
- if ( answerOption ) {
46
- const score = answerOption . extension ?. find ( checkExtUrl ) ?. valueDecimal ;
47
- if ( score !== undefined ) {
48
- // if we have a score extension for the answerOption, use it.
49
- res . push ( score ) ;
47
+ } else if ( valueCoding ) {
48
+ const linkIds = getLinkIds ( item . parentResNode ) ;
49
+ if ( linkIds . length ) {
50
+ if ( questionnaire ) {
51
+ const qItem = getQItemByLinkIds ( questionnaire , linkIds ) ;
52
+ const answerOption = qItem ?. answerOption ?. find ( o =>
53
+ o . valueCoding . code === valueCoding . code
54
+ && o . valueCoding . system === valueCoding . system
55
+ ) ;
56
+ if ( answerOption ) {
57
+ const score = answerOption . extension ?. find ( checkExtUrl ) ?. valueDecimal ;
58
+ if ( score !== undefined ) {
59
+ // if we have a score extension for the answerOption, use it.
60
+ res . push ( score ) ;
61
+ }
62
+ } else {
63
+ throw new Error (
64
+ 'Questionnaire answerOption with this linkId was not found: ' +
65
+ item . parentResNode . data . linkId + '.' ) ;
50
66
}
51
67
} else {
52
- throw new Error (
53
- 'Questionnaire answerOption with this linkId was not found: ' +
54
- answer . parentResNode . data . linkId +
55
- '. Looking upon the underlying CodeSystem is not supported yet.' ) ;
68
+ throw new Error ( '%questionnaire is needed but not specified.' ) ;
56
69
}
57
70
}
58
- } else {
59
- throw new Error ( '%questionnaire is needed but not specified.' ) ;
60
71
}
61
72
}
62
73
} ) ;
0 commit comments