Skip to content

Commit

Permalink
Made Scribe work with Symptoms, Investigations, Diagnosis and Prescri…
Browse files Browse the repository at this point in the history
…ptions (#8183)

* Fixed Symptoms and Diagnosis

* fixes

* fixed bugs

* fixed times, measured at, and rounds type

* fix translation issue

* minor enhancement

* fixed rounds type

* disable scribe

* init

* Added support for Investigations, and Prescriptions

* undo config

* Update src/Components/Scribe/formDetails.ts

* Fix bug related to diagnosis update

* cleanup

* more cleanup

---------

Co-authored-by: Mohammed Nihal <[email protected]>
  • Loading branch information
shivankacker and nihal467 authored Aug 8, 2024
1 parent b552047 commit 12b57b9
Show file tree
Hide file tree
Showing 5 changed files with 510 additions and 105 deletions.
89 changes: 45 additions & 44 deletions src/Components/Common/prescription-builder/InvestigationBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,28 @@ export interface InvestigationBuilderProps<T> {
setInvestigations: React.Dispatch<React.SetStateAction<T[]>>;
}

export default function InvestigationBuilder(
props: InvestigationBuilderProps<InvestigationType>,
) {
const { investigations, setInvestigations } = props;
const [investigationsList, setInvestigationsList] = useState<string[]>([]);
const [activeIdx, setActiveIdx] = useState<number | null>(null);
export const loadInvestigations = async () => {
const fetchInvestigations = async () => {
const { data } = await request(routes.listInvestigations);
return (
data?.results.map(
(investigation) =>
`${investigation.name} -- ${humanizeStrings(
investigation.groups.map((group) => ` ( ${group.name} ) `),
)}`,
) ?? []
);
};

const fetchInvestigationGroups = async () => {
const { data } = await request(routes.listInvestigationGroups);
return data?.results.map((group) => `${group.name} (GROUP)`) ?? [];
};

const invs = await fetchInvestigations();
const groups = await fetchInvestigationGroups();

let additionalStrings: string[] = [];
const additionalInvestigations = [
["Vitals", ["Temp", "Blood Pressure", "Respiratory Rate", "Pulse Rate"]],
[
Expand All @@ -51,57 +67,42 @@ export default function InvestigationBuilder(
],
],
];
additionalInvestigations.forEach((investigation) => {
additionalStrings.push((investigation[0] as string) + " (GROUP)");
additionalStrings = [
...additionalStrings,
...(investigation[1] as string[]).map(
(i: any) => i + " -- ( " + investigation[0] + " )",
),
];
});

return [...groups, ...invs, ...additionalStrings];
};

export default function InvestigationBuilder(
props: InvestigationBuilderProps<InvestigationType>,
) {
const { investigations, setInvestigations } = props;
const [investigationsList, setInvestigationsList] = useState<string[]>([]);
const [activeIdx, setActiveIdx] = useState<number | null>(null);

const setItem = (object: InvestigationType, i: number) => {
setInvestigations(
investigations.map((investigation, index) =>
investigations?.map((investigation, index) =>
index === i ? object : investigation,
),
);
};

useEffect(() => {
loadInvestigations();
const load = async () => setInvestigationsList(await loadInvestigations());
load();
}, []);

const loadInvestigations = async () => {
const invs = await fetchInvestigations();
const groups = await fetchInvestigationGroups();

let additionalStrings: string[] = [];
additionalInvestigations.forEach((investigation) => {
additionalStrings.push((investigation[0] as string) + " (GROUP)");
additionalStrings = [
...additionalStrings,
...(investigation[1] as string[]).map(
(i: any) => i + " -- ( " + investigation[0] + " )",
),
];
});

setInvestigationsList([...groups, ...invs, ...additionalStrings]);
};

const fetchInvestigations = async () => {
const { data } = await request(routes.listInvestigations);
return (
data?.results.map(
(investigation) =>
`${investigation.name} -- ${humanizeStrings(
investigation.groups.map((group) => ` ( ${group.name} ) `),
)}`,
) ?? []
);
};

const fetchInvestigationGroups = async () => {
const { data } = await request(routes.listInvestigationGroups);
return data?.results.map((group) => `${group.name} (GROUP)`) ?? [];
};

return (
<div className="mt-2">
{investigations.map((investigation, i) => {
{investigations?.map((investigation, i) => {
const setFrequency = (frequency: string) => {
setItem(
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useEffect, useState } from "react";
import useSlug from "../../../Common/hooks/useSlug";
import {
ConsultationDiagnosis,
Expand Down Expand Up @@ -83,6 +83,11 @@ interface EditDiagnosesProps {
export const EditDiagnosesBuilder = (props: EditDiagnosesProps) => {
const consultation = useSlug("consultation");
const [diagnoses, setDiagnoses] = useState(props.value);

useEffect(() => {
setDiagnoses(props.value);
}, [props.value]);

return (
<div className={props.className}>
<div className="flex w-full flex-col items-start rounded-lg border border-secondary-400">
Expand Down
140 changes: 135 additions & 5 deletions src/Components/Patient/DailyRounds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import RadioFormField from "../Form/FormFields/RadioFormField";
import request from "../../Utils/request/request";
import routes from "../../Redux/api";
import { Scribe } from "../Scribe/Scribe";
import { DAILY_ROUND_FORM_SCRIBE_DATA } from "../Scribe/formDetails";
import { SCRIBE_FORMS } from "../Scribe/formDetails";
import { DailyRoundsModel } from "./models";
import InvestigationBuilder from "../Common/prescription-builder/InvestigationBuilder";
import { FieldErrorText } from "../Form/FormFields/FormField";
Expand All @@ -45,6 +45,9 @@ import { EncounterSymptomsBuilder } from "../Symptoms/SymptomsBuilder";
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";

const Loading = lazy(() => import("../Common/Loading"));
Expand All @@ -54,6 +57,8 @@ export const DailyRounds = (props: any) => {
const authUser = useAuthUser();
const { goBack } = useAppHistory();
const { facilityId, patientId, consultationId, id } = props;
const [symptomsSeed, setSymptomsSeed] = useState<number>(1);
const [prescriptionSeed, setPrescriptionSeed] = useState(1);

const initForm: any = {
physical_examination_info: "",
Expand Down Expand Up @@ -478,11 +483,129 @@ export const DailyRounds = (props: any) => {
>
<div className="flex w-full justify-end md:m-4">
<Scribe
fields={DAILY_ROUND_FORM_SCRIBE_DATA}
onFormUpdate={(fields) => {
form={SCRIBE_FORMS.daily_round}
onFormUpdate={async (fields) => {
// Symptoms
let rounds_type = fields.rounds_type || state.form.rounds_type;
if (fields.additional_symptoms) {
for (const symptom of fields.additional_symptoms) {
const { res } = await request(SymptomsApi.add, {
pathParams: { consultationId },
body: {
...symptom,
},
});
if (res?.ok) setSymptomsSeed((s) => s + 1);
}
}

// ICD11 Diagnosis
if (fields.icd11_diagnosis) {
for (const diagnosis of fields.icd11_diagnosis) {
// Fetch available diagnoses

const { res: icdRes, data: icdData } = await request(
routes.listICD11Diagnosis,
{
query: { query: diagnosis.diagnosis },
},
);

if (!icdRes?.ok) {
error({
text: "Failed to fetch ICD11 Diagnosis",
});
continue;
}

const availableDiagnosis = icdData?.[0]?.id;

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 (
Object.keys(fields).some((f) =>
[
"investigations",
"icd11_diagnosis",
"additional_symptoms",
"prescriptions",
"prn_prescriptions",
].includes(f),
)
) {
rounds_type = "DOCTORS_LOG";
}

dispatch({
type: "set_form",
form: { ...state.form, ...fields },
form: { ...state.form, ...fields, rounds_type },
});
fields.action !== undefined && setPreviousAction(fields.action);
fields.review_interval !== undefined &&
Expand Down Expand Up @@ -536,6 +659,7 @@ export const DailyRounds = (props: any) => {
<div className="pb-6 md:col-span-2">
<FieldLabel>Symptoms</FieldLabel>
<EncounterSymptomsBuilder
key={symptomsSeed}
onChange={() => {
handleFormFieldChange({
name: "symptoms_dirty",
Expand Down Expand Up @@ -593,7 +717,11 @@ export const DailyRounds = (props: any) => {
<>
<h3 className="mb-6 md:col-span-2">Vitals</h3>

<BloodPressureFormField {...field("bp")} label="Blood Pressure" id="bloodPressure" />
<BloodPressureFormField
{...field("bp")}
label="Blood Pressure"
id="bloodPressure"
/>

<RangeAutocompleteFormField
{...field("pulse")}
Expand Down Expand Up @@ -759,6 +887,7 @@ export const DailyRounds = (props: any) => {
discontinued={
showDiscontinuedPrescriptions ? undefined : false
}
key={prescriptionSeed}
actions={["discontinue"]}
/>
</div>
Expand All @@ -783,6 +912,7 @@ export const DailyRounds = (props: any) => {
showDiscontinuedPrescriptions ? undefined : false
}
actions={["discontinue"]}
key={prescriptionSeed}
/>
</div>
</div>
Expand Down
Loading

0 comments on commit 12b57b9

Please sign in to comment.