@peopl-health/nexus 5.56.22 → 5.56.23

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.
@@ -273,7 +273,7 @@ const logPatientChangeController = async (req, res) => {
273
273
 
274
274
  const getPatientEscalationContextController = async (req, res) => {
275
275
  try {
276
- const context = await getEscalationContext({ code: req.params.code });
276
+ const context = await getEscalationContext({ code: req.params.code, sections: req.query?.sections ?? null });
277
277
  res.status(200).json({ success: true, context });
278
278
  } catch (error) {
279
279
  logger.error('Error fetching patient escalation context:', {
@@ -28,15 +28,26 @@ function sectionReaders(code, now) {
28
28
  };
29
29
  }
30
30
 
31
- async function getEscalationContext({ code, now = Date.now(), timeoutMs = SECTION_TIMEOUT_MS } = {}) {
31
+ function wantedSections(readers, sections) {
32
+ const names = Object.keys(readers);
33
+ if (sections == null) return names;
34
+ const asked = (Array.isArray(sections) ? sections : String(sections).split(','))
35
+ .map((name) => String(name).trim()).filter(Boolean);
36
+ if (!asked.length) return names;
37
+ const unknown = asked.find((name) => !names.includes(name));
38
+ if (unknown) throw httpError(400, `Unknown context section: ${unknown}`);
39
+ return [...new Set(asked)];
40
+ }
41
+
42
+ async function getEscalationContext({ code, sections = null, now = Date.now(), timeoutMs = SECTION_TIMEOUT_MS } = {}) {
32
43
  const patientCode = ensureWhatsAppFormat(String(code ?? '').trim());
33
44
  if (!PATIENT_CODE.test(patientCode)) throw httpError(400, 'A valid WhatsApp ID is required');
34
45
 
46
+ const readers = sectionReaders(patientCode, now);
47
+ const names = wantedSections(readers, sections);
48
+
35
49
  const patient = await withTimeout(getPatientInformation(patientCode), timeoutMs, 'patient lookup');
36
50
  if (!patient) throw httpError(404, 'Patient not found');
37
-
38
- const readers = sectionReaders(patientCode, now);
39
- const names = Object.keys(readers);
40
51
  const outcomes = await Promise.allSettled(names.map((name) => withTimeout(readers[name](), timeoutMs, name)));
41
52
 
42
53
  const context = { patientCode, asOf: new Date(now).toISOString(), degradedSections: [] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.56.22",
3
+ "version": "5.56.23",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",