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

Encounter Qustions dropdown values moved to constants and i18 applied for all strings #9859

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

arhamathar
Copy link
Contributor

@arhamathar arhamathar commented Jan 9, 2025

Proposed Changes

@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 internationalization (i18n) support for encounter-related components.
    • Enhanced localization capabilities for encounter status, class, priority, and other fields.
  • Improvements

    • Dynamically generated select options for encounter-related dropdowns.
    • Updated type definitions to improve type safety and maintainability.
  • Localization

    • Added comprehensive translation support for encounter-related terminology.
    • Introduced new translation keys for various encounter attributes and selection prompts, including admit source, diet preference, and discharge disposition.

@arhamathar arhamathar requested a review from a team as a code owner January 9, 2025 11:08
Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

Walkthrough

This pull request introduces comprehensive internationalization (i18n) support for encounter-related components. The changes span multiple files, including the EncounterQuestion.tsx component, the English localization JSON file, and the encounter type definitions. The modifications enable dynamic translation of encounter-related labels, status options, and select prompts while also refactoring type definitions to use constant arrays for improved type safety and maintainability.

Changes

File Change Summary
src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx Added useTranslation hook, replaced hardcoded labels with translation function calls, dynamically generated select options using imported constants
public/locale/en.json Added multiple new translation keys for encounter-related terms, select prompts, and loading states
src/types/emr/encounter.ts Replaced union types with constant arrays, updated type definitions using typeof to derive types from constants

Assessment against linked issues

Objective Addressed Explanation
Update encounters with diet preferences
Resolve diet preference payload formatting Requires backend validation to confirm complete resolution

Possibly related PRs

Suggested labels

tested, changes required

Suggested reviewers

  • rithviknishad
  • bodhish

Poem

🐰 A Rabbit's Localization Ballad 🌐
In fields of code where translations bloom,
Encounter questions dance and zoom,
With i18n's magical embrace,
We give each label its rightful place!
Hop, hop, hooray for multilingual might! 🌈

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

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 6c71732
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/6787e648e2bedb0008f1ac18
😎 Deploy Preview https://deploy-preview-9859--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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0592e63 and 9c6fbd2.

📒 Files selected for processing (2)
  • src/common/constants.tsx (1 hunks)
  • src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (3)
src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx (2)

14-14: LGTM! Clean import of diet preferences constant.

The import statement is well-placed with other imports from the common directory.


396-400: LGTM! Clean implementation of dynamic diet preferences.

The dynamic mapping of diet preferences from constants improves maintainability and follows React best practices.

src/common/constants.tsx (1)

1761-1764: LGTM! Well-documented deprecated constant.

The deprecated constant is properly documented with JSDoc comment and points to the new location.

Comment on lines 1766 to 1834
export const DIET_PREFERENCE_OPTIONS = [
{ label: "Vegetarian", value: "vegetarian" },
{ label: "Dairy Free", value: "diary_free" },
{ label: "Nut Free", value: "nut_free" },
{ label: "Gluten Free", value: "gluten_free" },
{ label: "Vegan", value: "vegan" },
{ label: "Halal", value: "halal" },
{ label: "Kosher", value: "kosher" },
{ label: "None", value: "none" },
] as const;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in diet preference value.

There's a typo in the "dairy_free" value (currently spelled as "diary_free").

Apply this diff to fix the typo:

-  { label: "Dairy Free", value: "diary_free" },
+  { label: "Dairy Free", value: "dairy_free" },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const DIET_PREFERENCE_OPTIONS = [
{ label: "Vegetarian", value: "vegetarian" },
{ label: "Dairy Free", value: "diary_free" },
{ label: "Nut Free", value: "nut_free" },
{ label: "Gluten Free", value: "gluten_free" },
{ label: "Vegan", value: "vegan" },
{ label: "Halal", value: "halal" },
{ label: "Kosher", value: "kosher" },
{ label: "None", value: "none" },
] as const;
export const DIET_PREFERENCE_OPTIONS = [
{ label: "Vegetarian", value: "vegetarian" },
{ label: "Dairy Free", value: "dairy_free" },
{ label: "Nut Free", value: "nut_free" },
{ label: "Gluten Free", value: "gluten_free" },
{ label: "Vegan", value: "vegan" },
{ label: "Halal", value: "halal" },
{ label: "Kosher", value: "kosher" },
{ label: "None", value: "none" },
] as const;

