@peopl-health/nexus 5.55.0-dev.8193 → 5.55.0-dev.8213
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.
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
const { SupportAction } = require('../../shared/dtos/SupportAction');
|
|
2
2
|
const { logger } = require('../../utils/logger');
|
|
3
3
|
const { claimInvitation, recordEngagement, updateSupportOperationalReview } = require('./supportCandidateService');
|
|
4
|
+
const { isSafeGroupCandidate } = require('./supportInvitability');
|
|
4
5
|
|
|
5
6
|
const TEMPLATE_VERSION = 'support-card-v1';
|
|
6
7
|
const URGENT_NUTRITION_TARGET = 'nutrition.urgent_intake';
|
|
7
8
|
|
|
8
|
-
function isSafeGroupCandidate(candidate) {
|
|
9
|
-
if (!candidate.groupEligible) return false;
|
|
10
|
-
return candidate.service === 'nutrition'
|
|
11
|
-
? (candidate.nutritionRisk === 'green' && candidate.disposition === 'group')
|
|
12
|
-
|| (candidate.nutritionRisk === 'yellow' && candidate.disposition === 'individual')
|
|
13
|
-
: candidate.disposition === 'group' && candidate.psychologyRisk === 'green';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
9
|
function isUrgentNutritionCandidate(candidate) {
|
|
17
10
|
return candidate.service === 'nutrition'
|
|
18
11
|
&& candidate.nutritionRisk === 'yellow'
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { v4: uuidv4 } = require('uuid');
|
|
2
2
|
|
|
3
3
|
const { getSupportCandidateModel } = require('../models/supportCandidateModel');
|
|
4
|
+
const { GROUP_INVITABLE } = require('./supportInvitability');
|
|
4
5
|
const { SupportRoutingRecommendation } = require('../../shared/dtos/SupportRoutingRecommendation');
|
|
5
6
|
|
|
6
7
|
const COOLDOWN_MS = 14 * 24 * 60 * 60 * 1000;
|
|
@@ -494,10 +495,16 @@ async function clearCandidateEscalation(candidateId, {
|
|
|
494
495
|
);
|
|
495
496
|
}
|
|
496
497
|
|
|
498
|
+
// The states claimEligibility accepts. 'declined' is absent from both; the rest stay so a
|
|
499
|
+
// specialist can see who was already invited and not invite them twice.
|
|
500
|
+
const INVITABLE_ENGAGEMENT = { 'engagement.state': { $in: ['notInvited', 'invited', 'registered', 'attended'] } };
|
|
501
|
+
|
|
502
|
+
|
|
497
503
|
async function readSupportDashboardCandidates() {
|
|
498
504
|
const rows = await getSupportCandidateModel().find({
|
|
499
505
|
service: { $in: ['nutrition', 'psychology'] },
|
|
500
506
|
$or: [
|
|
507
|
+
...GROUP_INVITABLE.map((clause) => ({ ...INVITABLE_ENGAGEMENT, ...clause })),
|
|
501
508
|
{ disposition: { $in: ['reviewRequired', 'escalated'] } },
|
|
502
509
|
{ service: 'psychology', disposition: 'individual', psychologyRisk: 'orange' },
|
|
503
510
|
{ 'operationalReviews.0': { $exists: true } },
|
|
@@ -505,7 +512,9 @@ async function readSupportDashboardCandidates() {
|
|
|
505
512
|
{ invitationAttempts: { $elemMatch: { status: { $in: ['failed', 'unknown'] } } } },
|
|
506
513
|
],
|
|
507
514
|
})
|
|
508
|
-
|
|
515
|
+
// No `evidence`: reasonCodes carry the "why" as stable snake_case, so the patient's own
|
|
516
|
+
// wording never leaves the clinical store.
|
|
517
|
+
.select('-_id candidateId patientId service disposition groupEligible nutritionRisk psychologyRisk confidence priority engagement.state engagement.lastInvitedAt engagement.cooldownUntil activeInvitationKey escalation operationalReviews operationalReviewOverflow reasonCodes createdAt lastEvaluatedAt invitationAttempts.invitationCycle invitationAttempts.status invitationAttempts.createdAt')
|
|
509
518
|
.limit(1001).maxTimeMS(10000).lean();
|
|
510
519
|
if (rows.length > 1000) throw new Error('Support dashboard candidates incomplete');
|
|
511
520
|
return rows;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* Who may be invited to a collective support session.
|
|
2
|
+
*
|
|
3
|
+
* Lives apart from supportCandidateService and supportActionService because those two are
|
|
4
|
+
* mocked by each other's tests, and a safety rule that can be mocked away is not a rule.
|
|
5
|
+
*
|
|
6
|
+
* A nutrition yellow is invitable at disposition 'individual': routing sends it to an
|
|
7
|
+
* individual consult and keeps it group-eligible at the same time.
|
|
8
|
+
*/
|
|
9
|
+
const GROUP_INVITABLE = Object.freeze([
|
|
10
|
+
Object.freeze({ service: 'nutrition', groupEligible: true, nutritionRisk: 'green', disposition: 'group' }),
|
|
11
|
+
Object.freeze({ service: 'nutrition', groupEligible: true, nutritionRisk: 'yellow', disposition: 'individual' }),
|
|
12
|
+
Object.freeze({ service: 'psychology', groupEligible: true, psychologyRisk: 'green', disposition: 'group' }),
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
function isSafeGroupCandidate(candidate) {
|
|
16
|
+
return GROUP_INVITABLE.some((clause) => Object.entries(clause)
|
|
17
|
+
.every(([field, value]) => candidate[field] === value));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = { GROUP_INVITABLE, isSafeGroupCandidate };
|