@icure/be-fhc-api 0.4.39 → 0.4.41

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.39",
3
+ "version": "0.4.41",
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,17 +193,19 @@ 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
- var _a;
202
201
  const actions = _.sortBy(patsDmgs[p.ssin], a => moment(a.date, "DD/MM/YYYY").format("YYYYMMDD"));
203
202
  let phcp = (p.patientHealthCareParties || (p.patientHealthCareParties = [])) &&
204
203
  p.patientHealthCareParties.find(phcp => phcp.healthcarePartyId === user.healthcarePartyId);
205
204
  if (!phcp) {
206
- phcp = new api_1.PatientHealthCareParty({ healthcarePartyId: user.healthcarePartyId, referralPeriods: [] });
205
+ phcp = new api_1.PatientHealthCareParty({
206
+ healthcarePartyId: user.healthcarePartyId,
207
+ referralPeriods: []
208
+ });
207
209
  p.patientHealthCareParties.push(phcp);
208
210
  }
209
211
  if (!phcp.referralPeriods) {
@@ -211,54 +213,101 @@ class MessageXApi {
211
213
  }
212
214
  const referralPeriods = phcp.referralPeriods;
213
215
  actions.map(action => {
216
+ if (!action.newHcp) {
217
+ action.newHcp = action.hcp || "";
218
+ }
214
219
  const actionDate = Number(moment((action === null || action === void 0 ? void 0 : action.date) || "", "DD/MM/YYYY").format("YYYYMMDD"));
215
- const rp = referralPeriods.find(per => ((!per.endDate || per.endDate >= actionDate) && ((per === null || per === void 0 ? void 0 : per.startDate) || 0) <= actionDate)
216
- || (action.form && (!per.endDate || per.endDate >= Number(moment(action.form).format("YYYYMMDD"))) && ((per === null || per === void 0 ? void 0 : per.startDate) || 0) <= Number(moment(action.form).format("YYYYMMDD")))
217
- || (action.to && (!per.endDate || per.endDate >= Number(moment(action.to).format("YYYYMMDD"))) && ((per === null || per === void 0 ? void 0 : per.startDate) || 0) <= Number(moment(action.to).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));
218
238
  if (action) {
219
239
  if (action.closure) {
220
240
  if (rp) {
221
- if (action.from) {
222
- const from = Number(moment(action.from).format("YYYYMMDD"));
223
- rp.startDate = from < (rp.startDate || 99999999) ? from : rp.startDate;
241
+ if (fromDate) {
242
+ rp.startDate =
243
+ fromDate < (rp.startDate || 99999999) ? fromDate : rp.startDate;
224
244
  }
225
- if (action.to) {
226
- const to = Number(moment(action.to).format("YYYYMMDD"));
227
- rp.endDate = to > (rp.endDate || 0) ? to : rp.endDate;
245
+ if (toDate) {
246
+ rp.endDate = toDate > (rp.endDate || 0) ? toDate : rp.endDate;
228
247
  }
229
248
  rp.endDate = actionDate > (rp.endDate || 0) ? actionDate : rp.endDate;
230
249
  if (action.newHcp) {
231
- rp.comment = (rp.comment + ' ' || '') + `Transferred to ${action.newHcp}`;
250
+ rp.comment =
251
+ (rp.comment + " " || "") + `Transferred to ${action.newHcp}`;
232
252
  }
233
253
  }
234
254
  else {
235
- const endDate = (actionDate || action.to) ? (Number(moment(action.to).format("YYYYMMDD")) > actionDate ? Number(moment(action.to).format("YYYYMMDD")) : actionDate) : moment().format("YYYYMMDD");
236
- const startDate = action.from ? Number(moment(action.from).format("YYYYMMDD")) : moment().format("YYYYMMDD");
237
- referralPeriods.push(new api_1.ReferralPeriod({ startDate: startDate, endDate: endDate, comment: `Transferred to ${action.newHcp ? action.newHcp : "unknown"}` }));
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
+ }));
238
266
  }
239
267
  }
240
268
  else {
241
269
  if (rp) {
242
- if (action.from) {
243
- const from = Number(moment(action.from).format("YYYYMMDD"));
244
- rp.startDate = from < (rp.startDate || 99999999) ? from : rp.startDate;
270
+ if (fromDate) {
271
+ rp.startDate =
272
+ fromDate < (rp.startDate || 99999999) ? fromDate : rp.startDate;
245
273
  }
246
- rp.startDate = actionDate < (rp.startDate || 99999999) ? actionDate : rp.startDate;
247
- if (action.to) {
248
- const to = Number(moment(action.to).format("YYYYMMDD"));
249
- rp.endDate = to > (rp.endDate || 0) ? to : rp.endDate;
274
+ rp.startDate =
275
+ actionDate < (rp.startDate || 99999999) ? actionDate : rp.startDate;
276
+ if (toDate) {
277
+ rp.endDate = toDate > (rp.endDate || 0) ? toDate : rp.endDate;
250
278
  }
251
279
  }
252
280
  else {
253
- const endDate = action.to ? Number(moment(action.to).format("YYYYMMDD")) : null;
254
- const startDate = (actionDate || action.from) ? (Number(moment(action.from).format("YYYYMMDD")) < actionDate ? Number(moment(action.from).format("YYYYMMDD")) : actionDate) : moment().format("YYYYMMDD");
255
- referralPeriods.push(new api_1.ReferralPeriod({ startDate: startDate, endDate: endDate, comment: `New Referral to ${action.newHcp ? action.newHcp : "unknown"}` }));
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
+ }));
256
292
  }
257
293
  }
258
294
  }
259
295
  });
260
- phcp.referralPeriods = referralPeriods.sort((a, b) => (a.startDate || 0) - (b.startDate || 0));
261
- phcp.referral = !Boolean(referralPeriods[referralPeriods.length - 1].endDate) || (((_a = referralPeriods[referralPeriods.length - 1]) === null || _a === void 0 ? void 0 : _a.endDate) || 99999999) > Number(moment().format("YYYYMMDD"));
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
+ });
262
311
  return p;
263
312
  }))))
264
313
  .then(pats => this.patientApi.bulkUpdatePatients(pats || []).catch(() => {
@@ -208,7 +208,7 @@ function toInvoiceItem(nihiiHealthcareProvider, patient, invoice, invoicingCode,
208
208
  // Only applies to flatrate invoicing (https://medispring.atlassian.net/wiki/spaces/EN/pages/2536013825/Behavior+of+diabetes+pre-care+pathways+flatrate+invoicing)
209
209
  if (speciality === "medicalhouse") {
210
210
  invoiceItem.endDateCode =
211
- invoiceItem.codeNomenclature === 109594 // Diabetes pre-care pathways
211
+ (invoiceItem.codeNomenclature === 109594 || invoiceItem.codeNomenclature === 400396) // Diabetes pre-care pathways
212
212
  ? (0, formatting_util_1.dateEncode)((0, formatting_util_1.toMoment)(invoicingCode.dateCode).toDate())
213
213
  : (0, formatting_util_1.dateEncode)((0, formatting_util_1.toMoment)(invoicingCode.dateCode)
214
214
  .endOf("month")