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 Info Card #10792

Merged
merged 9 commits into from
Feb 27, 2025
Merged

Encounter Info Card #10792

merged 9 commits into from
Feb 27, 2025

Conversation

amjithtitus09
Copy link
Contributor

@amjithtitus09 amjithtitus09 commented Feb 24, 2025

@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
    • Enhanced the encounter view to dynamically fetch and display patient details, including the most recent update information when available.
    • Updated the patient details display to support a simplified, non-interactive mode that presents key organizational information clearly without extra controls.
    • Introduced a conditional rendering feature for buttons and UI elements based on the new disableButtons property in the patient info card.

@amjithtitus09 amjithtitus09 requested a review from a team as a code owner February 24, 2025 09:07
@amjithtitus09 amjithtitus09 self-assigned this Feb 24, 2025
Copy link
Contributor

coderabbitai bot commented Feb 24, 2025

Walkthrough

The changes update two patient-related components. In the EncounterQuestionnaire component, new imports and a useQuery hook are introduced to fetch encounter data conditionally using an encounterId, with the PatientInfoCard rendered upon a successful data fetch. In the PatientInfoCard component, a new optional disableButtons property is added, which alters the rendering logic for interactive elements such as the LinkDepartmentsSheet and location update button. These modifications refactor the layout and enhance component flexibility.

Changes

File Change Summary
src/.../EncounterQuestionnaire.tsx Added new imports (useQuery, PatientInfoCard, utility functions) and integrated a query-based data fetching workflow. Modified rendering to conditionally display PatientInfoCard above the QuestionnaireForm.
src/.../PatientInfoCard.tsx Introduced an optional disableButtons prop to adjust UI interactivity. Updated conditional rendering for LinkDepartmentsSheet and update button, and refactored organization badge rendering.

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

I'm a rabbit with a skip and a hop,
Celebrating code that now will never stop.
Encounter flows and patient views,
Disabled states and queries, too!
With lines of logic soft and neat,
I nibble bugs 'til they're beat!
🐰 Happy coding in every beat!


📜 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 2c7121b and 95a277d.

