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

feat(medications): implement basic medication module #2249

Merged
merged 43 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e97c3ca
fix: add Relates Person search crash if matched person has no DoB
blestab Jul 8, 2020
5a34b8f
feat(incidents): add ability to resolve an incident
blestab Jul 10, 2020
daada44
Merge branch 'master' into master
matteovivona Jul 10, 2020
77c2be5
Merge branch 'master' into master
fox1t Jul 10, 2020
0b4d018
Merge branch 'master' into master
fox1t Jul 10, 2020
d2b935e
Merge branch 'master' of https://github.com/blestab/hospitalrun-frontend
blestab Jul 10, 2020
d43fa37
Merge branch 'master' of https://github.com/blestab/hospitalrun-frontend
blestab Jul 10, 2020
bfecf24
Merge branch 'master' of https://github.com/blestab/hospitalrun-frontend
blestab Jul 10, 2020
6f6bfe0
Merge branch 'master' into master
fox1t Jul 10, 2020
52dc151
Merge branch 'master' into master
matteovivona Jul 11, 2020
6bea698
Merge branch 'master' into master
matteovivona Jul 11, 2020
14ad01a
Merge branch 'master' of https://github.com/blestab/hospitalrun-frontend
blestab Jul 11, 2020
bfe9ccc
Merge branch 'master' into master
matteovivona Jul 11, 2020
2b01be8
Merge branch 'master' of https://github.com/blestab/hospitalrun-frontend
blestab Jul 11, 2020
20c0a71
Merge branch 'master' of https://github.com/blestab/hospitalrun-frontend
blestab Jul 11, 2020
eb9f2b3
Merge branch 'master' of https://github.com/blestab/hospitalrun-frontend
blestab Jul 11, 2020
309a716
Merge branch 'master' of https://github.com/blestab/hospitalrun-frontend
blestab Jul 11, 2020
a7e415c
feat(medications): implement basic medication module
blestab Jul 23, 2020
92e9233
Merge branch 'master' into master
matteovivona Jul 24, 2020
6944fb3
feat(medications): implement basic medication module
blestab Jul 23, 2020
ac914fe
Merge branch 'master' of https://github.com/blestab/hospitalrun-frontend
blestab Jul 25, 2020
7074b90
Merge branch 'master' of https://github.com/blestab/hospitalrun-frontend
blestab Jul 25, 2020
65ef8cb
Merge branch 'master' of https://github.com/blestab/hospitalrun-frontend
blestab Jul 26, 2020
d950e50
feat(medications): implement basic medication module
blestab Jul 26, 2020
40b08d8
Merge branch 'master' into master
matteovivona Jul 27, 2020
cae8481
feat(navbar): add "Request Medication" to quick create button in navbar
blestab Jul 28, 2020
0de73fc
Merge branch 'master' of https://github.com/blestab/hospitalrun-frontend
blestab Jul 28, 2020
abebbc7
Merge branch 'master' into master
matteovivona Jul 30, 2020
ea93a61
Merge branch 'master' into master
matteovivona Jul 31, 2020
cef43eb
Merge branch 'master' into master
matteovivona Aug 2, 2020
ee02c91
feat(medications): PR Feedback (tests, remove 'complete' feature)
blestab Aug 2, 2020
4a06814
Merge branch 'master' of https://github.com/blestab/hospitalrun-frontend
blestab Aug 2, 2020
6e909c4
feat(medications): PR feedback - refactor tests, setup function
blestab Aug 3, 2020
b67f68f
feat(medications): pr feedback refactor tests add setup function
blestab Aug 3, 2020
45678a0
Merge branch 'master' of https://github.com/blestab/hospitalrun-frontend
blestab Aug 3, 2020
5cf1307
Merge branch 'master' into fix_merge_conflicts_imagings_meds
blestab Aug 13, 2020
e52802d
fix: merge conflict imaging and medications
blestab Aug 13, 2020
871f1e7
fix(medications): pr merge conflicts
blestab Aug 13, 2020
c19fbac
fix merge issues
blestab Aug 13, 2020
07a9ff3
fix merge issues
blestab Aug 13, 2020
a755035
fix merge issues
blestab Aug 13, 2020
5e72dce
fix merge issues sidebar
blestab Aug 13, 2020
e2a83a2
bug: fix sidebar test
morrme Aug 13, 2020
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
2 changes: 2 additions & 0 deletions src/HospitalRun.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Redirect, Route, Switch } from 'react-router-dom'
import Dashboard from './dashboard/Dashboard'
import Incidents from './incidents/Incidents'
import Labs from './labs/Labs'
import Medications from './medications/Medications'
import Breadcrumbs from './page-header/breadcrumbs/Breadcrumbs'
import { ButtonBarProvider } from './page-header/button-toolbar/ButtonBarProvider'
import ButtonToolBar from './page-header/button-toolbar/ButtonToolBar'
Expand Down Expand Up @@ -51,6 +52,7 @@ const HospitalRun = () => {
<Route path="/appointments" component={Appointments} />
<Route path="/patients" component={Patients} />
<Route path="/labs" component={Labs} />
<Route path="/medications" component={Medications} />
<Route path="/incidents" component={Incidents} />
<Route path="/settings" component={Settings} />
</Switch>
Expand Down
50 changes: 50 additions & 0 deletions src/__tests__/HospitalRun.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import Dashboard from '../dashboard/Dashboard'
import HospitalRun from '../HospitalRun'
import Incidents from '../incidents/Incidents'
import ViewLabs from '../labs/ViewLabs'
import ViewMedications from '../medications/ViewMedications'
import { addBreadcrumbs } from '../page-header/breadcrumbs/breadcrumbs-slice'
import Appointments from '../scheduling/appointments/Appointments'
import Settings from '../settings/Settings'
import LabRepository from '../shared/db/LabRepository'
import MedicationRepository from '../shared/db/MedicationRepository'
import Permissions from '../shared/model/Permissions'
import { RootState } from '../shared/store'

Expand Down Expand Up @@ -123,6 +125,54 @@ describe('HospitalRun', () => {
})
})

