@welshare/questionnaire 0.1.2 → 0.2.0

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.
Files changed (96) hide show
  1. package/README.md +151 -0
  2. package/dist/esm/components/bmi-form.d.ts +68 -0
  3. package/dist/esm/components/bmi-form.d.ts.map +1 -0
  4. package/dist/esm/components/bmi-form.js +138 -0
  5. package/dist/esm/components/question-renderer.d.ts +6 -1
  6. package/dist/esm/components/question-renderer.d.ts.map +1 -1
  7. package/dist/esm/components/question-renderer.js +25 -14
  8. package/dist/esm/components/questions/decimal-question.d.ts +8 -1
  9. package/dist/esm/components/questions/decimal-question.d.ts.map +1 -1
  10. package/dist/esm/components/questions/decimal-question.js +19 -1
  11. package/dist/esm/components/questions/multiple-choice-question.d.ts.map +1 -1
  12. package/dist/esm/components/questions/multiple-choice-question.js +2 -2
  13. package/dist/esm/contexts/questionnaire-context.d.ts.map +1 -1
  14. package/dist/esm/contexts/questionnaire-context.js +3 -2
  15. package/dist/esm/index.d.ts +6 -2
  16. package/dist/esm/index.d.ts.map +1 -1
  17. package/dist/esm/index.js +5 -1
  18. package/dist/esm/lib/bmi-helpers.d.ts +50 -0
  19. package/dist/esm/lib/bmi-helpers.d.ts.map +1 -0
  20. package/dist/esm/lib/bmi-helpers.js +69 -0
  21. package/dist/esm/lib/constants.d.ts +94 -0
  22. package/dist/esm/lib/constants.d.ts.map +1 -0
  23. package/dist/esm/lib/constants.js +93 -0
  24. package/dist/esm/lib/questionnaire-utils.d.ts +21 -1
  25. package/dist/esm/lib/questionnaire-utils.d.ts.map +1 -1
  26. package/dist/esm/lib/questionnaire-utils.js +85 -4
  27. package/dist/esm/types/fhir.d.ts +1 -0
  28. package/dist/esm/types/fhir.d.ts.map +1 -1
  29. package/dist/esm/types/index.d.ts +25 -0
  30. package/dist/esm/types/index.d.ts.map +1 -1
  31. package/dist/styles.css +108 -0
  32. package/package.json +17 -6
  33. package/dist/node_modules/@welshare/questionnaire/.tshy/build.json +0 -8
  34. package/dist/node_modules/@welshare/questionnaire/.tshy/esm.json +0 -16
  35. package/dist/node_modules/@welshare/questionnaire/LICENSE +0 -7
  36. package/dist/node_modules/@welshare/questionnaire/README.md +0 -173
  37. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/debug-section.d.ts +0 -44
  38. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/debug-section.d.ts.map +0 -1
  39. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/debug-section.js +0 -28
  40. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/question-renderer.d.ts +0 -80
  41. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/question-renderer.d.ts.map +0 -1
  42. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/question-renderer.js +0 -183
  43. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/boolean-question.d.ts +0 -15
  44. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/boolean-question.d.ts.map +0 -1
  45. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/boolean-question.js +0 -19
  46. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/choice-question.d.ts +0 -19
  47. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/choice-question.d.ts.map +0 -1
  48. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/choice-question.js +0 -23
  49. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/decimal-question.d.ts +0 -12
  50. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/decimal-question.d.ts.map +0 -1
  51. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/decimal-question.js +0 -7
  52. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/integer-question.d.ts +0 -18
  53. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/integer-question.d.ts.map +0 -1
  54. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/integer-question.js +0 -24
  55. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/multiple-choice-question.d.ts +0 -20
  56. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/multiple-choice-question.d.ts.map +0 -1
  57. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/multiple-choice-question.js +0 -39
  58. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/string-question.d.ts +0 -12
  59. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/string-question.d.ts.map +0 -1
  60. package/dist/node_modules/@welshare/questionnaire/dist/esm/components/questions/string-question.js +0 -7
  61. package/dist/node_modules/@welshare/questionnaire/dist/esm/contexts/questionnaire-context.d.ts +0 -41
  62. package/dist/node_modules/@welshare/questionnaire/dist/esm/contexts/questionnaire-context.d.ts.map +0 -1
  63. package/dist/node_modules/@welshare/questionnaire/dist/esm/contexts/questionnaire-context.js +0 -350
  64. package/dist/node_modules/@welshare/questionnaire/dist/esm/index.d.ts +0 -7
  65. package/dist/node_modules/@welshare/questionnaire/dist/esm/index.d.ts.map +0 -1
  66. package/dist/node_modules/@welshare/questionnaire/dist/esm/index.js +0 -6
  67. package/dist/node_modules/@welshare/questionnaire/dist/esm/lib/questionnaire-utils.d.ts +0 -33
  68. package/dist/node_modules/@welshare/questionnaire/dist/esm/lib/questionnaire-utils.d.ts.map +0 -1
  69. package/dist/node_modules/@welshare/questionnaire/dist/esm/lib/questionnaire-utils.js +0 -99
  70. package/dist/node_modules/@welshare/questionnaire/dist/esm/package.json +0 -3
  71. package/dist/node_modules/@welshare/questionnaire/dist/esm/types/fhir.d.ts +0 -117
  72. package/dist/node_modules/@welshare/questionnaire/dist/esm/types/fhir.d.ts.map +0 -1
  73. package/dist/node_modules/@welshare/questionnaire/dist/esm/types/fhir.js +0 -3
  74. package/dist/node_modules/@welshare/questionnaire/dist/esm/types/index.d.ts +0 -51
  75. package/dist/node_modules/@welshare/questionnaire/dist/esm/types/index.d.ts.map +0 -1
  76. package/dist/node_modules/@welshare/questionnaire/dist/esm/types/index.js +0 -1
  77. package/dist/node_modules/@welshare/questionnaire/dist/styles.css +0 -467
  78. package/dist/node_modules/@welshare/questionnaire/dist/tokens.css +0 -130
  79. package/dist/node_modules/@welshare/questionnaire/package.json +0 -85
  80. package/dist/node_modules/@welshare/questionnaire/src/components/debug-section.tsx +0 -116
  81. package/dist/node_modules/@welshare/questionnaire/src/components/question-renderer.tsx +0 -391
  82. package/dist/node_modules/@welshare/questionnaire/src/components/questionnaire-styles.css +0 -467
  83. package/dist/node_modules/@welshare/questionnaire/src/components/questionnaire-tokens.css +0 -130
  84. package/dist/node_modules/@welshare/questionnaire/src/components/questions/boolean-question.tsx +0 -72
  85. package/dist/node_modules/@welshare/questionnaire/src/components/questions/choice-question.tsx +0 -68
  86. package/dist/node_modules/@welshare/questionnaire/src/components/questions/decimal-question.tsx +0 -32
  87. package/dist/node_modules/@welshare/questionnaire/src/components/questions/integer-question.tsx +0 -87
  88. package/dist/node_modules/@welshare/questionnaire/src/components/questions/multiple-choice-question.tsx +0 -119
  89. package/dist/node_modules/@welshare/questionnaire/src/components/questions/string-question.tsx +0 -31
  90. package/dist/node_modules/@welshare/questionnaire/src/contexts/questionnaire-context.tsx +0 -499
  91. package/dist/node_modules/@welshare/questionnaire/src/index.ts +0 -41
  92. package/dist/node_modules/@welshare/questionnaire/src/lib/__tests__/questionnaire-utils.test.ts +0 -578
  93. package/dist/node_modules/@welshare/questionnaire/src/lib/questionnaire-utils.ts +0 -122
  94. package/dist/node_modules/@welshare/questionnaire/src/types/fhir.ts +0 -126
  95. package/dist/node_modules/@welshare/questionnaire/src/types/index.ts +0 -44
  96. package/dist/node_modules/@welshare/questionnaire/tsconfig.json +0 -16
