Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTP appointment reschedule #9974

Merged

Conversation

Jacobjeevan
Copy link
Contributor

@Jacobjeevan Jacobjeevan commented Jan 15, 2025

Proposed Changes

  • Adding reschedule option for OTP appointment
  • Right now, there's a minor noticeable delay between user clicking the reschedule button, and both requests (cancellation of old and creation of new appointment) succeeding (relevant toast is displayed on each for both though).
    • So we may need to display a loader or something along those lines.

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

Release Notes

  • New Features

    • Added ability to reschedule appointments.
    • Enhanced appointment management with new routing options.
  • Localization

    • Added new localization string for rescheduling appointments.
  • Improvements

    • Updated import paths in Cypress test files for better module resolution.
    • Refined appointment scheduling workflow, integrating booking and rescheduling functionalities.
  • Chores

    • Minor code structure adjustments in type definitions and routing.

@Jacobjeevan Jacobjeevan added the waiting for related PR a co-related detail PR is under construction label Jan 15, 2025
Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

Walkthrough

This pull request introduces changes across multiple files to support appointment rescheduling functionality and update import paths. The modifications include adding a new route for rescheduling appointments, implementing a rescheduling mechanism in the Schedule and AppointmentDialog components, updating localization strings, and standardizing import statements using the @/cypress/ alias in Cypress test files.

Changes

File Change Summary
cypress/e2e/facility_spec/facility_creation.cy.ts Updated import statements to use @/cypress/ alias
cypress/e2e/patient_spec/patient_creation.cy.ts Updated import statements to use @/cypress/ alias
public/locale/en.json Added new localization string for rescheduling appointments
src/Routers/PatientRouter.tsx Added new route for appointment rescheduling
src/pages/Patient/components/AppointmentDialog.tsx Added handleRescheduleAppointment function
src/pages/PublicAppointments/Schedule.tsx Enhanced appointment scheduling/rescheduling logic
src/types/facility/facility.ts Duplicate interface declaration for FacilityBareMinimum

Possibly related PRs

Suggested labels

needs review, tested, P1

Suggested reviewers

  • rithviknishad

Poem

🐰 A rabbit's tale of code so bright,
Rescheduling made simple, what a delight!
Imports aligned, routes now clear,
Appointments dance without a fear.
Hop, hop, hurray for changes here! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Jan 15, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 3181c9c
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/6790b59f63371a0008a7eae6
😎 Deploy Preview https://deploy-preview-9974--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

src/pages/PublicAppointments/Schedule.tsx Dismissed Show resolved Hide resolved
Copy link

👋 Hi, @Jacobjeevan,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Jan 15, 2025
@rithviknishad rithviknishad removed the waiting for related PR a co-related detail PR is under construction label Jan 22, 2025
@github-actions github-actions bot added the Deploy-Failed Deplyment is not showing preview label Jan 22, 2025
@Jacobjeevan Jacobjeevan marked this pull request as ready for review January 22, 2025 06:31
@Jacobjeevan Jacobjeevan requested a review from a team as a code owner January 22, 2025 06:31
@Jacobjeevan Jacobjeevan removed the Deploy-Failed Deplyment is not showing preview label Jan 22, 2025
@Jacobjeevan Jacobjeevan removed their assignment Jan 22, 2025
@Jacobjeevan Jacobjeevan removed the merge conflict pull requests with merge conflict label Jan 22, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9f2d856 and a65811f.

