oro-sdk 2.1.4-dev1.0 → 2.2.1
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/README.md +26 -34
- package/dist/client.d.ts +4 -4
- package/dist/helpers/client.d.ts +1 -1
- package/dist/helpers/patient-registration.d.ts +1 -1
- package/dist/helpers/vault-grants.d.ts +1 -1
- package/dist/helpers/workflow.d.ts +1 -1
- package/dist/index.d.ts +15 -1
- package/dist/models/client.d.ts +1 -1
- package/dist/models/error.d.ts +0 -14
- package/dist/models/index.d.ts +0 -7
- package/dist/oro-sdk.cjs.development.js +313 -2367
- package/dist/oro-sdk.cjs.development.js.map +1 -1
- package/dist/oro-sdk.cjs.production.min.js +1 -1
- package/dist/oro-sdk.cjs.production.min.js.map +1 -1
- package/dist/oro-sdk.esm.js +246 -2344
- package/dist/oro-sdk.esm.js.map +1 -1
- package/dist/sdk-revision/client.d.ts +2 -2
- package/dist/services/index.d.ts +0 -9
- package/package.json +4 -1
- package/src/client.ts +161 -435
- package/src/helpers/client.ts +1 -1
- package/src/helpers/patient-registration.ts +85 -166
- package/src/helpers/vault-grants.ts +1 -1
- package/src/helpers/workflow.ts +21 -59
- package/src/index.ts +42 -28
- package/src/models/client.ts +1 -1
- package/src/models/error.ts +6 -13
- package/src/models/index.ts +0 -7
- package/src/sdk-revision/client.ts +25 -20
- package/src/services/external/clinia.ts +1 -1
- package/src/services/index.ts +0 -9
- package/dist/models/consult.d.ts +0 -102
- package/dist/models/diagnosis.d.ts +0 -122
- package/dist/models/guard.d.ts +0 -119
- package/dist/models/practice.d.ts +0 -353
- package/dist/models/shared.d.ts +0 -8
- package/dist/models/vault.d.ts +0 -124
- package/dist/models/workflow.d.ts +0 -106
- package/dist/services/api.d.ts +0 -11
- package/dist/services/axios.d.ts +0 -14
- package/dist/services/consult.d.ts +0 -54
- package/dist/services/diagnosis.d.ts +0 -44
- package/dist/services/guard.d.ts +0 -92
- package/dist/services/practice.d.ts +0 -100
- package/dist/services/teller.d.ts +0 -9
- package/dist/services/vault.d.ts +0 -54
- package/dist/services/workflow.d.ts +0 -21
- package/src/models/consult.ts +0 -110
- package/src/models/diagnosis.ts +0 -141
- package/src/models/guard.ts +0 -136
- package/src/models/practice.ts +0 -411
- package/src/models/shared.ts +0 -6
- package/src/models/vault.ts +0 -158
- package/src/models/workflow.ts +0 -142
- package/src/services/api.ts +0 -77
- package/src/services/axios.ts +0 -91
- package/src/services/consult.ts +0 -265
- package/src/services/diagnosis.ts +0 -144
- package/src/services/guard.ts +0 -228
- package/src/services/practice.ts +0 -537
- package/src/services/teller.ts +0 -39
- package/src/services/vault.ts +0 -178
- package/src/services/workflow.ts +0 -36
package/src/helpers/client.ts
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
import {
|
2
2
|
Consult,
|
3
3
|
ConsultationImageMeta,
|
4
|
-
getImagesFromIndexDb,
|
5
|
-
getWorkflowDataByCategory,
|
6
|
-
filterTriggeredAnsweredWithKind,
|
7
|
-
MedicalStatus,
|
8
|
-
OroClient,
|
9
|
-
PersonalMeta,
|
10
|
-
Practitioner,
|
11
|
-
RegisterPatientOutput,
|
12
|
-
} from '..'
|
13
|
-
import {
|
14
4
|
ConsultationMeta,
|
15
5
|
ConsultRequest,
|
16
6
|
DocumentType,
|
17
7
|
IndexKey,
|
18
8
|
MedicalMeta,
|
9
|
+
MedicalStatus,
|
19
10
|
MetadataCategory,
|
11
|
+
PersonalMeta,
|
12
|
+
Practitioner,
|
20
13
|
PreferenceMeta,
|
21
14
|
RawConsultationMeta,
|
22
15
|
Uuid,
|
23
16
|
VaultIndex,
|
24
17
|
WorkflowData,
|
25
|
-
} from '
|
18
|
+
} from 'oro-sdk-apis'
|
19
|
+
import {
|
20
|
+
filterTriggeredAnsweredWithKind,
|
21
|
+
getImagesFromIndexDb,
|
22
|
+
getWorkflowDataByCategory,
|
23
|
+
OroClient,
|
24
|
+
RegisterPatientOutput,
|
25
|
+
} from '..'
|
26
26
|
|
27
27
|
const MAX_RETRIES = 15
|
28
28
|
|
@@ -50,11 +50,8 @@ export async function registerPatient(
|
|
50
50
|
|
51
51
|
// Retrieving practitioners
|
52
52
|
if (!practitionerAdmin)
|
53
|
-
practitionerAdmin = (
|
54
|
-
|
55
|
-
consultRequest.uuidPractice
|
56
|
-
)
|
57
|
-
).uuidAdmin
|
53
|
+
practitionerAdmin = (await oroClient.practiceClient.practiceGetFromUuid(consultRequest.uuidPractice))
|
54
|
+
.uuidAdmin
|
58
55
|
|
59
56
|
let practitioners: Practitioner[] = await oroClient.practiceClient
|
60
57
|
.practiceGetPractitioners(consultRequest.uuidPractice)
|
@@ -65,61 +62,35 @@ export async function registerPatient(
|
|
65
62
|
|
66
63
|
// Creating consult
|
67
64
|
if (!consult) {
|
68
|
-
consult = await getOrCreatePatientConsultationUuid(
|
69
|
-
consultRequest,
|
70
|
-
oroClient
|
71
|
-
)
|
65
|
+
consult = await getOrCreatePatientConsultationUuid(consultRequest, oroClient)
|
72
66
|
}
|
73
67
|
|
74
68
|
// Creating lockbox
|
75
|
-
if (!lockboxUuid)
|
76
|
-
lockboxUuid = await getOrCreatePatientLockbox(oroClient)
|
69
|
+
if (!lockboxUuid) lockboxUuid = await getOrCreatePatientLockbox(oroClient)
|
77
70
|
|
78
|
-
isExistingPatient = await patientConsultExists(
|
79
|
-
consult,
|
80
|
-
lockboxUuid,
|
81
|
-
oroClient
|
82
|
-
).catch((err) => {
|
71
|
+
isExistingPatient = await patientConsultExists(consult, lockboxUuid, oroClient).catch((err) => {
|
83
72
|
console.error(`Error when retrieving existing consults ${err}`)
|
84
73
|
return false
|
85
74
|
})
|
86
|
-
await oroClient
|
87
|
-
.
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
err
|
92
|
-
)
|
93
|
-
// if we cannot grant to the admin, then the registration will fail
|
94
|
-
throw err
|
95
|
-
})
|
75
|
+
await oroClient.grantLockbox(practitionerAdmin, lockboxUuid).catch((err) => {
|
76
|
+
console.error(`Error while granting lockbox to practitioner admin ${practitionerAdmin}`, err)
|
77
|
+
// if we cannot grant to the admin, then the registration will fail
|
78
|
+
throw err
|
79
|
+
})
|
96
80
|
|
97
81
|
// Patient Grant to practice
|
98
82
|
let grantPromises = practitioners
|
99
|
-
.filter(
|
100
|
-
(practitioner) => practitioner.uuid !== practitionerAdmin
|
101
|
-
)
|
83
|
+
.filter((practitioner) => practitioner.uuid !== practitionerAdmin)
|
102
84
|
.map(async (practitioner) => {
|
103
|
-
return oroClient
|
104
|
-
.
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
)
|
110
|
-
// Acceptable to continue as admin has already been granted, but we should still try to retry
|
111
|
-
if (retry <= 1) return
|
112
|
-
else throw err
|
113
|
-
})
|
85
|
+
return oroClient.grantLockbox(practitioner.uuid, lockboxUuid!).catch((err) => {
|
86
|
+
console.error(`Error while granting lockbox to practitioner`, err)
|
87
|
+
// Acceptable to continue as admin has already been granted, but we should still try to retry
|
88
|
+
if (retry <= 1) return
|
89
|
+
else throw err
|
90
|
+
})
|
114
91
|
})
|
115
92
|
|
116
|
-
await storePatientData(
|
117
|
-
consult.uuid,
|
118
|
-
consultRequest.isoLanguageRequired,
|
119
|
-
lockboxUuid,
|
120
|
-
workflow,
|
121
|
-
oroClient
|
122
|
-
)
|
93
|
+
await storePatientData(consult.uuid, consultRequest.isoLanguageRequired, lockboxUuid, workflow, oroClient)
|
123
94
|
|
124
95
|
// the index will identify in which lockbox a consultation live
|
125
96
|
let consultIndex: VaultIndex = {
|
@@ -135,19 +106,13 @@ export async function registerPatient(
|
|
135
106
|
}
|
136
107
|
|
137
108
|
let consultIndexPromises = practitioners.map(async (practitioner) => {
|
138
|
-
return oroClient
|
139
|
-
.
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
err
|
144
|
-
)
|
145
|
-
/// it's acceptable to continue registration
|
146
|
-
return
|
147
|
-
})
|
109
|
+
return oroClient.vaultIndexAdd(consultIndex, practitioner.uuid).catch((err) => {
|
110
|
+
console.error(`Error while adding to the practitioner's index ${practitioner.uuid}`, err)
|
111
|
+
/// it's acceptable to continue registration
|
112
|
+
return
|
113
|
+
})
|
148
114
|
})
|
149
115
|
|
150
|
-
|
151
116
|
//DEPRECATED: REMOVE ME : BEGIN /////////////////////////////////////////
|
152
117
|
|
153
118
|
let deprecatedConsultIndex: VaultIndex = {
|
@@ -163,30 +128,22 @@ export async function registerPatient(
|
|
163
128
|
}
|
164
129
|
|
165
130
|
let deprecatedConsultIndexPromises = practitioners.map(async (practitioner) => {
|
166
|
-
return oroClient
|
167
|
-
.
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
err
|
172
|
-
)
|
173
|
-
/// it's acceptable to continue registration
|
174
|
-
return
|
175
|
-
})
|
131
|
+
return oroClient.vaultIndexAdd(deprecatedConsultIndex, practitioner.uuid).catch((err) => {
|
132
|
+
console.error(`Error while adding to the practitioner's index ${practitioner.uuid}`, err)
|
133
|
+
/// it's acceptable to continue registration
|
134
|
+
return
|
135
|
+
})
|
176
136
|
})
|
177
137
|
|
178
138
|
//DEPRECATED: REMOVE ME : END /////////////////////////////////////////
|
179
139
|
|
180
|
-
|
181
140
|
if (masterKey && !isExistingPatient) {
|
182
141
|
// generate and store recovery payload
|
183
|
-
await oroClient
|
184
|
-
.
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
return
|
189
|
-
})
|
142
|
+
await oroClient.updateMasterKey(patientUuid, masterKey, lockboxUuid).catch((err) => {
|
143
|
+
console.error(`Error while updating master key`, err)
|
144
|
+
/// it's acceptable to continue registration
|
145
|
+
return
|
146
|
+
})
|
190
147
|
} else {
|
191
148
|
// we did not set the master key so we do not return it
|
192
149
|
masterKey = undefined
|
@@ -202,10 +159,7 @@ export async function registerPatient(
|
|
202
159
|
2
|
203
160
|
)
|
204
161
|
.catch((err) => {
|
205
|
-
console.error(
|
206
|
-
`Error while updating security questions`,
|
207
|
-
err
|
208
|
-
)
|
162
|
+
console.error(`Error while updating security questions`, err)
|
209
163
|
/// it's acceptable to continue registration
|
210
164
|
return
|
211
165
|
})
|
@@ -220,9 +174,7 @@ export async function registerPatient(
|
|
220
174
|
// if we got through the complete flow, the registration succeeded
|
221
175
|
break
|
222
176
|
} catch (err) {
|
223
|
-
console.error(
|
224
|
-
`Error occured during registration, retrying... Retries remaining: ${retry}`
|
225
|
-
)
|
177
|
+
console.error(`Error occured during registration, retrying... Retries remaining: ${retry}`)
|
226
178
|
continue
|
227
179
|
}
|
228
180
|
}
|
@@ -255,17 +207,10 @@ async function patientConsultExists(
|
|
255
207
|
category: MetadataCategory.Consultation,
|
256
208
|
documentType: DocumentType.PopulatedWorkflowData,
|
257
209
|
}
|
258
|
-
let manifest = await oroClient.vaultClient.lockboxMetadataGet(
|
259
|
-
lockboxUuid,
|
260
|
-
['consultationId'],
|
261
|
-
[],
|
262
|
-
publicMetadata
|
263
|
-
)
|
210
|
+
let manifest = await oroClient.vaultClient.lockboxMetadataGet(lockboxUuid, ['consultationId'], [], publicMetadata)
|
264
211
|
return (
|
265
212
|
manifest[0].findIndex(
|
266
|
-
(v: { consultationId: Uuid }) =>
|
267
|
-
v.consultationId != null &&
|
268
|
-
v.consultationId !== currentConsultation.uuid
|
213
|
+
(v: { consultationId: Uuid }) => v.consultationId != null && v.consultationId !== currentConsultation.uuid
|
269
214
|
) !== -1
|
270
215
|
)
|
271
216
|
}
|
@@ -276,28 +221,21 @@ async function patientConsultExists(
|
|
276
221
|
* @param oroClient
|
277
222
|
* @returns the consult Uuid
|
278
223
|
*/
|
279
|
-
async function getOrCreatePatientConsultationUuid(
|
280
|
-
consult: ConsultRequest,
|
281
|
-
oroClient: OroClient
|
282
|
-
): Promise<Consult> {
|
224
|
+
async function getOrCreatePatientConsultationUuid(consult: ConsultRequest, oroClient: OroClient): Promise<Consult> {
|
283
225
|
let payment = await oroClient.practiceClient.practiceGetPayment(
|
284
226
|
consult.uuidPractice,
|
285
227
|
consult.idStripeInvoiceOrPaymentIntent
|
286
228
|
)
|
287
229
|
if (payment && payment.uuidConsult) {
|
288
|
-
return oroClient.consultClient
|
289
|
-
.
|
290
|
-
|
291
|
-
|
292
|
-
throw err
|
293
|
-
})
|
230
|
+
return oroClient.consultClient.getConsultByUUID(payment.uuidConsult).catch((err) => {
|
231
|
+
console.error('Error while retrieving consult', err)
|
232
|
+
throw err
|
233
|
+
})
|
294
234
|
} else {
|
295
|
-
return await oroClient.consultClient
|
296
|
-
.
|
297
|
-
|
298
|
-
|
299
|
-
throw err
|
300
|
-
})
|
235
|
+
return await oroClient.consultClient.consultCreate(consult).catch((err) => {
|
236
|
+
console.error('Error while creating consult', err)
|
237
|
+
throw err
|
238
|
+
})
|
301
239
|
}
|
302
240
|
}
|
303
241
|
|
@@ -309,9 +247,7 @@ async function getOrCreatePatientConsultationUuid(
|
|
309
247
|
async function getOrCreatePatientLockbox(oroClient: OroClient): Promise<Uuid> {
|
310
248
|
let grants = await oroClient.getGrants(undefined, true)
|
311
249
|
if (grants.length > 0) {
|
312
|
-
console.log(
|
313
|
-
'The grant has already been created, skipping lockbox create step'
|
314
|
-
)
|
250
|
+
console.log('The grant has already been created, skipping lockbox create step')
|
315
251
|
return grants[0].lockboxUuid!
|
316
252
|
} else
|
317
253
|
return (
|
@@ -340,12 +276,7 @@ async function storePatientData(
|
|
340
276
|
): Promise<(Uuid | void)[]> {
|
341
277
|
// Create and store registration data
|
342
278
|
return Promise.all([
|
343
|
-
storeImageAliases(
|
344
|
-
consultationId,
|
345
|
-
lockboxUuid,
|
346
|
-
workflow,
|
347
|
-
oroClient
|
348
|
-
).catch((err) => {
|
279
|
+
storeImageAliases(consultationId, lockboxUuid, workflow, oroClient).catch((err) => {
|
349
280
|
console.error('[SDK] Some errors happened during image upload', err)
|
350
281
|
}),
|
351
282
|
// Storing Raw data first
|
@@ -359,31 +290,29 @@ async function storePatientData(
|
|
359
290
|
},
|
360
291
|
{}
|
361
292
|
),
|
362
|
-
getWorkflowDataByCategory(workflow, MetadataCategory.Consultation).then(
|
363
|
-
(
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
)
|
293
|
+
getWorkflowDataByCategory(workflow, MetadataCategory.Consultation).then((data) =>
|
294
|
+
oroClient.getOrInsertJsonData<ConsultationMeta>(
|
295
|
+
lockboxUuid,
|
296
|
+
data,
|
297
|
+
{
|
298
|
+
category: MetadataCategory.Consultation,
|
299
|
+
documentType: DocumentType.PopulatedWorkflowData,
|
300
|
+
consultationId, // TODO: deprecated. Will finally only be in privateMetadata
|
301
|
+
},
|
302
|
+
{ consultationId }
|
303
|
+
)
|
374
304
|
),
|
375
|
-
getWorkflowDataByCategory(workflow, MetadataCategory.Medical).then(
|
376
|
-
(
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
)
|
305
|
+
getWorkflowDataByCategory(workflow, MetadataCategory.Medical).then((data) =>
|
306
|
+
oroClient.getOrInsertJsonData<MedicalMeta>(
|
307
|
+
lockboxUuid,
|
308
|
+
data,
|
309
|
+
{
|
310
|
+
category: MetadataCategory.Medical,
|
311
|
+
documentType: DocumentType.PopulatedWorkflowData,
|
312
|
+
consultationIds: [consultationId!],
|
313
|
+
},
|
314
|
+
{}
|
315
|
+
)
|
387
316
|
),
|
388
317
|
extractAndStorePersonalWorkflowData(
|
389
318
|
workflow,
|
@@ -424,16 +353,12 @@ async function storeImageAliases(
|
|
424
353
|
workflow: WorkflowData,
|
425
354
|
oroClient: OroClient
|
426
355
|
): Promise<(Uuid | void)[]> {
|
427
|
-
const images = await getImagesFromIndexDb(
|
428
|
-
(await filterTriggeredAnsweredWithKind(workflow, 'images-alias')).flat()
|
429
|
-
)
|
356
|
+
const images = await getImagesFromIndexDb((await filterTriggeredAnsweredWithKind(workflow, 'images-alias')).flat())
|
430
357
|
|
431
358
|
const nonNullImages = images.filter((img) => !!img)
|
432
359
|
|
433
360
|
if (images.length !== nonNullImages.length) {
|
434
|
-
console.error(
|
435
|
-
'[SDK] Some images have not been found, they have been skipped.'
|
436
|
-
)
|
361
|
+
console.error('[SDK] Some images have not been found, they have been skipped.')
|
437
362
|
}
|
438
363
|
|
439
364
|
let promises = nonNullImages.map((image) => {
|
@@ -465,16 +390,10 @@ export async function extractAndStorePersonalWorkflowData(
|
|
465
390
|
workflow: WorkflowData,
|
466
391
|
lockboxUuid: Uuid,
|
467
392
|
consultationId: Uuid,
|
468
|
-
category:
|
469
|
-
| MetadataCategory.Personal
|
470
|
-
| MetadataCategory.ChildPersonal
|
471
|
-
| MetadataCategory.OtherPersonal,
|
393
|
+
category: MetadataCategory.Personal | MetadataCategory.ChildPersonal | MetadataCategory.OtherPersonal,
|
472
394
|
oroClient: OroClient
|
473
395
|
): Promise<Uuid | void> {
|
474
|
-
return getWorkflowDataByCategory(
|
475
|
-
workflow,
|
476
|
-
(category as unknown) as MetadataCategory
|
477
|
-
).then((data) => {
|
396
|
+
return getWorkflowDataByCategory(workflow, category as unknown as MetadataCategory).then((data) => {
|
478
397
|
if (Object.keys(data.fields).length === 0) return
|
479
398
|
return oroClient.getOrInsertJsonData<PersonalMeta>(
|
480
399
|
lockboxUuid,
|
package/src/helpers/workflow.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { getMany } from 'idb-keyval'
|
2
|
+
import { WorkflowAnswersMissingError } from '../models'
|
2
3
|
import {
|
3
4
|
MetadataCategory,
|
4
5
|
PopulatedWorkflowData,
|
@@ -6,22 +7,14 @@ import {
|
|
6
7
|
QuestionData,
|
7
8
|
SelectedAnswerData,
|
8
9
|
SelectedAnswersData,
|
9
|
-
WorkflowAnswersMissingError,
|
10
10
|
WorkflowData,
|
11
11
|
WorkflowPageData,
|
12
12
|
WorkflowUploadedImage,
|
13
|
-
} from '
|
13
|
+
} from 'oro-sdk-apis'
|
14
14
|
|
15
15
|
export async function filterTriggeredAnsweredWithKind(
|
16
16
|
workflowData: WorkflowData,
|
17
|
-
kind:
|
18
|
-
| 'text'
|
19
|
-
| 'date'
|
20
|
-
| 'number'
|
21
|
-
| 'images'
|
22
|
-
| 'images-alias'
|
23
|
-
| 'body-parts'
|
24
|
-
| 'pharmacy-picker'
|
17
|
+
kind: 'text' | 'date' | 'number' | 'images' | 'images-alias' | 'body-parts' | 'pharmacy-picker'
|
25
18
|
): Promise<SelectedAnswerData[]> {
|
26
19
|
if (!workflowData.selectedAnswers) throw WorkflowAnswersMissingError
|
27
20
|
|
@@ -32,11 +25,7 @@ export async function filterTriggeredAnsweredWithKind(
|
|
32
25
|
workflowData.pages
|
33
26
|
.map((a) => {
|
34
27
|
return Object.entries(a.questions).filter(
|
35
|
-
([_, question]) =>
|
36
|
-
isTriggered(
|
37
|
-
question.triggers || [],
|
38
|
-
flattenedAnswers
|
39
|
-
) && question.kind === kind
|
28
|
+
([_, question]) => isTriggered(question.triggers || [], flattenedAnswers) && question.kind === kind
|
40
29
|
)
|
41
30
|
})
|
42
31
|
.flat()
|
@@ -46,11 +35,9 @@ export async function filterTriggeredAnsweredWithKind(
|
|
46
35
|
return { ...prev, ...cur }
|
47
36
|
}, {})
|
48
37
|
|
49
|
-
const res = Object.keys(triggeredQuestionsWithKind).map(
|
50
|
-
|
51
|
-
|
52
|
-
}
|
53
|
-
)
|
38
|
+
const res = Object.keys(triggeredQuestionsWithKind).map((questionFieldName) => {
|
39
|
+
return samePageAnswers[questionFieldName]
|
40
|
+
})
|
54
41
|
|
55
42
|
return res
|
56
43
|
}
|
@@ -90,17 +77,11 @@ export async function getWorkflowDataByCategory(
|
|
90
77
|
workflowData.selectedAnswers
|
91
78
|
.map((e) => Object.entries(e))
|
92
79
|
.flat()
|
93
|
-
.filter(
|
94
|
-
([k, v]) =>
|
95
|
-
triggeredQuestions[k] &&
|
96
|
-
triggeredQuestions[k]['metaCategory'] === category
|
97
|
-
)
|
80
|
+
.filter(([k, v]) => triggeredQuestions[k] && triggeredQuestions[k]['metaCategory'] === category)
|
98
81
|
.map(([k, v]) => {
|
99
|
-
return populateWorkflowField(triggeredQuestions[k], v).then(
|
100
|
-
|
101
|
-
|
102
|
-
}
|
103
|
-
)
|
82
|
+
return populateWorkflowField(triggeredQuestions[k], v).then((populatedValue) => {
|
83
|
+
fields[k] = populatedValue
|
84
|
+
})
|
104
85
|
})
|
105
86
|
)
|
106
87
|
.then(() => {
|
@@ -113,20 +94,13 @@ export async function getWorkflowDataByCategory(
|
|
113
94
|
return ret
|
114
95
|
})
|
115
96
|
.catch((err) => {
|
116
|
-
console.error(
|
117
|
-
`Error while extracting ${category} data from workflow`,
|
118
|
-
err
|
119
|
-
)
|
97
|
+
console.error(`Error while extracting ${category} data from workflow`, err)
|
120
98
|
throw err
|
121
99
|
})
|
122
100
|
}
|
123
101
|
|
124
|
-
export async function getImagesFromIndexDb(
|
125
|
-
answer
|
126
|
-
): Promise<WorkflowUploadedImage[]> {
|
127
|
-
return await getMany<WorkflowUploadedImage>(
|
128
|
-
(answer as any[]).map((v) => v.id ?? v) as string[]
|
129
|
-
)
|
102
|
+
export async function getImagesFromIndexDb(answer: SelectedAnswerData): Promise<WorkflowUploadedImage[]> {
|
103
|
+
return await getMany<WorkflowUploadedImage>((answer as any[]).map((v) => v.id ?? v) as string[])
|
130
104
|
}
|
131
105
|
|
132
106
|
/**
|
@@ -212,37 +186,25 @@ export function flattenSelectedAnswers(answers: SelectedAnswersData) {
|
|
212
186
|
* @param useDefault use workflow default values or not (this is used to avoid having unset values to appear in summaries)
|
213
187
|
* @returns a valid selectedAnswers structure
|
214
188
|
*/
|
215
|
-
export function getInitialisedSelectedAnswers(
|
216
|
-
workflow: WorkflowData,
|
217
|
-
useDefault: boolean = true
|
218
|
-
) {
|
189
|
+
export function getInitialisedSelectedAnswers(workflow: WorkflowData, useDefault: boolean = true) {
|
219
190
|
return workflow.pages.map((page) => {
|
220
191
|
const ret: any = {}
|
221
192
|
for (const [id, question] of Object.entries(page.questions)) {
|
222
193
|
if (question.kind === 'body-parts') {
|
223
194
|
ret[id] = useDefault ? [] : undefined
|
224
195
|
} else {
|
225
|
-
ret[id] =
|
226
|
-
useDefault && question.defaultValue
|
227
|
-
? question.defaultValue
|
228
|
-
: undefined
|
196
|
+
ret[id] = useDefault && question.defaultValue ? question.defaultValue : undefined
|
229
197
|
}
|
230
198
|
}
|
231
199
|
return ret
|
232
200
|
})
|
233
201
|
}
|
234
202
|
|
235
|
-
export function fillWorkflowFromPopulatedWorkflow(
|
236
|
-
workflow: WorkflowData,
|
237
|
-
populatedWorkflow: PopulatedWorkflowData
|
238
|
-
) {
|
203
|
+
export function fillWorkflowFromPopulatedWorkflow(workflow: WorkflowData, populatedWorkflow: PopulatedWorkflowData) {
|
239
204
|
const filledWorkflow = JSON.parse(JSON.stringify(workflow))
|
240
205
|
|
241
206
|
if (!filledWorkflow.selectedAnswers) {
|
242
|
-
filledWorkflow.selectedAnswers = getInitialisedSelectedAnswers(
|
243
|
-
filledWorkflow,
|
244
|
-
false
|
245
|
-
)
|
207
|
+
filledWorkflow.selectedAnswers = getInitialisedSelectedAnswers(filledWorkflow, false)
|
246
208
|
}
|
247
209
|
|
248
210
|
filledWorkflow.pages.forEach((page: WorkflowPageData, pageIdx: number) => {
|
@@ -250,9 +212,9 @@ export function fillWorkflowFromPopulatedWorkflow(
|
|
250
212
|
for (const [id] of Object.entries(page.questions)) {
|
251
213
|
if (populatedWorkflow.fields[id]) {
|
252
214
|
if (filledWorkflow.selectedAnswers)
|
253
|
-
filledWorkflow.selectedAnswers[pageIdx][
|
254
|
-
|
255
|
-
|
215
|
+
filledWorkflow.selectedAnswers[pageIdx][id] = populatedWorkflow.fields[id].answer as
|
216
|
+
| string
|
217
|
+
| string[]
|
256
218
|
}
|
257
219
|
}
|
258
220
|
})
|
package/src/index.ts
CHANGED
@@ -1,13 +1,4 @@
|
|
1
|
-
import
|
2
|
-
APIService,
|
3
|
-
TellerService,
|
4
|
-
VaultService,
|
5
|
-
GuardService,
|
6
|
-
PracticeService,
|
7
|
-
ConsultService,
|
8
|
-
WorkflowService,
|
9
|
-
DiagnosisService,
|
10
|
-
} from './services'
|
1
|
+
import initApis from 'oro-sdk-apis'
|
11
2
|
import { OroClient } from './client'
|
12
3
|
import * as OroToolboxNamespace from 'oro-toolbox'
|
13
4
|
|
@@ -15,6 +6,19 @@ export type OroToolbox = typeof OroToolboxNamespace
|
|
15
6
|
|
16
7
|
export let wasmPath = 'node_modules/oro-toolbox'
|
17
8
|
|
9
|
+
/**
|
10
|
+
* This function helps you to initialize and OroClient instance
|
11
|
+
* @param toolbox the OroToolbox object
|
12
|
+
* @param tellerBaseURL the teller service base URL
|
13
|
+
* @param vaultBaseURL the vault service base URL
|
14
|
+
* @param guardBaseURL the guard service base URL
|
15
|
+
* @param practiceBaseURL the practice service base URL
|
16
|
+
* @param consultBaseURL the consult service base URL
|
17
|
+
* @param workflowBaseURL the workflow service base URL
|
18
|
+
* @param diagnosisBaseURL the diagnosis service base URL
|
19
|
+
* @param authenticationCallback (optional) authenticationCallback the authentification callback
|
20
|
+
* @returns an instance of OroClient
|
21
|
+
*/
|
18
22
|
const init = (
|
19
23
|
toolbox: OroToolbox,
|
20
24
|
tellerBaseURL: string,
|
@@ -23,30 +27,39 @@ const init = (
|
|
23
27
|
practiceBaseURL: string,
|
24
28
|
consultBaseURL: string,
|
25
29
|
workflowBaseURL: string,
|
26
|
-
|
27
|
-
authenticationCallback?: (err: Error) => void
|
30
|
+
diagnosisBaseURL: string,
|
31
|
+
authenticationCallback?: (err: Error) => void
|
28
32
|
) => {
|
29
|
-
const
|
30
|
-
const tellerService = new TellerService(apiService, tellerBaseURL)
|
31
|
-
const practiceService = new PracticeService(
|
32
|
-
toolbox,
|
33
|
-
apiService,
|
34
|
-
practiceBaseURL
|
35
|
-
)
|
36
|
-
const consultService = new ConsultService(apiService, consultBaseURL)
|
37
|
-
const vaultService = new VaultService(apiService, vaultBaseURL)
|
38
|
-
const guardService = new GuardService(apiService, guardBaseURL)
|
39
|
-
const workflowService = new WorkflowService(apiService, workflowBaseURL)
|
40
|
-
const diagnosisService = new DiagnosisService(apiService, diagnosisBaseUrl)
|
41
|
-
const client = new OroClient(
|
42
|
-
toolbox,
|
33
|
+
const {
|
43
34
|
tellerService,
|
44
|
-
vaultService,
|
45
|
-
guardService,
|
46
35
|
practiceService,
|
47
36
|
consultService,
|
37
|
+
vaultService,
|
38
|
+
guardService,
|
48
39
|
workflowService,
|
49
40
|
diagnosisService,
|
41
|
+
} = initApis(
|
42
|
+
{
|
43
|
+
tellerBaseURL,
|
44
|
+
vaultBaseURL,
|
45
|
+
guardBaseURL,
|
46
|
+
practiceBaseURL,
|
47
|
+
consultBaseURL,
|
48
|
+
workflowBaseURL,
|
49
|
+
diagnosisBaseURL,
|
50
|
+
},
|
51
|
+
authenticationCallback
|
52
|
+
)
|
53
|
+
|
54
|
+
const client = new OroClient(
|
55
|
+
toolbox,
|
56
|
+
tellerService!,
|
57
|
+
vaultService!,
|
58
|
+
guardService!,
|
59
|
+
practiceService!,
|
60
|
+
consultService!,
|
61
|
+
workflowService!,
|
62
|
+
diagnosisService!,
|
50
63
|
authenticationCallback
|
51
64
|
)
|
52
65
|
|
@@ -54,6 +67,7 @@ const init = (
|
|
54
67
|
}
|
55
68
|
|
56
69
|
export { OroClient } from './client'
|
70
|
+
export * from 'oro-sdk-apis'
|
57
71
|
export * from './models'
|
58
72
|
export * from './helpers'
|
59
73
|
export * from './services'
|
package/src/models/client.ts
CHANGED