Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

fix(2494): Incidents: Add the ability to edit incident details #2689

Open
wants to merge 121 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
f8fd11d
Merge pull request #1 from HospitalRun/master
riiniii Mar 7, 2021
58a6336
fix(2494): add reportedTo to incident model
riiniii Mar 7, 2021
a36a94e
fix(2494): add update functionality to View Incident Page, change use…
riiniii Mar 12, 2021
e98344e
fix(2494): fix button css and add localization for en only
Apr 11, 2021
c45f6b1
fix(2494): add patient full name to incident table and form
Apr 12, 2021
1e6cd88
fix(2494): add reportedTo to incidents pages
Apr 12, 2021
918d818
fix(2494): add fixes to tests
riiniii May 1, 2021
0d8e0e2
fix(2494): update tests for incidents
riiniii May 1, 2021
7f6c795
fix(2404): fix incident test
riiniii May 1, 2021
1627557
fix(2494): remove extra/old test
riiniii Jun 2, 2021
ae0a945
Merge branch 'master' into fix/2494-3
riiniii Jun 2, 2021
dad980e
Merge branch 'master' into fix/2494-3
matteovivona Jun 8, 2021
7f70ef6
Merge branch 'master' into fix/2494-3
matteovivona Jun 9, 2021
890ece4
Merge branch 'master' into fix/2494-3
matteovivona Jun 16, 2021
6dd1c51
fix(2494): pr comments
riiniii Jul 12, 2021
c7131f6
Merge branch 'fix/2494-3' of github.com:riiniii/hospitalrun-frontend …
riiniii Jul 12, 2021
e08171e
fix(2494): update tests
riiniii Jul 12, 2021
eb70071
fix(2494): pr fixes and add back in updated field
riiniii Jul 12, 2021
e25372a
Merge branch 'master' into fix/2494-3
matteovivona Jul 12, 2021
8199d1e
Merge branch 'master' into fix/2494-3
Oct 2, 2021
500cacb
Merge branch 'master' into fix/2494-3
Oct 2, 2021
0f879f8
Merge branch 'master' into fix/2494-3
Oct 2, 2021
8261a0c
Merge branch 'master' into fix/2494-3
Oct 2, 2021
65b184a
Merge branch 'master' into fix/2494-3
Oct 2, 2021
5324ff5
Merge branch 'master' into fix/2494-3
Oct 2, 2021
59e8a7d
Merge branch 'master' into fix/2494-3
Oct 2, 2021
23dfbdd
Merge branch 'master' into fix/2494-3
Oct 5, 2021
92e8019
Merge branch 'master' into fix/2494-3
Oct 6, 2021
83d5d7d
Merge branch 'master' into fix/2494-3
Oct 7, 2021
c122294
Merge branch 'master' into fix/2494-3
Oct 11, 2021
234a238
Merge branch 'master' into fix/2494-3
Oct 11, 2021
dbd0fc1
Merge branch 'master' into fix/2494-3
Oct 12, 2021
3cf10be
Merge branch 'master' into fix/2494-3
Oct 12, 2021
fac2b0e
Merge branch 'master' into fix/2494-3
Oct 12, 2021
ea9ca78
Merge branch 'master' into fix/2494-3
Oct 13, 2021
4b69c24
Merge branch 'master' into fix/2494-3
Oct 15, 2021
84f9460
Merge branch 'master' into fix/2494-3
Oct 15, 2021
31a19aa
Merge branch 'master' into fix/2494-3
Oct 18, 2021
ce0ae18
Merge branch 'master' into fix/2494-3
Oct 19, 2021
26819a6
Merge branch 'master' into fix/2494-3
Oct 21, 2021
28d7a82
Merge branch 'master' into fix/2494-3
Oct 21, 2021
e421c5b
Merge branch 'master' into fix/2494-3
Oct 21, 2021
fe42773
Merge branch 'master' into fix/2494-3
Oct 21, 2021
fc9d4ef
Merge branch 'master' into fix/2494-3
Oct 21, 2021
fb59527
Merge branch 'master' into fix/2494-3
Oct 21, 2021
12cdc66
Merge branch 'master' into fix/2494-3
Oct 21, 2021
3ac691b
Merge branch 'master' into fix/2494-3
Oct 21, 2021
5be93a0
Merge branch 'master' into fix/2494-3
Oct 21, 2021
24f463c
Merge branch 'master' into fix/2494-3
Oct 21, 2021
2ede89b
Merge branch 'master' into fix/2494-3
Oct 21, 2021
3d74c59
Merge branch 'master' into fix/2494-3
Oct 21, 2021
078af74
Merge branch 'master' into fix/2494-3
Oct 21, 2021
053ec54
Merge branch 'master' into fix/2494-3
Oct 22, 2021
12cc093
Merge branch 'master' into fix/2494-3
Oct 22, 2021
6792e44
Merge branch 'master' into fix/2494-3
Oct 22, 2021
f1f4a3f
Merge branch 'master' into fix/2494-3
Oct 22, 2021
c7eb5d0
Merge branch 'master' into fix/2494-3
Oct 22, 2021
90d2b53
Merge branch 'master' into fix/2494-3
Oct 22, 2021
b951996
Merge branch 'master' into fix/2494-3
Nov 2, 2021
0a6d62c
Merge branch 'master' into fix/2494-3
Nov 2, 2021
a7583ee
Merge branch 'master' into fix/2494-3
Nov 2, 2021
c25a7f7
Merge branch 'master' into fix/2494-3
Nov 2, 2021
05723cd
Merge branch 'master' into fix/2494-3
Nov 2, 2021
7e5c47d
Merge branch 'master' into fix/2494-3
Nov 2, 2021
c700678
Merge branch 'master' into fix/2494-3
Nov 2, 2021
ba50190
Merge branch 'master' into fix/2494-3
Nov 3, 2021
4b71f7a
Merge branch 'master' into fix/2494-3
Nov 3, 2021
f0a7026
Merge branch 'master' into fix/2494-3
Nov 10, 2021
f8bce6e
Merge branch 'master' into fix/2494-3
Nov 10, 2021
0f5fa56
Merge branch 'master' into fix/2494-3
Nov 12, 2021
7b7d80a
Merge branch 'master' into fix/2494-3
Nov 12, 2021
215b80a
Merge branch 'master' into fix/2494-3
Nov 15, 2021
d03f584
Merge branch 'master' into fix/2494-3
Nov 17, 2021
f9e2bd2
Merge branch 'master' into fix/2494-3
Nov 17, 2021
f6203b0
Merge branch 'master' into fix/2494-3
Nov 17, 2021
7e7e104
Merge branch 'master' into fix/2494-3
Nov 17, 2021
2a1e49e
Merge branch 'master' into fix/2494-3
Nov 17, 2021
fc5daf4
Merge branch 'master' into fix/2494-3
Nov 17, 2021
e29c714
Merge branch 'master' into fix/2494-3
Nov 17, 2021
212ae0b
Merge branch 'master' into fix/2494-3
Nov 18, 2021
ebc3697
Merge branch 'master' into fix/2494-3
Nov 19, 2021
b08f231
Merge branch 'master' into fix/2494-3
Nov 19, 2021
ca5cb3e
Merge branch 'master' into fix/2494-3
Nov 19, 2021
f16cef3
Merge branch 'master' into fix/2494-3
Nov 19, 2021
71cf5da
Merge branch 'master' into fix/2494-3
Nov 19, 2021
88e2ef4
Merge branch 'master' into fix/2494-3
Nov 21, 2021
dd090e7
Merge branch 'master' into fix/2494-3
Nov 23, 2021
1d82484
Merge branch 'master' into fix/2494-3
Nov 23, 2021
15a202d
Merge branch 'master' into fix/2494-3
Nov 23, 2021
2a8701e
Merge branch 'master' into fix/2494-3
Nov 25, 2021
36c2e90
Merge branch 'master' into fix/2494-3
Nov 25, 2021
6fd67ca
Merge branch 'master' into fix/2494-3
Nov 29, 2021
cfc26f5
Merge branch 'master' into fix/2494-3
Dec 4, 2021
8d97593
Merge branch 'master' into fix/2494-3
Dec 13, 2021
6076eaf
Merge branch 'master' into fix/2494-3
Dec 13, 2021
ec3c876
Merge branch 'master' into fix/2494-3
Dec 17, 2021
6063cd4
Merge branch 'master' into fix/2494-3
Dec 17, 2021
0c19ff0
Merge branch 'master' into fix/2494-3
Dec 17, 2021
663b497
Merge branch 'master' into fix/2494-3
Dec 17, 2021
5ecedad
Merge branch 'master' into fix/2494-3
Dec 17, 2021
f0230d3
Merge branch 'master' into fix/2494-3
Dec 17, 2021
b2f7740
Merge branch 'master' into fix/2494-3
Dec 23, 2021
82e900d
Merge branch 'master' into fix/2494-3
Dec 27, 2021
3403eac
Merge branch 'master' into fix/2494-3
Dec 27, 2021
ce46437
Merge branch 'master' into fix/2494-3
Dec 27, 2021
2c0d42e
Merge branch 'master' into fix/2494-3
Dec 28, 2021
7833923
Merge branch 'master' into fix/2494-3
Dec 28, 2021
9359be4
Merge branch 'master' into fix/2494-3
Dec 28, 2021
01eecff
Merge branch 'master' into fix/2494-3
Dec 28, 2021
a230f8e
Merge branch 'master' into fix/2494-3
Dec 28, 2021
e08cc01
Merge branch 'master' into fix/2494-3
Jan 2, 2022
3beffb4
Merge branch 'master' into fix/2494-3
Jan 2, 2022
1609d7c
Merge branch 'master' into fix/2494-3
Jan 2, 2022
2403e76
Merge branch 'master' into fix/2494-3
Jan 4, 2022
4166855
Merge branch 'master' into fix/2494-3
Jan 4, 2022
05b1497
Merge branch 'master' into fix/2494-3
Feb 12, 2022
2edb680
Merge branch 'master' into fix/2494-3
Feb 12, 2022
4c22440
Merge branch 'master' into fix/2494-3
Feb 12, 2022
2728db1
Merge branch 'master' into fix/2494-3
Feb 12, 2022
c2e185e
Merge branch 'master' into fix/2494-3
Feb 12, 2022
06b3c7f
Merge branch 'master' into fix/2494-3
Feb 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import subDays from 'date-fns/subDays'

