-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #6544; Principal Diagnosis as Dropdown
- Loading branch information
1 parent
8b48e9b
commit a1e8493
Showing
6 changed files
with
138 additions
and
108 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
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
25 changes: 0 additions & 25 deletions
25
src/Components/Diagnosis/ConsultationDiagnosisBuilder/PrincipalDiagnosisCard.tsx
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
src/Components/Diagnosis/ConsultationDiagnosisBuilder/PrincipalDiagnosisSelect.tsx
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,66 @@ | ||
import { useState } from "react"; | ||
import { | ||
ActiveConditionVerificationStatuses, | ||
ConsultationDiagnosis, | ||
CreateDiagnosis, | ||
} from "../types"; | ||
import { SelectFormField } from "../../Form/FormFields/SelectFormField"; | ||
|
||
type Option = CreateDiagnosis | ConsultationDiagnosis; | ||
|
||
interface Props<T extends Option> { | ||
className?: string; | ||
diagnoses: T[]; | ||
onChange: (value?: T) => Promise<void>; | ||
} | ||
|
||
const PrincipalDiagnosisSelect = <T extends Option>(props: Props<T>) => { | ||
const [disabled, setDisabled] = useState(false); | ||
const value = props.diagnoses.find((d) => d.is_principal); | ||
const diagnosis = value?.diagnosis_object; | ||
|
||
const options = props.diagnoses.some(isConfirmed) | ||
? props.diagnoses.filter(isConfirmedOrPrincipal) | ||
: props.diagnoses.filter(isActive); | ||
|
||
return ( | ||
<div className={props.className}> | ||
<div className="rounded-lg border border-gray-400 bg-gray-200 p-4"> | ||
<SelectFormField | ||
name="principal_diagnosis" | ||
label="Principal Diagnosis" | ||
value={JSON.stringify(value)} | ||
disabled={disabled} | ||
options={options} | ||
optionLabel={(d) => d.diagnosis_object?.label} | ||
optionDescription={(d) => ( | ||
<p> | ||
Categorised under:{" "} | ||
<span className="font-bold">{d.diagnosis_object?.chapter}</span> | ||
</p> | ||
)} | ||
optionValue={(d) => JSON.stringify(d)} // TODO: momentary hack, figure out a better way to do this | ||
onChange={async ({ value }) => { | ||
setDisabled(true); | ||
await props.onChange(value ? (JSON.parse(value) as T) : undefined); | ||
setDisabled(false); | ||
}} | ||
errorClassName="hidden" | ||
/> | ||
{diagnosis && ( | ||
<span className="mt-3 flex w-full flex-wrap justify-center gap-x-1 px-2 text-center text-gray-900"> | ||
<p>This encounter will be categorised under:</p> | ||
<p className="font-bold">{diagnosis.chapter}</p> | ||
</span> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PrincipalDiagnosisSelect; | ||
|
||
const isConfirmed = (d: Option) => d.verification_status === "confirmed"; | ||
const isConfirmedOrPrincipal = (d: Option) => isConfirmed(d) || d.is_principal; | ||
const isActive = (d: Option) => | ||
ActiveConditionVerificationStatuses.includes(d.verification_status as any); |
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
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