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

Commit

Permalink
fix(patients): current patient can no longer be related person (#1959)
Browse files Browse the repository at this point in the history
  • Loading branch information
alti21 committed Apr 11, 2020
1 parent 71a6c7c commit b816ebf
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 18 deletions.
Expand Up @@ -3,20 +3,51 @@ import React from 'react'
import { ReactWrapper, mount } from 'enzyme'
import { Modal, Alert, Typeahead } from '@hospitalrun/components'
import { act } from '@testing-library/react'
import AddRelatedPersonModal from '../../../patients/related-persons/AddRelatedPersonModal'
import { Provider } from 'react-redux'
import thunk from 'redux-thunk'
import configureMockStore, { MockStore } from 'redux-mock-store'
import Patient from 'model/Patient'
import TextInputWithLabelFormGroup from '../../../components/input/TextInputWithLabelFormGroup'
import AddRelatedPersonModal from '../../../patients/related-persons/AddRelatedPersonModal'

const mockStore = configureMockStore([thunk])

describe('Add Related Person Modal', () => {
const patient = {
id: '123',
prefix: 'prefix',
givenName: 'givenName',
familyName: 'familyName',
suffix: 'suffix',
sex: 'male',
type: 'charity',
occupation: 'occupation',
preferredLanguage: 'preferredLanguage',
phoneNumber: 'phoneNumber',
email: 'email@email.com',
address: 'address',
code: 'P00001',
dateOfBirth: new Date().toISOString(),
} as Patient

let store: MockStore

describe('layout', () => {
let wrapper: ReactWrapper

store = mockStore({
patient: { patient },
})
beforeEach(() => {
wrapper = mount(
<AddRelatedPersonModal
show
onSave={jest.fn()}
onCloseButtonClick={jest.fn()}
toggle={jest.fn()}
/>,
<Provider store={store}>
<AddRelatedPersonModal
show
onSave={jest.fn()}
onCloseButtonClick={jest.fn()}
toggle={jest.fn()}
/>
</Provider>,
)
})

Expand Down Expand Up @@ -65,12 +96,14 @@ describe('Add Related Person Modal', () => {
beforeEach(() => {
onSaveSpy = jest.fn()
wrapper = mount(
<AddRelatedPersonModal
show
onSave={onSaveSpy}
onCloseButtonClick={jest.fn()}
toggle={jest.fn()}
/>,
<Provider store={store}>
<AddRelatedPersonModal
show
onSave={onSaveSpy}
onCloseButtonClick={jest.fn()}
toggle={jest.fn()}
/>
</Provider>,
)
})

Expand Down
19 changes: 14 additions & 5 deletions src/patients/related-persons/AddRelatedPersonModal.tsx
Expand Up @@ -5,6 +5,8 @@ import TextInputWithLabelFormGroup from 'components/input/TextInputWithLabelForm
import RelatedPerson from 'model/RelatedPerson'
import PatientRepository from 'clients/db/PatientRepository'
import Patient from 'model/Patient'
import { useSelector } from 'react-redux'
import { RootState } from '../../store'

interface Props {
show: boolean
Expand All @@ -21,6 +23,9 @@ const AddRelatedPersonModal = (props: Props) => {
patientId: '',
type: '',
})
const { patient } = useSelector((state: RootState) => state.patient)

const patientId = () => patient.id

const onFieldChange = (key: string, value: string) => {
setRelatedPerson({
Expand All @@ -33,8 +38,8 @@ const AddRelatedPersonModal = (props: Props) => {
onFieldChange(fieldName, event.target.value)
}

const onPatientSelect = (patient: Patient[]) => {
setRelatedPerson({ ...relatedPerson, patientId: patient[0].id })
const onPatientSelect = (p: Patient[]) => {
setRelatedPerson({ ...relatedPerson, patientId: p[0].id })
}

const body = (
Expand All @@ -50,9 +55,13 @@ const AddRelatedPersonModal = (props: Props) => {
placeholder={t('patient.relatedPerson')}
onChange={onPatientSelect}
onSearch={async (query: string) => PatientRepository.search(query)}
renderMenuItemChildren={(patient: Patient) => (
<div>{`${patient.fullName} (${patient.code})`}</div>
)}
renderMenuItemChildren={(p: Patient) => {
if (patientId() === p.id) {
return <div />
}

return <div>{`${p.fullName} (${p.code})`}</div>
}}
/>
</div>
</div>
Expand Down

1 comment on commit b816ebf

@vercel
Copy link

@vercel vercel bot commented on b816ebf Apr 11, 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.