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 Questionnaire: Org Access #10988

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

Conversation

Jacobjeevan
Copy link
Contributor

@Jacobjeevan Jacobjeevan commented Mar 3, 2025

Proposed Changes

  • Added route to render patient questionnaire (accessing from org)
    • Allowing roles like volunteers to submit questionnaires for patient
  • Added button under patient updates tab that points to said route
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 dedicated patient questionnaire page accessible via a new navigation route.
    • Added a direct-access button in the questionnaire responses list for navigating to different questionnaire pages based on facility.
    • Enhanced user messaging with new localized instructions for actions requiring an active encounter.
  • Refactor

    • Improved form handling by making certain context fields optional for greater flexibility.
    • Integrated dynamic translations for improved internationalization within the application.
  • Bug Fixes

    • Adjusted navigation logic to ensure proper handling of identifiers before proceeding to updates.
  • Chores

    • Removed the Updates component from the patient details tab, streamlining the interface.

Copy link
Contributor

coderabbitai bot commented Mar 3, 2025

Walkthrough

This pull request introduces new localization keys and a new route to enhance questionnaire functionality. It updates several components by making the facilityId property optional and integrating internationalization for user-facing strings. A new button is added to navigate directly to a patient-specific questionnaire. Additionally, control flow logic is adjusted to conditionally proceed based on the presence of both encounterId and facilityId.

Changes

File(s) Change Summary
public/locale/en.json Added localization keys: "add_another", "questionnaire_diagnosis_no_encounter", "questionnaire_medication_request_no_encounter", "questionnaire_medication_statement_no_encounter", "questionnaire_no_encounter", "questionnaire_symptom_no_encounter".
src/Routers/routes/ConsultationRoutes.tsx Added a new route "/patient/:patientId/questionnaire" that renders the EncounterQuestionnaire component with patientId and a static subjectType of "patient". Updated existing routes to include subjectType="encounter".
src/components/Patient/EncounterQuestionnaire.tsx Updated the facilityId in the Props interface from required to optional; adjusted usage in useQuery and the onSubmit function to require both encounterId and facilityId.
src/components/Patient/PatientDetailsTab/patientUpdates.tsx Removed the Updates component and introduced a new button component to navigate to the patient questionnaire page.
src/components/Questionnaire/QuestionRenderer.tsx,
src/components/Questionnaire/QuestionTypes/QuestionGroup.tsx,
src/components/Questionnaire/QuestionnaireForm.tsx
Modified the facilityId property from required to optional in their respective interfaces.
src/components/Questionnaire/QuestionTypes/QuestionInput.tsx Changed facilityId to optional, added useTranslation for internationalization of messages and labels, and updated the conditional logic for rendering the EncounterQuestion component.
src/components/Facility/ConsultationDetails/QuestionnaireResponsesList.tsx Introduced a new facilityId prop, removed the encounter prop, and updated the query function to include subject_type set to "patient".

Possibly related PRs

Suggested labels

needs review, needs testing

Suggested reviewers

  • rithviknishad

Poem

I’m hopping through the code with glee,
Adding keys and routes so free.
Localization carrots to boost the view,
Routes and updates blend anew.
With optional fields and translated art,
I nibble bugs and hop to heart.
Cheers from a rabbit in the code mart! 🐰


📜 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 51a76ef and 587d823.

📒 Files selected for processing (3)
  • src/components/Facility/ConsultationDetails/QuestionnaireResponsesList.tsx (5 hunks)
  • src/components/Patient/PatientDetailsTab/index.tsx (1 hunks)
  • src/components/Patient/PatientDetailsTab/patientUpdates.tsx (0 hunks)
💤 Files with no reviewable changes (1)
  • src/components/Patient/PatientDetailsTab/patientUpdates.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (7)
src/components/Patient/PatientDetailsTab/index.tsx (1)

34-34: Component replacement looks good

The change from Updates to QuestionnaireResponsesList aligns with the PR objective of enhancing patient questionnaire functionality.

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

3-3: Added necessary imports for routing

The import additions for Link and useQueryParams support the new routing functionality needed for organizational access to questionnaires.


8-11: UI component imports added correctly

The imports for CareIcon and Button are properly added to support the new UI elements in the component.


31-31: Interface update for optional facilityId

Making facilityId optional in the Props interface appropriately supports the dual-use case of this component - both for facility contexts and standalone patient contexts.


301-301: Component parameter aligned with interface

The component parameter is correctly updated to include the optional facilityId, matching the Props interface definition.


