Skip to content

Commit ec7ef8c

Browse files
committed
maskAll flag added to maskPatientData, unit test added
1 parent 9e8b0b4 commit ec7ef8c

File tree

4 files changed

+13
-43
lines changed

4 files changed

+13
-43
lines changed

src/extractors/CSVPatientExtractor.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,6 @@ 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-
3212
function joinAndReformatData(patientData) {
3313
logger.debug('Reformatting patient data from CSV into template format');
3414
// No join needed, just a reformatting
@@ -109,7 +89,7 @@ class CSVPatientExtractor extends BaseCSVExtractor {
10989

11090
// mask specified fields in the patient data
11191
if (typeof this.mask === 'string' && this.mask === 'all') {
112-
maskPatientData(bundle, ALL_SUPPORTED_MASK_FIELDS);
92+
maskPatientData(bundle, [], true);
11393
} else if (this.mask.length > 0) maskPatientData(bundle, this.mask);
11494
return bundle;
11595
}

src/extractors/FHIRPatientExtractor.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
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-
234
class FHIRPatientExtractor extends BaseFHIRExtractor {
245
constructor({ baseFhirUrl, requestHeaders, version, mask = [] }) {
256
super({ baseFhirUrl, requestHeaders, version });
@@ -39,7 +20,7 @@ class FHIRPatientExtractor extends BaseFHIRExtractor {
3920
const bundle = await super.get(argumentObject);
4021
// mask specified fields in the patient data
4122
if (typeof this.mask === 'string' && this.mask === 'all') {
42-
maskPatientData(bundle, ALL_SUPPORTED_MASK_FIELDS);
23+
maskPatientData(bundle, [], true);
4324
} else if (this.mask.length > 0) maskPatientData(bundle, this.mask);
4425
return bundle;
4526
}

src/helpers/patientUtils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ function getPatientName(name) {
8181
* 'gender','mrn','name','address','birthDate','language','ethnicity','birthsex',
8282
* 'race', 'telecom', 'multipleBirth', 'photo', 'contact', 'generalPractitioner',
8383
* 'managingOrganization', and 'link'
84+
* @param {Boolean} maskAll indicates that all supported fields should be masked, defaults to false
8485
*/
85-
function maskPatientData(bundle, mask) {
86+
function maskPatientData(bundle, mask, maskAll = false) {
8687
// get Patient resource from bundle
8788
const patient = fhirpath.evaluate(
8889
bundle,
@@ -109,7 +110,9 @@ function maskPatientData(bundle, mask) {
109110
];
110111
const masked = extensionArr(dataAbsentReasonExtension('masked'));
111112

112-
mask.forEach((field) => {
113+
const maskingFields = maskAll ? validFields : mask;
114+
115+
maskingFields.forEach((field) => {
113116
if (!validFields.includes(field)) {
114117
throw Error(`'${field}' is not a field that can be masked. Patient will only be extracted if all mask fields are valid. Valid fields include: Valid fields include: ${validFields.join(', ')}`);
115118
}

test/helpers/patientUtils.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ describe('PatientUtils', () => {
113113
expect(bundle).toEqual(exampleMaskedPatient);
114114
});
115115

116+
test('bundle should be modified to have dataAbsentReason for all fields when the maskAll flag is provided', () => {
117+
const bundle = _.cloneDeep(examplePatient);
118+
maskPatientData(bundle, [], true);
119+
expect(bundle).toEqual(exampleMaskedPatient);
120+
});
121+
116122
test('should mask gender even if it only had an extension', () => {
117123
const bundle = _.cloneDeep(examplePatient);
118124
delete bundle.entry[0].resource.gender;

0 commit comments

Comments
 (0)