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

Commit

Permalink
feat(diagnosis): link diagnosis with visit (#2321)
Browse files Browse the repository at this point in the history
Co-authored-by: Matteo Vivona <[email protected]>
  • Loading branch information
janmarkusmilan and matteovivona authored Aug 26, 2020
1 parent c0ee742 commit e558c27
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/__tests__/patients/diagnoses/DiagnosisForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { act } from 'react-dom/test-utils'

import DiagnosisForm from '../../../patients/diagnoses/DiagnosisForm'
import Diagnosis, { DiagnosisStatus } from '../../../shared/model/Diagnosis'
import Patient from '../../../shared/model/Patient'

describe('Diagnosis Form', () => {
let onDiagnosisChangeSpy: any
Expand All @@ -17,8 +18,14 @@ describe('Diagnosis Form', () => {
abatementDate: new Date().toISOString(),
status: DiagnosisStatus.Active,
note: 'some note',
visit: 'some visit',
}

const patient = {
givenName: 'first',
fullName: 'first',
} as Patient

const setup = (disabled = false, initializeDiagnosis = true, error?: any) => {
onDiagnosisChangeSpy = jest.fn()
const wrapper = mount(
Expand All @@ -27,6 +34,7 @@ describe('Diagnosis Form', () => {
diagnosis={initializeDiagnosis ? diagnosis : {}}
diagnosisError={error}
disabled={disabled}
patient={patient}
/>,
)
return { wrapper }
Expand Down Expand Up @@ -55,6 +63,29 @@ describe('Diagnosis Form', () => {
expect(onDiagnosisChangeSpy).toHaveBeenCalledWith({ name: expectedNewname })
})

it('should render a visit selector', () => {
const { wrapper } = setup()

const visitSelector = wrapper.findWhere((w) => w.prop('name') === 'visit')

expect(visitSelector).toHaveLength(1)
expect(visitSelector.prop('patient.diagnoses.visit'))
expect(visitSelector.prop('isRequired')).toBeFalsy()
expect(visitSelector.prop('defaultSelected')).toEqual([])
})

it('should call the on change handler when visit changes', () => {
const expectedNewVisit = patient.visits
const { wrapper } = setup(false, false)
act(() => {
const visitSelector = wrapper.findWhere((w) => w.prop('name') === 'visit')
const onChange = visitSelector.prop('onChange') as any
onChange([expectedNewVisit])
})

expect(onDiagnosisChangeSpy).toHaveBeenCalledWith({ status: expectedNewVisit })
})

it('should render a status selector', () => {
const { wrapper } = setup()

Expand Down
2 changes: 2 additions & 0 deletions src/patients/diagnoses/AddDiagnosisModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const initialDiagnosisState = {
onsetDate: new Date().toISOString(),
abatementDate: new Date().toISOString(),
note: '',
visit: '',
}

const AddDiagnosisModal = (props: Props) => {
Expand All @@ -45,6 +46,7 @@ const AddDiagnosisModal = (props: Props) => {
diagnosis={diagnosis}
diagnosisError={diagnosisError}
onChange={onDiagnosisChange}
patient={patient}
/>
)
return (
Expand Down
34 changes: 33 additions & 1 deletion src/patients/diagnoses/DiagnosisForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Alert, Row, Column } from '@hospitalrun/components'
import format from 'date-fns/format'
import React, { useState } from 'react'
import { useTranslation } from 'react-i18next'

Expand All @@ -9,6 +10,7 @@ import SelectWithLabelFormGroup, {
import TextFieldWithLabelFormGroup from '../../shared/components/input/TextFieldWithLabelFormGroup'
import TextInputWithLabelFormGroup from '../../shared/components/input/TextInputWithLabelFormGroup'
import Diagnosis, { DiagnosisStatus } from '../../shared/model/Diagnosis'
import Patient from '../../shared/model/Patient'

interface Error {
message?: string
Expand All @@ -19,16 +21,18 @@ interface Error {
status?: string
note?: string
}

interface Props {
diagnosis: Partial<Diagnosis>
diagnosisError?: Error
onChange?: (newDiagnosis: Partial<Diagnosis>) => void
disabled: boolean
patient: Patient
}

const DiagnosisForm = (props: Props) => {
const { t } = useTranslation()
const { diagnosis, diagnosisError, disabled, onChange } = props
const { diagnosis, diagnosisError, disabled, onChange, patient } = props
const [status, setStatus] = useState(diagnosis.status)

const onFieldChange = (name: string, value: string | DiagnosisStatus) => {
Expand All @@ -41,6 +45,18 @@ const DiagnosisForm = (props: Props) => {
}
}

const patientVisits = patient?.visits?.map((v) => ({
label: `${v.type} at ${format(new Date(v.startDateTime), 'yyyy-MM-dd, hh:mm a')}`,
value: v.id,
})) as Option[]

const defaultSelectedVisitOption = () => {
if (patientVisits !== undefined) {
return patientVisits.filter(({ value }) => value === diagnosis.visit)
}
return []
}

const statusOptions: Option[] = Object.values(DiagnosisStatus).map((v) => ({
label: v,
value: v,
Expand Down Expand Up @@ -116,6 +132,22 @@ const DiagnosisForm = (props: Props) => {
</Column>
</Row>

<Row>
<Column md={12}>
<SelectWithLabelFormGroup
name="visit"
label={t('patient.diagnoses.visit')}
isRequired={false}
options={patientVisits || []}
defaultSelected={defaultSelectedVisitOption()}
onChange={(values) => {
onFieldChange('visit', values[0])
}}
isEditable={patient?.visits !== undefined}
/>
</Column>
</Row>

<Row>
<Column md={12}>
<SelectWithLabelFormGroup
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/enUs/translations/patient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export default {
diagnosisDate: 'Diagnosis Date',
onsetDate: 'Onset Date',
abatementDate: 'Abatement Date',
visit: 'Visit',
status: 'Status',
active: 'Active',
recurrence: 'Recurrence',
Expand Down
1 change: 1 addition & 0 deletions src/shared/model/Diagnosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export default interface Diagnosis {
abatementDate: string
status: DiagnosisStatus
note: string
visit: string
}

1 comment on commit e558c27

@vercel
Copy link

@vercel vercel bot commented on e558c27 Aug 26, 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.