Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show skills of treating doctor in consultation dashboard #7822

Merged
26 changes: 24 additions & 2 deletions src/Components/Patient/PatientInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ import { Mews } from "../Facility/Consultations/Mews.js";
import DischargeSummaryModal from "../Facility/DischargeSummaryModal.js";
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 @@ -113,7 +115,26 @@ export default function PatientInfoCard(props: {

return false;
};

const { data: skills } = useQuery(routes.userListSkill, {
pathParams: {
username: consultation?.treating_physician_object?.username ?? "",
},
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 @@ -450,7 +471,7 @@ export default function PatientInfoCard(props: {
: null}
{(consultation?.treating_physician_object ||
consultation?.deprecated_verified_by) && (
<div className="text-sm" id="treating-physician">
<div className="flex text-sm" id="treating-physician">
<span className="font-semibold leading-relaxed">
{t("treating_doctor")}:{" "}
</span>
Expand All @@ -461,6 +482,7 @@ export default function PatientInfoCard(props: {
icon="l-check"
className="ml-2 fill-current text-xl text-green-500"
/>
{skills && getSkillsDescription(skills.results)}
</div>
)}
</div>
Expand Down
Loading