@@ -4,6 +4,8 @@ const _ = require('lodash');
4
4
const { CSVCancerRelatedMedicationExtractor } = require ( '../../src/extractors' ) ;
5
5
const exampleCSVMedicationModuleResponse = require ( './fixtures/csv-medication-module-response.json' ) ;
6
6
const exampleCSVMedicationBundle = require ( './fixtures/csv-medication-bundle.json' ) ;
7
+ const { getPatientFromContext } = require ( '../../src/helpers/contextUtils' ) ;
8
+ const MOCK_CONTEXT = require ( './fixtures/context-with-patient.json' ) ;
7
9
8
10
// Rewired extractor for helper tests
9
11
const CSVCancerRelatedMedicationExtractorRewired = rewire ( '../../src/extractors/CSVCancerRelatedMedicationExtractor.js' ) ;
@@ -35,24 +37,25 @@ describe('CSVCancerRelatedMedicationExtractor', () => {
35
37
test ( 'should join data appropriately and throw errors when missing required properties' , ( ) => {
36
38
const expectedErrorString = 'The cancer-related medication is missing an expected element; mrn, code, code system, and status are all required values.' ;
37
39
const localData = _ . cloneDeep ( exampleCSVMedicationModuleResponse ) ;
40
+ const patientId = getPatientFromContext ( MOCK_CONTEXT ) . id ;
38
41
39
42
// Test that valid maximal data works fine
40
- expect ( formatData ( exampleCSVMedicationModuleResponse ) ) . toEqual ( expect . anything ( ) ) ;
43
+ expect ( formatData ( localData , patientId ) ) . toEqual ( expect . anything ( ) ) ;
41
44
42
45
// Test that deleting an optional value works fine
43
46
delete localData [ 0 ] . treatmentIntent ;
44
- expect ( formatData ( exampleCSVMedicationModuleResponse ) ) . toEqual ( expect . anything ( ) ) ;
47
+ expect ( formatData ( localData , patientId ) ) . toEqual ( expect . anything ( ) ) ;
45
48
46
49
// Test that deleting a mandatory value throws an error
47
50
delete localData [ 0 ] . code ;
48
- expect ( ( ) => formatData ( localData ) ) . toThrow ( new Error ( expectedErrorString ) ) ;
51
+ expect ( ( ) => formatData ( localData , patientId ) ) . toThrow ( new Error ( expectedErrorString ) ) ;
49
52
} ) ;
50
53
} ) ;
51
54
52
55
describe ( 'get' , ( ) => {
53
56
test ( 'should return bundle with a CancerRelatedMedication' , async ( ) => {
54
57
csvModuleSpy . mockReturnValue ( exampleCSVMedicationModuleResponse ) ;
55
- const data = await csvCancerRelatedMedicationExtractor . get ( { mrn : MOCK_PATIENT_MRN } ) ;
58
+ const data = await csvCancerRelatedMedicationExtractor . get ( { mrn : MOCK_PATIENT_MRN , context : MOCK_CONTEXT } ) ;
56
59
expect ( data . resourceType ) . toEqual ( 'Bundle' ) ;
57
60
expect ( data . type ) . toEqual ( 'collection' ) ;
58
61
expect ( data . entry ) . toBeDefined ( ) ;
@@ -62,7 +65,7 @@ describe('CSVCancerRelatedMedicationExtractor', () => {
62
65
63
66
test ( 'should return empty bundle when no data available from module' , async ( ) => {
64
67
csvModuleSpy . mockReturnValue ( [ ] ) ;
65
- const data = await csvCancerRelatedMedicationExtractor . get ( { mrn : MOCK_PATIENT_MRN } ) ;
68
+ const data = await csvCancerRelatedMedicationExtractor . get ( { mrn : MOCK_PATIENT_MRN , context : MOCK_CONTEXT } ) ;
66
69
expect ( data . resourceType ) . toEqual ( 'Bundle' ) ;
67
70
expect ( data . type ) . toEqual ( 'collection' ) ;
68
71
expect ( data . entry ) . toBeDefined ( ) ;
@@ -72,8 +75,7 @@ describe('CSVCancerRelatedMedicationExtractor', () => {
72
75
test ( 'get() should return an array of 2 when two medication statements are tied to a single patient' , async ( ) => {
73
76
exampleCSVMedicationModuleResponse . push ( exampleEntry ) ;
74
77
csvModuleSpy . mockReturnValue ( exampleCSVMedicationModuleResponse ) ;
75
- const data = await csvCancerRelatedMedicationExtractor . get ( { mrn : MOCK_PATIENT_MRN } ) ;
76
-
78
+ const data = await csvCancerRelatedMedicationExtractor . get ( { mrn : MOCK_PATIENT_MRN , context : MOCK_CONTEXT } ) ;
77
79
expect ( data . resourceType ) . toEqual ( 'Bundle' ) ;
78
80
expect ( data . type ) . toEqual ( 'collection' ) ;
79
81
expect ( data . entry ) . toBeDefined ( ) ;
0 commit comments