From ead59e4ba104644298ba1a61d3a77d9eb1ee2e3c Mon Sep 17 00:00:00 2001 From: Dylan Mendelowitz Date: Mon, 11 Sep 2023 15:04:19 -0400 Subject: [PATCH] Making encounterId required --- src/extractors/CSVEncounterExtractor.js | 4 ++-- src/helpers/schemas/csv.js | 2 +- test/extractors/CSVEncounterExtractor.test.js | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/extractors/CSVEncounterExtractor.js b/src/extractors/CSVEncounterExtractor.js index 043aaab..1713c9a 100644 --- a/src/extractors/CSVEncounterExtractor.js +++ b/src/extractors/CSVEncounterExtractor.js @@ -21,8 +21,8 @@ function formatData(encounterData, patientId) { enddate: endDate, } = data; - if (!(status && classCode && classSystem)) { - throw Error('Missing required field for Encounter CSV Extraction: status, classCode or classSystem'); + if (!(encounterId && status && classCode && classSystem)) { + throw Error('Missing required field for Encounter CSV Extraction: encounterId, status, classCode or classSystem'); } return { diff --git a/src/helpers/schemas/csv.js b/src/helpers/schemas/csv.js index a905c34..04f813a 100644 --- a/src/helpers/schemas/csv.js +++ b/src/helpers/schemas/csv.js @@ -208,7 +208,7 @@ const CSVCTCAdverseEventSchema = { const CSVEncounterSchema = { headers: [ { name: 'mrn', required: true }, - { name: 'encounterId' }, + { name: 'encounterId', required: true }, { name: 'status', required: true }, { name: 'classCode', required: true }, { name: 'classSystem', required: true }, diff --git a/test/extractors/CSVEncounterExtractor.test.js b/test/extractors/CSVEncounterExtractor.test.js index df46c63..9f420d4 100644 --- a/test/extractors/CSVEncounterExtractor.test.js +++ b/test/extractors/CSVEncounterExtractor.test.js @@ -33,20 +33,20 @@ const csvModuleSpy = jest.spyOn(csvModule, 'get'); describe('CSVEncounterExtractor', () => { describe('formatData', () => { test('should format data appropriately and throw errors when missing required properties', () => { - const expectedErrorString = 'Missing required field for Encounter CSV Extraction: status, classCode or classSystem'; + const expectedErrorString = 'Missing required field for Encounter CSV Extraction: encounterId, status, classCode or classSystem'; const localData = _.cloneDeep(exampleCSVEncounterModuleResponse); const patientId = getPatientFromContext(MOCK_CONTEXT).id; // Test that valid data works fine expect(formatData(exampleCSVEncounterModuleResponse, patientId)).toEqual(expect.anything()); - localData[0].typecode = ''; // Evidence is not required and will not throw an error - localData[0].enddate = ''; // Observation Status is not required and will not throw an error + localData[0].typecode = ''; + localData[0].enddate = ''; // Only including required properties is valid expect(formatData(localData, patientId)).toEqual(expect.anything()); - const requiredProperties = ['status', 'classcode', 'classsystem']; + const requiredProperties = ['encounterid', 'status', 'classcode', 'classsystem']; // Removing each required property should throw an error requiredProperties.forEach((key) => {