@peopl-health/nexus 6.2.3 → 6.2.4
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/lib/core/NexusMessaging.js +18 -1
- package/package.json +1 -1
|
@@ -1086,6 +1086,8 @@ class NexusMessaging {
|
|
|
1086
1086
|
};
|
|
1087
1087
|
|
|
1088
1088
|
let runResult = null;
|
|
1089
|
+
let auditRowId = null;
|
|
1090
|
+
let sendThrew = false;
|
|
1089
1091
|
const executeTurn = () => this._executeWithPipeline(code, 'outreach', 'queue',
|
|
1090
1092
|
async (preProcessResult, shouldContinue, runId) => this.assistantProcessor.process({
|
|
1091
1093
|
code,
|
|
@@ -1106,7 +1108,7 @@ class NexusMessaging {
|
|
|
1106
1108
|
runId,
|
|
1107
1109
|
}
|
|
1108
1110
|
}),
|
|
1109
|
-
{ sendResponse: !dryRun });
|
|
1111
|
+
{ sendResponse: !dryRun, onSendSettled: async (settled) => { sendThrew = settled === 'threw'; } });
|
|
1110
1112
|
|
|
1111
1113
|
if (dryRun) {
|
|
1112
1114
|
runResult = await runInShadowScope(executeTurn);
|
|
@@ -1115,6 +1117,7 @@ class NexusMessaging {
|
|
|
1115
1117
|
messageData,
|
|
1116
1118
|
this._saveMessageFn,
|
|
1117
1119
|
async ({ _id }) => {
|
|
1120
|
+
auditRowId = _id;
|
|
1118
1121
|
runResult = await executeTurn();
|
|
1119
1122
|
if (_id) {
|
|
1120
1123
|
try {
|
|
@@ -1128,6 +1131,20 @@ class NexusMessaging {
|
|
|
1128
1131
|
);
|
|
1129
1132
|
}
|
|
1130
1133
|
|
|
1134
|
+
const result = this._outreachResult(code, runResult, { dryRun, firstName });
|
|
1135
|
+
if (auditRowId) {
|
|
1136
|
+
// A send that threw may have reached the patient in part.
|
|
1137
|
+
const outcome = { decision: result.decision, holdReason: result.holdReason, nextCheckAt: result.nextCheckAt, sent: sendThrew ? null : Boolean(result.accepted), traceId: result.traceId };
|
|
1138
|
+
try {
|
|
1139
|
+
await updateMessage({ _id: auditRowId }, { $set: { 'raw.outcome': outcome } });
|
|
1140
|
+
} catch (err) {
|
|
1141
|
+
logger.error('[processOutreach] Could not record the outreach outcome', { error: err.message, code });
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
return result;
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
_outreachResult(code, runResult, { dryRun, firstName }) {
|
|
1131
1148
|
// The pipeline returns null when the turn was superseded or a preProcess hook skipped it. That is
|
|
1132
1149
|
// not the agent choosing to stay quiet, and counting it as a hold would flatter the hold rate.
|
|
1133
1150
|
if (!runResult) {
|