@peopl-health/nexus 6.2.1 → 6.3.0-dev.18358
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.
|
@@ -57,6 +57,7 @@ const graveDueAt = (review, clock, flag) => {
|
|
|
57
57
|
function outcomeOf(review, clock, now) {
|
|
58
58
|
const wait = pendingWaitMinutes(clock?.level);
|
|
59
59
|
if (!wait || !OUTCOME_LEVELS.includes(clock.level) || !['draft_ready', 'awaiting_doctor'].includes(review.status)) return null;
|
|
60
|
+
// Handoffs count since the last decision, so a higher alarm on a case already with the doctor goes as an update.
|
|
60
61
|
const decidedAt = Math.max(0, ...(review.decisions ?? []).map((decision) => timeOf(decision.createdAt)));
|
|
61
62
|
const handoffs = (review.doctorHandoffs ?? []).filter((handoff) => timeOf(handoff.createdAt) > decidedAt);
|
|
62
63
|
const last = handoffs.at(-1);
|
|
@@ -73,7 +74,7 @@ function outcomeOf(review, clock, now) {
|
|
|
73
74
|
const present = latest.urgentPresentRedFlags ?? [];
|
|
74
75
|
// An update reaches the doctor's phone only with a grave flag the draft they have did not show; the panel always shows the latest draft.
|
|
75
76
|
const handedPresent = new Set((update ? review.drafts[last.draftNumber - 1]?.urgentPresentRedFlags ?? [] : []).map(flagKey));
|
|
76
|
-
//
|
|
77
|
+
// A higher alarm already rang the doctor's phone since the last handoff, so its update shows in the panel only; Airtable's alert goes to the team.
|
|
77
78
|
const raisedSince = (level) => (review.alarms ?? []).some((alarm) => alarm.urgencyLevel === level && timeOf(alarm.raisedAt) > timeOf(last.createdAt));
|
|
78
79
|
const rangSince = update && (review.doctorAlerts ?? []).some((sent) => sent.kind === 'initial' && !sent.error
|
|
79
80
|
&& sent.transport && sent.transport !== 'airtable' && timeOf(sent.sentAt) > timeOf(last.createdAt) && raisedSince(sent.urgencyLevel));
|
|
@@ -1030,7 +1030,7 @@ async function caseTakenReason(review, from, level) {
|
|
|
1030
1030
|
const changes = review.urgencyReclassifications ?? [];
|
|
1031
1031
|
const levelsAt = (at) => levelsOf(currentAlarms(review).filter((alarm) => new Date(alarm.raisedAt) <= new Date(at)), changes.filter((change) => new Date(change.at) < new Date(at)), appliedLevelOf);
|
|
1032
1032
|
if (level !== 'stat' && levelsAt(new Date(8.64e15)).some((entry) => entry.level === 'stat')) return 'stat_alarm';
|
|
1033
|
-
//
|
|
1033
|
+
// Lowering the level, from what this episode's alarms were at, means someone looked at the case; a raise restarts the clock instead.
|
|
1034
1034
|
const lowered = (change) => (URGENCY_RANK[change.toLevel] || 0) < Math.max(0, ...levelsAt(change.at).map((entry) => URGENCY_RANK[entry.level] || 0));
|
|
1035
1035
|
if (changes.some((change) => atOrAfter(change.at) && lowered(change))) return 'reclassified';
|
|
1036
1036
|
if ((review.callLogs ?? []).some((call) => call.outcome === 'contacted' && atOrAfter(call.calledAt))) return 'call_contacted';
|
|
@@ -20,6 +20,7 @@ function pendingFlagsOf(review, since) {
|
|
|
20
20
|
return { latest: drafts.at(-1) ?? null, flags: [...firstSeen].map(([flag, firstSeenAt]) => ({ flag, firstSeenAt, unobtainable: unobtainable.includes(flag) })) };
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
// The bot keeps documenting a case it handed to the doctor itself while it still redrafts it, so its grave questions still wait for the patient there.
|
|
23
24
|
const stillDocumented = (review) => DOCUMENTING_STATUSES.includes(review.status) || updatesDoctor(review);
|
|
24
25
|
|
|
25
26
|
// The latest draft speaks for the case only while no newer patient turn or redraft is waiting to replace it.
|
|
@@ -45,7 +45,7 @@ function responseDeadlinePolicy() {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
//
|
|
48
|
+
// Each alarm at the level the team set for it since it was raised; a raise restarts its clock, a lowering keeps it.
|
|
49
49
|
function levelsOf(alarms, reclassifications, startLevel = (alarm) => alarm.urgencyLevel) {
|
|
50
50
|
const changes = [...(reclassifications ?? [])].sort((a, b) => timeOf(a.at) - timeOf(b.at));
|
|
51
51
|
return (alarms ?? []).map((alarm) => changes
|
|
@@ -34,7 +34,8 @@ const duration = (minutes) => {
|
|
|
34
34
|
return rest ? `${hours} h ${rest} min` : `${hours} h`;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
//
|
|
37
|
+
// The clock runs at the highest level since the last decision, its stages from the first alarm or team raise at that level.
|
|
38
|
+
// The episode keeps the start the alarms' own levels give it, so a reclassification never re-keys its drafts or grave alerts.
|
|
38
39
|
function episodeStartOf(alarms) {
|
|
39
40
|
const top = alarms.reduce((level, alarm) => ((URGENCY_RANK[appliedLevelOf(alarm)] || 0) > (URGENCY_RANK[level] || 0) ? appliedLevelOf(alarm) : level), null);
|
|
40
41
|
return new Date(Math.min(...alarms.filter((alarm) => appliedLevelOf(alarm) === top).map((alarm) => new Date(alarm.raisedAt).getTime())));
|