Skip to content

Commit

Permalink
add routine view in nursing tab and improve i18n and other minor impr…
Browse files Browse the repository at this point in the history
…ovements
  • Loading branch information
rithviknishad committed Sep 18, 2024
1 parent 8287ab5 commit 307f50a
Show file tree
Hide file tree
Showing 25 changed files with 400 additions and 276 deletions.
2 changes: 1 addition & 1 deletion src/Common/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ export const RHYTHM_CHOICES = [
{ id: 10, text: "IRREGULAR", desc: "Irregular" },
] as const;

export const BOWEL_DIFFICULTY_CHOICES = [
export const BOWEL_ISSUE_CHOICES = [
"NO_DIFFICULTY",
"CONSTIPATION",
"DIARRHOEA",
Expand Down
218 changes: 210 additions & 8 deletions src/Components/Facility/ConsultationDetails/ConsultationNursingTab.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,226 @@
import { lazy } from "react";
import { lazy, useEffect, useState } from "react";
import { ConsultationTabProps } from "./index";
import { NursingPlot } from "../Consultations/NursingPlot";
import { useTranslation } from "react-i18next";
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";

const PageTitle = lazy(() => import("../../Common/PageTitle"));

export const ConsultationNursingTab = (props: ConsultationTabProps) => {
export default function ConsultationNursingTab(props: ConsultationTabProps) {
const { t } = useTranslation();
return (
<div>
<PageTitle
title={t("CONSULTATION_TAB_TITLE__NURSING")}
title={t("nursing_information")}
hideBack
breadcrumbs={false}
/>
<NursingPlot
facilityId={props.facilityId}
patientId={props.patientId}
consultationId={props.consultationId}
/>
<div>
<h4>{t("routine")}</h4>
<RoutineSection {...props} />
</div>
<div>
<h4>{t("nursing_care")}</h4>
<NursingPlot
facilityId={props.facilityId}
patientId={props.patientId}
consultationId={props.consultationId}
/>
</div>
</div>
);
}

const REVERSE_CHOICES = {
appetite: {
1: "INCREASED",
2: "SATISFACTORY",
3: "REDUCED",
4: "NO_TASTE_FOR_FOOD",
5: "CANNOT_BE_ASSESSED",
},
bladder_drainage: {
1: "NORMAL",
2: "CONDOM_CATHETER",
3: "DIAPER",
4: "INTERMITTENT_CATHETER",
5: "CONTINUOUS_INDWELLING_CATHETER",
6: "CONTINUOUS_SUPRAPUBIC_CATHETER",
7: "UROSTOMY",
},
bladder_issue: {
0: "NO_ISSUES",
1: "INCONTINENCE",
2: "RETENTION",
3: "HESITANCY",
},
bowel_issue: {
0: "NO_DIFFICULTY",
1: "CONSTIPATION",
2: "DIARRHOEA",
},
nutrition_route: {
1: "ORAL",
2: "RYLES_TUBE",
3: "GASTROSTOMY_OR_JEJUNOSTOMY",
4: "PEG",
5: "PARENTERAL_TUBING_FLUID",
6: "PARENTERAL_TUBING_TPN",
},
oral_issue: {
0: "NO_ISSUE",
1: "DYSPHAGIA",
2: "ODYNOPHAGIA",
},
is_experiencing_dysuria: {
true: "yes",
false: "no",
},
urination_frequency: {
1: "NORMAL",
2: "DECREASED",
3: "INCREASED",
},
sleep: {
1: "EXCESSIVE",
2: "SATISFACTORY",
3: "UNSATISFACTORY",
4: "NO_SLEEP",
},
} as const;

const RoutineSection = ({ consultationId }: ConsultationTabProps) => {
const { t } = useTranslation();
const [page, setPage] = useState(1);
const [totalCount, setTotalCount] = useState<number>();
const [results, setResults] = useState<Record<string, RoutineAnalysisRes>>();

useEffect(() => {
const getData = async () => {
const { data } = await request(routes.dailyRoundsAnalyse, {
body: { fields: RoutineFields, page },
pathParams: { consultationId },
});
if (!data) {
return;
}
setTotalCount(data.count);
setResults(
Object.fromEntries(
Object.entries(data.results).filter(([_, value]) =>
Object.entries(value).some(([k, v]) => k !== "id" && v != null),
),
) as typeof results,
);
};

getData();
}, [page, consultationId]);

if (results == null) {
return <Loading />;
}

if (Object.keys(results).length === 0) {
return (
<div className="mt-1 w-full rounded-lg border bg-white p-4 shadow">
<div className="flex items-center justify-center text-2xl font-bold text-secondary-500">
{t("no_data_found")}
</div>
</div>
);
}

return (
<div className="pb-8 pt-4">
<div className="m-2 w-fit overflow-hidden rounded-lg border border-black shadow">
<table className="border-collapse overflow-hidden rounded-lg border bg-secondary-100">
<thead className="bg-white shadow">
<tr>
<th className="w-48 border-b-2 border-r-2 border-black" />
{Object.keys(results).map((date) => (
<th
key={date}
className="border border-b-2 border-secondary-500 border-b-black p-1 text-sm font-semibold"
>
<p>{formatDate(date)}</p>
<p>{formatTime(date)}</p>
</th>
))}
</tr>
</thead>
<tbody className="bg-secondary-200">
{[
{ field: "sleep" } as const,
{ field: "bowel_issue" } as const,
{ title: "Bladder" } as const,
{ subField: true, field: "bladder_drainage" } as const,
{ subField: true, field: "bladder_issue" } as const,
{ subField: true, field: "is_experiencing_dysuria" } as const,
{ subField: true, field: "urination_frequency" } as const,
{ title: "Nutrition" } as const,
{ subField: true, field: "nutrition_route" } as const,
{ subField: true, field: "oral_issue" } as const,
{ subField: true, field: "appetite" } as const,
].map((row) => (
<tr
key={row.field ?? row.title}
className={classNames(
row.title && "border-t-2 border-t-secondary-600",
)}
>
<td
className={classNames(
"border border-r-2 border-secondary-500 border-r-black bg-white p-2",
row.subField ? "pl-4 font-medium" : "font-bold",
)}
>
{row.title ?? t(`LOG_UPDATE_FIELD_LABEL__${row.field!}`)}
</td>
{row.field &&
Object.values(results).map((obj, idx) => (
<td
key={`${row.field}-${idx}`}
className={classNames(
"border border-secondary-500 bg-secondary-100 p-2 text-center font-medium",
)}
>
{(() => {
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);
})()}
</td>
))}
</tr>
))}
</tbody>
</table>
</div>

{totalCount != null && totalCount > PAGINATION_LIMIT && (
<div className="mt-4 flex w-full justify-center">
<Pagination
cPage={page}
defaultPerPage={PAGINATION_LIMIT}
data={{ totalCount }}
onChange={setPage}
/>
</div>
)}
</div>
);
};
2 changes: 1 addition & 1 deletion src/Components/Facility/ConsultationDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { triggerGoal } from "../../../Integrations/Plausible";
import useAuthUser from "../../../Common/hooks/useAuthUser";
import { ConsultationUpdatesTab } from "./ConsultationUpdatesTab";
import { ConsultationABGTab } from "./ConsultationABGTab";
import { ConsultationNursingTab } from "./ConsultationNursingTab";
import ConsultationNursingTab from "./ConsultationNursingTab";
import { ConsultationFeedTab } from "./ConsultationFeedTab";
import { ConsultationSummaryTab } from "./ConsultationSummaryTab";
import { ConsultationFilesTab } from "./ConsultationFilesTab";
Expand Down
16 changes: 2 additions & 14 deletions src/Components/Facility/Consultations/ABGPlots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PAGINATION_LIMIT } from "../../../Common/constants";
import { formatDateTime } from "../../../Utils/utils";
import routes from "../../../Redux/api";
import request from "../../../Utils/request/request";
import { ABGPlotsFields } from "../models";

export const ABGPlots = (props: any) => {
const { consultationId } = props;
Expand All @@ -15,20 +16,7 @@ export const ABGPlots = (props: any) => {
useEffect(() => {
const fetchDailyRounds = async (currentPage: number) => {
const { res, data } = await request(routes.dailyRoundsAnalyse, {
body: {
page: currentPage,
fields: [
"ph",
"pco2",
"po2",
"hco3",
"base_excess",
"lactate",
"sodium",
"potassium",
"ventilator_fio2",
],
},
body: { page: currentPage, fields: ABGPlotsFields },
pathParams: {
consultationId,
},
Expand Down
6 changes: 2 additions & 4 deletions src/Components/Facility/Consultations/DialysisPlots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { LinePlot } from "./components/LinePlot";
import Pagination from "../../Common/Pagination";
import { PAGINATION_LIMIT } from "../../../Common/constants";
import { formatDateTime } from "../../../Utils/utils";
import { DialysisPlotsFields } from "../models";

export const DialysisPlots = (props: any) => {
const { consultationId } = props;
Expand All @@ -15,10 +16,7 @@ export const DialysisPlots = (props: any) => {
useEffect(() => {
const fetchDailyRounds = async (currentPage: number) => {
const { res, data } = await request(routes.dailyRoundsAnalyse, {
body: {
page: currentPage,
fields: ["dialysis_fluid_balance", "dialysis_net_balance"],
},
body: { page: currentPage, fields: DialysisPlotsFields },
pathParams: {
consultationId,
},
Expand Down
24 changes: 2 additions & 22 deletions src/Components/Facility/Consultations/NeurologicalTables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from "../../../Common/constants";
import { formatDateTime } from "../../../Utils/utils";
import { useTranslation } from "react-i18next";
import { NeurologicalTablesFields } from "../models";

const DataTable = (props: any) => {
const { title, data } = props;
Expand Down Expand Up @@ -113,28 +114,7 @@ export const NeurologicalTable = (props: any) => {
consultationId: string,
) => {
const { res, data } = await request(routes.dailyRoundsAnalyse, {
body: {
page: currentPage,
fields: [
"consciousness_level",
"left_pupil_size",
"left_pupil_size_detail",
"right_pupil_size",
"right_pupil_size_detail",
"left_pupil_light_reaction",
"left_pupil_light_reaction_detail",
"right_pupil_light_reaction",
"right_pupil_light_reaction_detail",
"limb_response_upper_extremity_right",
"limb_response_upper_extremity_left",
"limb_response_lower_extremity_left",
"limb_response_lower_extremity_right",
"glasgow_eye_open",
"glasgow_verbal_response",
"glasgow_motor_response",
"glasgow_total_calculated",
],
},
body: { page: currentPage, fields: NeurologicalTablesFields },
pathParams: {
consultationId,
},
Expand Down
8 changes: 3 additions & 5 deletions src/Components/Facility/Consultations/NursingPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import Pagination from "../../Common/Pagination";
import { formatDateTime } from "../../../Utils/utils";
import { useTranslation } from "react-i18next";
import { NursingPlotFields } from "../models";

export const NursingPlot = ({ consultationId }: any) => {
const { t } = useTranslation();
Expand All @@ -22,10 +23,7 @@ export const NursingPlot = ({ consultationId }: any) => {
consultationId: string,
) => {
const { res, data } = await request(routes.dailyRoundsAnalyse, {
body: {
page: currentPage,
fields: ["nursing"],
},
body: { page: currentPage, fields: NursingPlotFields },
pathParams: {
consultationId,
},
Expand Down Expand Up @@ -81,7 +79,7 @@ export const NursingPlot = ({ consultationId }: any) => {
{areFieldsEmpty() && (
<div className="mt-1 w-full rounded-lg border bg-white p-4 shadow">
<div className="flex items-center justify-center text-2xl font-bold text-secondary-500">
No data available
{t("no_data_found")}
</div>
</div>
)}
Expand Down
13 changes: 2 additions & 11 deletions src/Components/Facility/Consultations/NutritionPlots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Pagination from "../../Common/Pagination";
import { PAGINATION_LIMIT } from "../../../Common/constants";
import { formatDateTime } from "../../../Utils/utils";
import CareIcon from "../../../CAREUI/icons/CareIcon";
import { NutritionPlotsFields } from "../models";

export const NutritionPlots = (props: any) => {
const { consultationId } = props;
Expand All @@ -24,17 +25,7 @@ export const NutritionPlots = (props: any) => {
consultationId: string,
) => {
const { res, data } = await request(routes.dailyRoundsAnalyse, {
body: {
page: currentPage,
fields: [
"infusions",
"iv_fluids",
"feeds",
"total_intake_calculated",
"total_output_calculated",
"output",
],
},
body: { page: currentPage, fields: NutritionPlotsFields },
pathParams: {
consultationId,
},
Expand Down
Loading

0 comments on commit 307f50a

Please sign in to comment.