-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(fix) O3-1895 Edit Past Visit button does not work (#1269)
* O3-1895 Edit Past Visit button does not work * Rename * Upgrade core * Update translations * Upgrade core * Translations --------- Co-authored-by: Dennis Kigen <kigen.work@gmail.com>
- Loading branch information
1 parent
709d467
commit d38cd96
Showing
29 changed files
with
372 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
packages/esm-patient-banner-app/src/banner-tags/active-visit-tag.component.tsx
This file was deleted.
Oops, something went wrong.
54 changes: 0 additions & 54 deletions
54
packages/esm-patient-banner-app/src/banner-tags/active-visit-tag.test.tsx
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
packages/esm-patient-banner-app/src/banner-tags/visit-tag.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Tag, Toggletip, ToggletipButton, ToggletipContent } from '@carbon/react'; | ||
import { Visit, formatDatetime, parseDate } from '@openmrs/esm-framework'; | ||
import { useVisitOrOfflineVisit } from '@openmrs/esm-patient-common-lib'; | ||
import styles from './visit-tag.scss'; | ||
|
||
interface VisitTagProps { | ||
patientUuid: string; | ||
patient: fhir.Patient; | ||
} | ||
|
||
const VisitTag: React.FC<VisitTagProps> = ({ patientUuid, patient }) => { | ||
const { currentVisit, isRetrospective } = useVisitOrOfflineVisit(patientUuid); | ||
const isNotDeceased = !patient.deceasedDateTime; | ||
return ( | ||
currentVisit && | ||
(isRetrospective ? ( | ||
<RetrospectiveEntryTag currentVisit={currentVisit} /> | ||
) : ( | ||
isNotDeceased && <ActiveVisitTag currentVisit={currentVisit} /> | ||
)) | ||
); | ||
}; | ||
|
||
interface ActiveVisitTagProps { | ||
currentVisit: Visit; | ||
} | ||
|
||
const ActiveVisitTag: React.FC<ActiveVisitTagProps> = ({ currentVisit }) => { | ||
const { t } = useTranslation(); | ||
return ( | ||
<Toggletip align="bottom"> | ||
<ToggletipButton label={t('activeVisit', 'Active Visit')}> | ||
<Tag type="blue">{t('activeVisit', 'Active Visit')}</Tag> | ||
</ToggletipButton> | ||
<ToggletipContent> | ||
<div role="tooltip"> | ||
<h6 className={styles.heading}>{currentVisit?.visitType?.display}</h6> | ||
<span> | ||
<span className={styles.tooltipSmallText}>{t('started', 'Started')}: </span> | ||
<span>{formatDatetime(parseDate(currentVisit?.startDatetime), { mode: 'wide' })}</span> | ||
</span> | ||
</div> | ||
</ToggletipContent> | ||
</Toggletip> | ||
); | ||
}; | ||
|
||
interface RetrospectiveEntryTagProps { | ||
currentVisit: Visit; | ||
} | ||
|
||
const RetrospectiveEntryTag: React.FC<RetrospectiveEntryTagProps> = ({ currentVisit }) => { | ||
const { t } = useTranslation(); | ||
return ( | ||
<Toggletip align="bottom"> | ||
<ToggletipButton label={t('retrospectiveEntry', 'Retrospective Entry')}> | ||
<Tag type="purple">{t('retrospectiveEntry', 'Retrospective Entry')}</Tag> | ||
</ToggletipButton> | ||
<ToggletipContent> | ||
<div role="tooltip"> | ||
<h6 className={styles.heading}>{currentVisit?.visitType?.display}</h6> | ||
<div> | ||
<span className={styles.tooltipSmallText}>{t('startDate', 'Start date')}: </span> | ||
<span>{formatDatetime(parseDate(currentVisit?.startDatetime), { mode: 'wide' })}</span> | ||
</div> | ||
<div> | ||
<span className={styles.tooltipSmallText}>{t('endDate', 'End date')}: </span> | ||
<span>{formatDatetime(parseDate(currentVisit?.stopDatetime), { mode: 'wide' })}</span> | ||
</div> | ||
</div> | ||
</ToggletipContent> | ||
</Toggletip> | ||
); | ||
}; | ||
|
||
export default VisitTag; |
2 changes: 1 addition & 1 deletion
2
...app/src/banner-tags/active-visit-tag.scss → ...banner-app/src/banner-tags/visit-tag.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.tooltipPadding { | ||
.tooltipBox { | ||
padding: 0.25rem; | ||
} | ||
|
||
|
87 changes: 87 additions & 0 deletions
87
packages/esm-patient-banner-app/src/banner-tags/visit-tag.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { mockPatient } from '../../../../__mocks__/patient.mock'; | ||
import VisitTag from './visit-tag.component'; | ||
import { formatDatetime } from '@openmrs/esm-framework'; | ||
import { mockCurrentVisit } from '../../../../__mocks__/visits.mock'; | ||
import { useVisitOrOfflineVisit } from '@openmrs/esm-patient-common-lib'; | ||
|
||
const mockUseVisitOrOfflineVisit = useVisitOrOfflineVisit as jest.Mock; | ||
|
||
jest.mock('@openmrs/esm-patient-common-lib', () => ({ | ||
...(jest.requireActual('@openmrs/esm-patient-common-lib') as any), | ||
useVisitOrOfflineVisit: jest.fn(), | ||
})); | ||
|
||
describe('VisitBannerTag: ', () => { | ||
it('renders an active visit tag when an active visit is ongoing', () => { | ||
mockUseVisitOrOfflineVisit.mockReturnValue({ | ||
currentVisit: mockCurrentVisit, | ||
isRetrospective: false, | ||
error: null, | ||
}); | ||
const patient = { ...mockPatient, deceasedDateTime: null }; | ||
render(<VisitTag patientUuid={mockPatient.id} patient={patient} />); | ||
|
||
const visitMetadata = | ||
mockCurrentVisit.visitType.display + | ||
' Started: ' + | ||
formatDatetime(mockCurrentVisit.startDatetime, { mode: 'wide' }); | ||
|
||
expect( | ||
screen.getByRole('tooltip', { | ||
name: visitMetadata, | ||
}), | ||
).toBeInTheDocument(); | ||
expect(screen.getByRole('button', { name: /Active Visit/i })).toBeInTheDocument(); | ||
expect(screen.queryByRole('button', { name: /Retrospective Entry/i })).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('renders a retrospective visit tag when a retrospective visit is ongoing', () => { | ||
const currentVisit = { ...mockCurrentVisit, stopDatetime: new Date('2021-03-16T10:05:00.000+0000') }; | ||
mockUseVisitOrOfflineVisit.mockReturnValue({ | ||
currentVisit, | ||
isRetrospective: true, | ||
error: null, | ||
}); | ||
const patient = { ...mockPatient, deceasedDateTime: null }; | ||
render(<VisitTag patientUuid={mockPatient.id} patient={patient} />); | ||
|
||
const visitMetadata = | ||
currentVisit.visitType.display + | ||
' Start date: ' + | ||
formatDatetime(currentVisit.startDatetime, { mode: 'wide' }) + | ||
' End date: ' + | ||
formatDatetime(currentVisit.stopDatetime, { mode: 'wide' }); | ||
|
||
expect( | ||
screen.getByRole('tooltip', { | ||
name: visitMetadata, | ||
}), | ||
).toBeInTheDocument(); | ||
expect(screen.getByRole('button', { name: /Retrospective Entry/i })).toBeInTheDocument(); | ||
expect(screen.queryByRole('button', { name: /Active Visit/i })).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should not render active visit tag for deceased patients', () => { | ||
mockUseVisitOrOfflineVisit.mockReturnValue({ | ||
currentVisit: mockCurrentVisit, | ||
isRetrospective: false, | ||
error: null, | ||
}); | ||
const patient = { ...mockPatient, deceasedDateTime: '2002-04-04' }; | ||
render(<VisitTag patientUuid={mockPatient.id} patient={patient} />); | ||
expect(screen.queryByRole('button', { name: /Active Visit/i })).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('renders retrospective visit tag for deceased patients', () => { | ||
mockUseVisitOrOfflineVisit.mockReturnValue({ | ||
currentVisit: { mockCurrentVisit, stopDatetime: new Date('2021-03-16T10:05:00.000+0000') }, | ||
isRetrospective: true, | ||
error: null, | ||
}); | ||
const patient = { ...mockPatient, deceasedDateTime: '2002-04-04' }; | ||
render(<VisitTag patientUuid={mockPatient.id} patient={patient} />); | ||
expect(screen.getByRole('button', { name: /Retrospective Entry/i })).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.