Skip to content

Commit

Permalink
Making encounterId required
Browse files Browse the repository at this point in the history
  • Loading branch information
dmendelowitz committed Sep 11, 2023
1 parent 5de91f2 commit ead59e4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/extractors/CSVEncounterExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/schemas/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
8 changes: 4 additions & 4 deletions test/extractors/CSVEncounterExtractor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit ead59e4

Please sign in to comment.