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

fix(patients): current patient can no longer be related person #1959

Merged
merged 23 commits into from
Apr 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
08df8c5
fix(#1946): patients can also be related person
alti21 Apr 2, 2020
82f3c98
Merge branch 'master' into master
Apr 3, 2020
cdd1be8
Merge branch 'master' into master
Apr 3, 2020
c6d2b83
Merge branch 'master' into master
Apr 3, 2020
60e18fc
Merge branch 'master' into master
Apr 3, 2020
51771de
Merge branch 'master' into master
Apr 3, 2020
476de1a
Merge branch 'master' into master
Apr 3, 2020
534c9de
fix(patients): current patient can't be related person
alti21 Apr 4, 2020
2985c00
Merge branch 'master' of https://github.com/alti21/hospitalrun-frontend
alti21 Apr 4, 2020
32a568e
Merge branch 'master' into master
Apr 6, 2020
b4c31dc
Merge branch 'master' into master
Apr 6, 2020
666a9b8
Merge branch 'master' into master
Apr 7, 2020
46f72e9
Merge branch 'master' into master
Apr 8, 2020
3c403bc
Merge branch 'master' into master
Apr 8, 2020
4a168ed
Merge branch 'master' into master
Apr 8, 2020
27ad2b7
Merge branch 'master' into master
Apr 9, 2020
af67dac
Merge branch 'master' into master
Apr 9, 2020
fd195f2
fix(patients): added test for patient not showing in list
alti21 Apr 10, 2020
d36bcc0
Merge branch 'master' of https://github.com/alti21/hospitalrun-frontend
alti21 Apr 10, 2020
6ad726a
fix(patient): removed unnecessary comment
alti21 Apr 10, 2020
746b828
Merge remote-tracking branch 'upstream/master'
alti21 Apr 10, 2020
62dc561
Merge remote-tracking branch 'upstream/master'
alti21 Apr 10, 2020
5a8d701
Merge remote-tracking branch 'upstream/master'
alti21 Apr 10, 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
Original file line number Diff line number Diff line change
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 protected]',
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
Original file line number Diff line number Diff line change
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