Skip to content

Commit

Permalink
Merge pull request #63 from Samstar10/fix-patient-list-fetch
Browse files Browse the repository at this point in the history
Fix patient list fetch
  • Loading branch information
Michaelndula authored Aug 21, 2024
2 parents ce703db + c5526c4 commit b465eda
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 96 deletions.
4 changes: 2 additions & 2 deletions packages/esm-patient-list-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sjthc/esm-patient-list-app",
"version": "1.2.3",
"version": "1.2.4",
"license": "MPL-2.0",
"description": "Custom Patient list microfrontend for the OpenMRS SPA",
"browser": "dist/sjthc-esm-patient-list-app.js",
Expand Down Expand Up @@ -60,5 +60,5 @@
"@types/uuid": "^9.0.4",
"webpack": "^5.88.2"
},
"gitHead": "673ad31115e2e9da02ecaa47747c9fad09eb624e"
"gitHead": "dc93f7cfebbe379ad5b7f10b2aaab622e78f9b53"
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React, { useEffect, useState } from "react";
import React, { useState } from "react";
import styles from "./home-dashboard.scss";
import {useTranslation} from "react-i18next";
import PatientQueueIllustration from "./patient-queue-illustration.component";
import MetricsCard from "./dashboard-card/dashboard-card.component";
import {
DatePicker,
DatePickerInput,
Button,
Tile,
SkeletonPlaceholder,
Link,
Expand All @@ -21,7 +20,6 @@ import {
TableCell,
TableToolbar,
TableToolbarContent,
TableToolbarSearch,
Pagination,
Layer
} from "@carbon/react";
Expand All @@ -39,13 +37,8 @@ const PatientListHome: React.FC<PatientListHomeProps> = () => {
const {
isLoading,
data,
tableColumns,
customStyles,
setDateRange,
dateRange,
currentPaginationState,
getAllClients,
clear,
totalPatients,
} = usePatientList();

Expand Down Expand Up @@ -82,7 +75,7 @@ const PatientListHome: React.FC<PatientListHomeProps> = () => {

const rowData = data?.map((patient) => {
return {
id: patient.openmrsID,
id: patient.opdNumber,
fullName: () => (
<Link
href={`${window.getOpenmrsSpaBase()}patient/${
Expand Down
80 changes: 2 additions & 78 deletions packages/esm-patient-list-app/src/hooks/usePatientList.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, {useEffect, useState} from "react";
import {openmrsFetch} from "@openmrs/esm-framework";
import {getPaddedDateString} from "../helpers/dateOps";
import {Link} from "@carbon/react";

export function usePatientList() {
const [data, setData] = useState([]);
const [loading, setLoading] = useState(false);
const [currentPaginationState, setCurrentPaginationState] = useState({
size: 50,
size: 100,
page: 0
});
const [dateRange, setDateRange] = React.useState({
Expand Down Expand Up @@ -63,95 +62,20 @@ export function usePatientList() {
}
}

// useEffect(() => {
// // setData((prev) => {
// // return prev.slice(0, 0);
// // });
// getAllClients({...currentPaginationState})
// }, [dateRange.start, dateRange.end]);

useEffect(() => {
setCurrentPaginationState(prev => ({...prev, page: 0}))
// setData([]);
getAllClients({...currentPaginationState})
}, [dateRange, currentPaginationState.page]);

const tableColumns = [
{
name: "Name",
cell: (row) => (
<Link
href={`${window.getOpenmrsSpaBase()}patient/${
row.uuid
}/chart/Patient%20Summary`}
>
{row.fullName}
</Link>
),
},
{
name: "ID",
selector: (row) => row.openmrsID,
},
{
name: "Gender",
selector: (row) => row.gender,
},
{
name: "Age",
selector: (row) => row.age,
},
{
name: "OPD Number",
selector: (row) => row.opdNumber,
},
{
name: "Date Registered",
selector: (row) => row.dateRegistered,
},
{
name: "Time Registered",
selector: (row) => row.timeRegistered,
},
];

}, [dateRange]);

const clear = () => {
setDateRange({
start: `01-01-${new Date().getFullYear()}`,
end: `${new Date().getDate()}-${new Date().getMonth() + 1}-${new Date().getFullYear()}`
});
setData([]);
getAllClients({...currentPaginationState})
};
const customStyles = {
cells: {
style: {
minHeight: "22px",
fontSize: "14px",
fontWeight: "500",
},
},
headCells: {
style: {
fontSize: ".9rem",
fontWeight: "600",
},
},
};

return {
customStyles,
tableColumns,
data,
patient: data,
isLoading: loading,
dateRange,
setDateRange,
getAllClients,
currentPaginationState,
clear,
totalPatients,
// returnClients
};
}
4 changes: 2 additions & 2 deletions packages/esm-patient-visits-report-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sjthc/esm-patient-visits-report-app",
"version": "1.2.1",
"version": "1.2.2",
"license": "MPL-2.0",
"description": "Custom Patient Visits Reports microfrontend for the OpenMRS SPA",
"browser": "dist/sjthc-esm-patient-visits-report-app.js",
Expand Down Expand Up @@ -60,5 +60,5 @@
"@types/uuid": "^9.0.4",
"webpack": "^5.88.2"
},
"gitHead": "2f0170c033f60ecc53f69fa7e7655e437cc2b395"
"gitHead": "81ac4421d6e276613f81e351c9f0512c27d26d20"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect, useRef, useState} from "react";
import React, {useEffect, useMemo, useRef, useState} from "react";
import styles from "./home-dashboard.scss";
import {useTranslation} from "react-i18next";
import PatientQueueIllustration from "./patient-queue-illustration.component";
Expand Down Expand Up @@ -87,7 +87,7 @@ const PatientVisitsReportHome: React.FC<PatientVisistsReportHomeProps> = () => {

const rowData = filteredData?.map((patient) => {
return {
id: patient.openmrsID,
id: patient.opdNumber,
fullName: () => (
<Link
href={`${window.getOpenmrsSpaBase()}patient/${
Expand All @@ -103,7 +103,7 @@ const PatientVisitsReportHome: React.FC<PatientVisistsReportHomeProps> = () => {
opdNumber: patient.opdNumber,
diagnosis: patient.diagnosis,
}
}) || [];
})

const paginatedData = rowData?.slice(
(currentPage - 1) * itemsPerPage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export function useOPDCategories(initialCategory="outPatientClients") {
let startString = formatDateForReq(dateRange.start);
let endString = formatDateForReq(dateRange.end);

const url = `/ws/rest/v1/ehospital/${category}?startDate=${startString}&endDate=${endString}`;
const url = `/ws/rest/v1/ehospital/${category}?startDate=${startString}&endDate=${endString}&page=${page}&size=${size}`;
const {data} = await openmrsFetch(url);
const cardUrl = `/ws/rest/v1/ehospital/outPatientClients?startDate=${startString}&endDate=${endString}`;
const cardUrl = `/ws/rest/v1/ehospital/outPatientClients?startDate=${startString}&endDate=${endString}&page=${page}&size=${size}`;
const {data: cardData} = await openmrsFetch(cardUrl);

setData([])
Expand Down

0 comments on commit b465eda

Please sign in to comment.