diff --git a/cypress/e2e/patient_spec/patient_prescription.cy.ts b/cypress/e2e/patient_spec/patient_prescription.cy.ts
new file mode 100644
index 00000000000..f27cc0aa2e8
--- /dev/null
+++ b/cypress/e2e/patient_spec/patient_prescription.cy.ts
@@ -0,0 +1,66 @@
+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("testnurse4");
+ cy.visit("/");
+ });
+
+ it("should add a new medicine for the patient", () => {
+ facilityCreation.selectFacility("GHC payyanur");
+ const medicineName = "Estriol 1 mg oral tablet";
+ const dosage = 6;
+ const dosageInput = "6 Milligram";
+ 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,
+ )
+ .submitQuestionnaire()
+ .clickMedicinesTab()
+ .verifyMedication(
+ medicineName,
+ dosageInput,
+ frequency,
+ instructions,
+ route,
+ site,
+ method,
+ notes,
+ )
+ .clickEditPrescription()
+ .removeMedication()
+ .submitQuestionnaire()
+ .clickMedicinesTab()
+ .verifyDeletedMedication(
+ medicineName,
+ dosageInput,
+ frequency,
+ instructions,
+ route,
+ site,
+ method,
+ notes,
+ );
+ });
+});
diff --git a/cypress/fixtures/users.json b/cypress/fixtures/users.json
index db27e9969f7..739ca18ffd0 100644
--- a/cypress/fixtures/users.json
+++ b/cypress/fixtures/users.json
@@ -26,5 +26,9 @@
"teststaff4": {
"username": "teststaff4",
"password": "Test@123"
+ },
+ "testnurse4": {
+ "username": "testnurse4",
+ "password": "Test@123"
}
}
diff --git a/cypress/pageObject/Patients/PatientEncounter.ts b/cypress/pageObject/Patients/PatientEncounter.ts
index e38abe91b40..5699a997b6f 100644
--- a/cypress/pageObject/Patients/PatientEncounter.ts
+++ b/cypress/pageObject/Patients/PatientEncounter.ts
@@ -12,7 +12,88 @@ 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.clickAndSelectOption(
+ '[data-cy="question-medication-request"]',
+ medicineName,
+ );
+ cy.get('[data-cy="dosage"]').click().type(dosage);
+ cy.clickAndSelectOption('[data-cy="dosage"]', dosage);
+ cy.clickAndSelectOption('[data-cy="frequency"]', frequency);
+ cy.clickAndSelectOption('[data-cy="instructions"]', instructions);
+ cy.clickAndSelectOption('[data-cy="route"]', route);
+ cy.clickAndSelectOption('[data-cy="site"]', site);
+ cy.clickAndSelectOption('[data-cy="method"]', method);
+ cy.get('[data-cy="notes"]').click();
+ cy.get('[data-cy="notes-textarea"]').type(notes);
+ return this;
+ }
+ verifyMedication(
+ medicineName,
+ dosage,
+ frequency,
+ instructions,
+ route,
+ site,
+ method,
+ notes,
+ ) {
+ cy.get('[data-cy="medications-table"]').within(() => {
+ cy.contains("td", medicineName).should("exist");
+ cy.contains("td", dosage).should("exist");
+ cy.contains("td", frequency).should("exist");
+ cy.contains("td", instructions).should("exist");
+ cy.contains("td", route).should("exist");
+ cy.contains("td", site).should("exist");
+ cy.contains("td", method).should("exist");
+ cy.contains("td", notes).should("exist");
+ });
+ return this;
+ }
+ removeMedication() {
+ cy.get('[data-cy="remove-medication"]').first().click();
+ cy.verifyAndClickElement('[data-cy="confirm-remove-medication"]', "Remove");
+ return this;
+ }
+ verifyDeletedMedication(
+ medicineName,
+ dosage,
+ frequency,
+ instructions,
+ route,
+ site,
+ method,
+ notes,
+ ) {
+ cy.get('[data-cy="toggle-stopped-medications"]').click();
+ cy.get('[data-cy="medications-table"]').within(() => {
+ cy.contains("td", medicineName).should("exist");
+ cy.contains("td", dosage).should("exist");
+ cy.contains("td", frequency).should("exist");
+ cy.contains("td", instructions).should("exist");
+ cy.contains("td", route).should("exist");
+ cy.contains("td", site).should("exist");
+ cy.contains("td", method).should("exist");
+ cy.contains("td", notes).should("exist");
+ });
+ }
clickUpdateEncounter() {
cy.verifyAndClickElement(
'[data-cy="update-encounter-option"]',
diff --git a/src/components/Medicine/MedicationRequestTable/index.tsx b/src/components/Medicine/MedicationRequestTable/index.tsx
index 7c29e97bda4..d24e721e4fe 100644
--- a/src/components/Medicine/MedicationRequestTable/index.tsx
+++ b/src/components/Medicine/MedicationRequestTable/index.tsx
@@ -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"
>