feat: implement PolicyApplicabilityService to evaluate policy eligibility based on jurisdiction and cohort matches
This commit is contained in:
@@ -56,30 +56,38 @@ export class PolicyApplicabilityService {
|
|||||||
const policyJurisdictions = policy.jurisdictions || [];
|
const policyJurisdictions = policy.jurisdictions || [];
|
||||||
|
|
||||||
if (policyJurisdictions.length > 0) {
|
if (policyJurisdictions.length > 0) {
|
||||||
if (!incidentJurisdiction) {
|
const isGlobal = policyJurisdictions.some((pj) => {
|
||||||
this.logger.warn(
|
|
||||||
`[POLICY REJECTED ❌] Policy "${policy.policyName}" (ID: ${policy.id}) requires a jurisdiction, but incident context has no jurisdiction.`,
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const incJVal = incidentJurisdiction.trim().toUpperCase();
|
|
||||||
|
|
||||||
const hasMatch = policyJurisdictions.some((pj) => {
|
|
||||||
const pJId = pj.jurisdictionId;
|
|
||||||
const pJVal = (pj.jurisdiction?.value || pj.jurisdiction?.label || '').trim().toUpperCase();
|
const pJVal = (pj.jurisdiction?.value || pj.jurisdiction?.label || '').trim().toUpperCase();
|
||||||
const matchesId = Boolean(pJId) && pJId === incidentJurisdiction;
|
return pJVal === 'GLOBAL';
|
||||||
const matchesVal =
|
|
||||||
Boolean(pJVal) &&
|
|
||||||
(pJVal === incJVal || pJVal.includes(incJVal) || incJVal.includes(pJVal));
|
|
||||||
return matchesId || matchesVal;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!hasMatch) {
|
if (!isGlobal) {
|
||||||
this.logger.warn(
|
if (!incidentJurisdiction) {
|
||||||
`[POLICY REJECTED ❌] Policy "${policy.policyName}" (ID: ${policy.id}) jurisdictions DO NOT MATCH incident jurisdiction ("${incJVal}").`,
|
this.logger.warn(
|
||||||
);
|
`[POLICY REJECTED ❌] Policy "${policy.policyName}" (ID: ${policy.id}) requires a jurisdiction, but incident context has no jurisdiction.`,
|
||||||
return false;
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const incJVal = incidentJurisdiction.trim().toUpperCase();
|
||||||
|
|
||||||
|
const hasMatch = policyJurisdictions.some((pj) => {
|
||||||
|
const pJId = pj.jurisdictionId;
|
||||||
|
const pJVal = (pj.jurisdiction?.value || pj.jurisdiction?.label || '').trim().toUpperCase();
|
||||||
|
|
||||||
|
const matchesId = Boolean(pJId) && pJId === incidentJurisdiction;
|
||||||
|
const matchesVal =
|
||||||
|
Boolean(pJVal) &&
|
||||||
|
(pJVal === incJVal || pJVal.includes(incJVal) || incJVal.includes(pJVal));
|
||||||
|
return matchesId || matchesVal;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!hasMatch) {
|
||||||
|
this.logger.warn(
|
||||||
|
`[POLICY REJECTED ❌] Policy "${policy.policyName}" (ID: ${policy.id}) jurisdictions DO NOT MATCH incident jurisdiction ("${incJVal}").`,
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user