oro-sdk 5.3.1 → 5.3.4

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.3.1",
2
+ "version": "5.3.4",
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.2.1",
58
+ "oro-sdk-apis": "3.2.4",
59
59
  "oro-toolbox": "0.0.6",
60
60
  "uuid": "^8.3.2"
61
61
  }
package/src/client.ts CHANGED
@@ -46,7 +46,13 @@ import {
46
46
  } from 'oro-sdk-apis'
47
47
  import * as OroToolbox from 'oro-toolbox'
48
48
  import { CryptoRSA } from 'oro-toolbox'
49
- import { decryptConsultLockboxGrants, decryptGrants, registerPatient, sessionStorePrivateKeyName } from './helpers'
49
+ import {
50
+ createRefill,
51
+ decryptConsultLockboxGrants,
52
+ decryptGrants,
53
+ registerPatient,
54
+ sessionStorePrivateKeyName,
55
+ } from './helpers'
50
56
  import {
51
57
  AssociatedLockboxNotFound,
52
58
  IncompleteAuthentication,
@@ -312,6 +318,21 @@ export class OroClient {
312
318
  )
313
319
  }
314
320
 
321
+ /**
322
+ * Creates and stores all relevant refill data
323
+ * - New consultation is created
324
+ * - Stores refill workflow data in the lockbox
325
+ * - Updates the consult to new
326
+ *
327
+ * @param consult
328
+ * @param populatedRefillWorkflow
329
+ * @returns
330
+ */
331
+ public async createRefill(consult: ConsultRequest, populatedRefillWorkflow: WorkflowData): Promise<void> {
332
+ if (!this.rsa) throw IncompleteAuthentication
333
+ return createRefill(consult, populatedRefillWorkflow, this)
334
+ }
335
+
315
336
  /**
316
337
  * Fetches all grants, and consultations that exist in each lockbox
317
338
  * Then updates the index for the current user with the lockbox consult relationship
@@ -0,0 +1,29 @@
1
+ import { Consult, ConsultRequest } from 'oro-sdk-apis'
2
+ import { OroClient } from '..'
3
+
4
+ /**
5
+ * Creates a consultation if one has not been created and fails to be retrieved by the payment intent
6
+ * @param consult
7
+ * @param oroClient
8
+ * @returns the consult Uuid
9
+ */
10
+ export async function getOrCreatePatientConsultationUuid(
11
+ consult: ConsultRequest,
12
+ oroClient: OroClient
13
+ ): Promise<Consult> {
14
+ let payment = await oroClient.practiceClient.practiceGetPayment(
15
+ consult.uuidPractice,
16
+ consult.idStripeInvoiceOrPaymentIntent
17
+ )
18
+ if (payment && payment.uuidConsult) {
19
+ return oroClient.consultClient.getConsultByUUID(payment.uuidConsult).catch((err) => {
20
+ console.error('Error while retrieving consult', err)
21
+ throw err
22
+ })
23
+ } else {
24
+ return await oroClient.consultClient.consultCreate(consult).catch((err) => {
25
+ console.error('Error while creating consult', err)
26
+ throw err
27
+ })
28
+ }
29
+ }
@@ -2,3 +2,4 @@ export * from './client'
2
2
  export * from './workflow'
3
3
  export * from './patient-registration'
4
4
  export * from './vault-grants'
5
+ export * from './prescription-refill'
@@ -29,6 +29,7 @@ import {
29
29
  RegisterPatientOutput,
30
30
  toActualObject,
31
31
  } from '..'
32
+ import { getOrCreatePatientConsultationUuid } from './consult'
32
33
 
33
34
  const MAX_RETRIES = 15
34
35
 
@@ -275,30 +276,6 @@ export async function registerPatient(
275
276
  }
276
277
  }
277
278
 
