diff --git a/src/Components/Facility/ConsultationDetails/ConsultationNursingTab.tsx b/src/Components/Facility/ConsultationDetails/ConsultationNursingTab.tsx index 2f689c82d19..0ce1b5f7370 100644 --- a/src/Components/Facility/ConsultationDetails/ConsultationNursingTab.tsx +++ b/src/Components/Facility/ConsultationDetails/ConsultationNursingTab.tsx @@ -6,9 +6,9 @@ import request from "../../../Utils/request/request"; import routes from "../../../Redux/api"; import { RoutineAnalysisRes, RoutineFields } from "../models"; import Loading from "../../Common/Loading"; -import { classNames, formatDate, formatTime } from "../../../Utils/utils"; import Pagination from "../../Common/Pagination"; import { PAGINATION_LIMIT } from "../../../Common/constants"; +import SharedSectionTable from "../Consultations/components/SharedTable"; const PageTitle = lazy(() => import("../../Common/PageTitle")); @@ -153,65 +153,13 @@ const RoutineSection = ({ consultationId }: ConsultationTabProps) => { return (
-
- - - - - ))} - - - - {ROUTINE_ROWS.map((row) => ( - - - {row.field && - Object.values(results).map((obj, idx) => ( - - ))} - - ))} - -
- {Object.keys(results).map((date) => ( - -

{formatDate(date)}

-

{formatTime(date)}

-
- {row.title ?? t(`LOG_UPDATE_FIELD_LABEL__${row.field!}`)} - - {(() => { - const value = obj[row.field]; - if (value == null) { - return "-"; - } - if (typeof value === "boolean") { - return t(value ? "yes" : "no"); - } - const choices = REVERSE_CHOICES[row.field]; - const choice = `${row.field.toUpperCase()}__${choices[value as keyof typeof choices]}`; - return t(choice); - })()} -
-
+ {totalCount != null && totalCount > PAGINATION_LIMIT && (
diff --git a/src/Components/Facility/Consultations/NursingPlot.tsx b/src/Components/Facility/Consultations/NursingPlot.tsx index c747ec60d26..850d215f469 100644 --- a/src/Components/Facility/Consultations/NursingPlot.tsx +++ b/src/Components/Facility/Consultations/NursingPlot.tsx @@ -5,7 +5,7 @@ import { NURSING_CARE_PROCEDURES, PAGINATION_LIMIT, } from "../../../Common/constants"; - +import SharedSectionTable from "./components/SharedTable"; import Pagination from "../../Common/Pagination"; import { formatDateTime } from "../../../Utils/utils"; import { useTranslation } from "react-i18next"; @@ -71,50 +71,42 @@ export const NursingPlot = ({ consultationId }: any) => { else return false; }; + const rows = NURSING_CARE_PROCEDURES.filter((f) => filterEmpty(f)).map( + (procedure) => ({ + field: procedure, + title: t(`NURSING_CARE_PROCEDURE__${procedure}`), + }), + ); + + const mappedData = dataToDisplay.reduce( + (acc: Record, item: any) => { + if (!acc[item.date]) acc[item.date] = {}; + acc[item.date][item.procedure] = item.description; + return acc; + }, + {}, + ); + return (
-
- {areFieldsEmpty() && ( -
-
- {t("no_data_found")} -
+ {areFieldsEmpty() && ( +
+
+ {t("no_data_found")}
- )} - {NURSING_CARE_PROCEDURES.map( - (f) => - filterEmpty(f) && ( -
-
-
-

- {t(`NURSING_CARE_PROCEDURE__${f}`)} -

-
-
-
- {dataToDisplay - .filter((i: any) => i.procedure === f) - .map((care: any, index: number) => ( -
-
- {care.date} -
-
- {care.description} -
-
- ))} -
-
- ), - )} -
+
+ )} + + {!areFieldsEmpty() && ( + + )}
diff --git a/src/Components/Facility/Consultations/components/SharedTable.tsx b/src/Components/Facility/Consultations/components/SharedTable.tsx new file mode 100644 index 00000000000..c65cffac608 --- /dev/null +++ b/src/Components/Facility/Consultations/components/SharedTable.tsx @@ -0,0 +1,73 @@ +import React from "react"; +import { formatDate, formatTime } from "../../../../Utils/utils"; +import { classNames } from "../../../../Utils/utils"; + +interface SharedSectionTableProps { + data: Record; + rows: Array<{ title?: string; field?: string; subField?: boolean }>; + choices?: Record>; + translateKey: string; + t: (key: string) => string; +} + +const SharedSectionTable: React.FC = ({ + data, + rows, + choices = {}, + translateKey, + t, +}) => { + return ( +
+ + + + + ))} + + + + {rows.map((row) => ( + + + {Object.values(data).map((obj, idx) => ( + + ))} + + ))} + +
+ {Object.keys(data).map((date) => ( + +

{formatDate(date)}

+

{formatTime(date)}

+
+ {row.title ?? t(`${translateKey}__${row.field}`)} + + {row.field + ? choices[row.field] + ? (choices[row.field][obj[row.field]] ?? "-") + : (obj[row.field] ?? "-") + : "-"} +
+
+ ); +}; + +export default SharedSectionTable;