@icure/api 8.0.63 → 8.0.64

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.
@@ -22,7 +22,7 @@ export declare class IccHcpartyXApi extends IccHcpartyApi {
22
22
  }, authenticationProvider: AuthenticationProvider | undefined, authApi: IccAuthApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
23
23
  private getHcPartyFromCache;
24
24
  completeNames(hcParty?: models.HealthcareParty): models.HealthcareParty | undefined;
25
- putHcPartyInCache(key: string, value?: Promise<HealthcareParty> | null): Promise<HealthcareParty>;
25
+ putHcPartyInCache(key: string, hcpPromise: Promise<HealthcareParty>): Promise<HealthcareParty>;
26
26
  createHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty>;
27
27
  createHealthcarePartyInGroup(groupId: string, body?: HealthcareParty): Promise<HealthcareParty>;
28
28
  modifyHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty | any>;
@@ -58,15 +58,9 @@ class IccHcpartyXApi extends icc_api_1.IccHcpartyApi {
58
58
  }
59
59
  return finalHcParty;
60
60
  }
61
- putHcPartyInCache(key, value = null) {
62
- const hcp = value ||
63
- super.getHealthcareParty(key).catch((e) => {
64
- console.log(`Evict key ${key} because of error`);
65
- delete this.hcPartyCache[key];
66
- throw e;
67
- });
68
- this.hcPartyCache[key] = [Date.now() + this.CACHE_RETENTION_IN_MS, hcp];
69
- return hcp;
61
+ putHcPartyInCache(key, hcpPromise) {
62
+ this.hcPartyCache[key] = [Date.now() + this.CACHE_RETENTION_IN_MS, hcpPromise];
63
+ return hcpPromise;
70
64
  }
71
65
  createHealthcareParty(body) {
72
66
  return super.createHealthcareParty(this.completeNames(body));
@@ -82,28 +76,71 @@ class IccHcpartyXApi extends icc_api_1.IccHcpartyApi {
82
76
  return super.modifyHealthcareParty(this.completeNames(body)).then((hcp) => this.putHcPartyInCache(hcp.id, Promise.resolve(hcp)));
83
77
  }
84
78
  getHealthcareParty(healthcarePartyId, bypassCache = false) {
85
- const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId);
86
- return fromCache || this.putHcPartyInCache(healthcarePartyId);
79
+ const _super = Object.create(null, {
80
+ getHealthcareParty: { get: () => super.getHealthcareParty }
81
+ });
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId);
84
+ if (fromCache) {
85
+ try {
86
+ return yield fromCache;
87
+ }
88
+ catch (_a) {
89
+ if (this.hcPartyCache[healthcarePartyId][1] === fromCache) {
90
+ delete this.hcPartyCache[healthcarePartyId];
91
+ }
92
+ return this.getHealthcareParty(healthcarePartyId, bypassCache);
93
+ }
94
+ }
95
+ else {
96
+ return yield this.putHcPartyInCache(healthcarePartyId, _super.getHealthcareParty.call(this, healthcarePartyId));
97
+ }
98
+ });
87
99
  }