318-318: Query parameter logic change

Changed from using encounter ID to using "patient" as the subject_type. This change seems to support the organizational access use case by focusing on the patient rather than a specific encounter.


328-344: Good implementation of the new UI header with conditional routing

The added header section with the "Add Patient Updates" button implements the key functionality needed for this PR. The conditional routing correctly directs users to either a facility-specific or patient-specific questionnaire route based on the presence of facilityId.

The i18n integration is properly implemented with the use of the translation function.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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

netlify bot commented Mar 3, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 587d823
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67c94d209ec87700078d02f4
😎 Deploy Preview https://deploy-preview-10988.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

🔭 Outside diff range comments (1)
src/components/Questionnaire/QuestionTypes/QuestionGroup.tsx (1)

104-115: 💡 Verification agent

🧩 Analysis chain

Verify that QuestionInput component handles optional facilityId

The QuestionGroup component passes the potentially undefined facilityId to QuestionInput. Ensure that QuestionInput has also been updated to handle an optional facilityId.


🏁 Script executed:

#!/bin/bash
# Check if QuestionInput has been updated to handle optional facilityId

# Check the QuestionInput interface definition
rg -A 10 "interface QuestionInputProps" "src/components/Questionnaire/QuestionTypes/QuestionInput.tsx"

# Check for any direct usage of facilityId without optional chaining or checks
rg "facilityId\." "src/components/Questionnaire/QuestionTypes/QuestionInput.tsx"

Length of output: 494


Action Required: Update QuestionInput to Handle Optional facilityId

  • The QuestionGroup passes a facilityId prop which is potentially undefined, but the QuestionInput props (as defined in src/components/Questionnaire/QuestionTypes/QuestionInput.tsx) do not include a facilityId property.
  • Please update the QuestionInputProps interface to include an optional facilityId (e.g., facilityId?: string) and ensure that any internal usage within QuestionInput safely handles cases where it might be undefined.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d04d47a and d5d2051.

📒 Files selected for processing (8)
  • public/locale/en.json (2 hunks)
  • src/Routers/routes/ConsultationRoutes.tsx (1 hunks)
  • src/components/Patient/EncounterQuestionnaire.tsx (3 hunks)
  • src/components/Patient/PatientDetailsTab/patientUpdates.tsx (2 hunks)
  • src/components/Questionnaire/QuestionRenderer.tsx (1 hunks)
  • src/components/Questionnaire/QuestionTypes/QuestionGroup.tsx (1 hunks)
  • src/components/Questionnaire/QuestionTypes/QuestionInput.tsx (8 hunks)
  • src/components/Questionnaire/QuestionnaireForm.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (16)
src/Routers/routes/ConsultationRoutes.tsx (1)

90-92: New route successfully implements organization access to patient questionnaire

This new route allows direct access to a patient's questionnaire by only providing the patient ID, without requiring a facility ID. This aligns perfectly with the PR objective of enabling organizational roles (like volunteers) to submit questionnaires on behalf of patients.

src/components/Questionnaire/QuestionnaireForm.tsx (2)

59-59: Good change: Making facilityId optional improves component flexibility

Making the facilityId property optional is a necessary change to support the new organization access route where a facility ID may not be available.


266-266:

✅ Verification successful

Verify potential issue with undefined facilityId in context object

When facilityId is made optional, we need to ensure the code handles the case when it's undefined. On line 266, you're creating a context object with facilityId without checking if it exists. While this might work (as undefined values in objects are valid), it could lead to unexpected behavior in the structured data requests if they expect facilityId to be defined.


🏁 Script executed:

#!/bin/bash
# Check how structured data requests handle undefined facilityId

# Look for usage of facilityId in structured request handlers
rg -A 5 "facilityId" "src/components/Questionnaire/structured/handlers.ts"

# Check for existence of null/undefined checks in the getStructuredRequests function
rg -A 10 "getStructuredRequests" "src/components/Questionnaire/structured/handlers.ts"

Length of output: 1334


Review Verification: facilityId Handling Confirmed
The context object in QuestionnaireForm.tsx (line 266) passes facilityId without an explicit check, but downstream code in src/components/Questionnaire/structured/handlers.ts properly validates it. The getRequests function checks for a falsy facilityId and throws an error ("Cannot create encounter without a facility") if it is missing. This confirms that the current implementation is intentional and correctly prevents unexpected behavior from an undefined facilityId.

src/components/Questionnaire/QuestionRenderer.tsx (1)

