@icure/be-fhc-api 0.5.13 → 0.5.14

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.5.13",
3
+ "version": "0.5.14",
4
4
  "description": "Typescript version of Freehealth Connector standalone API client",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -43,14 +43,14 @@ class MessageXApi {
43
43
  subject: "Lists request",
44
44
  senderReferences: req.commonOutput ? Object.assign(Object.assign(Object.assign({}, (req.commonOutput.inputReference ? { inputReference: req.commonOutput.inputReference } : {})), (req.commonOutput.nipReference ? { nipReference: req.commonOutput.nipReference } : {})), (req.commonOutput.outputReference ? { outputReference: req.commonOutput.outputReference } : {})) : undefined,
45
45
  })
46
- .then(msg => this.api.createMessage(msg))
46
+ .then(msg => (0, api_1.retry)(() => this.api.createMessage(msg)))
47
47
  .then(msg => {
48
48
  return this.documentXApi
49
49
  .newInstance(user, msg, {
50
50
  name: `${msg.subject}_content.json`
51
51
  })
52
- .then(doc => this.documentXApi.createDocument(doc))
53
- .then(doc => this.documentXApi.setClearDocumentAttachment(doc, (0, api_1.ua2ab)((0, api_1.utf8_2ua)(JSON.stringify(req))), ["public.json"]))
52
+ .then(doc => (0, api_1.retry)(() => this.documentXApi.createDocument(doc)))
53
+ .then(doc => (0, api_1.retry)(() => this.documentXApi.setClearDocumentAttachment(doc, (0, api_1.ua2ab)((0, api_1.utf8_2ua)(JSON.stringify(req))), ["public.json"])))
54
54
  .then(() => msg);
55
55
  });
56
56
  }