88
100
  getHealthcarePartyHierarchyIds(healthcarePartyId, bypassCache = false) {
89
- const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId);
90
- return (fromCache || this.putHcPartyInCache(healthcarePartyId)).then((hcp) => __awaiter(this, void 0, void 0, function* () {
101
+ return this.getHealthcareParty(healthcarePartyId, bypassCache).then((hcp) => __awaiter(this, void 0, void 0, function* () {
91
102
  return hcp ? (hcp.parentId ? (yield this.getHealthcarePartyHierarchyIds(hcp.parentId, bypassCache)).concat([hcp.id]) : [hcp.id]) : [];
92
103
  }));
93
104
  }
94
105
  getHealthcareParties(healthcarePartyIds) {
95
- const ids = healthcarePartyIds.ids;
96
- if (!ids || !ids.length) {
97
- return Promise.resolve([]);
98
- }
99
- const cached = ids.map((id) => [id, this.getHcPartyFromCache(id)]);
100
- const toFetch = cached.filter((x) => !x[1]).map((x) => x[0]);
101
- if (!toFetch.length) {
102
- return Promise.all(cached.map((x) => x[1]));
103
- }
104
- const prom = super.getHealthcareParties(new models_1.ListOfIds({ ids: toFetch }));
105
- return Promise.all(cached.map((x) => x[1] ||
106
- this.putHcPartyInCache(x[0], prom.then((hcps) => hcps.find((h) => h.id === x[0])))));
106
+ const _super = Object.create(null, {
107
+ getHealthcareParties: { get: () => super.getHealthcareParties }
108
+ });
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ const ids = healthcarePartyIds.ids;
111
+ if (!ids || !ids.length) {
112
+ return Promise.resolve([]);
113
+ }
114
+ const cached = [];
115
+ for (const id of ids) {
116
+ let hcp;
117
+ try {
118
+ hcp = yield this.getHcPartyFromCache(id);
119
+ }
120
+ catch (_a) {
121
+ hcp = null;
122
+ delete this.hcPartyCache[id];
123
+ }
124
+ cached.push([id, hcp]);
125
+ }
126
+ const toFetch = cached.filter((x) => !x[1]).map((x) => x[0]);
127
+ if (!toFetch.length) {
128
+ return Promise.all(cached.map((x) => x[1]));
129
+ }
130
+ const prom = _super.getHealthcareParties.call(this, new models_1.ListOfIds({ ids: toFetch }));
131
+ return Promise.all(cached.map((x) => {
132
+ var _a;
133
+ return (_a = x[1]) !== null && _a !== void 0 ? _a : this.putHcPartyInCache(x[0], prom.then((hcps) => {
134
+ const hcp = hcps.find((h) => h.id === x[0]);
135
+ if (!!hcp) {
136
+ return hcp;
137
+ }
138
+ else {
139
+ throw new Error(`Hcp with id ${x[0]} not found`);
140
+ }
141
+ }));
142
+ }));
143
+ });
107
144
  }