278
- /**
279
- * Creates a consultation if one has not been created and fails to be retrieved by the payment intent
280
- * @param consult
281
- * @param oroClient
282
- * @returns the consult Uuid
283
- */
284
- async function getOrCreatePatientConsultationUuid(consult: ConsultRequest, oroClient: OroClient): Promise<Consult> {
285
- let payment = await oroClient.practiceClient.practiceGetPayment(
286
- consult.uuidPractice,
287
- consult.idStripeInvoiceOrPaymentIntent
288
- )
289
- if (payment && payment.uuidConsult) {
290
- return oroClient.consultClient.getConsultByUUID(payment.uuidConsult).catch((err) => {
291
- console.error('Error while retrieving consult', err)
292
- throw err
293
- })
294
- } else {
295
- return await oroClient.consultClient.consultCreate(consult).catch((err) => {
296
- console.error('Error while creating consult', err)
297
- throw err
298
- })
299
- }
300
- }
301
-
302
279
  /**
303
280
  * Creates a new lockbox for the patient if they do not have any, otherwise, use the first (and only one)
304
281
  * @param oroClient
@@ -0,0 +1,176 @@
1
+ import {
2
+ Consult,
3
+ ConsultRequest,
4
+ DocumentType,
5
+ MedicalStatus,
6
+ MetadataCategory,
7
+ PlaceData,
8
+ SelectedAnswersData,
9
+ Uuid,
10
+ WorkflowData,
11
+ } from 'oro-sdk-apis'
12
+ import { OroClient } from '..'
13
+ import { getOrCreatePatientConsultationUuid } from './consult'
14
+
15
+ const MAX_RETRIES = 15
16
+ /**
17
+ * Placeholder while the workflow interpreter for the refill flows is complete
18
+ *
19
+ * Creates a fake workflow in which the workflow data will reside
20
+ *
21
+ * @param isTreatmentWorking the value from the `is treatment working` question
22
+ * @param hasSideEffects the value from the `does the treatment have side effects` question
23
+ * @param deliveryAddress the provided delivery address
24
+ * @param pharmacy
25
+ * @returns a workflow
26
+ */
27
+ export function getRefillAnswersAsWorkflow(
28
+ isTreatmentWorking: string,
29
+ hasSideEffects: string,
30
+ deliveryAddress?: string,
31
+ pharmacy?: PlaceData
32
+ ): WorkflowData {
33
+ let selectedAnswers: SelectedAnswersData = [
34
+ {
35
+ ['isTreatmentWorking']: isTreatmentWorking,
36
+ },
37
+ {
38
+ ['hasSideEffects']: hasSideEffects,
39
+ },
40
+ ]
41
+
42
+ if (deliveryAddress) selectedAnswers.push({ ['deliveryAddress']: deliveryAddress })
43
+ if (pharmacy) selectedAnswers.push({ ['pharmacy']: JSON.stringify(pharmacy) })
44
+
45
+ return {
46
+ "id": "32573a20-6f1d-49be-9ad3-b87c58074979",
47
+ "createdAt": "2022-10-03T00:00:00.000Z",
48
+ "culDeSacs": [],
49
+ "hidePlanRules": [],
50
+ "pages": [
51
+ {
52
+ "title": "Prescription Refill",
53
+ "groups": [
54
+ {
55
+ "type": "field-group",
56
+ "fieldsAndGroups": [
57
+ {
58
+ "type": "field",
59
+ "id": "isTreatmentWorking"
60
+ },
61
+ {
62
+ "type": "field",
63
+ "id": "hasSideEffects"
64
+ },
65
+ {
66
+ "type": "field",
67
+ "id": "youPharmacy"
68
+ },
69
+ {
70
+ "type": "field",
71
+ "id": "youAddress"
72
+ }
73
+ ]
74
+ }
75
+ ],
76
+ "questions": {
77
+ "isTreatmentWorking": {
78
+ "label": "Is the treatment working for you?",
79
+ "kind": "radio",
80
+ "inline": true,
81
+ "inlineLabel": false,
82
+ "metaCategory": MetadataCategory.Refill,
83
+ "answers": {
84
+ "73bec6eb-0310-4787-af3c-ac9c291737b2": {
85
+ "text": "Yes"
86
+ },
87
+ "e193951f-986f-4db3-bede-903045a1804a": {
88
+ "text": "No"
89
+ }
90
+ }
91
+ },
92
+ "hasSideEffects": {
93
+ "label": "Are there any side effects",
94
+ "kind": "radio",
95
+ "inline": true,
96
+ "inlineLabel": false,
97
+ "metaCategory": MetadataCategory.Refill,
98
+ "answers": {
99
+ "1b87ad22-d316-4fac-9c7f-8f4ccb841aed": {
100
+ "text": "Yes"
101
+ },
102
+ "ab7f5a41-c351-4f5d-a568-e38f9f200e9a": {
103
+ "text": "No"
104
+ }
105
+ }
106
+ },
107
+ "youPharmacy": {
108
+ "kind": "online-pharmacy-picker",
109
+ "label": "Which pharmacy do you want the prescription sent to?",
110
+ "metaCategory": MetadataCategory.Refill,
111
+ "minorLabel": " (Optional)",
112
+ "summaryLabel": "Your pharmacy"
113
+ },
114
+ "youAddress": {
115
+ "kind": "place-address",
116
+ "label": "Address",
117
+ "metaCategory": MetadataCategory.Refill
118
+ }
119
+ }
120
+ }
121
+ ],
122
+ "locale": "en",
123
+ selectedAnswers
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Complete refill flow, creates a consult, stores refill data and updates consultation status
129
+ * @param consultRequest
130
+ * @param populatedRefillWorkflow the refill workflow data
131
+ * @param oroClient
132
+ */
133
+ export async function createRefill(
134
+ consultRequest: ConsultRequest,
135
+ populatedRefillWorkflow: WorkflowData,
136
+ oroClient: OroClient
137
+ ) {
138
+ let retry = MAX_RETRIES
139
+ let errorsThrown: Error[] = []
140
+
141
+ let newConsult: Consult | undefined
142
+ let lockboxUuid: Uuid | undefined
143
+
144
+ for (; retry > 0; retry--) {
145
+ try {
146
+ if (!newConsult) newConsult = await getOrCreatePatientConsultationUuid(consultRequest, oroClient)
147
+
148
+ if (!lockboxUuid) lockboxUuid = (await oroClient.getGrants())[0].lockboxUuid
149
+
150
+ await oroClient
151
+ .getOrInsertJsonData(
152
+ lockboxUuid!,
153
+ populatedRefillWorkflow,
154
+ {
155
+ category: MetadataCategory.Refill,
156
+ documentType: DocumentType.PopulatedWorkflowData,
157
+ consultationIds: [newConsult.uuid],
158
+ },
159
+ {}
160
+ )
161
+ .catch((err) => {
162
+ console.error('[SDK: prescription refill] Some errors happened during refill data upload', err)
163
+ errorsThrown.push(err)
164
+ })
165
+
166
+ if (errorsThrown.length > 0) throw errorsThrown
167
+ await oroClient.consultClient.updateConsultByUUID(newConsult.uuid, {
168
+ statusMedical: MedicalStatus.New,
169
+ })
170
+ } catch (err) {
171
+ console.error(`[SDK] Error occured during refill: ${err}, retrying... Retries remaining: ${retry}`)
172
+ errorsThrown = []
173
+ continue
174
+ }
175
+ }
176
+ }