@@ -60,7 +60,7 @@ class MessageXApi {
60
60
  _.each(list.acks, ack => {
61
61
  const ref = (ack.appliesTo || "").replace("urn:nip:reference:input:", "");
62
62
  promAck = promAck
63
- .then(() => this.api.findMessagesByTransportGuid(`GMD:OUT:${ref}`, false, undefined, undefined, 100))
63
+ .then(() => (0, api_1.retry)(() => this.api.findMessagesByTransportGuid(`GMD:OUT:${ref}`, false, undefined, undefined, 100)))
64
64
  .then(parents => {
65
65
  const msgsForHcp = ((parents && parents.rows) || []).filter((p) => p.responsible === hcp.id);
66
66
  if (!msgsForHcp.length) {
@@ -69,15 +69,15 @@ class MessageXApi {
69
69
  const parent = msgsForHcp[0];
70
70
  (parent.metas || (parent.metas = {}))[`tack.${ack.io}`] = ((ack.date && moment(ack.date)) ||
71
71
  moment()).format("YYYYMMDDHHmmss");
72
- return this.api.modifyMessage(parent);
72
+ return (0, api_1.retry)(() => this.api.modifyMessage(parent));
73
73
  })
74
74
  .catch(e => {
75
75
  console.log(e.message);
76
76
  return null;
77
77
  })
78
- .then(() => this.receiptXApi.logSCReceipt(ack, user, hcp.id, "dmg", "listAck", [
78
+ .then(() => (0, api_1.retry)(() => this.receiptXApi.logSCReceipt(ack, user, hcp.id, "dmg", "listAck", [
79
79
  `nip:pin:valuehash:${ack.valueHash}`
80
- ]))
80
+ ])))
81
81
  .then(receipt => {
82
82
  ack.valueHash && ackHashes.push(ack.valueHash);
83
83
  return receipt;
@@ -118,15 +118,15 @@ class MessageXApi {
118
118
  });
119
119
  promMsg = promMsg.then(acc => {
120
120
  let ref = (dmgsMsgList.appliesTo || "").replace("urn:nip:reference:input:", "");
121
- return this.api
122
- .findMessagesByTransportGuid(`GMD:OUT:${ref}`, false, undefined, undefined, 100)
121
+ return (0, api_1.retry)(() => this.api
122
+ .findMessagesByTransportGuid(`GMD:OUT:${ref}`, false, undefined, undefined, 100))
123
123
  .then(parents => {
124
124
  const msgsForHcp = ((parents && parents.rows) || []).filter((p) => p.responsible === hcp.id);
125
125
  if (!msgsForHcp.length) {
126
126
  throw new Error(`Cannot find parent with ref ${ref}`);
127
127
  }
128
128
  const parentMessage = msgsForHcp[0];
129
- return this.saveMessageInDb(user, "List", dmgsMsgList, hcp, metas, docXApi, dmgsMsgList.date, undefined, parentMessage && parentMessage.id).then(msg => {
129
+ return (0, api_1.retry)(() => this.saveMessageInDb(user, "List", dmgsMsgList, hcp, metas, docXApi, dmgsMsgList.date, undefined, parentMessage && parentMessage.id)).then(msg => {
130
130
  dmgsMsgList.valueHash && msgHashes.push(dmgsMsgList.valueHash);
131
131
  acc.push(msg);
132
132
  return acc;
@@ -139,21 +139,19 @@ class MessageXApi {
139
139
  });
140
140
  });
141
141
  _.each(list.closures, closure => {
142
- const metas = {
142
+ const metas = Object.entries({
143
143
  type: "closure",
144
- date: (closure.endOfPreviousDmg && moment(closure.endOfPreviousDmg).format("DD/MM/YYYY")) ||
145
- null,
144
+ date: (closure.endOfPreviousDmg && moment(closure.endOfPreviousDmg).format("DD/MM/YYYY")),
146
145
  closure: "true",
147
- endOfPreviousDmg: (closure.endOfPreviousDmg && moment(closure.endOfPreviousDmg).format("DD/MM/YYYY")) ||
148
- null,
149
- beginOfNewDmg: (closure.beginOfNewDmg && moment(closure.beginOfNewDmg).format("DD/MM/YYYY")) || null,
146
+ endOfPreviousDmg: (closure.endOfPreviousDmg && moment(closure.endOfPreviousDmg).format("DD/MM/YYYY")),
147
+ beginOfNewDmg: (closure.beginOfNewDmg && moment(closure.beginOfNewDmg).format("DD/MM/YYYY")),
150
148
  previousHcp: this.makeHcp(closure.previousHcParty),
151
149
  newHcp: this.makeHcp(closure.newHcParty),
152
- ssin: closure.inss || null,
153
- firstName: closure.firstName || null,
154
- lastName: closure.lastName || null,
155
- io: closure.io || null
156
- };
150
+ ssin: closure.inss,
151
+ firstName: closure.firstName,
152
+ lastName: closure.lastName,
153
+ io: closure.io
154
+ }).reduce((acc, [k, v]) => !!v ? Object.assign(Object.assign({}, acc), { [k]: v }) : acc, {});
157
155
  closure.inss && (patsDmgs[closure.inss] || (patsDmgs[closure.inss] = [])).push(metas);
158
156
  promMsg = promMsg.then(acc => {
159
157
  return this.saveMessageInDb(user, "Closure", closure, hcp, metas, docXApi, closure.endOfPreviousDmg, closure.inss).then(msg => {
@@ -164,17 +162,17 @@ class MessageXApi {
164
162
  });
165
163
  });
166
164
  _.each(list.extensions, ext => {
167
- const metas = {
165
+ const metas = Object.entries({
168
166
  type: "extension",
169
- date: (ext.encounterDate && moment(ext.encounterDate).format("DD/MM/YYYY")) || null,
170
- from: (ext.encounterDate && moment(ext.encounterDate).format("DD/MM/YYYY")) || null,
167
+ date: (ext.encounterDate && moment(ext.encounterDate).format("DD/MM/YYYY")),
168
+ from: (ext.encounterDate && moment(ext.encounterDate).format("DD/MM/YYYY")),
171
169
  hcp: this.makeHcp(ext.hcParty),
172
- claim: ext.claim || null,
173
- ssin: ext.inss || null,
174
- firstName: ext.firstName || null,
175
- lastName: ext.lastName || null,
176
- io: ext.io || null
177
- };
170
+ claim: ext.claim,
171
+ ssin: ext.inss,
172
+ firstName: ext.firstName,
173
+ lastName: ext.lastName,
174
+ io: ext.io
175
+ }).reduce((acc, [k, v]) => !!v ? Object.assign(Object.assign({}, acc), { [k]: v }) : acc, {});
178
176
  ext.inss && (patsDmgs[ext.inss] || (patsDmgs[ext.inss] = [])).push(metas);
179
177
  promMsg = promMsg.then(acc => {
180
178
  return this.saveMessageInDb(user, "Extension", ext, hcp, metas, docXApi, ext.encounterDate, ext.inss).then(msg => {
@@ -188,14 +186,14 @@ class MessageXApi {
188
186
  return promMsg.then(() => {
189
187
  _.chunk(Object.keys(patsDmgs), 100).forEach(ssins => {
190
188
  promPatient = promPatient
191
- .then(() => this.patientApi
189
+ .then(() => (0, api_1.retry)(() => this.patientApi
192
190
  .filterPatientsBy(undefined, undefined, 1000, 0, undefined, false, new api_1.FilterChainPatient({
193
191
  filter: new api_1.AbstractFilterPatient({
194
192
  $type: "PatientByHcPartyAndSsinsFilter",
195
193
  healthcarePartyId: parentId || hcp.parentId || hcp.id || user.healthcarePartyId,
196
194
  ssins: ssins
197
195
  })
198
- }))
196
+ })))
199
197
  .then((pats) => Promise.all((pats.rows || []).map(p => {
200
198
  const actions = _.sortBy(patsDmgs[p.ssin], a => moment(a.date, "DD/MM/YYYY").format("YYYYMMDD"));
201
199
  let phcp = (p.patientHealthCareParties || (p.patientHealthCareParties = [])) &&
@@ -309,14 +307,14 @@ class MessageXApi {
309
307
  });
310
308
  return p;
311
309
  }))))
312
- .then(pats => this.patientApi.bulkUpdatePatients(pats || []).catch(() => {
310
+ .then(pats => (0, api_1.retry)(() => this.patientApi.bulkUpdatePatients(pats || []).catch(() => {
313
311
  let catchProm = Promise.resolve([]);
314
312
  let newPats = [];
315
313
  (pats || []).forEach((pat) => {
316
314
  catchProm = catchProm.then(() => this.patientApi.modifyPatient(pat).then(p => (newPats = newPats.concat(p))));
317
315
  });
318
316
  return catchProm;
319
- }));
317
+ })));
320
318
  });
321
319
  return promPatient.then(() => [ackHashes, msgHashes]);
322
320
  });
@@ -348,14 +346,14 @@ class MessageXApi {
348
346
  : `${msgName} from IO ${dmgMessage.io}`,
349
347
  senderReferences: dmgMessage.commonOutput ? Object.assign(Object.assign(Object.assign({}, (dmgMessage.commonOutput.inputReference ? { inputReference: dmgMessage.commonOutput.inputReference } : {})), (dmgMessage.commonOutput.nipReference ? { nipReference: dmgMessage.commonOutput.nipReference } : {})), (dmgMessage.commonOutput.outputReference ? { outputReference: dmgMessage.commonOutput.outputReference } : {})) : undefined
350
348
  })
351
- .then(msg => this.api.createMessage(msg))
349
+ .then(msg => (0, api_1.retry)(() => this.api.createMessage(msg)))
352
350
  .then(msg => {
353
351
  return docXApi
354
352
  .newInstance(user, msg, {
355
353
  name: `${msg.subject}_content.json`
356
354
  })
357
- .then(doc => docXApi.createDocument(doc))
358
- .then(doc => docXApi.setClearDocumentAttachment(doc, (0, api_1.ua2ab)((0, api_1.utf8_2ua)(JSON.stringify(dmgMessage))), ["public.json"]))
355
+ .then(doc => (0, api_1.retry)(() => docXApi.createDocument(doc)))
356
+ .then(doc => (0, api_1.retry)(() => docXApi.setClearDocumentAttachment(doc, (0, api_1.ua2ab)((0, api_1.utf8_2ua)(JSON.stringify(dmgMessage))), ["public.json"])))
359
357
  .then(() => msg);
360
358
  });
361
359
  }
@@ -751,32 +749,32 @@ class MessageXApi {
751
749
  .then(invoices => {
752
750
  parentMessage.status = (parentMessage.status || 0) | statuses;
753
751
  if (batchErrors.length) {
754
- parentMessage.metas = _.assign(parentMessage.metas || {}, {
752
+ parentMessage.metas = Object.entries(_.assign(parentMessage.metas || {}, {
755
753
  errors: _(batchErrors)
756
754
  .map(this.extractErrorMessage)
757
755
  .uniq()
758
756
  .compact()
759
757
  .value()
760
758
  .join("; ")
761
- });
759
+ })).reduce((acc, [k, v]) => !!v ? Object.assign(Object.assign({}, acc), { [k]: v }) : acc, {});
762
760
  }
763
761
  if (parsedRecords.et91) {
764
762
  let et91s = parsedRecords.et91;
765
- parentMessage.metas = _.assign(parentMessage.metas || {}, {
763
+ parentMessage.metas = Object.entries(_.assign(parentMessage.metas || {}, {
766
764
  paymentReferenceAccount1: _(et91s)
767
765
  .map(et91 => et91.paymentReferenceAccount1)
768
766
  .uniq()
769
767
  .value()
770
768
  .join(", ")
771
- });
769
+ })).reduce((acc, [k, v]) => !!v ? Object.assign(Object.assign({}, acc), { [k]: v }) : acc, {});
772
770
  }
773
771
  if (parsedRecords.et92) {
774
772
  let et92 = parsedRecords.et92;
775
- parentMessage.metas = _.assign(parentMessage.metas || {}, {
773
+ parentMessage.metas = Object.entries(_.assign(parentMessage.metas || {}, {
776
774
  totalAskedAmount: Number(et92.totalAskedAmount) / 100,
777
775
  totalAcceptedAmount: Number(et92.totalAcceptedAmount) / 100,
778
776
  totalRejectedAmount: Number(et92.totalRejectedAmount) / 100
779
- });
777
+ })).reduce((acc, [k, v]) => !!v ? Object.assign(Object.assign({}, acc), { [k]: v }) : acc, {});
780
778
  }
781
779
  return this.api
782
780
  .modifyMessage(parentMessage)
@@ -859,7 +857,7 @@ class MessageXApi {
859
857
  .then(message => this.api.createMessage(Object.assign(message, {
860
858
  sent: sentDate,
861
859
  status: (message.status || 0) | (res.success ? 1 << 7 : 0) /*STATUS_SENT*/,
862
- metas: {
860
+ metas: Object.entries({
863
861
  ioFederationCode: batch.ioFederationCode,
864
862
  numericalRef: batch.numericalRef,
865
863
  invoiceMonth: _.padStart("" + batch.invoicingMonth, 2, "0"),
@@ -867,7 +865,7 @@ class MessageXApi {
867
865
  totalAmount: totalAmount,
868
866
  fhc_server: fhcServer,
869
867
  errors: res.error
870
- }
868
+ }).reduce((acc, [k, v]) => !!v ? Object.assign(Object.assign({}, acc), { [k]: v }) : acc, {})
871
869
  })))
872
870
  .then((msg) => {
873
871
  if (res.success) {