-
Notifications
You must be signed in to change notification settings - Fork 532
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
Conversation
WalkthroughThis 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
Sequence DiagramsequenceDiagram
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
Possibly related PRs
Suggested Labels
Suggested Reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for care-ohc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Deploying care-fe with Cloudflare Pages
|
CARE Run #4256
Run Properties:
|
Project |
CARE
|
Branch Review |
cypress-patient-creation
|
Run status |
Passed #4256
|
Run duration | 02m 28s |
Commit |
5c0239826d: patient registration and encounter creation
|
Committer | Mohammed Nihal |
View all properties for this run ↗︎ |
Test results | |
---|---|
Failures |
0
|
Flaky |
0
|
Pending |
0
|
Skipped |
0
|
Passing |
4
|
View all changes introduced in this branch ↗︎ |
There was a problem hiding this 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 getRandomIndexThe 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 dataThe hardcoded name arrays limit testing to English names. Consider:
- Moving name data to a configuration file
- Adding support for international names
- Adding more name variety for better test coverage
36-47
: Improve phone number validation and formattingThe phone number generation could be enhanced:
- Add format validation (exactly 10 digits)
- Consider adding country code support
- 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 optionsThe address generation could be improved:
- Add postal code generation
- Support international address formats
- Add address validation
cypress/pageObject/Patients/PatientDashboard.ts (1)
1-6
: Consider adding more dashboard verification methodsThe PatientDashboard class could be enhanced with methods to verify:
- Patient demographics
- Medical history
- Upcoming appointments
- 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 fileThe encounterTypeMap should be moved to a shared constants file for reusability and maintainability.
57-60
: Add timeout configuration for notification verificationLong-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:
- Add null coalescing for safer access to nested properties
- 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
📒 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 improvementThe 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.
@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! 🙌 |
Proposed Changes
@ohcnetwork/care-fe-code-reviewers
Merge Checklist
Summary by CodeRabbit
New Features
Tests
Chores