import useResolveIncident from '../../../incidents/hooks/useResolveIncident'
import useUpdateIncident from '../../../incidents/hooks/useUpdateIncident'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you made editing and resolving under the same mutation abstraction.

import IncidentRepository from '../../../shared/db/IncidentRepository'
import Incident from '../../../shared/model/Incident'
import executeMutation from '../../test-utils/use-mutation.util'

describe('useResolvedIncident', () => {
it('should mark incident as resolved and save', async () => {
const expectedStatus = 'resolved'
const expectedResolvedDate = new Date(Date.now())
Date.now = jest.fn().mockReturnValue(expectedResolvedDate)

Expand All @@ -17,7 +16,7 @@ describe('useResolvedIncident', () => {
date: subDays(new Date(), 3).toISOString(),
department: 'some department',
description: 'some description',
status: 'reported',
status: 'resolved',
code: 'I-some-code',
reportedOn: subDays(new Date(), 2).toISOString(),
reportedBy: 'some user',
Expand All @@ -26,11 +25,10 @@ describe('useResolvedIncident', () => {
const expectedIncident = {
...givenIncident,
resolvedOn: expectedResolvedDate.toISOString(),
status: expectedStatus,
} as Incident
jest.spyOn(IncidentRepository, 'save').mockResolvedValue(expectedIncident)

const actualData = await executeMutation(() => useResolveIncident(), givenIncident)
const actualData = await executeMutation(() => useUpdateIncident(), givenIncident)

expect(IncidentRepository.save).toHaveBeenCalledTimes(1)
expect(IncidentRepository.save).toBeCalledWith(expectedIncident)
Expand Down
6 changes: 4 additions & 2 deletions src/__tests__/incidents/list/ViewIncidentsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ describe('View Incidents Table', () => {
it('should display a table of incidents', async () => {
setup({ status: IncidentFilter.all })
expect(await screen.findByRole('table')).toBeInTheDocument()

const headers = screen.getAllByRole('columnheader')
const cells = screen.getAllByRole('cell')

expect(headers[0]).toHaveTextContent(/incidents.reports.code/i)
expect(headers[1]).toHaveTextContent(/incidents.reports.dateOfIncident/i)
expect(headers[2]).toHaveTextContent(/incidents.reports.reportedBy/i)
expect(headers[3]).toHaveTextContent(/incidents.reports.reportedOn/i)
expect(headers[4]).toHaveTextContent(/incidents.reports.status/i)
expect(headers[5]).toHaveTextContent(/actions.label/i)
expect(headers[5]).toHaveTextContent(/incidents.reports.patient/i)
expect(headers[6]).toHaveTextContent(/actions.label/i)
expect(cells[0]).toHaveTextContent(expectedIncident.code)
expect(cells[1]).toHaveTextContent(
format(new Date(expectedIncident.date), 'yyyy-MM-dd hh:mm a'),
Expand All @@ -64,6 +65,7 @@ describe('View Incidents Table', () => {
format(new Date(expectedIncident.reportedOn), 'yyyy-MM-dd hh:mm a'),
)
expect(cells[4]).toHaveTextContent(expectedIncident.status)

expect(screen.getByRole('button', { name: /actions.view/i })).toBeInTheDocument()
})

Expand Down
13 changes: 7 additions & 6 deletions src/__tests__/incidents/view/ViewIncidentDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ describe('View Incident Details', () => {
).toBeInTheDocument()
})
})
describe('form elements should not be editable', () => {
describe('form elements should be editable', () => {
it('should render the department input with label and display value', async () => {
setup(expectedIncident, [Permissions.ViewIncident])
expect(await screen.findByText(/incidents\.reports\.department/i)).toBeInTheDocument()

expect(
await screen.findByRole('textbox', { name: /incidents\.reports\.department/i }),
).not.toBeEnabled()
).toBeEnabled()

expect(
await screen.findByRole('textbox', { name: /incidents\.reports\.department/i }),
Expand All @@ -125,7 +125,7 @@ describe('View Incident Details', () => {

expect(
await screen.findByRole('textbox', { name: /incidents\.reports\.category$/i }),
).not.toBeEnabled()
).toBeEnabled()

expect(
await screen.findByRole('textbox', { name: /incidents\.reports\.category$/i }),
Expand All @@ -137,7 +137,7 @@ describe('View Incident Details', () => {

expect(
await screen.findByRole('textbox', { name: /incidents\.reports\.categoryItem$/i }),
).not.toBeEnabled()
).toBeEnabled()

expect(
await screen.findByRole('textbox', { name: /incidents\.reports\.categoryItem$/i }),
Expand All @@ -155,13 +155,14 @@ describe('View Incident Details', () => {
screen.getByRole('textbox', {
name: /incidents\.reports\.description/i,
}),
).not.toBeEnabled()
).toBeEnabled()

expect(
await screen.findByRole('textbox', { name: /incidents\.reports\.description/i }),
).toHaveDisplayValue('some description')
})
})

describe('on resolve', () => {
it('should mark the status as resolved and fill in the resolved date with the current time', async () => {
const { history } = setup(expectedIncident, [
Expand All @@ -170,7 +171,7 @@ describe('View Incident Details', () => {
])

const resolveButton = await screen.findByRole('button', {
name: /incidents\.reports\.resolve/i,
name: /incidents\.reports\.update/i,
})

userEvent.click(resolveButton)
Expand Down
20 changes: 0 additions & 20 deletions src/incidents/hooks/useResolveIncident.tsx

This file was deleted.

33 changes: 33 additions & 0 deletions src/incidents/hooks/useUpdateIncident.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { queryCache, useMutation } from 'react-query'

import IncidentRepository from '../../shared/db/IncidentRepository'
import Incident from '../../shared/model/Incident'

interface ResolvedOnDate {
resolvedOn?: string
}

/**
* Returns incident object with resolvedOn string if incident.status was resolved on, otherwise returns empty object
* @param {Incident} incident
* @returns {ResolvedOnDate}
*/
function getResolvedOn(incident: Incident): ResolvedOnDate {
return incident.status === 'resolved' ? { resolvedOn: new Date(Date.now()).toISOString() } : {}
}

function resolveIncident(incident: Incident): Promise<Incident> {
const resolvedOn = getResolvedOn(incident)
return IncidentRepository.saveOrUpdate({
...incident,
...resolvedOn,
})
}

export default function useUpdateIncident() {
return useMutation(resolveIncident, {
onSuccess: async (data: Incident) => {
queryCache.setQueryData(['incident', data.id], data)
},
})
}
6 changes: 5 additions & 1 deletion src/incidents/list/ViewIncidentsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function ViewIncidentsTable(props: Props) {
const { t } = useTranslator()
const history = useHistory()
const { data, isLoading } = useIncidents(searchRequest)

if (data === undefined || isLoading) {
return <Spinner type="DotLoader" loading />
}
Expand Down Expand Up @@ -113,6 +112,11 @@ function ViewIncidentsTable(props: Props) {
label: t('incidents.reports.status'),
key: 'status',
},
{
label: t('incidents.reports.patient'),
key: 'patient',
formatter: (row) => row.patientFullName,
},
]}
actionsHeaderText={t('actions.label')}
actions={[
Expand Down
28 changes: 17 additions & 11 deletions src/incidents/report/ReportIncident.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const ReportIncident = () => {
categoryItem: '',
description: '',
patient: '',
reportedTo: '',
})

const [error, setError] = useState<IncidentError | undefined>(undefined)
Expand Down Expand Up @@ -68,17 +69,13 @@ const ReportIncident = () => {
}

const onPatientChange = (patient: Patient) => {
if (patient) {
setIncident((prevIncident) => ({
...prevIncident,
patient: patient.id,
}))
} else {
setIncident((prevIncident) => ({
...prevIncident,
patient: '',
}))
}
const { id = '', fullName = '' } = patient || {}

setIncident((prevIncident) => ({
...prevIncident,
patient: id,
patientFullName: fullName,
}))
}

return (
Expand Down Expand Up @@ -150,6 +147,15 @@ const ReportIncident = () => {
</Column>
</Row>
<Row>
<Column md={6}>
<TextInputWithLabelFormGroup
label={t('incidents.reports.reportedTo')}
name="reportedTo"
value={incident.reportedTo}
isEditable
onChange={(event) => onTextInputChange(event.currentTarget.value, 'reportedTo')}
/>
</Column>
<Column md={6}>
<div className="form-group patient-typeahead">
<Label htmlFor="patientTypeahead" text={t('incidents.reports.patient')} />
Expand Down
Loading