From f130199d47ebfa6f61ce76292966632c95926b21 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Mon, 6 May 2024 19:53:24 +0530 Subject: [PATCH] Duplicate medicine --- cypress/e2e/patient_spec/patient_manage.cy.ts | 15 ------ .../patient_spec/patient_prescription.cy.ts | 49 +++++++++++++++++++ .../pageobject/Patient/PatientPrescription.ts | 10 ++-- 3 files changed, 54 insertions(+), 20 deletions(-) create mode 100644 cypress/e2e/patient_spec/patient_prescription.cy.ts diff --git a/cypress/e2e/patient_spec/patient_manage.cy.ts b/cypress/e2e/patient_spec/patient_manage.cy.ts index c25677d9e8b..00756f832f6 100644 --- a/cypress/e2e/patient_spec/patient_manage.cy.ts +++ b/cypress/e2e/patient_spec/patient_manage.cy.ts @@ -2,13 +2,11 @@ import { afterEach, before, beforeEach, cy, describe, it } from "local-cypress"; import LoginPage from "../../pageobject/Login/LoginPage"; import { PatientConsultationPage } from "../../pageobject/Patient/PatientConsultation"; import { PatientPage } from "../../pageobject/Patient/PatientCreation"; -import PatientPrescription from "../../pageobject/Patient/PatientPrescription"; describe("Patient", () => { const loginPage = new LoginPage(); const patientPage = new PatientPage(); const patientConsultationPage = new PatientConsultationPage(); - const patientPrescription = new PatientPrescription(); before(() => { loginPage.loginAsDisctrictAdmin(); @@ -45,19 +43,6 @@ describe("Patient", () => { cy.verifyNotification("Note added successfully"); }); - it("Edit prescription for an already created patient", () => { - patientPage.visitPatient("Dummy Patient 4"); - patientPrescription.visitEditPrescriptionPage(); - patientPrescription.clickAddPrescription(); - patientPrescription.interceptMedibase(); - patientPrescription.selectMedicinebox(); - patientPrescription.selectMedicine("DOLO"); - patientPrescription.enterDosage("4"); - patientPrescription.selectDosageFrequency("Twice daily"); - cy.submitButton("Submit"); - cy.verifyNotification("Medicine prescribed"); - }); - afterEach(() => { cy.saveLocalStorage(); }); 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..3cf5a1ba5aa --- /dev/null +++ b/cypress/e2e/patient_spec/patient_prescription.cy.ts @@ -0,0 +1,49 @@ +import PatientPrescription from "../../pageobject/Patient/PatientPrescription"; +import LoginPage from "../../pageobject/Login/LoginPage"; +import { PatientPage } from "../../pageobject/Patient/PatientCreation"; + +const patientPrescription = new PatientPrescription(); +const loginPage = new LoginPage(); +const patientPage = new PatientPage(); + +describe("Patient Medicine Administration", () => { + before(() => { + loginPage.loginAsDisctrictAdmin(); + cy.saveLocalStorage(); + }); + + beforeEach(() => { + cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); + cy.awaitUrl("/patients"); + }); + + it("Add a new medicine for a patient and verify the duplicate medicine validation", () => { + patientPage.visitPatient("Dummy Patient 4"); + patientPrescription.visitMedicineTab(); + patientPrescription.clickAddPrescription(); + patientPrescription.interceptMedibase(); + patientPrescription.selectMedicinebox(); + patientPrescription.selectMedicine("DOLO"); + patientPrescription.enterDosage("4"); + patientPrescription.selectDosageFrequency("Twice daily"); + cy.submitButton("Submit"); + cy.verifyNotification("Medicine prescribed"); + cy.closeNotification(); + // verify the duplicate medicine error message + patientPrescription.clickAddPrescription(); + patientPrescription.interceptMedibase(); + patientPrescription.selectMedicinebox(); + patientPrescription.selectMedicine("DOLO"); + patientPrescription.enterDosage("4"); + patientPrescription.selectDosageFrequency("Twice daily"); + cy.submitButton("Submit"); + cy.verifyNotification( + "Medicine - This medicine is already prescribed to this patient. Please discontinue the existing prescription to prescribe again.", + ); + }); + + afterEach(() => { + cy.saveLocalStorage(); + }); +}); diff --git a/cypress/pageobject/Patient/PatientPrescription.ts b/cypress/pageobject/Patient/PatientPrescription.ts index 5c5c64483e4..dc4163e4823 100644 --- a/cypress/pageobject/Patient/PatientPrescription.ts +++ b/cypress/pageobject/Patient/PatientPrescription.ts @@ -12,13 +12,13 @@ export class PatientPrescription { selectMedicine(medicine: string) { cy.searchAndSelectOption( "div#medicine_object input[placeholder='Select'][role='combobox']", - medicine + medicine, ); } selectMedicinebox() { cy.get( - "div#medicine_object input[placeholder='Select'][role='combobox']" + "div#medicine_object input[placeholder='Select'][role='combobox']", ).click(); } @@ -37,21 +37,21 @@ export class PatientPrescription { clickReturnToDashboard() { cy.verifyAndClickElement( "[data-testid='return-to-patient-dashboard']", - "Return to Patient Dashboard" + "Return to Patient Dashboard", ); } discontinuePreviousPrescription() { cy.intercept( "POST", - "**/api/v1/consultation/*/prescriptions/*/discontinue/" + "**/api/v1/consultation/*/prescriptions/*/discontinue/", ).as("deletePrescription"); cy.get("button").contains("Discontinue").click(); cy.get("#submit").contains("Discontinue").click(); cy.wait("@deletePrescription").its("response.statusCode").should("eq", 200); } - visitEditPrescriptionPage() { + visitMedicineTab() { cy.get("#consultation_tab_nav").scrollIntoView(); cy.get("#consultation_tab_nav").contains("Medicines").click(); cy.get("a[href='prescriptions']").first().click();