File size: 1,390 Bytes
096d021
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json
import os

class AlertIntakeSystem:
    """
    Handles alert ingestion and duplicate detection.
    Exception Handling Requirement: Duplicate alert on same account within active 
    case window -> merge into existing case rather than opening a second one.
    """
    
    _active_cases = {
        "ACC-998877": "CAS-2024-001" # Structuring case is active
    }
    
    @classmethod
    def ingest_alert(cls, alert_data: dict) -> str:
        account_id = alert_data.get("primary_subject", {}).get("account_id")
        
        if account_id in cls._active_cases:
            existing_case_id = cls._active_cases[account_id]
            print(f"[INTAKE] [MERGE] Duplicate alert detected for account {account_id}.")
            print(f"Merging new transaction data into existing case {existing_case_id} instead of opening a new case.")
            return existing_case_id
            
        new_case_id = f"CAS-{os.urandom(4).hex().upper()}"
        cls._active_cases[account_id] = new_case_id
        print(f"[INTAKE] Opened new case {new_case_id} for account {account_id}.")
        return new_case_id

if __name__ == "__main__":
    # Test duplicate ingestion
    new_alert = {
        "primary_subject": {"account_id": "ACC-998877"},
        "alert_type": "HIGH_VELOCITY",
        "transactions": [{"amount": 1000}]
    }
    AlertIntakeSystem.ingest_alert(new_alert)