Skip to content

Commit

Permalink
changes from review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak committed Nov 11, 2024
1 parent 1e87eb8 commit da4cf47
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,8 @@ const NursingPlot = ({ consultationId }: ConsultationTabProps) => {
const dataToDisplay = data
.map((x) =>
x.nursing
? x.nursing.map((f: any) => {
f["date"] = x.date;
return f;
? x.nursing.map((f) => {
return { ...f, date: x.date };
})
: [],
)
Expand Down Expand Up @@ -165,7 +164,7 @@ const NursingPlot = ({ consultationId }: ConsultationTabProps) => {
);

const mappedData = dataToDisplay.reduce(
(acc: Record<string, any>, item: any) => {
(acc: Record<string, Record<string, string>>, item) => {
if (!acc[item.date]) acc[item.date] = {};
acc[item.date][item.procedure] = item.description;
return acc;
Expand Down
42 changes: 20 additions & 22 deletions src/components/Facility/Consultations/LogUpdateAnalayseTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { useTranslation } from "react-i18next";
import { classNames, formatDate, formatTime } from "@/Utils/utils";

interface SharedSectionTableProps {
data: Record<string, any>;
data: Record<string, Record<string, string | boolean | null>>;
rows: Array<{ title?: string; field?: string; subField?: boolean }>;
choices?: Record<string, Record<number | string, string>>;
choices?: Record<string, Record<string | number, string>>;
}

const LogUpdateAnalayseTable: React.FC<SharedSectionTableProps> = ({
Expand All @@ -16,26 +16,26 @@ const LogUpdateAnalayseTable: React.FC<SharedSectionTableProps> = ({
}) => {
const { t } = useTranslation();

// Helper function to get the display value
const dataValues = React.useMemo(() => Object.values(data), [data]);

const getDisplayValue = (
value: string | boolean | null | undefined,
field?: string,
): string => {
if (value == null) {
return " ";
}

if (typeof value === "boolean") {
return t(value ? "yes" : "no");
}

if (field && choices[field]) {
const choiceMap = choices[field];
const choice =
choices[field][value as keyof (typeof choices)[typeof field]];
typeof value === "string" || typeof value === "number"
? choiceMap[value]
: undefined;
return choice ? t(`${field.toUpperCase()}__${choice}`) : "-";
}
if (value && typeof value == "string") return value;

return "-";
return typeof value === "string" ? value : "-";
};

return (
Expand All @@ -45,15 +45,13 @@ const LogUpdateAnalayseTable: React.FC<SharedSectionTableProps> = ({
<tr>
<th className="sticky left-0 border-b-2 border-r-2 border-black bg-white"></th>
{Object.keys(data).map((date) => (
<>
<th
key={date}
className="w-40 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>
</>
<th
key={date}
className="w-40 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>
Expand All @@ -73,14 +71,14 @@ const LogUpdateAnalayseTable: React.FC<SharedSectionTableProps> = ({
>
{row.title ?? t(`LOG_UPDATE_FIELD_LABEL__${row.field!}`)}
</th>
{Object.values(data).map((obj, idx) => {
const value = obj[row.field!];
{dataValues.map((obj, idx) => {
const value = row.field ? obj[row.field] : undefined;
return (
<td
key={`${row.field}-${idx}`}
className="w-80 border border-l-2 border-secondary-500 bg-secondary-100 p-2 text-center font-medium"
>
{getDisplayValue(value, row.field)}
{row.field ? getDisplayValue(value, row.field) : "-"}
</td>
);
})}
Expand Down
5 changes: 4 additions & 1 deletion src/components/Facility/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,10 @@ export const NursingPlotFields = [
] as const satisfies (keyof DailyRoundsModel)[];

export type NursingPlotRes = {
nursing: any[];
nursing: Array<{
procedure: string;
description: string;
}>;
};

export const RoutineFields = [
Expand Down

0 comments on commit da4cf47

Please sign in to comment.