@peopl-health/nexus 6.5.11 → 6.5.12
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.
|
@@ -8,6 +8,7 @@ const { PATIENT_CODE, redactDirectIdentifiers } = require('../utils/sanitizerUti
|
|
|
8
8
|
const { ageInYears, isoDay, mexicoDay } = require('../utils/dateUtils');
|
|
9
9
|
const { safeParse } = require('../utils/jsonUtils');
|
|
10
10
|
const { MAX_TEMPLATE_TEXT_LENGTH } = require('../utils/templateUtils');
|
|
11
|
+
const { mexicanPhoneForDisplay } = require('../utils/formatUtils');
|
|
11
12
|
const {
|
|
12
13
|
CALL_OUTCOMES,
|
|
13
14
|
CANCELLABLE_AFTER_HANDOFF_STATUSES,
|
|
@@ -1204,7 +1205,7 @@ async function sendPatientPrompt({ id, release, lease, now }) {
|
|
|
1204
1205
|
|
|
1205
1206
|
let directive;
|
|
1206
1207
|
try {
|
|
1207
|
-
directive = String((await composePrompt({ promptId: timer.promptId }))?.resolvedPrompt ?? '').trim();
|
|
1208
|
+
directive = String((await composePrompt({ promptId: timer.promptId, variables: await primaryDoctorVariables(review) }))?.resolvedPrompt ?? '').trim();
|
|
1208
1209
|
} catch (composeError) {
|
|
1209
1210
|
// A failed read may be transient: the same slot comes back shortly, and the sweep's attempt cap
|
|
1210
1211
|
// drops it (with a ledger entry) if Airtable stays unreachable.
|
|
@@ -1787,6 +1788,16 @@ async function addDraft({ id, doctorText, patientMessage, writtenBy, requestId =
|
|
|
1787
1788
|
return review;
|
|
1788
1789
|
}
|
|
1789
1790
|
|
|
1791
|
+
async function primaryDoctorVariables(review) {
|
|
1792
|
+
try {
|
|
1793
|
+
const approver = await notifiedApprover();
|
|
1794
|
+
return { medico_principal_nombre: approver.name, medico_principal_telefono: mexicanPhoneForDisplay(approver.phone) };
|
|
1795
|
+
} catch (error) {
|
|
1796
|
+
logger.error('[EscalationReview] The primary doctor could not be read or chosen; the patient prompt goes without one', { escalationReviewId: String(review._id), error: redactedError(error) });
|
|
1797
|
+
return {};
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1790
1801
|
async function notifiedApprover() {
|
|
1791
1802
|
const approvers = await listEscalationApprovers();
|
|
1792
1803
|
if (!approvers.length) {
|
package/lib/utils/formatUtils.js
CHANGED
|
@@ -42,6 +42,16 @@ function stripSpreadsheetErrorsDeep(value, options = {}) {
|
|
|
42
42
|
return value;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
// Mexico's two-digit area codes (Guadalajara, Mexico City, Monterrey); the rest have three digits.
|
|
46
|
+
const TWO_DIGIT_AREA_CODES = new Set(['33', '55', '56', '81']);
|
|
47
|
+
|
|
48
|
+
function mexicanPhoneForDisplay(phone) {
|
|
49
|
+
const national = String(phone ?? '').replace(/\D/g, '').match(/^521?(\d{10})$/)?.[1];
|
|
50
|
+
if (!national) return String(phone ?? '').trim();
|
|
51
|
+
const area = TWO_DIGIT_AREA_CODES.has(national.slice(0, 2)) ? 2 : 3;
|
|
52
|
+
return `+52 ${national.slice(0, area)} ${national.slice(area, 6)} ${national.slice(6)}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
45
55
|
function usableText(value) {
|
|
46
56
|
if (value === null || value === undefined) return '';
|
|
47
57
|
const text = typeof value === 'string' ? value : String(value);
|
|
@@ -54,5 +64,6 @@ module.exports = {
|
|
|
54
64
|
hasSpreadsheetError,
|
|
55
65
|
stripSpreadsheetErrors,
|
|
56
66
|
stripSpreadsheetErrorsDeep,
|
|
67
|
+
mexicanPhoneForDisplay,
|
|
57
68
|
usableText
|
|
58
69
|
};
|