Skip to content

Commit

Permalink
MHV-64662 Add error handling for self-entered data APIs (#33330)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoyer-va authored Dec 4, 2024
1 parent 2a0d8da commit 0741997
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 65 deletions.
249 changes: 184 additions & 65 deletions src/applications/mhv-medical-records/actions/selfEnteredData.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,96 +14,215 @@ import {
getSeiActivityJournal,
getSeiMedications,
} from '../api/seiApi';
import { selfEnteredTypes } from '../util/constants';

export const clearErrors = () => async dispatch => {
dispatch({ type: Actions.SelfEntered.CLEAR_ERRORS });
};

export const getSelfEnteredVitals = () => async dispatch => {
const response = await getSeiVitalSigns();
dispatch({
type: Actions.SelfEntered.GET_VITALS,
payload: response,
});
try {
const response = await getSeiVitalSigns();
dispatch({
type: Actions.SelfEntered.GET_VITALS,
payload: response,
});
} catch (error) {
dispatch({
type: Actions.SelfEntered.ADD_ERROR,
payload: { type: selfEnteredTypes.VITALS },
});
throw error;
}
};

export const getSelfEnteredAllergies = () => async dispatch => {
const response = await getSeiAllergies();
dispatch({
type: Actions.SelfEntered.GET_ALLERGIES,
payload: response,
});
try {
const response = await getSeiAllergies();
dispatch({
type: Actions.SelfEntered.GET_ALLERGIES,
payload: response,
});
} catch (error) {
dispatch({
type: Actions.SelfEntered.ADD_ERROR,
payload: { type: selfEnteredTypes.ALLERGIES },
});
throw error;
}
};

export const getSelfEnteredFamilyHistory = () => async dispatch => {
const response = await getSeiFamilyHistory();
dispatch({
type: Actions.SelfEntered.GET_FAMILY_HISTORY,
payload: response,
});
try {
const response = await getSeiFamilyHistory();
dispatch({
type: Actions.SelfEntered.GET_FAMILY_HISTORY,
payload: response,
});
} catch (error) {
dispatch({
type: Actions.SelfEntered.ADD_ERROR,
payload: { type: selfEnteredTypes.FAMILY_HISTORY },
});
throw error;
}
};

export const getSelfEnteredVaccines = () => async dispatch => {
const response = await getSeiVaccines();
dispatch({
type: Actions.SelfEntered.GET_VACCINES,
payload: response,
});
try {
const response = await getSeiVaccines();
dispatch({
type: Actions.SelfEntered.GET_VACCINES,
payload: response,
});
} catch (error) {
dispatch({
type: Actions.SelfEntered.ADD_ERROR,
payload: { type: selfEnteredTypes.VACCINES },
});
throw error;
}
};

export const getSelfEnteredTestEntries = () => async dispatch => {
const response = await getSeiTestEntries();
dispatch({
type: Actions.SelfEntered.GET_TEST_ENTRIES,
payload: response,
});
try {
const response = await getSeiTestEntries();
dispatch({
type: Actions.SelfEntered.GET_TEST_ENTRIES,
payload: response,
});
} catch (error) {
dispatch({
type: Actions.SelfEntered.ADD_ERROR,
payload: { type: selfEnteredTypes.TEST_ENTRIES },
});
throw error;
}
};

export const getSelfEnteredMedicalEvents = () => async dispatch => {
const response = await getSeiMedicalEvents();
dispatch({
type: Actions.SelfEntered.GET_MEDICAL_EVENTS,
payload: response,
});
try {
const response = await getSeiMedicalEvents();
dispatch({
type: Actions.SelfEntered.GET_MEDICAL_EVENTS,
payload: response,
});
} catch (error) {
dispatch({
type: Actions.SelfEntered.ADD_ERROR,
payload: { type: selfEnteredTypes.MEDICAL_EVENTS },
});
throw error;
}
};

export const getSelfEnteredMilitaryHistory = () => async dispatch => {
const response = await getSeiMilitaryHistory();
dispatch({
type: Actions.SelfEntered.GET_MILITARY_HISTORY,
payload: response,
});
try {
const response = await getSeiMilitaryHistory();
dispatch({
type: Actions.SelfEntered.GET_MILITARY_HISTORY,
payload: response,
});
} catch (error) {
dispatch({
type: Actions.SelfEntered.ADD_ERROR,
payload: { type: selfEnteredTypes.MILITARY_HISTORY },
});
throw error;
}
};
export const getSelfEnteredProviders = () => async dispatch => {
const response = await getSeiProviders();
dispatch({
type: Actions.SelfEntered.GET_PROVIDERS,
payload: response,
});
try {
const response = await getSeiProviders();
dispatch({
type: Actions.SelfEntered.GET_PROVIDERS,
payload: response,
});
} catch (error) {
dispatch({
type: Actions.SelfEntered.ADD_ERROR,
payload: { type: selfEnteredTypes.HEALTH_PROVIDERS },
});
throw error;
}
};

export const getSelfEnteredHealthInsurance = () => async dispatch => {
const response = await getSeiHealthInsurance();
dispatch({
type: Actions.SelfEntered.GET_HEALTH_INSURANCE,
payload: response,
});
try {
const response = await getSeiHealthInsurance();
dispatch({
type: Actions.SelfEntered.GET_HEALTH_INSURANCE,
payload: response,
});
} catch (error) {
dispatch({
type: Actions.SelfEntered.ADD_ERROR,
payload: { type: selfEnteredTypes.HEALTH_INSURANCE },
});
throw error;
}
};

export const getSelfEnteredTreatmentFacilities = () => async dispatch => {
const response = await getSeiTreatmentFacilities();
dispatch({
type: Actions.SelfEntered.GET_TREATMENT_FACILITIES,
payload: response,
});
try {
const response = await getSeiTreatmentFacilities();
dispatch({
type: Actions.SelfEntered.GET_TREATMENT_FACILITIES,
payload: response,
});
} catch (error) {
dispatch({
type: Actions.SelfEntered.ADD_ERROR,
payload: { type: selfEnteredTypes.TREATMENT_FACILITIES },
});
throw error;
}
};

export const getSelfEnteredFoodJournal = () => async dispatch => {
const response = await getSeiFoodJournal();
dispatch({
type: Actions.SelfEntered.GET_FOOD_JOURNAL,
payload: response,
});
try {
const response = await getSeiFoodJournal();
dispatch({
type: Actions.SelfEntered.GET_FOOD_JOURNAL,
payload: response,
});
} catch (error) {
dispatch({
type: Actions.SelfEntered.ADD_ERROR,
payload: { type: selfEnteredTypes.FOOD_JOURNAL },
});
throw error;
}
};

export const getSelfEnteredActivityJournal = () => async dispatch => {
const response = await getSeiActivityJournal();
dispatch({
type: Actions.SelfEntered.GET_ACTIVITY_JOURNAL,
payload: response,
});
try {
const response = await getSeiActivityJournal();
dispatch({
type: Actions.SelfEntered.GET_ACTIVITY_JOURNAL,
payload: response,
});
} catch (error) {
dispatch({
type: Actions.SelfEntered.ADD_ERROR,
payload: { type: selfEnteredTypes.ACTIVITY_JOURNAL },
});
throw error;
}
};

export const getSelfEnteredMedications = () => async dispatch => {
const response = await getSeiMedications();
dispatch({
type: Actions.SelfEntered.GET_MEDICATIONS,
payload: response,
});
try {
const response = await getSeiMedications();
dispatch({
type: Actions.SelfEntered.GET_MEDICATIONS,
payload: response,
});
} catch (error) {
dispatch({
type: Actions.SelfEntered.ADD_ERROR,
payload: { type: selfEnteredTypes.MEDICATIONS },
});
throw error;
}
};
13 changes: 13 additions & 0 deletions src/applications/mhv-medical-records/reducers/selfEnteredData.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const initialState = {
foodJournal: undefined,
activityJournal: undefined,
medications: undefined,
errors: [],
};

export const NONE_ENTERED = 'None entered';
Expand Down Expand Up @@ -811,6 +812,18 @@ export const selfEnteredReducer = (state = initialState, action) => {
medications: convertMedications(action.payload),
};
}
case Actions.SelfEntered.CLEAR_ERRORS: {
return {
...state,
errors: [],
};
}
case Actions.SelfEntered.ADD_ERROR: {
return {
...state,
errors: [...state.errors, action.payload.type],
};
}
default:
return state;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from 'chai';
import { Actions } from '../../util/actionTypes';
import {
convertActivityJournal,
convertAllergies,
Expand Down Expand Up @@ -28,8 +29,10 @@ import {
formatTimestamp,
mapValue,
NONE_ENTERED,
selfEnteredReducer,
sortDesc,
} from '../../reducers/selfEnteredData';
import { selfEnteredTypes } from '../../util/constants';
import seiVitals from '../fixtures/sei/seiVitals.json';

describe('mapValue', () => {
Expand Down Expand Up @@ -1558,3 +1561,35 @@ describe('convertMedications', () => {
expect(convertMedications([])).to.deep.equal([]);
});
});

describe('selfEnteredReducer', () => {
it('adds errors', () => {
let newState = selfEnteredReducer(
{ errors: [] },
{
type: Actions.SelfEntered.ADD_ERROR,
payload: { type: selfEnteredTypes.VITALS },
},
);

expect(newState.errors.length).to.equal(1);
expect(newState.errors[0]).to.equal(selfEnteredTypes.VITALS);

newState = selfEnteredReducer(newState, {
type: Actions.SelfEntered.ADD_ERROR,
payload: { type: selfEnteredTypes.ALLERGIES },
});

expect(newState.errors.length).to.equal(2);
expect(newState.errors[1]).to.equal(selfEnteredTypes.ALLERGIES);
});

it('clears errors', () => {
const newState = selfEnteredReducer(
{ errors: [selfEnteredTypes.VITALS] },
{ type: Actions.SelfEntered.CLEAR_ERRORS },
);

expect(newState.errors.length).to.equal(0);
});
});
2 changes: 2 additions & 0 deletions src/applications/mhv-medical-records/util/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,7 @@ export const Actions = {
GET_FOOD_JOURNAL: 'MR_SELF_ENTERED_GET_FOOD_JOURNAL',
GET_ACTIVITY_JOURNAL: 'MR_SELF_ENTERED_GET_ACTIVITY_JOURNAL',
GET_MEDICATIONS: 'MR_SELF_ENTERED_GET_MEDICATIONS',
CLEAR_ERRORS: 'MR_SELF_ENTERED_CLEAR_ERRORS',
ADD_ERROR: 'MR_SELF_ENTERED_ADD_ERROR',
},
};
16 changes: 16 additions & 0 deletions src/applications/mhv-medical-records/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,22 @@ export const pageTitles = {
'Medical Records Settings - Medical Records | Veterans Affairs',
};

export const selfEnteredTypes = {
VITALS: 'vitals',
ALLERGIES: 'allergies',
FAMILY_HISTORY: 'family history',
VACCINES: 'vaccines',
TEST_ENTRIES: 'test entries',
MEDICAL_EVENTS: 'medical events',
MILITARY_HISTORY: 'military history',
HEALTH_PROVIDERS: 'health providers',
HEALTH_INSURANCE: 'health insurance',
TREATMENT_FACILITIES: 'treatment facilities',
FOOD_JOURNAL: 'food journal',
ACTIVITY_JOURNAL: 'activity journal',
MEDICATIONS: 'medications',
};

export const allergyTypes = {
OBSERVED:
'Observed (you experienced this allergy or reaction while you were getting care at this VA location)',
Expand Down

0 comments on commit 0741997

Please sign in to comment.