Comment on lines 1766 to 1834
export const DIET_PREFERENCE_OPTIONS = [
{ label: "Vegetarian", value: "vegetarian" },
{ label: "Dairy Free", value: "diary_free" },
{ label: "Nut Free", value: "nut_free" },
{ label: "Gluten Free", value: "gluten_free" },
{ label: "Vegan", value: "vegan" },
{ label: "Halal", value: "halal" },
{ label: "Kosher", value: "kosher" },
{ label: "None", value: "none" },
] as const;
Copy link
Member

Choose a reason for hiding this comment

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

only the value list is needed, the label can be kept in i18n texts. Refer README for translation guidelines.

Comment on lines 1761 to 1764
/**
* @deprecated use `LocalStorageKeys.patientTokenKey` instead
*/
export const CarePatientTokenKey = LocalStorageKeys.patientTokenKey;
Copy link
Member

Choose a reason for hiding this comment

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

?

@rithviknishad
Copy link
Member

Do the same for all things present in EncounterQuestion and not just diet preference. Also add i18n translations for all literal strings in the file

src/common/constants.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 (2)
src/common/constants.tsx (2)

1784-1791: Add JSDoc comments to explain abbreviations.

The encounter class values use abbreviations that may not be immediately clear to other developers. Consider adding JSDoc comments to explain what each abbreviation means (e.g., imp = inpatient, amb = ambulatory, etc.).

+/**
+ * Encounter class types
+ * imp - Inpatient encounter
+ * amb - Ambulatory encounter
+ * obsenc - Observation encounter
+ * emer - Emergency encounter
+ * vr - Virtual encounter
+ * hh - Home health encounter
+ */
export const ENCOUNTER_CLASS = [
  "imp",
  "amb",
  "obsenc",
  "emer",
  "vr",
  "hh",
] as const;

1793-1807: Standardize casing format for priority values.

The priority values mix uppercase ("ASAP") with snake_case format. Standardize all values to use snake_case for consistency.

export const ENCOUNTER_PRIORITY = [
-  "ASAP",
+  "asap",
  "callback_results",
  "callback_for_scheduling",
  "elective",
  "emergency",
  "preop",
  "as_needed",
  "routine",
  "rush_reporting",
  "stat",
  "timing_critical",
  "use_as_directed",
  "urgent",
] as const;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e3c3e78 and e0fa855.