@@ -1,350 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createContext, useContext, useEffect, useState, } from "react";
3
- import { getAllQuestionsFromPage } from "../lib/questionnaire-utils.js";
4
- const QuestionnaireContext = createContext(undefined);
5
- export const useQuestionnaire = () => {
6
- const context = useContext(QuestionnaireContext);
7
- if (!context) {
8
- throw new Error("useQuestionnaire must be used within QuestionnaireProvider");
9
- }
10
- return context;
11
- };
12
- export const QuestionnaireProvider = ({ children, questionnaire, questionnaireId, useNestedStructure = true, }) => {
13
- const [response, setResponse] = useState({
14
- resourceType: "QuestionnaireResponse",
15
- status: "in-progress",
16
- item: [],
17
- });
18
- const [validationErrors, setValidationErrors] = useState(new Set());
19
- const [debugMode, setDebugMode] = useState(false);
20
- const toggleDebugMode = () => {
21
- setDebugMode((prev) => !prev);
22
- };
23
- // Determine the questionnaire ID to use
24
- const effectiveQuestionnaireId = questionnaireId || questionnaire.id;
25
- if (!effectiveQuestionnaireId) {
26
- throw new Error("QuestionnaireProvider: questionnaireId prop or questionnaire.id must be provided");
27
- }
28
- // Initialize response structure when questionnaire or options change
29
- useEffect(() => {
30
- if (useNestedStructure) {
31
- // Build response structure mirroring questionnaire hierarchy
32
- const buildResponseStructure = (questionnaireItems) => {
33
- if (!questionnaireItems)
34
- return [];
35
- return questionnaireItems.map((item) => {
36
- const responseItem = {
37
- linkId: item.linkId,
38
- };
39
- // Add text if present
40
- if (item.text) {
41
- responseItem.text = item.text;
42
- }
43
- // If item has nested items (group), recursively build structure
44
- if (item.item && item.item.length > 0) {
45
- responseItem.item = buildResponseStructure(item.item);
46
- }
47
- // If item has initial values, add them as answers
48
- if (item.initial && item.initial.length > 0) {
49
- responseItem.answer = item.initial;
50
- }
51
- return responseItem;
52
- });
53
- };
54
- const initialItems = buildResponseStructure(questionnaire.item);
55
- // Initialize response structure with hierarchical structure
56
- setResponse({
57
- resourceType: "QuestionnaireResponse",
58
- questionnaire: effectiveQuestionnaireId,
59
- status: "in-progress",
60
- authored: new Date().toISOString(),
61
- item: initialItems,
62
- });
63
- }
64
- else {
65
- // Flat structure initialization
66
- setResponse({
67
- resourceType: "QuestionnaireResponse",
68
- questionnaire: effectiveQuestionnaireId,
69
- status: "in-progress",
70
- authored: new Date().toISOString(),
71
- item: [],
72
- });
73
- }
74
- }, [questionnaire, effectiveQuestionnaireId, useNestedStructure]);
75
- const updateAnswer = (linkId, answer) => {
76
- setResponse((prev) => {
77
- const newResponse = { ...prev };
78
- if (useNestedStructure) {
79
- // Recursively find and update the item in the nested structure
80
- const updateNestedItem = (items = []) => {
81
- return items.map((item) => {
82
- // If this is the item we're looking for, update it
83
- if (item.linkId === linkId) {
84
- return {
85
- linkId: item.linkId,
86
- ...(item.definition && { definition: item.definition }),
87
- ...(item.text && { text: item.text }),
88
- answer: [answer],
89
- ...(item.item && { item: item.item }),
90
- };
91
- }
92
- // If this item has nested items, search within them
93
- if (item.item && item.item.length > 0) {
94
- return {
95
- ...item,
96
- item: updateNestedItem(item.item),
97
- };
98
- }
99
- return item;
100
- });
101
- };
102
- newResponse.item = updateNestedItem(newResponse.item);
103
- }
104
- else {
105
- // Flat structure: find or create the item
106
- const findOrCreateItem = (items = []) => {
107
- const existingIndex = items.findIndex((item) => item.linkId === linkId);
108
- if (existingIndex >= 0) {
109
- // Update existing item
110
- const updated = [...items];
111
- const existingItem = updated[existingIndex];
112
- updated[existingIndex] = {
113
- linkId: existingItem.linkId,
114
- ...(existingItem.definition && {
115
- definition: existingItem.definition,
116
- }),
117
- ...(existingItem.text && { text: existingItem.text }),
118
- answer: [answer],
119
- ...(existingItem.item && { item: existingItem.item }),
120
- };
121
- return updated;
122
- }
123
- else {
124
- // Create new item
125
- return [
126
- ...items,
127
- {
128
- linkId,
129
- answer: [answer],
130
- },
131
- ];
132
- }
133
- };
134
- newResponse.item = findOrCreateItem(newResponse.item);
135
- }
136
- return newResponse;
137
- });
138
- // Clear validation error for this question when answered
139
- setValidationErrors((prev) => {
140
- const newErrors = new Set(prev);
141
- newErrors.delete(linkId);
142
- return newErrors;
143
- });
144
- };
145
- const updateMultipleAnswers = (linkId, answers) => {
146
- setResponse((prev) => {
147
- const newResponse = { ...prev };
148
- if (useNestedStructure) {
149
- // Recursively find and update the item in the nested structure
150
- const updateNestedItem = (items = []) => {
151
- return items.map((item) => {
152
- // If this is the item we're looking for, update it
153
- if (item.linkId === linkId) {
154
- return {
155
- linkId: item.linkId,
156
- ...(item.definition && { definition: item.definition }),
157
- ...(item.text && { text: item.text }),
158
- answer: answers,
159
- ...(item.item && { item: item.item }),
160
- };
161
- }
162
- // If this item has nested items, search within them
163
- if (item.item && item.item.length > 0) {
164
- return {
165
- ...item,
166
- item: updateNestedItem(item.item),
167
- };
168
- }
169
- return item;
170
- });
171
- };
172
- newResponse.item = updateNestedItem(newResponse.item);
173
- }
174
- else {
175
- // Flat structure
176
- const findOrCreateItem = (items = []) => {
177
- const existingIndex = items.findIndex((item) => item.linkId === linkId);
178
- if (existingIndex >= 0) {
179
- const updated = [...items];
180
- const existingItem = updated[existingIndex];
181
- updated[existingIndex] = {
182
- linkId: existingItem.linkId,
183
- ...(existingItem.definition && {
184
- definition: existingItem.definition,
185
- }),
186
- ...(existingItem.text && { text: existingItem.text }),
187
- answer: answers,
188
- ...(existingItem.item && { item: existingItem.item }),
189
- };
190
- return updated;
191
- }
192
- else {
193
- return [
194
- ...items,
195
- {
196
- linkId,
197
- answer: answers,
198
- },
199
- ];
200
- }
201
- };
202
- newResponse.item = findOrCreateItem(newResponse.item);
203
- }
204
- return newResponse;
205
- });
206
- // Clear validation error for this question when answered
207
- setValidationErrors((prev) => {
208
- const newErrors = new Set(prev);
209
- newErrors.delete(linkId);
210
- return newErrors;
211
- });
212
- };
213
- const getAnswer = (linkId) => {
214
- // Recursively search for the item in nested structure or flat structure
215
- const findItem = (items) => {
216
- if (!items)
217
- return undefined;
218
- for (const item of items) {
219
- if (item.linkId === linkId) {
220
- return item;
221
- }
222
- if (item.item && item.item.length > 0) {
223
- const found = findItem(item.item);
224
- if (found)
225
- return found;
226
- }
227
- }
228
- return undefined;
229
- };
230
- const item = findItem(response.item);
231
- return item?.answer?.[0];
232
- };
233
- const getAnswers = (linkId) => {
234
- // Recursively search for the item in nested structure or flat structure
235
- const findItem = (items) => {
236
- if (!items)
237
- return undefined;
238
- for (const item of items) {
239
- if (item.linkId === linkId) {
240
- return item;
241
- }
242
- if (item.item && item.item.length > 0) {
243
- const found = findItem(item.item);
244
- if (found)
245
- return found;
246
- }
247
- }
248
- return undefined;
249
- };
250
- const item = findItem(response.item);
251
- return item?.answer || [];
252
- };
253
- const getRequiredQuestions = (pageItems) => {
254
- // Recursively flatten nested groups so required questions inside them
255
- // are included in page validation.
256
- const allQuestionsOnPage = getAllQuestionsFromPage({
257
- linkId: "__page__",
258
- type: "group",
259
- item: pageItems,
260
- });
261
- return allQuestionsOnPage.filter((item) => item.required === true);
262
- };
263
- const isNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
264
- const hasMeaningfulAnswer = (answer) => {
265
- if (!answer)
266
- return false;
267
- // Primitive numeric/boolean values are meaningful even when 0/false.
268
- if (answer.valueBoolean !== undefined)
269
- return true;
270
- if (answer.valueInteger !== undefined)
271
- return true;
272
- if (answer.valueDecimal !== undefined)
273
- return true;
274
- // String-like answers must be non-empty (trimmed) to be meaningful.
275
- if (isNonEmptyString(answer.valueString))
276
- return true;
277
- if (isNonEmptyString(answer.valueDate))
278
- return true;
279
- if (isNonEmptyString(answer.valueDateTime))
280
- return true;
281
- if (isNonEmptyString(answer.valueTime))
282
- return true;
283
- if (isNonEmptyString(answer.valueUri))
284
- return true;
285
- // Coding answers are meaningful when they contain at least one identifier.
286
- if (answer.valueCoding &&
287
- (isNonEmptyString(answer.valueCoding.code) ||
288
- isNonEmptyString(answer.valueCoding.display) ||
289
- isNonEmptyString(answer.valueCoding.system))) {
290
- return true;
291
- }
292
- // Quantity answers are meaningful when a value is provided.
293
- if (answer.valueQuantity?.value !== undefined)
294
- return true;
295
- return false;
296
- };
297
- const isPageValid = (pageItems) => {
298
- const requiredQuestions = getRequiredQuestions(pageItems);
299
- return requiredQuestions.every((question) => {
300
- // For multi-select questions (repeats = true), check if there's at least one answer
301
- if (question.repeats) {
302
- const answers = getAnswers(question.linkId);
303
- return answers.some((a) => hasMeaningfulAnswer(a));
304
- }
305
- // For single-answer questions
306
- const answer = getAnswer(question.linkId);
307
- return hasMeaningfulAnswer(answer);
308
- });
309
- };
310
- const getUnansweredRequiredQuestions = (pageItems) => {
311
- const requiredQuestions = getRequiredQuestions(pageItems);
312
- return requiredQuestions.filter((question) => {
313
- // For multi-select questions (repeats = true), check if there's at least one answer
314
- if (question.repeats) {
315
- const answers = getAnswers(question.linkId);
316
- return !answers.some((a) => hasMeaningfulAnswer(a));
317
- }
318
- // For single-answer questions
319
- const answer = getAnswer(question.linkId);
320
- return !hasMeaningfulAnswer(answer);
321
- });
322
- };
323
- const markValidationErrors = (pageItems) => {
324
- const unansweredRequired = getUnansweredRequiredQuestions(pageItems);
325
- const errorLinkIds = unansweredRequired.map((q) => q.linkId);
326
- setValidationErrors(new Set(errorLinkIds));
327
- };
328
- const clearValidationErrors = () => {
329
- setValidationErrors(new Set());
330
- };
331
- const hasValidationError = (linkId) => {
332
- return validationErrors.has(linkId);
333
- };
334
- return (_jsx(QuestionnaireContext.Provider, { value: {
335
- questionnaire,
336
- response,
337
- updateAnswer,
338
- updateMultipleAnswers,
339
- getAnswer,
340
- getAnswers,
341
- isPageValid,
342
- getRequiredQuestions,
343
- getUnansweredRequiredQuestions,
344
- markValidationErrors,
345
- clearValidationErrors,
346
- hasValidationError,
347
- debugMode,
348
- toggleDebugMode,
349
- }, children: children }));
350
- };
@@ -1,7 +0,0 @@
1
- export { QuestionRenderer } from "./components/question-renderer.js";
2
- export type { QuestionRendererProps } from "./components/question-renderer.js";
3
- export { QuestionnaireProvider, useQuestionnaire, type QuestionnaireContextType, type QuestionnaireProviderProps, } from "./contexts/questionnaire-context.js";
4
- export type { Coding, Extension, Questionnaire, QuestionnaireItem, QuestionnaireItemAnswerOption, QuestionnaireResponse, QuestionnaireResponseAnswer, QuestionnaireResponseItem, } from "./types/fhir.js";
5
- export type { RadioInputProps, CheckboxInputProps, } from "./types/index.js";
6
- export { calculateProgress, findQuestionnaireItem, getAllQuestionsFromPage, getExclusiveOptionCode, getVisiblePages, hasAnswerValue, isQuestionHidden, } from "./lib/questionnaire-utils.js";
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,YAAY,EACV,qBAAqB,EACtB,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,GAChC,MAAM,qCAAqC,CAAC;AAG7C,YAAY,EACV,MAAM,EACN,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,6BAA6B,EAC7B,qBAAqB,EACrB,2BAA2B,EAC3B,yBAAyB,GAC1B,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,eAAe,EACf,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,eAAe,EACf,cAAc,EACd,gBAAgB,GACjB,MAAM,8BAA8B,CAAC"}
@@ -1,6 +0,0 @@
1
- // Components
2
- export { QuestionRenderer } from "./components/question-renderer.js";
3
- // Contexts
4
- export { QuestionnaireProvider, useQuestionnaire, } from "./contexts/questionnaire-context.js";
5
- // Utils
6
- export { calculateProgress, findQuestionnaireItem, getAllQuestionsFromPage, getExclusiveOptionCode, getVisiblePages, hasAnswerValue, isQuestionHidden, } from "./lib/questionnaire-utils.js";
@@ -1,33 +0,0 @@
1
- import type { Questionnaire, QuestionnaireItem } from "../types/fhir.js";
2
- /**
3
- * Get visible pages from a questionnaire (excludes hidden groups)
4
- */
5
- export declare const getVisiblePages: (questionnaire: Questionnaire) => QuestionnaireItem[];
6
- /**
7
- * Calculate progress percentage
8
- * @param currentPageIndex 0-based page index
9
- * @param totalPages Total number of pages
10
- * @returns Progress percentage (0-100)
11
- */
12
- export declare const calculateProgress: (currentPageIndex: number, totalPages: number) => number;
13
- /**
14
- * Get all questions from a page (flattens nested groups)
15
- */
16
- export declare const getAllQuestionsFromPage: (pageItem: QuestionnaireItem) => QuestionnaireItem[];
17
- /**
18
- * Recursively searches for a questionnaire item by linkId
19
- */
20
- export declare function findQuestionnaireItem(items: QuestionnaireItem[] | undefined, linkId: string): QuestionnaireItem | null;
21
- /**
22
- * Check if a question has any answer value
23
- */
24
- export declare const hasAnswerValue: (answer: any) => boolean;
25
- /**
26
- * Check if a question item should be hidden based on extensions
27
- */
28
- export declare const isQuestionHidden: (item: QuestionnaireItem) => boolean;
29
- /**
30
- * Get the exclusive option code from a question item (if any)
31
- */
32
- export declare const getExclusiveOptionCode: (item: QuestionnaireItem) => string | undefined;
33
- //# sourceMappingURL=questionnaire-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"questionnaire-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/questionnaire-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAEzE;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,eAAe,aAAa,KAAG,iBAAiB,EAc/E,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,kBAAkB,MAAM,EAAE,YAAY,MAAM,KAAG,MAGhF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAAI,UAAU,iBAAiB,KAAG,iBAAiB,EAsBtF,CAAC;AAEF;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,iBAAiB,EAAE,GAAG,SAAS,EACtC,MAAM,EAAE,MAAM,GACb,iBAAiB,GAAG,IAAI,CAe1B;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,GAAG,KAAG,OAe5C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,iBAAiB,KAAG,OAM1D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAAI,MAAM,iBAAiB,KAAG,MAAM,GAAG,SAKzE,CAAC"}
@@ -1,99 +0,0 @@
1
- /**
2
- * Get visible pages from a questionnaire (excludes hidden groups)
3
- */
4
- export const getVisiblePages = (questionnaire) => {
5
- if (!questionnaire.item)
6
- return [];
7
- return questionnaire.item.filter((item) => {
8
- // Check if hidden
9
- const isHidden = item.extension?.some((ext) => ext.url === "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden" &&
10
- ext.valueBoolean === true);
11
- // Only include visible group items
12
- return item.type === "group" && !isHidden;
13
- });
14
- };
15
- /**
16
- * Calculate progress percentage
17
- * @param currentPageIndex 0-based page index
18
- * @param totalPages Total number of pages
19
- * @returns Progress percentage (0-100)
20
- */
21
- export const calculateProgress = (currentPageIndex, totalPages) => {
22
- if (totalPages === 0)
23
- return 0;
24
- return ((currentPageIndex + 1) / totalPages) * 100;
25
- };
26
- /**
27
- * Get all questions from a page (flattens nested groups)
28
- */
29
- export const getAllQuestionsFromPage = (pageItem) => {
30
- const questions = [];
31
- const collectQuestions = (items) => {
32
- if (!items)
33
- return;
34
- for (const item of items) {
35
- if (item.type === "group" && item.item) {
36
- // Recursively collect from nested groups
37
- collectQuestions(item.item);
38
- }
39
- else if (item.type !== "display") {
40
- // Add non-display items (actual questions)
41
- questions.push(item);
42
- }
43
- }
44
- };
45
- if (pageItem.item) {
46
- collectQuestions(pageItem.item);
47
- }
48
- return questions;
49
- };
50
- /**
51
- * Recursively searches for a questionnaire item by linkId
52
- */
53
- export function findQuestionnaireItem(items, linkId) {
54
- if (!items)
55
- return null;
56
- for (const item of items) {
57
- if (item.linkId === linkId) {
58
- return item;
59
- }
60
- // Recursively search nested items
61
- if (item.item && item.item.length > 0) {
62
- const found = findQuestionnaireItem(item.item, linkId);
63
- if (found)
64
- return found;
65
- }
66
- }
67
- return null;
68
- }
69
- /**
70
- * Check if a question has any answer value
71
- */
72
- export const hasAnswerValue = (answer) => {
73
- if (!answer)
74
- return false;
75
- return (answer.valueBoolean !== undefined ||
76
- answer.valueInteger !== undefined ||
77
- answer.valueDecimal !== undefined ||
78
- answer.valueString !== undefined ||
79
- answer.valueCoding !== undefined ||
80
- answer.valueDate !== undefined ||
81
- answer.valueDateTime !== undefined ||
82
- answer.valueTime !== undefined ||
83
- answer.valueUri !== undefined ||
84
- answer.valueQuantity !== undefined);
85
- };
86
- /**
87
- * Check if a question item should be hidden based on extensions
88
- */
89
- export const isQuestionHidden = (item) => {
90
- return item.extension?.some((ext) => ext.url === "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden" &&
91
- ext.valueBoolean === true) ?? false;
92
- };
93
- /**
94
- * Get the exclusive option code from a question item (if any)
95
- */
96
- export const getExclusiveOptionCode = (item) => {
97
- const exclusiveExt = item.extension?.find((ext) => ext.url === "http://codes.welshare.app/StructureDefinition/questionnaire-exclusive-option");
98
- return exclusiveExt?.valueString;
99
- };
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
@@ -1,117 +0,0 @@
1
- export type Coding = {
2
- system?: string;
3
- version?: string;
4
- code?: string;
5
- display?: string;
6
- userSelected?: boolean;
7
- };
8
- export type QuestionnaireItemAnswerOption = {
9
- valueCoding?: Coding;
10
- valueInteger?: number;
11
- valueDate?: string;
12
- valueTime?: string;
13
- valueString?: string;
14
- initialSelected?: boolean;
15
- };
16
- export type Extension = {
17
- url: string;
18
- valueBoolean?: boolean;
19
- valueString?: string;
20
- valueInteger?: number;
21
- valueCodeableConcept?: {
22
- coding?: Coding[];
23
- };
24
- valueExpression?: {
25
- language?: string;
26
- expression?: string;
27
- };
28
- extension?: Extension[];
29
- };
30
- export type QuestionnaireItem = {
31
- linkId: string;
32
- definition?: string;
33
- code?: Coding[];
34
- prefix?: string;
35
- text?: string;
36
- type: 'group' | 'display' | 'boolean' | 'decimal' | 'integer' | 'date' | 'dateTime' | 'time' | 'string' | 'text' | 'url' | 'choice' | 'open-choice' | 'attachment' | 'reference' | 'quantity';
37
- enableWhen?: Array<{
38
- question: string;
39
- operator: string;
40
- answerBoolean?: boolean;
41
- answerDecimal?: number;
42
- answerInteger?: number;
43
- answerDate?: string;
44
- answerDateTime?: string;
45
- answerTime?: string;
46
- answerString?: string;
47
- answerCoding?: Coding;
48
- }>;
49
- enableBehavior?: string;
50
- required?: boolean;
51
- repeats?: boolean;
52
- readOnly?: boolean;
53
- maxLength?: number;
54
- maxAnswers?: number;
55
- answerValueSet?: string;
56
- answerOption?: QuestionnaireItemAnswerOption[];
57
- initial?: Array<{
58
- valueBoolean?: boolean;
59
- valueDecimal?: number;
60
- valueInteger?: number;
61
- valueDate?: string;
62
- valueDateTime?: string;
63
- valueTime?: string;
64
- valueString?: string;
65
- valueCoding?: Coding;
66
- }>;
67
- extension?: Extension[];
68
- item?: QuestionnaireItem[];
69
- };
70
- export type Questionnaire = {
71
- resourceType: 'Questionnaire';
72
- id: string;
73
- url?: string;
74
- version?: string;
75
- name?: string;
76
- title?: string;
77
- status: 'draft' | 'active' | 'retired' | 'unknown';
78
- subjectType?: string[];
79
- date?: string;
80
- publisher?: string;
81
- description?: string;
82
- item?: QuestionnaireItem[];
83
- };
84
- export type QuestionnaireResponseAnswer = {
85
- valueBoolean?: boolean;
86
- valueDecimal?: number;
87
- valueInteger?: number;
88
- valueDate?: string;
89
- valueDateTime?: string;
90
- valueTime?: string;
91
- valueString?: string;
92
- valueUri?: string;
93
- valueCoding?: Coding;
94
- valueQuantity?: {
95
- value?: number;
96
- unit?: string;
97
- system?: string;
98
- code?: string;
99
- };
100
- item?: QuestionnaireResponseItem[];
101
- };
102
- export type QuestionnaireResponseItem = {
103
- linkId: string;
104
- definition?: string;
105
- text?: string;
106
- answer?: QuestionnaireResponseAnswer[];
107
- item?: QuestionnaireResponseItem[];
108
- };
109
- export type QuestionnaireResponse = {
110
- resourceType: 'QuestionnaireResponse';
111
- id?: string;
112
- questionnaire?: string;
113
- status: 'in-progress' | 'completed' | 'amended' | 'entered-in-error' | 'stopped';
114
- authored?: string;
115
- item?: QuestionnaireResponseItem[];
116
- };
117
- //# sourceMappingURL=fhir.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fhir.d.ts","sourceRoot":"","sources":["../../../src/types/fhir.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,MAAM,GAAG;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAA;AAED,MAAM,MAAM,6BAA6B,GAAG;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE;QACrB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;IACF,eAAe,CAAC,EAAE;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,SAAS,CAAC,EAAE,SAAS,EAAE,CAAC;CACzB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM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AAI,CAAC,EAAE,yBAAyB,EAAE,CAAC;CACpC,CAAA;AAED,MAAM,MAAM,yBAAyB,GAAG;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,2BAA2B,EAAE,CAAC;IACvC,IAAI,CAAC,EAAE,yBAAyB,EAAE,CAAC;CACpC,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,EAAE,uBAAuB,CAAC;IACtC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,aAAa,GAAG,WAAW,GAAG,SAAS,GAAG,kBAAkB,GAAG,SAAS,CAAC;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,yBAAyB,EAAE,CAAC;CACpC,CAAA"}
@@ -1,3 +0,0 @@
1
- // FHIR Types for Questionnaire and QuestionnaireResponse
2
- // Based on FHIR R4 Specification with extensions commonly used in Welshare surveys
3
- export {};