108
145
  getCurrentHealthcareParty() {
109
146
  return super.getCurrentHealthcareParty().then((hcp) => this.putHcPartyInCache(hcp.id, Promise.resolve(hcp)));
@@ -1 +1 @@
1
- {"version":3,"file":"icc-hcparty-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-hcparty-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAsD;AAEtD,kDAAiD;AACjD,qDAA8E;AAC9E,0EAAgG;AAEhG,mCAAsE;AACtE,4DAAwE;AACxE,oDAAmD;AAEnD,qCAAqC;AACrC,MAAa,cAAe,SAAQ,uBAAa;IAK/C,YACE,IAAY,EACZ,OAAkC,EAClC,yBAAiD,IAAI,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C,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CACtH,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,2BAAc,CAAC,EAAE,CAAC,CAC/B,CAAA;QACH,CAAC;KAAA;CACF;AAtJD,wCAsJC","sourcesContent":["import { IccAuthApi, IccHcpartyApi } from '../icc-api'\nimport { HealthcareParty } from '../icc-api/model/HealthcareParty'\nimport * as models from '../icc-api/model/models'\nimport { findName, garnishPersonWithName, hasName } from './utils/person-util'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { AbstractFilter } from './filters/filters'\nimport { subscribeToEntityEvents, SubscriptionOptions } from './utils'\nimport { Connection, ConnectionImpl } from '../icc-api/model/Connection'\nimport { ListOfIds } from '../icc-api/model/models'\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccHcpartyXApi extends IccHcpartyApi {\n hcPartyKeysCache: { [key: string]: { [key: string]: string } } = {}\n hcPartyCache: { [key: string]: [number, Promise<HealthcareParty>] } = {}\n\n private CACHE_RETENTION_IN_MS = 300_000\n constructor(\n host: string,\n headers: { [key: string]: string },\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n private readonly authApi: IccAuthApi,\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 }\n\n private getHcPartyFromCache(key: string) {\n const hcpInCache = this.hcPartyCache[key]\n const now = Date.now()\n if (hcpInCache && hcpInCache[0] > now) {\n return hcpInCache[1]\n }\n if (!hcpInCache) {\n console.log(`Cache miss for key ${key} because not in cache`)\n } else {\n console.log(`Cache miss for key ${key} because ${hcpInCache[0]} > ${now}`)\n }\n return null\n }\n\n completeNames(hcParty?: models.HealthcareParty): models.HealthcareParty | undefined {\n if (!hcParty) {\n return hcParty\n }\n\n let finalHcParty = hcParty\n\n if ((!!finalHcParty.lastName || !!finalHcParty.name) && !hasName(finalHcParty, models.PersonName.UseEnum.Official)) {\n finalHcParty = garnishPersonWithName(\n finalHcParty,\n models.PersonName.UseEnum.Official,\n finalHcParty.lastName,\n finalHcParty.firstName,\n finalHcParty.name\n )\n }\n\n if ((!finalHcParty.lastName || !finalHcParty.name) && !!hasName(finalHcParty, models.PersonName.UseEnum.Official)) {\n let officialName = findName(finalHcParty, models.PersonName.UseEnum.Official)\n finalHcParty = {\n ...finalHcParty,\n lastName: officialName!.lastName,\n firstName: officialName!.firstNames ? officialName!.firstNames[0] : undefined,\n name: officialName!.text,\n }\n }\n\n return finalHcParty\n }\n\n putHcPartyInCache(key: string, value: Promise<HealthcareParty> | null = null): Promise<HealthcareParty> {\n const hcp =\n value ||\n super.getHealthcareParty(key).catch((e) => {\n console.log(`Evict key ${key} because of error`)\n delete this.hcPartyCache[key]\n throw e\n })\n this.hcPartyCache[key] = [Date.now() + this.CACHE_RETENTION_IN_MS, hcp]\n return hcp\n }\n\n createHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty> {\n return super.createHealthcareParty(this.completeNames(body))\n }\n\n createHealthcarePartyInGroup(groupId: string, body?: HealthcareParty): Promise<HealthcareParty> {\n return super.createHealthcarePartyInGroup(groupId, this.completeNames(body))\n }\n\n modifyHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty | any> {\n if (body && body.id) {\n console.log(`Evict key ${body.id} because of modification`)\n delete this.hcPartyCache[body.id]\n }\n\n return super.modifyHealthcareParty(this.completeNames(body)).then((hcp) => this.putHcPartyInCache(hcp.id!, Promise.resolve(hcp)))\n }\n\n getHealthcareParty(healthcarePartyId: string, bypassCache = false): Promise<HealthcareParty | any> {\n const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId)\n return fromCache || this.putHcPartyInCache(healthcarePartyId)\n }\n\n getHealthcarePartyHierarchyIds(healthcarePartyId: string, bypassCache = false): Promise<string[]> {\n const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId)\n return (fromCache || this.putHcPartyInCache(healthcarePartyId)).then(async (hcp: HealthcareParty) => {\n return hcp ? (hcp.parentId ? (await this.getHealthcarePartyHierarchyIds(hcp.parentId!, bypassCache)).concat([hcp.id!]) : [hcp.id!]) : []\n })\n }\n\n getHealthcareParties(healthcarePartyIds: ListOfIds): Promise<Array<HealthcareParty> | any> {\n const ids = healthcarePartyIds.ids\n if (!ids || !ids.length) {\n return Promise.resolve([])\n }\n const cached: Array<[string, Promise<HealthcareParty> | null]> = ids.map((id) => [id, this.getHcPartyFromCache(id)])\n const toFetch = cached.filter((x) => !x[1]).map((x) => x[0])\n\n if (!toFetch.length) {\n return Promise.all(cached.map((x) => x[1]!))\n }\n\n const prom: Promise<HealthcareParty[]> = super.getHealthcareParties(new ListOfIds({ ids: toFetch }))\n return Promise.all(\n cached.map(\n (x) =>\n x[1] ||\n this.putHcPartyInCache(\n x[0],\n prom.then((hcps) => hcps.find((h) => h.id === x[0])!)\n )\n )\n )\n }\n\n getCurrentHealthcareParty(): Promise<HealthcareParty> {\n return super.getCurrentHealthcareParty().then((hcp) => this.putHcPartyInCache(hcp.id!, Promise.resolve(hcp)))\n }\n\n isValidCbe(cbe: string) {\n cbe = cbe.replace(new RegExp('[^(0-9)]', 'g'), '')\n cbe = cbe.length == 9 ? '0' + cbe : cbe\n\n return 97 - (Number(cbe.substring(0, 8)) % 97) === Number(cbe.substring(8, 2))\n }\n\n async subscribeToHealthcarePartyEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<HealthcareParty> | undefined,\n eventFired: (dataSample: HealthcareParty) => Promise<void>,\n options: SubscriptionOptions = {}\n ): Promise<Connection> {\n return subscribeToEntityEvents(this.host, this.authApi, 'HealthcareParty', eventTypes, filter, eventFired, options).then(\n (rs) => new ConnectionImpl(rs)\n )\n }\n}\n"]}
1
+ {"version":3,"file":"icc-hcparty-x-api.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C,GAAG,CAAC,EAAG,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAC/G,CAAC;IAED,UAAU,CAAC,GAAW;QACpB,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAA;QAClD,GAAG,GAAG,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;QAEvC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAChF,CAAC;IAEK,gCAAgC,CACpC,UAA8C,EAC9C,MAAmD,EACnD,UAA0D,EAC1D,UAA+B,EAAE;;YAEjC,OAAO,IAAA,+BAAuB,EAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CACtH,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,2BAAc,CAAC,EAAE,CAAC,CAC/B,CAAA;QACH,CAAC;KAAA;CACF;AA1KD,wCA0KC","sourcesContent":["import { IccAuthApi, IccHcpartyApi } from '../icc-api'\nimport { HealthcareParty } from '../icc-api/model/HealthcareParty'\nimport * as models from '../icc-api/model/models'\nimport { findName, garnishPersonWithName, hasName } from './utils/person-util'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { AbstractFilter } from './filters/filters'\nimport { subscribeToEntityEvents, SubscriptionOptions } from './utils'\nimport { Connection, ConnectionImpl } from '../icc-api/model/Connection'\nimport { ListOfIds } from '../icc-api/model/models'\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccHcpartyXApi extends IccHcpartyApi {\n hcPartyKeysCache: { [key: string]: { [key: string]: string } } = {}\n hcPartyCache: { [key: string]: [number, Promise<HealthcareParty>] } = {}\n\n private CACHE_RETENTION_IN_MS = 300_000\n constructor(\n host: string,\n headers: { [key: string]: string },\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n private readonly authApi: IccAuthApi,\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 }\n\n private getHcPartyFromCache(key: string) {\n const hcpInCache = this.hcPartyCache[key]\n const now = Date.now()\n if (hcpInCache && hcpInCache[0] > now) {\n return hcpInCache[1]\n }\n if (!hcpInCache) {\n console.log(`Cache miss for key ${key} because not in cache`)\n } else {\n console.log(`Cache miss for key ${key} because ${hcpInCache[0]} > ${now}`)\n }\n return null\n }\n\n completeNames(hcParty?: models.HealthcareParty): models.HealthcareParty | undefined {\n if (!hcParty) {\n return hcParty\n }\n\n let finalHcParty = hcParty\n\n if ((!!finalHcParty.lastName || !!finalHcParty.name) && !hasName(finalHcParty, models.PersonName.UseEnum.Official)) {\n finalHcParty = garnishPersonWithName(\n finalHcParty,\n models.PersonName.UseEnum.Official,\n finalHcParty.lastName,\n finalHcParty.firstName,\n finalHcParty.name\n )\n }\n\n if ((!finalHcParty.lastName || !finalHcParty.name) && !!hasName(finalHcParty, models.PersonName.UseEnum.Official)) {\n let officialName = findName(finalHcParty, models.PersonName.UseEnum.Official)\n finalHcParty = {\n ...finalHcParty,\n lastName: officialName!.lastName,\n firstName: officialName!.firstNames ? officialName!.firstNames[0] : undefined,\n name: officialName!.text,\n }\n }\n\n return finalHcParty\n }\n\n putHcPartyInCache(key: string, hcpPromise: Promise<HealthcareParty>): Promise<HealthcareParty> {\n this.hcPartyCache[key] = [Date.now() + this.CACHE_RETENTION_IN_MS, hcpPromise]\n return hcpPromise\n }\n\n createHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty> {\n return super.createHealthcareParty(this.completeNames(body))\n }\n\n createHealthcarePartyInGroup(groupId: string, body?: HealthcareParty): Promise<HealthcareParty> {\n return super.createHealthcarePartyInGroup(groupId, this.completeNames(body))\n }\n\n modifyHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty | any> {\n if (body && body.id) {\n console.log(`Evict key ${body.id} because of modification`)\n delete this.hcPartyCache[body.id]\n }\n\n return super.modifyHealthcareParty(this.completeNames(body)).then((hcp) => this.putHcPartyInCache(hcp.id!, Promise.resolve(hcp)))\n }\n\n async getHealthcareParty(healthcarePartyId: string, bypassCache = false): Promise<HealthcareParty | any> {\n const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId)\n if (fromCache) {\n try {\n return await fromCache\n } catch {\n if (this.hcPartyCache[healthcarePartyId][1] === fromCache) {\n delete this.hcPartyCache[healthcarePartyId]\n }\n return this.getHealthcareParty(healthcarePartyId, bypassCache)\n }\n } else {\n return await this.putHcPartyInCache(healthcarePartyId, super.getHealthcareParty(healthcarePartyId))\n }\n }\n\n getHealthcarePartyHierarchyIds(healthcarePartyId: string, bypassCache = false): Promise<string[]> {\n return this.getHealthcareParty(healthcarePartyId, bypassCache).then(async (hcp: HealthcareParty) => {\n return hcp ? (hcp.parentId ? (await this.getHealthcarePartyHierarchyIds(hcp.parentId!, bypassCache)).concat([hcp.id!]) : [hcp.id!]) : []\n })\n }\n\n async getHealthcareParties(healthcarePartyIds: ListOfIds): Promise<Array<HealthcareParty> | any> {\n const ids = healthcarePartyIds.ids\n if (!ids || !ids.length) {\n return Promise.resolve([])\n }\n const cached: Array<[string, HealthcareParty | null]> = []\n for (const id of ids) {\n let hcp\n try {\n hcp = await this.getHcPartyFromCache(id)\n } catch {\n hcp = null\n delete this.hcPartyCache[id]\n }\n cached.push([id, hcp])\n }\n const toFetch = cached.filter((x) => !x[1]).map((x) => x[0])\n\n if (!toFetch.length) {\n return Promise.all(cached.map((x) => x[1]!))\n }\n\n const prom: Promise<HealthcareParty[]> = super.getHealthcareParties(new ListOfIds({ ids: toFetch }))\n return Promise.all(\n cached.map(\n (x) =>\n x[1] ??\n this.putHcPartyInCache(\n x[0],\n prom.then((hcps) => {\n const hcp = hcps.find((h) => h.id === x[0])\n if (!!hcp) {\n return hcp\n } else {\n throw new Error(`Hcp with id ${x[0]} not found`)\n }\n })\n )\n )\n )\n }\n\n getCurrentHealthcareParty(): Promise<HealthcareParty> {\n return super.getCurrentHealthcareParty().then((hcp) => this.putHcPartyInCache(hcp.id!, Promise.resolve(hcp)))\n }\n\n isValidCbe(cbe: string) {\n cbe = cbe.replace(new RegExp('[^(0-9)]', 'g'), '')\n cbe = cbe.length == 9 ? '0' + cbe : cbe\n\n return 97 - (Number(cbe.substring(0, 8)) % 97) === Number(cbe.substring(8, 2))\n }\n\n async subscribeToHealthcarePartyEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<HealthcareParty> | undefined,\n eventFired: (dataSample: HealthcareParty) => Promise<void>,\n options: SubscriptionOptions = {}\n ): Promise<Connection> {\n return subscribeToEntityEvents(this.host, this.authApi, 'HealthcareParty', eventTypes, filter, eventFired, options).then(\n (rs) => new ConnectionImpl(rs)\n )\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icure/api",
3
- "version": "8.0.63",
3
+ "version": "8.0.64",
4
4
  "description": "Typescript version of iCure standalone API client",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -0,0 +1 @@
1
+ import 'isomorphic-fetch';
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ require("isomorphic-fetch");
13
+ const mocha_1 = require("mocha");
14
+ const test_utils_1 = require("../utils/test_utils");
15
+ var initApi = test_utils_1.TestUtils.initApi;
16
+ const chai_1 = require("chai");
17
+ const types_1 = require("@icure/test-setup/types");
18
+ (0, test_utils_1.setLocalStorage)(fetch);
19
+ let env;
20
+ describe('icc-hcparty-x-api Tests', () => {
21
+ (0, mocha_1.before)(function () {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ this.timeout(600000);
24
+ const initializer = yield (0, test_utils_1.getEnvironmentInitializer)();
25
+ env = yield initializer.execute((0, types_1.getEnvVariables)());
26
+ });
27
+ });
28
+ it('Does not cache entities that are not HCPs', () => __awaiter(void 0, void 0, void 0, function* () {
29
+ // Given
30
+ const { userApi: userApi, healthcarePartyApi: hcpApi } = yield initApi(env, test_utils_1.hcp1Username);
31
+ const user = yield userApi.getCurrentUser();
32
+ let promiseResolves;
33
+ try {
34
+ yield hcpApi.getHealthcareParties({ ids: [user.id, user.healthcarePartyId] });
35
+ promiseResolves = true;
36
+ }
37
+ catch (_a) {
38
+ promiseResolves = false;
39
+ }
40
+ yield hcpApi.getHealthcareParties({ ids: [user.id, user.healthcarePartyId] }).then((_) => {
41
+ throw new Error('This promise should not resolve');
42
+ }, (e) => {
43
+ (0, chai_1.expect)(JSON.parse(e.message)['message']).to.be.equal(`Object with ID ${user.id} is not of expected type org.taktik.icure.entities.HealthcareParty but of type org.taktik.icure.entities.User`);
44
+ });
45
+ (0, chai_1.expect)(promiseResolves).to.be.false;
46
+ const hcp = yield hcpApi.getHealthcareParty(user.healthcarePartyId);
47
+ (0, chai_1.expect)(hcp.id).to.be.equal(user.healthcarePartyId);
48
+ yield hcpApi.getHealthcareParty(user.id).then((_) => {
49
+ throw new Error('This promise should not resolve');
50
+ }, (e) => {
51
+ (0, chai_1.expect)(JSON.parse(e.message)['message']).to.be.equal(`Object with ID ${user.id} is not of expected type org.taktik.icure.entities.HealthcareParty but of type org.taktik.icure.entities.User`);
52
+ });
53
+ }));
54
+ });
55
+ //# sourceMappingURL=icc-hcparty-x-api-test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icc-hcparty-x-api-test.js","sourceRoot":"","sources":["../../../test/icc-x-api/icc-hcparty-x-api-test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4BAAyB;AAEzB,iCAA8B;AAC9B,oDAAyG;AACzG,IAAO,OAAO,GAAG,sBAAS,CAAC,OAAO,CAAA;AAClC,+BAA6B;AAC7B,mDAAmE;AAEnE,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AACtB,IAAI,GAAa,CAAA;AAEjB,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,IAAA,cAAM,EAAC;;YACL,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;YACpB,MAAM,WAAW,GAAG,MAAM,IAAA,sCAAyB,GAAE,CAAA;YACrD,GAAG,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,IAAA,uBAAe,GAAE,CAAC,CAAA;QACpD,CAAC;KAAA,CAAC,CAAA;IAEF,EAAE,CAAC,2CAA2C,EAAE,GAAS,EAAE;QACzD,QAAQ;QACR,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,yBAAY,CAAC,CAAA;QAEzF,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE,CAAA;QAE3C,IAAI,eAAwB,CAAA;QAC5B,IAAI;YACF,MAAM,MAAM,CAAC,oBAAoB,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI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K,CAClD,kBAAkB,IAAI,CAAC,EAAG,+GAA+G,CAC1I,CAAA;QACH,CAAC,CACF,CAAA;IACH,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import 'isomorphic-fetch'\n\nimport { before } from 'mocha'\nimport { getEnvironmentInitializer, hcp1Username, setLocalStorage, TestUtils } from '../utils/test_utils'\nimport initApi = TestUtils.initApi\nimport { expect } from 'chai'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\n\nsetLocalStorage(fetch)\nlet env: TestVars\n\ndescribe('icc-hcparty-x-api Tests', () => {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n it('Does not cache entities that are not HCPs', async () => {\n // Given\n const { userApi: userApi, healthcarePartyApi: hcpApi } = await initApi(env, hcp1Username)\n\n const user = await userApi.getCurrentUser()\n\n let promiseResolves: boolean\n try {\n await hcpApi.getHealthcareParties({ ids: [user.id!, user.healthcarePartyId!] })\n promiseResolves = true\n } catch {\n promiseResolves = false\n }\n\n await hcpApi.getHealthcareParties({ ids: [user.id!, user.healthcarePartyId!] }).then(\n (_) => {\n throw new Error('This promise should not resolve')\n },\n (e) => {\n expect(JSON.parse(e.message)['message']).to.be.equal(\n `Object with ID ${user.id!} is not of expected type org.taktik.icure.entities.HealthcareParty but of type org.taktik.icure.entities.User`\n )\n }\n )\n expect(promiseResolves).to.be.false\n\n const hcp = await hcpApi.getHealthcareParty(user.healthcarePartyId!)\n expect(hcp.id).to.be.equal(user.healthcarePartyId!)\n\n await hcpApi.getHealthcareParty(user.id!).then(\n (_) => {\n throw new Error('This promise should not resolve')\n },\n (e) => {\n expect(JSON.parse(e.message)['message']).to.be.equal(\n `Object with ID ${user.id!} is not of expected type org.taktik.icure.entities.HealthcareParty but of type org.taktik.icure.entities.User`\n )\n }\n )\n })\n})\n"]}