Skip to content

Commit

Permalink
Soorya | 1206804233224150 | Ward level filter (#162)
Browse files Browse the repository at this point in the history
* Add total and my patients filter

* Phani : Update css for hover

* Update summary api to get the my patients count

* Refresh the summary api on click of bookmark icon

* Add filter feature for ward level dashboard

* Handle Filter for tasks in ward

* Update snapshot

* fix. mock issue in test

* Skipping the testcases for now(Axios Error)

* Skipping the test suite for now(Axios Error)

* Fix the Axios error

* Add total and my patients filter

* Phani : Update css for hover

* Update summary api to get the my patients count

* Refresh the summary api on click of bookmark icon

* Add filter feature for ward level dashboard

* Handle Filter for tasks in ward

* Update snapshot

* fix. mock issue in test

* Fix the duplicate

* Push the string literals to a constant file, fix css and test

* Fix PR comments and css fix for CareView patients error and header

* Remove unused css

---------

Co-authored-by: Phanindra-tw <v.tadikonda@thoughtworks.com>
Co-authored-by: Arjun-Go <arjun.g@thoughtworks.com>
  • Loading branch information
3 people committed Apr 3, 2024
1 parent 4a4e61b commit bb044fe
Show file tree
Hide file tree
Showing 25 changed files with 1,902 additions and 156 deletions.
2 changes: 1 addition & 1 deletion public/i18n/locale_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"NOT_CURRENT_SHIFT_MESSAGE": "You're not viewing the current shift",
"COMPLETED": "Completed",
"MY_PATIENTS": "My patient(s)",
"TOTAL_PATIENTS": "Total patients",
"TOTAL_PATIENTS": "Total patient(s)",
"TOTAL_TEXT": "Total",
"CURRENT_PERIOD": "Current Period",
"NOT_CURRENT_PERIOD_MESSAGE": "You're not viewing the current period",
Expand Down
8 changes: 8 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export const ENCOUNTER_TYPE_URL = RESTWS_V1 + "/encountertype/{encounterType}";
export const LIST_OF_WARDS_URL = RESTWS_V1 + "/admissionLocation";
export const WARD_SUMMARY_URL = RESTWS_V1 + "/ipd/wards/{wardId}/summary";
export const GET_PATIENT_LIST_URL = RESTWS_V1 + "/ipd/wards/{wardId}/patients";
export const GET_MY_PATIENT_LIST_URL =
RESTWS_V1 + "/ipd/wards/{wardId}/myPatients";
export const CARE_VIEW_DASHBOARD_CONFIG_URL =
hostUrl + "/bahmni_config/openmrs/apps/careViewDashboard/app.json";
export const GET_SEARCH_PATIENT_LIST_URL =
Expand All @@ -88,6 +90,8 @@ export const INTAKE_OUTPUT_DATA_BASE_URL =
BAHMNI_CORE + "/observations?";
export const NON_MEDICATION_BASE_URL = RESTWS_V1 + "/tasks";

export const GET_TASKS_FOR_PATIENTS_URL = RESTWS_V1 + "/tasks";

export const defaultDateFormat = "DD MMM YYYY";
export const defaultDateTimeFormat = "DD MMM YYYY hh:mm a";
export const dateFormat = "DD/MM/YYYY";
Expand Down Expand Up @@ -122,3 +126,7 @@ export const MOBILE_BREAKPOINT = 480;
export const TABLET_BREAKPOINT = 1024;

export const IPD_PAGE_TITLE = "IPD";
export const WARD_SUMMARY_HEADER = {
TOTAL_PATIENTS: "TOTAL_PATIENTS",
MY_PATIENTS: "MY_PATIENTS",
};
14 changes: 13 additions & 1 deletion src/entries/CareViewDashboard/CareViewDashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ import { CareViewSummary } from "../../features/CareViewSummary/components/CareV
import { CareViewPatients } from "../../features/CareViewPatients/components/CareViewPatients";
import { FormattedMessage } from "react-intl";
import { I18nProvider } from "../../features/i18n/I18nProvider";
import { homePageUrl } from "../../constants";
import { homePageUrl, WARD_SUMMARY_HEADER } from "../../constants";
import { CareViewContext } from "../../context/CareViewContext";
import { getConfigForCareViewDashboard } from "./CareViewDashboardUtils";
import { getDashboardConfig } from "../../utils/CommonUtils";

const CareViewDashboard = (props) => {
const { hostApi, hostData } = props;
const [selectedWard, setSelectedWard] = useState({});
const [headerSelected, setHeaderSelected] = useState(
WARD_SUMMARY_HEADER.TOTAL_PATIENTS
);
const [isLoading, setIsLoading] = useState(false);
const [refreshPatientList, setRefreshPatientList] = useState(false);
const [refreshSummary, setRefreshSummary] = useState(false);
const [wardSummary, setWardSummary] = useState({});
const [careViewConfig, setCareViewConfig] = useState({});
const [ipdConfig, setIpdConfig] = useState({});
Expand All @@ -31,6 +35,10 @@ const CareViewDashboard = (props) => {
setRefreshPatientList(!refreshPatientList);
};

const handleRefreshSummary = () => {
setRefreshSummary(!refreshSummary);
};

const getIpdConfig = async () => {
const configData = await getDashboardConfig();
const config = configData.data || {};
Expand Down Expand Up @@ -67,6 +75,10 @@ const CareViewDashboard = (props) => {
handleRefreshPatientList,
careViewConfig,
ipdConfig,
headerSelected,
setHeaderSelected,
refreshSummary,
handleRefreshSummary,
}}
>
<div className="care-view-navigations">
Expand Down
139 changes: 137 additions & 2 deletions src/entries/CareViewDashboard/CareViewDashboard.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,57 @@
import React from "react";
import { render, waitFor } from "@testing-library/react";
import {
render,
waitFor,
screen,
within,
fireEvent,
} from "@testing-library/react";
import CareViewDashboard from "./CareViewDashboard";
import { CareViewContext } from "../../context/CareViewContext";
import { mockWardList } from "../../features/CareViewSummary/tests/CareViewSummaryMock";
import {
mockWithBookMarkPatientList,
mockWithMyPatientList,
} from "../../features/CareViewPatientsSummary/tests/CareViewPatientsSummaryMock";
import MockDate from "mockdate";
import { WARD_SUMMARY_HEADER } from "../../constants";

const mockConfig = jest.fn();
const mockGetWardDetails = jest.fn();
const mockFetchWardSummary = jest.fn();
const mockGetSliderPerView = jest.fn();
const mockFetchPatientsList = jest.fn();
const mockGetSlotsForPatients = jest.fn();
const mockGetTasksForPatients = jest.fn();

jest.mock("../../features/CareViewSummary/utils/CareViewSummary", () => {
return {
getWardDetails: () => mockGetWardDetails(),
fetchWardSummary: () => mockFetchWardSummary(),
getSlidesPerView: () => mockGetSliderPerView(),
getSlotsForPatients: () => mockGetSlotsForPatients(),
getTasksForPatients: () => mockGetTasksForPatients(),
};
});

jest.mock("../../features/CareViewPatients/utils/CareViewPatientsUtils", () => {
return {
fetchPatientsList: () => mockFetchPatientsList(),
};
});

const mockContext = {
selectedWard: { label: "ward", uuid: "uuid" },
setSelectedWard: jest.fn,
wardSummary: {
totalPatients: 5,
totalProviderPatients: 2,
},
setWardSummary: jest.fn,
headerSelected: WARD_SUMMARY_HEADER.TOTAL_PATIENTS,
setHeaderSelected: jest.fn(),
provider: { uuid: "provider-uuid" },
};

jest.mock("swiper/react", () => ({
Swiper: ({ children }) => children,
Expand All @@ -30,8 +78,20 @@ describe("CareViewDashboard", () => {
defaultPageSize: 10,
timeframeLimitInHours: 2,
});

MockDate.set("2023-01-01T12:00:00");
mockFetchPatientsList.mockResolvedValueOnce({
status: 200,
data: mockWithBookMarkPatientList,
});
mockGetTasksForPatients.mockReturnValue([]);
mockGetWardDetails.mockReturnValue(mockWardList);
mockFetchWardSummary.mockReturnValue({
status: 200,
data: {
totalPatients: 5,
totalProviderPatients: 2,
},
});
});

it("should match the snapshot", async () => {
Expand All @@ -56,4 +116,79 @@ describe("CareViewDashboard", () => {
expect(getByLabelText("home-button")).toBeTruthy();
});
});

it("should render the total patients with the patient list", async () => {
mockFetchPatientsList.mockResolvedValueOnce({
status: 200,
data: mockWithBookMarkPatientList,
});
const { container, getByLabelText } = render(
<CareViewContext.Provider value={mockContext}>
<CareViewDashboard
hostData={{ provider: "c61c0d60-b483-4c6a-ad97-8cdec7d48b08" }}
/>
</CareViewContext.Provider>
);
await waitFor(() => {
expect(getByLabelText("home-button")).toBeTruthy();
});

const totalPatientsSummary = container.querySelector(
".bx--tile.summary-tile.selected-header"
);
expect(
within(totalPatientsSummary).getByText(/Total patient/i)
).toBeTruthy();
expect(within(totalPatientsSummary).getByText(/5/i)).toBeTruthy();

await waitFor(() => {
const patientRow = container.querySelectorAll(
".care-view-patient-details"
);
expect(patientRow).toHaveLength(5);
expect(within(patientRow[0]).getByText(/PT55746/i)).toBeTruthy();
expect(within(patientRow[1]).getByText(/PT51187/i)).toBeTruthy();
expect(within(patientRow[3]).getByText(/PT49722/i)).toBeTruthy();
});
});

it("should render the my patients with the my patient list", async () => {
mockFetchPatientsList
.mockResolvedValueOnce({
status: 200,
data: mockWithBookMarkPatientList,
})
.mockResolvedValue({
status: 200,
data: mockWithMyPatientList,
});
const { container, getByLabelText } = render(
<CareViewContext.Provider value={mockContext}>
<CareViewDashboard
hostData={{ provider: "c61c0d60-b483-4c6a-ad97-8cdec7d48b08" }}
/>
</CareViewContext.Provider>
);
await waitFor(() => {
expect(getByLabelText("home-button")).toBeTruthy();
});
screen.debug();

fireEvent.click(screen.getByText(/My patient/i));

const myPatientsSummary = container.querySelector(
".bx--tile.summary-tile.selected-header"
);
expect(within(myPatientsSummary).getByText(/My patient/i)).toBeTruthy();
expect(within(myPatientsSummary).getByText(/2/i)).toBeTruthy();

await waitFor(() => {
const patientRow = container.querySelectorAll(
".care-view-patient-details"
);
expect(patientRow).toHaveLength(2);
expect(within(patientRow[0]).getByText(/PT55746/i)).toBeTruthy();
expect(within(patientRow[1]).getByText(/PT51187/i)).toBeTruthy();
});
});
});
Loading

0 comments on commit bb044fe

Please sign in to comment.