32-32: Making facilityId optional maintains consistency with parent components

Making the facilityId property optional in QuestionRendererProps is consistent with the changes made to other components in the questionnaire flow. This allows the component to be used in contexts where a facility ID is not available, such as when accessed from an organization route.

src/components/Questionnaire/QuestionTypes/QuestionGroup.tsx (1)

29-29: Making facilityId optional maintains consistency across component hierarchy

Making the facilityId property optional in QuestionGroupProps is consistent with changes to parent components. This ensures that the entire questionnaire component hierarchy can handle cases where a facility ID is not provided.

src/components/Patient/PatientDetailsTab/patientUpdates.tsx (2)

2-2: Added necessary imports for the new button component.

The imports for Link from raviger and Button from the UI components are correctly added to support the new functionality.

Also applies to: 9-9


45-50: Well-implemented button for patient questionnaire access.

This button addition implements the PR objective of providing organizational roles access to submit questionnaires on behalf of patients. The button:

  • Uses proper styling with variant="outline_primary"
  • Includes an appropriate icon for visual cues
  • Uses a translation key for internationalization
  • Links directly to the patient-specific questionnaire route

The placement next to the updates header is appropriate and maintains the UI's visual balance.

src/components/Questionnaire/QuestionTypes/QuestionInput.tsx (5)

1-2: Added internationalization support.

Properly imported and implemented the useTranslation hook to support internationalization within the component.

Also applies to: 59-59


44-44: Made facilityId optional to support the organizational access route.

Changed facilityId from required to optional, which is consistent with the PR objectives to support access from organizational routes where a facility ID might not be present.


130-130: Replaced hardcoded strings with translation keys.

All user-facing error messages have been properly internationalized:

  • Medication request errors
  • Medication statement errors
  • Symptom errors
  • Diagnosis errors
  • General encounter errors

This ensures consistent messaging across the application and supports multilingual users.

Also applies to: 143-144, 158-158, 165-165, 178-178


169-169: Updated conditional logic for encounter question rendering.

The condition now correctly checks for both encounterId AND facilityId before rendering the EncounterQuestion component. This ensures that the component only renders when all required data is available.


264-264: Internationalized button text.

Replaced the hardcoded "Add Another" text with a translation key, maintaining consistency with the internationalization approach throughout the component.

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

18-18: Made facilityId optional in the Props interface.

This change supports the PR objective of allowing organizational roles to access the questionnaire functionality, where a facilityId might not always be available.


75-81: Enhanced navigation logic based on available data.

The conditional navigation now properly handles both cases:

  1. When both encounterId and facilityId are available - navigates to the encounter-specific updates
  2. When either is missing - navigates to the general patient updates

This dual-path approach supports the organizational access feature while maintaining backward compatibility.

public/locale/en.json (2)

288-288: Added translation key for "Add Another" button.

New translation key supports the internationalization of the interface element.


1889-1893: Added error message translations for encounter-related validations.

Added well-named translation keys with clear, informative messages for encounter-related validation:

  • Diagnosis validation
  • Medication request validation
  • Medication statement validation
  • General encounter validation
  • Symptom validation

These messages help users understand why certain actions require an active encounter, improving the overall user experience.

Also applies to: 1897-1897

@Jacobjeevan Jacobjeevan mentioned this pull request Mar 4, 2025
6 tasks
@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Mar 4, 2025
Copy link

github-actions bot commented Mar 4, 2025

Conflicts have been detected against the base branch. Please merge the base branch into your branch.
cc: @Jacobjeevan

See: https://docs.ohc.network/docs/contributing#how-to-resolve-merge-conflicts

@khavinshankar khavinshankar added reviewed reviewed by a core member needs testing merge conflict pull requests with merge conflict and removed merge conflict pull requests with merge conflict needs testing needs review labels Mar 4, 2025
@nihal467
Copy link
Member

nihal467 commented Mar 5, 2025

image
image

  • Hide the "Patient Type Questionnaire" within the "Questionnaire" dropdown inside an encounter.

image

  • when we are trying to submit a questionnaire in the patient profile page, the API is throwing an error, mentioning the resource id is missing

@nihal467 nihal467 added test failed and removed needs testing reviewed reviewed by a core member labels Mar 5, 2025
@github-actions github-actions bot removed the merge conflict pull requests with merge conflict label Mar 5, 2025
@nihal467
Copy link
Member

nihal467 commented Mar 5, 2025

image

  • add preview of the submitted data, otherwise users wont be able to view them post submission

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