Skip to content

Commit

Permalink
MHV-65164 MHV-65254 Handle labs & tests and radiology together (#33583)
Browse files Browse the repository at this point in the history
* Prevent React state update on an unmounted component

* MHV-65164 Ensure labs & tests and radiology are handled together
  • Loading branch information
mmoyer-va authored Dec 16, 2024
1 parent e523d07 commit bb1e877
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
24 changes: 15 additions & 9 deletions src/applications/mhv-medical-records/actions/blueButtonReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,19 @@ export const getBlueButtonReportData = (options = {}) => async dispatch => {

const results = await Promise.allSettled(promises);

// Temporary variables to hold labsAndTests and radiology results
let labsAndTestsResponse = null;
let radiologyResponse = null;

results.forEach(({ status, value, reason }) => {
if (status === 'fulfilled') {
const { key, response } = value;
switch (key) {
case 'labsAndTests':
dispatch({
type: Actions.LabsAndTests.GET_LIST,
labsAndTestsResponse: response,
});
labsAndTestsResponse = response;
break;
// TODO: Handle this with labs
case 'radiology':
dispatch({
type: Actions.LabsAndTests.GET_LIST,
radiologyResponse: response,
});
radiologyResponse = response;
break;
case 'notes':
dispatch({
Expand Down Expand Up @@ -114,4 +111,13 @@ export const getBlueButtonReportData = (options = {}) => async dispatch => {
dispatch({ type: Actions.BlueButtonReport.ADD_FAILED, payload: key });
}
});

// Dispatch combined labsAndTests and radiology response
if (labsAndTestsResponse || radiologyResponse) {
dispatch({
type: Actions.LabsAndTests.GET_LIST,
labsAndTestsResponse,
radiologyResponse,
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ const DownloadFileType = props => {
() => {
const options = {
labsAndTests: recordFilter?.includes('labTests'),
radiology: recordFilter?.includes('labTests'),
notes: recordFilter?.includes('careSummaries'),
vaccines: recordFilter?.includes('vaccines'),
allergies:
Expand Down
5 changes: 4 additions & 1 deletion src/applications/mhv-medical-records/containers/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,18 @@ const App = ({ children }) => {
useEffect(
() => {
if (!current) return () => {};
let isMounted = true; // Flag to prevent React state update on an unmounted component

const resizeObserver = new ResizeObserver(() => {
requestAnimationFrame(() => {
if (height !== current.offsetHeight) {
if (isMounted && height !== current.offsetHeight) {
setHeight(current.offsetHeight);
}
});
});
resizeObserver.observe(current);
return () => {
isMounted = false;
if (current) {
resizeObserver.unobserve(current);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,22 @@ describe('getBlueButtonReportData', () => {
);
});
});

it('should dispatch combined labsAndTests and radiology responses in a single action', () => {
const mockData = { mockData: 'mockData' };
mockApiRequest(mockData);
const dispatch = sinon.spy();

return getBlueButtonReportData({ labsAndTests: true, radiology: true })(
dispatch,
).then(() => {
// Verify dispatch was called once for the combined action
expect(dispatch.calledOnce).to.be.true;

const action = dispatch.firstCall.args[0];
expect(action.type).to.equal(Actions.LabsAndTests.GET_LIST);
expect(action.labsAndTestsResponse).to.deep.equal(mockData);
expect(action.radiologyResponse).to.deep.equal(mockData);
});
});
});

0 comments on commit bb1e877

Please sign in to comment.