diff --git a/src/__tests__/imagings/ViewImagings.test.tsx b/src/__tests__/imagings/ViewImagings.test.tsx index 94ac8b53fb..f06f32e3cb 100644 --- a/src/__tests__/imagings/ViewImagings.test.tsx +++ b/src/__tests__/imagings/ViewImagings.test.tsx @@ -28,6 +28,7 @@ describe('View Imagings', () => { id: '1234', type: 'imaging type', patient: 'patient', + fullName: 'full name', status: 'requested', requestedOn: expectedDate.toISOString(), requestedBy: 'some user', @@ -110,7 +111,7 @@ describe('View Imagings', () => { expect.objectContaining({ label: 'imagings.imaging.requestedOn', key: 'requestedOn' }), ) expect(columns[3]).toEqual( - expect.objectContaining({ label: 'imagings.imaging.patient', key: 'patient' }), + expect.objectContaining({ label: 'imagings.imaging.patient', key: 'fullName' }), ) expect(columns[4]).toEqual( expect.objectContaining({ label: 'imagings.imaging.requestedBy', key: 'requestedBy' }), diff --git a/src/__tests__/imagings/requests/NewImagingRequest.test.tsx b/src/__tests__/imagings/requests/NewImagingRequest.test.tsx index a05bfde5a4..6d21d587f5 100644 --- a/src/__tests__/imagings/requests/NewImagingRequest.test.tsx +++ b/src/__tests__/imagings/requests/NewImagingRequest.test.tsx @@ -86,6 +86,14 @@ describe('New Imaging Request', () => { expect(typeahead.prop('searchAccessor')).toEqual('fullName') }) + it('should render a dropdown list of visits', async () => { + const wrapper = await setup('loading', {}) + const visitsTypeSelect = wrapper.find('.visits').find(SelectWithLabelFormGroup) + expect(visitsTypeSelect).toBeDefined() + expect(visitsTypeSelect.prop('label')).toEqual('patient.visits.label') + expect(visitsTypeSelect.prop('isRequired')).toBeTruthy() + }) + it('should render a type input box', async () => { const wrapper = await setup('loading', {}) const typeInputBox = wrapper.find(TextInputWithLabelFormGroup) @@ -98,7 +106,7 @@ describe('New Imaging Request', () => { it('should render a status types select', async () => { const wrapper = await setup('loading', {}) - const statusTypesSelect = wrapper.find(SelectWithLabelFormGroup) + const statusTypesSelect = wrapper.find('.imaging-status').find(SelectWithLabelFormGroup) expect(statusTypesSelect).toBeDefined() expect(statusTypesSelect.prop('label')).toEqual('imagings.imaging.status') @@ -184,6 +192,7 @@ describe('New Imaging Request', () => { patient: 'patient', type: 'expected type', status: 'requested', + visitId: 'expected visitId', notes: 'expected notes', id: '1234', requestedOn: expectedDate.toISOString(), @@ -204,12 +213,18 @@ describe('New Imaging Request', () => { onChange({ currentTarget: { value: expectedImaging.type } }) }) - const statusSelect = wrapper.find(SelectWithLabelFormGroup) + const statusSelect = wrapper.find('.imaging-status').find(SelectWithLabelFormGroup) act(() => { const onChange = statusSelect.prop('onChange') as any onChange({ currentTarget: { value: expectedImaging.status } }) }) + const visitsSelect = wrapper.find('.visits').find(SelectWithLabelFormGroup) + act(() => { + const onChange = visitsSelect.prop('onChange') as any + onChange({ currentTarget: { value: expectedImaging.visitId } }) + }) + const notesTextField = wrapper.find(TextFieldWithLabelFormGroup) act(() => { const onChange = notesTextField.prop('onChange') as any diff --git a/src/imagings/ViewImagings.tsx b/src/imagings/ViewImagings.tsx index ffc5317566..96b2bd4b9f 100644 --- a/src/imagings/ViewImagings.tsx +++ b/src/imagings/ViewImagings.tsx @@ -74,7 +74,7 @@ const ViewImagings = () => { formatter: (row) => row.requestedOn ? format(new Date(row.requestedOn), 'yyyy-MM-dd hh:mm a') : '', }, - { label: t('imagings.imaging.patient'), key: 'patient' }, + { label: t('imagings.imaging.patient'), key: 'fullName' }, { label: t('imagings.imaging.requestedBy'), key: 'requestedBy', diff --git a/src/imagings/imaging-slice.ts b/src/imagings/imaging-slice.ts index 5be2c06c03..70bd442e96 100644 --- a/src/imagings/imaging-slice.ts +++ b/src/imagings/imaging-slice.ts @@ -10,6 +10,7 @@ interface Error { type?: string status?: string message?: string + visitId?: string } interface ImagingState { diff --git a/src/imagings/requests/NewImagingRequest.tsx b/src/imagings/requests/NewImagingRequest.tsx index abbb768518..f6432f7e47 100644 --- a/src/imagings/requests/NewImagingRequest.tsx +++ b/src/imagings/requests/NewImagingRequest.tsx @@ -1,4 +1,5 @@ -import { Typeahead, Label, Button, Alert } from '@hospitalrun/components' +import { Typeahead, Label, Button, Alert, Column, Row } from '@hospitalrun/components' +import format from 'date-fns/format' import React, { useState } from 'react' import { useDispatch, useSelector } from 'react-redux' import { useHistory } from 'react-router-dom' @@ -23,6 +24,7 @@ const NewImagingRequest = () => { const history = useHistory() useTitle(t('imagings.requests.new')) const { status, error } = useSelector((state: RootState) => state.imaging) + const [visitOption, setVisitOption] = useState([] as Option[]) const statusOptions: Option[] = [ { label: t('imagings.status.requested'), value: 'requested' }, @@ -32,9 +34,11 @@ const NewImagingRequest = () => { const [newImagingRequest, setNewImagingRequest] = useState({ patient: '', + fullName: '', type: '', notes: '', status: '', + visitId: '', }) const breadcrumbs = [ @@ -46,10 +50,28 @@ const NewImagingRequest = () => { useAddBreadcrumbs(breadcrumbs) const onPatientChange = (patient: Patient) => { - setNewImagingRequest((previousNewImagingRequest) => ({ - ...previousNewImagingRequest, - patient: patient.fullName as string, - })) + if (patient) { + setNewImagingRequest((previousNewImagingRequest) => ({ + ...previousNewImagingRequest, + patient: patient.id, + fullName: patient.fullName as string, + })) + + const visits = patient.visits?.map((v) => ({ + label: `${v.type} at ${format(new Date(v.startDateTime), 'yyyy-MM-dd hh:mm a')}`, + value: v.id, + })) as Option[] + + setVisitOption(visits) + } else { + setNewImagingRequest((previousNewImagingRequest) => ({ + ...previousNewImagingRequest, + patient: '', + fullName: '', + visitId: '', + })) + setVisitOption([]) + } } const onImagingTypeChange = (event: React.ChangeEvent) => { @@ -67,6 +89,13 @@ const NewImagingRequest = () => { })) } + const onVisitChange = (value: string) => { + setNewImagingRequest((previousNewImagingRequest) => ({ + ...previousNewImagingRequest, + visitId: value, + })) + } + const onNoteChange = (event: React.ChangeEvent) => { const notes = event.currentTarget.value setNewImagingRequest((previousNewImagingRequest) => ({ @@ -88,25 +117,54 @@ const NewImagingRequest = () => { history.push('/imaging') } + const defaultSelectedVisitsOption = () => { + if (visitOption !== undefined) { + return visitOption.filter(({ value }) => value === newImagingRequest.visitId) + } + return [] + } + return ( <> {status === 'error' && ( )}
-
-
+ + +
+
+
+ +
+ { + onVisitChange(values[0]) + }} + /> +
+
+
+ { value={newImagingRequest.type} onChange={onImagingTypeChange} /> - value === newImagingRequest.status)} - onChange={(values) => onStatusChange(values[0])} - /> +
+ value === newImagingRequest.status, + )} + onChange={(values) => onStatusChange(values[0])} + /> +