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

New Cypress Test | Titrated dosage and Individual administration | Patient Prescription Module #7803

Merged
merged 3 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
56 changes: 50 additions & 6 deletions cypress/e2e/patient_spec/patient_prescription.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { PatientPage } from "../../pageobject/Patient/PatientCreation";
const patientPrescription = new PatientPrescription();
const loginPage = new LoginPage();
const patientPage = new PatientPage();
const medicineName = "DOLO";
const medicineBaseDosage = "4";
const medicineTargetDosage = "9";
const medicineFrequency = "Twice daily";
const medicineAdministerNote = "Medicine Administration Note";

describe("Patient Medicine Administration", () => {
before(() => {
Expand All @@ -18,25 +23,64 @@ describe("Patient Medicine Administration", () => {
cy.awaitUrl("/patients");
});

it("Add a new titrated medicine for a patient | Individual Administeration |", () => {
patientPage.visitPatient("Dummy Patient 5");
patientPrescription.visitMedicineTab();
patientPrescription.visitEditPrescription();
patientPrescription.clickAddPrescription();
patientPrescription.interceptMedibase();
patientPrescription.selectMedicinebox();
patientPrescription.selectMedicine(medicineName);
patientPrescription.clickTitratedDosage();
patientPrescription.enterDosage(medicineBaseDosage);
patientPrescription.enterTargetDosage(medicineTargetDosage);
patientPrescription.selectDosageFrequency(medicineFrequency);
cy.submitButton("Submit");
cy.verifyNotification("Medicine prescribed");
cy.closeNotification();
// Administer the medicine in edit form
patientPrescription.clickAdministerButton();
patientPrescription.enterAdministerDosage(medicineBaseDosage);
patientPrescription.enterAdministerNotes(medicineAdministerNote);
cy.submitButton("Administer Medicine");
cy.verifyNotification("Medicine(s) administered");
cy.closeNotification();
// Verify the Reflection on the Medicine
cy.verifyContentPresence("#medicine-preview", [
medicineName,
medicineBaseDosage,
medicineTargetDosage,
]);
patientPrescription.clickReturnToDashboard();
// Go to medicine tab and administer it again
patientPrescription.visitMedicineTab();
cy.verifyAndClickElement("#0", medicineName);
cy.submitButton("Administer");
patientPrescription.enterAdministerDosage(medicineBaseDosage);
cy.submitButton("Administer Medicine");
cy.verifyNotification("Medicine(s) administered");
});

it("Add a new medicine for a patient and verify the duplicate medicine validation", () => {
patientPage.visitPatient("Dummy Patient 4");
patientPrescription.visitMedicineTab();
patientPrescription.visitEditPrescription();
patientPrescription.clickAddPrescription();
patientPrescription.interceptMedibase();
patientPrescription.selectMedicinebox();
patientPrescription.selectMedicine("DOLO");
patientPrescription.enterDosage("4");
patientPrescription.selectDosageFrequency("Twice daily");
patientPrescription.selectMedicine(medicineName);
patientPrescription.enterDosage(medicineBaseDosage);
patientPrescription.selectDosageFrequency(medicineFrequency);
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");
patientPrescription.selectMedicine(medicineName);
patientPrescription.enterDosage(medicineBaseDosage);
patientPrescription.selectDosageFrequency(medicineFrequency);
cy.submitButton("Submit");
cy.verifyNotification(
"Medicine - This medicine is already prescribed to this patient. Please discontinue the existing prescription to prescribe again.",
Expand Down
34 changes: 30 additions & 4 deletions cypress/pageobject/Patient/PatientPrescription.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export class PatientPrescription {
clickAddPrescription() {
cy.contains("button", "Add Prescription Medication")
.should("be.visible")
.click();
cy.get("#add-prescription").scrollIntoView();
cy.verifyAndClickElement(
"#add-prescription",
"Add Prescription Medication",
);
}

interceptMedibase() {
Expand All @@ -16,6 +18,15 @@ export class PatientPrescription {
);
}

clickTitratedDosage() {
cy.get("#titrated-dosage").click();
}

clickAdministerButton() {
cy.get("#administer-medicine").should("be.visible");
cy.verifyAndClickElement("#administer-medicine", "Administer");
}

selectMedicinebox() {
cy.get(
"div#medicine_object input[placeholder='Select'][role='combobox']",
Expand All @@ -30,6 +41,18 @@ export class PatientPrescription {
cy.get("#base_dosage").type(doseAmount, { force: true });
}

enterAdministerDosage(dosage: string) {
cy.get("#dosage").type(dosage);
}

enterAdministerNotes(notes: string) {
cy.get("#administration_notes").type(notes);
}

enterTargetDosage(targetDosage: string) {
cy.get("#target_dosage").type(targetDosage, { force: true });
}

selectDosageFrequency(frequency: string) {
cy.clickAndSelectOption("#frequency", frequency);
}
Expand All @@ -54,7 +77,10 @@ export class PatientPrescription {
visitMedicineTab() {
cy.get("#consultation_tab_nav").scrollIntoView();
cy.get("#consultation_tab_nav").contains("Medicines").click();
cy.get("a[href='prescriptions']").first().click();
}

visitEditPrescription() {
cy.get("#edit-prescription").click();
}
}
export default PatientPrescription;
1 change: 1 addition & 0 deletions src/Components/Medicine/CreatePrescriptionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default function CreatePrescriptionForm(props: {
{props.prescription.dosage_type !== "PRN" &&
props.prescription.prescription_type !== "DISCHARGE" && (
<CheckBoxFormField
id="titrated-dosage"
label={t("titrate_dosage")}
name="Titrate Dosage"
value={field("dosage_type").value === "TITRATED"}
Expand Down
5 changes: 4 additions & 1 deletion src/Components/Medicine/ManagePrescriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export default function ManagePrescriptions() {

return (
<Page title={t("manage_prescriptions")}>
<div className="mx-auto flex w-full max-w-4xl flex-col gap-10 rounded bg-white p-6 transition-all sm:rounded-xl sm:p-12">
<div
className="mx-auto flex w-full max-w-4xl flex-col gap-10 rounded bg-white p-6 transition-all sm:rounded-xl sm:p-12"
id="medicine-preview"
>
<div className="flex flex-col gap-10 divide-y-2 divide-dashed divide-gray-600">
<div>
<h3 className="mb-4 text-lg font-semibold">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default function AdministrationEventCell({
/>
</DialogModal>
<button
id="administration-symbol"
className="scale-100 transition-transform duration-200 ease-in-out hover:scale-110"
onClick={() => setShowTimeline(true)}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const MedicineAdministrationSheet = ({ readonly, is_prn }: Props) => {
!!data?.results && (
<>
<ButtonV2
id="edit-prescription"
variant="secondary"
border
href="prescriptions"
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Medicine/PrescriptionBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default function PrescriptionBuilder({
className="mt-4 w-full bg-gray-200 text-gray-700 hover:bg-gray-300 hover:text-gray-900 focus:bg-gray-100 focus:text-gray-900"
disabled={disabled}
>
<div className="flex w-full justify-start gap-2">
<div className="flex w-full justify-start gap-2" id="add-prescription">
<CareIcon icon="l-plus" className="text-lg" />
<span className="font-bold">
{t(is_prn ? "add_prn_prescription" : "add_prescription_medication")}
Expand Down
1 change: 1 addition & 0 deletions src/Components/Medicine/PrescriptionDetailCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default function PrescriptionDetailCard({
prescription.prescription_type !== "DISCHARGE" && (
<div className="flex flex-col-reverse items-end gap-2 sm:flex-row">
<ButtonV2
id="administer-medicine"
disabled={prescription.discontinued}
onClick={props.onAdministerClick}
type="button"
Expand Down
Loading