@icure/be-fhc-api 0.4.37 → 0.4.39

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.37",
3
+ "version": "0.4.39",
4
4
  "description": "Typescript version of Freehealth Connector standalone API client",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -197,35 +197,68 @@ class MessageXApi {
197
197
  ssins: ssins
198
198
  })
199
199
  }))
200
- .then((pats) => Promise.resolve((pats.rows || []).map(p => {
200
+ .then((pats) => Promise.all((pats.rows || []).map(p => {
201
+ var _a;
201
202
  const actions = _.sortBy(patsDmgs[p.ssin], a => moment(a.date, "DD/MM/YYYY").format("YYYYMMDD"));
202
- const latestAction = actions.length && actions[actions.length - 1];
203
203
  let phcp = (p.patientHealthCareParties || (p.patientHealthCareParties = [])) &&
204
204
  p.patientHealthCareParties.find(phcp => phcp.healthcarePartyId === user.healthcarePartyId);
205
205
  if (!phcp) {
206
- p.patientHealthCareParties.push((phcp = new api_1.PatientHealthCareParty({
207
- healthcarePartyId: user.healthcarePartyId,
208
- referralPeriods: []
209
- })));
206
+ phcp = new api_1.PatientHealthCareParty({ healthcarePartyId: user.healthcarePartyId, referralPeriods: [] });
207
+ p.patientHealthCareParties.push(phcp);
210
208
  }
211
209
  if (!phcp.referralPeriods) {
212
210
  phcp.referralPeriods = [];
213
211
  }
214
- const rp = (phcp.referralPeriods && phcp.referralPeriods.find(per => !per.endDate)) ||
215
- (phcp.referralPeriods[phcp.referralPeriods.length] = new api_1.ReferralPeriod({}));
216
- const actionDate = Number(moment(latestAction.date, "DD/MM/YYYY").format("YYYYMMDD"));
217
- if (latestAction) {
218
- if (latestAction.closure) {
219
- rp.endDate = actionDate;
220
- rp.comment = `-> ${latestAction.newHcp}`;
221
- }
222
- else {
223
- if (actionDate > (rp.startDate || 0)) {
224
- rp.endDate = actionDate;
225
- phcp.referralPeriods.push(new api_1.ReferralPeriod({ startDate: actionDate }));
212
+ const referralPeriods = phcp.referralPeriods;
213
+ actions.map(action => {
214
+ 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"))));
218
+ if (action) {
219
+ if (action.closure) {
220
+ 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;
224
+ }
225
+ if (action.to) {
226
+ const to = Number(moment(action.to).format("YYYYMMDD"));
227
+ rp.endDate = to > (rp.endDate || 0) ? to : rp.endDate;
228
+ }
229
+ rp.endDate = actionDate > (rp.endDate || 0) ? actionDate : rp.endDate;
230
+ if (action.newHcp) {
231
+ rp.comment = (rp.comment + ' ' || '') + `Transferred to ${action.newHcp}`;
232
+ }
233
+ }
234
+ 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"}` }));
238
+ }
239
+ }
240
+ else {
241
+ 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;
245
+ }
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;
250
+ }
251
+ }
252
+ 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"}` }));
256
+ }
226
257
  }
227
258
  }
228
- }
259
+ });
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"));
229
262
  return p;
230
263
  }))))
231
264
  .then(pats => this.patientApi.bulkUpdatePatients(pats || []).catch(() => {