@icure/be-fhc-api 0.4.38 → 0.4.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icure/be-fhc-api",
3
- "version": "0.4.38",
3
+ "version": "0.4.40",
4
4
  "description": "Typescript version of Freehealth Connector standalone API client",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -19,7 +19,7 @@ export declare class MessageXApi {
19
19
  private patientApi;
20
20
  constructor(api: IccMessageXApi, crypto: IccCryptoXApi, documentXApi: IccDocumentXApi, insuranceApi: IccInsuranceApi, entityReferenceApi: IccEntityrefApi, fhcReceiptXApi: ReceiptXApi, invoiceXApi: IccInvoiceXApi, patientXApi: IccPatientXApi, patientApi: IccPatientApi);
21
21
  saveDmgsListRequest(user: User, req: GenAsyncResponse, requestDate?: number): Promise<Message>;
22
- processDmgMessagesList(user: User, hcp: HealthcareParty, list: DmgsList, docXApi: IccDocumentXApi): Promise<Array<Array<string>>>;
22
+ processDmgMessagesList(user: User, hcp: HealthcareParty, list: DmgsList, parentId: string, docXApi: IccDocumentXApi): Promise<Array<Array<string>>>;
23
23
  private makeHcp;
24
24
  private saveMessageInDb;
25
25
  saveDmgListRequestInDb(user: User, tack: string, resultMajor: string, appliesTo: string, hcp: HealthcareParty, date?: Date, inss?: string): Promise<Message>;
@@ -55,7 +55,7 @@ class MessageXApi {
55
55
  .then(() => msg);
56
56
  });
57
57
  }