describe('/medications', () => {
it('should render the Medications component when /medications is accessed', async () => {
jest.spyOn(MedicationRepository, 'findAll').mockResolvedValue([])
const store = mockStore({
title: 'test',
user: { user: { id: '123' }, permissions: [Permissions.ViewMedications] },
medications: { medications: [] },
breadcrumbs: { breadcrumbs: [] },
components: { sidebarCollapsed: false },
} as any)

let wrapper: any
await act(async () => {
wrapper = await mount(
<Provider store={store}>
<MemoryRouter initialEntries={['/medications']}>
<HospitalRun />
</MemoryRouter>
</Provider>,
)
})
wrapper.update()

expect(wrapper.find(ViewMedications)).toHaveLength(1)
})

it('should render the dashboard if the user does not have permissions to view medications', () => {
jest.spyOn(MedicationRepository, 'findAll').mockResolvedValue([])
const store = mockStore({
title: 'test',
user: { user: { id: '123' }, permissions: [] },
breadcrumbs: { breadcrumbs: [] },
components: { sidebarCollapsed: false },
} as any)

const wrapper = mount(
<Provider store={store}>
<MemoryRouter initialEntries={['/medications']}>
<HospitalRun />
</MemoryRouter>
</Provider>,
)

expect(wrapper.find(ViewMedications)).toHaveLength(0)
expect(wrapper.find(Dashboard)).toHaveLength(1)
})
})

