Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
reagan-meant committed Oct 9, 2024
1 parent ca0a1a1 commit be6252a
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 47 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const spaRoot = window['getOpenmrsSpaBase']();
export const historyBasePath = '/patient/:patientUuid/chart';
export const historyDashboardPath = `${historyBasePath}/:view/*`;
export const historyDashboardPath = `${historyBasePath}/:view/*`;
1 change: 0 additions & 1 deletion src/dashboard.meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export const dashboardMeta = {
path: 'Patient History',
title: 'Patient History',
};

27 changes: 12 additions & 15 deletions src/history/history-detail-overview.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,30 @@ const HistoryDetailOverview: React.FC<HistoryDetailOverviewProps> = () => {
setIsSubmitting(true);
createIpsResource(uuid, abortController)
.then((response) => {
if (response.status === 200) {
setIps((ps) => ({ ...ps, history: history, isLoading: isLoading, error: error?.message }));
setIsSubmitting(false);
showSnackbar({
isLowContrast: true,
kind: 'success',
title: t('ipsCreated', 'IPS'),
subtitle: t('ipsNowAvailable', 'The IPS has been updated and is now visible in the Patient History.'),
});
}
setIps((ps) => ({ ...ps, history: history, isLoading: isLoading, error: error?.message }));
setIsSubmitting(false);
showSnackbar({
isLowContrast: true,
kind: 'success',
title: t('ipsCreated', 'IPS'),
subtitle: t('ipsNowAvailable', 'The IPS has been updated and is now visible in the Patient History.'),
});
})
.catch((err) => {
setIps((ps) => ({ ...ps, history: null, isLoading: false, error: err?.message || 'Failed to fetch IPS' }));
setIsSubmitting(false);
showSnackbar({
title: t('ipsCreationError', 'IPS'),
title: t('ipsCreationError', 'Error updating IPS'),
kind: 'error',
isLowContrast: false,
subtitle: t(
'checkForServerAvailability',
'The Fhir server maybe unreachable or the IPS generation process exited with an error!',
'The FHIR server maybe unreachable or the IPS generation process exited with an error!',
),
});
console.error(err?.message);
})
.finally(() => {
abortController.abort();
});
.finally(() => {});
};

return (
Expand Down
6 changes: 3 additions & 3 deletions src/history/patient-history.component.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import React from 'react';
import { useParams } from 'react-router-dom';
import HistoryDetailOverview from './history-detail-overview.component';

const PatientHistory: React.FC = () => {
const { patientUuid } = useParams();
return (
<>
<HistoryDetailOverview patientUuid={patientUuid} />
<HistoryDetailOverview patientUuid={patientUuid} />
</>
);
}
};

export default PatientHistory;
18 changes: 5 additions & 13 deletions src/history/patient-history.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import HistoryDetailOverview from './history-detail-overview.component';
import React from 'react';
import { FetchResponse, usePatient } from '@openmrs/esm-framework';
import { createIpsResource, useIpsResource } from '../common/history.resource';
import { mockIPS, mockPUTResponse } from '../test.util';
import { mockIPS, mockPUTResponse } from '../__mocks__/test.util';

const mockUsePatient = jest.mocked(usePatient);
const mockUseIpsResource = jest.mocked(useIpsResource);

jest.mock('../common/history.resource');

