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

Cypress: Patient Prescription Management #10740

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions cypress/e2e/patient_spec/patient_prescription.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { PatientEncounter } from "@/pageObject/Patients/PatientEncounter";
import { FacilityCreation } from "@/pageObject/facility/FacilityCreation";

const facilityCreation = new FacilityCreation();
const patientEncounter = new PatientEncounter();

describe("Patient Prescription Management", () => {
beforeEach(() => {
cy.loginByApi("devnurse");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cy.loginByApi("devnurse");
cy.loginByApi("devnurse");
  • create a new user and update it in fixtures then use that id here

cy.visit("/");
});

it("should add a new medicine for the patient", () => {
facilityCreation.selectFacility("GHC payyanur");
const medicineName = "Senna 15 mg oral tablet";
const dosage = 6;
const frequency = "BID (1-0-1)";
const instructions = "Until symptoms improve";
const route = "Sublabial route";
const site = "Structure of left deltoid muscle";
const method = "Bathe";
const notes = "testing notes";
patientEncounter
.navigateToEncounters()
.openFirstEncounterDetails()
.clickMedicinesTab()
.clickEditPrescription()
.addMedication(
medicineName,
dosage,
frequency,
instructions,
route,
site,
method,
notes,
Copy link
Member

@nihal467 nihal467 Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
notes,
notes,
  • verify that the added medicine is reflected properly in the medicine module,
  • Verify the success notification and API request

);
});
it("should delete prescription", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • don't create a separate test, combine this with the above test itself

facilityCreation.selectFacility("GHC payyanur");

patientEncounter
.navigateToEncounters()
.openFirstEncounterDetails()
.clickMedicinesTab()
.clickEditPrescription()
.removeMedication();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.removeMedication();
.removeMedication();

once the medicine is removed, verify that the changes in the relevant module is verified

});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add validation for medication removal.

The deletion test should verify that the medication was actually removed.

 it("should delete prescription", () => {
   facilityCreation.selectFacility("GHC payyanur");
+  const medicineName = "Senna 15 mg oral tablet";
+  
+  // First add a medication to ensure we have something to delete
+  patientEncounter
+    .navigateToEncounters()
+    .openFirstEncounterDetails()
+    .clickMedicinesTab()
+    .clickEditPrescription()
+    .addMedication(medicineName, 6, "BID (1-0-1)", "", "", "", "", "");
 
   patientEncounter
     .navigateToEncounters()
     .openFirstEncounterDetails()
     .clickMedicinesTab()
     .clickEditPrescription()
-    .removeMedication();
+    .removeMedication()
+    .verifyMedicationRemoved(medicineName);
 });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("should delete prescription", () => {
facilityCreation.selectFacility("GHC payyanur");
patientEncounter
.navigateToEncounters()
.openFirstEncounterDetails()
.clickMedicinesTab()
.clickEditPrescription()
.removeMedication();
});
it("should delete prescription", () => {
facilityCreation.selectFacility("GHC payyanur");
const medicineName = "Senna 15 mg oral tablet";
// First add a medication to ensure we have something to delete
patientEncounter
.navigateToEncounters()
.openFirstEncounterDetails()
.clickMedicinesTab()
.clickEditPrescription()
.addMedication(medicineName, 6, "BID (1-0-1)", "", "", "", "", "");
patientEncounter
.navigateToEncounters()
.openFirstEncounterDetails()
.clickMedicinesTab()
.clickEditPrescription()
.removeMedication()
.verifyMedicationRemoved(medicineName);
});

});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add more test scenarios for comprehensive coverage.

The test suite should include additional scenarios:

  1. Editing an existing medication
  2. Adding multiple medications
  3. Error handling for invalid inputs
  4. Validation of required fields
it("should edit an existing medication", () => {
  // Add test for editing medication
});

it("should validate required fields", () => {
  // Add test for field validation
});

it("should handle invalid inputs gracefully", () => {
  // Add test for error scenarios
});

