Skip to content

Commit

Permalink
Merge branch 'develop' into issues/#7600/filter-button-behaviour-in-l…
Browse files Browse the repository at this point in the history
…ive-feed
  • Loading branch information
Dev-Harwani authored Jun 19, 2024
2 parents 162e982 + f2a192b commit 24679b9
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 61 deletions.
49 changes: 43 additions & 6 deletions cypress/e2e/patient_spec/patient_prescription.cy.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { afterEach, before, beforeEach, cy, describe, it } from "local-cypress";
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();
const medicineName = "DOLO";
const medicineNameOne = "DOLO";
const medicineNameTwo = "FDEP PLUS";
const medicineBaseDosage = "4";
const medicineTargetDosage = "9";
const medicineFrequency = "Twice daily";
const medicineAdministerNote = "Medicine Administration Note";
const medicineIndicator = "Test Indicator";

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

it("Add a PRN Prescription medicine | Group Administrate it |", () => {
patientPage.visitPatient("Dummy Patient 6");
patientPrescription.visitMedicineTab();
patientPrescription.visitEditPrescription();
// Add First Medicine
patientPrescription.clickAddPrnPrescriptionButton();
patientPrescription.interceptMedibase();
patientPrescription.selectMedicinebox();
patientPrescription.selectMedicine(medicineNameOne);
patientPrescription.enterDosage(medicineBaseDosage);
patientPrescription.enterIndicator(medicineIndicator);
cy.submitButton("Submit");
cy.verifyNotification("Medicine prescribed");
cy.closeNotification();
// Add Second Medicine
patientPrescription.clickAddPrnPrescriptionButton();
patientPrescription.interceptMedibase();
patientPrescription.selectMedicinebox();
patientPrescription.selectMedicine(medicineNameTwo);
patientPrescription.enterDosage(medicineBaseDosage);
patientPrescription.enterIndicator(medicineIndicator);
cy.submitButton("Submit");
cy.verifyNotification("Medicine prescribed");
cy.closeNotification();
patientPrescription.clickReturnToDashboard();
// Group Administer the PRN Medicine
patientPrescription.visitMedicineTab();
patientPrescription.clickAdministerBulkMedicine();
patientPrescription.clickAllVisibleAdministration();
patientPrescription.clickAdministerSelectedMedicine();
cy.verifyNotification("Medicine(s) administered");
cy.closeNotification();
});

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.selectMedicine(medicineNameOne);
patientPrescription.clickTitratedDosage();
patientPrescription.enterDosage(medicineBaseDosage);
patientPrescription.enterTargetDosage(medicineTargetDosage);
Expand All @@ -47,14 +84,14 @@ describe("Patient Medicine Administration", () => {
cy.closeNotification();
// Verify the Reflection on the Medicine
cy.verifyContentPresence("#medicine-preview", [
medicineName,
medicineNameOne,
medicineBaseDosage,
medicineTargetDosage,
]);
patientPrescription.clickReturnToDashboard();
// Go to medicine tab and administer it again
patientPrescription.visitMedicineTab();
cy.verifyAndClickElement("#0", medicineName);
cy.verifyAndClickElement("#0", medicineNameOne);
cy.submitButton("Administer");
patientPrescription.enterAdministerDosage(medicineBaseDosage);
cy.submitButton("Administer Medicine");
Expand All @@ -68,7 +105,7 @@ describe("Patient Medicine Administration", () => {
patientPrescription.clickAddPrescription();
patientPrescription.interceptMedibase();
patientPrescription.selectMedicinebox();
patientPrescription.selectMedicine(medicineName);
patientPrescription.selectMedicine(medicineNameOne);
patientPrescription.enterDosage(medicineBaseDosage);
patientPrescription.selectDosageFrequency(medicineFrequency);
cy.submitButton("Submit");
Expand All @@ -78,7 +115,7 @@ describe("Patient Medicine Administration", () => {
patientPrescription.clickAddPrescription();
patientPrescription.interceptMedibase();
patientPrescription.selectMedicinebox();
patientPrescription.selectMedicine(medicineName);
patientPrescription.selectMedicine(medicineNameOne);
patientPrescription.enterDosage(medicineBaseDosage);
patientPrescription.selectDosageFrequency(medicineFrequency);
cy.submitButton("Submit");
Expand Down
29 changes: 21 additions & 8 deletions cypress/pageobject/Patient/PatientPrescription.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { cy } from "local-cypress";
export class PatientPrescription {
clickAddPrescription() {
cy.get("#add-prescription").scrollIntoView();
Expand All @@ -7,6 +8,10 @@ export class PatientPrescription {
);
}

clickAddPrnPrescriptionButton() {
cy.contains("button", "Add PRN Prescription").click();
}

interceptMedibase() {
cy.intercept("GET", "**/api/v1/medibase/**").as("getMedibase");
}
Expand All @@ -27,6 +32,15 @@ export class PatientPrescription {
cy.verifyAndClickElement("#administer-medicine", "Administer");
}

clickAdministerBulkMedicine() {
cy.get("#bulk-administer").should("be.visible");
cy.get("#bulk-administer").click();
}

clickAllVisibleAdministration() {
cy.get("#should_administer").should("be.visible").click();
}

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

enterIndicator(indicator: string) {
cy.get("#indicator").type(indicator);
}

enterAdministerDosage(dosage: string) {
cy.get("#dosage").type(dosage);
}
Expand All @@ -64,14 +82,9 @@ export class PatientPrescription {
);
}

discontinuePreviousPrescription() {
cy.intercept(
"POST",
"**/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);
clickAdministerSelectedMedicine() {
cy.get("#administer-selected-medicine").should("be.visible");
cy.get("#administer-selected-medicine").click();
}

visitMedicineTab() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ const LogUpdateCardAttribute = <T extends keyof DailyRoundsModel>({
<span className="text-sm font-semibold text-gray-700">
{(attributeValue as string) === "VENTILATOR"
? "CRITICAL CARE"
: (attributeValue as string)}
: (attributeValue as string) === "DOCTORS_LOG"
? "PROGRESS NOTE"
: (attributeValue as string)}
</span>
</div>
);
Expand Down
6 changes: 5 additions & 1 deletion src/Components/Medicine/MedicineAdministration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ export default function MedicineAdministration(props: Props) {
</PrescriptionDetailCard>
))}
<div className="flex justify-end">
<ButtonV2 onClick={handleSubmit} disabled={!selectedCount}>
<ButtonV2
id="administer-selected-medicine"
onClick={handleSubmit}
disabled={!selectedCount}
>
<CareIcon icon="l-syringe" className="text-lg" />
{t("administer_selected_medicines")}{" "}
{selectedCount > 0 && `(${selectedCount})`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function BulkAdminister({ prescriptions, onDone }: Props) {
return (
<>
<ButtonV2
id="bulk-administer"
ghost
border
onClick={() => setShowBulkAdminister(true)}
Expand Down
71 changes: 26 additions & 45 deletions src/Components/Shifting/ShiftingBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,6 @@ interface boardProps {
containerHeight: number;
}

const reduceLoading = (action: string, current: any) => {
switch (action) {
case "MORE":
return { ...current, more: true };
case "BOARD":
return { ...current, board: true };
case "COMPLETE":
return { board: false, more: false };
}
};

const ShiftCard = ({ shift, filter }: any) => {
const { wartime_shifting } = useConfig();
const [modalFor, setModalFor] = useState({
Expand Down Expand Up @@ -268,7 +257,8 @@ export default function ShiftingBoard({
}: boardProps) {
const containerRef = useRef<HTMLDivElement>(null);
const [offset, setOffSet] = useState(0);
const [isLoading, setIsLoading] = useState({ board: "BOARD", more: false });
const [pages, setPages] = useState<PaginatedResponse<IShift>[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [{ isOver }, drop] = useDrop(() => ({
accept: "shift-card",
drop: (item: any) => {
Expand All @@ -278,23 +268,24 @@ export default function ShiftingBoard({
},
collect: (monitor) => ({ isOver: !!monitor.isOver() }),
}));
const [data, setData] = useState<PaginatedResponse<IShift>>();

useQuery(routes.listShiftRequests, {
const query = useQuery(routes.listShiftRequests, {
query: formatFilter({
...filterProp,
status: board,
}),
onResponse: ({ res, data: listShiftData }) => {
setIsLoading(false);
if (res?.ok && listShiftData) {
setData(listShiftData);
setPages((prev) => [...prev, listShiftData]);
}
setIsLoading((loading) => reduceLoading("COMPLETE", loading));
},
});

useEffect(() => {
setIsLoading((loading) => reduceLoading("BOARD", loading));
setPages([]);
setIsLoading(true);
query.refetch();
}, [
filterProp.facility,
filterProp.origin_facility,
Expand All @@ -316,7 +307,7 @@ export default function ShiftingBoard({
]);

const handlePagination = async () => {
setIsLoading((loading) => reduceLoading("MORE", loading));
setIsLoading(true);
setOffSet(offset + 14);
const { res, data: newPageData } = await request(routes.listShiftRequests, {
query: formatFilter({
Expand All @@ -326,18 +317,15 @@ export default function ShiftingBoard({
}),
});
if (res?.ok && newPageData) {
setData((prev) =>
prev
? { ...prev, results: [...prev.results, ...newPageData.results] }
: newPageData,
);
setPages((prev) => [...prev, newPageData]);
}
setIsLoading((loading) => reduceLoading("COMPLETE", loading));
setIsLoading(false);
};
const { t } = useTranslation();

const patientFilter = (filter: string) => {
return data?.results
return pages
.flatMap((p) => p.results)
.filter(({ status }) => status === filter)
.map((shift: any) => (
<ShiftCard key={`shift_${shift.id}`} shift={shift} filter={filter} />
Expand All @@ -350,7 +338,7 @@ export default function ShiftingBoard({
const { height } = container.getBoundingClientRect();
containerHeight < height && setContainerHeight(height);
}
}, [containerRef.current, data?.results.length]);
}, [containerRef.current, pages.flatMap((p) => p.results).length]);

return (
<div
Expand All @@ -376,12 +364,17 @@ export default function ShiftingBoard({
/>
</h3>
<span className="ml-2 rounded-lg bg-primary-500 px-2 text-white">
{data?.count || "0"}
{pages[0] ? pages[0].count : "..."}
</span>
</div>
</div>
<div ref={containerRef} className="mt-2 flex flex-col pb-2 text-sm">
{isLoading.board ? (
{pages[0]?.count > 0
? patientFilter(board)
: !isLoading && (
<p className="mx-auto p-4">{t("no_patients_to_show")}</p>
)}
{isLoading ? (
<div className="m-1">
<div className="mx-auto w-full max-w-sm rounded-md border border-gray-300 bg-white p-4 shadow">
<div className="flex animate-pulse space-x-4 ">
Expand All @@ -395,25 +388,13 @@ export default function ShiftingBoard({
</div>
</div>
</div>
) : data?.count ?? 0 > 0 ? (
patientFilter(board)
) : (
<p className="mx-auto p-4">{t("no_patients_to_show")}</p>
pages.at(-1)?.next && (
<ButtonV2 onClick={(_) => handlePagination()} className="m-2 block">
Load More
</ButtonV2>
)
)}
{!isLoading.board &&
(data?.count ?? 0) < (data?.results.length || 0) &&
(isLoading.more ? (
<div className="mx-auto my-4 rounded-md bg-gray-100 p-2 px-4 hover:bg-white">
{t("loading")}
</div>
) : (
<button
onClick={(_) => handlePagination()}
className="mx-auto my-4 rounded-md bg-gray-100 p-2 px-4 hover:bg-white"
>
More...
</button>
))}
</div>
</div>
);
Expand Down

0 comments on commit 24679b9

Please sign in to comment.