mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage-server
synced 2026-05-18 20:08:19 +00:00
feat: rules engine — json-rules-engine integration with worklist scoring
- Self-contained NestJS module: types, storage (Redis+JSON), fact providers, action handlers - PriorityConfig CRUD (slider values for task weights, campaign weights, source weights) - Score action handler with SLA multiplier + campaign multiplier formula - Worklist consumer: scores and ranks items before returning - Hospital starter template (7 rules) - REST API: /api/rules/* (CRUD, priority-config, evaluate, templates) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
12
src/rules-engine/actions/assign.action.ts
Normal file
12
src/rules-engine/actions/assign.action.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
// src/rules-engine/actions/assign.action.ts
|
||||
|
||||
import type { ActionHandler, ActionResult } from '../types/action.types';
|
||||
import type { RuleAction } from '../types/rule.types';
|
||||
|
||||
export class AssignActionHandler implements ActionHandler {
|
||||
type = 'assign';
|
||||
|
||||
async execute(_action: RuleAction, _context: Record<string, any>): Promise<ActionResult> {
|
||||
return { success: true, data: { stub: true, action: 'assign' } };
|
||||
}
|
||||
}
|
||||
12
src/rules-engine/actions/escalate.action.ts
Normal file
12
src/rules-engine/actions/escalate.action.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
// src/rules-engine/actions/escalate.action.ts
|
||||
|
||||
import type { ActionHandler, ActionResult } from '../types/action.types';
|
||||
import type { RuleAction } from '../types/rule.types';
|
||||
|
||||
export class EscalateActionHandler implements ActionHandler {
|
||||
type = 'escalate';
|
||||
|
||||
async execute(_action: RuleAction, _context: Record<string, any>): Promise<ActionResult> {
|
||||
return { success: true, data: { stub: true, action: 'escalate' } };
|
||||
}
|
||||
}
|
||||
33
src/rules-engine/actions/score.action.ts
Normal file
33
src/rules-engine/actions/score.action.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
// src/rules-engine/actions/score.action.ts
|
||||
|
||||
import type { ActionHandler, ActionResult } from '../types/action.types';
|
||||
import type { RuleAction, ScoreActionParams } from '../types/rule.types';
|
||||
import { computeSlaMultiplier } from '../facts/call-facts.provider';
|
||||
|
||||
export class ScoreActionHandler implements ActionHandler {
|
||||
type = 'score';
|
||||
|
||||
async execute(action: RuleAction, context: Record<string, any>): Promise<ActionResult> {
|
||||
const params = action.params as ScoreActionParams;
|
||||
let score = params.weight;
|
||||
let slaApplied = false;
|
||||
let campaignApplied = false;
|
||||
|
||||
if (params.slaMultiplier && context['call.slaElapsedPercent'] != null) {
|
||||
score *= computeSlaMultiplier(context['call.slaElapsedPercent']);
|
||||
slaApplied = true;
|
||||
}
|
||||
|
||||
if (params.campaignMultiplier) {
|
||||
const campaignWeight = (context['_campaignWeight'] ?? 5) / 10;
|
||||
const sourceWeight = (context['_sourceWeight'] ?? 5) / 10;
|
||||
score *= campaignWeight * sourceWeight;
|
||||
campaignApplied = true;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: { score, weight: params.weight, slaApplied, campaignApplied },
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user