diff --git a/src/components/Questionnaire/QuestionTypes/DiagnosisQuestion.tsx b/src/components/Questionnaire/QuestionTypes/DiagnosisQuestion.tsx index 9f6ab12a8a7..71db5800a5c 100644 --- a/src/components/Questionnaire/QuestionTypes/DiagnosisQuestion.tsx +++ b/src/components/Questionnaire/QuestionTypes/DiagnosisQuestion.tsx @@ -1,21 +1,20 @@ -import { PlusIcon, TrashIcon } from "@radix-ui/react-icons"; -import { useState } from "react"; +import { + DotsVerticalIcon, + MinusCircledIcon, + Pencil2Icon, +} from "@radix-ui/react-icons"; +import React, { useState } from "react"; import { Button } from "@/components/ui/button"; import { - Command, - CommandEmpty, - CommandGroup, - CommandInput, - CommandItem, - CommandList, -} from "@/components/ui/command"; + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuSeparator, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu"; +import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; -import { - Popover, - PopoverContent, - PopoverTrigger, -} from "@/components/ui/popover"; import { Select, SelectContent, @@ -23,91 +22,70 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select"; -import { - Table, - TableBody, - TableCell, - TableHead, - TableHeader, - TableRow, -} from "@/components/ui/table"; -import routes from "@/Utils/request/api"; -import useQuery from "@/Utils/request/useQuery"; +import ValueSetSelect from "@/components/Questionnaire/ValueSetSelect"; + +import { Code } from "@/types/questionnaire/code"; import { DIAGNOSIS_CLINICAL_STATUS, DIAGNOSIS_VERIFICATION_STATUS, - type Diagnosis, + Diagnosis, } from "@/types/questionnaire/diagnosis"; -import type { QuestionnaireResponse } from "@/types/questionnaire/form"; +import { QuestionnaireResponse } from "@/types/questionnaire/form"; +import { Question } from "@/types/questionnaire/question"; interface DiagnosisQuestionProps { - question: any; + question: Question; questionnaireResponse: QuestionnaireResponse; updateQuestionnaireResponseCB: (response: QuestionnaireResponse) => void; disabled?: boolean; } +const DIAGNOSIS_INITIAL_VALUE: Partial = { + code: { code: "", display: "", system: "" }, + clinical_status: "active", + verification_status: "confirmed", + onset: { onset_datetime: new Date().toISOString().split("T")[0] }, +}; + export function DiagnosisQuestion({ question, questionnaireResponse, updateQuestionnaireResponseCB, disabled, }: DiagnosisQuestionProps) { - const [diagnoses, setDiagnoses] = useState(() => { - return (questionnaireResponse.values?.[0]?.value as Diagnosis[]) || []; - }); - - const diagnosisSearch = useQuery(routes.valueset.expand, { - pathParams: { system: "system-condition-code" }, - body: { count: 10 }, - prefetch: false, - }); + const diagnoses = + (questionnaireResponse.values?.[0]?.value as Diagnosis[]) || []; - const handleAddDiagnosis = () => { + const handleAddDiagnosis = (code: Code) => { const newDiagnoses = [ ...diagnoses, - { code: { code: "", display: "", system: "" } } as Diagnosis, - ]; - setDiagnoses(newDiagnoses); + { ...DIAGNOSIS_INITIAL_VALUE, code }, + ] as Diagnosis[]; updateQuestionnaireResponseCB({ ...questionnaireResponse, - values: [ - { - type: "diagnosis", - value: newDiagnoses, - }, - ], + values: [{ type: "diagnosis", value: newDiagnoses }], }); }; const handleRemoveDiagnosis = (index: number) => { const newDiagnoses = diagnoses.filter((_, i) => i !== index); - setDiagnoses(newDiagnoses); updateQuestionnaireResponseCB({ ...questionnaireResponse, - values: [ - { - type: "diagnosis", - value: newDiagnoses, - }, - ], + values: [{ type: "diagnosis", value: newDiagnoses }], }); }; - const updateDiagnosis = (index: number, updates: Partial) => { + const handleUpdateDiagnosis = ( + index: number, + updates: Partial, + ) => { const newDiagnoses = diagnoses.map((diagnosis, i) => i === index ? { ...diagnosis, ...updates } : diagnosis, ); - setDiagnoses(newDiagnoses); updateQuestionnaireResponseCB({ ...questionnaireResponse, - values: [ - { - type: "diagnosis", - value: newDiagnoses, - }, - ], + values: [{ type: "diagnosis", value: newDiagnoses }], }); }; @@ -117,183 +95,205 @@ export function DiagnosisQuestion({ {question.text} {question.required && *} -
-
- - - - Diagnosis - Clinical Status - Verification - Onset Date - Note - - - - - {diagnoses.map((diagnosis, index) => ( - - - - - - - - 1}> - - diagnosisSearch.refetch({ body: { search } }) - } - /> - - - {diagnosisSearch.loading - ? "Loading..." - : "No diagnoses found"} - - - {diagnosisSearch.data?.results.map( - (option) => - option.code && ( - { - updateDiagnosis(index, { - code: { - code: option.code, - display: option.display || "", - system: option.system || "", - }, - }); - }} - > - {option.display} - - ), - )} - - - - - - - - - - - - - - - updateDiagnosis(index, { - onset: { - onset_datetime: e.target.value, - }, - }) - } - disabled={disabled} - /> - - - - updateDiagnosis(index, { note: e.target.value }) - } - disabled={disabled} - /> - - - - - - ))} - -
+ {diagnoses.length > 0 && ( +
+
+
Diagnosis
+
Onset Date
+
Status
+
Verification
+
Action
+
+
+ {diagnoses.map((diagnosis, index) => ( + handleUpdateDiagnosis(index, updates)} + onRemove={() => handleRemoveDiagnosis(index)} + /> + ))} +
- -
+ )} +
); } + +interface DiagnosisItemProps { + diagnosis: Diagnosis; + disabled?: boolean; + onUpdate?: (diagnosis: Partial) => void; + onRemove?: () => void; +} + +const DiagnosisItem: React.FC = ({ + diagnosis, + disabled, + onUpdate, + onRemove, +}) => { + const [showNotes, setShowNotes] = useState(false); + + return ( +
+
+
+
+ {diagnosis.code.display} +
+
+ + + + + + setShowNotes(!showNotes)}> + + {showNotes ? "Hide Notes" : "Add Notes"} + + + + + Remove Diagnosis + + + +
+
+
+
+ + + onUpdate?.({ + onset: { onset_datetime: e.target.value }, + }) + } + disabled={disabled} + className="h-8 md:h-9" + /> +
+
+ + +
+
+ + +
+
+
+ + + + + + setShowNotes(!showNotes)}> + + {showNotes ? "Hide Notes" : "Add Notes"} + + + + + Remove Diagnosis + + + +
+
+ {showNotes && ( +
+ onUpdate?.({ note: e.target.value })} + disabled={disabled} + /> +
+ )} +
+ ); +}; diff --git a/src/components/Questionnaire/QuestionTypes/SymptomQuestion.tsx b/src/components/Questionnaire/QuestionTypes/SymptomQuestion.tsx index f154b167004..0d3a6db503f 100644 --- a/src/components/Questionnaire/QuestionTypes/SymptomQuestion.tsx +++ b/src/components/Questionnaire/QuestionTypes/SymptomQuestion.tsx @@ -147,7 +147,12 @@ const SymptomItem: React.FC = ({
-
{symptom.code.display}
+
+ {symptom.code.display} +