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" > @@ -198,6 +199,7 @@ export default function MedicationRequestTable({
setShowStopped(!showStopped)} + data-cy="toggle-stopped-medications" > { } return ( -
+
diff --git a/src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx b/src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx index 9e7dc18a175..56df58c8ff9 100644 --- a/src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx +++ b/src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx @@ -199,6 +199,7 @@ export function MedicationRequestQuestion({ {t("remove")} @@ -318,6 +319,7 @@ export function MedicationRequestQuestion({ medication.status === "entered_in_error" } className="h-8 w-8" + data-cy="remove-medication" > @@ -514,7 +516,10 @@ const MedicationRequestGridRow: React.FC = ({ {/* Dosage */} -
+
{dosageInstruction?.dose_and_rate?.dose_range ? ( @@ -529,6 +534,7 @@ const MedicationRequestGridRow: React.FC = ({ ) : ( <> { if (!value.value || !value.unit) return; @@ -613,7 +619,7 @@ const MedicationRequestGridRow: React.FC = ({ }} disabled={disabled || isReadOnly} > - + @@ -707,7 +713,10 @@ const MedicationRequestGridRow: React.FC = ({
{/* Instructions */} -
+
@@ -750,11 +759,15 @@ const MedicationRequestGridRow: React.FC = ({ } placeholder={t("select_additional_instructions")} disabled={disabled || isReadOnly} + data-cy="medication-instructions" /> )}
{/* Route */} -
+
= ({ />
{/* Site */} -
+
= ({ />
{/* Method */} -
+
{hasNotes ? (
@@ -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" /> diff --git a/src/pages/Encounters/EncounterShow.tsx b/src/pages/Encounters/EncounterShow.tsx index d51538adceb..83e74eae2ab 100644 --- a/src/pages/Encounters/EncounterShow.tsx +++ b/src/pages/Encounters/EncounterShow.tsx @@ -171,6 +171,7 @@ export const EncounterShow = (props: Props) => { {keysOf(tabs).map((tab) => (