File size: 667 Bytes
d0e3a07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import re

# Simple, configurable redaction. Replace with your enterprise DLP when ready.
RE_PATTERNS = {
    "MRN": re.compile(r"\b(?:MRN|Med(?:ical)?\s*Record)\s*[:#]?\s*\d{5,10}\b", re.I),
    "DOB": re.compile(r"\b(?:DOB|DoB|Birth\s*Date)\s*[:#]?\s*(\d{4}[-/]\d{2}[-/]\d{2}|\d{2}[-/]\d{2}[-/]\d{4})\b", re.I),
    "PHONE": re.compile(r"\b(?:\+?\d{1,2}\s*)?(?:\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4})\b"),
    "EMAIL": re.compile(r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b"),
}

def redact_text(text: str) -> str:
    if not text:
        return text
    red = text
    for pat in RE_PATTERNS.values():
        red = pat.sub("[REDACTED]", red)
    return red