@ltht-react/table 2.0.162 → 2.0.164

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.
@@ -1,349 +1,351 @@
1
- import { CSSProperties } from 'react'
2
- import { ActionMenuOption } from '@ltht-react/menu'
3
- import {
4
- Axis,
5
- Maybe,
6
- Questionnaire,
7
- QuestionnaireItem,
8
- QuestionnaireResponse,
9
- QuestionnaireResponseItem,
10
- QuestionnaireResponseItemAnswer,
11
- QuestionnaireResponseStatus,
12
- } from '@ltht-react/types'
13
- import { EnsureMaybe, EnsureMaybeArray, partialDateTimeText } from '@ltht-react/utils'
14
- import { getZIndex, TableDataWithPopUp } from '@ltht-react/styles'
15
- import { DataEntity, Header, TableData } from '../molecules/table'
16
- import { CellProps } from '../molecules/table-cell'
17
- import QuestionnaireWithdrawnTableCell from '../atoms/questionnaire-withdrawn-table-cell'
18
-
19
- const DEFAULT_VERTICAL_HEADER_CELL_STYLE: CSSProperties = {
20
- maxWidth: '15rem',
21
- textWrap: 'wrap',
22
- textAlign: 'left',
23
- }
24
-
25
- const withdrawnWrapper = (text: string): JSX.Element => <QuestionnaireWithdrawnTableCell text={text} />
26
-
27
- const mapQuestionnaireDefinitionAndResponsesToTableData = (
28
- definition: Questionnaire,
29
- questionnaireResponses: QuestionnaireResponse[],
30
- axis: Axis,
31
- adminActions?: AdminActionsForQuestionnaire[]
32
- ): TableData | undefined => {
33
- const definitionItems = EnsureMaybeArray<QuestionnaireItem>(
34
- EnsureMaybe<Maybe<QuestionnaireItem>[]>(definition.item, [])
35
- )
36
-
37
- if (definitionItems.length === 0) {
38
- return undefined
39
- }
40
-
41
- if (axis === 'y') {
42
- return mapQuestionnaireObjectsToVerticalTableData(definitionItems, questionnaireResponses, adminActions)
43
- }
44
- return mapQuestionnaireObjectsToHorizontalTableData(definitionItems, questionnaireResponses, adminActions)
45
- }
46
-
47
- const mapQuestionnaireObjectsToHorizontalTableData = (
48
- definitionItems: Array<QuestionnaireItem>,
49
- records: QuestionnaireResponse[],
50
- adminActions?: AdminActionsForQuestionnaire[]
51
- ): TableData => {
52
- const tableData: TableData = {
53
- headers: [
54
- {
55
- id: 'date',
56
- type: 'accessor',
57
- cellProps: { text: 'Record Date' },
58
- },
59
- ...recursivelyMapQuestionnaireItemsIntoHeaders(definitionItems),
60
- ],
61
- rows: mapQuestionnaireResponsesIntoDataEntities(records, adminActions),
62
- }
63
-
64
- if (adminActions) {
65
- tableData.headers.splice(1, 0, {
66
- id: 'adminactions',
67
- type: 'accessor',
68
- cellProps: { text: 'Actions' },
69
- })
70
- }
71
- return tableData
72
- }
73
-
74
- const recursivelyMapQuestionnaireItemsIntoHeaders = (questionnaireItems: QuestionnaireItem[]): Header[] =>
75
- questionnaireItems.map((questionnaireItem) => {
76
- const subItems = EnsureMaybeArray<QuestionnaireItem>(questionnaireItem.item ?? [])
77
-
78
- return {
79
- id: questionnaireItem?.linkId ?? '',
80
- type: subItems.length > 0 ? 'group' : 'accessor',
81
- cellProps: { text: questionnaireItem?.text ?? '' },
82
- subHeaders: recursivelyMapQuestionnaireItemsIntoHeaders(subItems),
83
- }
84
- })
85
-
86
- const mapQuestionnaireResponsesIntoDataEntities = (
87
- records: QuestionnaireResponse[],
88
- adminActions?: AdminActionsForQuestionnaire[]
89
- ): DataEntity[] =>
90
- records
91
- .filter((record) => !!record.item)
92
- .map((record) => {
93
- let dataEntity: DataEntity = {}
94
-
95
- dataEntity.date = {
96
- customComponentOverride:
97
- record.status === QuestionnaireResponseStatus.EnteredInError
98
- ? withdrawnWrapper(partialDateTimeText(record.authored))
99
- : undefined,
100
- text: partialDateTimeText(record.authored),
101
- }
102
-
103
- if (adminActions) {
104
- const adminActionsForThisDataEntity = adminActions.find(
105
- (actionForForm) => actionForForm.questionnaire === record.id
106
- )
107
- if (adminActionsForThisDataEntity) {
108
- dataEntity.adminactions = {
109
- adminActions: adminActionsForThisDataEntity.adminActions,
110
- parentStyle: { zIndex: getZIndex(TableDataWithPopUp) },
111
- }
112
- }
113
- }
114
- record.item
115
- ?.filter((item) => item?.linkId && item?.answer)
116
- .forEach((item) => {
117
- const linkId = EnsureMaybe<string>(item?.linkId)
118
- const answer = EnsureMaybe<QuestionnaireResponseItemAnswer>(item?.answer?.find((answer) => !!answer))
119
-
120
- dataEntity[linkId] = createCellPropsForAnswer(
121
- answer,
122
- false,
123
- record.status === QuestionnaireResponseStatus.EnteredInError
124
- )
125
-
126
- if (answer.item) {
127
- dataEntity = recursivelyMapResponseItemsOntoData(
128
- EnsureMaybeArray<QuestionnaireResponseItem>(answer.item),
129
- dataEntity,
130
- record.status
131
- )
132
- }
133
- })
134
-
135
- return dataEntity
136
- })
137
-
138
- const recursivelyMapResponseItemsOntoData = (
139
- items: QuestionnaireResponseItem[],
140
- dataEntity: DataEntity,
141
- status: QuestionnaireResponseStatus
142
- ): DataEntity => {
143
- let updatedDataEntity = { ...dataEntity }
144
- items.forEach((item) => {
145
- const firstAnswer = item.answer ? item.answer[0] : undefined
146
-
147
- if (item.linkId && firstAnswer) {
148
- const props = createCellPropsForAnswer(firstAnswer, false, status === QuestionnaireResponseStatus.EnteredInError)
149
- updatedDataEntity[item.linkId] = {
150
- customComponentOverride: props.customComponentOverride,
151
- text: props.text,
152
- }
153
-
154
- if (firstAnswer.item) {
155
- updatedDataEntity = recursivelyMapResponseItemsOntoData(
156
- EnsureMaybeArray<QuestionnaireResponseItem>(firstAnswer.item),
157
- updatedDataEntity,
158
- status
159
- )
160
- }
161
- }
162
- })
163
- return updatedDataEntity
164
- }
165
-
166
- const mapQuestionnaireObjectsToVerticalTableData = (
167
- definitionItems: Array<QuestionnaireItem>,
168
- records: QuestionnaireResponse[],
169
- adminActions?: AdminActionsForQuestionnaire[]
170
- ): TableData => ({
171
- headers: [
172
- {
173
- id: 'property',
174
- type: 'accessor',
175
- cellProps: { text: '' },
176
- },
177
- ...records.map(
178
- (record): Header => ({
179
- id: record?.id ?? '',
180
- type: 'accessor',
181
- cellProps: {
182
- customComponentOverride:
183
- record.status === QuestionnaireResponseStatus.EnteredInError
184
- ? withdrawnWrapper(partialDateTimeText(record.authored) ?? '')
185
- : undefined,
186
- text: partialDateTimeText(record.authored) ?? '',
187
- },
188
- })
189
- ),
190
- ],
191
- rows: buildVerticalCellRows(definitionItems, records, adminActions),
192
- })
193
-
194
- const buildVerticalCellRows = (
195
- definitionItems: QuestionnaireItem[],
196
- records: QuestionnaireResponse[],
197
- adminActions?: AdminActionsForQuestionnaire[]
198
- ): DataEntity[] => {
199
- const dataEntities = definitionItems.map((item) => {
200
- let dataEntity: DataEntity = {}
201
-
202
- dataEntity = buildVerticalCellRowsRecursive(EnsureMaybeArray<QuestionnaireItem>([item]), records, dataEntity)
203
-
204
- return dataEntity
205
- })
206
-
207
- if (adminActions) {
208
- const actionsDataEntity: DataEntity = {}
209
- actionsDataEntity.property = { text: 'Actions', parentStyle: DEFAULT_VERTICAL_HEADER_CELL_STYLE }
210
-
211
- records.forEach((record) => {
212
- const adminActionsForThisDataEntity = adminActions.find(
213
- (actionForForm) => actionForForm.questionnaire === record.id
214
- )
215
-
216
- if (adminActionsForThisDataEntity) {
217
- actionsDataEntity[record.id] = {
218
- adminActions: adminActionsForThisDataEntity.adminActions,
219
- parentStyle: { zIndex: getZIndex(TableDataWithPopUp) },
220
- }
221
- }
222
- })
223
-
224
- return [actionsDataEntity].concat(dataEntities)
225
- }
226
- return dataEntities
227
- }
228
-
229
- const buildVerticalCellRowsRecursive = (
230
- definitionItems: QuestionnaireItem[],
231
- records: QuestionnaireResponse[],
232
- dataEntity: DataEntity
233
- ): DataEntity => {
234
- let updatedDataEntity = { ...dataEntity }
235
- definitionItems.forEach((definitionItem) => {
236
- const containsChildItems = !!definitionItem.item && definitionItem.item.length > 0
237
-
238
- updatedDataEntity.property = {
239
- text: definitionItem.text ?? '',
240
- parentStyle: {
241
- ...DEFAULT_VERTICAL_HEADER_CELL_STYLE,
242
- fontWeight: containsChildItems ? 'bold' : 'normal',
243
- },
244
- }
245
-
246
- if (definitionItem.linkId) {
247
- records.forEach((record) => {
248
- updatedDataEntity = getRecordItemByLinkId(
249
- EnsureMaybeArray<QuestionnaireResponseItem>(record.item ?? []),
250
- EnsureMaybe<string>(definitionItem.linkId),
251
- updatedDataEntity,
252
- record.id,
253
- record.status
254
- )
255
- })
256
- }
257
-
258
- if (definitionItem.item && definitionItem.item.length > 0) {
259
- updatedDataEntity.subRows = buildVerticalCellRows(
260
- EnsureMaybeArray<QuestionnaireItem>(definitionItem.item),
261
- records
262
- )
263
- }
264
- })
265
-
266
- return updatedDataEntity
267
- }
268
-
269
- const getRecordItemByLinkId = (
270
- recordItems: QuestionnaireResponseItem[],
271
- linkId: string,
272
- dataEntity: DataEntity,
273
- recordId: string,
274
- status: QuestionnaireResponseStatus
275
- ) => {
276
- let updatedDataEntity = { ...dataEntity }
277
- recordItems.forEach((recordItem) => {
278
- const recordItemAnswer =
279
- recordItem.answer && recordItem.answer.length > 0 ? EnsureMaybe(recordItem.answer[0]) : undefined
280
-
281
- if (recordItemAnswer) {
282
- if (recordItem?.linkId && recordItem?.linkId === linkId) {
283
- updatedDataEntity[recordId] = createCellPropsForAnswer(
284
- recordItemAnswer,
285
- true,
286
- status === QuestionnaireResponseStatus.EnteredInError
287
- )
288
- }
289
- if (recordItemAnswer.item && recordItemAnswer.item.length > 0) {
290
- updatedDataEntity = getRecordItemByLinkId(
291
- EnsureMaybeArray<QuestionnaireResponseItem>(recordItemAnswer.item),
292
- linkId,
293
- updatedDataEntity,
294
- recordId,
295
- status
296
- )
297
- }
298
- }
299
- })
300
-
301
- return updatedDataEntity
302
- }
303
-
304
- const createCellPropsForAnswer = (
305
- answer: QuestionnaireResponseItemAnswer,
306
- shouldRenderCheckbox: boolean,
307
- isEnteredInError: boolean
308
- ): CellProps => {
309
- if (answer.valueString) {
310
- if (shouldRenderCheckbox && answer.valueString === 'CHECKBOX') {
311
- return {
312
- iconProps: { type: 'checkbox', size: 'medium' },
313
- }
314
- }
315
- return {
316
- customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueString) : undefined,
317
- text: answer.valueString,
318
- }
319
- }
320
- if (answer.valueBoolean != null) {
321
- const parsedBoolean = answer.valueBoolean ? 'Yes' : 'No'
322
- return {
323
- customComponentOverride: isEnteredInError ? withdrawnWrapper(parsedBoolean) : undefined,
324
- text: parsedBoolean,
325
- }
326
- }
327
- if (answer.valueInteger != null) {
328
- return {
329
- customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueInteger.toString()) : undefined,
330
- text: answer.valueInteger.toString(),
331
- }
332
- }
333
- if (answer.valueDecimal != null) {
334
- return {
335
- customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueDecimal.toString()) : undefined,
336
- text: answer.valueDecimal.toString(),
337
- }
338
- }
339
- return {
340
- text: '',
341
- }
342
- }
343
-
344
- export interface AdminActionsForQuestionnaire {
345
- questionnaire: string
346
- adminActions: ActionMenuOption[]
347
- }
348
-
349
- export default mapQuestionnaireDefinitionAndResponsesToTableData
1
+ import { CSSProperties } from 'react'
2
+ import { ActionMenuOption } from '@ltht-react/menu'
3
+ import {
4
+ Axis,
5
+ Maybe,
6
+ Questionnaire,
7
+ QuestionnaireItem,
8
+ QuestionnaireResponse,
9
+ QuestionnaireResponseItem,
10
+ QuestionnaireResponseItemAnswer,
11
+ QuestionnaireResponseStatus,
12
+ } from '@ltht-react/types'
13
+ import { EnsureMaybe, EnsureMaybeArray, partialDateTimeText } from '@ltht-react/utils'
14
+ import { getZIndex, TableDataWithPopUp } from '@ltht-react/styles'
15
+ import { DataEntity, Header, TableData } from '../molecules/table'
16
+ import { CellProps } from '../molecules/table-cell'
17
+ import QuestionnaireWithdrawnTableCell from '../atoms/questionnaire-withdrawn-table-cell'
18
+
19
+ const DEFAULT_VERTICAL_HEADER_CELL_STYLE: CSSProperties = {
20
+ maxWidth: '15rem',
21
+ textWrap: 'wrap',
22
+ textAlign: 'left',
23
+ }
24
+
25
+ const withdrawnWrapper = (text: string): JSX.Element => <QuestionnaireWithdrawnTableCell text={text} />
26
+
27
+ const mapQuestionnaireDefinitionAndResponsesToTableData = (
28
+ definition: Questionnaire,
29
+ questionnaireResponses: QuestionnaireResponse[],
30
+ axis: Axis,
31
+ adminActions?: AdminActionsForQuestionnaire[]
32
+ ): TableData | undefined => {
33
+ const definitionItems = EnsureMaybeArray<QuestionnaireItem>(
34
+ EnsureMaybe<Maybe<QuestionnaireItem>[]>(definition.item, [])
35
+ )
36
+
37
+ if (definitionItems.length === 0) {
38
+ return undefined
39
+ }
40
+
41
+ if (axis === 'y') {
42
+ return mapQuestionnaireObjectsToVerticalTableData(definitionItems, questionnaireResponses, adminActions)
43
+ }
44
+ return mapQuestionnaireObjectsToHorizontalTableData(definitionItems, questionnaireResponses, adminActions)
45
+ }
46
+
47
+ const mapQuestionnaireObjectsToHorizontalTableData = (
48
+ definitionItems: Array<QuestionnaireItem>,
49
+ records: QuestionnaireResponse[],
50
+ adminActions?: AdminActionsForQuestionnaire[]
51
+ ): TableData => {
52
+ const tableData: TableData = {
53
+ headers: [
54
+ {
55
+ id: 'date',
56
+ type: 'accessor',
57
+ cellProps: { text: 'Record Date' },
58
+ },
59
+ ...recursivelyMapQuestionnaireItemsIntoHeaders(definitionItems),
60
+ ],
61
+ rows: mapQuestionnaireResponsesIntoDataEntities(records, adminActions),
62
+ }
63
+
64
+ if (adminActions) {
65
+ tableData.headers.splice(1, 0, {
66
+ id: 'adminactions',
67
+ type: 'accessor',
68
+ cellProps: { text: 'Actions' },
69
+ })
70
+ }
71
+ return tableData
72
+ }
73
+
74
+ const recursivelyMapQuestionnaireItemsIntoHeaders = (questionnaireItems: QuestionnaireItem[]): Header[] =>
75
+ questionnaireItems.map((questionnaireItem) => {
76
+ const subItems = EnsureMaybeArray<QuestionnaireItem>(questionnaireItem.item ?? [])
77
+
78
+ return {
79
+ id: questionnaireItem?.linkId ?? '',
80
+ type: subItems.length > 0 ? 'group' : 'accessor',
81
+ cellProps: { text: questionnaireItem?.text ?? '' },
82
+ subHeaders: recursivelyMapQuestionnaireItemsIntoHeaders(subItems),
83
+ }
84
+ })
85
+
86
+ const mapQuestionnaireResponsesIntoDataEntities = (
87
+ records: QuestionnaireResponse[],
88
+ adminActions?: AdminActionsForQuestionnaire[]
89
+ ): DataEntity[] =>
90
+ records
91
+ .filter((record) => !!record.item)
92
+ .map((record) => {
93
+ let dataEntity: DataEntity = {}
94
+
95
+ dataEntity.date = {
96
+ customComponentOverride:
97
+ record.status === QuestionnaireResponseStatus.EnteredInError
98
+ ? withdrawnWrapper(partialDateTimeText(record.authored))
99
+ : undefined,
100
+ text: partialDateTimeText(record.authored),
101
+ }
102
+
103
+ if (adminActions) {
104
+ const adminActionsForThisDataEntity = adminActions.find(
105
+ (actionForForm) => actionForForm.questionnaire === record.id
106
+ )
107
+ if (adminActionsForThisDataEntity) {
108
+ dataEntity.adminactions = {
109
+ id: record.id,
110
+ adminActions: adminActionsForThisDataEntity.adminActions,
111
+ parentStyle: { zIndex: getZIndex(TableDataWithPopUp) },
112
+ }
113
+ }
114
+ }
115
+ record.item
116
+ ?.filter((item) => item?.linkId && item?.answer)
117
+ .forEach((item) => {
118
+ const linkId = EnsureMaybe<string>(item?.linkId)
119
+ const answer = EnsureMaybe<QuestionnaireResponseItemAnswer>(item?.answer?.find((answer) => !!answer))
120
+
121
+ dataEntity[linkId] = createCellPropsForAnswer(
122
+ answer,
123
+ false,
124
+ record.status === QuestionnaireResponseStatus.EnteredInError
125
+ )
126
+
127
+ if (answer.item) {
128
+ dataEntity = recursivelyMapResponseItemsOntoData(
129
+ EnsureMaybeArray<QuestionnaireResponseItem>(answer.item),
130
+ dataEntity,
131
+ record.status
132
+ )
133
+ }
134
+ })
135
+
136
+ return dataEntity
137
+ })
138
+
139
+ const recursivelyMapResponseItemsOntoData = (
140
+ items: QuestionnaireResponseItem[],
141
+ dataEntity: DataEntity,
142
+ status: QuestionnaireResponseStatus
143
+ ): DataEntity => {
144
+ let updatedDataEntity = { ...dataEntity }
145
+ items.forEach((item) => {
146
+ const firstAnswer = item.answer ? item.answer[0] : undefined
147
+
148
+ if (item.linkId && firstAnswer) {
149
+ const props = createCellPropsForAnswer(firstAnswer, false, status === QuestionnaireResponseStatus.EnteredInError)
150
+ updatedDataEntity[item.linkId] = {
151
+ customComponentOverride: props.customComponentOverride,
152
+ text: props.text,
153
+ }
154
+
155
+ if (firstAnswer.item) {
156
+ updatedDataEntity = recursivelyMapResponseItemsOntoData(
157
+ EnsureMaybeArray<QuestionnaireResponseItem>(firstAnswer.item),
158
+ updatedDataEntity,
159
+ status
160
+ )
161
+ }
162
+ }
163
+ })
164
+ return updatedDataEntity
165
+ }
166
+
167
+ const mapQuestionnaireObjectsToVerticalTableData = (
168
+ definitionItems: Array<QuestionnaireItem>,
169
+ records: QuestionnaireResponse[],
170
+ adminActions?: AdminActionsForQuestionnaire[]
171
+ ): TableData => ({
172
+ headers: [
173
+ {
174
+ id: 'property',
175
+ type: 'accessor',
176
+ cellProps: { text: '' },
177
+ },
178
+ ...records.map(
179
+ (record): Header => ({
180
+ id: record?.id ?? '',
181
+ type: 'accessor',
182
+ cellProps: {
183
+ customComponentOverride:
184
+ record.status === QuestionnaireResponseStatus.EnteredInError
185
+ ? withdrawnWrapper(partialDateTimeText(record.authored) ?? '')
186
+ : undefined,
187
+ text: partialDateTimeText(record.authored) ?? '',
188
+ },
189
+ })
190
+ ),
191
+ ],
192
+ rows: buildVerticalCellRows(definitionItems, records, adminActions),
193
+ })
194
+
195
+ const buildVerticalCellRows = (
196
+ definitionItems: QuestionnaireItem[],
197
+ records: QuestionnaireResponse[],
198
+ adminActions?: AdminActionsForQuestionnaire[]
199
+ ): DataEntity[] => {
200
+ const dataEntities = definitionItems.map((item) => {
201
+ let dataEntity: DataEntity = {}
202
+
203
+ dataEntity = buildVerticalCellRowsRecursive(EnsureMaybeArray<QuestionnaireItem>([item]), records, dataEntity)
204
+
205
+ return dataEntity
206
+ })
207
+
208
+ if (adminActions) {
209
+ const actionsDataEntity: DataEntity = {}
210
+ actionsDataEntity.property = { text: 'Actions', parentStyle: DEFAULT_VERTICAL_HEADER_CELL_STYLE }
211
+
212
+ records.forEach((record) => {
213
+ const adminActionsForThisDataEntity = adminActions.find(
214
+ (actionForForm) => actionForForm.questionnaire === record.id
215
+ )
216
+
217
+ if (adminActionsForThisDataEntity) {
218
+ actionsDataEntity[record.id] = {
219
+ id: record.id,
220
+ adminActions: adminActionsForThisDataEntity.adminActions,
221
+ parentStyle: { zIndex: getZIndex(TableDataWithPopUp) },
222
+ }
223
+ }
224
+ })
225
+
226
+ return [actionsDataEntity].concat(dataEntities)
227
+ }
228
+ return dataEntities
229
+ }
230
+
231
+ const buildVerticalCellRowsRecursive = (
232
+ definitionItems: QuestionnaireItem[],
233
+ records: QuestionnaireResponse[],
234
+ dataEntity: DataEntity
235
+ ): DataEntity => {
236
+ let updatedDataEntity = { ...dataEntity }
237
+ definitionItems.forEach((definitionItem) => {
238
+ const containsChildItems = !!definitionItem.item && definitionItem.item.length > 0
239
+
240
+ updatedDataEntity.property = {
241
+ text: definitionItem.text ?? '',
242
+ parentStyle: {
243
+ ...DEFAULT_VERTICAL_HEADER_CELL_STYLE,
244
+ fontWeight: containsChildItems ? 'bold' : 'normal',
245
+ },
246
+ }
247
+
248
+ if (definitionItem.linkId) {
249
+ records.forEach((record) => {
250
+ updatedDataEntity = getRecordItemByLinkId(
251
+ EnsureMaybeArray<QuestionnaireResponseItem>(record.item ?? []),
252
+ EnsureMaybe<string>(definitionItem.linkId),
253
+ updatedDataEntity,
254
+ record.id,
255
+ record.status
256
+ )
257
+ })
258
+ }
259
+
260
+ if (definitionItem.item && definitionItem.item.length > 0) {
261
+ updatedDataEntity.subRows = buildVerticalCellRows(
262
+ EnsureMaybeArray<QuestionnaireItem>(definitionItem.item),
263
+ records
264
+ )
265
+ }
266
+ })
267
+
268
+ return updatedDataEntity
269
+ }
270
+
271
+ const getRecordItemByLinkId = (
272
+ recordItems: QuestionnaireResponseItem[],
273
+ linkId: string,
274
+ dataEntity: DataEntity,
275
+ recordId: string,
276
+ status: QuestionnaireResponseStatus
277
+ ) => {
278
+ let updatedDataEntity = { ...dataEntity }
279
+ recordItems.forEach((recordItem) => {
280
+ const recordItemAnswer =
281
+ recordItem.answer && recordItem.answer.length > 0 ? EnsureMaybe(recordItem.answer[0]) : undefined
282
+
283
+ if (recordItemAnswer) {
284
+ if (recordItem?.linkId && recordItem?.linkId === linkId) {
285
+ updatedDataEntity[recordId] = createCellPropsForAnswer(
286
+ recordItemAnswer,
287
+ true,
288
+ status === QuestionnaireResponseStatus.EnteredInError
289
+ )
290
+ }
291
+ if (recordItemAnswer.item && recordItemAnswer.item.length > 0) {
292
+ updatedDataEntity = getRecordItemByLinkId(
293
+ EnsureMaybeArray<QuestionnaireResponseItem>(recordItemAnswer.item),
294
+ linkId,
295
+ updatedDataEntity,
296
+ recordId,
297
+ status
298
+ )
299
+ }
300
+ }
301
+ })
302
+
303
+ return updatedDataEntity
304
+ }
305
+
306
+ const createCellPropsForAnswer = (
307
+ answer: QuestionnaireResponseItemAnswer,
308
+ shouldRenderCheckbox: boolean,
309
+ isEnteredInError: boolean
310
+ ): CellProps => {
311
+ if (answer.valueString) {
312
+ if (shouldRenderCheckbox && answer.valueString === 'CHECKBOX') {
313
+ return {
314
+ iconProps: { type: 'checkbox', size: 'medium' },
315
+ }
316
+ }
317
+ return {
318
+ customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueString) : undefined,
319
+ text: answer.valueString,
320
+ }
321
+ }
322
+ if (answer.valueBoolean != null) {
323
+ const parsedBoolean = answer.valueBoolean ? 'Yes' : 'No'
324
+ return {
325
+ customComponentOverride: isEnteredInError ? withdrawnWrapper(parsedBoolean) : undefined,
326
+ text: parsedBoolean,
327
+ }
328
+ }
329
+ if (answer.valueInteger != null) {
330
+ return {
331
+ customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueInteger.toString()) : undefined,
332
+ text: answer.valueInteger.toString(),
333
+ }
334
+ }
335
+ if (answer.valueDecimal != null) {
336
+ return {
337
+ customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueDecimal.toString()) : undefined,
338
+ text: answer.valueDecimal.toString(),
339
+ }
340
+ }
341
+ return {
342
+ text: '',
343
+ }
344
+ }
345
+
346
+ export interface AdminActionsForQuestionnaire {
347
+ questionnaire: string
348
+ adminActions: ActionMenuOption[]
349
+ }
350
+
351
+ export default mapQuestionnaireDefinitionAndResponsesToTableData