-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(feat) O3-3604: Add notes history section on inpatient notes workspace #1269
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f4e486f
feat: add patient notes history
usamaidrsk e2860a5
chore: add tests
usamaidrsk 022d65f
Reset yarn.lock to its state in the last commit
usamaidrsk 68c492f
render nothing if no notes to show as histoy
usamaidrsk fe7cb30
add failed to load notes inline notification
usamaidrsk a3a4acd
remove dummy filtering
usamaidrsk 20caf1a
fix: use useEmrConfigurationemr hook and not props
usamaidrsk 1173f7b
fix: fix tests
usamaidrsk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
packages/esm-ward-app/src/ward-patient-card/ward-patient-card.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
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
13 changes: 0 additions & 13 deletions
13
packages/esm-ward-app/src/ward-workspace/ward-patient-notes/form/notes-form.resource.ts
This file was deleted.
Oops, something went wrong.
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
53 changes: 53 additions & 0 deletions
53
packages/esm-ward-app/src/ward-workspace/ward-patient-notes/history/note.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,53 @@ | ||
import React from 'react'; | ||
import { type PatientNote } from '../types'; | ||
import { SkeletonText, Tag, Tile } from '@carbon/react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import dayjs from 'dayjs'; | ||
import styles from './styles.scss'; | ||
|
||
export const InPatientNoteSkeleton: React.FC = () => { | ||
return ( | ||
<Tile className={styles.noteTile} data-testid="in-patient-note-skeleton"> | ||
<div className={styles.noteHeader}> | ||
<SkeletonText heading width="30%" /> | ||
<SkeletonText width="20%" /> | ||
</div> | ||
<SkeletonText width="15%" /> | ||
<SkeletonText width="100%" /> | ||
<SkeletonText width="80%" /> | ||
</Tile> | ||
); | ||
}; | ||
|
||
interface InPatientNoteProps { | ||
note: PatientNote; | ||
} | ||
|
||
const InPatientNote: React.FC<InPatientNoteProps> = ({ note }) => { | ||
const { t } = useTranslation(); | ||
const formattedDate = note.encounterNoteRecordedAt | ||
? dayjs(note.encounterNoteRecordedAt).format('dddd, D MMM YYYY') | ||
: ''; | ||
const formattedTime = note.encounterNoteRecordedAt ? dayjs(note.encounterNoteRecordedAt).format('HH:mm') : ''; | ||
|
||
return ( | ||
<Tile className={styles.noteTile}> | ||
<div className={styles.noteHeader}> | ||
<span className={styles.noteProviderRole}>{t('note', 'Note')}</span> | ||
<span className={styles.noteDateAndTime}> | ||
{formattedDate}, {formattedTime} | ||
</span> | ||
</div> | ||
{note.diagnoses && | ||
note.diagnoses.split(',').map((diagnosis, index) => ( | ||
<Tag key={index} type="red"> | ||
{diagnosis.trim()} | ||
</Tag> | ||
))} | ||
<div className={styles.noteBody}>{note.encounterNote}</div> | ||
<div className={styles.noteProviderName}>{note.encounterProvider}</div> | ||
</Tile> | ||
); | ||
}; | ||
|
||
export default InPatientNote; |
53 changes: 53 additions & 0 deletions
53
.../esm-ward-app/src/ward-workspace/ward-patient-notes/history/notes-container.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,53 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { type PatientUuid } from '@openmrs/esm-framework'; | ||
import { usePatientNotes } from '../notes.resource'; | ||
import InPatientNote, { InPatientNoteSkeleton } from './note.component'; | ||
import styles from './styles.scss'; | ||
import { InlineNotification } from '@carbon/react'; | ||
import useEmrConfiguration from '../../../hooks/useEmrConfiguration'; | ||
|
||
interface PatientNotesHistoryProps { | ||
patientUuid: PatientUuid; | ||
} | ||
|
||
const PatientNotesHistory: React.FC<PatientNotesHistoryProps> = ({ patientUuid }) => { | ||
const { t } = useTranslation(); | ||
const { emrConfiguration, isLoadingEmrConfiguration, errorFetchingEmrConfiguration } = useEmrConfiguration(); | ||
|
||
const { patientNotes, isLoadingPatientNotes, errorFetchingPatientNotes } = usePatientNotes( | ||
patientUuid, | ||
emrConfiguration?.visitNoteEncounterType?.uuid, | ||
emrConfiguration?.consultFreeTextCommentsConcept.uuid, | ||
); | ||
|
||
const isLoading = isLoadingPatientNotes || isLoadingEmrConfiguration; | ||
|
||
if (!isLoading && patientNotes.length === 0 && !errorFetchingPatientNotes) return null; | ||
|
||
return ( | ||
<div className={styles.notesContainer}> | ||
<div className={styles.notesContainerHeader}> | ||
<div className={styles.notesContainerTitle}>History</div> | ||
</div> | ||
{isLoading ? [1, 2, 3, 4].map((item, index) => <InPatientNoteSkeleton key={index} />) : null} | ||
{patientNotes.map((patientNote) => ( | ||
<InPatientNote key={patientNote.id} note={patientNote} /> | ||
))} | ||
{errorFetchingPatientNotes && ( | ||
<InlineNotification | ||
kind="error" | ||
title={t('patientNotesDidntLoad', "Patient notes didn't load")} | ||
subtitle={t( | ||
'fetchingPatientNotesFailed', | ||
'Fetching patient notes failed. Try refreshing the page or contact your system administrator.', | ||
)} | ||
lowContrast | ||
hideCloseButton | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default PatientNotesHistory; |
84 changes: 84 additions & 0 deletions
84
packages/esm-ward-app/src/ward-workspace/ward-patient-notes/history/notes-container.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,84 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import PatientNotesHistory from './notes-container.component'; | ||
import { usePatientNotes } from '../notes.resource'; | ||
import useEmrConfiguration from '../../../hooks/useEmrConfiguration'; | ||
import { emrConfigurationMock } from '__mocks__'; | ||
|
||
const mockedUseEmrConfiguration = jest.mocked(useEmrConfiguration); | ||
|
||
jest.mock('../../../hooks/useEmrConfiguration', () => jest.fn()); | ||
|
||
jest.mock('../notes.resource', () => ({ | ||
usePatientNotes: jest.fn(), | ||
})); | ||
|
||
const mockPatientUuid = 'sample-patient-uuid'; | ||
|
||
const mockPatientNotes = [ | ||
{ | ||
id: 'note-1', | ||
diagnoses: '', | ||
encounterDate: '2024-08-01', | ||
encounterNote: 'Patient shows improvement with current medication.', | ||
encounterNoteRecordedAt: '2024-08-01T12:34:56Z', | ||
encounterProvider: 'Dr. John Doe', | ||
encounterProviderRole: 'Endocrinologist', | ||
}, | ||
{ | ||
id: 'note-2', | ||
diagnoses: '', | ||
encounterDate: '2024-08-02', | ||
encounterNote: 'Blood pressure is slightly elevated. Consider adjusting medication.', | ||
encounterNoteRecordedAt: '2024-08-02T14:22:00Z', | ||
encounterProvider: 'Dr. Jane Smith', | ||
encounterProviderRole: 'Cardiologist', | ||
}, | ||
]; | ||
|
||
describe('PatientNotesHistory', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
test('displays loading skeletons when loading', () => { | ||
mockedUseEmrConfiguration.mockReturnValue({ | ||
emrConfiguration: emrConfigurationMock, | ||
mutateEmrConfiguration: jest.fn(), | ||
isLoadingEmrConfiguration: false, | ||
errorFetchingEmrConfiguration: null, | ||
}); | ||
|
||
usePatientNotes.mockReturnValue({ | ||
patientNotes: [], | ||
isLoadingPatientNotes: true, | ||
}); | ||
|
||
render(<PatientNotesHistory patientUuid={mockPatientUuid} />); | ||
|
||
expect(screen.getAllByTestId('in-patient-note-skeleton')).toHaveLength(4); | ||
}); | ||
|
||
test('displays patient notes when available', () => { | ||
mockedUseEmrConfiguration.mockReturnValue({ | ||
emrConfiguration: emrConfigurationMock, | ||
mutateEmrConfiguration: jest.fn(), | ||
isLoadingEmrConfiguration: false, | ||
errorFetchingEmrConfiguration: null, | ||
}); | ||
|
||
usePatientNotes.mockReturnValue({ | ||
patientNotes: mockPatientNotes, | ||
isLoadingPatientNotes: false, | ||
}); | ||
|
||
render(<PatientNotesHistory patientUuid={mockPatientUuid} />); | ||
|
||
expect(screen.getByText('History')).toBeInTheDocument(); | ||
|
||
expect(screen.getByText('Patient shows improvement with current medication.')).toBeInTheDocument(); | ||
expect(screen.getByText('Dr. John Doe')).toBeInTheDocument(); | ||
expect(screen.getByText('Blood pressure is slightly elevated. Consider adjusting medication.')).toBeInTheDocument(); | ||
expect(screen.getByText('Dr. Jane Smith')).toBeInTheDocument(); | ||
}); | ||
}); |
62 changes: 62 additions & 0 deletions
62
packages/esm-ward-app/src/ward-workspace/ward-patient-notes/history/styles.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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
@use '@carbon/layout'; | ||
@use '@carbon/colors'; | ||
@import '@carbon/styles/scss/type'; | ||
@import '@openmrs/esm-styleguide/src/vars'; | ||
|
||
.notesContainer { | ||
margin: layout.$spacing-04; | ||
} | ||
|
||
.notesContainerHeader { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: space-between; | ||
margin-top: layout.$spacing-05; | ||
margin-bottom: layout.$spacing-02; | ||
} | ||
|
||
.notesContainerTitle { | ||
font-weight: 600; | ||
font-size: layout.$spacing-05; | ||
color: #393939; | ||
} | ||
|
||
.noteTile { | ||
padding: layout.$spacing-04; | ||
margin-bottom: layout.$spacing-04; | ||
} | ||
|
||
.noteHeader { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
margin-bottom: layout.$spacing-04; | ||
} | ||
|
||
.noteProviderRole { | ||
flex-grow: 0; | ||
font-size: 0.875rem; | ||
font-weight: 600; | ||
color: $text-02; | ||
} | ||
|
||
.noteBody { | ||
font-size: 0.875rem; | ||
color: $text-02; | ||
} | ||
|
||
.noteDateAndTime { | ||
font-size: layout.$spacing-04; | ||
color: $text-02; | ||
} | ||
|
||
.noteProviderName { | ||
font-size: layout.$spacing-04; | ||
margin-top: layout.$spacing-04; | ||
color: $text-02; | ||
} | ||
|
||
.noteSkeletonContainer { | ||
height: layout.$spacing-13; | ||
} |
66 changes: 66 additions & 0 deletions
66
packages/esm-ward-app/src/ward-workspace/ward-patient-notes/notes.resource.ts
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,66 @@ | ||
import { type FetchResponse, openmrsFetch, restBaseUrl } from '@openmrs/esm-framework'; | ||
import useSWR from 'swr'; | ||
import { type PatientNote, type UsePatientNotes, type VisitEncountersFetchResponse } from './types'; | ||
import { type EncounterPayload } from '../../types'; | ||
import { useMemo } from 'react'; | ||
|
||
export function savePatientNote(payload: EncounterPayload, abortController: AbortController = new AbortController()) { | ||
return openmrsFetch(`${restBaseUrl}/encounter`, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
method: 'POST', | ||
body: payload, | ||
signal: abortController.signal, | ||
}); | ||
} | ||
|
||
export function usePatientNotes(patientUuid: string, encounterType: string, conceptUuid: string): UsePatientNotes { | ||
const customRepresentation = | ||
'custom:(uuid,display,encounterDatetime,patient,obs,' + | ||
'encounterProviders:(uuid,display,' + | ||
'encounterRole:(uuid,display),' + | ||
'provider:(uuid,person:(uuid,display))),' + | ||
'diagnoses'; | ||
const encountersApiUrl = `${restBaseUrl}/encounter?patient=${patientUuid}&encounterType=${encounterType}&v=${customRepresentation}`; | ||
|
||
const { data, error, isLoading, isValidating, mutate } = useSWR<FetchResponse<VisitEncountersFetchResponse>, Error>( | ||
patientUuid && encounterType ? encountersApiUrl : null, | ||
openmrsFetch, | ||
); | ||
|
||
const patientNotes: Array<PatientNote> | null = useMemo( | ||
() => | ||
data | ||
? data.data.results | ||
.map((encounter) => { | ||
const noteObs = encounter.obs.find((obs) => obs.concept.uuid === conceptUuid); | ||
|
||
return { | ||
id: encounter.uuid, | ||
diagnoses: encounter.diagnoses.map((d) => d.display).join(', '), | ||
encounterDate: encounter.encounterDatetime, | ||
encounterNote: noteObs ? noteObs.value : '', | ||
encounterNoteRecordedAt: noteObs ? noteObs.obsDatetime : '', | ||
encounterProvider: encounter.encounterProviders.map((ep) => ep.provider.person.display).join(', '), | ||
encounterProviderRole: encounter.encounterProviders.map((ep) => ep.encounterRole.display).join(', '), | ||
}; | ||
}) | ||
.sort( | ||
(a, b) => new Date(b.encounterNoteRecordedAt).getTime() - new Date(a.encounterNoteRecordedAt).getTime(), | ||
) | ||
: [], | ||
[data, conceptUuid], | ||
); | ||
|
||
return useMemo( | ||
() => ({ | ||
patientNotes, | ||
errorFetchingPatientNotes: error, | ||
isLoadingPatientNotes: isLoading, | ||
isValidatingPatientNotes: isValidating, | ||
mutatePatientNotes: mutate, | ||
}), | ||
[patientNotes, isLoading, isValidating, mutate, error], | ||
); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great... I will add the "visit" limiting factor once the endpoint is ready with it.