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

Commit

Permalink
feat(medications): implement basic medication module (#2249)
Browse files Browse the repository at this point in the history
Co-authored-by: Matteo Vivona <matteo.vivona@me.com>
Co-authored-by: Maksim Sinik <maksim@sinik.it>
Co-authored-by: morrme <morrme@users.noreply.github.com>
  • Loading branch information
4 people committed Aug 14, 2020
1 parent 1ccd2f6 commit ab1bd5c
Show file tree
Hide file tree
Showing 27 changed files with 2,666 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/HospitalRun.tsx
Expand Up @@ -7,6 +7,7 @@ import Dashboard from './dashboard/Dashboard'
import Imagings from './imagings/Imagings'
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 @@ -52,6 +53,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} />
<Route path="/imaging" component={Imagings} />
Expand Down
50 changes: 50 additions & 0 deletions src/__tests__/HospitalRun.test.tsx
Expand Up @@ -12,12 +12,14 @@ import HospitalRun from '../HospitalRun'
import ViewImagings from '../imagings/ViewImagings'
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 ImagingRepository from '../shared/db/ImagingRepository'
import IncidentRepository from '../shared/db/IncidentRepository'
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 @@ -125,6 +127,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 () => {
jest.spyOn(IncidentRepository, 'search').mockResolvedValue([])
Expand Down
102 changes: 102 additions & 0 deletions src/__tests__/medications/Medications.test.tsx
@@ -0,0 +1,102 @@
import { act } from '@testing-library/react'
import { mount, ReactWrapper } 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', () => {
const setup = (route: string, permissions: Array<string>) => {
jest.resetAllMocks()
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)

const store = mockStore({
title: 'test',
user: { permissions },
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)

const wrapper = mount(
<Provider store={store}>
<MemoryRouter initialEntries={[route]}>
<Medications />
</MemoryRouter>
</Provider>,
)
return wrapper as ReactWrapper
}

describe('routing', () => {
describe('/medications/new', () => {
it('should render the new medication request screen when /medications/new is accessed', () => {
const route = '/medications/new'
const permissions = [Permissions.RequestMedication]
const wrapper = setup(route, permissions)
expect(wrapper.find(NewMedicationRequest)).toHaveLength(1)
})

it('should not navigate to /medications/new if the user does not have RequestMedication permissions', () => {
const route = '/medications/new'
const permissions: never[] = []
const wrapper = setup(route, permissions)
expect(wrapper.find(NewMedicationRequest)).toHaveLength(0)
})
})

describe('/medications/:id', () => {
it('should render the view medication screen when /medications/:id is accessed', async () => {
const route = '/medications/1234'
const permissions = [Permissions.ViewMedication]
let wrapper: any
await act(async () => {
wrapper = setup(route, permissions)

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

it('should not navigate to /medications/:id if the user does not have ViewMedication permissions', async () => {
const route = '/medications/1234'
const permissions: never[] = []
const wrapper = setup(route, permissions)

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

1 comment on commit ab1bd5c

@vercel
Copy link

@vercel vercel bot commented on ab1bd5c Aug 14, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.