Expand All @@ -19,14 +22,11 @@ jest.mock('react-router-dom', () => ({

describe('Display patient IPS', () => {
beforeEach(() => {
const mockUseParams = useParams as jest.Mock;
const mockUseParams = jest.mocked(useParams);
mockUseParams.mockReturnValue({ patientUuid: 'mock-uuid' });
});

it('renders without crashing', () => {
const mockUsePatient = jest.mocked(usePatient);
const mockUseIpsResource = jest.mocked(useIpsResource);

mockUsePatient.mockReturnValue({
isLoading: false,
patient: undefined,
Expand All @@ -43,9 +43,6 @@ describe('Display patient IPS', () => {
});

it('renders loading before resolving ips', async () => {
const mockUsePatient = jest.mocked(usePatient);
const mockUseIpsResource = jest.mocked(useIpsResource);

mockUsePatient.mockReturnValue({
isLoading: false,
patient: undefined,
Expand All @@ -65,9 +62,6 @@ describe('Display patient IPS', () => {
});

it('renders the ips', async () => {
const mockUsePatient = jest.mocked(usePatient);
const mockUseIpsResource = jest.mocked(useIpsResource);

mockUsePatient.mockReturnValue({
isLoading: false,
patient: undefined,
Expand Down Expand Up @@ -96,8 +90,6 @@ describe('Display patient IPS', () => {
});

it('refresh button triggers downloading new ips', async () => {
const mockUsePatient = jest.mocked(usePatient);
const mockUseIpsResource = jest.mocked(useIpsResource);
const mockCreateIpsResource = jest.mocked(createIpsResource);

mockCreateIpsResource.mockReturnValue({
Expand Down
4 changes: 2 additions & 2 deletions src/root.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const Root: React.FC = () => {
<div className={styles.patientHistoryWrapper}>
<BrowserRouter basename={spaRoot}>
<Routes>
<Route path={historyBasePath} element={<PatientHistory/>} />
<Route path={historyDashboardPath} element={<PatientHistory/>} />
<Route path={historyBasePath} element={<PatientHistory />} />
<Route path={historyDashboardPath} element={<PatientHistory />} />
</Routes>
</BrowserRouter>
</div>
Expand Down
4 changes: 2 additions & 2 deletions translations/am.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"ipsCreated": "IPS",
"ipsNowAvailable": "The IPS has been updated and is now visible in the Patient History.",
"ipsCreationError": "IPS",
"checkForServerAvailability": "The Fhir server maybe unreachable or the IPS generation process exited with an error!",
"ipsCreationError": "Error updating IPS",
"checkForServerAvailability": "The FHIR server maybe unreachable or the IPS generation process exited with an error!",
"refresh": "Refresh",
"patientHistory": "Patient History",
"criticality": "Criticality",
Expand Down
4 changes: 2 additions & 2 deletions translations/en.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"ipsCreated": "IPS",
"ipsNowAvailable": "The IPS has been updated and is now visible in the Patient History.",
"ipsCreationError": "IPS",
"checkForServerAvailability": "The Fhir server maybe unreachable or the IPS generation process exited with an error!",
"ipsCreationError": "Error updating IPS",
"checkForServerAvailability": "The FHIR server maybe unreachable or the IPS generation process exited with an error!",
"refresh": "Refresh",
"patientHistory": "Patient History",
"criticality": "Criticality",
Expand Down
4 changes: 2 additions & 2 deletions translations/es.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"ipsCreated": "IPS",
"ipsNowAvailable": "The IPS has been updated and is now visible in the Patient History.",
"ipsCreationError": "IPS",
"checkForServerAvailability": "The Fhir server maybe unreachable or the IPS generation process exited with an error!",
"ipsCreationError": "Error updating IPS",
"checkForServerAvailability": "The FHIR server maybe unreachable or the IPS generation process exited with an error!",
"refresh": "Refresh",
"patientHistory": "Patient History",
"criticality": "Criticality",
Expand Down
4 changes: 2 additions & 2 deletions translations/fr.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"ipsCreated": "IPS",
"ipsNowAvailable": "The IPS has been updated and is now visible in the Patient History.",
"ipsCreationError": "IPS",
"checkForServerAvailability": "The Fhir server maybe unreachable or the IPS generation process exited with an error!",
"ipsCreationError": "Error updating IPS",
"checkForServerAvailability": "The FHIR server maybe unreachable or the IPS generation process exited with an error!",
"refresh": "Refresh",
"patientHistory": "Antécédents du patient",
"criticality": "Criticality",
Expand Down
4 changes: 2 additions & 2 deletions translations/he.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"ipsCreated": "IPS",
"ipsNowAvailable": "The IPS has been updated and is now visible in the Patient History.",
"ipsCreationError": "IPS",
"checkForServerAvailability": "The Fhir server maybe unreachable or the IPS generation process exited with an error!",
"ipsCreationError": "Error updating IPS",
"checkForServerAvailability": "The FHIR server maybe unreachable or the IPS generation process exited with an error!",
"refresh": "Refresh",
"patientHistory": "Patient History",
"criticality": "Criticality",
Expand Down
4 changes: 2 additions & 2 deletions translations/km.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"ipsCreated": "IPS",
"ipsNowAvailable": "The IPS has been updated and is now visible in the Patient History.",
"ipsCreationError": "IPS",
"checkForServerAvailability": "The Fhir server maybe unreachable or the IPS generation process exited with an error!",
"ipsCreationError": "Error updating IPS",
"checkForServerAvailability": "The FHIR server maybe unreachable or the IPS generation process exited with an error!",
"refresh": "Refresh",
"patientHistory": "Patient History",
"criticality": "Criticality",
Expand Down

0 comments on commit be6252a

Please sign in to comment.