-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
111 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { | ||
ActiveConditionVerificationStatuses, | ||
ConditionVerificationStatus, | ||
ConsultationDiagnosis, | ||
} from "./types"; | ||
import { useTranslation } from "react-i18next"; | ||
import { classNames, compareBy } from "../../Utils/utils"; | ||
import { useState } from "react"; | ||
import CareIcon from "../../CAREUI/icons/CareIcon"; | ||
import ButtonV2 from "../Common/components/ButtonV2"; | ||
|
||
interface Props { | ||
diagnoses: ConsultationDiagnosis[]; | ||
} | ||
|
||
type GroupedDiagnoses = Record< | ||
ConditionVerificationStatus, | ||
ConsultationDiagnosis[] | ||
>; | ||
|
||
function groupDiagnoses(diagnoses: ConsultationDiagnosis[]) { | ||
const groupedDiagnoses = {} as GroupedDiagnoses; | ||
|
||
for (const status of ActiveConditionVerificationStatuses) { | ||
groupedDiagnoses[status] = diagnoses | ||
.filter((d) => d.verification_status === status) | ||
.sort(compareBy("is_principal")); | ||
} | ||
|
||
return groupedDiagnoses; | ||
} | ||
|
||
export default function DiagnosesListAccordion(props: Props) { | ||
const [isVisible, setIsVisible] = useState(true); | ||
const diagnoses = groupDiagnoses(props.diagnoses); | ||
|
||
return ( | ||
<div> | ||
<div className="flex justify-between"> | ||
{!isVisible && ( | ||
<ButtonV2 | ||
className="text-md w-full p-0 font-semibold text-black" | ||
ghost | ||
onClick={() => { | ||
setIsVisible((prev) => !prev); | ||
}} | ||
> | ||
<CareIcon icon="l-angle-down" className="h-7" /> | ||
Expand Diagnoses | ||
</ButtonV2> | ||
)} | ||
</div> | ||
<div | ||
className={classNames("transition-all duration-500 ease-in-out")} | ||
style={ | ||
isVisible | ||
? { | ||
overflow: "visible", | ||
} | ||
: { height: "0px", overflow: "hidden" } | ||
} | ||
> | ||
<h3 className="my-2 text-lg font-semibold leading-relaxed text-gray-900"> | ||
Diagnoses | ||
</h3> | ||
<div className="grid grid-cols-1 items-start gap-2 lg:grid-cols-2 2xl:grid-cols-3"> | ||
{Object.entries(diagnoses).map( | ||
([status, diagnoses]) => | ||
!!diagnoses.length && ( | ||
<DiagnosesOfStatus key={status} diagnoses={diagnoses} /> | ||
) | ||
)} | ||
</div> | ||
<ButtonV2 | ||
className="text-md mt-2 w-full p-0 font-semibold text-black" | ||
ghost | ||
onClick={() => { | ||
setIsVisible(false); | ||
}} | ||
> | ||
<CareIcon icon="l-angle-up" className="h-7" /> | ||
Hide Diagnoses | ||
</ButtonV2> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
const DiagnosesOfStatus = ({ diagnoses }: Props) => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<div> | ||
<h2 className="text-sm font-semibold"> | ||
{t(diagnoses[0].verification_status)} {t("diagnoses")}{" "} | ||
<span>({t("icd11_as_recommended")})</span> | ||
</h2> | ||
<ul className="text-sm"> | ||
{diagnoses.map((diagnosis) => ( | ||
<li key={diagnosis.id} className="flex items-center gap-2"> | ||
<span>{diagnosis.diagnosis_object?.label}</span> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters