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

Patient encounter notes #9617

Merged
merged 6 commits into from
Jan 6, 2025
Merged

Patient encounter notes #9617

merged 6 commits into from
Jan 6, 2025

Conversation

bodhisha
Copy link
Collaborator

@bodhisha bodhisha commented Dec 30, 2024

Proposed Changes

  • Patient encounter notes

@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 Notes functionality for patient encounters.
    • Introduced a new "Notes" tab in encounter details.
    • Enabled creating and managing discussion threads.
    • Implemented message posting and retrieval for encounter notes.
  • Localization

    • Updated English language strings to support the new notes feature, including the addition of "Notes" under the encounter tab.
    • Enhanced localization with new keys for encounter notes discussions and messages.

These release notes highlight the addition of a comprehensive notes system for patient encounters, allowing healthcare professionals to create, view, and manage discussion threads and messages directly within the patient's encounter view.

@bodhisha bodhisha requested a review from a team as a code owner December 30, 2024 22:07
Copy link
Contributor

coderabbitai bot commented Dec 30, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces enhancements to the notes functionality in a healthcare application. Changes include updates to a localization file, the addition of new API routes for managing patient notes, and the creation of a new React component for displaying and interacting with these notes. A new tab for "EncounterNotes" is integrated into the encounter view, allowing users to manage notes effectively. TypeScript interfaces for messages and threads are also added to ensure type safety.

Changes

File Change Summary
public/locale/en.json Added new localization key ENCOUNTER_TAB__notes with value "Notes"; moved keys quantity_required, time, and time_slot; added multiple new keys related to encounter notes.
src/Utils/request/api.tsx Added new notes routes with methods for listing threads, creating threads, getting messages, and posting messages.
src/pages/Encounters/EncounterShow.tsx Integrated EncounterNotesTab into the encounter view, added it to the defaultTabs object.
src/pages/Encounters/tabs/EncounterNotesTab.tsx Created new component for managing encounter notes with thread and message interactions, utilizing React Query for state management.
src/types/notes/messages.ts Added Message interface defining the structure of a message object.
src/types/notes/threads.ts Added Thread interface defining the structure of a thread object.

Possibly related PRs

  • Add View Consultation Button #9296: The addition of the "view_consultation": "View Latest Encounter" key in the localization file relates to the main PR's changes in the public/locale/en.json file, which also involves modifications to localization strings.
  • Added no user assingned message #9666: The addition of the "no_user_assigned": "No User Assigned to this patient" key in the localization file is relevant as it also involves updates to the public/locale/en.json file, similar to the changes made in the main PR.
  • Fix: Display Modify date and i18n Localization in Patient Encounter Page #9696: The changes in the public/locale/en.json file, which include the addition of "discussion_notes": "Discussion Notes" and "encounter": "Encounter", are related to the main PR's modifications to localization strings.

Suggested labels

good to merge, tested, needs review

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

🐰 Hop, hop, through the code we go,
Notes now dance, in rows they flow
Threads and messages take their flight,
Encounter stories shining bright! 📝✨


📜 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 157307f and 38e369b.

📒 Files selected for processing (5)
  • public/locale/en.json (3 hunks)
  • src/Utils/request/api.tsx (2 hunks)
  • src/pages/Encounters/EncounterShow.tsx (2 hunks)
  • src/pages/Encounters/tabs/EncounterNotesTab.tsx (1 hunks)
  • src/types/notes/threads.ts (1 hunks)

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

cloudflare-workers-and-pages bot commented Dec 30, 2024

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 157307f
Status: ✅  Deploy successful!
Preview URL: https://f71034ed.care-fe.pages.dev
Branch Preview URL: https://encounter-notes.care-fe.pages.dev

View logs

@bodhish
Copy link
Member

bodhish commented Dec 30, 2024

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Dec 30, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Base automatically changed from form-field-v1 to develop December 31, 2024 06:36
Copy link

netlify bot commented Dec 31, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 38e369b
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/677bcb65bc1cb30008da4b85
😎 Deploy Preview https://deploy-preview-9617--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: 0

🧹 Nitpick comments (4)
src/Utils/request/api.tsx (1)

1645-1673: Add optional error handling callbacks for note-related routes.
While the new note-related routes (listThreads, createThread, getMessages, postMessage) follow the established pattern, consider adding standardized error handling (e.g., HTTP 4xx or 5xx responses) to help keep consumers of these routes informed about potential request failures.

src/pages/Encounters/tabs/EncounterNotesTab.tsx (3)

31-43: Consider a configurable skeleton item count.
For loading states, make the skeleton item count configurable or dynamic, instead of [1, 2, 3], to handle long message lists or different UI states.


67-82: Add fallback for missing or anonymized user data.
While the avatar logic is correct, consider gracefully handling a scenario where username or profile_picture_url might be absent, to avoid runtime errors or broken images.


136-373: Handle API errors for thread and message creation.
Overall, the component is well-designed with infinite scroll, thread creation, and message posting. For completeness, consider adding onError callbacks in the createThreadMutation and createMessageMutation to handle failures gracefully, e.g., showing a toast notification on error.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f968ac5 and 2765b11.

📒 Files selected for processing (6)
  • public/locale/en.json (4 hunks)
  • src/Utils/request/api.tsx (2 hunks)
  • src/pages/Encounters/EncounterShow.tsx (2 hunks)
  • src/pages/Encounters/tabs/EncounterNotesTab.tsx (1 hunks)
  • src/types/notes/messages.ts (1 hunks)
  • src/types/notes/threads.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/types/notes/messages.ts
  • src/types/notes/threads.ts
  • public/locale/en.json
  • src/pages/Encounters/EncounterShow.tsx
🔇 Additional comments (4)
src/Utils/request/api.tsx (1)

104-105: Imports are consistent and well-organized.
No issues found with these new imports.

src/pages/Encounters/tabs/EncounterNotesTab.tsx (3)

45-66: Thread item layout and style are clear.
The code snippet is straightforward. The highlighting for selected threads is intuitive. No issues.


83-127: Well-structured message rendering.
The usage of conditional classes for the sender vs. recipient is well-conceived. Optionally, you can display timestamps or message statuses here if needed.


129-134: Generic paginated response interface is a good approach.
This interface is consistent with the rest of the codebase. No issues found.

src/types/notes/threads.ts Outdated Show resolved Hide resolved
src/types/notes/messages.ts Outdated Show resolved Hide resolved
onClick={handleCreateThread}
disabled={!newThreadTitle}
>
{t("Create")}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
{t("Create")}
{t("create")}

onClick={() => setShowNewThreadForm(true)}
>
<Plus className="mr-2 h-4 w-4" />
{t("Create New Thread")}
Copy link
Member

Choose a reason for hiding this comment

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

translation keys missing in en.json, needs to be added as mentioned in Merge Checklist

Suggested change
{t("Create New Thread")}
{t("create_new_thread")}

Comment on lines 171 to 181
queryFn: async ({ pageParam = 0 }) => {
const response = await query(routes.notes.patient.getMessages, {
pathParams: {
patientId: encounter.patient.id,
threadId: selectedThread!,
},
queryParams: {
limit: String(LIMIT),
offset: String(pageParam),
},
})({ signal: new AbortController().signal });
Copy link
Member

Choose a reason for hiding this comment

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

won't we get signal from the queryFn's callbacks args itself? 🤔

Suggested change
queryFn: async ({ pageParam = 0 }) => {
const response = await query(routes.notes.patient.getMessages, {
pathParams: {
patientId: encounter.patient.id,
threadId: selectedThread!,
},
queryParams: {
limit: String(LIMIT),
offset: String(pageParam),
},
})({ signal: new AbortController().signal });
queryFn: async ({ pageParam = 0, signal }) => {
const response = await query(routes.notes.patient.getMessages, {
pathParams: {
patientId: encounter.patient.id,
threadId: selectedThread!,
},
queryParams: {
limit: String(LIMIT),
offset: String(pageParam),
},
})({ signal });

}) => (
<div
className={`relative p-3 cursor-pointer rounded-lg transition-colors ${
isSelected ? "bg-primary/10" : "hover:bg-muted"
Copy link
Member

Choose a reason for hiding this comment

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

we don't have muted color configured/defined.

Copy link
Member

Choose a reason for hiding this comment

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

Nice find

Comment on lines 67 to 81
const UserAvatar = ({ user }: { user: Message["created_by"] }) => {
const initials = user.username.charAt(0).toUpperCase();

return user.profile_picture_url ? (
<img
src={user.profile_picture_url}
alt={user.username}
className="w-8 h-8 rounded-full object-cover"
/>
) : (
<div className="w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center text-primary font-medium">
{initials}
</div>
);
};
Copy link
Member

Choose a reason for hiding this comment

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

We can reuse the existing Avatar component right?

Comment on lines 129 to 134
interface PaginatedResponse<T> {
count: number;
next: string | null;
previous: string | null;
results: T[];
}
Copy link
Member

Choose a reason for hiding this comment

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

This is already defined in src/Utils/request/types.ts, let's not redefine it

src/Utils/request/api.tsx Show resolved Hide resolved
@@ -22,6 +22,8 @@ import { EncounterUpdatesTab } from "@/pages/Encounters/tabs/EncounterUpdatesTab
import { Encounter } from "@/types/emr/encounter";
import { Patient } from "@/types/emr/newPatient";

import { EncounterNotesTab } from "./tabs/EncounterNotesTab";
Copy link
Member

Choose a reason for hiding this comment

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

switch to absolute imports

Copy link

Reminder: To add the "needs testing" label, comment "ready for testing" on this PR.

Copy link

cypress bot commented Jan 2, 2025

CARE    Run #4127

Run Properties:  status check failed Failed #4127  •  git commit 157307f2df: Patient encounter notes
Project CARE
Branch Review encounter-notes
Run status status check failed Failed #4127
Run duration 01m 41s
Commit git commit 157307f2df: Patient encounter notes
Committer Bodhisha Thomas
View all properties for this run ↗︎

Test results
Tests that failed  Failures 1
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 2
View all changes introduced in this branch ↗︎

Tests for review

Failed  cypress/e2e/public_spec/loginpage.cy.ts • 1 failed test

View Output

Test Artifacts
Login Page > should successfully login with admin credentials Test Replay Screenshots

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 (4)
src/types/notes/messages.ts (2)

3-9: Consider improving type safety for message_history

The interface looks well-structured, but the message_history property using Record<string, unknown> could be more type-safe. Consider defining a specific type for the history entries to better document and enforce the expected structure.

+interface MessageHistoryEntry {
+  timestamp: string;
+  previous_message: string;
+  updated_by: UserBase;
+}
+
 export interface Message {
   id: string;
   message: string;
-  message_history: Record<string, unknown>;
+  message_history: Record<string, MessageHistoryEntry>;
   created_by: UserBase;
   updated_by: UserBase;
 }

10-10: Remove extra newlines at end of file

Keep only one newline at the end of the file to comply with linting rules.

 }
-
-
+
🧰 Tools
🪛 eslint

[error] 10-11: Delete

(prettier/prettier)

🪛 GitHub Check: lint

[failure] 10-10:
Delete

src/types/notes/threads.ts (2)

1-4: Consider adding more thread properties for medical context.

The interface structure is clean and follows TypeScript best practices. However, for a medical notes system, consider adding these essential properties:

  • createdAt: Timestamp for when the thread was created
  • authorId: ID of the healthcare provider who created the thread
  • patientId: Reference to the associated patient
  • status: Thread state (e.g., active, archived)
  • lastUpdated: Timestamp for the latest modification

Here's a suggested enhancement:

 export interface Thread {
   id: string;
   title: string;
+  createdAt: string;
+  authorId: string;
+  patientId: string;
+  status: 'active' | 'archived';
+  lastUpdated: string;
 }

5-5: Remove extra newlines at the end of file.

 }
-
-
🧰 Tools
🪛 eslint

[error] 5-6: Delete

(prettier/prettier)

🪛 GitHub Check: lint

[failure] 5-5:
Delete

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 050a7e2 and 157307f.

📒 Files selected for processing (2)
  • src/types/notes/messages.ts (1 hunks)
  • src/types/notes/threads.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Check: lint
src/types/notes/threads.ts

[failure] 5-5:
Delete

src/types/notes/messages.ts

[failure] 10-10:
Delete

@bodhish bodhish merged commit ef4d63b into develop Jan 6, 2025
7 of 12 checks passed
@bodhish bodhish deleted the encounter-notes branch January 6, 2025 12:24
Copy link

github-actions bot commented Jan 6, 2025

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

4 participants