Skip to content

Commit 12b5283

Browse files
committed
All option for masking fields added to config
1 parent 806d3bc commit 12b5283

File tree

5 files changed

+75
-7
lines changed

5 files changed

+75
-7
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ To mask a property, provide an array of the properties to mask in the `construct
148148
}
149149
```
150150

151+
Alternatively, providing a string with a value of `all` in the `constructorArgs` of the Patient extractor will mask all of the supported properties listed above. The following configuration can be used to mask all properties of the `Patient` resource, rather than listing each individual property:
152+
153+
```bash
154+
{
155+
"label": "patient",
156+
"type": "CSVPatientExtractor",
157+
"constructorArgs": {
158+
"filePath": "./data/patient-information.csv"
159+
"mask": "all"
160+
}
161+
}
162+
```
151163
### Extraction Date Range
152164

153165
The mCODE Extraction Client will extract all data that is provided in the CSV files by default, regardless of any dates associated with each row of data. It is recommended that any required date filtering is performed outside of the scope of this client.

src/extractors/CSVPatientExtractor.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@ const { getEmptyBundle } = require('../helpers/fhirUtils');
99
const { CSVPatientSchema } = require('../helpers/schemas/csv');
1010
const logger = require('../helpers/logger');
1111

12+
const ALL_SUPPORTED_MASK_FIELDS = [
13+
'gender',
14+
'mrn',
15+
'name',
16+
'address',
17+
'birthDate',
18+
'language',
19+
'ethnicity',
20+
'birthsex',
21+
'race',
22+
'telecom',
23+
'multipleBirth',
24+
'photo',
25+
'contact',
26+
'generalPractitioner',
27+
'managingOrganization',
28+
'link',
29+
];
30+
31+
1232
function joinAndReformatData(patientData) {
1333
logger.debug('Reformatting patient data from CSV into template format');
1434
// No join needed, just a reformatting
@@ -87,8 +107,10 @@ class CSVPatientExtractor extends BaseCSVExtractor {
87107
// 3. Generate FHIR Resources
88108
const bundle = generateMcodeResources('Patient', packagedPatientData);
89109

90-
// mask fields in the patient data if specified in mask array
91-
if (this.mask.length > 0) maskPatientData(bundle, this.mask);
110+
// mask specified fields in the patient data
111+
if (typeof this.mask === 'string') {
112+
maskPatientData(bundle, ALL_SUPPORTED_MASK_FIELDS);
113+
} else if (this.mask.length > 0) maskPatientData(bundle, this.mask);
92114
return bundle;
93115
}
94116
}

src/extractors/FHIRPatientExtractor.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
const { BaseFHIRExtractor } = require('./BaseFHIRExtractor');
22
const { maskPatientData } = require('../helpers/patientUtils.js');
33

4+
const ALL_SUPPORTED_MASK_FIELDS = [
5+
'gender',
6+
'mrn',
7+
'name',
8+
'address',
9+
'birthDate',
10+
'language',
11+
'ethnicity',
12+
'birthsex',
13+
'race',
14+
'telecom',
15+
'multipleBirth',
16+
'photo',
17+
'contact',
18+
'generalPractitioner',
19+
'managingOrganization',
20+
'link',
21+
];
22+
423
class FHIRPatientExtractor extends BaseFHIRExtractor {
524
constructor({ baseFhirUrl, requestHeaders, version, mask = [] }) {
625
super({ baseFhirUrl, requestHeaders, version });
@@ -18,7 +37,10 @@ class FHIRPatientExtractor extends BaseFHIRExtractor {
1837

1938
async get(argumentObject) {
2039
const bundle = await super.get(argumentObject);
21-
if (this.mask.length > 0) maskPatientData(bundle, this.mask);
40+
// mask specified fields in the patient data
41+
if (typeof this.mask === 'string') {
42+
maskPatientData(bundle, ALL_SUPPORTED_MASK_FIELDS);
43+
} else if (this.mask.length > 0) maskPatientData(bundle, this.mask);
2244
return bundle;
2345
}
2446
}

src/helpers/configUtils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ ajv.addFormat('email-with-name', {
3434
return emailRegex.test(email.trim().split(' ').pop());
3535
},
3636
});
37+
ajv.addFormat('mask-all', {
38+
type: 'string',
39+
validate: (string) => string === 'all',
40+
});
3741

3842
const validator = ajv.addSchema(configSchema, 'config');
3943

src/helpers/schemas/config.schema.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,18 @@
128128
},
129129
"mask": {
130130
"title": "Masked Fields",
131-
"type": "array",
132-
"items": {
133-
"type": "string"
134-
}
131+
"oneOf": [
132+
{
133+
"type": "string",
134+
"format": "mask-all"
135+
},
136+
{
137+
"type": "array",
138+
"items": {
139+
"type": "string"
140+
}
141+
}
142+
]
135143
}
136144
}
137145
}

0 commit comments

Comments
 (0)