@icure/be-fhc-api 0.4.37 → 0.4.38

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.38",
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,41 @@ 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
201
  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
- let phcp = (p.patientHealthCareParties || (p.patientHealthCareParties = [])) &&
204
- p.patientHealthCareParties.find(phcp => phcp.healthcarePartyId === user.healthcarePartyId);
205
- if (!phcp) {
206
- p.patientHealthCareParties.push((phcp = new api_1.PatientHealthCareParty({
207
- healthcarePartyId: user.healthcarePartyId,
208
- referralPeriods: []
209
- })));
210
- }
202
+ let phcp = ((p.patientHealthCareParties || (p.patientHealthCareParties = [])) &&
203
+ p.patientHealthCareParties.find(phcp => phcp.healthcarePartyId === user.healthcarePartyId)) || new api_1.PatientHealthCareParty({ healthcarePartyId: user.healthcarePartyId, referralPeriods: [] });
211
204
  if (!phcp.referralPeriods) {
212
205
  phcp.referralPeriods = [];
213
206
  }
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 }));
207
+ const referralPeriods = phcp.referralPeriods;
208
+ actions.map(action => {
209
+ const actionDate = Number(moment((action === null || action === void 0 ? void 0 : action.date) || "", "DD/MM/YYYY").format("YYYYMMDD"));
210
+ if (action) {
211
+ 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
+ if (rp) {
214
+ rp.comment = (rp.comment + ' ' || '') + (rp.endDate ? "Correction End Date. " : "") + `Transferred to ${action.newHcp}`;
215
+ rp.endDate = actionDate;
216
+ }
217
+ else {
218
+ referralPeriods.push(new api_1.ReferralPeriod({ startDate: Number(moment().format("YYYYMMDD")), endDate: actionDate, comment: `No start Date Info. Transferred to ${action.newHcp}` }));
219
+ }
220
+ }
221
+ else {
222
+ const rp = referralPeriods.find(per => (!per.endDate || per.endDate > actionDate) && ((per === null || per === void 0 ? void 0 : per.startDate) || 0) < actionDate);
223
+ if (rp) {
224
+ rp.startDate = actionDate < (rp.startDate || 0) ? actionDate : rp.startDate;
225
+ rp.comment = (rp.comment + ' ' || '') + 'Correction Start Date.';
226
+ }
227
+ else {
228
+ referralPeriods.push(new api_1.ReferralPeriod({ startDate: actionDate, comment: `New Referral to ${action.newHcp}` }));
229
+ }
226
230
  }
227
231
  }
228
- }
232
+ });
233
+ phcp.referralPeriods = referralPeriods.sort((a, b) => (a.startDate || 0) - (b.startDate || 0));
234
+ phcp.referral = !Boolean(referralPeriods[referralPeriods.length - 1].endDate);
229
235
  return p;
230
236
  }))))
231
237
  .then(pats => this.patientApi.bulkUpdatePatients(pats || []).catch(() => {