@welshare/questionnaire 0.1.1 → 0.1.2
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/esm/components/question-renderer.js +28 -4
- package/dist/node_modules/@welshare/questionnaire/dist/esm/components/question-renderer.js +28 -4
- package/dist/node_modules/@welshare/questionnaire/package.json +1 -1
- package/dist/node_modules/@welshare/questionnaire/src/components/question-renderer.tsx +27 -4
- package/package.json +1 -1
|
@@ -49,7 +49,13 @@ const QuestionRendererInternal = ({ item, className = "", inputClassName = "", c
|
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
51
|
const handleChoiceChange = (valueCoding, valueInteger) => {
|
|
52
|
-
|
|
52
|
+
// For choice questions, only set one field: valueCoding takes precedence
|
|
53
|
+
if (valueCoding && (valueCoding.code || valueCoding.display || valueCoding.system)) {
|
|
54
|
+
updateAnswer(item.linkId, { valueCoding });
|
|
55
|
+
}
|
|
56
|
+
else if (valueInteger !== undefined) {
|
|
57
|
+
updateAnswer(item.linkId, { valueInteger });
|
|
58
|
+
}
|
|
53
59
|
};
|
|
54
60
|
const handleMultipleChoiceToggle = (valueCoding, valueInteger) => {
|
|
55
61
|
const isSelected = currentAnswers.some((answer) => answer.valueCoding?.code === valueCoding.code);
|
|
@@ -66,7 +72,13 @@ const QuestionRendererInternal = ({ item, className = "", inputClassName = "", c
|
|
|
66
72
|
// Check if we're selecting the exclusive option
|
|
67
73
|
if (exclusiveOptionCode && valueCoding.code === exclusiveOptionCode) {
|
|
68
74
|
// Clear all other answers and only keep this one
|
|
69
|
-
|
|
75
|
+
// For choice questions, only set one field: valueCoding takes precedence
|
|
76
|
+
const answer = valueCoding && (valueCoding.code || valueCoding.display || valueCoding.system)
|
|
77
|
+
? { valueCoding }
|
|
78
|
+
: valueInteger !== undefined
|
|
79
|
+
? { valueInteger }
|
|
80
|
+
: { valueCoding };
|
|
81
|
+
newAnswers = [answer];
|
|
70
82
|
}
|
|
71
83
|
else {
|
|
72
84
|
// Check if exclusive option is currently selected
|
|
@@ -74,13 +86,25 @@ const QuestionRendererInternal = ({ item, className = "", inputClassName = "", c
|
|
|
74
86
|
if (exclusiveSelected) {
|
|
75
87
|
// Remove exclusive option and add new selection
|
|
76
88
|
newAnswers = currentAnswers.filter((answer) => answer.valueCoding?.code !== exclusiveOptionCode);
|
|
77
|
-
|
|
89
|
+
// For choice questions, only set one field: valueCoding takes precedence
|
|
90
|
+
const answer = valueCoding && (valueCoding.code || valueCoding.display || valueCoding.system)
|
|
91
|
+
? { valueCoding }
|
|
92
|
+
: valueInteger !== undefined
|
|
93
|
+
? { valueInteger }
|
|
94
|
+
: { valueCoding };
|
|
95
|
+
newAnswers = [...newAnswers, answer];
|
|
78
96
|
}
|
|
79
97
|
else {
|
|
80
98
|
// Normal behavior: Add the answer (respecting maxAnswers limit)
|
|
81
99
|
const maxAnswers = item.maxAnswers || Number.MAX_SAFE_INTEGER;
|
|
82
100
|
if (currentAnswers.length < maxAnswers) {
|
|
83
|
-
|
|
101
|
+
// For choice questions, only set one field: valueCoding takes precedence
|
|
102
|
+
const answer = valueCoding && (valueCoding.code || valueCoding.display || valueCoding.system)
|
|
103
|
+
? { valueCoding }
|
|
104
|
+
: valueInteger !== undefined
|
|
105
|
+
? { valueInteger }
|
|
106
|
+
: { valueCoding };
|
|
107
|
+
newAnswers = [...currentAnswers, answer];
|
|
84
108
|
}
|
|
85
109
|
else {
|
|
86
110
|
// Already at max, don't add
|
|
@@ -49,7 +49,13 @@ const QuestionRendererInternal = ({ item, className = "", inputClassName = "", c
|
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
51
|
const handleChoiceChange = (valueCoding, valueInteger) => {
|
|
52
|
-
|
|
52
|
+
// For choice questions, only set one field: valueCoding takes precedence
|
|
53
|
+
if (valueCoding && (valueCoding.code || valueCoding.display || valueCoding.system)) {
|
|
54
|
+
updateAnswer(item.linkId, { valueCoding });
|
|
55
|
+
}
|
|
56
|
+
else if (valueInteger !== undefined) {
|
|
57
|
+
updateAnswer(item.linkId, { valueInteger });
|
|
58
|
+
}
|
|
53
59
|
};
|
|
54
60
|
const handleMultipleChoiceToggle = (valueCoding, valueInteger) => {
|
|
55
61
|
const isSelected = currentAnswers.some((answer) => answer.valueCoding?.code === valueCoding.code);
|
|
@@ -66,7 +72,13 @@ const QuestionRendererInternal = ({ item, className = "", inputClassName = "", c
|
|
|
66
72
|
// Check if we're selecting the exclusive option
|
|
67
73
|
if (exclusiveOptionCode && valueCoding.code === exclusiveOptionCode) {
|
|
68
74
|
// Clear all other answers and only keep this one
|
|
69
|
-
|
|
75
|
+
// For choice questions, only set one field: valueCoding takes precedence
|
|
76
|
+
const answer = valueCoding && (valueCoding.code || valueCoding.display || valueCoding.system)
|
|
77
|
+
? { valueCoding }
|
|
78
|
+
: valueInteger !== undefined
|
|
79
|
+
? { valueInteger }
|
|
80
|
+
: { valueCoding };
|
|
81
|
+
newAnswers = [answer];
|
|
70
82
|
}
|
|
71
83
|
else {
|
|
72
84
|
// Check if exclusive option is currently selected
|
|
@@ -74,13 +86,25 @@ const QuestionRendererInternal = ({ item, className = "", inputClassName = "", c
|
|
|
74
86
|
if (exclusiveSelected) {
|
|
75
87
|
// Remove exclusive option and add new selection
|
|
76
88
|
newAnswers = currentAnswers.filter((answer) => answer.valueCoding?.code !== exclusiveOptionCode);
|
|
77
|
-
|
|
89
|
+
// For choice questions, only set one field: valueCoding takes precedence
|
|
90
|
+
const answer = valueCoding && (valueCoding.code || valueCoding.display || valueCoding.system)
|
|
91
|
+
? { valueCoding }
|
|
92
|
+
: valueInteger !== undefined
|
|
93
|
+
? { valueInteger }
|
|
94
|
+
: { valueCoding };
|
|
95
|
+
newAnswers = [...newAnswers, answer];
|
|
78
96
|
}
|
|
79
97
|
else {
|
|
80
98
|
// Normal behavior: Add the answer (respecting maxAnswers limit)
|
|
81
99
|
const maxAnswers = item.maxAnswers || Number.MAX_SAFE_INTEGER;
|
|
82
100
|
if (currentAnswers.length < maxAnswers) {
|
|
83
|
-
|
|
101
|
+
// For choice questions, only set one field: valueCoding takes precedence
|
|
102
|
+
const answer = valueCoding && (valueCoding.code || valueCoding.display || valueCoding.system)
|
|
103
|
+
? { valueCoding }
|
|
104
|
+
: valueInteger !== undefined
|
|
105
|
+
? { valueInteger }
|
|
106
|
+
: { valueCoding };
|
|
107
|
+
newAnswers = [...currentAnswers, answer];
|
|
84
108
|
}
|
|
85
109
|
else {
|
|
86
110
|
// Already at max, don't add
|
|
@@ -160,7 +160,12 @@ const QuestionRendererInternal = ({
|
|
|
160
160
|
valueCoding: { system?: string; code?: string; display?: string },
|
|
161
161
|
valueInteger?: number
|
|
162
162
|
) => {
|
|
163
|
-
|
|
163
|
+
// For choice questions, only set one field: valueCoding takes precedence
|
|
164
|
+
if (valueCoding && (valueCoding.code || valueCoding.display || valueCoding.system)) {
|
|
165
|
+
updateAnswer(item.linkId, { valueCoding });
|
|
166
|
+
} else if (valueInteger !== undefined) {
|
|
167
|
+
updateAnswer(item.linkId, { valueInteger });
|
|
168
|
+
}
|
|
164
169
|
};
|
|
165
170
|
|
|
166
171
|
const handleMultipleChoiceToggle = (
|
|
@@ -189,7 +194,13 @@ const QuestionRendererInternal = ({
|
|
|
189
194
|
// Check if we're selecting the exclusive option
|
|
190
195
|
if (exclusiveOptionCode && valueCoding.code === exclusiveOptionCode) {
|
|
191
196
|
// Clear all other answers and only keep this one
|
|
192
|
-
|
|
197
|
+
// For choice questions, only set one field: valueCoding takes precedence
|
|
198
|
+
const answer = valueCoding && (valueCoding.code || valueCoding.display || valueCoding.system)
|
|
199
|
+
? { valueCoding }
|
|
200
|
+
: valueInteger !== undefined
|
|
201
|
+
? { valueInteger }
|
|
202
|
+
: { valueCoding };
|
|
203
|
+
newAnswers = [answer];
|
|
193
204
|
} else {
|
|
194
205
|
// Check if exclusive option is currently selected
|
|
195
206
|
const exclusiveSelected = currentAnswers.some(
|
|
@@ -201,12 +212,24 @@ const QuestionRendererInternal = ({
|
|
|
201
212
|
newAnswers = currentAnswers.filter(
|
|
202
213
|
(answer) => answer.valueCoding?.code !== exclusiveOptionCode
|
|
203
214
|
);
|
|
204
|
-
|
|
215
|
+
// For choice questions, only set one field: valueCoding takes precedence
|
|
216
|
+
const answer = valueCoding && (valueCoding.code || valueCoding.display || valueCoding.system)
|
|
217
|
+
? { valueCoding }
|
|
218
|
+
: valueInteger !== undefined
|
|
219
|
+
? { valueInteger }
|
|
220
|
+
: { valueCoding };
|
|
221
|
+
newAnswers = [...newAnswers, answer];
|
|
205
222
|
} else {
|
|
206
223
|
// Normal behavior: Add the answer (respecting maxAnswers limit)
|
|
207
224
|
const maxAnswers = item.maxAnswers || Number.MAX_SAFE_INTEGER;
|
|
208
225
|
if (currentAnswers.length < maxAnswers) {
|
|
209
|
-
|
|
226
|
+
// For choice questions, only set one field: valueCoding takes precedence
|
|
227
|
+
const answer = valueCoding && (valueCoding.code || valueCoding.display || valueCoding.system)
|
|
228
|
+
? { valueCoding }
|
|
229
|
+
: valueInteger !== undefined
|
|
230
|
+
? { valueInteger }
|
|
231
|
+
: { valueCoding };
|
|
232
|
+
newAnswers = [...currentAnswers, answer];
|
|
210
233
|
} else {
|
|
211
234
|
// Already at max, don't add
|
|
212
235
|
return;
|