oro-sdk 3.22.0 → 3.25.0-dev1
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/dist/client.d.ts +2 -1
- package/dist/helpers/patient-registration.d.ts +5 -1
- package/dist/oro-sdk.cjs.development.js +775 -1158
- 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 +775 -1158
- package/dist/oro-sdk.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/client.ts +5 -3
- package/src/helpers/patient-registration.ts +63 -4
- package/LICENSE +0 -21
    
        package/package.json
    CHANGED
    
    | @@ -1,5 +1,5 @@ | |
| 1 1 | 
             
            {
         | 
| 2 | 
            -
                "version": "3. | 
| 2 | 
            +
                "version": "3.25.0-dev1",
         | 
| 3 3 | 
             
                "main": "dist/index.js",
         | 
| 4 4 | 
             
                "typings": "dist/index.d.ts",
         | 
| 5 5 | 
             
                "files": [
         | 
| @@ -54,7 +54,7 @@ | |
| 54 54 | 
             
                    "form-data": "^4.0.0",
         | 
| 55 55 | 
             
                    "formdata-node": "^4.3.1",
         | 
| 56 56 | 
             
                    "idb-keyval": "^5.0.6",
         | 
| 57 | 
            -
                    "oro-sdk-apis": "1. | 
| 57 | 
            +
                    "oro-sdk-apis": "1.57.0-dev1",
         | 
| 58 58 | 
             
                    "oro-toolbox": "0.0.6",
         | 
| 59 59 | 
             
                    "uuid": "^8.3.2"
         | 
| 60 60 | 
             
                }
         | 
    
        package/src/client.ts
    CHANGED
    
    | @@ -285,6 +285,7 @@ export class OroClient { | |
| 285 285 | 
             
                 * @param workflow
         | 
| 286 286 | 
             
                 * @param recoveryQA
         | 
| 287 287 | 
             
                 * @param indexSearch create search index for the consultation if true
         | 
| 288 | 
            +
                 * @param onProgress callback that is called whenever a new step of patient registration is executed. Note: progress ranges from 0 to 1, and descriptionKey is a description of the progress as a key so the app would use it to translate the description
         | 
| 288 289 | 
             
                 * @returns
         | 
| 289 290 | 
             
                 */
         | 
| 290 291 | 
             
                public async registerPatient(
         | 
| @@ -295,10 +296,11 @@ export class OroClient { | |
| 295 296 | 
             
                        recoverySecurityQuestions: string[]
         | 
| 296 297 | 
             
                        recoverySecurityAnswers: string[]
         | 
| 297 298 | 
             
                    },
         | 
| 298 | 
            -
                    indexSearch: boolean = true
         | 
| 299 | 
            +
                    indexSearch: boolean = true,
         | 
| 300 | 
            +
                    onProgress?: (progress: number, descriptionKey: string) => void
         | 
| 299 301 | 
             
                ): Promise<RegisterPatientOutput> {
         | 
| 300 302 | 
             
                    if (!this.rsa) throw IncompleteAuthentication
         | 
| 301 | 
            -
                    return registerPatient(patientUuid, consult, workflow, this, this.toolbox.uuid(), recoveryQA, indexSearch)
         | 
| 303 | 
            +
                    return registerPatient(patientUuid, consult, workflow, this, this.toolbox.uuid(), recoveryQA, indexSearch, onProgress)
         | 
| 302 304 | 
             
                }
         | 
| 303 305 |  | 
| 304 306 | 
             
                /**
         | 
| @@ -1513,4 +1515,4 @@ export class OroClient { | |
| 1513 1515 |  | 
| 1514 1516 | 
             
                    return updatedIdentity
         | 
| 1515 1517 | 
             
                }
         | 
| 1516 | 
            -
            }
         | 
| 1518 | 
            +
            }
         | 
| @@ -51,6 +51,7 @@ const MAX_RETRIES = 15 | |
| 51 51 | 
             
             * @param masterKey
         | 
| 52 52 | 
             
             * @param recoveryQA
         | 
| 53 53 | 
             
             * @param indexSearch create search index for the consultation if true
         | 
| 54 | 
            +
             * @param onProgress callback that is called whenever a new step of patient registration is executed. Note: progress ranges from 0 to 1, and descriptionKey is a description of the progress as a key so the app would use it to translate the description
         | 
| 54 55 | 
             
             * @returns the successful registration
         | 
| 55 56 | 
             
             */
         | 
| 56 57 | 
             
            export async function registerPatient(
         | 
| @@ -63,7 +64,8 @@ export async function registerPatient( | |
| 63 64 | 
             
                    recoverySecurityQuestions: string[]
         | 
| 64 65 | 
             
                    recoverySecurityAnswers: string[]
         | 
| 65 66 | 
             
                },
         | 
| 66 | 
            -
                indexSearch: boolean = true
         | 
| 67 | 
            +
                indexSearch: boolean = true,
         | 
| 68 | 
            +
                onProgress?: (progress: number, descriptionKey: string, extraInfo?: { storedImagesNum?: number, totalImagesNum?: number }) => void
         | 
| 67 69 | 
             
            ): Promise<RegisterPatientOutput> {
         | 
| 68 70 | 
             
                let consult: Consult | undefined = undefined
         | 
| 69 71 | 
             
                let lockboxUuid: Uuid | undefined = undefined
         | 
| @@ -71,9 +73,16 @@ export async function registerPatient( | |
| 71 73 | 
             
                let retry = MAX_RETRIES
         | 
| 72 74 | 
             
                let identity: IdentityResponse | undefined = undefined
         | 
| 73 75 | 
             
                let errorsThrown: Error[] = []
         | 
| 76 | 
            +
                const stepsTotalNum = 9
         | 
| 77 | 
            +
                let currentStep: number
         | 
| 74 78 |  | 
| 75 79 | 
             
                for (; retry > 0; retry--) {
         | 
| 76 80 | 
             
                    try {
         | 
| 81 | 
            +
                        currentStep = 0
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                        if (onProgress) onProgress((currentStep++)/stepsTotalNum, 'retrieve_practitioners')
         | 
| 84 | 
            +
             | 
| 85 | 
            +
             | 
| 77 86 | 
             
                        // Wait a bit each retry (we also want the first one to wait)
         | 
| 78 87 | 
             
                        await new Promise((resolve) => setTimeout(resolve, 2000))
         | 
| 79 88 |  | 
| @@ -90,11 +99,15 @@ export async function registerPatient( | |
| 90 99 | 
             
                            })
         | 
| 91 100 |  | 
| 92 101 | 
             
                        // Creating consult
         | 
| 102 | 
            +
                        if (onProgress) onProgress((currentStep++)/stepsTotalNum, 'create_consult')
         | 
| 103 | 
            +
             | 
| 93 104 | 
             
                        if (!consult) {
         | 
| 94 105 | 
             
                            consult = await getOrCreatePatientConsultationUuid(consultRequest, oroClient)
         | 
| 95 106 | 
             
                        }
         | 
| 96 107 |  | 
| 97 108 | 
             
                        // Creating lockbox
         | 
| 109 | 
            +
                        if (onProgress) onProgress((currentStep++)/stepsTotalNum, 'create_lockbox')
         | 
| 110 | 
            +
             | 
| 98 111 | 
             
                        if (!lockboxUuid) lockboxUuid = await getOrCreatePatientLockbox(oroClient)
         | 
| 99 112 |  | 
| 100 113 | 
             
                        if (!identity) identity = await oroClient.guardClient.identityGet(patientUuid)
         | 
| @@ -106,6 +119,8 @@ export async function registerPatient( | |
| 106 119 | 
             
                        })
         | 
| 107 120 |  | 
| 108 121 | 
             
                        // Patient Grant to practice
         | 
| 122 | 
            +
                        if (onProgress) onProgress((currentStep++)/stepsTotalNum, 'grant_patient')
         | 
| 123 | 
            +
             | 
| 109 124 | 
             
                        let grantPromises = practitioners
         | 
| 110 125 | 
             
                            .filter((practitioner) => practitioner.uuid !== practitionerAdmin)
         | 
| 111 126 | 
             
                            .map(async (practitioner) => {
         | 
| @@ -142,12 +157,25 @@ export async function registerPatient( | |
| 142 157 | 
             
                            })
         | 
| 143 158 | 
             
                        })
         | 
| 144 159 |  | 
| 145 | 
            -
                        await storeImageAliases( | 
| 160 | 
            +
                        await storeImageAliases(
         | 
| 161 | 
            +
                            consult.uuid,
         | 
| 162 | 
            +
                            lockboxUuid,
         | 
| 163 | 
            +
                            workflow,
         | 
| 164 | 
            +
                            oroClient,
         | 
| 165 | 
            +
                            onProgress? {
         | 
| 166 | 
            +
                                onProgress,
         | 
| 167 | 
            +
                                currentStep,
         | 
| 168 | 
            +
                                stepsTotalNum
         | 
| 169 | 
            +
                            } : undefined
         | 
| 170 | 
            +
                        ).catch((err) => {
         | 
| 146 171 | 
             
                            console.error('[SDK: registration] Some errors happened during image upload', err)
         | 
| 147 172 | 
             
                            // Acceptable to continue as images can be requested during the consultation, but we should still retry until the last retry remains
         | 
| 148 173 | 
             
                            if (retry <= 1) return
         | 
| 149 174 | 
             
                            else errorsThrown.push(err)
         | 
| 150 175 | 
             
                        })
         | 
| 176 | 
            +
                        ++currentStep
         | 
| 177 | 
            +
             | 
| 178 | 
            +
                        if (onProgress) onProgress((currentStep++)/stepsTotalNum, 'store_patient_data')
         | 
| 151 179 |  | 
| 152 180 | 
             
                        await storePatientData(
         | 
| 153 181 | 
             
                            consult.uuid,
         | 
| @@ -160,6 +188,8 @@ export async function registerPatient( | |
| 160 188 | 
             
                            errorsThrown.push(err)
         | 
| 161 189 | 
             
                        })
         | 
| 162 190 |  | 
| 191 | 
            +
                        if (onProgress) onProgress((currentStep++)/stepsTotalNum, 'set_masterkey')
         | 
| 192 | 
            +
             | 
| 163 193 | 
             
                        if (masterKey && !identity?.recoveryMasterKey) {
         | 
| 164 194 | 
             
                            // generate and store recovery payload and updates the identity
         | 
| 165 195 | 
             
                            identity = await oroClient.updateMasterKey(patientUuid, masterKey, lockboxUuid).catch((err) => {
         | 
| @@ -174,6 +204,8 @@ export async function registerPatient( | |
| 174 204 | 
             
                            masterKey = undefined
         | 
| 175 205 | 
             
                        }
         | 
| 176 206 |  | 
| 207 | 
            +
                        if (onProgress) onProgress((currentStep++)/stepsTotalNum, 'set_security_questions')
         | 
| 208 | 
            +
             | 
| 177 209 | 
             
                        if (recoveryQA && !identity?.recoverySecurityQuestions)
         | 
| 178 210 | 
             
                            // Patient security question recovery threshold is 2 answers and updates the identity
         | 
| 179 211 | 
             
                            identity = await oroClient
         | 
| @@ -194,6 +226,8 @@ export async function registerPatient( | |
| 194 226 | 
             
                        await Promise.all([...grantPromises, ...consultIndexPromises])
         | 
| 195 227 |  | 
| 196 228 |  | 
| 229 | 
            +
                        if (onProgress) onProgress((currentStep++)/stepsTotalNum, 'search_indexing')
         | 
| 230 | 
            +
             | 
| 197 231 | 
             
                        if (indexSearch) {
         | 
| 198 232 | 
             
                            await buildConsultSearchIndex(consult, workflow, oroClient).catch((err) => {
         | 
| 199 233 | 
             
                                console.error(
         | 
| @@ -213,6 +247,8 @@ export async function registerPatient( | |
| 213 247 | 
             
                        })
         | 
| 214 248 |  | 
| 215 249 | 
             
                        // if we got through the complete flow, the registration succeeded
         | 
| 250 | 
            +
                        if (onProgress) onProgress((currentStep++)/stepsTotalNum, 'success')
         | 
| 251 | 
            +
             | 
| 216 252 | 
             
                        break
         | 
| 217 253 | 
             
                    } catch (err) {
         | 
| 218 254 | 
             
                        console.error(`[SDK] Error occured during registration: ${err}, retrying... Retries remaining: ${retry}`)
         | 
| @@ -374,7 +410,12 @@ async function storeImageAliases( | |
| 374 410 | 
             
                consultationId: Uuid,
         | 
| 375 411 | 
             
                lockboxUuid: Uuid,
         | 
| 376 412 | 
             
                workflow: WorkflowData,
         | 
| 377 | 
            -
                oroClient: OroClient
         | 
| 413 | 
            +
                oroClient: OroClient,
         | 
| 414 | 
            +
                progress?: {
         | 
| 415 | 
            +
                    currentStep: number;
         | 
| 416 | 
            +
                    stepsTotalNum: number;
         | 
| 417 | 
            +
                    onProgress: (progress: number, descriptionKey: string, extraInfo?: { storedImagesNum?: number; totalImagesNum?: number }) => void;
         | 
| 418 | 
            +
                }
         | 
| 378 419 | 
             
            ): Promise<(Uuid | void)[]> {
         | 
| 379 420 | 
             
                const images = await getImagesFromIndexDb((await filterTriggeredAnsweredWithKind(workflow, 'images-alias')).flat())
         | 
| 380 421 |  | 
| @@ -384,6 +425,11 @@ async function storeImageAliases( | |
| 384 425 | 
             
                    console.error('[SDK] Some images have not been found, they have been skipped.')
         | 
| 385 426 | 
             
                }
         | 
| 386 427 |  | 
| 428 | 
            +
                let storedImagesNum = 0
         | 
| 429 | 
            +
                let totalImagesNum = nonNullImages.length
         | 
| 430 | 
            +
                if (progress)
         | 
| 431 | 
            +
                    progress.onProgress(progress.currentStep/progress.stepsTotalNum, 'store_images', {storedImagesNum, totalImagesNum})
         | 
| 432 | 
            +
             | 
| 387 433 | 
             
                let promises = nonNullImages.map((image) => {
         | 
| 388 434 | 
             
                    return oroClient.getOrInsertJsonData<ConsultationImageMeta>(
         | 
| 389 435 | 
             
                        lockboxUuid,
         | 
| @@ -395,7 +441,20 @@ async function storeImageAliases( | |
| 395 441 | 
             
                            idbId: image.idbId as string,
         | 
| 396 442 | 
             
                        },
         | 
| 397 443 | 
             
                        {}
         | 
| 398 | 
            -
                    )
         | 
| 444 | 
            +
                    ).then(() => {
         | 
| 445 | 
            +
                        if (progress) {
         | 
| 446 | 
            +
                            ++storedImagesNum
         | 
| 447 | 
            +
                            let progressStepValue = Math.round((((progress.currentStep + 1)/progress.stepsTotalNum) - (progress.currentStep/progress.stepsTotalNum)) * 100) / 100
         | 
| 448 | 
            +
                            progress.onProgress(
         | 
| 449 | 
            +
                                (progress.currentStep/progress.stepsTotalNum) + (progressStepValue * (storedImagesNum/totalImagesNum)),
         | 
| 450 | 
            +
                                'store_images',
         | 
| 451 | 
            +
                                {
         | 
| 452 | 
            +
                                    storedImagesNum,
         | 
| 453 | 
            +
                                    totalImagesNum
         | 
| 454 | 
            +
                                })
         | 
| 455 | 
            +
                        }
         | 
| 456 | 
            +
             | 
| 457 | 
            +
                    })
         | 
| 399 458 | 
             
                })
         | 
| 400 459 | 
             
                return Promise.all(promises)
         | 
| 401 460 | 
             
            }
         | 
    
        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.
         |