-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(allergies): ability to click on allergy and view an allergy #2224
Changes from 1 commit
67fc24d
27c8474
81277d8
4578b32
1627078
4061c58
8c1c100
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { mount } from 'enzyme' | ||
import { createMemoryHistory } from 'history' | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { Route, Router } from 'react-router-dom' | ||
import createMockStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
|
||
import ViewAllergy from '../../../patients/allergies/viewAllergy' | ||
import TextInputWithLabelFormGroup from '../../../shared/components/input/TextInputWithLabelFormGroup' | ||
import Patient from '../../../shared/model/Patient' | ||
import { RootState } from '../../../shared/store' | ||
|
||
const mockStore = createMockStore<RootState, any>([thunk]) | ||
|
||
describe('View Care Plan', () => { | ||
const patient = { | ||
id: 'patientId', | ||
allergies: [{ id: '123', name: 'some name' }], | ||
} as Patient | ||
|
||
const setup = () => { | ||
const store = mockStore({ patient: { patient }, user: { user: { id: '123' } } } as any) | ||
const history = createMemoryHistory() | ||
history.push(`/patients/${patient.id}/allergies/${patient.allergies![0].id}`) | ||
const wrapper = mount( | ||
<Provider store={store}> | ||
<Router history={history}> | ||
<Route path="/patients/:id/allergies/:allergyId"> | ||
<ViewAllergy /> | ||
</Route> | ||
</Router> | ||
</Provider>, | ||
) | ||
|
||
return { wrapper } | ||
} | ||
|
||
it('should render a allergy input with the correct data', () => { | ||
const { wrapper } = setup() | ||
|
||
const allergyName = wrapper.find(TextInputWithLabelFormGroup) | ||
expect(allergyName).toHaveLength(1) | ||
expect(allergyName.prop('value')).toEqual(patient.allergies![0].name) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { Button, List, ListItem, Alert } from '@hospitalrun/components' | ||
import React, { useState } from 'react' | ||
import { useSelector } from 'react-redux' | ||
import { Route, Switch, useHistory } from 'react-router-dom' | ||
|
||
import useAddBreadcrumbs from '../../page-header/breadcrumbs/useAddBreadcrumbs' | ||
import useTranslator from '../../shared/hooks/useTranslator' | ||
|
@@ -9,6 +10,7 @@ import Patient from '../../shared/model/Patient' | |
import Permissions from '../../shared/model/Permissions' | ||
import { RootState } from '../../shared/store' | ||
import NewAllergyModal from './NewAllergyModal' | ||
import ViewAllergy from './viewAllergy' | ||
|
||
interface AllergiesProps { | ||
patient: Patient | ||
|
@@ -19,6 +21,7 @@ const Allergies = (props: AllergiesProps) => { | |
const { patient } = props | ||
const { permissions } = useSelector((state: RootState) => state.user) | ||
const [showNewAllergyModal, setShowNewAllergyModal] = useState(false) | ||
const history = useHistory() | ||
|
||
const breadcrumbs = [ | ||
{ | ||
|
@@ -46,18 +49,30 @@ const Allergies = (props: AllergiesProps) => { | |
</div> | ||
</div> | ||
<br /> | ||
<Switch> | ||
<Route exact path="/patients/:id/allergies"> | ||
<List> | ||
{patient.allergies?.map((a: Allergy) => ( | ||
<ListItem | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should indicate that the list item is clickable. We can do this by adding |
||
key={a.id} | ||
onClick={() => history.push(`/patients/${patient.id}/allergies/${a.id}`)} | ||
> | ||
{a.name} | ||
</ListItem> | ||
))} | ||
</List> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should extract this to its own component |
||
</Route> | ||
<Route exact path="/patients/:id/allergies/:allergyId"> | ||
<ViewAllergy /> | ||
</Route> | ||
</Switch> | ||
{(!patient.allergies || patient.allergies.length === 0) && ( | ||
<Alert | ||
color="warning" | ||
title={t('patient.allergies.warning.noAllergies')} | ||
message={t('patient.allergies.addAllergyAbove')} | ||
/> | ||
)} | ||
<List> | ||
{patient.allergies?.map((a: Allergy) => ( | ||
<ListItem key={a.id}>{a.name}</ListItem> | ||
))} | ||
</List> | ||
<NewAllergyModal | ||
show={showNewAllergyModal} | ||
onCloseButtonClick={() => setShowNewAllergyModal(false)} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import findLast from 'lodash/findLast' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. convention for file naming is So for this file, |
||
import React, { useEffect, useState } from 'react' | ||
import { useSelector } from 'react-redux' | ||
import { useParams } from 'react-router-dom' | ||
|
||
import TextInputWithLabelFormGroup from '../../shared/components/input/TextInputWithLabelFormGroup' | ||
import useTranslator from '../../shared/hooks/useTranslator' | ||
import Allergy from '../../shared/model/Allergy' | ||
import { RootState } from '../../shared/store' | ||
|
||
const ViewAllergy = () => { | ||
const { t } = useTranslator() | ||
const { patient } = useSelector((root: RootState) => root.patient) | ||
const { allergyId } = useParams() | ||
|
||
const [allergy, setAllergy] = useState<Allergy | undefined>() | ||
|
||
useEffect(() => { | ||
if (patient && allergyId) { | ||
const currentAllergy = findLast(patient.allergies, (a: Allergy) => a.id === allergyId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than using |
||
setAllergy(currentAllergy) | ||
} | ||
}, [setAllergy, allergyId, patient]) | ||
|
||
if (allergy) { | ||
return ( | ||
<> | ||
<TextInputWithLabelFormGroup | ||
name="name" | ||
label={t('patient.allergies.allergyName')} | ||
isEditable={false} | ||
placeholder={t('patient.allergies.allergyName')} | ||
value={allergy.name} | ||
/> | ||
</> | ||
) | ||
} | ||
return <></> | ||
} | ||
|
||
export default ViewAllergy |
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.
there should be a test that ensures the functionality of clicking on a list element navigates to the allergy.