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 registration in multiple combination #10287

Merged
merged 5 commits into from
Jan 30, 2025

Conversation

nihal467
Copy link
Member

@nihal467 nihal467 commented Jan 30, 2025

Proposed Changes

  • Fixes #issue_number
  • Change 1
  • Change 2
  • More?

@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

  • Testing Improvements

    • Enhanced Cypress test suite with more robust login and authentication mechanisms
    • Improved patient creation test cases with structured data and multiple scenarios
    • Added data-cy attributes to improve test component identification
  • Patient Registration

    • Updated patient form data structure to support more detailed patient information
    • Added optional fields for permanent address and emergency contact
    • Introduced more specific types for gender and blood group selection
  • Utility Enhancements

    • Improved address generation utility with multi-line formatting option

Copy link
Contributor

coderabbitai bot commented Jan 30, 2025

Walkthrough

This pull request introduces comprehensive changes across multiple Cypress test files and related components, focusing on streamlining test setup processes, enhancing patient registration functionality, and improving test structure. The modifications primarily involve consolidating login processes into before hooks, updating patient data interfaces, refactoring test cases, and adding more robust data handling for patient creation. The changes aim to create more modular, flexible, and maintainable test suites and component interactions.

Changes

File Change Summary
cypress/e2e/facility_spec/facility_creation.cy.ts Added before hook for login, modified beforeEach to remove login step
cypress/e2e/patient_spec/patient_creation.cy.ts Restructured test cases, introduced PatientFormData, created patientTestCases array
cypress/e2e/patient_spec/patient_encounter.cy.ts Added API login before hook, simplified beforeEach hook
cypress/e2e/users_spec/user_creation.cy.ts Added API login before hook, removed login page visit
cypress/pageObject/Patients/PatientCreation.ts Enhanced PatientFormData interface, added new methods for address and contact handling
cypress/support/commands.ts Refactored loginByApi command, removed local storage token management
cypress/support/index.ts Removed awaitUrl and clearAllFilters method signatures
cypress/utils/commonUtils.ts Updated generateAddress function with multi-line address generation
src/components/Patient/PatientRegistration.tsx Added data-cy attributes to patient registration tabs

Sequence Diagram

sequenceDiagram
    participant Test as Cypress Test
    participant Login as Login Command
    participant Page as Patient Registration Page
    
    Test->>Login: Invoke loginByApi
    Login->>Page: Navigate to root URL
    Login-->>Test: Authenticate user
    Test->>Page: Visit page
    Test->>Page: Fill patient details
    Test->>Page: Submit registration
    Page-->>Test: Verify patient creation
Loading

Possibly related PRs

Suggested Labels

needs review, tested

Suggested Reviewers

  • rithviknishad

Poem

🐰 In the realm of tests, a rabbit's delight,
Hooks and pages now dance with might!
Login once, then create with glee,
Patient data flows, oh so free!
Cypress hops, the code takes flight! 🚀

✨ 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 30, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 4b4bf67
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/679b6215a3ca760008a2a41a
😎 Deploy Preview https://deploy-preview-10287--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

cloudflare-workers-and-pages bot commented Jan 30, 2025

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4b4bf67
Status: ✅  Deploy successful!
Preview URL: https://d8573122.care-fe.pages.dev
Branch Preview URL: https://cypress-patientregistration.care-fe.pages.dev

View logs

Copy link

cypress bot commented Jan 30, 2025

CARE    Run #4482

Run Properties:  status check passed Passed #4482  •  git commit 4b4bf67112: patient registration in multiple combination
Project CARE
Branch Review cypress-patientregistration
Run status status check passed Passed #4482
Run duration 05m 23s
Commit git commit 4b4bf67112: patient registration in multiple combination
Committer Mohammed Nihal
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 9
View all changes introduced in this branch ↗︎

@nihal467 nihal467 marked this pull request as ready for review January 30, 2025 11:28
@nihal467 nihal467 requested a review from a team as a code owner January 30, 2025 11:28
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: 4

🧹 Nitpick comments (5)
cypress/support/commands.ts (1)

6-7: Leverage cy.session for streamlined login flow.

