Skip to content

Commit db5d986

Browse files
committed
Add any ResearchStudy ids to this.study in AdverseEvent extractor
1 parent ccc3412 commit db5d986

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

src/extractors/FHIRAdverseEventExtractor.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const { BaseFHIRExtractor } = require('./BaseFHIRExtractor');
2+
const { getResearchStudiesFromContext } = require('../helpers/contextUtils');
3+
const logger = require('../helpers/logger');
24

35
const BASE_STUDY = ''; // No base study specified
46

@@ -12,14 +14,28 @@ class FHIRAdverseEventExtractor extends BaseFHIRExtractor {
1214
// In addition to default parametrization, add study if specified
1315
async parametrizeArgsForFHIRModule({ context }) {
1416
const paramsWithID = await super.parametrizeArgsForFHIRModule({ context });
17+
let allResearchStudyResources = [];
18+
try {
19+
allResearchStudyResources = getResearchStudiesFromContext(context);
20+
} catch (e) {
21+
logger.error(e.message);
22+
logger.debug(e.stack);
23+
}
24+
1525
// The patient is referenced in the 'subject' field of an AdverseEvent
1626
paramsWithID.subject = paramsWithID.patient;
1727
delete paramsWithID.patient;
18-
// Only add study to parameters if it has been specified
19-
return {
28+
29+
// If there are research study resources, create a parameters object for each call to be made
30+
const newStudyIds = allResearchStudyResources.map((rs) => rs.id).join(',');
31+
const studyIdsForCurrentPatient = `${this.study}${this.study && newStudyIds ? ',' : ''}${newStudyIds}`;
32+
33+
// Only add study to parameters if it has been specified or was included from context
34+
const obj = {
2035
...paramsWithID,
21-
...(this.study && { study: this.study }),
36+
...(studyIdsForCurrentPatient && { study: studyIdsForCurrentPatient }),
2237
};
38+
return obj;
2339
}
2440
}
2541

test/extractors/FHIRAdverseEventExtractor.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,28 @@ const MOCK_CONTEXT = {
1515
},
1616
],
1717
};
18+
const researchStudyResource = {
19+
resourceType: 'ResearchStudy',
20+
id: 'ResearchStudyExample01',
21+
};
22+
const MOCK_CONTEXT_WITH_RESEARCH_STUDY = {
23+
resourceType: 'Bundle',
24+
type: 'collection',
25+
entry: [
26+
{
27+
fullUrl: 'context-url-1',
28+
resource: { resourceType: 'Patient', id: MOCK_MRN },
29+
},
30+
{
31+
fullUrl: 'context-url-2',
32+
resource: researchStudyResource,
33+
},
34+
{
35+
fullUrl: 'context-url-3',
36+
resource: { ...researchStudyResource, id: 'ResearchStudyExample02' },
37+
},
38+
],
39+
};
1840

1941
// Construct extractor and create spies for mocking responses
2042
const extractor = new FHIRAdverseEventExtractor({ baseFhirUrl: MOCK_URL, requestHeaders: MOCK_HEADERS });
@@ -40,6 +62,12 @@ describe('FHIRAdverseEventExtractor', () => {
4062
expect(params).not.toHaveProperty('study');
4163
});
4264

65+
test('should add study id for all ResearchStudy resources that are in context', async () => {
66+
const params = await extractor.parametrizeArgsForFHIRModule({ context: MOCK_CONTEXT_WITH_RESEARCH_STUDY });
67+
expect(params).toHaveProperty('study');
68+
expect(params.study).toEqual(`${researchStudyResource.id},ResearchStudyExample02`);
69+
});
70+
4371
describe('pass in optional study parameter', () => {
4472
test('should add study when set to param values', async () => {
4573
const params = await extractorWithStudy.parametrizeArgsForFHIRModule({ context: MOCK_CONTEXT });
@@ -51,6 +79,12 @@ describe('FHIRAdverseEventExtractor', () => {
5179
const params = await extractorWithStudy.parametrizeArgsForFHIRModule({ context: MOCK_CONTEXT });
5280
expect(params).not.toHaveProperty('patient');
5381
});
82+
83+
test('should add study from study parameter and from context', async () => {
84+
const params = await extractorWithStudy.parametrizeArgsForFHIRModule({ context: MOCK_CONTEXT_WITH_RESEARCH_STUDY });
85+
expect(params).toHaveProperty('study');
86+
expect(params.study).toEqual(`${extractorWithStudy.study},${researchStudyResource.id},ResearchStudyExample02`);
87+
});
5488
});
5589
});
5690
});

0 commit comments

Comments
 (0)