Skip to content

Commit

Permalink
update age format in Patientinfocard
Browse files Browse the repository at this point in the history
  • Loading branch information
rash-27 committed Mar 22, 2024
1 parent 154e910 commit c891f40
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/Components/Patient/PatientInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -217,7 +222,7 @@ export default function PatientInfoCard(props: {
>
{patient.name}
<div className="ml-3 mr-2 mt-[6px] text-sm font-semibold text-gray-600">
{patient.age} years{patient.gender}
{formatPatientAge(patient, true)}{patient.gender}
</div>
<div className="mr-3 flex flex-col items-center">
<Link
Expand Down Expand Up @@ -262,7 +267,7 @@ export default function PatientInfoCard(props: {
>
{patient.name}
<div className="ml-3 mr-2 mt-[6px] text-sm font-semibold text-gray-600">
{patient.age} years{patient.gender}
{formatPatientAge(patient, true)}{patient.gender}
</div>
</div>
<div className="flex flex-wrap items-center gap-2 text-sm sm:flex-row">
Expand Down
5 changes: 2 additions & 3 deletions src/Utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
Expand Down

0 comments on commit c891f40

Please sign in to comment.