Skip to content

Commit

Permalink
MHV-65059 Harmonized logic for downloading BB PDF (#33503)
Browse files Browse the repository at this point in the history
* MHV-65059 Don't overwrite data if key is missing from the action payload

* MHV-65059 Modified action to only call necessary APIs

* MHV-65059 Harmonized flow for generating BB PDF

* MHV-65059 Revert test data
  • Loading branch information
mmoyer-va authored Dec 11, 2024
1 parent ab2d071 commit 75e5974
Show file tree
Hide file tree
Showing 5 changed files with 321 additions and 253 deletions.
136 changes: 79 additions & 57 deletions src/applications/mhv-medical-records/actions/blueButtonReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,64 +16,86 @@ import { Actions } from '../util/actionTypes';
import * as Constants from '../util/constants';
import { addAlert } from './alerts';

export const getBlueButtonReportData = () => async dispatch => {
export const getBlueButtonReportData = (options = {}) => async dispatch => {
try {
const [
labs,
notes,
vaccines,
allergies,
conditions,
vitals,
radiology,
medications,
appointments,
demographics,
militaryService,
patient,
] = await Promise.all([
getLabsAndTests(),
getNotes(),
getVaccineList(),
getAllergies(),
getConditions(),
getVitalsList(),
getMhvRadiologyTests(),
getMedications(),
getAppointments(),
getDemographicInfo(),
getMilitaryService(),
getPatient(),
]);
dispatch({
type: Actions.LabsAndTests.GET_LIST,
labsAndTestsResponse: labs,
radiologyResponse: radiology,
});
dispatch({
type: Actions.CareSummariesAndNotes.GET_LIST,
response: notes,
});
dispatch({
type: Actions.Vaccines.GET_LIST,
response: vaccines,
});
dispatch({
type: Actions.Allergies.GET_LIST,
response: allergies,
});
dispatch({
type: Actions.Conditions.GET_LIST,
response: conditions,
});
dispatch({ type: Actions.Vitals.GET_LIST, response: vitals });
dispatch({
type: Actions.BlueButtonReport.GET,
medicationsResponse: medications,
appointmentsResponse: appointments,
demographicsResponse: demographics,
militaryServiceResponse: militaryService,
patientResponse: patient,
const fetchMap = {
labs: getLabsAndTests,
notes: getNotes,
vaccines: getVaccineList,
allergies: getAllergies,
conditions: getConditions,
vitals: getVitalsList,
radiology: getMhvRadiologyTests,
medications: getMedications,
appointments: getAppointments,
demographics: getDemographicInfo,
militaryService: getMilitaryService,
patient: getPatient,
};

const promises = Object.entries(fetchMap)
.filter(([key]) => options[key]) // Only include enabled fetches
.map(([key, fetchFn]) => fetchFn().then(response => ({ key, response })));

const results = await Promise.all(promises);

results.forEach(({ key, response }) => {
switch (key) {
case 'labs':
dispatch({
type: Actions.LabsAndTests.GET_LIST,
labsAndTestsResponse: response,
});
break;
case 'notes':
dispatch({
type: Actions.CareSummariesAndNotes.GET_LIST,
response,
});
break;
case 'vaccines':
dispatch({
type: Actions.Vaccines.GET_LIST,
response,
});
break;
case 'allergies':
dispatch({
type: Actions.Allergies.GET_LIST,
response,
});
break;
case 'conditions':
dispatch({
type: Actions.Conditions.GET_LIST,
response,
});
break;
case 'vitals':
dispatch({
type: Actions.Vitals.GET_LIST,
response,
});
break;
case 'radiology':
dispatch({
type: Actions.LabsAndTests.GET_LIST,
radiologyResponse: response,
});
break;
case 'medications':
case 'appointments':
case 'demographics':
case 'militaryService':
case 'patient':
dispatch({
type: Actions.BlueButtonReport.GET,
[`${key}Response`]: response,
});
break;
default:
break;
}
});
} catch (error) {
dispatch(addAlert(Constants.ALERT_TYPE_ERROR, error));
Expand Down
Loading

0 comments on commit 75e5974

Please sign in to comment.