@icure/api 5.3.0 → 5.3.2
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/IccCalendarItemApi.d.ts +20 -0
- package/icc-api/api/IccCalendarItemApi.js +49 -0
- package/icc-api/api/IccCalendarItemApi.js.map +1 -1
- package/icc-api/model/CalendarItem.d.ts +1 -0
- package/icc-api/model/CalendarItem.js.map +1 -1
- package/icc-api/model/PaginatedListCalendarItem.d.ts +20 -0
- package/icc-api/model/PaginatedListCalendarItem.js +10 -0
- package/icc-api/model/PaginatedListCalendarItem.js.map +1 -0
- package/icc-api/model/models.d.ts +1 -0
- package/icc-api/model/models.js +1 -0
- package/icc-api/model/models.js.map +1 -1
- package/icc-x-api/icc-calendar-item-x-api.d.ts +3 -1
- package/icc-x-api/icc-calendar-item-x-api.js +13 -1
- package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
- package/icc-x-api/icc-classification-x-api.js +14 -3
- package/icc-x-api/icc-classification-x-api.js.map +1 -1
- package/icc-x-api/icc-contact-x-api.js +1 -0
- package/icc-x-api/icc-contact-x-api.js.map +1 -1
- package/icc-x-api/icc-crypto-x-api.d.ts +39 -5
- package/icc-x-api/icc-crypto-x-api.js +36 -0
- package/icc-x-api/icc-crypto-x-api.js.map +1 -1
- package/icc-x-api/icc-document-x-api.js +14 -3
- package/icc-x-api/icc-document-x-api.js.map +1 -1
- package/icc-x-api/icc-helement-x-api.js +1 -0
- package/icc-x-api/icc-helement-x-api.js.map +1 -1
- package/icc-x-api/icc-invoice-x-api.js +14 -3
- package/icc-x-api/icc-invoice-x-api.js.map +1 -1
- package/icc-x-api/icc-message-x-api.js +14 -3
- package/icc-x-api/icc-message-x-api.js.map +1 -1
- package/icc-x-api/index.js +0 -42
- package/icc-x-api/index.js.map +1 -1
- package/icc-x-api/utils/error-reporting.d.ts +20 -0
- package/icc-x-api/utils/error-reporting.js +382 -0
- package/icc-x-api/utils/error-reporting.js.map +1 -0
- package/icc-x-api/utils/formatting-util.js +1 -1
- package/icc-x-api/utils/formatting-util.js.map +1 -1
- package/icc-x-api/utils/insurability-util.d.ts +1 -1
- package/icc-x-api/utils/insurability-util.js +1 -1
- package/icc-x-api/utils/insurability-util.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,382 @@
|
|
|
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
|
+
exports.ErrorReporting = void 0;
|
|
13
|
+
const binary_utils_1 = require("./binary-utils");
|
|
14
|
+
var Result;
|
|
15
|
+
(function (Result) {
|
|
16
|
+
class Success {
|
|
17
|
+
constructor(content) {
|
|
18
|
+
this.content = content;
|
|
19
|
+
}
|
|
20
|
+
map(f) {
|
|
21
|
+
return f(this.content).then((x) => new Success(x));
|
|
22
|
+
}
|
|
23
|
+
flatMap(f) {
|
|
24
|
+
return f(this.content);
|
|
25
|
+
}
|
|
26
|
+
mapErrorMsg(f) {
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
pojo() {
|
|
30
|
+
return this.content;
|
|
31
|
+
}
|
|
32
|
+
getOrElse(defaultValue) {
|
|
33
|
+
return this.content;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
Result.Success = Success;
|
|
37
|
+
class Failure {
|
|
38
|
+
constructor(failedOperation, errorMsg) {
|
|
39
|
+
this.failedOperation = failedOperation;
|
|
40
|
+
this.errorMsg = errorMsg;
|
|
41
|
+
}
|
|
42
|
+
map() {
|
|
43
|
+
return Promise.resolve(this);
|
|
44
|
+
}
|
|
45
|
+
flatMap() {
|
|
46
|
+
return Promise.resolve(this);
|
|
47
|
+
}
|
|
48
|
+
mapErrorMsg(f) {
|
|
49
|
+
return new Failure(this.failedOperation, f(this.errorMsg));
|
|
50
|
+
}
|
|
51
|
+
pojo() {
|
|
52
|
+
return { failedOperation: this.failedOperation, errorMsg: this.errorMsg };
|
|
53
|
+
}
|
|
54
|
+
getOrElse(defaultValue) {
|
|
55
|
+
return defaultValue();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
Result.Failure = Failure;
|
|
59
|
+
function wrap(operation, f) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
try {
|
|
62
|
+
return new Success(yield f());
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
const errorMsg = e instanceof Error ? e.message : typeof e === 'string' ? e : `Unexpected of type ${typeof e} content ${JSON.stringify(e)}`;
|
|
66
|
+
return new Failure(operation, errorMsg);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
Result.wrap = wrap;
|
|
71
|
+
})(Result || (Result = {}));
|
|
72
|
+
class ErrorReporting {
|
|
73
|
+
constructor(crypto) {
|
|
74
|
+
this.crypto = crypto;
|
|
75
|
+
}
|
|
76
|
+
collectDataForReport(description, // Description of what caused the error
|
|
77
|
+
involvedEntities, // Entities that were being processed when the error occurred
|
|
78
|
+
dataOwnerId // Id of the data owner who was doing the processing when the error occurred
|
|
79
|
+
) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const fullData = yield this.collectFullData(description, involvedEntities, dataOwnerId);
|
|
82
|
+
return {
|
|
83
|
+
fullData: yield new FullDataExporter(this.crypto).exportDataToPojo(fullData),
|
|
84
|
+
minimalData: yield new MinimalDataExporter(this.crypto).exportDataToPojo(fullData),
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
collectFullData(description, involvedEntities, dataOwnerId) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const hierarchy = yield this.collectDataOwnerHierarchy(dataOwnerId);
|
|
91
|
+
const availableKeypairsPublic = yield this.collectAvailableKeypairsPublic();
|
|
92
|
+
const byDataOwner = yield hierarchy.map((hierarchy) => __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const res = {};
|
|
94
|
+
for (const currOwner of hierarchy) {
|
|
95
|
+
const delegators = yield this.getDelegators(involvedEntities, currOwner.dataOwner.id);
|
|
96
|
+
const encryptedExchangeKeys = yield this.findEncryptedExchangeKeys(currOwner.dataOwner.id);
|
|
97
|
+
const decryptedExchangeKeys = yield delegators.flatMap((delegators) => __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
return this.decryptExchangeKeys(currOwner.dataOwner.id, delegators.map((x) => x.dataOwner.id));
|
|
99
|
+
}));
|
|
100
|
+
const decryptedEntitiesMetadata = yield decryptedExchangeKeys.flatMap((xks) => __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
return yield this.decryptDelegations(xks, involvedEntities, currOwner.dataOwner.id);
|
|
102
|
+
}));
|
|
103
|
+
res[currOwner.dataOwner.id] = {
|
|
104
|
+
delegators,
|
|
105
|
+
encryptedExchangeKeys,
|
|
106
|
+
decryptedExchangeKeys,
|
|
107
|
+
decryptedEntitiesMetadata,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return res;
|
|
111
|
+
}));
|
|
112
|
+
return {
|
|
113
|
+
description,
|
|
114
|
+
involvedEntities,
|
|
115
|
+
hierarchy,
|
|
116
|
+
availableKeypairsPublic,
|
|
117
|
+
byDataOwner,
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
// res[0] -> self, res[1] -> self.parent, ...
|
|
122
|
+
collectDataOwnerHierarchy(startOwnerId) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
return Result.wrap('collectDataOwnerHierarchy', () => __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const res = [];
|
|
126
|
+
res.push(yield this.crypto.getDataOwner(startOwnerId, true));
|
|
127
|
+
while (!!res[res.length - 1].dataOwner.parentId) {
|
|
128
|
+
res.push(yield this.crypto.getDataOwner(res[res.length - 1].dataOwner.parentId, true));
|
|
129
|
+
}
|
|
130
|
+
return res;
|
|
131
|
+
}));
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
collectAvailableKeypairsPublic() {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
return Result.wrap('collectAvailableKeypairsPublic', () => __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
const res = {};
|
|
138
|
+
for (const [fp, pair] of Object.entries(this.crypto.rsaKeyPairs)) {
|
|
139
|
+
res[fp] = (0, binary_utils_1.ua2hex)(yield this.crypto.RSA.exportKey(pair.publicKey, 'spki'));
|
|
140
|
+
}
|
|
141
|
+
return res;
|
|
142
|
+
}));
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
getDelegators(entities, hierarchyMemberId) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
return Result.wrap('getDelegators', () => __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
const allDelegationLikes = entities.flatMap((e) => {
|
|
149
|
+
var _a, _b, _c, _d, _e, _f;
|
|
150
|
+
return [
|
|
151
|
+
...((_b = (_a = e.delegations) === null || _a === void 0 ? void 0 : _a[hierarchyMemberId]) !== null && _b !== void 0 ? _b : []),
|
|
152
|
+
...((_d = (_c = e.encryptionKeys) === null || _c === void 0 ? void 0 : _c[hierarchyMemberId]) !== null && _d !== void 0 ? _d : []),
|
|
153
|
+
...((_f = (_e = e.cryptedForeignKeys) === null || _e === void 0 ? void 0 : _e[hierarchyMemberId]) !== null && _f !== void 0 ? _f : []),
|
|
154
|
+
];
|
|
155
|
+
});
|
|
156
|
+
const ownerIds = new Set(allDelegationLikes.map((d) => d.owner));
|
|
157
|
+
const res = [];
|
|
158
|
+
for (const ownerId of ownerIds) {
|
|
159
|
+
if (!!ownerId)
|
|
160
|
+
res.push(yield this.crypto.getDataOwner(ownerId, true));
|
|
161
|
+
}
|
|
162
|
+
return res;
|
|
163
|
+
}));
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
findEncryptedExchangeKeys(hierarchyMemberId) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
return Result.wrap('findEncryptedExchangeKeys', () => this.crypto.getEncryptedAesExchangeKeysForDelegate(hierarchyMemberId));
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
decryptExchangeKeys(hierarchyMemberId, delegatorsIds) {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
return Result.wrap('decryptExchangeKeys', () => __awaiter(this, void 0, void 0, function* () { return this.crypto.decryptAndImportAesHcPartyKeysForDelegators(delegatorsIds, hierarchyMemberId); }));
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
decryptDelegations(keys, entities, hierarchyMemberId) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
return Result.wrap('decryptDelegations', () => __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
var _a, _b, _c, _d, _e, _f;
|
|
180
|
+
const res = {};
|
|
181
|
+
for (const entity of entities) {
|
|
182
|
+
const delegations = yield this.decryptDelegationLikes(keys, (_b = (_a = entity.delegations) === null || _a === void 0 ? void 0 : _a[hierarchyMemberId]) !== null && _b !== void 0 ? _b : []);
|
|
183
|
+
const encryptionKeys = yield this.decryptDelegationLikes(keys, (_d = (_c = entity.encryptionKeys) === null || _c === void 0 ? void 0 : _c[hierarchyMemberId]) !== null && _d !== void 0 ? _d : []);
|
|
184
|
+
const cryptedForeignKeys = yield this.decryptDelegationLikes(keys, (_f = (_e = entity.cryptedForeignKeys) === null || _e === void 0 ? void 0 : _e[hierarchyMemberId]) !== null && _f !== void 0 ? _f : []);
|
|
185
|
+
res[entity.id] = { delegations, encryptionKeys, cryptedForeignKeys };
|
|
186
|
+
}
|
|
187
|
+
return res;
|
|
188
|
+
}));
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
decryptDelegationLikes(keys, delegationLikes) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
const res = {};
|
|
194
|
+
for (const currDelegation of delegationLikes) {
|
|
195
|
+
const currDelegationRes = {};
|
|
196
|
+
for (const currKey of keys) {
|
|
197
|
+
if (currKey.delegatorId == currDelegation.owner) {
|
|
198
|
+
currDelegationRes[currKey.rawKey] = yield Result.wrap('decryptDelegation', () => __awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
const decrypted = yield this.crypto.AES.decrypt(currKey.key, (0, binary_utils_1.hex2ua)(currDelegation.key));
|
|
200
|
+
return (0, binary_utils_1.ua2string)(decrypted);
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
res[currDelegation.key] = currDelegationRes;
|
|
205
|
+
}
|
|
206
|
+
return res;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.ErrorReporting = ErrorReporting;
|
|
211
|
+
class DataExporter {
|
|
212
|
+
constructor(crypto) {
|
|
213
|
+
this.crypto = crypto;
|
|
214
|
+
}
|
|
215
|
+
exportDataToPojo(data) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
/*
|
|
218
|
+
* To make sure we don't leak info we salt sensitive data before hasing it (for example we want to make sure that we are unable to figure out the
|
|
219
|
+
* actual value of a cfk by comparing its hash to the hash of all the ids of patients/messages in the database)
|
|
220
|
+
*/
|
|
221
|
+
const salt = this.crypto.randomUuid();
|
|
222
|
+
const errorMsgSubstitutions = yield this.getErrorMsgSubstitutions(data, salt);
|
|
223
|
+
return {
|
|
224
|
+
description: data.description,
|
|
225
|
+
involvedEntities: data.involvedEntities.map((x) => this.encryptedEntityPojo(x)),
|
|
226
|
+
hierarchy: (yield data.hierarchy.map((res) => Promise.resolve(res.map((x) => this.dataOwnerPojo(x)))))
|
|
227
|
+
.mapErrorMsg((x) => this.applyErrorMsgSubstitutions(x, errorMsgSubstitutions))
|
|
228
|
+
.pojo(),
|
|
229
|
+
availableKeypairsPublic: data.availableKeypairsPublic.mapErrorMsg((x) => this.applyErrorMsgSubstitutions(x, errorMsgSubstitutions)).pojo(),
|
|
230
|
+
byDataOwner: (yield data.byDataOwner.map((byDataOwnerContent) => __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
const res = {};
|
|
232
|
+
for (const [dataOwnerId, dataOwnerContent] of Object.entries(byDataOwnerContent)) {
|
|
233
|
+
res[dataOwnerId] = {
|
|
234
|
+
delegators: (yield dataOwnerContent.delegators.map((ds) => Promise.resolve(ds.map((d) => this.dataOwnerPojo(d)))))
|
|
235
|
+
.mapErrorMsg((x) => this.applyErrorMsgSubstitutions(x, errorMsgSubstitutions))
|
|
236
|
+
.pojo(),
|
|
237
|
+
encryptedExchangeKeys: dataOwnerContent.encryptedExchangeKeys
|
|
238
|
+
.mapErrorMsg((x) => this.applyErrorMsgSubstitutions(x, errorMsgSubstitutions))
|
|
239
|
+
.pojo(),
|
|
240
|
+
decryptedExchangeKeys: (yield dataOwnerContent.decryptedExchangeKeys.map((x) => this.decryptedExchangeKeysPojo(x, salt)))
|
|
241
|
+
.mapErrorMsg((x) => this.applyErrorMsgSubstitutions(x, errorMsgSubstitutions))
|
|
242
|
+
.pojo(),
|
|
243
|
+
decryptedEntitiesMetadata: (yield dataOwnerContent.decryptedEntitiesMetadata.map((decryptedEntitiesData) => __awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
const currEntityData = {};
|
|
245
|
+
for (const [entityId, entityData] of Object.entries(decryptedEntitiesData)) {
|
|
246
|
+
currEntityData[entityId] = yield this.decryptedEntityInfoPojo(entityData, salt, errorMsgSubstitutions);
|
|
247
|
+
}
|
|
248
|
+
return currEntityData;
|
|
249
|
+
})))
|
|
250
|
+
.mapErrorMsg((x) => this.applyErrorMsgSubstitutions(x, errorMsgSubstitutions))
|
|
251
|
+
.pojo(),
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
return res;
|
|
255
|
+
})))
|
|
256
|
+
.mapErrorMsg((x) => this.applyErrorMsgSubstitutions(x, errorMsgSubstitutions))
|
|
257
|
+
.pojo(),
|
|
258
|
+
};
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
decryptedExchangeKeysPojo(decryptedExchangeKeys, hashingSalt) {
|
|
262
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
const res = [];
|
|
264
|
+
for (const d of decryptedExchangeKeys) {
|
|
265
|
+
res.push({
|
|
266
|
+
delegatorId: d.delegatorId,
|
|
267
|
+
keyInfo: yield this.processRawSecretToExtendedInfo(d.rawKey, hashingSalt),
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
return res;
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
decryptedEntityInfoPojo(data, salt, errorMsgSubstitutions) {
|
|
274
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
275
|
+
return {
|
|
276
|
+
delegations: yield this.decryptedDelegationInfoPojo(data.delegations, salt, errorMsgSubstitutions),
|
|
277
|
+
encryptionKeys: yield this.decryptedDelegationInfoPojo(data.encryptionKeys, salt, errorMsgSubstitutions),
|
|
278
|
+
cryptedForeignKeys: yield this.decryptedDelegationInfoPojo(data.cryptedForeignKeys, salt, errorMsgSubstitutions),
|
|
279
|
+
};
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
decryptedDelegationInfoPojo(data, salt, errorMsgSubstitutions) {
|
|
283
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
284
|
+
const res = {};
|
|
285
|
+
for (const [encryptedDelegationKey, rawKeys] of Object.entries(data)) {
|
|
286
|
+
const currRawKeys = {};
|
|
287
|
+
for (const [rawKey, result] of Object.entries(rawKeys)) {
|
|
288
|
+
currRawKeys[yield this.processRawSecretToString(rawKey, salt)] = (yield result.map((x) => this.processRawSecretToExtendedInfo(x, salt)))
|
|
289
|
+
.mapErrorMsg((x) => this.applyErrorMsgSubstitutions(x, errorMsgSubstitutions))
|
|
290
|
+
.pojo();
|
|
291
|
+
}
|
|
292
|
+
res[encryptedDelegationKey] = currRawKeys;
|
|
293
|
+
}
|
|
294
|
+
return res;
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
applyErrorMsgSubstitutions(msg, substitutions) {
|
|
298
|
+
let res = msg;
|
|
299
|
+
for (const [key, value] of Object.entries(substitutions)) {
|
|
300
|
+
res = res.split(key).join(value); // Replace all
|
|
301
|
+
}
|
|
302
|
+
return res;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
class FullDataExporter extends DataExporter {
|
|
306
|
+
constructor(crypto) {
|
|
307
|
+
super(crypto);
|
|
308
|
+
}
|
|
309
|
+
dataOwnerPojo(dataOwner) {
|
|
310
|
+
return dataOwner;
|
|
311
|
+
}
|
|
312
|
+
encryptedEntityPojo(entity) {
|
|
313
|
+
return entity;
|
|
314
|
+
}
|
|
315
|
+
processRawSecretToExtendedInfo(rawSecret, salt) {
|
|
316
|
+
return Promise.resolve(rawSecret);
|
|
317
|
+
}
|
|
318
|
+
processRawSecretToString(rawSecret, salt) {
|
|
319
|
+
return Promise.resolve(rawSecret);
|
|
320
|
+
}
|
|
321
|
+
getErrorMsgSubstitutions(data, salt) {
|
|
322
|
+
return Promise.resolve({});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
class MinimalDataExporter extends DataExporter {
|
|
326
|
+
constructor(crypto) {
|
|
327
|
+
super(crypto);
|
|
328
|
+
}
|
|
329
|
+
dataOwnerPojo(dataOwner) {
|
|
330
|
+
return {
|
|
331
|
+
id: dataOwner.dataOwner.id,
|
|
332
|
+
rev: dataOwner.dataOwner.rev,
|
|
333
|
+
type: dataOwner.type,
|
|
334
|
+
publicKey: dataOwner.dataOwner.publicKey,
|
|
335
|
+
aesExchangeKeys: dataOwner.dataOwner.aesExchangeKeys,
|
|
336
|
+
hcPartyKeys: dataOwner.dataOwner.hcPartyKeys,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
encryptedEntityPojo(entity) {
|
|
340
|
+
return {
|
|
341
|
+
id: entity.id,
|
|
342
|
+
rev: entity.rev,
|
|
343
|
+
delegations: entity.delegations,
|
|
344
|
+
cryptedForeignKeys: entity.cryptedForeignKeys,
|
|
345
|
+
encryptionKeys: entity.encryptionKeys,
|
|
346
|
+
secretForeignKeys: entity.secretForeignKeys,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
processRawSecretToExtendedInfo(rawSecret, salt) {
|
|
350
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
351
|
+
return Object.assign(Object.assign({ hashedValue: yield this.hashWithSalt(rawSecret, salt) }, this.analyseRawSecret(rawSecret)), { byColumnSeparatedPiece: rawSecret.includes(':') ? rawSecret.split(':').map((x) => this.analyseRawSecret(x)) : undefined });
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
analyseRawSecret(rawSecret) {
|
|
355
|
+
return {
|
|
356
|
+
length: rawSecret.length,
|
|
357
|
+
isUuid: !!rawSecret.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/),
|
|
358
|
+
isSameCaseHex: !!rawSecret.match(/^[0-9a-f]+$/) || !!rawSecret.match(/^[0-9A-F]+$/),
|
|
359
|
+
isMixedCaseHex: !!rawSecret.match(/^[0-9a-fA-F]+$/),
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
processRawSecretToString(rawSecret, salt) {
|
|
363
|
+
return this.hashWithSalt(rawSecret, salt);
|
|
364
|
+
}
|
|
365
|
+
hashWithSalt(data, hashingSalt) {
|
|
366
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
367
|
+
return (0, binary_utils_1.ua2hex)(yield this.crypto.sha256((0, binary_utils_1.string2ua)(data + hashingSalt)));
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
getErrorMsgSubstitutions(data, salt) {
|
|
371
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
372
|
+
const res = {};
|
|
373
|
+
for (const infoOfCurrentDataOnwer of Object.values(data.byDataOwner.getOrElse(() => ({})))) {
|
|
374
|
+
for (const key of infoOfCurrentDataOnwer.decryptedExchangeKeys.getOrElse(() => [])) {
|
|
375
|
+
res[key.rawKey] = 'hashedRawKey-' + (yield this.hashWithSalt(key.delegatorId, salt));
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return res;
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
//# sourceMappingURL=error-reporting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-reporting.js","sourceRoot":"","sources":["../../../icc-x-api/utils/error-reporting.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,iDAAqE;AASrE,IAAU,MAAM,CAyDf;AAzDD,WAAU,MAAM;IACd,MAAa,OAAO;QAClB,YAA6B,OAAU;YAAV,YAAO,GAAP,OAAO,CAAG;QAAG,CAAC;QAE3C,GAAG,CAAI,CAA6B;YAClC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;QACpD,CAAC;QAED,OAAO,CAAI,CAAqC;YAC9C,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACxB,CAAC;QAED,WAAW,CAAC,CAA+B;YACzC,OAAO,IAAI,CAAA;QACb,CAAC;QAED,IAAI;YACF,OAAO,IAAI,CAAC,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MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAA;iBACrF;aACF;YACD,OAAO,GAAG,CAAA;QACZ,CAAC;KAAA;CACF","sourcesContent":["import { CachedDataOwner, DelegatorAndKeys, IccCryptoXApi } from '../icc-crypto-x-api'\nimport { Delegation, EncryptedEntity } from '../../icc-api/model/models'\nimport { hex2ua, string2ua, ua2hex, ua2string } from './binary-utils'\n\ninterface Result<A> {\n map<B>(f: (content: A) => Promise<B>): Promise<Result<B>>\n mapErrorMsg(f: (errorMsg: string) => string): Result<A>\n flatMap<B>(f: (content: A) => Promise<Result<B>>): Promise<Result<B>>\n pojo(): any\n getOrElse(defaultValue: () => A): A\n}\nnamespace Result {\n export class Success<A> implements Result<A> {\n constructor(private readonly content: A) {}\n\n map<B>(f: (content: A) => Promise<B>): Promise<Result<B>> {\n return f(this.content).then((x) => new Success(x))\n }\n\n flatMap<B>(f: (content: A) => Promise<Result<B>>): Promise<Result<B>> {\n return f(this.content)\n }\n\n mapErrorMsg(f: (errorMsg: string) => string): Result<A> {\n return this\n }\n\n pojo(): any {\n return this.content\n }\n\n getOrElse(defaultValue: () => A): A {\n return this.content\n }\n }\n\n export class Failure implements Result<never> {\n constructor(private readonly failedOperation: string, private readonly errorMsg: string) {}\n\n map<B>(): Promise<Result<B>> {\n return Promise.resolve(this)\n }\n\n flatMap<B>(): Promise<Result<B>> {\n return Promise.resolve(this)\n }\n\n mapErrorMsg(f: (errorMsg: string) => string): Result<never> {\n return new Failure(this.failedOperation, f(this.errorMsg))\n }\n\n pojo(): any {\n return { failedOperation: this.failedOperation, errorMsg: this.errorMsg }\n }\n\n getOrElse(defaultValue: () => never): never {\n return defaultValue()\n }\n }\n\n export async function wrap<A>(operation: string, f: () => Promise<A>): Promise<Result<A>> {\n try {\n return new Success(await f())\n } catch (e) {\n const errorMsg = e instanceof Error ? e.message : typeof e === 'string' ? e : `Unexpected of type ${typeof e} content ${JSON.stringify(e)}`\n return new Failure(operation, errorMsg)\n }\n }\n}\n\ntype DecryptedDelegationInfo = { [encryptedDelegationKey: string]: { [rawKey: string]: Result<string> } } // rawKey: exchangeKey used in the decryption\n\ntype DecryptedEntityInfo = {\n delegations: DecryptedDelegationInfo\n encryptionKeys: DecryptedDelegationInfo\n cryptedForeignKeys: DecryptedDelegationInfo\n}\n\ntype EncryptedExchangeKeys = { [delegator: string]: { [mainXkDelegatorPubFp: string]: { [xkEncryptionPubFp: string]: string /*encryptedXkByKey*/ } } }\n\ntype ByDataOwnerData = {\n delegators: Result<CachedDataOwner[]>\n encryptedExchangeKeys: Result<EncryptedExchangeKeys> // As retrieved using the view: may differ from data retrieved by delegators\n decryptedExchangeKeys: Result<DelegatorAndKeys[]>\n decryptedEntitiesMetadata: Result<{ [entityId: string]: DecryptedEntityInfo }>\n}\n\ntype FullData = {\n description: string\n involvedEntities: EncryptedEntity[]\n hierarchy: Result<CachedDataOwner[]>\n availableKeypairsPublic: Result<{ [fp: string]: string }>\n byDataOwner: Result<{\n [dataOwnerId: string]: ByDataOwnerData\n }>\n}\n\nexport class ErrorReporting {\n constructor(private readonly crypto: IccCryptoXApi) {}\n\n async collectDataForReport(\n description: string, // Description of what caused the error\n involvedEntities: EncryptedEntity[], // Entities that were being processed when the error occurred\n dataOwnerId: string // Id of the data owner who was doing the processing when the error occurred\n ): Promise<{\n minimalData: object // Does not contain any sensitive data\n fullData: object // May contain sensitive data, we should not ask for it unless desperate\n }> {\n const fullData = await this.collectFullData(description, involvedEntities, dataOwnerId)\n return {\n fullData: await new FullDataExporter(this.crypto).exportDataToPojo(fullData),\n minimalData: await new MinimalDataExporter(this.crypto).exportDataToPojo(fullData),\n }\n }\n\n private async collectFullData(description: string, involvedEntities: EncryptedEntity[], dataOwnerId: string): Promise<FullData> {\n const hierarchy = await this.collectDataOwnerHierarchy(dataOwnerId)\n const availableKeypairsPublic = await this.collectAvailableKeypairsPublic()\n const byDataOwner = await hierarchy.map(async (hierarchy) => {\n const res = {} as { [dataOwnerId: string]: ByDataOwnerData }\n for (const currOwner of hierarchy) {\n const delegators = await this.getDelegators(involvedEntities, currOwner.dataOwner.id!)\n const encryptedExchangeKeys = await this.findEncryptedExchangeKeys(currOwner.dataOwner.id!)\n const decryptedExchangeKeys = await delegators.flatMap(async (delegators) => {\n return this.decryptExchangeKeys(\n currOwner.dataOwner.id!,\n delegators.map((x) => x.dataOwner.id!)\n )\n })\n const decryptedEntitiesMetadata = await decryptedExchangeKeys.flatMap(async (xks) => {\n return await this.decryptDelegations(xks, involvedEntities, currOwner.dataOwner.id!)\n })\n res[currOwner.dataOwner.id!] = {\n delegators,\n encryptedExchangeKeys,\n decryptedExchangeKeys,\n decryptedEntitiesMetadata,\n }\n }\n return res\n })\n return {\n description,\n involvedEntities,\n hierarchy,\n availableKeypairsPublic,\n byDataOwner,\n }\n }\n\n // res[0] -> self, res[1] -> self.parent, ...\n private async collectDataOwnerHierarchy(startOwnerId: string): Promise<Result<CachedDataOwner[]>> {\n return Result.wrap('collectDataOwnerHierarchy', async () => {\n const res = []\n res.push(await this.crypto.getDataOwner(startOwnerId, true))\n while (!!(res[res.length - 1].dataOwner as any).parentId) {\n res.push(await this.crypto.getDataOwner((res[res.length - 1].dataOwner as any).parentId, true))\n }\n return res\n })\n }\n\n private async collectAvailableKeypairsPublic(): Promise<Result<{ [fp: string]: string }>> {\n return Result.wrap('collectAvailableKeypairsPublic', async () => {\n const res = {} as { [fp: string]: string }\n for (const [fp, pair] of Object.entries(this.crypto.rsaKeyPairs)) {\n res[fp] = ua2hex(await this.crypto.RSA.exportKey(pair.publicKey, 'spki'))\n }\n return res\n })\n }\n\n private async getDelegators(entities: EncryptedEntity[], hierarchyMemberId: string): Promise<Result<CachedDataOwner[]>> {\n return Result.wrap('getDelegators', async () => {\n const allDelegationLikes = entities.flatMap((e) => [\n ...(e.delegations?.[hierarchyMemberId] ?? []),\n ...(e.encryptionKeys?.[hierarchyMemberId] ?? []),\n ...(e.cryptedForeignKeys?.[hierarchyMemberId] ?? []),\n ])\n const ownerIds = new Set(allDelegationLikes.map((d) => d.owner))\n const res = []\n for (const ownerId of ownerIds) {\n if (!!ownerId) res.push(await this.crypto.getDataOwner(ownerId, true))\n }\n return res\n })\n }\n\n private async findEncryptedExchangeKeys(hierarchyMemberId: string): Promise<Result<EncryptedExchangeKeys>> {\n return Result.wrap('findEncryptedExchangeKeys', () => this.crypto.getEncryptedAesExchangeKeysForDelegate(hierarchyMemberId))\n }\n\n private async decryptExchangeKeys(hierarchyMemberId: string, delegatorsIds: string[]): Promise<Result<DelegatorAndKeys[]>> {\n return Result.wrap('decryptExchangeKeys', async () => this.crypto.decryptAndImportAesHcPartyKeysForDelegators(delegatorsIds, hierarchyMemberId))\n }\n\n private async decryptDelegations(keys: DelegatorAndKeys[], entities: EncryptedEntity[], hierarchyMemberId: string) {\n return Result.wrap('decryptDelegations', async () => {\n const res = {} as { [entityId: string]: DecryptedEntityInfo }\n for (const entity of entities) {\n const delegations = await this.decryptDelegationLikes(keys, entity.delegations?.[hierarchyMemberId] ?? [])\n const encryptionKeys = await this.decryptDelegationLikes(keys, entity.encryptionKeys?.[hierarchyMemberId] ?? [])\n const cryptedForeignKeys = await this.decryptDelegationLikes(keys, entity.cryptedForeignKeys?.[hierarchyMemberId] ?? [])\n res[entity.id!] = { delegations, encryptionKeys, cryptedForeignKeys }\n }\n return res\n })\n }\n\n private async decryptDelegationLikes(keys: DelegatorAndKeys[], delegationLikes: Delegation[]): Promise<DecryptedDelegationInfo> {\n const res = {} as DecryptedDelegationInfo\n for (const currDelegation of delegationLikes) {\n const currDelegationRes = {} as { [rawKey: string]: Result<string> }\n for (const currKey of keys) {\n if (currKey.delegatorId == currDelegation.owner) {\n currDelegationRes[currKey.rawKey] = await Result.wrap('decryptDelegation', async () => {\n const decrypted = await this.crypto.AES.decrypt(currKey.key, hex2ua(currDelegation.key!))\n return ua2string(decrypted)\n })\n }\n }\n res[currDelegation.key!] = currDelegationRes\n }\n return res\n }\n}\n\nabstract class DataExporter {\n protected constructor(protected readonly crypto: IccCryptoXApi) {}\n\n async exportDataToPojo(data: FullData): Promise<object> {\n /*\n * To make sure we don't leak info we salt sensitive data before hasing it (for example we want to make sure that we are unable to figure out the\n * actual value of a cfk by comparing its hash to the hash of all the ids of patients/messages in the database)\n */\n const salt = this.crypto.randomUuid()\n const errorMsgSubstitutions = await this.getErrorMsgSubstitutions(data, salt)\n return {\n description: data.description,\n involvedEntities: data.involvedEntities.map((x) => this.encryptedEntityPojo(x)),\n hierarchy: (await data.hierarchy.map((res) => Promise.resolve(res.map((x) => this.dataOwnerPojo(x)))))\n .mapErrorMsg((x) => this.applyErrorMsgSubstitutions(x, errorMsgSubstitutions))\n .pojo(),\n availableKeypairsPublic: data.availableKeypairsPublic.mapErrorMsg((x) => this.applyErrorMsgSubstitutions(x, errorMsgSubstitutions)).pojo(),\n byDataOwner: (\n await data.byDataOwner.map(async (byDataOwnerContent) => {\n const res = {} as { [dataOwnerId: string]: object }\n for (const [dataOwnerId, dataOwnerContent] of Object.entries(byDataOwnerContent)) {\n res[dataOwnerId] = {\n delegators: (await dataOwnerContent.delegators.map((ds) => Promise.resolve(ds.map((d) => this.dataOwnerPojo(d)))))\n .mapErrorMsg((x) => this.applyErrorMsgSubstitutions(x, errorMsgSubstitutions))\n .pojo(),\n encryptedExchangeKeys: dataOwnerContent.encryptedExchangeKeys\n .mapErrorMsg((x) => this.applyErrorMsgSubstitutions(x, errorMsgSubstitutions))\n .pojo(),\n decryptedExchangeKeys: (await dataOwnerContent.decryptedExchangeKeys.map((x) => this.decryptedExchangeKeysPojo(x, salt)))\n .mapErrorMsg((x) => this.applyErrorMsgSubstitutions(x, errorMsgSubstitutions))\n .pojo(),\n decryptedEntitiesMetadata: (\n await dataOwnerContent.decryptedEntitiesMetadata.map(async (decryptedEntitiesData) => {\n const currEntityData = {} as { [entityId: string]: object }\n for (const [entityId, entityData] of Object.entries(decryptedEntitiesData)) {\n currEntityData[entityId] = await this.decryptedEntityInfoPojo(entityData, salt, errorMsgSubstitutions)\n }\n return currEntityData\n })\n )\n .mapErrorMsg((x) => this.applyErrorMsgSubstitutions(x, errorMsgSubstitutions))\n .pojo(),\n }\n }\n return res\n })\n )\n .mapErrorMsg((x) => this.applyErrorMsgSubstitutions(x, errorMsgSubstitutions))\n .pojo(),\n }\n }\n\n protected abstract getErrorMsgSubstitutions(data: FullData, salt: string): Promise<{ [key: string]: string }>\n protected abstract encryptedEntityPojo(entity: EncryptedEntity): object\n protected abstract dataOwnerPojo(dataOwner: CachedDataOwner): object\n protected async decryptedExchangeKeysPojo(decryptedExchangeKeys: DelegatorAndKeys[], hashingSalt: string): Promise<object> {\n const res = []\n for (const d of decryptedExchangeKeys) {\n res.push({\n delegatorId: d.delegatorId,\n keyInfo: await this.processRawSecretToExtendedInfo(d.rawKey, hashingSalt),\n })\n }\n return res\n }\n private async decryptedEntityInfoPojo(data: DecryptedEntityInfo, salt: string, errorMsgSubstitutions: { [key: string]: string }): Promise<object> {\n return {\n delegations: await this.decryptedDelegationInfoPojo(data.delegations, salt, errorMsgSubstitutions),\n encryptionKeys: await this.decryptedDelegationInfoPojo(data.encryptionKeys, salt, errorMsgSubstitutions),\n cryptedForeignKeys: await this.decryptedDelegationInfoPojo(data.cryptedForeignKeys, salt, errorMsgSubstitutions),\n }\n }\n private async decryptedDelegationInfoPojo(\n data: DecryptedDelegationInfo,\n salt: string,\n errorMsgSubstitutions: { [key: string]: string }\n ): Promise<object> {\n const res = {} as { [encryptedDelegationKey: string]: object }\n for (const [encryptedDelegationKey, rawKeys] of Object.entries(data)) {\n const currRawKeys = {} as { [rawKey: string]: object }\n for (const [rawKey, result] of Object.entries(rawKeys)) {\n currRawKeys[await this.processRawSecretToString(rawKey, salt)] = (await result.map((x) => this.processRawSecretToExtendedInfo(x, salt)))\n .mapErrorMsg((x) => this.applyErrorMsgSubstitutions(x, errorMsgSubstitutions))\n .pojo()\n }\n res[encryptedDelegationKey] = currRawKeys\n }\n return res\n }\n protected abstract processRawSecretToString(rawSecret: string, salt: string): Promise<string>\n protected abstract processRawSecretToExtendedInfo(rawSecret: string, salt: string): Promise<any>\n\n private applyErrorMsgSubstitutions(msg: string, substitutions: { [key: string]: string }): string {\n let res = msg\n for (const [key, value] of Object.entries(substitutions)) {\n res = res.split(key).join(value) // Replace all\n }\n return res\n }\n}\n\nclass FullDataExporter extends DataExporter {\n constructor(crypto: IccCryptoXApi) {\n super(crypto)\n }\n\n protected dataOwnerPojo(dataOwner: CachedDataOwner): object {\n return dataOwner\n }\n\n protected encryptedEntityPojo(entity: EncryptedEntity): object {\n return entity\n }\n\n protected processRawSecretToExtendedInfo(rawSecret: string, salt: string): Promise<any> {\n return Promise.resolve(rawSecret)\n }\n\n protected processRawSecretToString(rawSecret: string, salt: string): Promise<string> {\n return Promise.resolve(rawSecret)\n }\n\n protected getErrorMsgSubstitutions(data: FullData, salt: string): Promise<{ [p: string]: string }> {\n return Promise.resolve({})\n }\n}\n\nclass MinimalDataExporter extends DataExporter {\n constructor(crypto: IccCryptoXApi) {\n super(crypto)\n }\n\n protected dataOwnerPojo(dataOwner: CachedDataOwner): object {\n return {\n id: dataOwner.dataOwner.id,\n rev: dataOwner.dataOwner.rev,\n type: dataOwner.type,\n publicKey: dataOwner.dataOwner.publicKey,\n aesExchangeKeys: dataOwner.dataOwner.aesExchangeKeys,\n hcPartyKeys: dataOwner.dataOwner.hcPartyKeys,\n }\n }\n\n protected encryptedEntityPojo(entity: EncryptedEntity): object {\n return {\n id: entity.id,\n rev: entity.rev,\n delegations: entity.delegations,\n cryptedForeignKeys: entity.cryptedForeignKeys,\n encryptionKeys: entity.encryptionKeys,\n secretForeignKeys: entity.secretForeignKeys,\n }\n }\n\n protected async processRawSecretToExtendedInfo(rawSecret: string, salt: string): Promise<any> {\n return {\n hashedValue: await this.hashWithSalt(rawSecret, salt),\n ...this.analyseRawSecret(rawSecret),\n byColumnSeparatedPiece: rawSecret.includes(':') ? rawSecret.split(':').map((x) => this.analyseRawSecret(x)) : undefined,\n }\n }\n\n private analyseRawSecret(rawSecret: string): object {\n return {\n length: rawSecret.length,\n isUuid: !!rawSecret.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/),\n isSameCaseHex: !!rawSecret.match(/^[0-9a-f]+$/) || !!rawSecret.match(/^[0-9A-F]+$/),\n isMixedCaseHex: !!rawSecret.match(/^[0-9a-fA-F]+$/),\n }\n }\n\n protected processRawSecretToString(rawSecret: string, salt: string): Promise<string> {\n return this.hashWithSalt(rawSecret, salt)\n }\n\n private async hashWithSalt(data: string, hashingSalt: string): Promise<string> {\n return ua2hex(await this.crypto.sha256(string2ua(data + hashingSalt)))\n }\n\n protected async getErrorMsgSubstitutions(data: FullData, salt: string): Promise<{ [p: string]: string }> {\n const res: { [p: string]: string } = {}\n for (const infoOfCurrentDataOnwer of Object.values(data.byDataOwner.getOrElse(() => ({})))) {\n for (const key of infoOfCurrentDataOnwer.decryptedExchangeKeys.getOrElse(() => [])) {\n res[key.rawKey] = 'hashedRawKey-' + (await this.hashWithSalt(key.delegatorId, salt))\n }\n }\n return res\n }\n}\n"]}
|
|
@@ -87,7 +87,7 @@ function phoneNumberFormat(phoneNumber) {
|
|
|
87
87
|
// The number is not valid, so we leave the input string as-is.
|
|
88
88
|
return phoneNumber;
|
|
89
89
|
}
|
|
90
|
-
return (0, libphonenumber_js_1.formatNumber)(parsedPhoneNumber, '
|
|
90
|
+
return (0, libphonenumber_js_1.formatNumber)(parsedPhoneNumber, 'INTERNATIONAL');
|
|
91
91
|
}
|
|
92
92
|
exports.phoneNumberFormat = phoneNumberFormat;
|
|
93
93
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting-util.js","sourceRoot":"","sources":["../../../icc-x-api/utils/formatting-util.ts"],"names":[],"mappings":";;;AAAA,yDAA0F;AAE1F,iCAAgC;AAChC,4BAA2B;AAG3B,6BAA6B;AAC7B,MAAM,e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n\nimport * as moment from 'moment'\nimport * as _ from 'lodash'\nimport { Moment } from 'moment'\n\n// TODO: move this to env.js?\nconst DEFAULT_COUNTRY = 'BE'\n\nexport const nihiiRegExp = new RegExp('^(\\\\d{1})(\\\\d{5})(\\\\d{2})(\\\\d{3})$')\nexport const ssinRegExp = new RegExp('^(\\\\d{2})(\\\\d{2})(\\\\d{2})(\\\\d{3})(\\\\d{2})$')\nexport const ibanRegExp = new RegExp('^(\\\\d{4})(\\\\d{4})(\\\\d{4})(\\\\d{4})$')\n\nconst patterns = {\n IBAN: (iban: string) => /^BE\\d{14}$/.test(iban) && isValidIBAN(iban),\n IBANBE: (iban: string) => /^BE\\d{14}$/.test(iban) && isValidIBAN(iban),\n}\n\n//http://ht5ifv.serprest.pt/extensions/tools/IBAN/\nexport function isValidIBAN(iban: string) {\n //This function check if the checksum if correct\n iban = iban.replace(/^(.{4})(.*)$/, '$2$1') //Move the first 4 chars from left to the right\n const fun = (e: string) => (e.charCodeAt(0) - 'A'.charCodeAt(0) + 10).toString()\n iban = iban.replace(/[A-Z]/g, fun) //Convert A-Z to 10-25\n let $sum = 0\n let $ei = 1 //First exponent\n for (let $i = iban.length - 1; $i >= 0; $i--) {\n $sum += $ei * parseInt(iban.charAt($i), 10) //multiply the digit by it's exponent\n $ei = ($ei * 10) % 97 //compute next base 10 exponent in modulus 97\n }\n return $sum % 97 === 1\n}\n\nexport function ibanValidate(iban: string) {\n if (iban.startsWith('BE')) {\n return patterns.IBANBE(iban)\n } else {\n return patterns.IBAN(iban)\n }\n}\n\nexport function ibanFormat(iban: string): string {\n return iban.replace(ibanRegExp, '$1 $2 $3 $4')\n}\n\nexport function nihiiFormat(nihii: string): string {\n return nihii.replace(nihiiRegExp, '$1 $2 $3 $4')\n}\n\nexport function nihiiValidate(nihii: string): boolean {\n return !!nihii.match(nihiiRegExp)\n}\n\nexport function ssinFormat(ssin: string): string {\n return ssin.replace(ssinRegExp, '$1 $2 $3 $4 $5')\n}\n\nexport function ssinValidate(ssin: string): boolean {\n return !!ssin.match(ssinRegExp)\n}\n\n/* Alternate lib free version\nexport function phoneNumberValidate(phoneNumber: string): boolean {\n return (\n !!phoneNumber.match(/(?:\\+|00)([1-9][0-9]{1-2})([- /.]*([0-9]+))+/) ||\n !!phoneNumber.match(/(0[1-9][0-9]*)([- /.]*([0-9]+))+/)\n )\n}\n\nexport function phoneNumberFormat(phoneNumber: string): string {\n let match = phoneNumber.match(/(?:\\+|00)([1-9][0-9]{1-2})([- /.]*([0-9]+))+/)\n if (match) {\n return `+${match[1]} ${match[2].replace(/[- /.]/g, \" \")}`.replace(/ /g, \" \")\n }\n match = phoneNumber.match(/0([1-9][0-9]*)([- /.]*([0-9]+))+/)\n if (match) {\n return `+32 ${match[1]} ${match[2].replace(/[- /.]/g, \" \")}`.replace(/ /g, \" \")\n }\n return phoneNumber\n}\n*/\n\nexport function phoneNumberValidate(phoneNumber: string): boolean {\n return isValidNumber(phoneNumber)\n}\n\nexport function phoneNumberFormat(phoneNumber: string): string {\n const parsedPhoneNumber = parseNumber(phoneNumber, DEFAULT_COUNTRY) as ParsedNumber\n if (_.isEmpty(parsedPhoneNumber)) {\n // The number is not valid, so we leave the input string as-is.\n return phoneNumber\n }\n return formatNumber(parsedPhoneNumber, 'International')\n}\n\n/**\n * Converts a backend date number (e.g., patient birth date) into a Date object.\n * @param dateNumber a YYYYMMDD date number from the backend\n * @return a Date object\n * @throws Error if it is impossible to create a date from the number, other if dateNumber is negative.\n * @see #dateEncode\n * @see #timeDecode\n */\nexport function dateDecode(dateNumber: number): Date | undefined {\n if (!dateNumber) {\n return undefined\n }\n\n if (dateNumber < 0) {\n throw new Error(\"We don't decode negative dates. Please make sure you have valid data.\")\n }\n const dateNumberStr: string = _.padStart(dateNumber.toString(), 8, '19700101')\n if (dateNumberStr.length > 8) {\n if (dateNumberStr.endsWith('000000')) {\n return dateNumber ? moment(dateNumberStr, 'YYYYMMDD000000').toDate() : undefined\n }\n\n throw Error(\"Decoded date is over year 9999. We can't format it properly.\")\n }\n return dateNumber ? moment(dateNumberStr, 'YYYYMMDD').toDate() : undefined\n}\n\n/**\n * Converts a backend time number (e.g., health element openingDate) into a Date object.\n * @param timeNumber a YYYYMMDD date number from the backend\n * @return a Date object\n * @see #timeEncode\n * @see #dateDecode\n */\nexport function timeDecode(timeNumber: number): Date | undefined {\n return timeNumber ? moment(timeNumber.toString(), 'YYYYMMDDHHmmss').toDate() : undefined\n}\n\n/**\n * Encodes a Date object into a backend date number (e.g., patient birth date).\n * @param date a Date object\n * @return a YYYYMMDD date number for the backend\n * @see #dateDecode\n * @see #timeEncode\n */\nexport function dateEncode(date: Date): number | undefined {\n const dateStr = _.padStart(moment(date).format('YYYYMMDD'), 8, '19700101')\n // date is null if the field is not set\n return date ? Number(dateStr) : undefined\n}\n\n/**\n * Encodes a Date object into a backend time number (e.g., health element openingDate).\n * @param date a Date object\n * @return a YYYYMMDDHHmmss date number for the backend\n * @see #timeDecode\n * @see #dateEncode\n */\nexport function timeEncode(date: Date): number | undefined {\n return date ? Number(moment(date).format('YYYYMMDDHHmmss')) : undefined\n}\n\n/**\n * Formats a value and a physical unit into text.\n * @param value the numerical or string value to encode\n * @param unit the unit represented as a string (an empty string is also supported)\n */\nexport function unit(value: number | string, unit: string | null): string {\n unit = unit || ''\n let separator: string\n if (!unit || unit.startsWith('°')) {\n separator = ''\n } else {\n // including '%'\n separator = '\\xa0'\n }\n return value + separator + unit\n}\n\n/**\n * 0.1 + 0.2 = 0.30000000000000004. Use this function to be better at maths.\n * @param a number\n * @return the rounded number, two after the comma\n */\nexport function amount(value: number): number {\n return Number((value || 0).toFixed(2))\n}\n\n/**\n * A simple formatter to keep the logic across the app.\n * Input: 2.1 ; Output: 2.10€\n */\nexport function money(value: number): string {\n return [(value || 0).toFixed(2), '€'].join('')\n}\n\n/**\n * Transform a dictionary to a url params.\n * From { key1: value1, key2: value2, ... } returns key1=value1&key2=value2&...=...\n */\nexport function toUrlParams(params: { [key: string]: string }): string {\n return _.filter(_.map(params, (value, key) => (value ? key + '=' + value : undefined))).join('&')\n}\n\nexport function personName(person: { firstName?: string; lastName?: string }): string {\n return `${person.firstName || ''} ${person.lastName || ''}`.trim()\n}\n\nexport function personNameAbbrev(person: { firstName?: string; lastName?: string }): string {\n const firstName = person.firstName ? person.firstName[0] + '.' : undefined\n return personName({ ...person, firstName })\n}\n\nexport function toMoment(epochOrLongCalendar: number): Moment | null {\n if (!epochOrLongCalendar && epochOrLongCalendar !== 0) {\n return null\n }\n if (epochOrLongCalendar >= 18000101 && epochOrLongCalendar < 25400000) {\n return moment('' + epochOrLongCalendar, 'YYYYMMDD')\n } else if (epochOrLongCalendar >= 18000101000000) {\n return moment('' + epochOrLongCalendar, 'YYYYMMDDhhmmss')\n } else {\n return moment(epochOrLongCalendar)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"formatting-util.js","sourceRoot":"","sources":["../../../icc-x-api/utils/formatting-util.ts"],"names":[],"mappings":";;;AAAA,yDAA0F;AAE1F,iCAAgC;AAChC,4BAA2B;AAG3B,6BAA6B;AAC7B,MAAM,eAAe,GAAG,IAAI,CAAA;AAEf,QAAA,WAAW,GAAG,IAAI,MAAM,CAAC,oCAAoC,CAAC,CAAA;AAC9D,QAAA,UAAU,GAAG,IAAI,MAAM,CAAC,4CAA4C,CAAC,CAAA;AACrE,QAAA,UAAU,GAAG,IAAI,MAAM,CAAC,oCAAoC,CAAC,CAAA;AAE1E,MAAM,QAAQ,GAAG;IACf,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC;IACpE,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC;CACvE,CAAA;AAED,kDAAkD;AAClD,SAAgB,WAAW,CAAC,IAAY;IACtC,gDAAgD;IAChD,IAAI,GAAG,IAAI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AC,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,SAAS,CAAA;IAC1E,OAAO,UAAU,iCAAM,MAAM,KAAE,SAAS,IAAG,CAAA;AAC7C,CAAC;AAHD,4CAGC;AAED,SAAgB,QAAQ,CAAC,mBAA2B;IAClD,IAAI,CAAC,mBAAmB,IAAI,mBAAmB,KAAK,CAAC,EAAE;QACrD,OAAO,IAAI,CAAA;KACZ;IACD,IAAI,mBAAmB,IAAI,QAAQ,IAAI,mBAAmB,GAAG,QAAQ,EAAE;QACrE,OAAO,MAAM,CAAC,EAAE,GAAG,mBAAmB,EAAE,UAAU,CAAC,CAAA;KACpD;SAAM,IAAI,mBAAmB,IAAI,cAAc,EAAE;QAChD,OAAO,MAAM,CAAC,EAAE,GAAG,mBAAmB,EAAE,gBAAgB,CAAC,CAAA;KAC1D;SAAM;QACL,OAAO,MAAM,CAAC,mBAAmB,CAAC,CAAA;KACnC;AACH,CAAC;AAXD,4BAWC","sourcesContent":["import { parseNumber, formatNumber, isValidNumber, ParsedNumber } from 'libphonenumber-js'\n\nimport * as moment from 'moment'\nimport * as _ from 'lodash'\nimport { Moment } from 'moment'\n\n// TODO: move this to env.js?\nconst DEFAULT_COUNTRY = 'BE'\n\nexport const nihiiRegExp = new RegExp('^(\\\\d{1})(\\\\d{5})(\\\\d{2})(\\\\d{3})$')\nexport const ssinRegExp = new RegExp('^(\\\\d{2})(\\\\d{2})(\\\\d{2})(\\\\d{3})(\\\\d{2})$')\nexport const ibanRegExp = new RegExp('^(\\\\d{4})(\\\\d{4})(\\\\d{4})(\\\\d{4})$')\n\nconst patterns = {\n IBAN: (iban: string) => /^BE\\d{14}$/.test(iban) && isValidIBAN(iban),\n IBANBE: (iban: string) => /^BE\\d{14}$/.test(iban) && isValidIBAN(iban),\n}\n\n//http://ht5ifv.serprest.pt/extensions/tools/IBAN/\nexport function isValidIBAN(iban: string) {\n //This function check if the checksum if correct\n iban = iban.replace(/^(.{4})(.*)$/, '$2$1') //Move the first 4 chars from left to the right\n const fun = (e: string) => (e.charCodeAt(0) - 'A'.charCodeAt(0) + 10).toString()\n iban = iban.replace(/[A-Z]/g, fun) //Convert A-Z to 10-25\n let $sum = 0\n let $ei = 1 //First exponent\n for (let $i = iban.length - 1; $i >= 0; $i--) {\n $sum += $ei * parseInt(iban.charAt($i), 10) //multiply the digit by it's exponent\n $ei = ($ei * 10) % 97 //compute next base 10 exponent in modulus 97\n }\n return $sum % 97 === 1\n}\n\nexport function ibanValidate(iban: string) {\n if (iban.startsWith('BE')) {\n return patterns.IBANBE(iban)\n } else {\n return patterns.IBAN(iban)\n }\n}\n\nexport function ibanFormat(iban: string): string {\n return iban.replace(ibanRegExp, '$1 $2 $3 $4')\n}\n\nexport function nihiiFormat(nihii: string): string {\n return nihii.replace(nihiiRegExp, '$1 $2 $3 $4')\n}\n\nexport function nihiiValidate(nihii: string): boolean {\n return !!nihii.match(nihiiRegExp)\n}\n\nexport function ssinFormat(ssin: string): string {\n return ssin.replace(ssinRegExp, '$1 $2 $3 $4 $5')\n}\n\nexport function ssinValidate(ssin: string): boolean {\n return !!ssin.match(ssinRegExp)\n}\n\n/* Alternate lib free version\nexport function phoneNumberValidate(phoneNumber: string): boolean {\n return (\n !!phoneNumber.match(/(?:\\+|00)([1-9][0-9]{1-2})([- /.]*([0-9]+))+/) ||\n !!phoneNumber.match(/(0[1-9][0-9]*)([- /.]*([0-9]+))+/)\n )\n}\n\nexport function phoneNumberFormat(phoneNumber: string): string {\n let match = phoneNumber.match(/(?:\\+|00)([1-9][0-9]{1-2})([- /.]*([0-9]+))+/)\n if (match) {\n return `+${match[1]} ${match[2].replace(/[- /.]/g, \" \")}`.replace(/ /g, \" \")\n }\n match = phoneNumber.match(/0([1-9][0-9]*)([- /.]*([0-9]+))+/)\n if (match) {\n return `+32 ${match[1]} ${match[2].replace(/[- /.]/g, \" \")}`.replace(/ /g, \" \")\n }\n return phoneNumber\n}\n*/\n\nexport function phoneNumberValidate(phoneNumber: string): boolean {\n return isValidNumber(phoneNumber)\n}\n\nexport function phoneNumberFormat(phoneNumber: string): string {\n const parsedPhoneNumber = parseNumber(phoneNumber, DEFAULT_COUNTRY) as ParsedNumber\n if (_.isEmpty(parsedPhoneNumber)) {\n // The number is not valid, so we leave the input string as-is.\n return phoneNumber\n }\n return formatNumber(parsedPhoneNumber, 'INTERNATIONAL')\n}\n\n/**\n * Converts a backend date number (e.g., patient birth date) into a Date object.\n * @param dateNumber a YYYYMMDD date number from the backend\n * @return a Date object\n * @throws Error if it is impossible to create a date from the number, other if dateNumber is negative.\n * @see #dateEncode\n * @see #timeDecode\n */\nexport function dateDecode(dateNumber: number): Date | undefined {\n if (!dateNumber) {\n return undefined\n }\n\n if (dateNumber < 0) {\n throw new Error(\"We don't decode negative dates. Please make sure you have valid data.\")\n }\n const dateNumberStr: string = _.padStart(dateNumber.toString(), 8, '19700101')\n if (dateNumberStr.length > 8) {\n if (dateNumberStr.endsWith('000000')) {\n return dateNumber ? moment(dateNumberStr, 'YYYYMMDD000000').toDate() : undefined\n }\n\n throw Error(\"Decoded date is over year 9999. We can't format it properly.\")\n }\n return dateNumber ? moment(dateNumberStr, 'YYYYMMDD').toDate() : undefined\n}\n\n/**\n * Converts a backend time number (e.g., health element openingDate) into a Date object.\n * @param timeNumber a YYYYMMDD date number from the backend\n * @return a Date object\n * @see #timeEncode\n * @see #dateDecode\n */\nexport function timeDecode(timeNumber: number): Date | undefined {\n return timeNumber ? moment(timeNumber.toString(), 'YYYYMMDDHHmmss').toDate() : undefined\n}\n\n/**\n * Encodes a Date object into a backend date number (e.g., patient birth date).\n * @param date a Date object\n * @return a YYYYMMDD date number for the backend\n * @see #dateDecode\n * @see #timeEncode\n */\nexport function dateEncode(date: Date): number | undefined {\n const dateStr = _.padStart(moment(date).format('YYYYMMDD'), 8, '19700101')\n // date is null if the field is not set\n return date ? Number(dateStr) : undefined\n}\n\n/**\n * Encodes a Date object into a backend time number (e.g., health element openingDate).\n * @param date a Date object\n * @return a YYYYMMDDHHmmss date number for the backend\n * @see #timeDecode\n * @see #dateEncode\n */\nexport function timeEncode(date: Date): number | undefined {\n return date ? Number(moment(date).format('YYYYMMDDHHmmss')) : undefined\n}\n\n/**\n * Formats a value and a physical unit into text.\n * @param value the numerical or string value to encode\n * @param unit the unit represented as a string (an empty string is also supported)\n */\nexport function unit(value: number | string, unit: string | null): string {\n unit = unit || ''\n let separator: string\n if (!unit || unit.startsWith('°')) {\n separator = ''\n } else {\n // including '%'\n separator = '\\xa0'\n }\n return value + separator + unit\n}\n\n/**\n * 0.1 + 0.2 = 0.30000000000000004. Use this function to be better at maths.\n * @param a number\n * @return the rounded number, two after the comma\n */\nexport function amount(value: number): number {\n return Number((value || 0).toFixed(2))\n}\n\n/**\n * A simple formatter to keep the logic across the app.\n * Input: 2.1 ; Output: 2.10€\n */\nexport function money(value: number): string {\n return [(value || 0).toFixed(2), '€'].join('')\n}\n\n/**\n * Transform a dictionary to a url params.\n * From { key1: value1, key2: value2, ... } returns key1=value1&key2=value2&...=...\n */\nexport function toUrlParams(params: { [key: string]: string }): string {\n return _.filter(_.map(params, (value, key) => (value ? key + '=' + value : undefined))).join('&')\n}\n\nexport function personName(person: { firstName?: string; lastName?: string }): string {\n return `${person.firstName || ''} ${person.lastName || ''}`.trim()\n}\n\nexport function personNameAbbrev(person: { firstName?: string; lastName?: string }): string {\n const firstName = person.firstName ? person.firstName[0] + '.' : undefined\n return personName({ ...person, firstName })\n}\n\nexport function toMoment(epochOrLongCalendar: number): Moment | null {\n if (!epochOrLongCalendar && epochOrLongCalendar !== 0) {\n return null\n }\n if (epochOrLongCalendar >= 18000101 && epochOrLongCalendar < 25400000) {\n return moment('' + epochOrLongCalendar, 'YYYYMMDD')\n } else if (epochOrLongCalendar >= 18000101000000) {\n return moment('' + epochOrLongCalendar, 'YYYYMMDDhhmmss')\n } else {\n return moment(epochOrLongCalendar)\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Patient, Insurability } from '../../icc-api/model/models';
|
|
2
|
-
export declare function isBIM(ct1: number | string, ct2: number | string): boolean;
|
|
2
|
+
export declare function isBIM(ct1: number | string | undefined, ct2: number | string | undefined): boolean;
|
|
3
3
|
export declare function patientIsBIM(patient: Patient): boolean;
|
|
4
4
|
export declare function isPatientPaymentByIo(patient: Patient): boolean;
|
|
5
5
|
/**
|
|
@@ -4,7 +4,7 @@ exports.isPatientHospitalized = exports.getInsurability = exports.getMembership
|
|
|
4
4
|
const _ = require("lodash");
|
|
5
5
|
function isBIM(ct1, ct2) {
|
|
6
6
|
//BIM if ct1 ood and ct2 ood
|
|
7
|
-
return +ct1 % 2 !== 0 && +ct2 % 2 !== 0;
|
|
7
|
+
return +(ct1 !== null && ct1 !== void 0 ? ct1 : 0) % 2 !== 0 && +(ct2 !== null && ct2 !== void 0 ? ct2 : 0) % 2 !== 0;
|
|
8
8
|
}
|
|
9
9
|
exports.isBIM = isBIM;
|
|
10
10
|
function patientIsBIM(patient) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insurability-util.js","sourceRoot":"","sources":["../../../icc-x-api/utils/insurability-util.ts"],"names":[],"mappings":";;;AAAA,4BAA2B;AAG3B,SAAgB,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"insurability-util.js","sourceRoot":"","sources":["../../../icc-x-api/utils/insurability-util.ts"],"names":[],"mappings":";;;AAAA,4BAA2B;AAG3B,SAAgB,KAAK,CAAC,GAAgC,EAAE,GAAgC;IACtF,4BAA4B;IAC5B,OAAO,CAAC,CAAC,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;AACvD,CAAC;AAHD,sBAGC;AAED,SAAgB,YAAY,CAAC,OAAgB;IAC3C,6HAA6H;IAC7H,OAAO,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,kCAAkC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,kCAAkC,CAAC,CAAC,CAAA;AACtH,CAAC;AAHD,oCAGC;AAED,SAAgB,oBAAoB,CAAC,OAAgB;IACnD,MAAM,WAAW,GAAG,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,0CAA0C,CAAC,CAAA;IAC9E,OAAO,WAAW,KAAK,MAAM,CAAA;AAC/B,CAAC;AAHD,oDAGC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,OAAgB;IAC5C,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,wCAAwC,CAAC,CAAA;IACvE,IAAI,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE;QACzB,iBAAiB;QACjB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;KAChE;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAPD,sCAOC;AAED;;;;GAIG;AACH,SAAgB,eAAe,CAAC,OAAgB;IAC9C,MAAM,YAAY,GAAG,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAA;IACxD,IAAI,CAAC,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE;QAC/B,iBAAiB;QACjB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;KAChE;IACD,OAAO,YAAY,CAAA;AACrB,CAAC;AAPD,0CAOC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,OAAgB;IACpD,OAAO,eAAe,CAAC,OAAO,CAAC,CAAC,eAAe,IAAI,KAAK,CAAA;AAC1D,CAAC;AAFD,sDAEC","sourcesContent":["import * as _ from 'lodash'\nimport { Patient, Insurability } from '../../icc-api/model/models'\n\nexport function isBIM(ct1: number | string | undefined, ct2: number | string | undefined): boolean {\n //BIM if ct1 ood and ct2 ood\n return +(ct1 ?? 0) % 2 !== 0 && +(ct2 ?? 0) % 2 !== 0\n}\n\nexport function patientIsBIM(patient: Patient) {\n // FIXME this doesn't check the date of the insurability. It is related to the idea of having only on insurability at a time.\n return isBIM(_.get(patient, 'insurabilities[0].parameters.tc1'), _.get(patient, 'insurabilities[0].parameters.tc2'))\n}\n\nexport function isPatientPaymentByIo(patient: Patient) {\n const paymentByIo = _.get(patient, 'insurabilities[0].parameters.paymentByIo')\n return paymentByIo === 'true'\n}\n\n/**\n * Returns the titulary id from patient insurability\n * @throws error if the patient has no insurability data\n * @param patient The patient\n */\nexport function getMembership(patient: Patient): string {\n const ioCode = _.get(patient, 'insurabilities[0].identificationNumber')\n if (_.isUndefined(ioCode)) {\n // TODO translate\n throw new Error(\"Le patient n'a pas de données d'assurabilité\")\n }\n return ioCode\n}\n\n/**\n * Returns the insurability from patient\n * @throws error if the patient has no insurability data\n * @param patient The patient\n */\nexport function getInsurability(patient: Patient): Insurability {\n const insurability = _.get(patient, 'insurabilities[0]')\n if (_.isUndefined(insurability)) {\n // TODO translate\n throw new Error(\"Le patient n'a pas de données d'assurabilité\")\n }\n return insurability\n}\n\n/**\n * Returns the insurability from patient\n * @throws error if the patient has no insurability data\n * @param patient\n */\nexport function isPatientHospitalized(patient: Patient): boolean {\n return getInsurability(patient).hospitalisation || false\n}\n"]}
|