oro-sdk 5.4.0 → 5.5.1

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.4.0",
2
+ "version": "5.5.1",
3
3
  "main": "dist/index.js",
4
4
  "typings": "dist/index.d.ts",
5
5
  "files": [
@@ -55,7 +55,7 @@
55
55
  "form-data": "^4.0.0",
56
56
  "formdata-node": "^4.3.1",
57
57
  "idb-keyval": "^5.0.6",
58
- "oro-sdk-apis": "3.3.0",
58
+ "oro-sdk-apis": "3.3.1",
59
59
  "oro-toolbox": "0.0.6",
60
60
  "uuid": "^8.3.2"
61
61
  }
package/src/client.ts CHANGED
@@ -328,9 +328,14 @@ export class OroClient {
328
328
  * @param populatedRefillWorkflow
329
329
  * @returns
330
330
  */
331
- public async createRefill(consult: ConsultRequest, populatedRefillWorkflow: WorkflowData): Promise<void> {
331
+ public async createRefill(
332
+ consult: ConsultRequest,
333
+ populatedRefillWorkflow: WorkflowData,
334
+ indexSearch: boolean = true,
335
+ onProgress?: (progress: number, descriptionKey: string) => void
336
+ ): Promise<Consult> {
332
337
  if (!this.rsa) throw IncompleteAuthentication
333
- return createRefill(consult, populatedRefillWorkflow, this)
338
+ return createRefill(consult, populatedRefillWorkflow, this, indexSearch, onProgress)
334
339
  }
335
340
 
336
341
  /**
@@ -9,7 +9,7 @@ import {
9
9
  Uuid,
10
10
  WorkflowData,
11
11
  } from 'oro-sdk-apis'
12
- import { OroClient } from '..'
12
+ import { buildConsultSearchIndex, OroClient } from '..'
13
13
  import { getOrCreatePatientConsultationUuid } from './consult'
14
14
 
15
15
  const MAX_RETRIES = 15
@@ -17,7 +17,9 @@ const MAX_RETRIES = 15
17
17
  * Placeholder while the workflow interpreter for the refill flows is complete
18
18
  *
19
19
  * Creates a fake workflow in which the workflow data will reside
20
- *
20
+ *
21
+ * @todo deprecate this function when using workflows and populating them from the app
22
+ *
21
23
  * @param isTreatmentWorking the value from the `is treatment working` question
22
24
  * @param hasSideEffects the value from the `does the treatment have side effects` question
23
25
  * @param deliveryAddress the provided delivery address
@@ -28,19 +30,20 @@ export function getRefillAnswersAsWorkflow(
28
30
  isTreatmentWorking: string,
29
31
  hasSideEffects: string,
30
32
  deliveryAddress?: string,
31
- pharmacy?: PlaceData
33
+ pharmacy?: PlaceData,
32
34
  ): WorkflowData {
33
35
  let selectedAnswers: SelectedAnswersData = [
34
36
  {
35
37
  ['isTreatmentWorking']: isTreatmentWorking,
36
- },
37
- {
38
38
  ['hasSideEffects']: hasSideEffects,
39
39
  },
40
40
  ]
41
41
 
42
- if (deliveryAddress) selectedAnswers.push({ ['deliveryAddress']: deliveryAddress })
43
- if (pharmacy) selectedAnswers.push({ ['pharmacy']: JSON.stringify(pharmacy) })
42
+ // appends the delivery address to the first page of the answers if provided
43
+ if (deliveryAddress) selectedAnswers[0] = { ...selectedAnswers[0], ['deliveryAddress']: deliveryAddress }
44
+
45
+ // appends the pharmacy to the first page of the answers if provided
46
+ if (pharmacy) selectedAnswers[0] = { ...selectedAnswers[0], ['pharmacy']: JSON.stringify(pharmacy) }
44
47
 
45
48
  return {
46
49
  id: '32573a20-6f1d-49be-9ad3-b87c58074979',
@@ -108,7 +111,6 @@ export function getRefillAnswersAsWorkflow(
108
111
  kind: 'online-pharmacy-picker',
109
112
  label: 'Which pharmacy do you want the prescription sent to?',
110
113
  metaCategory: MetadataCategory.Refill,
111
- minorLabel: ' (Optional)',
112
114
  summaryLabel: 'Your pharmacy',
113
115
  },
114
116
  youAddress: {
@@ -133,20 +135,33 @@ export function getRefillAnswersAsWorkflow(
133
135
  export async function createRefill(
134
136
  consultRequest: ConsultRequest,
135
137
  populatedRefillWorkflow: WorkflowData,
136
- oroClient: OroClient
137
- ) {
138
+ oroClient: OroClient,
139
+ indexSearch: boolean = true,
140
+ onProgress?: (
141
+ progress: number,
142
+ descriptionKey: string,
143
+ extraInfo?: { storedImagesNum?: number; totalImagesNum?: number }
144
+ ) => void
145
+ ): Promise<Consult> {
138
146
  let retry = MAX_RETRIES
139
147
  let errorsThrown: Error[] = []
140
-
141
- let newConsult: Consult | undefined
148
+ let newConsult: Consult | undefined = undefined
142
149
  let lockboxUuid: Uuid | undefined
150
+ const stepsTotalNum = 6
151
+ let currentStep: number
143
152
 
144
153
  for (; retry > 0; retry--) {
145
154
  try {
146
- if (!newConsult) newConsult = await getOrCreatePatientConsultationUuid(consultRequest, oroClient)
155
+ currentStep = 0
156
+
157
+ if (onProgress) onProgress(currentStep++ / stepsTotalNum, 'create_consult')
158
+ // Creating refill consult
159
+ newConsult = await getOrCreatePatientConsultationUuid(consultRequest, oroClient)
147
160
 
161
+ if (onProgress) onProgress(currentStep++ / stepsTotalNum, 'get_patient_grant')
148
162
  if (!lockboxUuid) lockboxUuid = (await oroClient.getGrants())[0].lockboxUuid
149
163
 
164
+ if (onProgress) onProgress(currentStep++ / stepsTotalNum, 'store_patient_data')
150
165
  await oroClient
151
166
  .getOrInsertJsonData(
152
167
  lockboxUuid!,
@@ -160,18 +175,62 @@ export async function createRefill(
160
175
  { withNotification: true }
161
176
  )
162
177
  .catch((err) => {
163
- console.error('[SDK: prescription refill] Some errors happened during refill data upload', err)
178
+ console.error('[SDK: prescription refill request] Some errors happened during refill data upload', err)
164
179
  errorsThrown.push(err)
165
180
  })
166
181
 
182
+ if (indexSearch) {
183
+ if (onProgress) onProgress(currentStep++ / stepsTotalNum, 'fetching_parent_workflow_data')
184
+ // raw workflow from parent consultation (contains first and last name of patient)
185
+ let rawConsultationManifest = await oroClient.getLockboxManifest(lockboxUuid!, { category: MetadataCategory.Raw, consultationId: consultRequest.uuidParent }, false)
186
+ if (rawConsultationManifest && rawConsultationManifest.length > 0) {
187
+ let rawConsultation = await oroClient.getJsonData<WorkflowData>(lockboxUuid!, rawConsultationManifest[0].dataUuid)
188
+ if (onProgress) onProgress(currentStep++ / stepsTotalNum, 'search_indexing')
189
+ await buildConsultSearchIndex(newConsult, rawConsultation, oroClient).catch((err) => {
190
+ console.error(
191
+ '[SDK: prescription refill request] personal information not found or another error occured during search indexing',
192
+ err
193
+ )
194
+ if (retry <= 1) return // this statement is to avoid failing the registration due to the failure in search indexing the consult, this practically implements a soft retry
195
+ errorsThrown.push(err)
196
+ })
197
+ } else {
198
+ console.error(
199
+ '[SDK: prescription refill request] parent consultation\'s raw data not found',
200
+ )
201
+ errorsThrown.push(Error('RawData Not Found'))
202
+ }
203
+ }
204
+
167
205
  if (errorsThrown.length > 0) throw errorsThrown
206
+
207
+ // Deem the consultation as ready
168
208
  await oroClient.consultClient.updateConsultByUUID(newConsult.uuid, {
169
209
  statusMedical: MedicalStatus.New,
170
210
  })
211
+
212
+ // if we got through the complete flow, the registration succeeded
213
+ if (onProgress) onProgress(currentStep++ / stepsTotalNum, 'success')
214
+
215
+ await oroClient.cleanIndex()
216
+ break
217
+
171
218
  } catch (err) {
172
- console.error(`[SDK] Error occured during refill: ${err}, retrying... Retries remaining: ${retry}`)
219
+ console.error(`[SDK] Error occured during prescription refill request: ${err}, retrying... Retries remaining: ${retry}`)
173
220
  errorsThrown = []
174
221
  continue
175
222
  }
176
223
  }
224
+ if (retry <= 0) {
225
+ console.error('[SDK] prescription refill request failed: MAX_RETRIES reached')
226
+ throw 'RegistrationFailed'
227
+ }
228
+
229
+ if (!newConsult) {
230
+ console.error('[SDK] prescription refill request failed: MAX_RETRIES reached')
231
+ throw 'RegistrationFailed'
232
+ }
233
+
234
+ console.log('Successfully Created refill')
235
+ return newConsult
177
236
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 ORO Health Inc.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.