Migrating from local storage reliance to cy.session is a recommended Cypress practice. It simplifies authentication handling by automatically caching sessions and reduces repeated login flows. The additional post-login check (asserting the URL doesn’t include /login) ensures the login was indeed successful.

A potential enhancement is to incorporate a check for valid user data (e.g., verifying server responses) before confirming the session is ready.

Also applies to: 18-18

cypress/pageObject/Patients/PatientCreation.ts (1)

26-27: Consider validations for region-specific fields.

state and district properties are newly introduced. If the application is region-specific, ensure these fields are validated against a known reference. Otherwise, consider a fallback or “Other” option for unknown states/districts.

cypress/e2e/patient_spec/patient_encounter.cy.ts (1)

13-14: Consider removing duplicate login calls.

Since the user is already logged in at before, calling loginByApi("devnurse") again in beforeEach might be redundant. If multiple test cases require re-initialization, a forced session refresh can be done, but do confirm necessity before doubling the login calls.

cypress/utils/commonUtils.ts (1)

Line range hint 49-74: Add input validation for address generation.

While the multi-line address support is a good addition, the function could benefit from input validation and proper string sanitization.

Consider these improvements:

 export function generateAddress(multiLine: boolean = false): string {
+  // Validate input
+  if (typeof multiLine !== 'boolean') {
+    throw new TypeError('multiLine parameter must be a boolean');
+  }
+
   const houseNumbers = ["123", "45A", "67B", "89", "234"];
   const apartments = ["Apt 4B", "Unit 12", "Flat 3A", "Suite 7", "#15"];
   const streets = [
     "Main Street",
     "Park Avenue",
     "Oak Road",
     "Church Street",
     "Hill Road",
   ];
   const areas = [
     "Downtown",
     "Westside",
     "North Colony",
     "South Extension",
     "East End",
   ];

   const randomHouse = houseNumbers[getRandomIndex(houseNumbers.length)];
   const randomApt = apartments[getRandomIndex(apartments.length)];
   const randomStreet = streets[getRandomIndex(streets.length)];
   const randomArea = areas[getRandomIndex(areas.length)];

+  // Sanitize components to prevent injection
+  const sanitize = (str: string) => str.replace(/[<>]/g, '');
+
   return multiLine
-    ? `${randomHouse} ${randomStreet}\n${randomApt}\n${randomArea}`
-    : `${randomHouse}, ${randomStreet}, ${randomArea}`;
+    ? `${sanitize(randomHouse)} ${sanitize(randomStreet)}\n${sanitize(randomApt)}\n${sanitize(randomArea)}`
+    : `${sanitize(randomHouse)}, ${sanitize(randomStreet)}, ${sanitize(randomArea)}`;
 }
cypress/e2e/patient_spec/patient_creation.cy.ts (1)

28-35: Consider extracting basePatientData to a separate test data file.

The base patient data could be moved to a separate file to improve maintainability and reusability across different test files.

Create a new file cypress/fixtures/patientTestData.ts:

export const basePatientData: Partial<PatientFormData> = {
  pincode: "682001",
  state: "Kerala",
  district: "Ernakulam",
  localBody: "Aluva",
  ward: "4",
  sameAsPermanentAddress: true,
  hasEmergencyContact: false,
};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 50cb157 and 4b4bf67.

📒 Files selected for processing (9)
  • cypress/e2e/facility_spec/facility_creation.cy.ts (1 hunks)
  • cypress/e2e/patient_spec/patient_creation.cy.ts (2 hunks)
  • cypress/e2e/patient_spec/patient_encounter.cy.ts (1 hunks)
  • cypress/e2e/users_spec/user_creation.cy.ts (1 hunks)
  • cypress/pageObject/Patients/PatientCreation.ts (6 hunks)
  • cypress/support/commands.ts (1 hunks)
  • cypress/support/index.ts (0 hunks)
  • cypress/utils/commonUtils.ts (2 hunks)
  • src/components/Patient/PatientRegistration.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • cypress/support/index.ts
✅ Files skipped from review due to trivial changes (1)
  • src/components/Patient/PatientRegistration.tsx