📒 Files selected for processing (7)
  • cypress/e2e/facility_spec/facility_creation.cy.ts (1 hunks)
  • cypress/e2e/patient_spec/patient_creation.cy.ts (1 hunks)
  • public/locale/en.json (1 hunks)
  • src/Routers/PatientRouter.tsx (1 hunks)
  • src/pages/Patient/components/AppointmentDialog.tsx (3 hunks)
  • src/pages/PublicAppointments/Schedule.tsx (10 hunks)
  • src/types/facility/facility.ts (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • src/types/facility/facility.ts
  • cypress/e2e/patient_spec/patient_creation.cy.ts
  • cypress/e2e/facility_spec/facility_creation.cy.ts
🔇 Additional comments (9)
src/pages/PublicAppointments/Schedule.tsx (4)

1-2: Imports added correctly for new functionalities

The import statements for useMutation, useQuery, useQueryClient, and date-fns functions (format, isBefore, isSameDay) are necessary and correctly added to support the new appointment rescheduling functionalities.


40-40: Added appointmentId prop to AppointmentsProps interface

The addition of the optional appointmentId prop in the AppointmentsProps interface allows the component to handle both booking and rescheduling of appointments effectively.


64-83: Ensure proper handling of sensitive appointment data

Fetching appointment data using useQuery is appropriate for rescheduling functionality. However, please verify that any sensitive patient information within appointmentData is handled securely and complies with privacy regulations.


368-379: Verify that selectedSlot is defined before rescheduling

When handling the reschedule action, ensure that selectedSlot is selected by the user before attempting to create a new appointment. If selectedSlot is undefined, it may cause errors during appointment creation.

Consider adding a check before calling handleRescheduleAppointment:

if (appointmentId && appointment) {
+ if (selectedSlot) {
    handleRescheduleAppointment(appointment);
+ } else {
+   toast.error(t("please_select_a_slot"));
+ }
} else {
  // existing code
}
src/Routers/PatientRouter.tsx (1)

50-64: Reschedule route added correctly

The new route for rescheduling appointments is properly added to AppointmentRoutes. The route parameters are correctly defined, and the ScheduleAppointment component receives all necessary props for rescheduling functionality.

src/pages/Patient/components/AppointmentDialog.tsx (3)

2-2: Imported navigate from raviger

The import statement for navigate from raviger is correctly added to enable navigation within the appointment dialog.


43-47: Function handleRescheduleAppointment implemented correctly

The handleRescheduleAppointment function constructs the correct URL for navigating to the reschedule appointment page using the appointment details.


112-115: Reschedule button added with correct functionality

The "Reschedule" button is appropriately added to the dialog footer and correctly calls handleRescheduleAppointment on click, enabling users to initiate the rescheduling process.

public/locale/en.json (1)

1773-1773: LGTM! The new localization string is well-formatted.

The added key-value pair follows the established naming conventions and is properly placed in alphabetical order. The text is appropriately capitalized and grammatically correct.

src/pages/PublicAppointments/Schedule.tsx Outdated Show resolved Hide resolved
src/pages/PublicAppointments/Schedule.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/pages/PublicAppointments/Schedule.tsx (3)

79-83: Add cleanup to the appointment reason effect.

The effect that sets the reason should clean up its changes when the component unmounts or when the appointment changes.

 useEffect(() => {
   if (appointment) {
     setReason(appointment.reason_for_visit);
   }
+  return () => {
+    setReason("");
+  };
 }, [appointment]);

169-178: Consider using a transaction or optimistic updates for reschedule flow.

The current implementation has a potential race condition where the cancellation succeeds but the creation fails. While global error handling is in place, consider using optimistic updates to improve the user experience during the delay between cancel and create operations.

 onSuccess: (appointment: Appointment) => {
   toast.success(t("appointment_cancelled"));
+  // Optimistically update the UI
+  queryClient.setQueryData(
+    ["appointment", tokenData.phoneNumber],
+    (old: { results: Appointment[] } | undefined) => ({
+      results: old?.results.filter((a) => a.id !== appointment.id) || [],
+    })
+  );
   queryClient.invalidateQueries({
     queryKey: ["appointment", tokenData.phoneNumber],
   });
   createAppointment({
     reason_for_visit: reason,
     patient: appointment.patient.id,
   });
 },

375-379: Consider session storage for temporary data.

While the stored data isn't sensitive (as confirmed in past reviews), consider using sessionStorage instead of localStorage for temporary data that's only needed during the booking flow.

-localStorage.setItem(
+sessionStorage.setItem(
   "selectedSlot",
   JSON.stringify(selectedSlot),
 );
-localStorage.setItem(
+sessionStorage.setItem(
   "reason",
   reason
 );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a65811f and 3181c9c.

📒 Files selected for processing (1)
  • src/pages/PublicAppointments/Schedule.tsx (10 hunks)
🔇 Additional comments (1)
src/pages/PublicAppointments/Schedule.tsx (1)

365-367: Good use of loading indicators!

The loading state handling addresses the delay mentioned in the PR objectives, providing clear feedback to users during the reschedule operation.

@khavinshankar khavinshankar merged commit d3962ce into ohcnetwork:develop Jan 22, 2025
17 of 19 checks passed
Copy link

@Jacobjeevan Your efforts have helped advance digital healthcare and TeleICU systems. 🚀 Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! 🙌

manmeetnagii pushed a commit to manmeetnagii/care_fe that referenced this pull request Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants