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

Populate encounter edit options based on questionnaire tags #9927

Merged
merged 3 commits into from
Jan 13, 2025

Conversation

Jacobjeevan
Copy link
Contributor

@Jacobjeevan Jacobjeevan commented Jan 13, 2025

Proposed Changes

  • May need to update the name of Community Nurse Homecare Form -> Community Nurse Form.
  • The extra hook maybe unnecessary, but I figured we might want to modify the drop down based on roles in the future/pass different tags in.
image

@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

  • New Features

    • Introduced a dynamic mechanism for retrieving questionnaire options.
    • Added a custom hook to fetch questionnaire options from the API.
  • Improvements

    • Enhanced flexibility in managing dropdown options.
    • Replaced hardcoded options with a more adaptable data retrieval approach.
  • Removed Features

    • Removed the route for editing encounters, making this functionality unavailable in the application.

@Jacobjeevan Jacobjeevan requested a review from a team as a code owner January 13, 2025 08:36
Copy link
Contributor

coderabbitai bot commented Jan 13, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces a custom hook useQuestionnaireOptions to dynamically retrieve questionnaire options in the PatientInfoCard component. The hardcoded constant array QUESTIONNAIRE_OPTIONS has been removed, and its usage has been replaced with the new hook that fetches options from an API based on provided slugs. Additionally, a route for editing encounters has been removed from the ConsultationRoutes. This change enhances the flexibility of how questionnaire options are managed and displayed while preserving the overall functionality of the component.

Changes

File Change Summary
src/components/Patient/PatientInfoCard.tsx Removed hardcoded QUESTIONNAIRE_OPTIONS and replaced with useQuestionnaireOptions hook
src/hooks/useQuestionnaireOptions.ts New custom hook created to dynamically fetch and process questionnaire options
src/Routers/routes/ConsultationRoutes.tsx Removed route for editing encounters

Possibly related PRs

Suggested labels

work-in-progress

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

🐰 Hop, hop, through code so bright,
Questionnaire options take flight!
Static arrays, now dynamic and free,
A hook that sets the data's glee 🌈
Flexibility dances with each query's might!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f35f971 and 957db36.

📒 Files selected for processing (3)
  • src/Routers/routes/ConsultationRoutes.tsx (0 hunks)
  • src/components/Patient/PatientInfoCard.tsx (3 hunks)
  • src/hooks/useQuestionnaireOptions.ts (1 hunks)

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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 13, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 957db36
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67851f9c84c28100080c4307
😎 Deploy Preview https://deploy-preview-9927--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.

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

🧹 Nitpick comments (2)
src/hooks/useQuestionnaireOptions.ts (1)

11-16: Consider internationalizing the default option title.

The default option's title "Update Encounter" should be internationalized to maintain consistency with the rest of the application's UI text, as mentioned in the PR checklist.

 const DEFAULT_OPTIONS: EditQuestionnaireOption[] = [
   {
     slug: "encounter",
-    title: "Update Encounter",
+    title: t("update_encounter"),
   },
 ];
src/components/Patient/PatientInfoCard.tsx (1)

33-33: Consider extracting the questionnaire tag as a constant.

The "encounter_actions" slug should be defined as a constant to avoid magic strings and make it easier to maintain.

+const ENCOUNTER_ACTIONS_TAG = "encounter_actions" as const;
+
 export default function PatientInfoCard(props: PatientInfoCardProps) {
   // ...
-  const questionnaireOptions = useQuestionnaireOptions(["encounter_actions"]);
+  const questionnaireOptions = useQuestionnaireOptions([ENCOUNTER_ACTIONS_TAG]);

Also applies to: 53-53

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 19239d5 and c624f2e.

📒 Files selected for processing (2)
  • src/components/Patient/PatientInfoCard.tsx (3 hunks)
  • src/hooks/useQuestionnaireOptions.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/hooks/useQuestionnaireOptions.ts

[error] 36-36: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (3)
src/hooks/useQuestionnaireOptions.ts (2)

1-9: LGTM! Well-structured imports and interface definition.

The imports are appropriate, and the interface is well-typed for the questionnaire options.


18-28: LGTM! Well-implemented query configuration.

The useQueries implementation is clean, type-safe, and follows react-query best practices.

src/components/Patient/PatientInfoCard.tsx (1)

Line range hint 318-329: LGTM! Clean dropdown implementation with proper translations.

The dropdown menu implementation correctly maps over the questionnaire options and uses proper translations and routing.

src/hooks/useQuestionnaireOptions.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Jan 13, 2025
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.

@Jacobjeevan Jacobjeevan removed the merge conflict pull requests with merge conflict label Jan 13, 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: 0

🧹 Nitpick comments (2)
src/components/Patient/PatientInfoCard.tsx (2)

54-54: Consider documenting the "encounter_actions" slug.

The hook usage is correct. However, it would be helpful to add a comment explaining what types of options are fetched using the "encounter_actions" slug, making it easier for other developers to understand the purpose and potentially add more slugs in the future.

+  // Fetch questionnaire options for encounter actions (e.g., forms, assessments)
   const questionnaireOptions = useQuestionnaireOptions(["encounter_actions"]);

Line range hint 319-328: Consider adding error handling for empty or loading states.

The dropdown menu implementation looks good. However, it might be worth handling cases where:

  1. The options are still loading
  2. The API request failed
  3. No options were returned
+                  {questionnaireOptions.length === 0 ? (
+                    <DropdownMenuItem disabled>
+                      {t("no_questionnaire_options_available")}
+                    </DropdownMenuItem>
+                  ) : (
                     questionnaireOptions.map((option) => (
                       <DropdownMenuItem key={option.slug} asChild>
                         <Link
                           href={`/facility/${encounter.facility.id}/patient/${patient.id}/encounter/${encounter.id}/questionnaire/${option.slug}`}
                           className="cursor-pointer text-gray-800"
                         >
                           {t(option.title)}
                         </Link>
                       </DropdownMenuItem>
                     ))
+                  )}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c624f2e and f35f971.

📒 Files selected for processing (1)
  • src/components/Patient/PatientInfoCard.tsx (3 hunks)
🧰 Additional context used
📓 Learnings (1)
src/components/Patient/PatientInfoCard.tsx (1)
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#9927
File: src/hooks/useQuestionnaireOptions.ts:30-42
Timestamp: 2025-01-13T12:24:08.854Z
Learning: The `useQuestionnaireOptions` hook in `src/hooks/useQuestionnaireOptions.ts` is specifically designed for populating dropdown options. Performance optimizations for array operations (like avoiding spread in reduce) are unnecessary as the data size will always be within a reasonable range for dropdown usage.
🔇 Additional comments (1)
src/components/Patient/PatientInfoCard.tsx (1)

33-34: LGTM!

The import statement follows the project's conventions and is correctly placed in the custom hooks section.

Comment on lines 19 to 28
const queries = useQueries({
queries: slugs.map((slug) => ({
queryKey: ["questionnaire", slug] as const,
queryFn: query(questionnaireApi.list, {
queryParams: {
tag_slug: slug,
},
}),
})),
});
Copy link
Member

Choose a reason for hiding this comment

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

batch_request was an option

@gigincg gigincg merged commit dcd59bd into ohcnetwork:develop Jan 13, 2025
9 of 11 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! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants