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

Disable encounter create during save #9795

Merged
merged 3 commits into from
Jan 6, 2025

Conversation

bodhish
Copy link
Member

@bodhish bodhish commented Jan 6, 2025

This pull request includes changes to the CreateEncounterForm component to improve the user experience by providing feedback during form submission.

User experience improvements:

…tiple components

- Added `encounterId` prop to `ObservationChart`, `ObservationHistoryTable`, `ObservationsList`, `QuestionnaireResponsesList`, and `StructuredResponseView` components to improve data fetching and display related to specific encounters.
- Updated query parameters in API calls to include `encounterId` for better data context.
- Refactored `EncounterPlotsTab` and `EncounterUpdatesTab` to pass the new `encounterId` prop, ensuring consistent data handling across the application.

This change improves the overall functionality and user experience by ensuring that encounter-specific data is accurately retrieved and displayed.
@bodhish bodhish requested a review from a team as a code owner January 6, 2025 13:55
Copy link
Contributor

coderabbitai bot commented Jan 6, 2025

Walkthrough

The pull request introduces comprehensive changes to encounter-related components across multiple files. The primary focus is on integrating encounterId as a new parameter in various components, enabling more precise data fetching and rendering of encounter-specific information. Components like ObservationChart, ObservationHistoryTable, and StructuredResponseView have been updated to include this new parameter. Additionally, the CreateEncounterForm and EncounterUpdatesTab components received structural modifications to improve user interaction and component layout.

Changes

File Change Summary
src/components/Common/Charts/ObservationChart.tsx Added encounterId to props, query key, and query parameters; updated component signature
src/components/Common/Charts/ObservationHistoryTable.tsx Added encounterId to props interface
src/components/Encounter/CreateEncounterForm.tsx Added isPending state to mutation hook; updated form submission button
src/components/Facility/ConsultationDetails/ObservationsList.tsx Replaced pagination with infinite scrolling mechanism
src/components/Facility/ConsultationDetails/QuestionnaireResponsesList.tsx Modified encounterId parameter passing
src/components/Facility/ConsultationDetails/StructuredResponseView.tsx Added encounterId to props and query configuration
src/pages/Encounters/tabs/EncounterPlotsTab.tsx Added encounterId prop to ObservationVisualizer
src/pages/Encounters/tabs/EncounterUpdatesTab.tsx Restructured component props and layout

Sequence Diagram

sequenceDiagram
    participant User
    participant CreateEncounterForm
    participant API
    participant ObservationVisualizer
    
    User->>CreateEncounterForm: Submit encounter
    CreateEncounterForm->>API: Create encounter
    API-->>CreateEncounterForm: Return encounter ID
    CreateEncounterForm->>ObservationVisualizer: Pass encounter ID
    ObservationVisualizer->>API: Fetch observations with encounter ID
    API-->>ObservationVisualizer: Return encounter-specific observations
Loading

Possibly related PRs

Suggested labels

needs review, tested, changes required

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

🐰 Encounter's tale, a code so bright,
With encounterId in perfect sight,
Scrolling smooth, data precise,
Components dance, oh so nice!
A rabbit's code, a joyful flight! 🚀


📜 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 7c58703 and 7ffc0bd.

📒 Files selected for processing (8)
  • src/components/Common/Charts/ObservationChart.tsx (4 hunks)
  • src/components/Common/Charts/ObservationHistoryTable.tsx (3 hunks)
  • src/components/Encounter/CreateEncounterForm.tsx (2 hunks)
  • src/components/Facility/ConsultationDetails/ObservationsList.tsx (2 hunks)
  • src/components/Facility/ConsultationDetails/QuestionnaireResponsesList.tsx (2 hunks)
  • src/components/Facility/ConsultationDetails/StructuredResponseView.tsx (2 hunks)
  • src/pages/Encounters/tabs/EncounterPlotsTab.tsx (1 hunks)
  • src/pages/Encounters/tabs/EncounterUpdatesTab.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages: care-fe
🔇 Additional comments (20)
src/pages/Encounters/tabs/EncounterUpdatesTab.tsx (3)

8-11: Proactively handle missing encounter or patient data.
While destructuring props is neat, consider how this component might behave if encounter or patient is undefined or null. Defensively handle these cases to avoid rendering errors.


13-20: Consistent use of utility classes.
Using gap-4 throughout maintains a consistent layout. This is good for readability and maintainability.


28-30: Ensure correct prop usage for forms.
QuestionnaireResponsesList references encounter directly. Confirm that any changes to the encounter shape in upstream code won’t break partial usage or generate runtime errors.

src/pages/Encounters/tabs/EncounterPlotsTab.tsx (1)

58-58: Prop forwarding for encounterId.
Including the encounterId in the ObservationVisualizer ensures appropriate scoping of data. This is consistent with the approach in other files—nice work!

src/components/Facility/ConsultationDetails/StructuredResponseView.tsx (3)

19-19: New prop encounterId.
Adding encounterId to the props broadens the component’s utility for encounter-specific data. This is a logical step for narrowing down relevant records.


22-27: Validate required props.
Consider scenarios where encounterId could be missing or empty. If an encounter is not yet created or loaded, you might need fallback logic or a guard clause.


35-47: Explicit queryParams usage.
Explicitly passing encounter as a query param is a clear design choice. Verify that the backing API endpoint behaves gracefully if encounter is invalid or if no matching records exist.

src/components/Facility/ConsultationDetails/ObservationsList.tsx (3)

1-4: Switch to infinite query approach.
Using useInfiniteQuery with useInView is a solid strategy for loading more data on demand. This significantly improves UX compared to manual pagination.


11-13: API layer abstraction check.
Imports from the local query utility and custom route definitions suggest you rely on stable endpoints. Ensure continuous alignment with the API contract to prevent breakages.


68-78: No data state.
A distinct empty state is a best practice. Nicely done.

src/components/Common/Charts/ObservationHistoryTable.tsx (2)

31-31: Good addition of encounterId prop.

Adding the encounterId field to the interface improves specificity in retrieving observations. This aligns with the rest of the code changes that allow for more precise data filtering.


49-49: Destructure encounterId carefully.

Ensure that any parent component passing encounterId does so consistently, and consider whether it should be optional if certain workflows do not require filtering by encounter.

src/components/Facility/ConsultationDetails/QuestionnaireResponsesList.tsx (2)

152-154: Passing encounterId via query props.

Revising the code to pass encounterId in the query object (instead of path params) looks correct. Verify parent components do not rely on the old path-based pattern; otherwise, the query might break where encounterId is expected in path params.


269-269: Ensure encounterId usage in StructuredResponseView.

Passing encounterId to StructuredResponseView is consistent with the rest of the application’s approach to encounter-specific data. Confirm that the StructuredResponseView handles it properly, particularly if encounterId is optional in some edge cases.

src/components/Encounter/CreateEncounterForm.tsx (2)

148-148: Use of isPending in the mutation.

This is a clean approach for tracking the ongoing mutation state. It helps prevent duplicate submissions and improves user experience. Double-check if there are alternative states (isLoading, isSuccess) that should also affect UI behavior.


321-322: Disable submit button during creation.

Disabling the button while showing “Creating...” prevents duplicate submissions and clearly communicates the in-progress state. This aligns well with best practices for form submissions.

src/components/Common/Charts/ObservationChart.tsx (4)

54-54: New encounterId prop.

Requiring encounterId formalizes the component’s usage and ensures the correct contextual data is loaded. If some use cases don’t require an encounter scope, consider making it optional or providing a default.


102-102: Include encounterId in destructuring.

Destructuring the new prop is straightforward. Make sure this property is always provided by the parent. If not, re-check the TypeScript interface or consider default handling for undefined values.


118-120: Pass encounterId as query param.

Adding encounter to queryParams helps the API limit data to a specific encounter scope. Potential fallback logic might be needed if encounterId is absent (for example, historical or unsaved data).


389-389: Provide encounterId to ObservationHistoryTable.

Continuing the consistent usage of encounterId across components is a good practice. Double-check that ObservationHistoryTable handles scenarios where encounterId could be missing or invalid.


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

Deploy Preview for care-ohc ready!

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

cypress bot commented Jan 6, 2025

CARE    Run #4168

Run Properties:  status check failed Failed #4168  •  git commit 7ffc0bd035: Disable encounter create during save
Project CARE
Branch Review fix/9794-disable-encounter-create-during-save
Run status status check failed Failed #4168
Run duration 01m 46s
Commit git commit 7ffc0bd035: Disable encounter create during save
Committer Bodhish 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 3
View all changes introduced in this branch ↗︎

Tests for review

Failed  cypress/e2e/patient_spec/patient_search.cy.ts • 1 failed test

View Output

Test Artifacts
Patient Search > search patient with phone number and verifies details Test Replay Screenshots

Copy link

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: dfef85b
Status:⚡️  Build in progress...

View logs

@bodhish bodhish merged commit b208351 into develop Jan 6, 2025
6 of 12 checks passed
@bodhish bodhish deleted the fix/9794-disable-encounter-create-during-save branch January 6, 2025 13:59
Copy link

github-actions bot commented Jan 6, 2025

@bodhish 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! 🙌

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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 1

🧹 Nitpick comments (9)
src/pages/Encounters/tabs/EncounterUpdatesTab.tsx (2)

23-25: Align naming with domain.
The naming here is consistent with the concept of Diagnoses. If expansions or additional domain concepts are introduced, ensure it remains well-organized (e.g., separate sections or tabs).


32-36: Observation viewing block.
This column-based layout is a good approach for separating observation rendering from other sections. Keep an eye on performance if the ObservationsList grows large, and consider lazy loading or virtualization if needed.

src/components/Facility/ConsultationDetails/StructuredResponseView.tsx (1)

57-58: Broad query key usage.
The query key uses [type, id], plus path/queryParams. This is typically fine, but be aware that if encounterId changes while type and id remain the same, you may need to invalidate or refetch.

src/components/Facility/ConsultationDetails/ObservationsList.tsx (4)

18-19: Hard-coded paging limit.
LIMIT = 20 is clear, but consider externalizing it or making it configurable, so it can be more easily adjusted based on performance or design needs.


30-50: Comprehensive concurrency and error handling.
The infinite query approach is well-configured. Just ensure you handle partial loads or re-fetch logic after errors (e.g., if an error occurs mid-fetch).

Would you like help creating a more robust error recovery flow in case the query fails?


52-56: fetchNextPage trigger.
This effect properly checks inView and hasNextPage. This is a good location-based approach. Consider a small margin threshold if you have tall items and want early pre-loading.


58-66: Dedicated loading state.
Clear and user-friendly. That said, if you handle partial loads, you might want to differentiate initial load from subsequent fetches.

src/components/Common/Charts/ObservationHistoryTable.tsx (1)

62-62: Filter observations by encounter.

Including encounter in queryParams is a clear, flexible way to fetch encounter-scoped observations. Verify that downstream logic handles scenarios where the specified encounter might not exist or return no data.

src/components/Common/Charts/ObservationChart.tsx (1)

113-113: Add encounterId to queryKey.

Inserting encounterId into the query key is consistent with the approach to ensure a unique cache entry per encounter. Confirm that this does not inadvertently invalidate caches used elsewhere.

🛑 Comments failed to post (1)
src/components/Facility/ConsultationDetails/ObservationsList.tsx (1)

81-118: 🛠️ Refactor suggestion

Infinite scroll rendering.
Displaying observations in an auto-scrolling container is well-structured. For large data sets, consider virtualization strategies to further optimize performance (e.g., React Window or similar).

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

Successfully merging this pull request may close these issues.

1 participant