@icure/api 6.3.1 → 6.4.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/icc-api/api/IccAccesslogApi.d.ts +7 -0
- package/icc-api/api/IccAccesslogApi.js +20 -0
- package/icc-api/api/IccAccesslogApi.js.map +1 -1
- package/icc-api/api/IccCalendarItemApi.d.ts +7 -0
- package/icc-api/api/IccCalendarItemApi.js +20 -0
- package/icc-api/api/IccCalendarItemApi.js.map +1 -1
- package/icc-api/api/IccContactApi.d.ts +16 -0
- package/icc-api/api/IccContactApi.js +44 -0
- package/icc-api/api/IccContactApi.js.map +1 -1
- package/icc-api/api/IccDataownerApi.d.ts +33 -0
- package/icc-api/api/IccDataownerApi.js +55 -0
- package/icc-api/api/IccDataownerApi.js.map +1 -0
- package/icc-api/api/IccFormApi.d.ts +17 -0
- package/icc-api/api/IccFormApi.js +46 -0
- package/icc-api/api/IccFormApi.js.map +1 -1
- package/icc-api/api/IccGroupApi.d.ts +10 -1
- package/icc-api/api/IccGroupApi.js +23 -2
- package/icc-api/api/IccGroupApi.js.map +1 -1
- package/icc-api/api/IccHelementApi.d.ts +14 -0
- package/icc-api/api/IccHelementApi.js +40 -0
- package/icc-api/api/IccHelementApi.js.map +1 -1
- package/icc-api/api/IccInvoiceApi.d.ts +14 -0
- package/icc-api/api/IccInvoiceApi.js +40 -0
- package/icc-api/api/IccInvoiceApi.js.map +1 -1
- package/icc-api/api/IccMessageApi.d.ts +6 -0
- package/icc-api/api/IccMessageApi.js +15 -0
- package/icc-api/api/IccMessageApi.js.map +1 -1
- package/icc-api/api/IccUserApi.js +1 -1
- package/icc-api/api/IccUserApi.js.map +1 -1
- package/icc-api/iccApi.d.ts +1 -0
- package/icc-api/iccApi.js +1 -0
- package/icc-api/iccApi.js.map +1 -1
- package/icc-api/model/AttachmentMetadata.d.ts +21 -0
- package/icc-api/model/AttachmentMetadata.js +24 -0
- package/icc-api/model/AttachmentMetadata.js.map +1 -0
- package/icc-api/model/BulkAttachmentUpdateOptions.d.ts +28 -0
- package/icc-api/model/BulkAttachmentUpdateOptions.js +13 -0
- package/icc-api/model/BulkAttachmentUpdateOptions.js.map +1 -0
- package/icc-api/model/{Body2.d.ts → DataOwnerWithType.d.ts} +4 -4
- package/icc-api/model/{Body1.js → DataOwnerWithType.js} +5 -6
- package/icc-api/model/DataOwnerWithType.js.map +1 -0
- package/icc-api/model/DiaryNoteExportInfo.d.ts +1 -1
- package/icc-api/model/DiaryNoteExportInfo.js.map +1 -1
- package/icc-api/model/GroupDeletionReport.d.ts +17 -0
- package/icc-api/model/{Body2.js → GroupDeletionReport.js} +7 -8
- package/icc-api/model/GroupDeletionReport.js.map +1 -0
- package/icc-api/model/IncapacityExportInfo.d.ts +2 -0
- package/icc-api/model/IncapacityExportInfo.js.map +1 -1
- package/icc-api/model/{Body1.d.ts → Part.d.ts} +1 -2
- package/icc-api/model/Part.js +21 -0
- package/icc-api/model/Part.js.map +1 -0
- package/icc-api/model/UserGroup.d.ts +2 -0
- package/icc-api/model/UserGroup.js +0 -11
- package/icc-api/model/UserGroup.js.map +1 -1
- package/icc-api/model/models.d.ts +8 -1
- package/icc-api/model/models.js +8 -1
- package/icc-api/model/models.js.map +1 -1
- package/icc-x-api/auth/JwtAuthService.js.map +1 -1
- package/icc-x-api/crypto/AES.d.ts +1 -0
- package/icc-x-api/crypto/AES.js +10 -1
- package/icc-x-api/crypto/AES.js.map +1 -1
- package/icc-x-api/filters/PatientByHcPartyAndAddressFilter.d.ts +21 -0
- package/icc-x-api/filters/PatientByHcPartyAndAddressFilter.js +24 -0
- package/icc-x-api/filters/PatientByHcPartyAndAddressFilter.js.map +1 -0
- package/icc-x-api/filters/filters.d.ts +2 -0
- package/icc-x-api/filters/filters.js +10 -0
- package/icc-x-api/filters/filters.js.map +1 -1
- package/icc-x-api/icc-accesslog-x-api.d.ts +3 -1
- package/icc-x-api/icc-accesslog-x-api.js +15 -6
- package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
- package/icc-x-api/icc-bekmehr-x-api.d.ts +1 -0
- package/icc-x-api/icc-bekmehr-x-api.js +100 -64
- package/icc-x-api/icc-bekmehr-x-api.js.map +1 -1
- package/icc-x-api/icc-calendar-item-x-api.d.ts +2 -1
- package/icc-x-api/icc-calendar-item-x-api.js +17 -4
- package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
- package/icc-x-api/icc-contact-x-api.d.ts +3 -1
- package/icc-x-api/icc-contact-x-api.js +19 -8
- package/icc-x-api/icc-contact-x-api.js.map +1 -1
- package/icc-x-api/icc-crypto-x-api.d.ts +6 -0
- package/icc-x-api/icc-crypto-x-api.js +19 -6
- package/icc-x-api/icc-crypto-x-api.js.map +1 -1
- package/icc-x-api/icc-form-x-api.d.ts +3 -2
- package/icc-x-api/icc-form-x-api.js +8 -4
- package/icc-x-api/icc-form-x-api.js.map +1 -1
- package/icc-x-api/icc-helement-x-api.d.ts +8 -3
- package/icc-x-api/icc-helement-x-api.js +33 -6
- package/icc-x-api/icc-helement-x-api.js.map +1 -1
- package/icc-x-api/icc-invoice-x-api.d.ts +2 -1
- package/icc-x-api/icc-invoice-x-api.js +5 -2
- package/icc-x-api/icc-invoice-x-api.js.map +1 -1
- package/icc-x-api/icc-maintenance-task-x-api.js +8 -2
- package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
- package/icc-x-api/icc-patient-x-api.d.ts +2 -2
- package/icc-x-api/icc-patient-x-api.js +72 -61
- package/icc-x-api/icc-patient-x-api.js.map +1 -1
- package/package.json +1 -1
- package/icc-api/model/Body1.js.map +0 -1
- package/icc-api/model/Body2.js.map +0 -1
|
@@ -27,8 +27,9 @@ export declare class IccFormXApi extends IccFormApi {
|
|
|
27
27
|
* After these painful steps, you have the contacts of the patient.
|
|
28
28
|
*
|
|
29
29
|
* @param hcpartyId
|
|
30
|
-
* @param patient
|
|
30
|
+
* @param patient
|
|
31
|
+
* @param usingPost (Promise)
|
|
31
32
|
*/
|
|
32
|
-
findBy(hcpartyId: string, patient: models.Patient): Promise<void | (void | models.Form)[]>;
|
|
33
|
+
findBy(hcpartyId: string, patient: models.Patient, usingPost?: boolean): Promise<void | (void | models.Form)[]>;
|
|
33
34
|
decrypt(hcpartyId: string, forms: Array<models.Form>): Promise<void | (void | models.Form)[]>;
|
|
34
35
|
}
|
|
@@ -83,12 +83,15 @@ class IccFormXApi extends icc_api_1.IccFormApi {
|
|
|
83
83
|
* After these painful steps, you have the contacts of the patient.
|
|
84
84
|
*
|
|
85
85
|
* @param hcpartyId
|
|
86
|
-
* @param patient
|
|
86
|
+
* @param patient
|
|
87
|
+
* @param usingPost (Promise)
|
|
87
88
|
*/
|
|
88
|
-
findBy(hcpartyId, patient) {
|
|
89
|
+
findBy(hcpartyId, patient, usingPost = false) {
|
|
89
90
|
return this.crypto
|
|
90
91
|
.extractDelegationsSFKs(patient, hcpartyId)
|
|
91
|
-
.then((secretForeignKeys) =>
|
|
92
|
+
.then((secretForeignKeys) => usingPost
|
|
93
|
+
? this.findFormsByHCPartyPatientForeignKeysUsingPost(secretForeignKeys.hcpartyId, undefined, undefined, undefined, _.uniq(secretForeignKeys.extractedKeys))
|
|
94
|
+
: this.findFormsByHCPartyPatientForeignKeys(secretForeignKeys.hcpartyId, _.uniq(secretForeignKeys.extractedKeys).join(',')))
|
|
92
95
|
.then((forms) => this.decrypt(hcpartyId, forms))
|
|
93
96
|
.then(function (decryptedForms) {
|
|
94
97
|
return decryptedForms;
|
|
@@ -99,7 +102,8 @@ class IccFormXApi extends icc_api_1.IccFormApi {
|
|
|
99
102
|
.extractKeysFromDelegationsForHcpHierarchy(hcpartyId, form.id, _.size(form.encryptionKeys) ? form.encryptionKeys : form.delegations)
|
|
100
103
|
.then(({ extractedKeys: sfks }) => {
|
|
101
104
|
if (form.encryptedSelf) {
|
|
102
|
-
|
|
105
|
+
sfks = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(sfks);
|
|
106
|
+
return this.crypto.AES.importKey('raw', (0, binary_utils_1.hex2ua)(sfks[0]))
|
|
103
107
|
.then((key) => new Promise((resolve) => {
|
|
104
108
|
this.crypto.AES.decrypt(key, (0, binary_utils_1.string2ua)((0, binary_utils_1.a2b)(form.encryptedSelf))).then(resolve, () => {
|
|
105
109
|
console.log('Cannot decrypt form', form.id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-form-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-form-x-api.ts"],"names":[],"mappings":";;;AAAA,wCAAuC;AAGvC,4BAA2B;AAG3B,uDAAwE;AAExE,0EAAgG;AAEhG,qCAAqC;AACrC,MAAa,WAAY,SAAQ,oBAAU;IAIzC,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EAC9B,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;QACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAED,qCAAqC;IACrC,WAAW,CAAC,IAAiB,EAAE,OAAuB,EAAE,IAAS,EAAE,EAAE,YAAsB,EAAE;QAC3F,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CACnB;YACE,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;YAC5B,KAAK,EAAE,gCAAgC;YACvC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC7B,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC9B,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,cAAc,C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;YAChB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QAChB,CAAC,CAAC,CACL,CACF,CAAC,KAAK,CAAC,UAAU,CAAC;YACjB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QAChB,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAtKD,kCAsKC","sourcesContent":["import { IccFormApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\n\nimport { a2b, hex2ua, string2ua, ua2string } from './utils/binary-utils'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccFormXApi extends IccFormApi {\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n }\n\n // noinspection JSUnusedGlobalSymbols\n newInstance(user: models.User, patient: models.Patient, c: any = {}, delegates: string[] = []) {\n const form = _.extend(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.Form',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: this.dataOwnerApi.getDataOwnerOf(user),\n author: user.id,\n codes: [],\n tags: [],\n },\n c || {}\n )\n\n return this.initDelegationsAndEncryptionKeys(user, patient, form, delegates)\n }\n\n initEncryptionKeys(user: models.User, form: models.Form) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto.initEncryptionKeys(form, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(form, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((contact) =>\n this.crypto.appendEncryptionKeys(contact, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(extraEks.modifiedObject, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n private initDelegationsAndEncryptionKeys(\n user: models.User,\n patient: models.Patient,\n form: models.Form,\n delegates: string[] = []\n ): Promise<models.Form> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto\n .extractDelegationsSFKs(patient, dataOwnerId!)\n .then((secretForeignKeys) =>\n Promise.all([\n this.crypto.initObjectDelegations(form, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0]),\n this.crypto.initEncryptionKeys(form, dataOwnerId!),\n ])\n )\n .then((initData) => {\n const dels = initData[0]\n const eks = initData[1]\n _.extend(form, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(form)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((form) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, form, dataOwnerId!, delegateId, dels.secretId, eks.secretId).catch((e) => {\n console.log(e)\n return form\n })\n ))\n )\n return promise\n })\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all contacts with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the contacts of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n */\n findBy(hcpartyId: string, patient: models.Patient) {\n return this.crypto\n .extractDelegationsSFKs(patient, hcpartyId)\n .then((secretForeignKeys) =>\n this.findFormsByHCPartyPatientForeignKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(','))\n )\n .then((forms) => this.decrypt(hcpartyId, forms))\n .then(function (decryptedForms) {\n return decryptedForms\n })\n }\n\n decrypt(hcpartyId: string, forms: Array<models.Form>) {\n return Promise.all(\n forms.map((form) =>\n this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(hcpartyId, form.id!, _.size(form.encryptionKeys) ? form.encryptionKeys! : form.delegations!)\n .then(({ extractedKeys: sfks }) => {\n if (form.encryptedSelf) {\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0].replace(/-/g, '')))\n .then(\n (key) =>\n new Promise((resolve: (value: any) => any) => {\n this.crypto.AES.decrypt(key, string2ua(a2b(form.encryptedSelf!))).then(resolve, () => {\n console.log('Cannot decrypt form', form.id)\n resolve(null)\n })\n })\n )\n .then((decrypted: ArrayBuffer) => {\n if (decrypted) {\n form = _.extend(form, JSON.parse(ua2string(decrypted)))\n }\n return form\n })\n } else {\n return Promise.resolve(form)\n }\n })\n .catch(function (e) {\n console.log(e)\n })\n )\n ).catch(function (e) {\n console.log(e)\n })\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"icc-form-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-form-x-api.ts"],"names":[],"mappings":";;;AAAA,wCAAuC;AAGv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AK,CAAC,UAAU,CAAC;YACjB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QAChB,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAhLD,kCAgLC","sourcesContent":["import { IccFormApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\n\nimport { a2b, hex2ua, string2ua, ua2string } from './utils/binary-utils'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccFormXApi extends IccFormApi {\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n }\n\n // noinspection JSUnusedGlobalSymbols\n newInstance(user: models.User, patient: models.Patient, c: any = {}, delegates: string[] = []) {\n const form = _.extend(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.Form',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: this.dataOwnerApi.getDataOwnerOf(user),\n author: user.id,\n codes: [],\n tags: [],\n },\n c || {}\n )\n\n return this.initDelegationsAndEncryptionKeys(user, patient, form, delegates)\n }\n\n initEncryptionKeys(user: models.User, form: models.Form) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto.initEncryptionKeys(form, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(form, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((contact) =>\n this.crypto.appendEncryptionKeys(contact, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(extraEks.modifiedObject, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n private initDelegationsAndEncryptionKeys(\n user: models.User,\n patient: models.Patient,\n form: models.Form,\n delegates: string[] = []\n ): Promise<models.Form> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto\n .extractDelegationsSFKs(patient, dataOwnerId!)\n .then((secretForeignKeys) =>\n Promise.all([\n this.crypto.initObjectDelegations(form, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0]),\n this.crypto.initEncryptionKeys(form, dataOwnerId!),\n ])\n )\n .then((initData) => {\n const dels = initData[0]\n const eks = initData[1]\n _.extend(form, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(form)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((form) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, form, dataOwnerId!, delegateId, dels.secretId, eks.secretId).catch((e) => {\n console.log(e)\n return form\n })\n ))\n )\n return promise\n })\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all contacts with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the contacts of the patient.\n *\n * @param hcpartyId\n * @param patient\n * @param usingPost (Promise)\n */\n findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false) {\n return this.crypto\n .extractDelegationsSFKs(patient, hcpartyId)\n .then((secretForeignKeys) =>\n usingPost\n ? this.findFormsByHCPartyPatientForeignKeysUsingPost(\n secretForeignKeys.hcpartyId!,\n undefined,\n undefined,\n undefined,\n _.uniq(secretForeignKeys.extractedKeys)\n )\n : this.findFormsByHCPartyPatientForeignKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(','))\n )\n .then((forms) => this.decrypt(hcpartyId, forms))\n .then(function (decryptedForms) {\n return decryptedForms\n })\n }\n\n decrypt(hcpartyId: string, forms: Array<models.Form>) {\n return Promise.all(\n forms.map((form) =>\n this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(hcpartyId, form.id!, _.size(form.encryptionKeys) ? form.encryptionKeys! : form.delegations!)\n .then(({ extractedKeys: sfks }) => {\n if (form.encryptedSelf) {\n sfks = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(sfks)\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0]))\n .then(\n (key) =>\n new Promise((resolve: (value: any) => any) => {\n this.crypto.AES.decrypt(key, string2ua(a2b(form.encryptedSelf!))).then(resolve, () => {\n console.log('Cannot decrypt form', form.id)\n resolve(null)\n })\n })\n )\n .then((decrypted: ArrayBuffer) => {\n if (decrypted) {\n form = _.extend(form, JSON.parse(ua2string(decrypted)))\n }\n return form\n })\n } else {\n return Promise.resolve(form)\n }\n })\n .catch(function (e) {\n console.log(e)\n })\n )\n ).catch(function (e) {\n console.log(e)\n })\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IccHelementApi } from '../icc-api';
|
|
2
2
|
import { IccCryptoXApi } from './icc-crypto-x-api';
|
|
3
3
|
import * as models from '../icc-api/model/models';
|
|
4
|
-
import { HealthElement } from '../icc-api/model/models';
|
|
4
|
+
import { FilterChainHealthElement, HealthElement, PaginatedListHealthElement } from '../icc-api/model/models';
|
|
5
5
|
import { IccDataOwnerXApi } from './icc-data-owner-x-api';
|
|
6
6
|
import { AuthenticationProvider } from './auth/AuthenticationProvider';
|
|
7
7
|
export declare class IccHelementXApi extends IccHelementApi {
|
|
@@ -25,7 +25,8 @@ export declare class IccHelementXApi extends IccHelementApi {
|
|
|
25
25
|
newHealthElementDelegationsWithUser(user: models.User, healthElementId: string, body?: Array<models.Delegation>): Promise<models.HealthElement>;
|
|
26
26
|
findHealthElementsByHCPartyPatientForeignKeys(hcPartyId: string, secretFKeys: string): never;
|
|
27
27
|
findHealthElementsByHCPartyPatientForeignKeysWithUser(user: models.User, hcPartyId: string, secretFKeys: string): Promise<HealthElement[]>;
|
|
28
|
-
|
|
28
|
+
findHealthElementsByHCPartyPatientForeignKeysArrayWithUser(user: models.User, hcPartyId: string, secretFKeys: string[]): Promise<HealthElement[]>;
|
|
29
|
+
findHealthElementsByHCPartyAndPatientWithUser(user: models.User, hcPartyId: string, patient: models.Patient, usingPost?: boolean): Promise<models.HealthElement[]>;
|
|
29
30
|
modifyHealthElement(body?: HealthElement): never;
|
|
30
31
|
modifyHealthElementWithUser(user: models.User, body?: HealthElement): Promise<HealthElement | any>;
|
|
31
32
|
modifyHealthElements(body?: Array<HealthElement>): never;
|
|
@@ -45,13 +46,17 @@ export declare class IccHelementXApi extends IccHelementApi {
|
|
|
45
46
|
* @param hcpartyId
|
|
46
47
|
* @param patient (Promise)
|
|
47
48
|
* @param keepObsoleteVersions
|
|
49
|
+
* @param usingPost
|
|
48
50
|
*/
|
|
49
|
-
findBy(hcpartyId: string, patient: models.Patient, keepObsoleteVersions?: boolean): Promise<models.HealthElement[]>;
|
|
51
|
+
findBy(hcpartyId: string, patient: models.Patient, keepObsoleteVersions?: boolean, usingPost?: boolean): Promise<models.HealthElement[]>;
|
|
50
52
|
findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.Contact> | any>;
|
|
53
|
+
findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<models.Contact> | any>;
|
|
51
54
|
encrypt(user: models.User, healthElements: Array<models.HealthElement>): Promise<Array<models.HealthElement>>;
|
|
52
55
|
initEncryptionKeys(user: models.User, he: models.HealthElement): Promise<models.HealthElement>;
|
|
53
56
|
decryptWithUser(user: models.User, hes: Array<models.HealthElement>): Promise<Array<models.HealthElement>>;
|
|
54
57
|
decrypt(dataOwnerId: string, hes: Array<models.HealthElement>): Promise<Array<models.HealthElement>>;
|
|
58
|
+
filterHealthElementsBy(startDocumentId?: string, limit?: number, body?: FilterChainHealthElement): never;
|
|
59
|
+
filterByWithUser(user: models.User, startDocumentId?: string, limit?: number, body?: FilterChainHealthElement): Promise<PaginatedListHealthElement>;
|
|
55
60
|
serviceToHealthElement(user: models.User, patient: models.Patient, heSvc: models.Service, descr: string): Promise<never>;
|
|
56
61
|
stringToCode(code: string): models.Code;
|
|
57
62
|
}
|
|
@@ -121,14 +121,19 @@ class IccHelementXApi extends icc_api_1.IccHelementApi {
|
|
|
121
121
|
findHealthElementsByHCPartyPatientForeignKeysWithUser(user, hcPartyId, secretFKeys) {
|
|
122
122
|
return super.findHealthElementsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((hes) => this.decryptWithUser(user, hes));
|
|
123
123
|
}
|
|
124
|
-
|
|
124
|
+
findHealthElementsByHCPartyPatientForeignKeysArrayWithUser(user, hcPartyId, secretFKeys) {
|
|
125
|
+
return super.findHealthElementsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys).then((hes) => this.decryptWithUser(user, hes));
|
|
126
|
+
}
|
|
127
|
+
findHealthElementsByHCPartyAndPatientWithUser(user, hcPartyId, patient, usingPost = false) {
|
|
125
128
|
return this.crypto.extractSFKsHierarchyFromDelegations(patient, hcPartyId).then((keysAndHcPartyId) => {
|
|
126
129
|
var _a;
|
|
127
130
|
const keys = (_a = keysAndHcPartyId.find((secretForeignKeys) => secretForeignKeys.hcpartyId == hcPartyId)) === null || _a === void 0 ? void 0 : _a.extractedKeys;
|
|
128
131
|
if (keys == undefined) {
|
|
129
132
|
throw Error('No delegation for user');
|
|
130
133
|
}
|
|
131
|
-
return
|
|
134
|
+
return usingPost
|
|
135
|
+
? this.findHealthElementsByHCPartyPatientForeignKeysArrayWithUser(user, hcPartyId, keys)
|
|
136
|
+
: this.findHealthElementsByHCPartyPatientForeignKeysWithUser(user, hcPartyId, keys.join(','));
|
|
132
137
|
});
|
|
133
138
|
}
|
|
134
139
|
modifyHealthElement(body) {
|
|
@@ -168,8 +173,9 @@ class IccHelementXApi extends icc_api_1.IccHelementApi {
|
|
|
168
173
|
* @param hcpartyId
|
|
169
174
|
* @param patient (Promise)
|
|
170
175
|
* @param keepObsoleteVersions
|
|
176
|
+
* @param usingPost
|
|
171
177
|
*/
|
|
172
|
-
findBy(hcpartyId, patient, keepObsoleteVersions = false) {
|
|
178
|
+
findBy(hcpartyId, patient, keepObsoleteVersions = false, usingPost = false) {
|
|
173
179
|
return this.crypto
|
|
174
180
|
.extractSFKsHierarchyFromDelegations(patient, hcpartyId)
|
|
175
181
|
.then((secretForeignKeys) => secretForeignKeys && secretForeignKeys.length > 0
|
|
@@ -183,7 +189,9 @@ class IccHelementXApi extends icc_api_1.IccHelementApi {
|
|
|
183
189
|
]);
|
|
184
190
|
}, [])
|
|
185
191
|
.filter((l) => l.extractedKeys.length > 0)
|
|
186
|
-
.map(({ hcpartyId, extractedKeys }) =>
|
|
192
|
+
.map(({ hcpartyId, extractedKeys }) => usingPost
|
|
193
|
+
? this.findByHCPartyPatientSecretFKeysArray(hcpartyId, _.uniq(extractedKeys))
|
|
194
|
+
: this.findByHCPartyPatientSecretFKeys(hcpartyId, _.uniq(extractedKeys).join(',')))).then((results) => _.uniqBy(_.flatMap(results), (x) => x.id))
|
|
187
195
|
: Promise.resolve([]))
|
|
188
196
|
.then((decryptedHelements) => {
|
|
189
197
|
const byIds = {};
|
|
@@ -206,13 +214,23 @@ class IccHelementXApi extends icc_api_1.IccHelementApi {
|
|
|
206
214
|
findByHCPartyPatientSecretFKeys(hcPartyId, secretFKeys) {
|
|
207
215
|
return super.findHealthElementsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((helements) => this.decrypt(hcPartyId, helements));
|
|
208
216
|
}
|
|
217
|
+
findByHCPartyPatientSecretFKeysArray(hcPartyId, secretFKeys) {
|
|
218
|
+
return super
|
|
219
|
+
.findHealthElementsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys)
|
|
220
|
+
.then((helements) => this.decrypt(hcPartyId, helements));
|
|
221
|
+
}
|
|
209
222
|
encrypt(user, healthElements) {
|
|
210
223
|
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
211
224
|
return Promise.all(healthElements.map((he) => (he.encryptionKeys && Object.keys(he.encryptionKeys).some((k) => !!he.encryptionKeys[k].length)
|
|
212
225
|
? Promise.resolve(he)
|
|
213
226
|
: this.initEncryptionKeys(user, he))
|
|
214
227
|
.then((healthElement) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, healthElement.id, healthElement.encryptionKeys))
|
|
215
|
-
.then((sfks) =>
|
|
228
|
+
.then((sfks) => {
|
|
229
|
+
const keys = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(sfks.extractedKeys);
|
|
230
|
+
if (!keys.length)
|
|
231
|
+
throw new Error('No valid keys found for calendar item encryption');
|
|
232
|
+
return this.crypto.AES.importKey('raw', (0, binary_utils_1.hex2ua)(keys[0]));
|
|
233
|
+
})
|
|
216
234
|
.then((key) => (0, utils_1.crypt)(he, (obj) => this.crypto.AES.encrypt(key, (0, binary_utils_1.utf8_2ua)(JSON.stringify(obj, (k, v) => {
|
|
217
235
|
return v instanceof ArrayBuffer || v instanceof Uint8Array
|
|
218
236
|
? (0, binary_utils_1.b2a)(new Uint8Array(v).reduce((d, b) => d + String.fromCharCode(b), ''))
|
|
@@ -246,12 +264,13 @@ class IccHelementXApi extends icc_api_1.IccHelementApi {
|
|
|
246
264
|
return Promise.all(hes.map((he) => this.crypto
|
|
247
265
|
.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, he.id, _.size(he.encryptionKeys) ? he.encryptionKeys : he.delegations)
|
|
248
266
|
.then(({ extractedKeys: sfks }) => {
|
|
267
|
+
sfks = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(sfks);
|
|
249
268
|
if (!sfks || !sfks.length) {
|
|
250
269
|
console.log('Cannot decrypt helement', he.id);
|
|
251
270
|
return Promise.resolve(he);
|
|
252
271
|
}
|
|
253
272
|
if (he.encryptedSelf) {
|
|
254
|
-
return this.crypto.AES.importKey('raw', (0, binary_utils_1.hex2ua)(sfks[0]
|
|
273
|
+
return this.crypto.AES.importKey('raw', (0, binary_utils_1.hex2ua)(sfks[0])).then((key) => new Promise((resolve) => this.crypto.AES.decrypt(key, (0, binary_utils_1.string2ua)((0, binary_utils_1.a2b)(he.encryptedSelf))).then((dec) => {
|
|
255
274
|
let jsonContent;
|
|
256
275
|
try {
|
|
257
276
|
jsonContent = dec && (0, binary_utils_1.ua2utf8)(dec);
|
|
@@ -271,6 +290,14 @@ class IccHelementXApi extends icc_api_1.IccHelementApi {
|
|
|
271
290
|
}
|
|
272
291
|
})));
|
|
273
292
|
}
|
|
293
|
+
filterHealthElementsBy(startDocumentId, limit, body) {
|
|
294
|
+
throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption');
|
|
295
|
+
}
|
|
296
|
+
filterByWithUser(user, startDocumentId, limit, body) {
|
|
297
|
+
return super
|
|
298
|
+
.filterHealthElementsBy(startDocumentId, limit, body)
|
|
299
|
+
.then((pl) => this.decryptWithUser(user, pl.rows).then((dr) => Object.assign(pl, { rows: dr })));
|
|
300
|
+
}
|
|
274
301
|
// noinspection JSUnusedGlobalSymbols
|
|
275
302
|
serviceToHealthElement(user, patient, heSvc, descr) {
|
|
276
303
|
return this.newInstance(user, patient, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-helement-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-helement-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA2C;AAG3C,kDAAiD;AAEjD,4BAA2B;AAC3B,iCAAgC;AAChC,uDAAqF;AAGrF,mCAA+B;AAC/B,0EAAgG;AAEhG,MAAa,eAAgB,SAAQ,wBAAc;IAMjD,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EAC9B,gBAA+B,CAAC,OAAO,EAAE,MAAM,CAAC,EAChD,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;QACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;IACpC,CAAC;IAED,WAAW,CAAC,IAAiB,EAAE,OAAuB,EAAE,CAAM,EAAE,YAAY,GAAG,KAAK,EAAE,YAAsB,EAAE;QAC5G,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;QAC1D,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CACvB;YACE,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;YAC5B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AAmB,CAAC,EAAE,CAAC,CAAA;QACrC,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,0DAA0D;IAC1D,YAAY,CAAC,IAAY;QACvB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACzB,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC;YACrB,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YACV,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YACV,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;YACb,EAAE,EAAE,IAAI;SACT,CAAC,CAAA;IACJ,CAAC;CACF;AA3YD,0CA2YC","sourcesContent":["import { IccHelementApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as models from '../icc-api/model/models'\n\nimport * as _ from 'lodash'\nimport * as moment from 'moment'\nimport { a2b, b2a, hex2ua, string2ua, ua2utf8, utf8_2ua } from './utils/binary-utils'\nimport { HealthElement } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { crypt } from './utils'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\nexport class IccHelementXApi extends IccHelementApi {\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n\n private readonly encryptedKeys: Array<string>\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n encryptedKeys: Array<string> = ['descr', 'note'],\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n this.encryptedKeys = encryptedKeys\n }\n\n newInstance(user: models.User, patient: models.Patient, h: any, confidential = false, delegates: string[] = []) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n const helement = _.assign(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.HealthElement',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: dataOwnerId,\n author: user.id,\n codes: [],\n tags: [],\n healthElementId: this.crypto.randomUuid(),\n openingDate: parseInt(moment().format('YYYYMMDDHHmmss')),\n },\n h || {}\n )\n\n return this.initDelegationsAndEncryptionKeys(helement, patient, user, confidential, delegates)\n }\n\n initDelegationsAndEncryptionKeys(\n healthElement: models.HealthElement,\n patient: models.Patient,\n user: models.User,\n confidential: boolean,\n delegates: string[] = []\n ): Promise<models.HealthElement> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto.extractPreferredSfk(patient, dataOwnerId!, confidential).then(async (key) => {\n if (!key) {\n console.error(`SFK cannot be found for Health element ${key}. The healthElement will not be reachable from the patient side`)\n }\n const dels = await this.crypto.initObjectDelegations(healthElement, patient, dataOwnerId!, key ?? null)\n const eks = await this.crypto.initEncryptionKeys(healthElement, dataOwnerId!)\n _.extend(healthElement, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(healthElement)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((healthElement) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, healthElement, dataOwnerId!, delegateId, dels.secretId, eks.secretId).catch((e) => {\n console.log(e)\n return healthElement\n })\n ))\n )\n ;(user.autoDelegations && user.autoDelegations.anonymousMedicalInformation ? user.autoDelegations.anonymousMedicalInformation : []).forEach(\n (delegateId) =>\n (promise = promise.then((healthElement) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, healthElement, dataOwnerId!, delegateId, null, eks.secretId).catch((e) => {\n console.log(e)\n return healthElement\n })\n ))\n )\n return promise\n })\n }\n\n createHealthElement(body?: models.HealthElement): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n createHealthElementWithUser(user: models.User, body?: models.HealthElement): Promise<models.HealthElement | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((hes) => super.createHealthElement(hes[0]))\n .then((he) => this.decryptWithUser(user, [he]))\n .then((hes) => hes[0])\n : Promise.resolve(null)\n }\n\n createHealthElements(body?: Array<HealthElement>): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n createHealthElementsWithUser(user: models.User, bodies?: models.HealthElement[]): Promise<models.HealthElement[] | any> {\n return bodies\n ? this.encrypt(\n user,\n bodies.map((c) => _.cloneDeep(c))\n )\n .then((hes) => super.createHealthElements(hes))\n .then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), hes))\n : Promise.resolve(null)\n }\n\n getHealthElement(healthElementId: string): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n getHealthElementWithUser(user: models.User, healthElementId: string): Promise<models.HealthElement> {\n return super\n .getHealthElement(healthElementId)\n .then((he) => this.decryptWithUser(user, [he]))\n .then((hes) => hes[0])\n }\n\n getHealthElements(body?: models.ListOfIds): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n getHealthElementsWithUser(user: models.User, body?: models.ListOfIds): Promise<models.HealthElement[]> {\n return super.getHealthElements(body).then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), hes))\n }\n\n newHealthElementDelegations(healthElementId: string, body?: Array<models.Delegation>): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n newHealthElementDelegationsWithUser(user: models.User, healthElementId: string, body?: Array<models.Delegation>): Promise<models.HealthElement> {\n return super\n .newHealthElementDelegations(healthElementId, body)\n .then((he) => this.decryptWithUser(user, [he]))\n .then((he) => he[0])\n }\n\n findHealthElementsByHCPartyPatientForeignKeys(hcPartyId: string, secretFKeys: string): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n findHealthElementsByHCPartyPatientForeignKeysWithUser(user: models.User, hcPartyId: string, secretFKeys: string): Promise<HealthElement[]> {\n return super.findHealthElementsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((hes) => this.decryptWithUser(user, hes))\n }\n\n findHealthElementsByHCPartyAndPatientWithUser(user: models.User, hcPartyId: string, patient: models.Patient): Promise<models.HealthElement[]> {\n return this.crypto.extractSFKsHierarchyFromDelegations(patient, hcPartyId).then((keysAndHcPartyId) => {\n const keys = keysAndHcPartyId.find((secretForeignKeys) => secretForeignKeys.hcpartyId == hcPartyId)?.extractedKeys\n\n if (keys == undefined) {\n throw Error('No delegation for user')\n }\n\n return this.findHealthElementsByHCPartyPatientForeignKeysWithUser(user, hcPartyId, keys.join(','))\n })\n }\n\n modifyHealthElement(body?: HealthElement): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n modifyHealthElementWithUser(user: models.User, body?: HealthElement): Promise<HealthElement | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((hes) => super.modifyHealthElement(hes[0]))\n .then((he) => this.decryptWithUser(user, [he]))\n .then((hes) => hes[0])\n : Promise.resolve(null)\n }\n\n modifyHealthElements(body?: Array<HealthElement>): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n modifyHealthElementsWithUser(user: models.User, bodies?: HealthElement[]): Promise<HealthElement[] | any> {\n return bodies\n ? this.encrypt(\n user,\n bodies.map((c) => _.cloneDeep(c))\n )\n .then((hes) => super.modifyHealthElements(hes))\n .then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), hes))\n : Promise.resolve(null)\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all helements with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the helements of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n * @param keepObsoleteVersions\n */\n\n findBy(hcpartyId: string, patient: models.Patient, keepObsoleteVersions = false) {\n return this.crypto\n .extractSFKsHierarchyFromDelegations(patient, hcpartyId)\n .then((secretForeignKeys) =>\n secretForeignKeys && secretForeignKeys.length > 0\n ? Promise.all(\n secretForeignKeys\n .reduce((acc, level) => {\n return acc.concat([\n {\n hcpartyId: level.hcpartyId,\n extractedKeys: level.extractedKeys.filter((key) => !acc.some((previousLevel) => previousLevel.extractedKeys.includes(key))),\n },\n ])\n }, [] as Array<{ hcpartyId: string; extractedKeys: Array<string> }>)\n .filter((l) => l.extractedKeys.length > 0)\n .map(({ hcpartyId, extractedKeys }) => this.findByHCPartyPatientSecretFKeys(hcpartyId, _.uniq(extractedKeys).join(',')))\n ).then((results) => _.uniqBy(_.flatMap(results), (x) => x.id))\n : Promise.resolve([])\n )\n .then((decryptedHelements: Array<models.HealthElement>) => {\n const byIds: { [key: string]: models.HealthElement } = {}\n\n if (keepObsoleteVersions) {\n return decryptedHelements\n } else {\n decryptedHelements.forEach((he) => {\n if (he.healthElementId) {\n const phe = byIds[he.healthElementId]\n if (!phe || !phe.modified || (he.modified && phe.modified < he.modified)) {\n byIds[he.healthElementId] = he\n }\n }\n })\n return _.values(byIds).filter((s: any) => !s.endOfLife)\n }\n })\n }\n\n findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.Contact> | any> {\n return super.findHealthElementsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((helements) => this.decrypt(hcPartyId, helements))\n }\n\n encrypt(user: models.User, healthElements: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return Promise.all(\n healthElements.map((he) =>\n (he.encryptionKeys && Object.keys(he.encryptionKeys).some((k) => !!he.encryptionKeys![k].length)\n ? Promise.resolve(he)\n : this.initEncryptionKeys(user, he)\n )\n .then((healthElement: HealthElement) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, healthElement.id!, healthElement.encryptionKeys!)\n )\n .then((sfks: { extractedKeys: Array<string>; hcpartyId: string }) =>\n this.crypto.AES.importKey('raw', hex2ua(sfks.extractedKeys[0].replace(/-/g, '')))\n )\n .then((key: CryptoKey) =>\n crypt(\n he,\n (obj: { [key: string]: string }) =>\n this.crypto.AES.encrypt(\n key,\n utf8_2ua(\n JSON.stringify(obj, (k, v) => {\n return v instanceof ArrayBuffer || v instanceof Uint8Array\n ? b2a(new Uint8Array(v).reduce((d, b) => d + String.fromCharCode(b), ''))\n : v\n })\n )\n ),\n this.encryptedKeys\n )\n )\n )\n )\n }\n\n initEncryptionKeys(user: models.User, he: models.HealthElement): Promise<models.HealthElement> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto.initEncryptionKeys(he, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(he, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((healthElement) =>\n this.crypto\n .appendEncryptionKeys(healthElement, dataOwnerId!, delegateId, eks.secretId)\n .then((extraEks) => {\n return _.extend(extraEks.modifiedObject, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n .catch((e) => {\n console.log(e.message)\n return healthElement\n })\n ))\n )\n return promise\n })\n }\n\n decryptWithUser(user: models.User, hes: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n return this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), hes)\n }\n\n decrypt(dataOwnerId: string, hes: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n return Promise.all(\n hes.map((he) =>\n this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, he.id!, _.size(he.encryptionKeys) ? he.encryptionKeys! : he.delegations!)\n .then(({ extractedKeys: sfks }) => {\n if (!sfks || !sfks.length) {\n console.log('Cannot decrypt helement', he.id)\n return Promise.resolve(he)\n }\n if (he.encryptedSelf) {\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0].replace(/-/g, ''))).then(\n (key) =>\n new Promise((resolve: (value: any) => any) =>\n this.crypto.AES.decrypt(key, string2ua(a2b(he.encryptedSelf!))).then(\n (dec) => {\n let jsonContent\n try {\n jsonContent = dec && ua2utf8(dec)\n jsonContent && _.assign(he, JSON.parse(jsonContent))\n } catch (e) {\n console.log('Cannot parse he', he.id, jsonContent || '<- Invalid encoding')\n }\n resolve(he)\n },\n () => {\n console.log('Cannot decrypt health element', he.id)\n resolve(he)\n }\n )\n )\n )\n } else {\n return Promise.resolve(he)\n }\n })\n )\n )\n }\n\n // noinspection JSUnusedGlobalSymbols\n serviceToHealthElement(user: models.User, patient: models.Patient, heSvc: models.Service, descr: string) {\n return this.newInstance(user, patient, {\n idService: heSvc.id,\n author: heSvc.author,\n responsible: heSvc.responsible,\n openingDate: heSvc.valueDate || heSvc.openingDate,\n descr: descr,\n idOpeningContact: heSvc.contactId,\n modified: heSvc.modified,\n created: heSvc.created,\n codes: heSvc.codes,\n tags: heSvc.tags,\n }).then((he) => {\n return this.createHealthElement(he)\n })\n }\n\n // noinspection JSUnusedGlobalSymbols, JSMethodCanBeStatic\n stringToCode(code: string) {\n const c = code.split('|')\n return new models.Code({\n type: c[0],\n code: c[1],\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,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE;YACb,OAAO,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAA;QACrC,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,0DAA0D;IAC1D,YAAY,CAAC,IAAY;QACvB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACzB,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC;YACrB,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YACV,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YACV,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;YACb,EAAE,EAAE,IAAI;SACT,CAAC,CAAA;IACJ,CAAC;CACF;AAnbD,0CAmbC","sourcesContent":["import { IccHelementApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as models from '../icc-api/model/models'\n\nimport * as _ from 'lodash'\nimport * as moment from 'moment'\nimport { a2b, b2a, hex2ua, string2ua, ua2utf8, utf8_2ua } from './utils/binary-utils'\nimport { FilterChainHealthElement, HealthElement, PaginatedListHealthElement } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { crypt } from './utils'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\nexport class IccHelementXApi extends IccHelementApi {\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n\n private readonly encryptedKeys: Array<string>\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n encryptedKeys: Array<string> = ['descr', 'note'],\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n this.encryptedKeys = encryptedKeys\n }\n\n newInstance(user: models.User, patient: models.Patient, h: any, confidential = false, delegates: string[] = []) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n const helement = _.assign(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.HealthElement',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: dataOwnerId,\n author: user.id,\n codes: [],\n tags: [],\n healthElementId: this.crypto.randomUuid(),\n openingDate: parseInt(moment().format('YYYYMMDDHHmmss')),\n },\n h || {}\n )\n\n return this.initDelegationsAndEncryptionKeys(helement, patient, user, confidential, delegates)\n }\n\n initDelegationsAndEncryptionKeys(\n healthElement: models.HealthElement,\n patient: models.Patient,\n user: models.User,\n confidential: boolean,\n delegates: string[] = []\n ): Promise<models.HealthElement> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto.extractPreferredSfk(patient, dataOwnerId!, confidential).then(async (key) => {\n if (!key) {\n console.error(`SFK cannot be found for Health element ${key}. The healthElement will not be reachable from the patient side`)\n }\n const dels = await this.crypto.initObjectDelegations(healthElement, patient, dataOwnerId!, key ?? null)\n const eks = await this.crypto.initEncryptionKeys(healthElement, dataOwnerId!)\n _.extend(healthElement, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(healthElement)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((healthElement) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, healthElement, dataOwnerId!, delegateId, dels.secretId, eks.secretId).catch((e) => {\n console.log(e)\n return healthElement\n })\n ))\n )\n ;(user.autoDelegations && user.autoDelegations.anonymousMedicalInformation ? user.autoDelegations.anonymousMedicalInformation : []).forEach(\n (delegateId) =>\n (promise = promise.then((healthElement) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, healthElement, dataOwnerId!, delegateId, null, eks.secretId).catch((e) => {\n console.log(e)\n return healthElement\n })\n ))\n )\n return promise\n })\n }\n\n createHealthElement(body?: models.HealthElement): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n createHealthElementWithUser(user: models.User, body?: models.HealthElement): Promise<models.HealthElement | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((hes) => super.createHealthElement(hes[0]))\n .then((he) => this.decryptWithUser(user, [he]))\n .then((hes) => hes[0])\n : Promise.resolve(null)\n }\n\n createHealthElements(body?: Array<HealthElement>): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n createHealthElementsWithUser(user: models.User, bodies?: models.HealthElement[]): Promise<models.HealthElement[] | any> {\n return bodies\n ? this.encrypt(\n user,\n bodies.map((c) => _.cloneDeep(c))\n )\n .then((hes) => super.createHealthElements(hes))\n .then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), hes))\n : Promise.resolve(null)\n }\n\n getHealthElement(healthElementId: string): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n getHealthElementWithUser(user: models.User, healthElementId: string): Promise<models.HealthElement> {\n return super\n .getHealthElement(healthElementId)\n .then((he) => this.decryptWithUser(user, [he]))\n .then((hes) => hes[0])\n }\n\n getHealthElements(body?: models.ListOfIds): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n getHealthElementsWithUser(user: models.User, body?: models.ListOfIds): Promise<models.HealthElement[]> {\n return super.getHealthElements(body).then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), hes))\n }\n\n newHealthElementDelegations(healthElementId: string, body?: Array<models.Delegation>): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n newHealthElementDelegationsWithUser(user: models.User, healthElementId: string, body?: Array<models.Delegation>): Promise<models.HealthElement> {\n return super\n .newHealthElementDelegations(healthElementId, body)\n .then((he) => this.decryptWithUser(user, [he]))\n .then((he) => he[0])\n }\n\n findHealthElementsByHCPartyPatientForeignKeys(hcPartyId: string, secretFKeys: string): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n findHealthElementsByHCPartyPatientForeignKeysWithUser(user: models.User, hcPartyId: string, secretFKeys: string): Promise<HealthElement[]> {\n return super.findHealthElementsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((hes) => this.decryptWithUser(user, hes))\n }\n\n findHealthElementsByHCPartyPatientForeignKeysArrayWithUser(user: models.User, hcPartyId: string, secretFKeys: string[]): Promise<HealthElement[]> {\n return super.findHealthElementsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys).then((hes) => this.decryptWithUser(user, hes))\n }\n\n findHealthElementsByHCPartyAndPatientWithUser(\n user: models.User,\n hcPartyId: string,\n patient: models.Patient,\n usingPost: boolean = false\n ): Promise<models.HealthElement[]> {\n return this.crypto.extractSFKsHierarchyFromDelegations(patient, hcPartyId).then((keysAndHcPartyId) => {\n const keys = keysAndHcPartyId.find((secretForeignKeys) => secretForeignKeys.hcpartyId == hcPartyId)?.extractedKeys\n\n if (keys == undefined) {\n throw Error('No delegation for user')\n }\n\n return usingPost\n ? this.findHealthElementsByHCPartyPatientForeignKeysArrayWithUser(user, hcPartyId, keys)\n : this.findHealthElementsByHCPartyPatientForeignKeysWithUser(user, hcPartyId, keys.join(','))\n })\n }\n\n modifyHealthElement(body?: HealthElement): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n modifyHealthElementWithUser(user: models.User, body?: HealthElement): Promise<HealthElement | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((hes) => super.modifyHealthElement(hes[0]))\n .then((he) => this.decryptWithUser(user, [he]))\n .then((hes) => hes[0])\n : Promise.resolve(null)\n }\n\n modifyHealthElements(body?: Array<HealthElement>): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n modifyHealthElementsWithUser(user: models.User, bodies?: HealthElement[]): Promise<HealthElement[] | any> {\n return bodies\n ? this.encrypt(\n user,\n bodies.map((c) => _.cloneDeep(c))\n )\n .then((hes) => super.modifyHealthElements(hes))\n .then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), hes))\n : Promise.resolve(null)\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all helements with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the helements of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n * @param keepObsoleteVersions\n * @param usingPost\n */\n\n findBy(hcpartyId: string, patient: models.Patient, keepObsoleteVersions = false, usingPost = false) {\n return this.crypto\n .extractSFKsHierarchyFromDelegations(patient, hcpartyId)\n .then((secretForeignKeys) =>\n secretForeignKeys && secretForeignKeys.length > 0\n ? Promise.all(\n secretForeignKeys\n .reduce((acc, level) => {\n return acc.concat([\n {\n hcpartyId: level.hcpartyId,\n extractedKeys: level.extractedKeys.filter((key) => !acc.some((previousLevel) => previousLevel.extractedKeys.includes(key))),\n },\n ])\n }, [] as Array<{ hcpartyId: string; extractedKeys: Array<string> }>)\n .filter((l) => l.extractedKeys.length > 0)\n .map(({ hcpartyId, extractedKeys }) =>\n usingPost\n ? this.findByHCPartyPatientSecretFKeysArray(hcpartyId, _.uniq(extractedKeys))\n : this.findByHCPartyPatientSecretFKeys(hcpartyId, _.uniq(extractedKeys).join(','))\n )\n ).then((results) => _.uniqBy(_.flatMap(results), (x) => x.id))\n : Promise.resolve([])\n )\n .then((decryptedHelements: Array<models.HealthElement>) => {\n const byIds: { [key: string]: models.HealthElement } = {}\n\n if (keepObsoleteVersions) {\n return decryptedHelements\n } else {\n decryptedHelements.forEach((he) => {\n if (he.healthElementId) {\n const phe = byIds[he.healthElementId]\n if (!phe || !phe.modified || (he.modified && phe.modified < he.modified)) {\n byIds[he.healthElementId] = he\n }\n }\n })\n return _.values(byIds).filter((s: any) => !s.endOfLife)\n }\n })\n }\n\n findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.Contact> | any> {\n return super.findHealthElementsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((helements) => this.decrypt(hcPartyId, helements))\n }\n\n findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<models.Contact> | any> {\n return super\n .findHealthElementsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys)\n .then((helements) => this.decrypt(hcPartyId, helements))\n }\n\n encrypt(user: models.User, healthElements: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return Promise.all(\n healthElements.map((he) =>\n (he.encryptionKeys && Object.keys(he.encryptionKeys).some((k) => !!he.encryptionKeys![k].length)\n ? Promise.resolve(he)\n : this.initEncryptionKeys(user, he)\n )\n .then((healthElement: HealthElement) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, healthElement.id!, healthElement.encryptionKeys!)\n )\n .then((sfks: { extractedKeys: Array<string>; hcpartyId: string }) => {\n const keys = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(sfks.extractedKeys)\n if (!keys.length) throw new Error('No valid keys found for calendar item encryption')\n return this.crypto.AES.importKey('raw', hex2ua(keys[0]))\n })\n .then((key: CryptoKey) =>\n crypt(\n he,\n (obj: { [key: string]: string }) =>\n this.crypto.AES.encrypt(\n key,\n utf8_2ua(\n JSON.stringify(obj, (k, v) => {\n return v instanceof ArrayBuffer || v instanceof Uint8Array\n ? b2a(new Uint8Array(v).reduce((d, b) => d + String.fromCharCode(b), ''))\n : v\n })\n )\n ),\n this.encryptedKeys\n )\n )\n )\n )\n }\n\n initEncryptionKeys(user: models.User, he: models.HealthElement): Promise<models.HealthElement> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto.initEncryptionKeys(he, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(he, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((healthElement) =>\n this.crypto\n .appendEncryptionKeys(healthElement, dataOwnerId!, delegateId, eks.secretId)\n .then((extraEks) => {\n return _.extend(extraEks.modifiedObject, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n .catch((e) => {\n console.log(e.message)\n return healthElement\n })\n ))\n )\n return promise\n })\n }\n\n decryptWithUser(user: models.User, hes: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n return this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), hes)\n }\n\n decrypt(dataOwnerId: string, hes: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n return Promise.all(\n hes.map((he) =>\n this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, he.id!, _.size(he.encryptionKeys) ? he.encryptionKeys! : he.delegations!)\n .then(({ extractedKeys: sfks }) => {\n sfks = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(sfks)\n if (!sfks || !sfks.length) {\n console.log('Cannot decrypt helement', he.id)\n return Promise.resolve(he)\n }\n if (he.encryptedSelf) {\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0])).then(\n (key) =>\n new Promise((resolve: (value: any) => any) =>\n this.crypto.AES.decrypt(key, string2ua(a2b(he.encryptedSelf!))).then(\n (dec) => {\n let jsonContent\n try {\n jsonContent = dec && ua2utf8(dec)\n jsonContent && _.assign(he, JSON.parse(jsonContent))\n } catch (e) {\n console.log('Cannot parse he', he.id, jsonContent || '<- Invalid encoding')\n }\n resolve(he)\n },\n () => {\n console.log('Cannot decrypt health element', he.id)\n resolve(he)\n }\n )\n )\n )\n } else {\n return Promise.resolve(he)\n }\n })\n )\n )\n }\n\n filterHealthElementsBy(startDocumentId?: string, limit?: number, body?: FilterChainHealthElement): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n filterByWithUser(\n user: models.User,\n startDocumentId?: string,\n limit?: number,\n body?: FilterChainHealthElement\n ): Promise<PaginatedListHealthElement> {\n return super\n .filterHealthElementsBy(startDocumentId, limit, body)\n .then((pl) => this.decryptWithUser(user, pl.rows!).then((dr) => Object.assign(pl, { rows: dr })))\n }\n\n // noinspection JSUnusedGlobalSymbols\n serviceToHealthElement(user: models.User, patient: models.Patient, heSvc: models.Service, descr: string) {\n return this.newInstance(user, patient, {\n idService: heSvc.id,\n author: heSvc.author,\n responsible: heSvc.responsible,\n openingDate: heSvc.valueDate || heSvc.openingDate,\n descr: descr,\n idOpeningContact: heSvc.contactId,\n modified: heSvc.modified,\n created: heSvc.created,\n codes: heSvc.codes,\n tags: heSvc.tags,\n }).then((he) => {\n return this.createHealthElement(he)\n })\n }\n\n // noinspection JSUnusedGlobalSymbols, JSMethodCanBeStatic\n stringToCode(code: string) {\n const c = code.split('|')\n return new models.Code({\n type: c[0],\n code: c[1],\n version: c[2],\n id: code,\n })\n }\n}\n"]}
|
|
@@ -33,8 +33,9 @@ export declare class IccInvoiceXApi extends IccInvoiceApi {
|
|
|
33
33
|
*
|
|
34
34
|
* @param hcpartyId
|
|
35
35
|
* @param patient (Promise)
|
|
36
|
+
* @param usingPost
|
|
36
37
|
*/
|
|
37
|
-
findBy(hcpartyId: string, patient: models.Patient): Promise<Array<models.Invoice>>;
|
|
38
|
+
findBy(hcpartyId: string, patient: models.Patient, usingPost?: boolean): Promise<Array<models.Invoice>>;
|
|
38
39
|
encrypt(user: models.User, invoices: Array<models.Invoice>): Promise<models.Invoice[]>;
|
|
39
40
|
decrypt(hcpartyId: string, invoices: Array<models.Invoice>): Promise<Array<models.Invoice>>;
|
|
40
41
|
}
|
|
@@ -126,11 +126,14 @@ class IccInvoiceXApi extends icc_api_1.IccInvoiceApi {
|
|
|
126
126
|
*
|
|
127
127
|
* @param hcpartyId
|
|
128
128
|
* @param patient (Promise)
|
|
129
|
+
* @param usingPost
|
|
129
130
|
*/
|
|
130
|
-
findBy(hcpartyId, patient) {
|
|
131
|
+
findBy(hcpartyId, patient, usingPost = false) {
|
|
131
132
|
return this.crypto
|
|
132
133
|
.extractDelegationsSFKs(patient, hcpartyId)
|
|
133
|
-
.then((secretForeignKeys) =>
|
|
134
|
+
.then((secretForeignKeys) => usingPost ?
|
|
135
|
+
this.findInvoicesByHCPartyPatientForeignKeysUsingPost(secretForeignKeys.hcpartyId, _.uniq(secretForeignKeys.extractedKeys)) :
|
|
136
|
+
this.findInvoicesByHCPartyPatientForeignKeys(secretForeignKeys.hcpartyId, _.uniq(secretForeignKeys.extractedKeys).join(',')))
|
|
134
137
|
.then((invoices) => this.decrypt(hcpartyId, invoices))
|
|
135
138
|
.then(function (decryptedInvoices) {
|
|
136
139
|
return decryptedInvoices;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-invoice-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-invoice-x-api.ts"],"names":[],"mappings":";;;AAAA,wCAA2D;AAG3D,4BAA2B;AAC3B,kDAAiD;AAGjD,0EAAgG;AAEhG,MAAa,cAAe,SAAQ,uBAAa;IAK/C,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA6B,EAC7B,YAA8B,EAC9B,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,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AC9H;aACA,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;aACrD,IAAI,CAAC,UAAU,iBAAiB;YAC/B,OAAO,iBAAiB,CAAA;QAC1B,CAAC,CAAC,CAAA;IACN,CAAC;IAED,OAAO,CAAC,IAAiB,EAAE,QAA+B;QACxD,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC;IAED,OAAO,CAAC,SAAiB,EAAE,QAA+B;QACxD,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC;CACF;AA7LD,wCA6LC","sourcesContent":["import { IccEntityrefApi, IccInvoiceApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { Invoice } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\nexport class IccInvoiceXApi extends IccInvoiceApi {\n crypto: IccCryptoXApi\n entityrefApi: IccEntityrefApi\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n entityrefApi: IccEntityrefApi,\n dataOwnerApi: IccDataOwnerXApi,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.entityrefApi = entityrefApi\n this.dataOwnerApi = dataOwnerApi\n }\n\n newInstance(user: models.User, patient: models.Patient, inv: any = {}, delegates: string[] = []): Promise<models.Invoice> {\n const invoice = new models.Invoice(\n _.extend(\n {\n id: this.crypto.randomUuid(),\n groupId: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.Invoice',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: this.dataOwnerApi.getDataOwnerOf(user),\n author: user.id,\n codes: [],\n tags: [],\n invoicingCodes: [],\n },\n inv || {}\n )\n )\n\n return this.initDelegationsAndEncryptionKeys(user, patient, invoice, delegates)\n }\n\n initEncryptionKeys(user: models.User, invoice: models.Invoice) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto.initEncryptionKeys(invoice, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(invoice, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.financialInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((invoice) =>\n this.crypto.appendEncryptionKeys(invoice, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(extraEks.modifiedObject, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n private initDelegationsAndEncryptionKeys(\n user: models.User,\n patient: models.Patient,\n invoice: models.Invoice,\n delegates: string[] = []\n ): Promise<models.Invoice> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto\n .extractDelegationsSFKs(patient, dataOwnerId)\n .then((secretForeignKeys) =>\n Promise.all([\n this.crypto.initObjectDelegations(invoice, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0]),\n this.crypto.initEncryptionKeys(invoice, dataOwnerId!),\n ])\n )\n .then((initData) => {\n const dels = initData[0]\n const eks = initData[1]\n _.extend(invoice, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(invoice)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.financialInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((invoice) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, invoice, dataOwnerId!, delegateId, dels.secretId, eks.secretId).catch((e) => {\n console.log(e)\n return invoice\n })\n ))\n )\n return promise\n })\n }\n\n createInvoice(invoice: Invoice, prefix?: string): Promise<Invoice> {\n if (!prefix) {\n return super.createInvoice(invoice)\n }\n if (!invoice.id) {\n invoice.id = this.crypto.randomUuid()\n }\n return this.getNextInvoiceReference(prefix, this.entityrefApi)\n .then((reference) => this.createInvoiceReference(reference, invoice.id!, prefix, this.entityrefApi))\n .then((entityReference) => {\n if (!entityReference.id) {\n throw new Error('Cannot create invoice')\n }\n\n if (invoice.internshipNihii) {\n const ref = entityReference.id.substr(prefix.length).replace('0', '1')\n invoice.invoiceReference = ref\n } else {\n invoice.invoiceReference = entityReference.id.substr(prefix.length)\n }\n return super.createInvoice(invoice)\n })\n }\n\n getNextInvoiceReference(prefix: string, entityrefApi: IccEntityrefApi): Promise<number> {\n return entityrefApi.getLatest(prefix).then((entRef: models.EntityReference) => {\n if (!entRef || !entRef.id || !entRef.id!.startsWith(prefix)) return 1\n const sequenceNumber = entRef.id!.split(':').pop() || 0\n return Number(sequenceNumber) + 1\n })\n }\n\n createInvoiceReference(nextReference: number, docId: string, prefix: string, entityrefApi: IccEntityrefApi): Promise<models.EntityReference> {\n return entityrefApi\n .createEntityReference(\n new models.EntityReference({\n id: prefix + nextReference.toString().padStart(6, '0'),\n docId,\n })\n )\n .catch((err) => {\n console.log(err)\n return this.createInvoiceReference(nextReference + 1, docId, prefix, entityrefApi)\n })\n }\n\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all invoices with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the invoices of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n */\n findBy(hcpartyId: string, patient: models.Patient): Promise<Array<models.Invoice>> {\n return this.crypto\n .extractDelegationsSFKs(patient, hcpartyId)\n .then((secretForeignKeys) =>\n this.findInvoicesByHCPartyPatientForeignKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(','))\n )\n .then((invoices) => this.decrypt(hcpartyId, invoices))\n .then(function (decryptedInvoices) {\n return decryptedInvoices\n })\n }\n\n encrypt(user: models.User, invoices: Array<models.Invoice>) {\n return Promise.resolve(invoices)\n }\n\n decrypt(hcpartyId: string, invoices: Array<models.Invoice>): Promise<Array<models.Invoice>> {\n return Promise.resolve(invoices)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"icc-invoice-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-invoice-x-api.ts"],"names":[],"mappings":";;;AAAA,wCAA2D;AAG3D,4BAA2B;AAC3B,kDAAiD;AAGjD,0EAAgG;AAEhG,MAAa,cAAe,SAAQ,uBAAa;IAK/C,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA6B,EAC7B,YAA8B,EAC9B,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;QACvD,IAAI,CAAC,MAAM,GAAG,MA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AAC;aACrD,IAAI,CAAC,UAAU,iBAAiB;YAC/B,OAAO,iBAAiB,CAAA;QAC1B,CAAC,CAAC,CAAA;IACN,CAAC;IAED,OAAO,CAAC,IAAiB,EAAE,QAA+B;QACxD,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC;IAED,OAAO,CAAC,SAAiB,EAAE,QAA+B;QACxD,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC;CACF;AAhMD,wCAgMC","sourcesContent":["import { IccEntityrefApi, IccInvoiceApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { Invoice } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\nexport class IccInvoiceXApi extends IccInvoiceApi {\n crypto: IccCryptoXApi\n entityrefApi: IccEntityrefApi\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n entityrefApi: IccEntityrefApi,\n dataOwnerApi: IccDataOwnerXApi,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.entityrefApi = entityrefApi\n this.dataOwnerApi = dataOwnerApi\n }\n\n newInstance(user: models.User, patient: models.Patient, inv: any = {}, delegates: string[] = []): Promise<models.Invoice> {\n const invoice = new models.Invoice(\n _.extend(\n {\n id: this.crypto.randomUuid(),\n groupId: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.Invoice',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: this.dataOwnerApi.getDataOwnerOf(user),\n author: user.id,\n codes: [],\n tags: [],\n invoicingCodes: [],\n },\n inv || {}\n )\n )\n\n return this.initDelegationsAndEncryptionKeys(user, patient, invoice, delegates)\n }\n\n initEncryptionKeys(user: models.User, invoice: models.Invoice) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto.initEncryptionKeys(invoice, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(invoice, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.financialInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((invoice) =>\n this.crypto.appendEncryptionKeys(invoice, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(extraEks.modifiedObject, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n private initDelegationsAndEncryptionKeys(\n user: models.User,\n patient: models.Patient,\n invoice: models.Invoice,\n delegates: string[] = []\n ): Promise<models.Invoice> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto\n .extractDelegationsSFKs(patient, dataOwnerId)\n .then((secretForeignKeys) =>\n Promise.all([\n this.crypto.initObjectDelegations(invoice, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0]),\n this.crypto.initEncryptionKeys(invoice, dataOwnerId!),\n ])\n )\n .then((initData) => {\n const dels = initData[0]\n const eks = initData[1]\n _.extend(invoice, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(invoice)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.financialInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((invoice) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, invoice, dataOwnerId!, delegateId, dels.secretId, eks.secretId).catch((e) => {\n console.log(e)\n return invoice\n })\n ))\n )\n return promise\n })\n }\n\n createInvoice(invoice: Invoice, prefix?: string): Promise<Invoice> {\n if (!prefix) {\n return super.createInvoice(invoice)\n }\n if (!invoice.id) {\n invoice.id = this.crypto.randomUuid()\n }\n return this.getNextInvoiceReference(prefix, this.entityrefApi)\n .then((reference) => this.createInvoiceReference(reference, invoice.id!, prefix, this.entityrefApi))\n .then((entityReference) => {\n if (!entityReference.id) {\n throw new Error('Cannot create invoice')\n }\n\n if (invoice.internshipNihii) {\n const ref = entityReference.id.substr(prefix.length).replace('0', '1')\n invoice.invoiceReference = ref\n } else {\n invoice.invoiceReference = entityReference.id.substr(prefix.length)\n }\n return super.createInvoice(invoice)\n })\n }\n\n getNextInvoiceReference(prefix: string, entityrefApi: IccEntityrefApi): Promise<number> {\n return entityrefApi.getLatest(prefix).then((entRef: models.EntityReference) => {\n if (!entRef || !entRef.id || !entRef.id!.startsWith(prefix)) return 1\n const sequenceNumber = entRef.id!.split(':').pop() || 0\n return Number(sequenceNumber) + 1\n })\n }\n\n createInvoiceReference(nextReference: number, docId: string, prefix: string, entityrefApi: IccEntityrefApi): Promise<models.EntityReference> {\n return entityrefApi\n .createEntityReference(\n new models.EntityReference({\n id: prefix + nextReference.toString().padStart(6, '0'),\n docId,\n })\n )\n .catch((err) => {\n console.log(err)\n return this.createInvoiceReference(nextReference + 1, docId, prefix, entityrefApi)\n })\n }\n\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all invoices with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the invoices of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n * @param usingPost\n */\n findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false): Promise<Array<models.Invoice>> {\n return this.crypto\n .extractDelegationsSFKs(patient, hcpartyId)\n .then((secretForeignKeys) =>\n usingPost ?\n this.findInvoicesByHCPartyPatientForeignKeysUsingPost(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys)) :\n this.findInvoicesByHCPartyPatientForeignKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(','))\n )\n .then((invoices) => this.decrypt(hcpartyId, invoices))\n .then(function (decryptedInvoices) {\n return decryptedInvoices\n })\n }\n\n encrypt(user: models.User, invoices: Array<models.Invoice>) {\n return Promise.resolve(invoices)\n }\n\n decrypt(hcpartyId: string, invoices: Array<models.Invoice>): Promise<Array<models.Invoice>> {\n return Promise.resolve(invoices)\n }\n}\n"]}
|
|
@@ -124,7 +124,12 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
|
|
|
124
124
|
? Promise.resolve(m)
|
|
125
125
|
: this.initEncryptionKeys(user, m))
|
|
126
126
|
.then((m) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, m.id, m.encryptionKeys))
|
|
127
|
-
.then((sfks) =>
|
|
127
|
+
.then((sfks) => {
|
|
128
|
+
const keys = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(sfks.extractedKeys);
|
|
129
|
+
if (!keys.length)
|
|
130
|
+
throw new Error('No valid keys found for calendar item encryption');
|
|
131
|
+
return this.crypto.AES.importKey('raw', (0, utils_1.hex2ua)(keys[0]));
|
|
132
|
+
})
|
|
128
133
|
.then((key) => (0, utils_1.crypt)(m, (obj) => this.crypto.AES.encrypt(key, (0, utils_1.utf8_2ua)(JSON.stringify(obj, (k, v) => {
|
|
129
134
|
return v instanceof ArrayBuffer || v instanceof Uint8Array
|
|
130
135
|
? (0, ModelHelper_1.b2a)(new Uint8Array(v).reduce((d, b) => d + String.fromCharCode(b), ''))
|
|
@@ -136,12 +141,13 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
|
|
|
136
141
|
return Promise.all(maintenanceTasks.map((mT) => {
|
|
137
142
|
var _a;
|
|
138
143
|
return this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, mT.id, (_a = mT.encryptionKeys) !== null && _a !== void 0 ? _a : {}).then(({ extractedKeys: sfks }) => {
|
|
144
|
+
sfks = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(sfks);
|
|
139
145
|
if (!sfks || !sfks.length) {
|
|
140
146
|
console.log('Cannot decrypt maintenanceTask', mT.id);
|
|
141
147
|
return Promise.resolve(mT);
|
|
142
148
|
}
|
|
143
149
|
if (mT.encryptedSelf) {
|
|
144
|
-
return this.crypto.AES.importKey('raw', (0, utils_1.hex2ua)(sfks[0]
|
|
150
|
+
return this.crypto.AES.importKey('raw', (0, utils_1.hex2ua)(sfks[0])).then((key) => new Promise((resolve) => this.crypto.AES.decrypt(key, (0, ModelHelper_1.string2ua)((0, ModelHelper_1.a2b)(mT.encryptedSelf))).then((dec) => {
|
|
145
151
|
let jsonContent;
|
|
146
152
|
try {
|
|
147
153
|
jsonContent = dec && (0, utils_1.ua2utf8)(dec);
|