🧰 Additional context used
📓 Learnings (1)
cypress/e2e/facility_spec/facility_creation.cy.ts (2)
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#9145
File: cypress/e2e/facility_spec/FacilityCreation.cy.ts:177-180
Timestamp: 2024-11-18T10:44:30.303Z
Learning: In `cypress/e2e/facility_spec/FacilityCreation.cy.ts`, when testing bed and staff capacity individually for additional error verification, we prefer to use separate method calls to handle bed and staff capacity, rather than using `facilityPage.createNewFacility(testFacilityData)` which also handles bed management.
Learnt from: kihan2518B
PR: ohcnetwork/care_fe#8956
File: cypress/e2e/facility_spec/FacilityCreation.cy.ts:261-261
Timestamp: 2024-12-04T18:58:47.241Z
Learning: In `cypress/e2e/facility_spec/FacilityCreation.cy.ts`, the test case titled "Create a new facility with no bed and doctor capacity" includes steps to select bed types and specializations before validation. This is done intentionally to verify that error messages are shown properly when no capacity is specified.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (13)
cypress/support/commands.ts (2)

4-4: Use dynamic session naming for easier debugging.

Defining the session name based on the user role is a good approach for isolating cached session data, which helps improve test maintainability and debugging.


21-21: No additional changes or issues identified.

cypress/pageObject/Patients/PatientCreation.ts (9)

4-14: Strongly typed enums for patient data.

Using string literal unions for gender and bloodGroup ensures better type-safety across the codebase. Converting them to TypeScript enums or a separate constants file could further centralize these definitions if they are reused in multiple places.


16-17: Optional fields improve flexibility.

Allowing dateOfBirth or age (instead of requiring both) and introducing address/contact checkboxes provide a robust data model. Just ensure that form validations are in place to avoid partial or invalid data, especially for emergency contact details.

Also applies to: 19-22


37-56: Selector naming is consistent.

The choice of data-cy attributes and naming conventions is consistent and descriptive. This helps maintain stable locators for Cypress tests.


81-81: Verifying content presence with partial matches.

Using cy.verifyContentPresence() with Object.values() ensures coverage for relevant text in search results. Confirm that no extraneous fields appear in search results, as partial matches could pass inadvertently.


90-90: Improved data entry methods.

These lines streamline data entry for patient attributes (name, phone number, DOB, gender, blood group, address, pincode). The typed approach clarifies test intent and improves reliability. Just ensure that errors (e.g., invalid phone format) are handled or tested separately.

Also applies to: 95-95, 105-107, 114-116, 121-121, 126-126, 131-131


135-174: Comprehensive patient details workflow.

  1. Conditional handling of DOB or age prevents conflicting data sets.
  2. Toggling permanent address vs. current address (lines 149-156) is well-structured.
  3. Emergency contact logic (lines 157-167) covers both enabling and disabling the field.
  4. The final block chaining for pincode/state/district/ward ensures a single cohesive flow.

Perform thorough testing, especially around date/age edge cases and defaulting to sameAsPermanentAddress = true if not specified.


178-178: Location dropdown methods.

Using typeAndSelectOption is a good approach for dynamic dropdowns. Just make sure it handles special characters or synonyms that might appear in local bodies and wards.

Also applies to: 183-183


201-212: New address & emergency contact methods.

Implementing separate helpers (enterPermanentAddress and enterEmergencyPhone) keeps the code modular. Validate edge cases such as blank addresses or phone numbers.


214-221: Conditional state/district selection ensures minimal re-typing.

Skipping re-selection if values match the existing dropdown is an excellent performance optimization. Confirm that re-selection logic is correct when updating from an already-filled field.

Also applies to: 223-230

cypress/e2e/patient_spec/patient_encounter.cy.ts (1)

8-10: Single login before tests.

Moving the loginByApi("devnurse") call into the before hook ensures that the session is established only once and persists across the suite. This reduces repeated login overhead and speeds up the tests.

cypress/e2e/patient_spec/patient_creation.cy.ts (1)

111-137: Great test coverage for diverse patient scenarios!

The test cases effectively cover various patient types and scenarios, including non-binary, transgender, and different address combinations. This aligns well with the PR objective of handling multiple patient registration combinations.

@rithviknishad rithviknishad merged commit cdf4e46 into develop Jan 30, 2025
35 checks passed
@rithviknishad rithviknishad deleted the cypress-patientregistration branch January 30, 2025 12:41
Copy link

@nihal467 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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants