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

Add suggestion chips instead of autofilling diagnosis #8369

Merged
merged 8 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface AddICD11DiagnosisProps {
onAdd: (object: CreateDiagnosis) => Promise<boolean>;
disallowed: ICD11DiagnosisModel[];
disabled?: boolean;
prefill?: ICD11DiagnosisModel;
setPrefill?: (prefill?: ICD11DiagnosisModel) => void;
}

export default function AddICD11Diagnosis(props: AddICD11DiagnosisProps) {
Expand All @@ -36,6 +38,10 @@ export default function AddICD11Diagnosis(props: AddICD11DiagnosisProps) {
}
}, [res?.status]);

useEffect(() => props.prefill && setSelected(props.prefill), [props.prefill]);

useEffect(() => props.setPrefill?.(undefined), [selected]);
Copy link
Member

@khavinshankar khavinshankar Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shivankacker can we remove the second use effect and use a util function like handleSelection which updates both selected and prefill state

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some changes, is that what you meant?


const handleAdd = async (status: CreateDiagnosis["verification_status"]) => {
if (!selected) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import request from "../../../Utils/request/request";
import DiagnosesRoutes from "../routes";
import * as Notification from "../../../Utils/Notifications";
import PrincipalDiagnosisSelect from "./PrincipalDiagnosisSelect";
import CareIcon from "../../../CAREUI/icons/CareIcon";

interface CreateDiagnosesProps {
className?: string;
Expand Down Expand Up @@ -78,11 +79,14 @@ export const CreateDiagnosesBuilder = (props: CreateDiagnosesProps) => {
interface EditDiagnosesProps {
className?: string;
value: ConsultationDiagnosis[];
suggestions?: ICD11DiagnosisModel[];
onUpdate?: (diagnoses: ConsultationDiagnosis[]) => void;
}

export const EditDiagnosesBuilder = (props: EditDiagnosesProps) => {
const consultation = useSlug("consultation");
const [diagnoses, setDiagnoses] = useState(props.value);
const [prefill, setPrefill] = useState<ICD11DiagnosisModel>();

useEffect(() => {
setDiagnoses(props.value);
Expand Down Expand Up @@ -129,16 +133,34 @@ export const EditDiagnosesBuilder = (props: EditDiagnosesProps) => {

if (res?.ok && data) {
setDiagnoses([...diagnoses, data]);
setPrefill(undefined);
props.onUpdate?.(diagnoses);
return true;
}

if (error) {
Notification.Error({ msg: error });
}

return false;
}}
prefill={prefill}
setPrefill={setPrefill}
/>
{!!props.suggestions?.length && (
<div className="mb-4 flex flex-wrap gap-2">
{props.suggestions?.map((suggestion, i) => (
<button
key={i}
className="flex items-center gap-2 rounded-full border border-primary-500 px-4 py-1 text-sm text-primary-500 transition-all hover:bg-primary-400/10"
onClick={() => setPrefill(suggestion)}
type="button"
>
<CareIcon icon="l-heart-medical" />
{suggestion.label}
</button>
))}
</div>
)}
</div>
</div>

Expand Down
89 changes: 14 additions & 75 deletions src/Components/Patient/DailyRounds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ import { FieldLabel } from "../Form/FormFields/FormField";
import useAuthUser from "../../Common/hooks/useAuthUser";
import CheckBoxFormField from "../Form/FormFields/CheckBoxFormField";
import SymptomsApi from "../Symptoms/api";
import DiagnosesRoutes from "../Diagnosis/routes";
import MedicineRoutes from "../Medicine/routes";
import { scrollTo } from "../../Utils/utils";
import { ICD11DiagnosisModel } from "../Facility/models";

const Loading = lazy(() => import("../Common/Loading"));

Expand All @@ -58,7 +57,9 @@ export const DailyRounds = (props: any) => {
const { goBack } = useAppHistory();
const { facilityId, patientId, consultationId, id } = props;
const [symptomsSeed, setSymptomsSeed] = useState<number>(1);
const [prescriptionSeed, setPrescriptionSeed] = useState(1);
const [diagnosisSuggestions, setDiagnosisSuggestions] = useState<
ICD11DiagnosisModel[]
>([]);

const initForm: any = {
physical_examination_info: "",
Expand Down Expand Up @@ -489,6 +490,7 @@ export const DailyRounds = (props: any) => {
<Scribe
form={SCRIBE_FORMS.daily_round}
onFormUpdate={async (fields) => {
setDiagnosisSuggestions([]);
// Symptoms
let rounds_type = fields.rounds_type || state.form.rounds_type;
if (fields.additional_symptoms) {
Expand Down Expand Up @@ -522,74 +524,10 @@ export const DailyRounds = (props: any) => {
continue;
}

const availableDiagnosis = icdData?.[0]?.id;
const availableDiagnosis = icdData?.slice(0, 5);

if (!availableDiagnosis) {
error({
text: "Could not find the requested diagnosis. Please enter manually.",
});
continue;
}

const { res, data } = await request(
DiagnosesRoutes.createConsultationDiagnosis,
{
pathParams: { consultation: consultationId },
body: {
...diagnosis,
diagnosis: availableDiagnosis,
},
},
);

if (res?.ok && data)
setDiagnoses((diagnoses) => [...(diagnoses || []), data]);
}
}

// Prescriptions
if (fields.prescriptions || fields.prn_prescriptions) {
const combined_prescriptions = [
...(fields.prescriptions || []),
...(fields.prn_prescriptions || []),
];
for (const prescription of combined_prescriptions) {
// fetch medicine
const { res: medicineRes, data: medicineData } = await request(
routes.listMedibaseMedicines,
{
query: { query: prescription.medicine },
},
);

if (!medicineRes?.ok) {
error({
text: "Failed to fetch medicine",
});
continue;
}

const availableMedicine = medicineData?.[0]?.id;

if (!availableMedicine) {
error({
text: "Could not find the requested medicine. Please enter manually.",
});
continue;
}

const { res } = await request(
MedicineRoutes.createPrescription,
{
pathParams: { consultation: consultationId },
body: {
...prescription,
medicine: availableMedicine,
},
},
);

if (res?.ok) setPrescriptionSeed((s) => s + 1);
if (availableDiagnosis?.length)
setDiagnosisSuggestions(availableDiagnosis);
}
}

Expand All @@ -598,8 +536,7 @@ export const DailyRounds = (props: any) => {
[
"investigations",
"icd11_diagnosis",
"prescriptions",
"prn_prescriptions",
"additional_symptoms",
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
].includes(f),
) &&
roundTypes.some((t) => t.id === "DOCTORS_LOG")
Expand Down Expand Up @@ -850,7 +787,11 @@ export const DailyRounds = (props: any) => {
</h3>
{/* */}
{diagnoses ? (
<EditDiagnosesBuilder value={diagnoses} />
<EditDiagnosesBuilder
value={diagnoses}
suggestions={diagnosisSuggestions}
onUpdate={() => setDiagnosisSuggestions([])}
/>
) : (
<div className="flex animate-pulse justify-center py-4 text-center font-medium text-secondary-800">
Fetching existing diagnosis of patient...
Expand Down Expand Up @@ -891,7 +832,6 @@ export const DailyRounds = (props: any) => {
discontinued={
showDiscontinuedPrescriptions ? undefined : false
}
key={prescriptionSeed}
actions={["discontinue"]}
/>
</div>
Expand All @@ -916,7 +856,6 @@ export const DailyRounds = (props: any) => {
showDiscontinuedPrescriptions ? undefined : false
}
actions={["discontinue"]}
key={prescriptionSeed}
/>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/Components/Scribe/formDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ const DAILY_ROUND_FORM_SCRIBE_DATA: Field[] = [
});
return true;
},
},
} /*
{
friendlyName: "Prescriptions",
id: "prescriptions",
Expand Down Expand Up @@ -330,7 +330,7 @@ const DAILY_ROUND_FORM_SCRIBE_DATA: Field[] = [
return true;
},
},
/*{
{
friendlyName: "Round Type",
id: "rounds_type",
type: "string",
Expand All @@ -355,7 +355,7 @@ const DAILY_ROUND_FORM_SCRIBE_DATA: Field[] = [
"A string to store the date and time at which the round was taken or measured. 'The round was taken yesterday/today' would amount to yesterday/today's date.",
validator: (value) => typeof value === "string",
},
*/
*/,
];

export const SCRIBE_FORMS: { [key: string]: ScribeForm } = {
Expand Down
Loading