📒 Files selected for processing (1)
  • src/components/Patient/PatientInfoCard.tsx (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: cypress-run (1)
  • GitHub Check: Cloudflare Pages: care-fe
🔇 Additional comments (6)
src/components/Patient/PatientInfoCard.tsx (6)

62-62: New prop for conditional rendering.

The addition of disableButtons provides more flexibility for this component, allowing it to be used in contexts where the interactive elements should be hidden.


335-337: Code improvement: Extracted organization badge rendering to a separate function.

Good refactoring by extracting the organization badge rendering to a dedicated function, improving code reusability and maintainability.


397-412: Conditional rendering for location update UI elements.

The conditional rendering based on disableButtons aligns with the PR objectives to improve the UI in different contexts.


417-431: Conditional badge visibility for location addition.

Good implementation that addresses the PR objectives by conditionally showing the "Add Location" badge based on the encounter status and disableButtons prop.


442-514: Conditional rendering for update button and related UI elements.

This change improves component reusability by allowing it to be used in a read-only context.


520-535: Well-implemented helper function for organization badges.

The organizationBadge function improves code organization and allows for consistent styling of organization badges with conditional interactivity.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
  • @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

cloudflare-workers-and-pages bot commented Feb 24, 2025

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 95a277d
Status: ✅  Deploy successful!
Preview URL: https://59c4a7f0.care-fe.pages.dev
Branch Preview URL: https://encounter-info-card.care-fe.pages.dev

View logs

Copy link

netlify bot commented Feb 24, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 95a277d
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67c047a3e4b86b0008a14e98
😎 Deploy Preview https://deploy-preview-10792.preview.ohc.network
📱 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 (3)
src/pages/Encounters/EncounterInfoCard.tsx (3)

24-31: Consider adding error handling for the query.

While the loading state is handled, there's no explicit error handling for the query. Consider adding error state handling to improve user experience.

 const { data: encounter, isLoading } = useQuery({
+  const { data: encounter, isLoading, error } = useQuery({
   queryKey: ["encounter", encounterId],
   queryFn: query(routes.encounter.get, {
     pathParams: { id: encounterId },
     queryParams: { facility: facilityId },
   }),
   enabled: !!encounterId,
 });

+if (error) {
+  return <div className="text-red-500">Error loading encounter information</div>;
+}

63-78: Consider extracting Badge components to reduce duplication.

The date badges share similar structure and styling. Consider extracting them into a reusable component to improve maintainability.

+interface DateBadgeProps {
+  label: string;
+  date: string | null;
+  fallback: string;
+}
+
+function DateBadge({ label, date, fallback }: DateBadgeProps) {
+  const formattedDate = date ? formatDateTime(date) : fallback;
+  return (
+    <Badge
+      className="gap-1 rounded-sm py-1 px-2"
+      variant="primary"
+      title={`${label}: ${formattedDate}`}
+    >
+      {label}:
+      <span className="text-xs">{formattedDate}</span>
+    </Badge>
+  );
+}

-<Badge className="gap-1 rounded-sm py-1 px-2" variant="primary" title={...}>
-  {t("start_date")}:
-  <span className="text-xs">
-    {encounter.period.start ? formatDateTime(encounter.period.start) : t("not_started")}
-  </span>
-</Badge>
+<DateBadge
+  label={t("start_date")}
+  date={encounter.period.start}
+  fallback={t("not_started")}
+/>

Also applies to: 79-94


108-114: Consider using a constant for status icon mapping.

The status icon logic could be moved to a constant mapping to make it more maintainable and reusable.

+const STATUS_ICONS = {
+  completed: <CircleCheck className="w-4 h-4 text-green-300" fill="green" />,
+  default: <CircleDashed className="w-4 h-4 text-yellow-500" />
+};

-{completedEncounterStatus.includes(encounter.status) ? (
-  <CircleCheck className="w-4 h-4 text-green-300" fill="green" />
-) : (
-  <CircleDashed className="w-4 h-4 text-yellow-500" />
-)}
+{STATUS_ICONS[completedEncounterStatus.includes(encounter.status) ? 'completed' : 'default']}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7749aba and 159bfa4.

📒 Files selected for processing (3)
  • public/locale/en.json (1 hunks)
  • src/components/Patient/EncounterQuestionnaire.tsx (2 hunks)
  • src/pages/Encounters/EncounterInfoCard.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Redirect rules - care-ohc
  • GitHub Check: Header rules - care-ohc
  • GitHub Check: Pages changed - care-ohc
  • GitHub Check: Test
  • GitHub Check: OSSAR-Scan
  • GitHub Check: cypress-run (1)
🔇 Additional comments (3)
public/locale/en.json (1)

1540-1540: LGTM! New localization key added.

The new key "op_number" follows the existing naming pattern and provides a clear translation.

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

11-12: LGTM! Clean integration of EncounterInfoCard.

The component is properly imported and conditionally rendered with the required props. The implementation follows React best practices.

Also applies to: 31-33

src/pages/Encounters/EncounterInfoCard.tsx (1)

15-19: LGTM! Well-defined TypeScript interface.

The interface clearly defines the required props with appropriate types.

Comment on lines 115 to 124
{patient.blood_group && (
<Badge
className="capitalize gap-1 py-1 px-2"
variant="outline"
title={`Blood Group: ${patient.blood_group?.replace("_", " ")}`}
>
<Droplet className="w-4 h-4 text-red-300" fill="red" />
{patient.blood_group?.replace("_", " ")}
</Badge>
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider sanitizing blood group value before display.

The blood group value is directly rendered after a simple underscore replacement. Consider proper sanitization and validation.

+const sanitizeBloodGroup = (bloodGroup: string) => {
+  const validGroups = ['A+', 'A-', 'B+', 'B-', 'AB+', 'AB-', 'O+', 'O-'];
+  const formatted = bloodGroup.replace(/_/g, ' ').toUpperCase();
+  return validGroups.includes(formatted) ? formatted : 'Unknown';
+};

-{patient.blood_group?.replace("_", " ")}
+{sanitizeBloodGroup(patient.blood_group || '')}
📝 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
{patient.blood_group && (
<Badge
className="capitalize gap-1 py-1 px-2"
variant="outline"
title={`Blood Group: ${patient.blood_group?.replace("_", " ")}`}
>
<Droplet className="w-4 h-4 text-red-300" fill="red" />
{patient.blood_group?.replace("_", " ")}
</Badge>
)}
// Add the following helper function (adjust the location as needed, e.g. above the component definition)
const sanitizeBloodGroup = (bloodGroup: string) => {
const validGroups = ['A+', 'A-', 'B+', 'B-', 'AB+', 'AB-', 'O+', 'O-'];
const formatted = bloodGroup.replace(/_/g, ' ').toUpperCase();
return validGroups.includes(formatted) ? formatted : 'Unknown';
};
{patient.blood_group && (
<Badge
className="capitalize gap-1 py-1 px-2"
variant="outline"
title={`Blood Group: ${sanitizeBloodGroup(patient.blood_group || '')}`}
>
<Droplet className="w-4 h-4 text-red-300" fill="red" />
{sanitizeBloodGroup(patient.blood_group || '')}
</Badge>
)}

Copy link

cypress bot commented Feb 24, 2025

CARE    Run #4979

Run Properties:  status check passed Passed #4979  •  git commit 95a277d91c: Encounter Info Card
Project CARE
Branch Review encounter-info-card
Run status status check passed Passed #4979
Run duration 07m 01s
Commit git commit 95a277d91c: Encounter Info Card
Committer Amjith Titus
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 11
View all changes introduced in this branch ↗︎

@nihal467
Copy link
Member

image

  • when the Hospital identifier is blank, hide he badge
  • rename the OP number badge to something common, since IP/OP/emr all are recording in a single field called hospital identifier

image

  • fix the mobile view for the same

@amjithtitus09
Copy link
Contributor Author

@nihal467 Done

@nihal467
Copy link
Member

LGTM in cloudflare pages

@amjithtitus09
Copy link
Contributor Author

@nihal467 Switched to existing Patient Info Card but in disabled state
image

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 (1)
src/components/Patient/EncounterQuestionnaire.tsx (1)

59-61: Consider handling loading state

The code doesn't handle the loading state of the encounter data fetch, which could result in layout shifts.

Consider adding a loading state indicator:

          <div className="flex flex-col justify-between gap-2 px-4 py-1 md:flex-row">
            <div className="font-base flex flex-col text-xs leading-relaxed text-secondary-700 md:text-right">
              <div className="flex items-center">
                <span className="text-secondary-900">
                  {t("last_modified")}:{" "}
                </span>
                &nbsp;
-                {formatDateTime(encounter.modified_date)}
+                {encounter.modified_date ? formatDateTime(encounter.modified_date) : t("loading")}
              </div>
            </div>
          </div>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0bda5f7 and cffe719.

📒 Files selected for processing (2)
  • src/components/Patient/EncounterQuestionnaire.tsx (2 hunks)
  • src/components/Patient/PatientInfoCard.tsx (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Redirect rules - care-ohc
  • GitHub Check: Header rules - care-ohc
  • GitHub Check: Pages changed - care-ohc
  • GitHub Check: cypress-run (1)
🔇 Additional comments (11)
src/components/Patient/EncounterQuestionnaire.tsx (4)

1-15: Import structure looks good

The new imports are well organized and properly support the functionality being added to fetch and display encounter data.


33-40: Good implementation of conditional data fetching

The useQuery hook is properly implemented with appropriate query key, function, and conditional enabling based on encounter ID availability.


43-65: PatientInfoCard implementation aligns with PR objectives

This implementation properly addresses the "Encounter Info Card" requirement from the PR objectives. The disabled state prevents interaction while displaying relevant encounter data.


66-87: Layout structure looks good

The nested Card component with the QuestionnaireForm is properly structured within the flex container.

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

56-63: Good type import and interface update

The FacilityOrganization type import and adding the optional disabled property to the interface are appropriate changes.


66-66: Appropriate default value for disabled prop

Setting the default value of disabled to false ensures backward compatibility with existing code.


328-357: Implements hospital identifier badge hiding requirement

This conditional rendering implementation fulfills the PR objective of hiding empty hospital identifier badges, as part of the broader implementation of a disabled state.


405-420: Good conditional rendering of interactive elements

The location update button is properly conditionally rendered based on the disabled state.


447-519: Proper implementation of update actions conditional rendering

Preventing update actions when the component is in disabled state is consistent with the PR requirements.


525-540: Good extraction of organization badge rendering logic

Extracting the organizationBadge function improves code organization and maintainability.


532-532: Good cursor styling based on disabled state

The cursor styling is appropriately conditional based on the disabled state.

@amjithtitus09 amjithtitus09 added reviewed reviewed by a core member and removed needs review labels Feb 26, 2025
@nihal467
Copy link
Member

image

  • When we're clicking the add location button in the info card, it triggers the browser warning message

@nihal467 nihal467 added changes required and removed needs testing reviewed reviewed by a core member labels Feb 27, 2025
@amjithtitus09
Copy link
Contributor Author

@nihal467 Removed the Add Location button

@amjithtitus09 amjithtitus09 added needs testing reviewed reviewed by a core member and removed changes required labels Feb 27, 2025
@nihal467
Copy link
Member

LGTM

@bodhish bodhish merged commit 9b82db3 into develop Feb 27, 2025
25 checks passed
@bodhish bodhish deleted the encounter-info-card branch February 27, 2025 12:44
Copy link

@amjithtitus09 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
Labels
reviewed reviewed by a core member tested
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants