Skip to content

Commit

Permalink
VAMC system/facilities selectors, connectors, and tests (#27557)
Browse files Browse the repository at this point in the history
* selectors, connectors, and tests

* rename test
  • Loading branch information
eselkin authored and Peter Hill committed Mar 14, 2024
1 parent 6935c95 commit 71292c4
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { connectDrupalStaticDataFile } from '../../../connect';
import { preProcessSystemData } from './preProcess';

export const connectDrupalStaticDataFileVamcSystem = dispatch => {
connectDrupalStaticDataFile(dispatch, {
fileName: 'vamc-system.json',
preProcess: preProcessSystemData,
statePropName: 'vamcSystemData',
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Structure of vamcSystemData:
*
* {
* "data": {
* "systems": {
* "VAMC System name": {
* "vhaId": "Facility name",
* }
* }
* }
* }
* vhaId is used to lookup the facility in whatever other source it's needed (e.g. police data is id'ed by facility vhaId)
*/

export const preProcessSystemData = vamcSystemData => {
return vamcSystemData;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// breaks unit tests if we use the workspace import
// eslint-disable-next-line @department-of-veterans-affairs/use-workspace-imports
import { selectDrupalStaticData } from 'platform/site-wide/drupal-static-data/selectors';

export const selectVamcSystemData = state =>
selectDrupalStaticData(state)?.vamcSystemData?.data.systems || {};

// Returns an array of [vhaId, facilityName] tuples
export const selectFacilitiesForSystem = (state, systemName) =>
Object.entries(selectVamcSystemData(state)?.[systemName] || {}) || [];
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* eslint-disable camelcase */
import { expect } from 'chai';
import { preProcessSystemData } from '../connect/preProcess';

describe('does nothing, output format is same as source', () => {
const vamcSystemData = {
data: {
systems: {
'VA Pittsburgh health care': {
vha_646GC: 'Beaver County VA Clinic',
vha_646GA: 'Belmont County VA Clinic',
vha_646GE: 'Fayette County VA Clinic',
vha_646A4:
'H. John Heinz III Department of Veterans Affairs Medical Center',
vha_646GF: 'Monroeville VA Clinic',
vha_646: 'Pittsburgh VA Medical Center-University Drive',
vha_646GD: 'Washington County VA Clinic',
vha_646GB: 'Westmoreland County VA Clinic',
},
'VA Altoona health care': {
vha_503GB: 'DuBois VA Clinic',
vha_503GD: 'Huntingdon County VA Clinic',
vha_503GE: 'Indiana County VA Clinic',
vha_503: "James E. Van Zandt Veterans' Administration Medical Center",
vha_503GA: 'Johnstown VA Clinic',
vha_503GC: 'State College VA Clinic',
},
},
},
};

it('returns empty objects when no data present', () => {
const emptyVamcSystemData = {};
expect(preProcessSystemData(emptyVamcSystemData)).to.deep.equal({});
});

it('does not change input', () => {
expect(preProcessSystemData(vamcSystemData)).to.deep.equal(vamcSystemData);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* eslint-disable camelcase */
import { expect } from 'chai';
import { selectFacilitiesForSystem, selectVamcSystemData } from '../selectors';

describe('getVamcSystemNameFromVhaId', () => {
const drupalStaticData = {
drupalStaticData: {
vamcSystemData: {
data: {
systems: {
'VA Pittsburgh health care': {
vha_646GC: 'Beaver County VA Clinic',
vha_646GA: 'Belmont County VA Clinic',
vha_646GE: 'Fayette County VA Clinic',
vha_646A4:
'H. John Heinz III Department of Veterans Affairs Medical Center',
vha_646GF: 'Monroeville VA Clinic',
vha_646: 'Pittsburgh VA Medical Center-University Drive',
vha_646GD: 'Washington County VA Clinic',
vha_646GB: 'Westmoreland County VA Clinic',
},
'VA Altoona health care': {
vha_503GB: 'DuBois VA Clinic',
vha_503GD: 'Huntingdon County VA Clinic',
vha_503GE: 'Indiana County VA Clinic',
vha_503:
"James E. Van Zandt Veterans' Administration Medical Center",
vha_503GA: 'Johnstown VA Clinic',
vha_503GC: 'State College VA Clinic',
},
},
},
},
},
};

it('selects VAMC facility id name tuples', () => {
expect(selectVamcSystemData(drupalStaticData)).to.deep.equal(
drupalStaticData.drupalStaticData.vamcSystemData.data.systems,
);
expect(
selectFacilitiesForSystem(drupalStaticData, 'VA Altoona health care'),
).to.deep.equal([
['vha_503GB', 'DuBois VA Clinic'],
['vha_503GD', 'Huntingdon County VA Clinic'],
['vha_503GE', 'Indiana County VA Clinic'],
['vha_503', "James E. Van Zandt Veterans' Administration Medical Center"],
['vha_503GA', 'Johnstown VA Clinic'],
['vha_503GC', 'State College VA Clinic'],
]);
});
});

0 comments on commit 71292c4

Please sign in to comment.