From c891f402b7c984855fe576fd17117772d7ba9bdb Mon Sep 17 00:00:00 2001 From: rash-27 Date: Fri, 22 Mar 2024 18:42:45 +0530 Subject: [PATCH] update age format in Patientinfocard --- src/Components/Patient/PatientInfoCard.tsx | 11 ++++++++--- src/Utils/utils.ts | 5 ++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Components/Patient/PatientInfoCard.tsx b/src/Components/Patient/PatientInfoCard.tsx index e91ce645626..6ee5a921a56 100644 --- a/src/Components/Patient/PatientInfoCard.tsx +++ b/src/Components/Patient/PatientInfoCard.tsx @@ -15,7 +15,12 @@ import { useState } from "react"; import CareIcon from "../../CAREUI/icons/CareIcon.js"; import useConfig from "../../Common/hooks/useConfig.js"; import dayjs from "../../Utils/dayjs.js"; -import { classNames, formatDate, formatDateTime } from "../../Utils/utils.js"; +import { + classNames, + formatDate, + formatDateTime, + formatPatientAge, +} from "../../Utils/utils.js"; import ABHAProfileModal from "../ABDM/ABHAProfileModal.js"; import LinkABHANumberModal from "../ABDM/LinkABHANumberModal.js"; import LinkCareContextModal from "../ABDM/LinkCareContextModal.js"; @@ -217,7 +222,7 @@ export default function PatientInfoCard(props: { > {patient.name}
- {patient.age} years • {patient.gender} + {formatPatientAge(patient, true)} • {patient.gender}
{patient.name}
- {patient.age} years • {patient.gender} + {formatPatientAge(patient, true)} • {patient.gender}
diff --git a/src/Utils/utils.ts b/src/Utils/utils.ts index 7ddd67b5ade..b4d6cc9c55f 100644 --- a/src/Utils/utils.ts +++ b/src/Utils/utils.ts @@ -431,9 +431,8 @@ export const formatPatientAge = (obj: PatientModel, abbreviated = false) => { : `Born on ${obj.year_of_birth}`; } - const days = end.diff(start, "years"); - const month = (days / 30) | 0; - const day = days % 30; + const month = end.diff(start, "month"); + const day = end.diff(start.add(month, "month"), "day"); if (month) { return `${month}${suffixes.month} ${day}${suffixes.day}`; }