📒 Files selected for processing (3)
  • public/locale/en.json (10 hunks)
  • src/common/constants.tsx (1 hunks)
  • src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx (12 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: cypress-run (1)
  • GitHub Check: OSSAR-Scan
🔇 Additional comments (5)
src/common/constants.tsx (4)

1772-1782: LGTM! Well-structured encounter status values.

The status values follow a logical progression and use consistent snake_case formatting.


1809-1820: LGTM! Consistent admit source values.

The admit source values use consistent snake_case formatting and are well-organized.


1822-1834: LGTM! Well-structured discharge disposition values.

The discharge disposition values use consistent snake_case formatting and are logically organized.


1761-1770: 🛠️ Refactor suggestion

⚠️ Potential issue

Fix typo and refactor to array format.

  1. Fix the typo in "diary_free" value.
  2. Refactor to use array format for consistency with existing patterns.
-export const ENCOUNTER_DIET_PREFERENCE = [
-  "vegetarian",
-  "diary_free",
-  "nut_free",
-  "gluten_free",
-  "vegan",
-  "halal",
-  "kosher",
-  "none",
-] as const;
+export const ENCOUNTER_DIET_PREFERENCE = [
+  "vegetarian",
+  "dairy_free",
+  "nut_free", 
+  "gluten_free",
+  "vegan",
+  "halal",
+  "kosher",
+  "none"
+] as const;

Likely invalid or redundant comment.

public/locale/en.json (1)

351-351: LGTM! Complete and well-organized translations.

All encounter-related constants have corresponding translations with proper naming conventions.

Also applies to: 719-719, 725-725, 816-816, 884-884, 1061-1061, 1120-1120, 1179-1179, 1565-1565, 1696-1696, 1698-1698, 1702-1702, 1703-1703, 1718-1718, 1723-1723

@arhamathar
Copy link
Contributor Author

Hi @rithviknishad I have moved the values to an array. Can you please check and confirm

src/common/constants.tsx Outdated Show resolved Hide resolved
@rithviknishad
Copy link
Member

Do update the PR title btw

@rithviknishad rithviknishad requested a review from bodhish January 11, 2025 13:43
@arhamathar arhamathar changed the title diet preference value moved to constants as snake_case Encounter Qustions dropdown values moved to constants and i18 applied for all strings Jan 11, 2025
Copy link

👋 Hi, @arhamathar,
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 11, 2025
@github-actions github-actions bot removed the merge conflict pull requests with merge conflict label Jan 12, 2025
Copy link

👋 Hi, @arhamathar,
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 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: 1

🧹 Nitpick comments (2)
src/types/emr/encounter.ts (2)

39-51: Consider adding descriptions for abbreviated values.

The discharge disposition constants use abbreviated values that might not be immediately clear (e.g., "aadvice", "exp", "psy", "snf"). Consider adding comments or using more descriptive values.


53-67: Maintain consistent casing in priority constants.

The priority constant "ASAP" uses uppercase while other values use snake_case. Consider maintaining consistency.

Apply this diff to maintain consistent casing:

-  "ASAP",
+  "asap",
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2bc071d and 6c71732.

📒 Files selected for processing (3)
  • public/locale/en.json (9 hunks)
  • src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx (12 hunks)
  • src/types/emr/encounter.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (5)
src/types/emr/encounter.ts (4)

6-17: LGTM! Well-structured admit source constants.

The ENCOUNTER_ADMIT_SOURCE array is well-organized and uses consistent snake_case naming convention.


19-26: LGTM! Well-structured class constants.

The ENCOUNTER_CLASS array follows the established pattern and naming conventions.


69-79: LGTM! Well-structured status constants.

The ENCOUNTER_STATUS array follows the established pattern and naming conventions.


81-93: LGTM! Type-safe type definitions.

The type definitions correctly use the constant arrays with typeof and array indexing for type safety.

public/locale/en.json (1)

362-362: Verify translations for all encounter constants.

The translations for encounter-related strings have been added, but let's verify the coverage:

  1. Missing translation for encounter class "obsenc" (Observation)
  2. Missing translation for encounter priority "use_as_directed"
  3. Missing translation for encounter status "entered_in_error"

Run this script to check for missing translations:

Also applies to: 763-763, 769-769, 932-932, 1126-1126, 1127-1127, 1187-1187, 1250-1250, 1676-1676, 1841-1841, 1844-1844, 1848-1848, 1849-1849, 1873-1873, 1880-1880

Comment on lines +28 to +37
export const ENCOUNTER_DIET_PREFERENCE = [
"vegetarian",
"diary_free",
"nut_free",
"gluten_free",
"vegan",
"halal",
"kosher",
"none",
] as const;
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 15, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in diet preference constant.

There's a typo in the diet preference value "diary_free" which should be "dairy_free".

Apply this diff to fix the typo:

-  "diary_free",
+  "dairy_free",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const ENCOUNTER_DIET_PREFERENCE = [
"vegetarian",
"diary_free",
"nut_free",
"gluten_free",
"vegan",
"halal",
"kosher",
"none",
] as const;
export const ENCOUNTER_DIET_PREFERENCE = [
"vegetarian",
"dairy_free",
"nut_free",
"gluten_free",
"vegan",
"halal",
"kosher",
"none",
] as const;

Copy link
Contributor

Choose a reason for hiding this comment

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

currently backend uses diary_free so it will need to be updated there first.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Jacobjeevan Understood, thanks for the clarification. I'll withdraw my suggestion since changing it would break compatibility with the backend. Would you like me to create a follow-up issue to track updating both the backend and frontend to use the correct spelling?


✏️ Learnings added
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#9859
File: src/types/emr/encounter.ts:28-37
Timestamp: 2025-01-16T12:22:40.009Z
Learning: The backend API for diet preferences uses "diary_free" (instead of "dairy_free") as one of the valid values, so the frontend must maintain the same spelling for compatibility.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, go ahead

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Member

@rithviknishad rithviknishad Jan 16, 2025

Choose a reason for hiding this comment

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

oh i was talking to you @coderabbitai

Copy link
Contributor

Choose a reason for hiding this comment

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

@coderabbitai create the issue as suggested above.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Jacobjeevan I've created issue #10029 to track updating the "diary_free" typo to "dairy_free" in both backend and frontend. You've been assigned to the issue.

🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
gh issue create \
  --title "Fix typo: Update 'diary_free' to 'dairy_free' in diet preferences" \
  --body "Currently, both the backend and frontend use 'diary_free' as one of the diet preference values, which is a typo. This should be updated to 'dairy_free'.

Required changes:
1. Update the backend API to use 'dairy_free'
2. Update the frontend constant ENCOUNTER_DIET_PREFERENCE to use 'dairy_free'

Note: Both changes need to be coordinated to maintain compatibility.

References:
- Discussion: https://github.com/ohcnetwork/care_fe/pull/9859#discussion_r1917012367
- PR: https://github.com/ohcnetwork/care_fe/pull/9859" \
  --assignee "Jacobjeevan"

Length of output: 730


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

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.

Failed to update encounters on selecting certain diet preference
3 participants