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

feat(edit appointment): implement Edit Appointment #1845

Merged
merged 9 commits into from
Feb 24, 2020

Conversation

MatthewDorner
Copy link
Contributor

@MatthewDorner MatthewDorner commented Feb 21, 2020

Fixes #1807

Changes proposed in this pull request:

  • Implement Edit Appointment
  • Rename translation keys to be consistent across Patient and Appointment
  • Move createAppointment from appointments-slice to appointment-slice
  • Rename AppointmentsRepository to AppointmentRepository to be consistent with PatientRepository
  • Add createAppointmentSuccess action to set isLoading to false and be consistent with createPatient
  • Refactor AppointmentDetailsForm to use single Typeahead for patient instead of conditional typeahead / text field

@vercel
Copy link

vercel bot commented Feb 21, 2020

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/hospitalrun/hospitalrun-frontend/fafryjun5
✅ Preview: https://hospitalrun-frontend-git-fork-matthewdorner-edit-appointment.hospitalrun.now.sh

@vercel vercel bot temporarily deployed to Preview February 21, 2020 23:04 Inactive
<Label htmlFor="patientTypeahead" text={t('scheduling.appointment.patient')} />
<Typeahead
id="patientTypeahead"
disabled={!isEditable || patient !== undefined}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line appears to be why the Travis build is failing, because it doesn't recognize disabled as a prop. I recently added disabled in HospitalRun/components#290. Is Travis running it with an older version of the components library?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it, since GitHub actions passed. @tehkapa can you check this out?

Copy link
Member

@jackcmeyer jackcmeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome feature 🎉

One other bug:
The tool bar button on the /appointments route is showing the internationalized key rather than the value.

Comment on lines +66 to +82
export const createAppointment = (appointment: Appointment, history: any): AppThunk => async (
dispatch,
) => {
dispatch(createAppointmentStart())
await AppointmentRepository.save(appointment)
dispatch(createAppointmentSuccess())
history.push('/appointments')
}

export const updateAppointment = (appointment: Appointment, history: any): AppThunk => async (
dispatch,
) => {
dispatch(updateAppointmentStart())
const updatedAppointment = await AppointmentRepository.saveOrUpdate(appointment)
dispatch(updateAppointmentSuccess(updatedAppointment))
history.push(`/appointments/${updatedAppointment.id}`)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have success alerts for successful create/edit. I think we can open new issues to accomplish this, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wasn't sure if we wanted Toasts for everything or which ones we wanted them for.

src/scheduling/appointments/view/ViewAppointment.tsx Outdated Show resolved Hide resolved
Comment on lines +42 to +50
let newErrorMessage = ''
if (isBefore(new Date(appointment.endDateTime), new Date(appointment.startDateTime))) {
newErrorMessage += ` ${t('scheduling.appointment.errors.startDateMustBeBeforeEndDate')}`
}

if (newErrorMessage) {
setErrorMessage(newErrorMessage.trim())
return
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is duplicated with the New Appointment save logic.

It seems like we should be able to use the same logic in both places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I'm not sure where it should go. It's the same for New Patient / Edit Patient.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure either, right now. Let's think on this and we can figure out the right abstraction later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have two complete modules with new/view/edit/delete, maybe we should make a point to look over the code in general with an eye for code that's duplicated as I'm sure there are a few more instances. Just now I can think of the Save/Cancel buttons, Appointment and Patient objects used in tests, getFriendlyId, form field change handlers...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree! We're getting close to that point, if not at that point when this PR gets merged.

src/scheduling/appointments/edit/EditAppointment.tsx Outdated Show resolved Hide resolved
src/scheduling/appointments/edit/EditAppointment.tsx Outdated Show resolved Hide resolved
@jackcmeyer jackcmeyer added 🚀enhancement an issue/pull request that adds a feature to the application scheduling issue/pull request that interacts with scheduling module labels Feb 22, 2020
@jackcmeyer jackcmeyer added this to In progress in Version 2.0 via automation Feb 22, 2020
@jackcmeyer jackcmeyer added this to the v2.0.0 milestone Feb 22, 2020
@matteovivona matteovivona requested review from jackcmeyer and removed request for matteovivona February 22, 2020 08:46
Comment on lines +79 to +86
<PrivateRoute
isAuthenticated={
permissions.includes(Permissions.WriteAppointments) &&
permissions.includes(Permissions.ReadAppointments)
}
exact
path="/appointments/edit/:id"
component={EditAppointment}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add some tests around this in HospitalRun.test.tsx. Just looking for tests around the security and then making sure the component renders when the route is accessed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to this, do you think it should require any Patient permissions for this route?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably since there is patient data that can be seen...

We probably need a ReadPatient and ReadPatients permission. New Appointments and Edit Appointments should require ReadPatients maybe?

I think that is outside the scope of this issue though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, added tests.

Comment on lines +42 to +50
let newErrorMessage = ''
if (isBefore(new Date(appointment.endDateTime), new Date(appointment.startDateTime))) {
newErrorMessage += ` ${t('scheduling.appointment.errors.startDateMustBeBeforeEndDate')}`
}

if (newErrorMessage) {
setErrorMessage(newErrorMessage.trim())
return
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure either, right now. Let's think on this and we can figure out the right abstraction later.

@MatthewDorner
Copy link
Contributor Author

The tool bar button on the /appointments route is showing the internationalized key rather than the value.

This should also be fixed now.

jackcmeyer
jackcmeyer previously approved these changes Feb 23, 2020
@matteovivona
Copy link
Contributor

@MatthewDorner I've accepted 2 PRs and there's been an "avalanche" of conflict. Sorry, dude!

@MatthewDorner
Copy link
Contributor Author

@MatthewDorner I've accepted 2 PRs and there's been an "avalanche" of conflict. Sorry, dude!

Should be fixed now. Not sure what's going on with the tests now, but they're passing for me locally (Ubuntu).

@vercel vercel bot temporarily deployed to Preview February 24, 2020 08:55 Inactive
@matteovivona matteovivona merged commit 4366462 into HospitalRun:master Feb 24, 2020
Version 2.0 automation moved this from In progress to Done Feb 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🚀enhancement an issue/pull request that adds a feature to the application scheduling issue/pull request that interacts with scheduling module
Projects
Version 2.0
  
Done
Development

Successfully merging this pull request may close these issues.

Edit Appointment
3 participants