describe('/incidents', () => {
it('should render the Incidents component when /incidents is accessed', async () => {
const store = mockStore({
Expand Down
135 changes: 135 additions & 0 deletions src/__tests__/medications/Medications.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { act } from '@testing-library/react'
import { mount } from 'enzyme'
import React from 'react'
import { Provider } from 'react-redux'
import { MemoryRouter } from 'react-router-dom'
import createMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'

import Medications from '../../medications/Medications'
import NewMedicationRequest from '../../medications/requests/NewMedicationRequest'
import ViewMedication from '../../medications/ViewMedication'
import MedicationRepository from '../../shared/db/MedicationRepository'
import PatientRepository from '../../shared/db/PatientRepository'
import Medication from '../../shared/model/Medication'
import Patient from '../../shared/model/Patient'
import Permissions from '../../shared/model/Permissions'
import { RootState } from '../../shared/store'

const mockStore = createMockStore<RootState, any>([thunk])

describe('Medications', () => {
jest.spyOn(MedicationRepository, 'findAll').mockResolvedValue([])
jest
.spyOn(MedicationRepository, 'find')
.mockResolvedValue({ id: '1234', requestedOn: new Date().toISOString() } as Medication)
jest
.spyOn(PatientRepository, 'find')
.mockResolvedValue({ id: '12345', fullName: 'test test' } as Patient)

describe('routing', () => {
describe('/medications/new', () => {
it('should render the new medication request screen when /medications/new is accessed', () => {
const store = mockStore({
title: 'test',
user: { permissions: [Permissions.RequestMedication] },
breadcrumbs: { breadcrumbs: [] },
components: { sidebarCollapsed: false },
medication: {
medication: ({ id: 'medicationId', patientId: 'patientId' } as unknown) as Medication,
patient: { id: 'patientId', fullName: 'some name' },
error: {},
},
} as any)

const wrapper = mount(
<Provider store={store}>
<MemoryRouter initialEntries={['/medications/new']}>
<Medications />
</MemoryRouter>
</Provider>,
)
blestab marked this conversation as resolved.
Show resolved Hide resolved

expect(wrapper.find(NewMedicationRequest)).toHaveLength(1)
})

it('should not navigate to /medications/new if the user does not have RequestMedication permissions', () => {
const store = mockStore({
title: 'test',
user: { permissions: [] },
breadcrumbs: { breadcrumbs: [] },
components: { sidebarCollapsed: false },
} as any)

const wrapper = mount(
<Provider store={store}>
<MemoryRouter initialEntries={['/medications/new']}>
<Medications />
</MemoryRouter>
</Provider>,
)

expect(wrapper.find(NewMedicationRequest)).toHaveLength(0)
})
})

describe('/medications/:id', () => {
it('should render the view medication screen when /medications/:id is accessed', async () => {
const store = mockStore({
title: 'test',
user: { permissions: [Permissions.ViewMedication] },
breadcrumbs: { breadcrumbs: [] },
components: { sidebarCollapsed: false },
medication: {
medication: ({
id: 'medicationId',
patientId: 'patientId',
requestedOn: new Date().toISOString(),
medication: 'medication',
status: 'draft',
intent: 'order',
priority: 'routine',
quantity: { value: 1, unit: 'unit' },
notes: 'medication notes',
} as unknown) as Medication,
patient: { id: 'patientId', fullName: 'some name' },
error: {},
},
} as any)

let wrapper: any

await act(async () => {
wrapper = await mount(
<Provider store={store}>
<MemoryRouter initialEntries={['/medications/1234']}>
<Medications />
</MemoryRouter>
</Provider>,
)

expect(wrapper.find(ViewMedication)).toHaveLength(1)
})
})

it('should not navigate to /medications/:id if the user does not have ViewMedication permissions', async () => {
const store = mockStore({
title: 'test',
user: { permissions: [] },
breadcrumbs: { breadcrumbs: [] },
components: { sidebarCollapsed: false },
} as any)

const wrapper = await mount(
<Provider store={store}>
<MemoryRouter initialEntries={['/medications/1234']}>
<Medications />
</MemoryRouter>
</Provider>,
)

expect(wrapper.find(ViewMedication)).toHaveLength(0)
})
})
})
})
Loading