This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(appointments): adds ability to display appointments on calendar
- Loading branch information
1 parent
fe0fb6d
commit 842b9ee
Showing
8 changed files
with
349 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/__tests__/scheduling/appointments/view/ViewAppointment.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import '../../../../__mocks__/matchMediaMock' | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
import { Provider } from 'react-redux' | ||
import createMockStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
import Appointment from 'model/Appointment' | ||
import ViewAppointment from 'scheduling/appointments/view/ViewAppointment' | ||
import * as titleUtil from '../../../../page-header/useTitle' | ||
import { Router, Route } from 'react-router' | ||
import { createMemoryHistory } from 'history' | ||
|
||
describe('View Appointment', () => { | ||
describe('header', () => { | ||
it('should use the correct title', () => { | ||
jest.spyOn(titleUtil, 'default') | ||
const history = createMemoryHistory() | ||
const mockStore = createMockStore([thunk]) | ||
const store = mockStore({ | ||
appointment: { | ||
appointment: { | ||
id: '123', | ||
patientId: 'patient', | ||
} as Appointment, | ||
isLoading: false, | ||
}, | ||
}) | ||
mount( | ||
<Provider store={store}> | ||
<Router history={history}> | ||
<Route path="appointments/:id"> | ||
<ViewAppointment /> | ||
</Route> | ||
</Router> | ||
</Provider>, | ||
) | ||
|
||
expect(titleUtil.default).toHaveBeenCalledWith('scheduling.appointments.view.label') | ||
}) | ||
}) | ||
|
||
it('should render a loading spinner', () => {}) | ||
|
||
it('should render a AppointmentDetailForm with the correct data', () => {}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import React from 'react' | ||
import Appointment from 'model/Appointment' | ||
import DateTimePickerWithLabelFormGroup from 'components/input/DateTimePickerWithLabelFormGroup' | ||
import { Typeahead, Label } from '@hospitalrun/components' | ||
import Patient from 'model/Patient' | ||
import PatientRepository from 'clients/db/PatientRepository' | ||
import TextInputWithLabelFormGroup from 'components/input/TextInputWithLabelFormGroup' | ||
import TextFieldWithLabelFormGroup from 'components/input/TextFieldWithLabelFormGroup' | ||
import SelectWithLabelFormGroup from 'components/input/SelectWithLableFormGroup' | ||
import { useTranslation } from 'react-i18next' | ||
interface Props { | ||
appointment: Appointment | ||
onAppointmentChange: (appointment: Appointment) => void | ||
} | ||
|
||
const AppointmentDetailForm = (props: Props) => { | ||
const { onAppointmentChange, appointment } = props | ||
const { t } = useTranslation() | ||
return ( | ||
<> | ||
<div className="row"> | ||
<div className="col"> | ||
<div className="form-group"> | ||
<Label htmlFor="patientTypeahead" text={t('scheduling.appointment.patient')} /> | ||
<Typeahead | ||
id="patientTypeahead" | ||
placeholder={t('scheduling.appointment.patient')} | ||
onChange={(patient: Patient[]) => { | ||
onAppointmentChange({ ...appointment, patientId: patient[0].id }) | ||
}} | ||
onSearch={async (query: string) => PatientRepository.search(query)} | ||
searchAccessor="fullName" | ||
renderMenuItemChildren={(patient: Patient) => ( | ||
<div>{`${patient.fullName} (${patient.friendlyId})`}</div> | ||
)} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="row"> | ||
<div className="col"> | ||
<DateTimePickerWithLabelFormGroup | ||
name="startDate" | ||
label={t('scheduling.appointment.startDate')} | ||
value={new Date(appointment.startDateTime)} | ||
isEditable | ||
onChange={(date) => { | ||
onAppointmentChange({ ...appointment, startDateTime: date.toISOString() }) | ||
}} | ||
/> | ||
</div> | ||
<div className="col"> | ||
<DateTimePickerWithLabelFormGroup | ||
name="endDate" | ||
label={t('scheduling.appointment.endDate')} | ||
value={new Date(appointment.endDateTime)} | ||
isEditable | ||
onChange={(date) => { | ||
onAppointmentChange({ ...appointment, endDateTime: date.toISOString() }) | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
<div className="row"> | ||
<div className="col"> | ||
<TextInputWithLabelFormGroup | ||
name="location" | ||
label={t('scheduling.appointment.location')} | ||
value={appointment.location} | ||
isEditable | ||
onChange={(event) => { | ||
onAppointmentChange({ ...appointment, location: event?.target.value }) | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
<div className="row"> | ||
<div className="col"> | ||
<SelectWithLabelFormGroup | ||
name="type" | ||
label={t('scheduling.appointment.type')} | ||
value={appointment.type} | ||
options={[ | ||
{ label: t('scheduling.appointment.types.checkup'), value: 'checkup' }, | ||
{ label: t('scheduling.appointment.types.emergency'), value: 'emergency' }, | ||
{ label: t('scheduling.appointment.types.followUp'), value: 'follow up' }, | ||
{ label: t('scheduling.appointment.types.routine'), value: 'routine' }, | ||
{ label: t('scheduling.appointment.types.walkUp'), value: 'walk up' }, | ||
]} | ||
onChange={(event: React.ChangeEvent<HTMLSelectElement>) => { | ||
onAppointmentChange({ ...appointment, type: event.currentTarget.value }) | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
<div className="row"> | ||
<div className="col"> | ||
<div className="form-group"> | ||
<TextFieldWithLabelFormGroup | ||
name="reason" | ||
label={t('scheduling.appointment.reason')} | ||
value={appointment.reason} | ||
isEditable | ||
onChange={(event) => { | ||
onAppointmentChange({ ...appointment, reason: event?.target.value }) | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export default AppointmentDetailForm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,61 @@ | ||
import React from 'react' | ||
import React, { useEffect, useState } from 'react' | ||
import { Calendar } from '@hospitalrun/components' | ||
import useTitle from 'page-header/useTitle' | ||
import { useTranslation } from 'react-i18next' | ||
import { useSelector, useDispatch } from 'react-redux' | ||
import { RootState } from 'store' | ||
import { useHistory } from 'react-router' | ||
import { fetchAppointments } from './appointments-slice' | ||
|
||
interface Event { | ||
id: string | ||
start: Date | ||
end: Date | ||
title: string | ||
allDay: boolean | ||
} | ||
|
||
const Appointments = () => { | ||
const { t } = useTranslation() | ||
const history = useHistory() | ||
useTitle(t('scheduling.appointments.label')) | ||
return <Calendar /> | ||
const dispatch = useDispatch() | ||
const { appointments } = useSelector((state: RootState) => state.appointments) | ||
const [events, setEvents] = useState<Event[]>([]) | ||
|
||
useEffect(() => { | ||
dispatch(fetchAppointments()) | ||
}, [dispatch]) | ||
|
||
useEffect(() => { | ||
if (appointments) { | ||
const newEvents: Event[] = [] | ||
appointments.forEach((a) => { | ||
const event = { | ||
id: a.id, | ||
start: new Date(a.startDateTime), | ||
end: new Date(a.endDateTime), | ||
title: a.patientId, | ||
allDay: false, | ||
} | ||
|
||
newEvents.push(event) | ||
}) | ||
|
||
setEvents(newEvents) | ||
} | ||
}, [appointments]) | ||
|
||
return ( | ||
<div> | ||
<Calendar | ||
events={events} | ||
onEventClick={(event) => { | ||
history.push(`/appointments/${event.id}`) | ||
}} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default Appointments |
Oops, something went wrong.