58
- processDmgMessagesList(user, hcp, list, docXApi) {
58
+ processDmgMessagesList(user, hcp, list, parentId, docXApi) {
59
59
  const ackHashes = [];
60
60
  let promAck = Promise.resolve(null);
61
61
  _.each(list.acks, ack => {
@@ -126,8 +126,8 @@ class MessageXApi {
126
126
  if (!msgsForHcp.length) {
127
127
  throw new Error(`Cannot find parent with ref ${ref}`);
128
128
  }
129
- const parent = msgsForHcp[0];
130
- return this.saveMessageInDb(user, "List", dmgsMsgList, hcp, metas, docXApi, dmgsMsgList.date, undefined, parent && parent.id).then(msg => {
129
+ const parentMessage = msgsForHcp[0];
130
+ return this.saveMessageInDb(user, "List", dmgsMsgList, hcp, metas, docXApi, dmgsMsgList.date, undefined, parentMessage && parentMessage.id).then(msg => {
131
131
  dmgsMsgList.valueHash && msgHashes.push(dmgsMsgList.valueHash);
132
132
  acc.push(msg);
133
133
  return acc;
@@ -193,45 +193,121 @@ class MessageXApi {
193
193
  .filterPatientsBy(undefined, undefined, 1000, 0, undefined, false, new api_1.FilterChainPatient({
194
194
  filter: new api_1.AbstractFilterPatient({
195
195
  $type: "PatientByHcPartyAndSsinsFilter",
196
- healthcarePartyId: user.healthcarePartyId,
196
+ healthcarePartyId: parentId || hcp.parentId || hcp.id || user.healthcarePartyId,
197
197
  ssins: ssins
198
198
  })
199
199
  }))
200
200
  .then((pats) => Promise.all((pats.rows || []).map(p => {
201
201
  const actions = _.sortBy(patsDmgs[p.ssin], a => moment(a.date, "DD/MM/YYYY").format("YYYYMMDD"));
202
- let phcp = ((p.patientHealthCareParties || (p.patientHealthCareParties = [])) &&
203
- p.patientHealthCareParties.find(phcp => phcp.healthcarePartyId === user.healthcarePartyId)) || new api_1.PatientHealthCareParty({ healthcarePartyId: user.healthcarePartyId, referralPeriods: [] });
202
+ let phcp = (p.patientHealthCareParties || (p.patientHealthCareParties = [])) &&
203
+ p.patientHealthCareParties.find(phcp => phcp.healthcarePartyId === user.healthcarePartyId);
204
+ if (!phcp) {
205
+ phcp = new api_1.PatientHealthCareParty({
206
+ healthcarePartyId: user.healthcarePartyId,
207
+ referralPeriods: []
208
+ });
209
+ p.patientHealthCareParties.push(phcp);
210
+ }
204
211
  if (!phcp.referralPeriods) {
205
212
  phcp.referralPeriods = [];
206
213
  }
207
214
  const referralPeriods = phcp.referralPeriods;
208
215
  actions.map(action => {
216
+ if (!action.newHcp) {
217
+ action.newHcp = action.hcp || "";
218
+ }
209
219
  const actionDate = Number(moment((action === null || action === void 0 ? void 0 : action.date) || "", "DD/MM/YYYY").format("YYYYMMDD"));
220
+ const fromDate = action.from
221
+ ? action.from.toString().includes("/")
222
+ ? Number(moment(action.from, "DD/MM/YYYY").format("YYYYMMDD"))
223
+ : Number(moment(action.from).format("YYYYMMDD"))
224
+ : null;
225
+ const toDate = action.to
226
+ ? action.to.toString().includes("/")
227
+ ? Number(moment(action.to, "DD/MM/YYYY").format("YYYYMMDD"))
228
+ : Number(moment(action.to).format("YYYYMMDD"))
229
+ : null;
230
+ const rp = referralPeriods.find(per => ((!per.endDate || per.endDate >= actionDate) &&
231
+ ((per === null || per === void 0 ? void 0 : per.startDate) || 0) <= actionDate) ||
232
+ (fromDate &&
233
+ (!per.endDate || per.endDate >= fromDate) &&
234
+ ((per === null || per === void 0 ? void 0 : per.startDate) || 0) <= fromDate) ||
235
+ (toDate &&
236
+ (!per.endDate || per.endDate >= toDate) &&
237
+ ((per === null || per === void 0 ? void 0 : per.startDate) || 0) <= toDate));
210
238
  if (action) {
211
239
  if (action.closure) {
212
- const rp = referralPeriods.find(per => (!per.endDate || per.endDate > actionDate) && ((per === null || per === void 0 ? void 0 : per.startDate) || 0) < actionDate);
213
240
  if (rp) {
214
- rp.comment = (rp.comment + ' ' || '') + (rp.endDate ? "Correction End Date. " : "") + `Transferred to ${action.newHcp}`;
215
- rp.endDate = actionDate;
241
+ if (fromDate) {
242
+ rp.startDate =
243
+ fromDate < (rp.startDate || 99999999) ? fromDate : rp.startDate;
244
+ }
245
+ if (toDate) {
246
+ rp.endDate = toDate > (rp.endDate || 0) ? toDate : rp.endDate;
247
+ }
248
+ rp.endDate = actionDate > (rp.endDate || 0) ? actionDate : rp.endDate;
249
+ if (action.newHcp) {
250
+ rp.comment =
251
+ (rp.comment + " " || "") + `Transferred to ${action.newHcp}`;
252
+ }
216
253
  }
217
254
  else {
218
- referralPeriods.push(new api_1.ReferralPeriod({ startDate: Number(moment().format("YYYYMMDD")), endDate: actionDate, comment: `No start Date Info. Transferred to ${action.newHcp}` }));
255
+ const endDate = actionDate || toDate
256
+ ? (toDate || 0) > actionDate
257
+ ? toDate
258
+ : actionDate
259
+ : moment().format("YYYYMMDD");
260
+ const startDate = fromDate ? fromDate : moment().format("YYYYMMDD");
261
+ referralPeriods.push(new api_1.ReferralPeriod({
262
+ startDate: startDate,
263
+ endDate: endDate,
264
+ comment: `Transferred to ${action.newHcp ? action.newHcp : ""}`
265
+ }));
219
266
  }
220
267
  }
221
268
  else {
222
- const rp = referralPeriods.find(per => (!per.endDate || per.endDate > actionDate) && ((per === null || per === void 0 ? void 0 : per.startDate) || 0) < actionDate);
223
269
  if (rp) {
224
- rp.startDate = actionDate < (rp.startDate || 0) ? actionDate : rp.startDate;
225
- rp.comment = (rp.comment + ' ' || '') + 'Correction Start Date.';
270
+ if (fromDate) {
271
+ rp.startDate =
272
+ fromDate < (rp.startDate || 99999999) ? fromDate : rp.startDate;
273
+ }
274
+ rp.startDate =
275
+ actionDate < (rp.startDate || 99999999) ? actionDate : rp.startDate;
276
+ if (toDate) {
277
+ rp.endDate = toDate > (rp.endDate || 0) ? toDate : rp.endDate;
278
+ }
226
279
  }
227
280
  else {
228
- referralPeriods.push(new api_1.ReferralPeriod({ startDate: actionDate, comment: `New Referral to ${action.newHcp}` }));
281
+ const endDate = toDate ? toDate : null;
282
+ const startDate = actionDate || fromDate
283
+ ? (fromDate || 99999999) < actionDate
284
+ ? fromDate
285
+ : actionDate
286
+ : moment().format("YYYYMMDD");
287
+ referralPeriods.push(new api_1.ReferralPeriod({
288
+ startDate: startDate,
289
+ endDate: endDate,
290
+ comment: `New Referral to ${action.newHcp ? action.newHcp : "unknown"}`
291
+ }));
229
292
  }
230
293
  }
231
294
  }
232
295
  });
233
- phcp.referralPeriods = referralPeriods.sort((a, b) => (a.startDate || 0) - (b.startDate || 0));
234
- phcp.referral = !Boolean(referralPeriods[referralPeriods.length - 1].endDate);
296
+ p.patientHealthCareParties = p.patientHealthCareParties.map(phcpTemp => {
297
+ var _a, _b;
298
+ if (!phcpTemp.referralPeriods) {
299
+ phcpTemp.referralPeriods = [];
300
+ }
301
+ phcpTemp.referralPeriods = (_a = phcpTemp === null || phcpTemp === void 0 ? void 0 : phcpTemp.referralPeriods) === null || _a === void 0 ? void 0 : _a.sort((a, b) => (a.startDate || 0) - (b.startDate || 0));
302
+ const lastRp = ((_b = phcpTemp === null || phcpTemp === void 0 ? void 0 : phcpTemp.referralPeriods) === null || _b === void 0 ? void 0 : _b.length)
303
+ ? phcpTemp.referralPeriods[phcpTemp.referralPeriods.length - 1]
304
+ : null;
305
+ phcpTemp.referral = lastRp
306
+ ? !Boolean(lastRp.endDate) ||
307
+ ((lastRp === null || lastRp === void 0 ? void 0 : lastRp.endDate) || 99999999) > Number(moment().format("YYYYMMDD"))
308
+ : false;
309
+ return phcpTemp;
310
+ });
235
311
  return p;
236
312
  }))))
237
313
  .then(pats => this.patientApi.bulkUpdatePatients(pats || []).catch(() => {