diff --git a/public/config.json b/public/config.json index 74a665c6ded..678e218070c 100644 --- a/public/config.json +++ b/public/config.json @@ -23,6 +23,6 @@ "sample_format_external_result_import": "/External-Results-Template.csv", "enable_abdm": true, "enable_hcx": false, - "enable_scribe": true, + "enable_scribe": false, "min_encounter_date": "2020-01-01" } \ No newline at end of file diff --git a/src/Components/Patient/DailyRounds.tsx b/src/Components/Patient/DailyRounds.tsx index 261f02263ed..38285e1fe5b 100644 --- a/src/Components/Patient/DailyRounds.tsx +++ b/src/Components/Patient/DailyRounds.tsx @@ -49,6 +49,9 @@ import SymptomsApi from "../Symptoms/api"; import DiagnosesRoutes from "../Diagnosis/routes"; import MedicineRoutes from "../Medicine/routes"; import { scrollTo } from "../../Utils/utils"; +import useQuery from "../../Utils/request/useQuery"; +import { EncounterSymptom } from "../Symptoms/types"; +import _ from "lodash"; const Loading = lazy(() => import("../Common/Loading")); @@ -100,6 +103,12 @@ export const DailyRounds = (props: any) => { errors: { ...initError }, }; + const { data: additionalSymptoms, refetch: refetchAdditionalSymptoms } = + useQuery(SymptomsApi.list, { + pathParams: { consultationId }, + query: { limit: 100 }, + }); + const DailyRoundsFormReducer = (state = initialState, action: any) => { switch (action.type) { case "set_form": { @@ -488,26 +497,57 @@ export const DailyRounds = (props: any) => {
{ - const { data } = await request(SymptomsApi.list, { - pathParams: { consultationId }, - query: { limit: 100 }, - }); - return state.form; + existingData={{ + ...state.form, + additional_symptoms: additionalSymptoms?.results.filter( + (s) => s.clinical_impression_status !== "entered-in-error", + ), }} onFormUpdate={async (fields) => { // Symptoms let rounds_type = fields.rounds_type || state.form.rounds_type; + const existingSymptoms = additionalSymptoms?.results.filter( + (s) => s.clinical_impression_status !== "entered-in-error", + ); + if (fields.additional_symptoms) { + const coveredSymptoms: EncounterSymptom[] = []; for (const symptom of fields.additional_symptoms) { - const { res } = await request(SymptomsApi.add, { - pathParams: { consultationId }, - body: { - ...symptom, - }, + const existingSymptom = existingSymptoms?.find( + (s) => s.symptom === symptom.symptom, + ); + // Check if symptom is altered or added + if (!_.isEqual(symptom, existingSymptom)) { + if (existingSymptom) { + // symptom was altered + await request(SymptomsApi.partialUpdate, { + pathParams: { consultationId, external_id: symptom.id }, + body: _.pick(symptom, ["onset_date", "cure_date"]), + }); + } else { + // symptom does not exist, so must be added + await request(SymptomsApi.add, { + pathParams: { consultationId }, + body: { + ...symptom, + }, + }); + } + } + coveredSymptoms.push(symptom); + } + // check for deleted symptoms + const deletedSymptoms = + existingSymptoms?.filter( + (s) => !coveredSymptoms.find((c) => c.symptom === s.symptom), + ) || []; + for (const symptom of deletedSymptoms) { + //symptom was deleted + await request(SymptomsApi.markAsEnteredInError, { + pathParams: { consultationId, external_id: symptom.id }, }); - if (res?.ok) setSymptomsSeed((s) => s + 1); } + setSymptomsSeed((s) => s + 1); } // ICD11 Diagnosis @@ -676,6 +716,7 @@ export const DailyRounds = (props: any) => { name: "symptoms_dirty", value: true, }); + refetchAdditionalSymptoms(); }} />
diff --git a/src/Components/Scribe/Scribe.tsx b/src/Components/Scribe/Scribe.tsx index 19e3e19d9a7..8e042f177d2 100644 --- a/src/Components/Scribe/Scribe.tsx +++ b/src/Components/Scribe/Scribe.tsx @@ -67,7 +67,6 @@ export const Scribe: React.FC = ({ form, onFormUpdate, existingData, - context, }) => { const { enable_scribe } = useConfig(); const [open, setOpen] = useState(false); @@ -421,10 +420,10 @@ export const Scribe: React.FC = ({ .join(" "); }; - const getOptionText = (value: string | number): string => { - if (!options) return value.toString(); + const getOptionText = (value: string | number | null): string => { + if (!options) return value?.toString() || ""; const option = options.find((opt) => opt.id === value); - return option ? option.text : value.toString(); + return option ? option.text : value?.toString() || ""; }; const renderPrimitive = (value: any): any => {