diff --git a/cypress/e2e/patient_spec/patient_discharge.cy.ts b/cypress/e2e/patient_spec/patient_discharge.cy.ts new file mode 100644 index 00000000000..34ad423d1e8 --- /dev/null +++ b/cypress/e2e/patient_spec/patient_discharge.cy.ts @@ -0,0 +1,127 @@ +import { afterEach, before, beforeEach, cy, describe, it } from "local-cypress"; +import LoginPage from "../../pageobject/Login/LoginPage"; +import { PatientPage } from "../../pageobject/Patient/PatientCreation"; +import PatientDischarge from "../../pageobject/Patient/PatientDischarge"; +import PatientPrescription from "../../pageobject/Patient/PatientPrescription"; + +describe("Patient Discharge based on multiple reason", () => { + const loginPage = new LoginPage(); + const patientPage = new PatientPage(); + const patientDischarge = new PatientDischarge(); + const patientPrescription = new PatientPrescription(); + const patientDischargeReason1 = "Recovered"; + const patientDischargeReason2 = "Referred"; + const patientDischargeReason3 = "Expired"; + const patientDischargeReason4 = "LAMA"; + const patientDischargeAdvice = "Discharge Advice"; + const patientMedicine = "ZOLE"; + const referringFacility = "Dummy Shifting Center, Ernakulam"; + const referringFreetextFacility = "Aster Mims"; + const patientDeathCause = "Cause Of Death"; + const doctorName = "Custom Doctor"; + + before(() => { + loginPage.loginAsDisctrictAdmin(); + cy.saveLocalStorage(); + }); + + beforeEach(() => { + cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); + cy.awaitUrl("/patients"); + }); + + it("Discharge a LAMA patient in the consultation", () => { + patientPage.visitPatient("Dummy Patient 12"); + patientDischarge.clickDischarge(); + patientDischarge.selectDischargeReason(patientDischargeReason4); + cy.submitButton("Confirm Discharge"); + cy.verifyNotification("Patient Discharged Successfully"); + cy.closeNotification(); + // Verify the consultation dashboard reflection + cy.verifyContentPresence("#consultation-buttons", ["LAMA"]); + // verify the discharge information card + cy.verifyContentPresence("#discharge-information", [ + patientDischargeReason4, + ]); + }); + + it("Discharge a expired patient in the consultation", () => { + patientPage.visitPatient("Dummy Patient 13"); + patientDischarge.clickDischarge(); + patientDischarge.selectDischargeReason(patientDischargeReason3); + patientDischarge.typeDischargeNote(patientDeathCause); + patientDischarge.typeDoctorName(doctorName); + cy.submitButton("Confirm Discharge"); + cy.verifyNotification("Patient Discharged Successfully"); + cy.closeNotification(); + // Verify the consultation dashboard reflection + cy.verifyContentPresence("#consultation-buttons", ["EXPIRED"]); + // verify the discharge information card + cy.verifyContentPresence("#discharge-information", [ + patientDischargeReason3, + patientDeathCause, + doctorName, + ]); + }); + + it("Discharge patient with referred reason to a facility", () => { + patientPage.visitPatient("Dummy Patient 16"); + patientDischarge.clickDischarge(); + patientDischarge.selectDischargeReason(patientDischargeReason2); + patientDischarge.typeDischargeNote(patientDischargeAdvice); + // select a registrated facility from dropdown and clear + patientDischarge.typeReferringFacility(referringFacility); + patientDischarge.clickClearButton(); + // select a non-registered facility and perform the discharge + patientDischarge.typeReferringFacility(referringFreetextFacility); + cy.wait(2000); + cy.submitButton("Confirm Discharge"); + cy.wait(2000); + cy.verifyNotification("Patient Discharged Successfully"); + cy.closeNotification(); + // Verify the consultation dashboard reflection + cy.verifyContentPresence("#consultation-buttons", ["Referred"]); + // Verify the dashboard and discharge information + cy.verifyContentPresence("#discharge-information", [ + patientDischargeReason2, + patientDischargeAdvice, + referringFreetextFacility, + ]); + }); + + it("Discharge a recovered patient with all relevant fields", () => { + patientPage.visitPatient("Dummy Patient 15"); + patientDischarge.clickDischarge(); + patientDischarge.selectDischargeReason(patientDischargeReason1); + patientDischarge.typeDischargeNote(patientDischargeAdvice); + // Prescribe a medicine for the patient + patientPrescription.clickAddPrescription(); + patientPrescription.interceptMedibase(); + patientPrescription.selectMedicinebox(); + patientPrescription.selectMedicine(patientMedicine); + patientPrescription.enterDosage("4"); + patientPrescription.selectDosageFrequency("Twice daily"); + cy.submitButton("Submit"); + cy.verifyNotification("Medicine prescribed"); + cy.wait(2000); + cy.closeNotification(); + // submit the discharge pop-up + cy.submitButton("Confirm Discharge"); + cy.wait(2000); + cy.verifyNotification("Patient Discharged Successfully"); + cy.closeNotification(); + // Verify the consultation dashboard reflection + cy.verifyContentPresence("#consultation-buttons", ["Recovered"]); + // Verify the dashboard and discharge information + cy.verifyContentPresence("#discharge-information", [ + patientDischargeReason1, + patientDischargeAdvice, + patientMedicine, + ]); + }); + + afterEach(() => { + cy.saveLocalStorage(); + }); +}); diff --git a/cypress/e2e/patient_spec/patient_manage.cy.ts b/cypress/e2e/patient_spec/patient_manage.cy.ts index 35b89aedb7f..c25677d9e8b 100644 --- a/cypress/e2e/patient_spec/patient_manage.cy.ts +++ b/cypress/e2e/patient_spec/patient_manage.cy.ts @@ -58,14 +58,6 @@ describe("Patient", () => { cy.verifyNotification("Medicine prescribed"); }); - it("Discharge a patient", () => { - patientPage.visitPatient("Dummy Patient 6"); - patientConsultationPage.clickDischargePatient(); - patientConsultationPage.selectDischargeReason("Recovered"); - patientConsultationPage.addDischargeNotes("Discharge notes"); - patientConsultationPage.confirmDischarge(); - }); - afterEach(() => { cy.saveLocalStorage(); }); diff --git a/cypress/pageobject/Patient/PatientConsultation.ts b/cypress/pageobject/Patient/PatientConsultation.ts index 0a39a1f839a..87cead3fc1f 100644 --- a/cypress/pageobject/Patient/PatientConsultation.ts +++ b/cypress/pageobject/Patient/PatientConsultation.ts @@ -100,7 +100,7 @@ export class PatientConsultationPage { cy.get("button").contains("Manage Patient").click(); cy.verifyAndClickElement( "#consultation-buttons", - "Edit Consultation Details" + "Edit Consultation Details", ); cy.wait(3000); } @@ -130,30 +130,4 @@ export class PatientConsultationPage { cy.get("#add_doctor_note_button").click(); cy.wait("@postDoctorNotes").its("response.statusCode").should("eq", 201); } - - clickDischargePatient() { - cy.get("#show-more").scrollIntoView(); - cy.get("#show-more").click(); - cy.contains("p", "Discharge from CARE").click(); - } - - selectDischargeReason(reason: string) { - cy.get("#discharge_reason") - .click() - .then(() => { - cy.get("[role='option']").contains(reason).click(); - }); - } - - addDischargeNotes(notes: string) { - cy.get("#discharge_notes").type(notes); - } - - confirmDischarge() { - cy.intercept("POST", "**/api/v1/consultation/*/discharge_patient/").as( - "dischargePatient" - ); - cy.get("#submit").contains("Confirm Discharge").click(); - cy.wait("@dischargePatient").its("response.statusCode").should("eq", 200); - } } diff --git a/cypress/pageobject/Patient/PatientDischarge.ts b/cypress/pageobject/Patient/PatientDischarge.ts new file mode 100644 index 00000000000..eda6a379a3f --- /dev/null +++ b/cypress/pageobject/Patient/PatientDischarge.ts @@ -0,0 +1,29 @@ +class PatientDischarge { + clickDischarge() { + cy.get("#show-more").scrollIntoView(); + cy.verifyAndClickElement("#show-more", "Manage Patient"); + cy.verifyAndClickElement("#show-more", "Discharge from CARE"); + } + + selectDischargeReason(reason: string) { + cy.clickAndSelectOption("#discharge_reason", reason); + } + + typeDischargeNote(note: string) { + cy.get("#discharge_notes").type(note); + } + + typeReferringFacility(facility: string) { + cy.searchAndSelectOption("#facility-referredto", facility); + } + + clickClearButton() { + cy.get("#clear-button").click(); + } + + typeDoctorName(doctorName: string) { + cy.get("#death_confirmed_by").type(doctorName); + } +} + +export default PatientDischarge; diff --git a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx index 950ae89b62e..f4150617f1f 100644 --- a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx +++ b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx @@ -202,7 +202,7 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => { "lg:col-span-2" }`} > -
+

Discharge Information

diff --git a/src/Components/Facility/DischargeModal.tsx b/src/Components/Facility/DischargeModal.tsx index 7b170379066..c81ab2cf74e 100644 --- a/src/Components/Facility/DischargeModal.tsx +++ b/src/Components/Facility/DischargeModal.tsx @@ -211,19 +211,21 @@ const DischargeModal = ({ {preDischargeForm.new_discharge_reason === DISCHARGE_REASONS.find((i) => i.text == "Referred")?.id && ( <> - Referred to - - handleFacilitySelect(selected as FacilityModel | undefined) - } - selected={facility ?? null} - showAll - freeText - multiple={false} - errors={errors?.referred_to} - className="mb-4" - /> +
+ Referred to + + handleFacilitySelect(selected as FacilityModel | undefined) + } + selected={facility ?? null} + showAll + freeText + multiple={false} + errors={errors?.referred_to} + className="mb-4" + /> +
)} {
{hasSelection && !loading && !required && ( -
+