Skip to content

Commit

Permalink
Fix action field in consultation form
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashesh3 committed Sep 20, 2023
1 parent 97ed8ae commit 26eab22
Showing 1 changed file with 55 additions and 56 deletions.
111 changes: 55 additions & 56 deletions src/Components/Facility/ConsultationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type FormDetails = {
procedure: ProcedureType[];
investigation: InvestigationType[];
is_telemedicine: BooleanStrings;
action?: string;
action?: number;
assigned_to: string;
assigned_to_object: UserModel | null;
special_instruction: string;
Expand Down Expand Up @@ -143,7 +143,7 @@ const initForm: FormDetails = {
procedure: [],
investigation: [],
is_telemedicine: "false",
action: "NO_ACTION",
action: 10,
assigned_to: "",
assigned_to_object: null,
special_instruction: "",
Expand Down Expand Up @@ -279,15 +279,14 @@ export const ConsultationForm = (props: any) => {
setIsLoading(true);
const res = await dispatchAction(getPatient({ id: patientId }));
if (res.data) {
setPatientName(res.data.name);
setFacilityName(res.data.facility_object.name);
if (isUpdate) {
const form = { ...state.form };
form.action = TELEMEDICINE_ACTIONS.find(
(a) => a.id === res.data.action
)?.text;
dispatch({ type: "set_form", form });
dispatch({
type: "set_form",
form: { ...state.form, action: res.data.action },
});
}
setPatientName(res.data.name);
setFacilityName(res.data.facility_object.name);
}
} else {
setPatientName("");
Expand All @@ -302,6 +301,49 @@ export const ConsultationForm = (props: any) => {
!!state.form.symptoms.length && !state.form.symptoms.includes(1);
const isOtherSymptomsSelected = state.form.symptoms.includes(9);

const handleFormFieldChange: FieldChangeEventHandler<unknown> = (event) => {
if (event.name === "consultation_status" && event.value === "1") {
dispatch({
type: "set_form",
form: {
...state.form,
consultation_status: 1,
symptoms: [1],
symptoms_onset_date: new Date(),
category: "Critical",
suggestion: "DD",
},
});
} else if (event.name === "suggestion" && event.value === "DD") {
dispatch({
type: "set_form",
form: {
...state.form,
suggestion: "DD",
consultation_notes: "Patient declared dead",
verified_by: "Declared Dead",
},
});
} else if (
event.name === "icd11_diagnoses_object" ||
event.name === "icd11_provisional_diagnoses_object"
) {
dispatch({
type: "set_form",
form: {
...state.form,
[event.name]: event.value,
icd11_principal_diagnosis: undefined,
},
});
} else {
dispatch({
type: "set_form",
form: { ...state.form, [event.name]: event.value },
});
}
};

const fetchData = useCallback(
async (status: statusType) => {
if (!patientId) setIsLoading(true);
Expand Down Expand Up @@ -352,7 +394,7 @@ export const ConsultationForm = (props: any) => {
death_confirmed_doctor: res.data?.death_confirmed_doctor || "",
InvestigationAdvice: res.data.investigation,
};
dispatch({ type: "set_form", form: formData });
dispatch({ type: "set_form", form: { ...state.form, ...formData } });
setBed(formData.bed);

if (res.data.last_daily_round) {
Expand All @@ -364,7 +406,7 @@ export const ConsultationForm = (props: any) => {
setIsLoading(false);
}
},
[dispatchAction, id]
[dispatchAction, id, patientName, patientId]
);

useAbortableEffect(
Expand Down Expand Up @@ -745,49 +787,6 @@ export const ConsultationForm = (props: any) => {
}
};

const handleFormFieldChange: FieldChangeEventHandler<unknown> = (event) => {
if (event.name === "consultation_status" && event.value === "1") {
dispatch({
type: "set_form",
form: {
...state.form,
consultation_status: 1,
symptoms: [1],
symptoms_onset_date: new Date(),
category: "Critical",
suggestion: "DD",
},
});
} else if (event.name === "suggestion" && event.value === "DD") {
dispatch({
type: "set_form",
form: {
...state.form,
suggestion: "DD",
consultation_notes: "Patient declared dead",
verified_by: "Declared Dead",
},
});
} else if (
event.name === "icd11_diagnoses_object" ||
event.name === "icd11_provisional_diagnoses_object"
) {
dispatch({
type: "set_form",
form: {
...state.form,
[event.name]: event.value,
icd11_principal_diagnosis: undefined,
},
});
} else {
dispatch({
type: "set_form",
form: { ...state.form, [event.name]: event.value },
});
}
};

const handleDoctorSelect = (event: FieldChangeEvent<UserModel | null>) => {
if (event.value?.id) {
dispatch({
Expand Down Expand Up @@ -1347,12 +1346,12 @@ export const ConsultationForm = (props: any) => {
</div>
<div className="flex-1" ref={fieldRef["action"]}>
<SelectFormField
{...field("action")}
{...selectField("action")}
label="Action"
position="above"
options={TELEMEDICINE_ACTIONS}
optionLabel={(option) => option.desc}
optionValue={(option) => option.text}
optionDescription={() => ""}
/>
</div>
</div>
Expand Down

0 comments on commit 26eab22

Please sign in to comment.