49 changes: 49 additions & 0 deletions cypress/pageObject/Patients/PatientEncounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,56 @@ export class PatientEncounter {
.click();
return this;
}
clickMedicinesTab() {
cy.verifyAndClickElement('[data-cy="tab-medicines"]', "Medicines");
return this;
}
clickEditPrescription() {
cy.verifyAndClickElement('[data-cy="edit-prescription"]', "Edit");
return this;
}
addMedication(
medicineName,
dosage,
frequency,
instructions,
route,
site,
method,
notes,
) {
cy.get('[data-cy="question-medication-request"]').click();
cy.get('[role="listbox"]')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cy.get('[role="listbox"]')
cy.get('[role="listbox"]')

check already existing command function to interact with dropdown, replace every usage with command function

.find('[role="option"]')
.contains(medicineName)
.click();
cy.get('input[inputmode="numeric"]').should("exist").type(dosage);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • use proper id
  • use existing command function for this

cy.get('[data-cy="frequency"]').click();
cy.get('[role="option"]').contains(frequency).click();
cy.contains("Select additional instructions").click();
cy.get('[role="listbox"]')
.find('[role="option"]')
.contains(instructions)
.click();
cy.contains("Select route").click();
cy.get('[role="listbox"]').find('[role="option"]').contains(route).click();
cy.contains("Select site").click();
cy.get('[role="listbox"]').find('[role="option"]').contains(site).click();
cy.contains("Select method").click();
cy.get('[role="listbox"]').get('[role="option"]').contains(method).click();
cy.get('[data-cy="notes"]').click();
cy.get('[data-cy="notes-textarea"]').type(notes);

this.clickSubmitQuestionnaire();
this.verifyQuestionnaireSubmission();
return this;
}
removeMedication() {
cy.get('[data-cy="medication-remove"]').first().click();
cy.verifyAndClickElement('[data-cy="confirm-remove-medication"]', "Remove");
this.clickSubmitQuestionnaire();
this.verifyQuestionnaireSubmission();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add verification after medication removal.

The removeMedication method should include verification that the medication was actually removed.

   removeMedication() {
     cy.get('[data-cy="medication-remove"]').first().click();
     cy.verifyAndClickElement('[data-cy="confirm-remove-medication"]', "Remove");
     this.clickSubmitQuestionnaire();
     this.verifyQuestionnaireSubmission();
+    // Add verification that medication was removed
+    cy.get('[data-cy="medication-list"]').should('not.contain', this.lastRemovedMedication);
+    return this;
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
removeMedication() {
cy.get('[data-cy="medication-remove"]').first().click();
cy.verifyAndClickElement('[data-cy="confirm-remove-medication"]', "Remove");
this.clickSubmitQuestionnaire();
this.verifyQuestionnaireSubmission();
}
removeMedication() {
cy.get('[data-cy="medication-remove"]').first().click();
cy.verifyAndClickElement('[data-cy="confirm-remove-medication"]', "Remove");
this.clickSubmitQuestionnaire();
this.verifyQuestionnaireSubmission();
// Add verification that medication was removed
cy.get('[data-cy="medication-list"]').should('not.contain', this.lastRemovedMedication);
return this;
}

clickUpdateEncounter() {
cy.verifyAndClickElement(
'[data-cy="update-encounter-option"]',
Expand Down
1 change: 1 addition & 0 deletions src/components/Medicine/MedicationRequestTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export default function MedicationRequestTable({
variant="outline"
size="sm"
className="text-gray-950 hover:text-gray-700 h-9"
data-cy="edit-prescription"
>
<Link
href={`/facility/${facilityId}/patient/${patientId}/encounter/${encounterId}/questionnaire/medication_request`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export function MedicationRequestQuestion({
<AlertDialogAction
onClick={confirmRemoveMedication}
className={cn(buttonVariants({ variant: "destructive" }))}
data-cy="confirm-remove-medication"
>
{t("remove")}
</AlertDialogAction>
Expand Down Expand Up @@ -317,6 +318,7 @@ export function MedicationRequestQuestion({
medication.status === "entered_in_error"
}
className="h-8 w-8"
data-cy="medication-remove"
>
<MinusCircledIcon className="h-4 w-4" />
</Button>
Expand Down Expand Up @@ -619,7 +621,7 @@ const MedicationRequestGridRow: React.FC<MedicationRequestGridRowProps> = ({
}}
disabled={disabled || isReadOnly}
>
<SelectTrigger className="h-9 text-sm">
<SelectTrigger className="h-9 text-sm" data-cy="frequency">
<SelectValue placeholder={t("select_frequency")} />
</SelectTrigger>
<SelectContent>
Expand Down Expand Up @@ -879,6 +881,7 @@ const MedicationRequestGridRow: React.FC<MedicationRequestGridRowProps> = ({
onClick={onRemove}
disabled={disabled}
className="h-8 w-8"
data-cy="medication-remove"
>
<MinusCircledIcon className="h-4 w-4" />
</Button>
Expand Down
2 changes: 2 additions & 0 deletions src/components/Questionnaire/QuestionTypes/NotesInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function NotesInput({
size="sm"
className="h-full w-28 text-sm font-normal text-gray-700 hover:text-gray-900"
disabled={disabled}
data-cy="notes"
>
{hasNotes ? (
<div className="w-1.5 h-1.5 rounded-full bg-orange-400 " />
Expand All @@ -54,6 +55,7 @@ export function NotesInput({
className=" border-yellow-200 focus-visible:border-yellow-300 focus-visible:ring-yellow-300"
placeholder="Add notes..."
disabled={disabled}
data-cy="notes-textarea"
/>
</PopoverContent>
</Popover>
Expand Down
1 change: 1 addition & 0 deletions src/pages/Encounters/EncounterShow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export const EncounterShow = (props: Props) => {
{keysOf(tabs).map((tab) => (
<Link
key={tab}
data-cy={`tab-${tab}`}
className={tabButtonClasses(props.tab === tab)}
href={`/facility/${facilityId}/patient/${patientId}/encounter/${encounterData.id}/${tab}`}
>
Expand Down
Loading