Skip to content

Commit

Permalink
Merge branch 'develop' into fix#6771
Browse files Browse the repository at this point in the history
  • Loading branch information
nihal467 authored Apr 23, 2024
2 parents 3c490bc + 88e1a0b commit b43b1fa
Show file tree
Hide file tree
Showing 14 changed files with 339 additions and 193 deletions.
127 changes: 127 additions & 0 deletions cypress/e2e/patient_spec/patient_discharge.cy.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
8 changes: 0 additions & 8 deletions cypress/e2e/patient_spec/patient_manage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
28 changes: 1 addition & 27 deletions cypress/pageobject/Patient/PatientConsultation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
29 changes: 29 additions & 0 deletions cypress/pageobject/Patient/PatientDischarge.ts
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
"lg:col-span-2"
}`}
>
<div className="px-4 py-5 sm:p-6">
<div className="px-4 py-5 sm:p-6" id="discharge-information">
<h3 className="text-lg font-semibold leading-relaxed text-gray-900">
Discharge Information
</h3>
Expand Down
34 changes: 18 additions & 16 deletions src/Components/Facility/DischargeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ const DischargeModal = ({
}
};

const handleFacilitySelect = (selected: FacilityModel) => {
const handleFacilitySelect = (selected?: FacilityModel) => {
setFacility(selected);
setPreDischargeForm((prev) => ({
...prev,
referred_to: selected.id ?? null,
referred_to_external: !selected.id ? selected.name : null,
referred_to: selected?.id ?? null,
referred_to_external: !selected?.id ? selected?.name : null,
}));
};

Expand Down Expand Up @@ -211,19 +211,21 @@ const DischargeModal = ({
{preDischargeForm.new_discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Referred")?.id && (
<>
<FieldLabel>Referred to</FieldLabel>
<FacilitySelect
name="referred_to"
setSelected={(selected) =>
handleFacilitySelect(selected as FacilityModel)
}
selected={facility ?? null}
showAll
freeText
multiple={false}
errors={errors?.referred_to}
className="mb-4"
/>
<div id="facility-referredto">
<FieldLabel>Referred to</FieldLabel>
<FacilitySelect
name="referred_to"
setSelected={(selected) =>
handleFacilitySelect(selected as FacilityModel | undefined)
}
selected={facility ?? null}
showAll
freeText
multiple={false}
errors={errors?.referred_to}
className="mb-4"
/>
</div>
</>
)}
<TextAreaFormField
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Form/AutoCompleteAsync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const AutoCompleteAsync = (props: Props) => {
<Combobox.Button className="absolute inset-y-0 right-0 flex items-center pr-2">
<div className="absolute right-0 top-1 mr-2 flex items-center text-lg text-secondary-900">
{hasSelection && !loading && !required && (
<div className="tooltip">
<div className="tooltip" id="clear-button">
<CareIcon
icon="l-times-circle"
className="mb-[-5px] h-4 w-4 text-gray-800 transition-colors duration-200 ease-in-out hover:text-gray-500"
Expand Down
41 changes: 21 additions & 20 deletions src/Components/Medicine/CreatePrescriptionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,27 @@ export default function CreatePrescriptionForm(props: {
{...field("medicine_object", RequiredFieldValidator())}
required
/>
{props.prescription.dosage_type !== "PRN" && (
<CheckBoxFormField
label={t("titrate_dosage")}
name="Titrate Dosage"
value={field("dosage_type").value === "TITRATED"}
onChange={(e) => {
if (e.value) {
field("dosage_type").onChange({
name: "dosage_type",
value: "TITRATED",
});
} else {
field("dosage_type").onChange({
name: "dosage_type",
value: "REGULAR",
});
}
}}
/>
)}
{props.prescription.dosage_type !== "PRN" &&
props.prescription.prescription_type !== "DISCHARGE" && (
<CheckBoxFormField
label={t("titrate_dosage")}
name="Titrate Dosage"
value={field("dosage_type").value === "TITRATED"}
onChange={(e) => {
if (e.value) {
field("dosage_type").onChange({
name: "dosage_type",
value: "TITRATED",
});
} else {
field("dosage_type").onChange({
name: "dosage_type",
value: "REGULAR",
});
}
}}
/>
)}
<div className="flex flex-wrap items-center gap-x-4">
<SelectFormField
className="flex-1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ interface Props {
interval: { start: Date; end: Date };
prescription: Prescription;
refetch: () => void;
readonly?: boolean;
}

export default function AdministrationEventCell({
administrations,
interval: { start, end },
prescription,
refetch,
readonly,
}: Props) {
const [showTimeline, setShowTimeline] = useState(false);
// Check if cell belongs to an administered prescription (including start and excluding end)
Expand Down Expand Up @@ -56,6 +58,7 @@ export default function AdministrationEventCell({
prescription={prescription}
showPrescriptionDetails
onRefetch={refetch}
readonly={readonly}
/>
</DialogModal>
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ interface Props {
prescriptions: Prescription[];
pagination: ReturnType<typeof useRangePagination>;
onRefetch: () => void;
readonly: boolean;
}

export default function MedicineAdministrationTable({
readonly,
pagination,
prescriptions,
onRefetch,
Expand Down Expand Up @@ -101,6 +103,7 @@ export default function MedicineAdministrationTable({
prescription={obj}
intervals={pagination.slots!}
refetch={onRefetch}
readonly={readonly}
/>
))}
</tbody>
Expand Down
Loading

0 comments on commit b43b1fa

Please sign in to comment.