Skip to content

Commit

Permalink
made changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sulochan-khadka committed May 15, 2024
1 parent c490eb0 commit 09c0447
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/Components/Patient/PatientInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import DischargeModal from "../Facility/DischargeModal.js";
import { useTranslation } from "react-i18next";
import useQuery from "../../Utils/request/useQuery.js";
import FetchRecordsModal from "../ABDM/FetchRecordsModal.js";
import { SkillModel } from "../Users/models.js";

export default function PatientInfoCard(props: {
patient: PatientModel;
Expand Down Expand Up @@ -120,6 +121,20 @@ export default function PatientInfoCard(props: {
},
prefetch: !!consultation?.treating_physician_object?.username,
});
const getSkillsDescription = (skills: SkillModel[]) => {
if (skills.length === 1) {
return skills[0].skill_object.name;
}
if (skills.length === 2) {
return skills.map((s) => s.skill_object.name).join(" and ");
}
return (
skills
.slice(0, 2)
.map((s) => s.skill_object.name)
.join(", ") + ` and ${skills.length - 2} more`
);
};
return (
<>
<DialogModal
Expand Down Expand Up @@ -467,27 +482,7 @@ export default function PatientInfoCard(props: {
icon="l-check"
className="ml-2 fill-current text-xl text-green-500"
/>
{skills?.results?.slice(0, 2).map((item, index) => (
<div key={index} className="">
{index === 1 ? (
<span className="mr-2">
,{item.skill_object.name}
</span>
) : (
<span className="mr-2">{item.skill_object.name}</span>
)}
</div>
))}
{skills?.results?.slice(2)?.length ?? 0 > 0 ? (
<span>
and {skills?.results?.slice(2)?.length ?? 0 - 2}{" "}
{skills?.results?.length ?? 0 - 2 === 1
? "other skill."
: "other skills."}
</span>
) : (
<span>.</span>
)}
{skills && getSkillsDescription(skills.results)}
</div>
)}
</div>
Expand Down

0 comments on commit 09c0447

Please sign in to comment.