|
| 1 | +const { when } = require('jest-when'); |
| 2 | +const rewire = require('rewire'); |
| 3 | +const { MCODERadiationProcedureExtractor } = require('../../src/extractors/MCODERadiationProcedureExtractor.js'); |
| 4 | +const exampleProcedureBundle = require('./fixtures/surgical-radiation-procedure-bundle.json'); |
| 5 | + |
| 6 | +const radiationProcedureExtractorRewired = rewire('../../src/extractors/MCODERadiationProcedureExtractor.js'); |
| 7 | +const getMCODERadiationProcedures = radiationProcedureExtractorRewired.__get__('getMCODERadiationProcedures'); |
| 8 | + |
| 9 | +const MOCK_URL = 'http://example.com'; |
| 10 | +const MOCK_HEADERS = {}; |
| 11 | +const MOCK_PATIENT_MRN = 'EXAMPLE-MRN'; |
| 12 | + |
| 13 | +const extractor = new MCODERadiationProcedureExtractor({ baseFhirUrl: MOCK_URL, requestHeaders: MOCK_HEADERS }); |
| 14 | +const { fhirProcedureExtractor } = extractor; |
| 15 | + |
| 16 | +// Spy on fhirProcedureExtractor.get |
| 17 | +const fhirProcedureExtractorSpy = jest.spyOn(fhirProcedureExtractor, 'get'); |
| 18 | + |
| 19 | +describe('MCODERadiationProcedureExtractor', () => { |
| 20 | + describe('getFHIRProcedures', () => { |
| 21 | + // it('should return procedure entries for patient from context', async () => { |
| 22 | + // const contextPatient = { |
| 23 | + // resourceType: 'Patient', |
| 24 | + // id: 'context-patient-id', |
| 25 | + // }; |
| 26 | + // const contextProcedure1 = { |
| 27 | + // resourceType: 'Procedure', |
| 28 | + // id: 'context-procedure-1-id', |
| 29 | + // }; |
| 30 | + // const contextProcedure2 = { |
| 31 | + // resourceType: 'Procedure', |
| 32 | + // id: 'context-procedure-2-id', |
| 33 | + // }; |
| 34 | + // const context = { |
| 35 | + // resourceType: 'Bundle', |
| 36 | + // type: 'collection', |
| 37 | + // entry: [ |
| 38 | + // { |
| 39 | + // fullUrl: 'context-patient-url', |
| 40 | + // resource: contextPatient, |
| 41 | + // }, |
| 42 | + // { |
| 43 | + // fullUrl: 'context-procedure-1-url', |
| 44 | + // resource: contextProcedure1, |
| 45 | + // }, |
| 46 | + // { |
| 47 | + // fullUrl: 'context-procedure-2-url', |
| 48 | + // resource: contextProcedure2, |
| 49 | + // }, |
| 50 | + // ], |
| 51 | + // }; |
| 52 | + // const procedures = await extractor.getFHIRProcedures(MOCK_PATIENT_MRN, context); |
| 53 | + // expect(fhirProcedureExtractorSpy).not.toHaveBeenCalled(); |
| 54 | + // expect(procedures).toHaveLength(2); |
| 55 | + // expect(procedures[0].resource.id).toEqual(contextProcedure1.id); |
| 56 | + // expect(procedures[1].resource.id).toEqual(contextProcedure2.id); |
| 57 | + // }); |
| 58 | + |
| 59 | + it('should return procedure entries for patient from FHIR search if no context', async () => { |
| 60 | + fhirProcedureExtractorSpy.mockClear(); |
| 61 | + when(fhirProcedureExtractorSpy).calledWith({ mrn: MOCK_PATIENT_MRN, context: {} }).mockReturnValue(exampleProcedureBundle); |
| 62 | + const procedures = await extractor.getFHIRProcedures(MOCK_PATIENT_MRN, {}); |
| 63 | + expect(fhirProcedureExtractorSpy).toHaveBeenCalled(); |
| 64 | + expect(procedures).toEqual(exampleProcedureBundle.entry); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should return no procedures if search is empty', async () => { |
| 68 | + const emptyCollectionBundle = { |
| 69 | + resourceType: 'Bundle', |
| 70 | + type: 'collection', |
| 71 | + entry: [], |
| 72 | + }; |
| 73 | + fhirProcedureExtractorSpy.mockClear(); |
| 74 | + when(fhirProcedureExtractorSpy).calledWith({ mrn: MOCK_PATIENT_MRN, context: {} }).mockReturnValue(emptyCollectionBundle); |
| 75 | + const procedures = await extractor.getFHIRProcedures(MOCK_PATIENT_MRN, {}); |
| 76 | + expect(fhirProcedureExtractorSpy).toHaveBeenCalled(); |
| 77 | + expect(procedures).toEqual([]); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + describe('getMCODERadiationProcedures', () => { |
| 82 | + const radiationProcedureCoding = { |
| 83 | + system: 'http://snomed.info/sct', |
| 84 | + code: '152198000', |
| 85 | + display: 'Brachytherapy (procedure)', |
| 86 | + }; |
| 87 | + const otherProcedureCoding = { |
| 88 | + system: 'http://snomed.info/sct', |
| 89 | + code: '173170008', |
| 90 | + display: 'Bilobectomy of lung', |
| 91 | + }; |
| 92 | + let fhirProcedures; |
| 93 | + beforeEach(() => { |
| 94 | + fhirProcedures = [ |
| 95 | + { |
| 96 | + fullUrl: 'urn:uuid:abc-123', |
| 97 | + resource: { |
| 98 | + resourceType: 'Procedure', |
| 99 | + id: 'abc-123', |
| 100 | + code: { |
| 101 | + coding: [otherProcedureCoding], |
| 102 | + }, |
| 103 | + }, |
| 104 | + }, |
| 105 | + ]; |
| 106 | + }); |
| 107 | + test('should return procedure that has single code in radiation procedure VS', () => { |
| 108 | + const radiationProcedure = { |
| 109 | + fullUrl: 'urn:uuid:xyz-987', |
| 110 | + resource: { |
| 111 | + resourceType: 'Procedure', |
| 112 | + id: 'xyz-987', |
| 113 | + code: { |
| 114 | + coding: [radiationProcedureCoding], |
| 115 | + }, |
| 116 | + }, |
| 117 | + }; |
| 118 | + fhirProcedures.push(radiationProcedure); |
| 119 | + const resultingProcedures = getMCODERadiationProcedures(fhirProcedures); |
| 120 | + expect(resultingProcedures).toHaveLength(1); |
| 121 | + expect(resultingProcedures).toContain(radiationProcedure); |
| 122 | + }); |
| 123 | + |
| 124 | + test('should return procedure that has any code in radiation procedure VS', () => { |
| 125 | + const radiationProcedure = { |
| 126 | + fullUrl: 'urn:uuid:xyz-987', |
| 127 | + resource: { |
| 128 | + resourceType: 'Procedure', |
| 129 | + id: 'xyz-987', |
| 130 | + code: { |
| 131 | + coding: [otherProcedureCoding, radiationProcedureCoding], |
| 132 | + }, |
| 133 | + }, |
| 134 | + }; |
| 135 | + fhirProcedures.push(radiationProcedure); |
| 136 | + const resultingProcedures = getMCODERadiationProcedures(fhirProcedures); |
| 137 | + expect(resultingProcedures).toHaveLength(1); |
| 138 | + expect(resultingProcedures).toContain(radiationProcedure); |
| 139 | + }); |
| 140 | + |
| 141 | + test('should not return procedure that has no code in radiation procedure VS', () => { |
| 142 | + const resultingProcedures = getMCODERadiationProcedures(fhirProcedures); |
| 143 | + expect(resultingProcedures).toHaveLength(0); |
| 144 | + }); |
| 145 | + |
| 146 | + test('should not return procedure that has no codes', () => { |
| 147 | + const emptyProcedure = { |
| 148 | + fullUrl: 'urn:uuid:xyz-987', |
| 149 | + resource: { |
| 150 | + resourceType: 'Procedure', |
| 151 | + id: 'xyz-987', |
| 152 | + code: { |
| 153 | + coding: [], |
| 154 | + }, |
| 155 | + }, |
| 156 | + }; |
| 157 | + fhirProcedures.push(emptyProcedure); |
| 158 | + const resultingProcedures = getMCODERadiationProcedures(fhirProcedures); |
| 159 | + expect(resultingProcedures).toHaveLength(0); |
| 160 | + }); |
| 161 | + test('should return an empty list when provided an empty list of procedures', () => { |
| 162 | + const resultingProcedures = getMCODERadiationProcedures([]); |
| 163 | + expect(resultingProcedures).toHaveLength(0); |
| 164 | + }); |
| 165 | + }); |
| 166 | + |
| 167 | + describe('get', () => { |
| 168 | + test('should return a bundle with only procedures that are MCODE cancer related radiation procedures', async () => { |
| 169 | + const bundle = { |
| 170 | + resourceType: 'Bundle', |
| 171 | + type: 'collection', |
| 172 | + entry: exampleProcedureBundle.entry, |
| 173 | + }; |
| 174 | + fhirProcedureExtractorSpy.mockClear(); |
| 175 | + when(fhirProcedureExtractorSpy).calledWith({ mrn: MOCK_PATIENT_MRN, context: {} }).mockReturnValue(bundle); |
| 176 | + const data = await extractor.get({ mrn: MOCK_PATIENT_MRN, context: {} }); |
| 177 | + expect(data.resourceType).toEqual('Bundle'); |
| 178 | + expect(data.type).toEqual('collection'); |
| 179 | + expect(data.entry).toBeDefined(); |
| 180 | + expect(data.entry).toHaveLength(1); |
| 181 | + expect(data.entry[0].resource.code.coding[0].code).toEqual('152198000'); // Brachytherapy (procedure) - is in MCODE Cancer Related Radiation Procedure VS |
| 182 | + }); |
| 183 | + }); |
| 184 | +}); |
0 commit comments