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 and encounter creation #9902

Merged
merged 2 commits into from
Jan 11, 2025

Conversation

nihal467
Copy link
Member

@nihal467 nihal467 commented Jan 11, 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

  • New Features

    • Added end-to-end tests for patient management, including patient creation and verification.
    • Enhanced testing capabilities with new page objects for patient-related operations.
  • Tests

    • Introduced comprehensive Cypress test suite for patient creation, verification, and encounter management.
    • Added new test utilities for generating random patient data.
  • Chores

    • Updated test infrastructure with new data attributes for improved test targeting.
    • Added new test user credentials.
    • Refactored existing test page objects and utility functions.

@nihal467 nihal467 requested a review from a team as a code owner January 11, 2025 13:57
Copy link
Contributor

coderabbitai bot commented Jan 11, 2025

Walkthrough

This pull request introduces comprehensive end-to-end testing for patient management functionality using Cypress. The changes include new test suites, page objects, and utility functions for patient creation, verification, and encounter management. The implementation adds robust testing capabilities with dynamically generated patient data, enhanced UI interaction methods, and specific data attributes for improved test targeting across various components.

Changes

File Change Summary
cypress/e2e/patient_spec/patient_creation.cy.ts New end-to-end test suite for patient management with two test cases: patient creation and verification
cypress/fixtures/users.json Added a new "doctor" user entry
cypress/pageObject/Patients/* Added/modified page objects for patient creation, dashboard, verification, and removed patient search object
cypress/support/commands.ts Enhanced Cypress commands for notification handling and dropdown interactions
cypress/utils/commonUtils.ts Added utility functions for generating patient names, addresses, and phone numbers
src/components/* Added data-cy attributes to various patient-related components for improved testability

Sequence Diagram

sequenceDiagram
    participant User
    participant LoginPage
    participant FacilitySelector
    participant PatientCreationForm
    participant PatientVerification
    participant EncounterCreation

    User->>LoginPage: Login
    LoginPage->>FacilitySelector: Select Facility
    FacilitySelector->>PatientCreationForm: Navigate to Patient Creation
    PatientCreationForm->>PatientCreationForm: Fill Patient Details
    PatientCreationForm->>PatientVerification: Submit Patient
    PatientVerification->>EncounterCreation: Create Encounter
    EncounterCreation->>PatientVerification: Verify Encounter Details
Loading

Possibly related PRs

Suggested Labels

needs review, needs testing

Suggested Reviewers

  • rithviknishad
  • Jacobjeevan

Poem

🐰 A Rabbit's Test of Patient Care
With Cypress hopping through each page,
Testing patients, stage by stage,
Clicks and types with bunny might,
Ensuring everything's just right!
Patient data, fresh and new,
Verified with a carrot or two! 🥕


📜 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 ccee044 and 5c02398.

📒 Files selected for processing (1)
  • cypress/pageObject/Patients/PatientCreation.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cypress/pageObject/Patients/PatientCreation.ts

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

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 5c02398
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67827be408fa70000806cd1f
😎 Deploy Preview https://deploy-preview-9902--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 11, 2025

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5c02398
Status: ✅  Deploy successful!
Preview URL: https://2e315e44.care-fe.pages.dev
Branch Preview URL: https://cypress-patient-creation.care-fe.pages.dev

View logs

Copy link

cypress bot commented Jan 11, 2025

CARE    Run #4256

Run Properties:  status check passed Passed #4256  •  git commit 5c0239826d: patient registration and encounter creation
Project CARE
Branch Review cypress-patient-creation
Run status status check passed Passed #4256
Run duration 02m 28s
Commit git commit 5c0239826d: patient registration and encounter creation
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 4
View all changes introduced in this branch ↗︎

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 (11)
cypress/utils/commonUtils.ts (4)

2-6: Consider adding input validation to getRandomIndex

The function should validate that max is positive and non-zero to prevent potential issues.

 function getRandomIndex(max: number): number {
+  if (max <= 0) {
+    throw new Error('max must be positive');
+  }
   const randomBytes = new Uint8Array(1);
   crypto.getRandomValues(randomBytes);
   return randomBytes[0] % max;
 }

9-34: Consider internationalizing name data

The hardcoded name arrays limit testing to English names. Consider:

  1. Moving name data to a configuration file
  2. Adding support for international names
  3. Adding more name variety for better test coverage

36-47: Improve phone number validation and formatting

The phone number generation could be enhanced:

  1. Add format validation (exactly 10 digits)
  2. Consider adding country code support
  3. Add formatting option (e.g., XXX-XXX-XXXX)
 export function generatePhoneNumber(): string {
   const validFirstDigits = [6, 7, 8, 9];
   const firstDigit = validFirstDigits[getRandomIndex(validFirstDigits.length)];

   const remainingDigits = new Uint8Array(9);
   crypto.getRandomValues(remainingDigits);
   const remainingDigitsStr = Array.from(remainingDigits)
     .map((byte) => byte % 10)
     .join("");

-  return `${firstDigit}${remainingDigitsStr}`;
+  const number = `${firstDigit}${remainingDigitsStr}`;
+  if (number.length !== 10) {
+    return generatePhoneNumber(); // Recursively try again
+  }
+  return number;
 }

49-71: Consider adding address validation and formatting options

The address generation could be improved:

  1. Add postal code generation
  2. Support international address formats
  3. Add address validation
cypress/pageObject/Patients/PatientDashboard.ts (1)

1-6: Consider adding more dashboard verification methods

The PatientDashboard class could be enhanced with methods to verify:

  1. Patient demographics
  2. Medical history
  3. Upcoming appointments
  4. Recent encounters

Example addition:

verifyPatientDemographics(demographics: {
  age?: string;
  gender?: string;
  contact?: string;
}) {
  Object.entries(demographics).forEach(([key, value]) => {
    cy.get(`[data-cy="patient-${key}"]`).should('contain', value);
  });
  return this;
}
cypress/pageObject/Patients/PatientVerify.ts (2)

24-31: Consider moving encounter types to a constants file

The encounterTypeMap should be moved to a shared constants file for reusability and maintainability.


57-60: Add timeout configuration for notification verification

Long-running operations might delay the notification. Consider adding a configurable timeout.

 assertEncounterCreationSuccess() {
-  cy.verifyNotification("Encounter created successfully");
+  cy.verifyNotification("Encounter created successfully", { timeout: 10000 });
   return this;
 }
cypress/e2e/patient_spec/patient_creation.cy.ts (2)

11-13: Move encounter constants to test fixtures.

Consider moving these hardcoded encounter values to test fixtures for better maintainability. This would make it easier to update these values if they change in the future.

-const ENCOUNTER_TYPE = "Observation";
-const ENCOUNTER_STATUS = "In Progress";
-const ENCOUNTER_PRIORITY = "ASAP";

Create a new fixture file cypress/fixtures/encounters.json:

{
  "default": {
    "type": "Observation",
    "status": "In Progress",
    "priority": "ASAP"
  }
}

15-21: Move patient test data to fixtures.

Consider moving the hardcoded patient details to test fixtures for better maintainability.

-  const TEST_PHONE = "9495031234";
-  const PATIENT_DETAILS = {
-    name: "Nihal",
-    sex: "Male",
-    phone: TEST_PHONE,
-  };

Create a new fixture file cypress/fixtures/patients.json:

{
  "default": {
    "phone": "9495031234",
    "name": "Nihal",
    "sex": "Male"
  }
}
cypress/pageObject/Patients/PatientCreation.ts (1)

17-24: Standardize selectors to use data-cy attributes.

For consistency and better maintainability, consider using data-cy attributes for all selectors instead of mixing with id selectors.

  private selectors = {
    patientsButton: '[data-cy="patients-button"]',
-   searchInput: "#patient-search",
-   patientCard: "#patient-search-results",
+   searchInput: '[data-cy="patient-search"]',
+   patientCard: '[data-cy="patient-search-results"]',
    patientName: '[data-cy="patient-name"]',
-   patientDetails: "#patient-search-results",
+   patientDetails: '[data-cy="patient-search-results"]',
    createNewPatientButton: '[data-cy="create-new-patient-button"]',
  };
src/pages/Organization/components/OrganizationSelector.tsx (1)

119-119: Make data-cy attributes more robust.

Consider these improvements for the data-cy attributes:

  1. Add null coalescing for safer access to nested properties
  2. Extract the fallback value to a constant
+const DEFAULT_ORG_TYPE = "state";

-data-cy={`select-${level.metadata?.govt_org_type?.toLowerCase()}`}
+data-cy={`select-${level.metadata?.govt_org_type?.toLowerCase() ?? DEFAULT_ORG_TYPE}`}

-data-cy={`edit-${level.metadata?.govt_org_type?.toLowerCase()}`}
+data-cy={`edit-${level.metadata?.govt_org_type?.toLowerCase() ?? DEFAULT_ORG_TYPE}`}

-data-cy={`select-${
-  lastLevel?.metadata?.govt_org_children_type?.toLowerCase() ||
-  lastLevel?.metadata?.govt_org_type?.toLowerCase() ||
-  "state"
-}`}
+data-cy={`select-${
+  lastLevel?.metadata?.govt_org_children_type?.toLowerCase() ??
+  lastLevel?.metadata?.govt_org_type?.toLowerCase() ??
+  DEFAULT_ORG_TYPE
+}`}

Also applies to: 130-130, 160-164

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1dc6138 and ccee044.

📒 Files selected for processing (16)
  • cypress/e2e/patient_spec/patient_creation.cy.ts (1 hunks)
  • cypress/e2e/patient_spec/patient_search.cy.ts (0 hunks)
  • cypress/fixtures/users.json (1 hunks)
  • cypress/pageObject/Patients/PatientCreation.ts (1 hunks)
  • cypress/pageObject/Patients/PatientDashboard.ts (1 hunks)
  • cypress/pageObject/Patients/PatientSearch.ts (0 hunks)
  • cypress/pageObject/Patients/PatientVerify.ts (1 hunks)
  • cypress/support/commands.ts (3 hunks)
  • cypress/support/index.ts (1 hunks)
  • cypress/utils/commonUtils.ts (1 hunks)
  • src/components/Encounter/CreateEncounterForm.tsx (3 hunks)
  • src/components/Patient/PatientIndex.tsx (1 hunks)
  • src/components/Patient/PatientRegistration.tsx (11 hunks)
  • src/components/ui/autocomplete.tsx (3 hunks)
  • src/pages/Organization/components/OrganizationSelector.tsx (3 hunks)
  • src/pages/Patients/VerifyPatient.tsx (2 hunks)
💤 Files with no reviewable changes (2)
  • cypress/e2e/patient_spec/patient_search.cy.ts
  • cypress/pageObject/Patients/PatientSearch.ts
✅ Files skipped from review due to trivial changes (2)
  • src/components/Patient/PatientIndex.tsx
  • src/components/Encounter/CreateEncounterForm.tsx
🧰 Additional context used
📓 Learnings (1)
cypress/e2e/patient_spec/patient_creation.cy.ts (1)
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#9145
File: cypress/e2e/patient_spec/PatientConsultationCreation.cy.ts:93-94
Timestamp: 2024-11-18T10:48:08.501Z
Learning: In `cypress/e2e/patient_spec/PatientConsultationCreation.cy.ts`, bed capacity verification assertions after patient admission are already being performed elsewhere, so adding them here is unnecessary.
🔇 Additional comments (14)
cypress/support/index.ts (1)

42-42: LGTM! Type definition improvement

The change to Chainable<JQuery<HTMLElement>> provides better type safety and clarity.

src/components/ui/autocomplete.tsx (1)

34-34: LGTM!

The addition of the data-cy attribute follows best practices for component testability.

Also applies to: 45-45, 63-63

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

1-13: LGTM!

The interface is well-structured and includes all necessary fields for the patient form.

cypress/support/commands.ts (3)

88-92: LGTM! Enhanced notification verification.

The addition of visibility check before closing notification improves test reliability.


111-123: LGTM! Improved dropdown interaction.

The restructured command provides more robust interaction with CMDK components by:

  • Ensuring dropdown is opened before typing
  • Verifying command input visibility
  • Confirming option visibility before selection

205-213: LGTM! Enhanced notification closing logic.

The improved implementation:

  • Targets specific notification structure
  • Adds timeout for element appearance
  • Verifies close button visibility
src/pages/Patients/VerifyPatient.tsx (2)

90-90: LGTM! Added test selector for patient name.

Added data-cy attribute to improve test targeting.


155-155: LGTM! Added test selector for create encounter button.

Added data-cy attribute to improve test targeting.

src/components/Patient/PatientRegistration.tsx (4)

314-314: LGTM! Added test selectors for basic information fields.

Added data-cy attributes for:

  • Patient name input
  • Phone number input
  • Same phone number checkbox

Also applies to: 341-341, 366-366


422-422: LGTM! Added test selectors for gender and blood group fields.

Added data-cy attributes for:

  • Gender radio buttons
  • Blood group select

Also applies to: 446-446


495-495: LGTM! Added test selectors for date of birth fields.

Added data-cy attributes for:

  • Day input
  • Month input
  • Year input

Also applies to: 516-516, 537-537


615-615: LGTM! Added test selectors for address and contact fields.

Added data-cy attributes for:

  • Current address input
  • Pincode input
  • Nationality input

Also applies to: 668-672, 709-709

cypress/fixtures/users.json (2)

10-13: LGTM! Added doctor user for testing.

Added test credentials for doctor role.


18-18: LGTM! Added newline at end of file.

Added missing newline at EOF.

cypress/pageObject/Patients/PatientVerify.ts Show resolved Hide resolved
cypress/pageObject/Patients/PatientVerify.ts Show resolved Hide resolved
cypress/pageObject/Patients/PatientCreation.ts Outdated Show resolved Hide resolved
@rithviknishad rithviknishad merged commit dce66bc into develop Jan 11, 2025
24 checks passed
@rithviknishad rithviknishad deleted the cypress-patient-creation branch January 11, 2025 14:21
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