-
Notifications
You must be signed in to change notification settings - Fork 0
/
redaction.gs
64 lines (57 loc) · 3.35 KB
/
redaction.gs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Use regex101.com to test and build javascript code examples.
//
// https://regex101.com/codegen?language=javascript
// @param regex A regex literal like: /(?<=- Reporter E-mail: )(.*?)(?=\
)/gim
function ReplaceReporterField(report, regex){
const redacted = '[REDACTED]';
// NOTE: Do not use alternative syntax using RegExp constructor, i.e. new RegExp('pattern', 'gim')
// As I couldn't reproduce the same results as in the UI, codegen doesn't use it.
// TypeError: Cannot read properties of undefined (reading 'replace')
const redactedReport = report?.replace(regex, redacted);
return redactedReport;
}
function RedactReport(report){
var redacted_report = report
// Specific report tags, ex: '- Another Field: something to redact here
'
//redacted_report = ReplaceReporterField(redacted_report, /(?<=- Another Field: )(.*?)(?=\
)/gim);
redacted_report = ReplaceReporterField(redacted_report, /(?<=- Phone Number: )(.*?)(?=\
)/gim);
redacted_report = ReplaceReporterField(redacted_report, /(?<=- Phone Type: )(.*?)(?=\
)/gim);
redacted_report = ReplaceReporterField(redacted_report, /(?<=- Reporter E-mail: )(.*?)(?=\
)/gim);
redacted_report = ReplaceReporterField(redacted_report, /(?<=- Reporter Name: )(.*?)(?=\
)/gim);
redacted_report = ReplaceReporterField(redacted_report, /(?<=- Reporter Home Address: )(.*?)(?=\
)/gim);
redacted_report = ReplaceReporterField(redacted_report, /(?<=- Reporter's Name: )(.*?)(?=\
)/gim);
redacted_report = ReplaceReporterField(redacted_report, /(?<=- Reporter's Phone Number: )(.*?)(?=\
)/gim);
// free form `name dob` type comments
redacted_report = ReplaceReporterField(redacted_report, /(\S+)\s*(\S+)\s*correction on dob\s*/gim); // 10/10/1993 correction on dob
redacted_report = ReplaceReporterField(redacted_report, /(\S+)\s*(\S+)\s*dob\s*(\S+)/gim); // 'dob' only
// https://regex101.com/r/fjAyuB/1
// last[,] first [middle] mm/dd/yy[yy]
// last[,] first [middle] mm-dd-yy[yy]
// last[,] first [middle] mmddyy[yy]
const last_first_name_dob = /([A-Za-z]+)[, ]+\s*([A-Za-z]+)\s*([A-Za-z]+)*(\S+)\s*\d{2}([/-]?)+\d{2}([/-]?)+\d{2,4}/gim;
redacted_report = ReplaceReporterField(redacted_report, last_first_name_dob);
return redacted_report;
}
var mockReport = `
- E-mail: [email protected]
- Other Phone Number: 13031234567
- Reporter e-mail: [email protected]
 /gim "i" means case insensitive
- Reporter E-mail: [email protected]
- Phone Number: 13031234567
- Phone Type: MOBILE
- Reporter Name: JANE DOE
- Reporter's Name: JANE DOE
- Reporter Home Address: 123 yellow brick Road, kansas
... | last, first DOB 10/21/1968 12:00:00 PM | ...
... | LAST, first DOB 10-21-1968 12:00:00 PM | ...
... Doe Jane 03/10/10 Jan 20 2022 7:14PM | ...
... DOE, jane 03/10/10 Jan 20 2022 7:14PM | ...
... DOE, jane nicole 03/10/10 Jan 20 2022 7:14PM | ...
... | 10/10/1993 correction on dob Jan 20 2022 7:14PM | DOE, jane nicole 03/10/10 Jan 20 2022 7:14PM | ... | DOE, Jane 10/12/1993 Jan 20 2022 7:11PM | ...
... | john Doe DOB112789 .. actual date example
... | john Doe DOB11/27/1989 .. different possible date schema
... | Samuel Dickerson 08/08/2001 Mar 17 2022 2:44PM | ...
... | Samuel, Dickerson 082990 Jan 28 2022 12:31PM | ...
... | Samuel, Dickerson 08-29-90 Jan 28 2022 12:31PM | ...
`;
//Logger.log(RedactReport(mockReport))