Skip to content

Commit 8c77023

Browse files
Merge pull request #77 from mcode/fhir-adverse-event-extractor
FHIR Extractor for Adverse Events
2 parents f077fed + 284a8fb commit 8c77023

File tree

6 files changed

+100
-0
lines changed

6 files changed

+100
-0
lines changed

src/client/MCODEClient.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
CSVProcedureExtractor,
1010
CSVStagingExtractor,
1111
CSVTreatmentPlanChangeExtractor,
12+
FHIRAdverseEventExtractor,
1213
FHIRAllergyIntoleranceExtractor,
1314
FHIRConditionExtractor,
1415
FHIRDocumentReferenceExtractor,
@@ -33,6 +34,7 @@ class MCODEClient extends BaseClient {
3334
CSVProcedureExtractor,
3435
CSVStagingExtractor,
3536
CSVTreatmentPlanChangeExtractor,
37+
FHIRAdverseEventExtractor,
3638
FHIRAllergyIntoleranceExtractor,
3739
FHIRConditionExtractor,
3840
FHIRDocumentReferenceExtractor,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const { BaseFHIRExtractor } = require('./BaseFHIRExtractor');
2+
3+
const BASE_STUDY = ''; // No base study specified
4+
5+
class FHIRAdverseEventExtractor extends BaseFHIRExtractor {
6+
constructor({ baseFhirUrl, requestHeaders, version, study }) {
7+
super({ baseFhirUrl, requestHeaders, version });
8+
this.resourceType = 'AdverseEvent';
9+
this.study = study || BASE_STUDY;
10+
}
11+
12+
// In addition to default parametrization, add study if specified
13+
async parametrizeArgsForFHIRModule({ mrn, context }) {
14+
const paramsWithID = await super.parametrizeArgsForFHIRModule({ mrn, context });
15+
// The patient is referenced in the 'subject' field of an AdverseEvent
16+
paramsWithID.subject = paramsWithID.patient;
17+
delete paramsWithID.patient;
18+
// Only add study to parameters if it has been specified
19+
return {
20+
...paramsWithID,
21+
...(this.study && { study: this.study }),
22+
};
23+
}
24+
}
25+
26+
module.exports = {
27+
FHIRAdverseEventExtractor,
28+
};

src/extractors/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { CSVProcedureExtractor } = require('./CSVProcedureExtractor');
99
const { CSVStagingExtractor } = require('./CSVStagingExtractor');
1010
const { CSVTreatmentPlanChangeExtractor } = require('./CSVTreatmentPlanChangeExtractor');
1111
const { Extractor } = require('./Extractor');
12+
const { FHIRAdverseEventExtractor } = require('./FHIRAdverseEventExtractor');
1213
const { FHIRAllergyIntoleranceExtractor } = require('./FHIRAllergyIntoleranceExtractor');
1314
const { FHIRConditionExtractor } = require('./FHIRConditionExtractor');
1415
const { FHIRDocumentReferenceExtractor } = require('./FHIRDocumentReferenceExtractor');
@@ -33,6 +34,7 @@ module.exports = {
3334
CSVStagingExtractor,
3435
CSVTreatmentPlanChangeExtractor,
3536
Extractor,
37+
FHIRAdverseEventExtractor,
3638
FHIRAllergyIntoleranceExtractor,
3739
FHIRConditionExtractor,
3840
FHIRDocumentReferenceExtractor,

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const {
2020
CSVStagingExtractor,
2121
CSVTreatmentPlanChangeExtractor,
2222
Extractor,
23+
FHIRAdverseEventExtractor,
2324
FHIRAllergyIntoleranceExtractor,
2425
FHIRConditionExtractor,
2526
FHIRDocumentReferenceExtractor,
@@ -83,6 +84,7 @@ module.exports = {
8384
CSVStagingExtractor,
8485
CSVTreatmentPlanChangeExtractor,
8586
Extractor,
87+
FHIRAdverseEventExtractor,
8688
FHIRAllergyIntoleranceExtractor,
8789
FHIRConditionExtractor,
8890
FHIRDocumentReferenceExtractor,
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const rewire = require('rewire');
2+
const { FHIRAdverseEventExtractor } = require('../../src/extractors/FHIRAdverseEventExtractor');
3+
const examplePatientBundle = require('./fixtures/patient-bundle.json');
4+
5+
const FHIRAdverseEventExtractorRewired = rewire('../../src/extractors/FHIRAdverseEventExtractor.js');
6+
const MOCK_URL = 'http://example.com';
7+
const MOCK_HEADERS = {};
8+
const MOCK_MRN = '123456789';
9+
const MOCK_STUDIES = 'study1,study2';
10+
11+
// Construct extractor and create sppies for mocking responses
12+
const extractor = new FHIRAdverseEventExtractor({ baseFhirUrl: MOCK_URL, requestHeaders: MOCK_HEADERS });
13+
const extractorWithStudy = new FHIRAdverseEventExtractor({ baseFhirUrl: MOCK_URL, requestHeaders: MOCK_HEADERS, study: MOCK_STUDIES });
14+
const baseStudy = FHIRAdverseEventExtractorRewired.__get__('BASE_STUDY');
15+
16+
describe('FHIRAdverseEventExtractor', () => {
17+
describe('Constructor', () => {
18+
test('Constructor sets resourceType as AdverseEvent', () => {
19+
expect(extractor.resourceType).toEqual('AdverseEvent');
20+
});
21+
test('sets study based on BASE_STUDY if not provided', () => {
22+
expect(extractor.study).toEqual(baseStudy);
23+
});
24+
test('sets study if provided', () => {
25+
expect(extractorWithStudy.study).toEqual(MOCK_STUDIES);
26+
});
27+
});
28+
29+
describe('parametrizeArgsForFHIRModule', () => {
30+
test('should not add study when not set to param values', async () => {
31+
// Create spy
32+
const { baseFHIRModule } = extractor;
33+
const baseFHIRModuleSearchSpy = jest.spyOn(baseFHIRModule, 'search');
34+
baseFHIRModuleSearchSpy
35+
.mockReturnValue(examplePatientBundle);
36+
37+
const params = await extractor.parametrizeArgsForFHIRModule({ mrn: MOCK_MRN });
38+
expect(params).not.toHaveProperty('study');
39+
});
40+
41+
describe('pass in optional study parameter', () => {
42+
beforeEach(() => {
43+
// Create spy
44+
const { baseFHIRModule } = extractorWithStudy;
45+
const baseFHIRModuleSearchSpy = jest.spyOn(baseFHIRModule, 'search');
46+
baseFHIRModuleSearchSpy
47+
.mockReturnValue(examplePatientBundle);
48+
});
49+
50+
test('should add study when set to param values', async () => {
51+
const params = await extractorWithStudy.parametrizeArgsForFHIRModule({ mrn: MOCK_MRN });
52+
expect(params).toHaveProperty('study');
53+
expect(params.study).toEqual(extractorWithStudy.study);
54+
});
55+
56+
test('should delete patient after its value is moved to subject', async () => {
57+
const params = await extractorWithStudy.parametrizeArgsForFHIRModule({ mrn: MOCK_MRN });
58+
expect(params).not.toHaveProperty('patient');
59+
});
60+
});
61+
});
62+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mrn,adverseEventId,adverseEventCode,adverseEventCodeSystem,adverseEventDisplayText,suspectedCauseId,suspectedCauseType,seriousness,seriousnessCodeSystem,seriousnessDisplayText,category,categoryCodeSystem,categoryDisplayText,severity,actuality,studyId,effectiveDate,recordedDate
2+
123,adverseEventId-1,109006,code-system,Anxiety disorder of childhood OR adolescence,procedure-id,Procedure,Serious,http://terminology.hl7.org/CodeSystem/adverse-event-seriousness,Serious,product-use-error,http://terminology.hl7.org/CodeSystem/adverse-event-category,Product Use Error,severe,actual,researchId-1,12-09-1994,12-09-1994
3+
456,adverseEventId-2,134006,http://snomed.info/sct,Decreased hair growth,medicationId-1,Medication,Non-serious,http://terminology.hl7.org/CodeSystem/adverse-event-seriousness,Non-serious,product-quality,http://terminology.hl7.org/CodeSystem/adverse-event-category,Product Quality,mild,potential,researchId-2,12-10-1995,12-10-1995
4+
789,adverseEventId-3,150003,,,,,,,,,,,,,,12-09-1994,

0 commit comments

Comments
 (0)