@peopl-health/nexus 5.55.0 → 5.56.0-dev.8490
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.
|
@@ -428,6 +428,27 @@ async function markInvitedCandidateDeclined({ patientId, service, preference = '
|
|
|
428
428
|
}, { new: true });
|
|
429
429
|
}
|
|
430
430
|
|
|
431
|
+
const ANSWERABLE_INVITATION = [
|
|
432
|
+
{ activeInvitationKey: null, cooldownInvitationKey: { $ne: null }, 'engagement.state': 'invited' },
|
|
433
|
+
{ activeInvitationKey: { $ne: null }, cooldownInvitationKey: null, 'engagement.state': 'notInvited' },
|
|
434
|
+
];
|
|
435
|
+
|
|
436
|
+
async function recordSentInvitationResponse({ patientId, service, outcome, sessionId = null, preference = 'not_now' }, { Model = getSupportCandidateModel() } = {}) {
|
|
437
|
+
if (!['accepted', 'declined'].includes(outcome)) throw new Error(`invalid invitation outcome: ${outcome}`);
|
|
438
|
+
if (outcome === 'accepted' && !sessionId) throw new Error('sessionId is required for an acceptance');
|
|
439
|
+
if (outcome === 'declined' && !['another_date', 'not_now', 'never'].includes(preference)) {
|
|
440
|
+
throw new Error(`invalid decline preference: ${preference}`);
|
|
441
|
+
}
|
|
442
|
+
const patch = outcome === 'accepted'
|
|
443
|
+
? engagementPatch('registered', sessionId, new Date(), null)
|
|
444
|
+
: engagementPatch('declined', null, new Date(), preference);
|
|
445
|
+
return Model.findOneAndUpdate({
|
|
446
|
+
patientId,
|
|
447
|
+
service,
|
|
448
|
+
$or: ANSWERABLE_INVITATION,
|
|
449
|
+
}, { $set: patch, $inc: { revision: 1 } }, { new: true });
|
|
450
|
+
}
|
|
451
|
+
|
|
431
452
|
async function recordLegacyInvitationResponse({ patientId, service, outcome, sessionId = null, preference = 'not_now' }, options = {}) {
|
|
432
453
|
if (outcome === 'accepted') {
|
|
433
454
|
if (!sessionId) throw new Error('sessionId is required for a legacy acceptance');
|
|
@@ -520,6 +541,7 @@ async function readSupportDashboardCandidates() {
|
|
|
520
541
|
}
|
|
521
542
|
|
|
522
543
|
module.exports = {
|
|
544
|
+
recordSentInvitationResponse,
|
|
523
545
|
updateSupportOperationalReview,
|
|
524
546
|
readSupportDashboardCandidates,
|
|
525
547
|
approveCandidate,
|
package/lib/index.d.ts
CHANGED
|
@@ -876,6 +876,13 @@ declare module '@peopl-health/nexus' {
|
|
|
876
876
|
sessionId?: string | null;
|
|
877
877
|
preference?: 'another_date' | 'not_now' | 'never';
|
|
878
878
|
}, options?: { Model?: unknown }): Promise<SupportCandidateRecord | null>;
|
|
879
|
+
recordSentInvitationResponse(request: {
|
|
880
|
+
patientId: string;
|
|
881
|
+
service: SupportService;
|
|
882
|
+
outcome: 'accepted' | 'declined';
|
|
883
|
+
sessionId?: string | null;
|
|
884
|
+
preference?: 'another_date' | 'not_now' | 'never';
|
|
885
|
+
}, options?: { Model?: unknown }): Promise<SupportCandidateRecord | null>;
|
|
879
886
|
recordSupportRoutingRecommendation(recommendation: SupportRoutingRecommendationInput, options?: { Model?: unknown }): Promise<SupportCandidateRecord[]>;
|
|
880
887
|
rescheduleDeclinedCandidate(candidateId: string, options?: { Model?: unknown }): Promise<SupportCandidateRecord | null>;
|
|
881
888
|
settleInvitation(request: {
|