From 56931499c291078f2618876c78bb2eb5c001f5d5 Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Thu, 7 Dec 2023 15:02:33 +0530 Subject: [PATCH] Refactor discharge_reason data type to Integer --- src/Common/constants.tsx | 8 ++-- .../ConsultationUpdatesTab.tsx | 19 +++++--- src/Components/Facility/ConsultationForm.tsx | 10 +++-- src/Components/Facility/DischargeModal.tsx | 43 ++++++++++++------- src/Components/Facility/models.tsx | 2 +- src/Components/Patient/PatientHome.tsx | 9 +++- src/Components/Patient/PatientInfoCard.tsx | 6 ++- .../Shifting/ShiftDetailsUpdate.tsx | 5 ++- 8 files changed, 66 insertions(+), 36 deletions(-) diff --git a/src/Common/constants.tsx b/src/Common/constants.tsx index 069a39e1539..c690841d8ae 100644 --- a/src/Common/constants.tsx +++ b/src/Common/constants.tsx @@ -294,10 +294,10 @@ export const SYMPTOM_CHOICES = [ ]; export const DISCHARGE_REASONS = [ - { id: "REC", text: "Recovered" }, - { id: "EXP", text: "Expired" }, - { id: "REF", text: "Referred" }, - { id: "LAMA", text: "LAMA" }, + { id: 1, text: "Recovered" }, + { id: 2, text: "Referred" }, + { id: 3, text: "Expired" }, + { id: 4, text: "LAMA" }, ]; export const LINES_CATHETER_CHOICES: Array = [ diff --git a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx index 0d8a70781da..3b4cb9cfa8c 100644 --- a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx +++ b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx @@ -196,7 +196,8 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => { {props.consultationData.discharge_date && (
i.text == "Recovered")?.id && "lg:col-span-2" }`} > @@ -214,7 +215,9 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => { )?.text ?? "--"}
- {props.consultationData.discharge_reason === "REF" && ( + {props.consultationData.discharge_reason === + DISCHARGE_REASONS.find((i) => i.text == "Referred") + ?.id && (
Referred Facility {" - "} @@ -224,7 +227,9 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
)} - {props.consultationData.discharge_reason === "REC" && ( + {props.consultationData.discharge_reason === + DISCHARGE_REASONS.find((i) => i.text == "Recovered") + ?.id && (
Discharge Date {" - "} @@ -259,7 +264,9 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
)} - {props.consultationData.discharge_reason === "EXP" && ( + {props.consultationData.discharge_reason === + DISCHARGE_REASONS.find((i) => i.text == "Expired") + ?.id && (
Date of Death {" - "} @@ -286,8 +293,8 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
)} - {["REF", "LAMA"].includes( - props.consultationData.discharge_reason ?? "" + {[2, 4].includes( + props.consultationData.discharge_reason ?? 0 ) && (
diff --git a/src/Components/Facility/ConsultationForm.tsx b/src/Components/Facility/ConsultationForm.tsx index 1d4abbedc39..bbb0133e3d7 100644 --- a/src/Components/Facility/ConsultationForm.tsx +++ b/src/Components/Facility/ConsultationForm.tsx @@ -3,6 +3,7 @@ import * as Notification from "../../Utils/Notifications.js"; import { BedModel, FacilityModel } from "./models"; import { CONSULTATION_SUGGESTION, + DISCHARGE_REASONS, PATIENT_CATEGORIES, REVIEW_AT_CHOICES, TELEMEDICINE_ACTIONS, @@ -120,7 +121,7 @@ type FormDetails = { weight: string; height: string; bed: BedModel | null; - discharge_reason: string; + discharge_reason: number | null; cause_of_death: string; death_datetime: string; death_confirmed_doctor: string; @@ -170,7 +171,7 @@ const initForm: FormDetails = { weight: "", height: "", bed: null, - discharge_reason: "", + discharge_reason: null, cause_of_death: "", death_datetime: "", death_confirmed_doctor: "", @@ -396,7 +397,7 @@ export const ConsultationForm = (props: any) => { weight: res.data.weight ? res.data.weight : "", height: res.data.height ? res.data.height : "", bed: res.data?.current_bed?.bed_object || null, - discharge_reason: res.data?.discharge_reason || "", + discharge_reason: res.data?.discharge_reason || null, cause_of_death: res.data?.discharge_notes || "", death_datetime: res.data?.death_datetime || "", death_confirmed_doctor: res.data?.death_confirmed_doctor || "", @@ -648,7 +649,8 @@ export const ConsultationForm = (props: any) => { const dischargeResponse = await dispatchAction( dischargePatient( { - discharge_reason: "EXP", + discharge_reason: DISCHARGE_REASONS.find((i) => i.text === "Expired") + ?.id, discharge_notes: cause_of_death, death_datetime: death_datetime, death_confirmed_doctor: death_confirmed_doctor, diff --git a/src/Components/Facility/DischargeModal.tsx b/src/Components/Facility/DischargeModal.tsx index 3384efa686b..45e7e0ffa73 100644 --- a/src/Components/Facility/DischargeModal.tsx +++ b/src/Components/Facility/DischargeModal.tsx @@ -26,7 +26,7 @@ import { FacilityModel } from "./models"; import dayjs from "../../Utils/dayjs"; interface PreDischargeFormInterface { - discharge_reason: string; + discharge_reason: number | null; discharge_notes: string; discharge_date?: string; death_datetime?: string; @@ -40,7 +40,7 @@ interface IProps { onClose: () => void; consultationData: ConsultationModel; afterSubmit?: () => void; - discharge_reason?: string; + discharge_reason?: number | null; discharge_notes?: string; discharge_date?: string; death_datetime?: string; @@ -54,7 +54,7 @@ const DischargeModal = ({ onClose(); window.location.reload(); }, - discharge_reason = "", + discharge_reason = null, discharge_notes = "", discharge_date = dayjs().format("YYYY-MM-DDTHH:mm"), death_datetime = dayjs().format("YYYY-MM-DDTHH:mm"), @@ -123,8 +123,9 @@ const DischargeModal = ({ } if ( - preDischargeForm.discharge_reason == "EXP" && - !preDischargeForm.discharge_notes.trim() + (preDischargeForm.discharge_reason == + DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id, + !preDischargeForm.discharge_notes.trim()) ) { setErrors({ ...errors, @@ -212,7 +213,8 @@ const DischargeModal = ({ } error={errors?.discharge_reason} /> - {preDischargeForm.discharge_reason === "REF" && ( + {preDischargeForm.discharge_reason === + DISCHARGE_REASONS.find((i) => i.text == "Referred")?.id && ( <> Referred to )} i.text == "Expired")?.id + } label={ { - EXP: "Cause of death", - REC: "Discharged Advice", - }[preDischargeForm.discharge_reason] ?? "Notes" + "3": "Cause of death", + "1": "Discharged Advice", + }[preDischargeForm.discharge_reason ?? 0] ?? "Notes" } name="discharge_notes" value={preDischargeForm.discharge_notes} @@ -249,19 +254,22 @@ const DischargeModal = ({ /> i.text == "Expired")?.id ? "death_datetime" : "discharge_date" } label={ - preDischargeForm.discharge_reason === "EXP" + preDischargeForm.discharge_reason === + DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id ? "Date of Death" : "Date and Time of Discharge" } type="datetime-local" value={ preDischargeForm[ - preDischargeForm.discharge_reason === "EXP" + preDischargeForm.discharge_reason === + DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id ? "death_datetime" : "discharge_date" ] @@ -280,13 +288,15 @@ const DischargeModal = ({ ).format("YYYY-MM-DDTHH:mm")} max={dayjs().format("YYYY-MM-DDTHH:mm")} error={ - preDischargeForm.discharge_reason === "EXP" + preDischargeForm.discharge_reason === + DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id ? errors?.death_datetime : errors?.discharge_date } /> - {preDischargeForm.discharge_reason === "REC" && ( + {preDischargeForm.discharge_reason === + DISCHARGE_REASONS.find((i) => i.text == "Recovered")?.id && ( <>
Discharge Prescription Medications @@ -298,7 +308,8 @@ const DischargeModal = ({
)} - {preDischargeForm.discharge_reason === "EXP" && ( + {preDischargeForm.discharge_reason === + DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id && ( {
- {patientData.last_consultation?.discharge_reason === "EXP" && ( + {patientData.last_consultation?.discharge_reason === + DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id && (
i.text == "Expired")?.id ? ( {" "} Expired on {formatDate(consultation?.death_datetime)} @@ -354,7 +355,8 @@ export default function PatientInfoCard(props: { ? "OP file closed" : "UNKNOWN"} - ) : consultation?.discharge_reason === "EXP" ? ( + ) : consultation?.discharge_reason === + DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id ? ( EXPIRED ) : ( DISCHARGE_REASONS.find( diff --git a/src/Components/Shifting/ShiftDetailsUpdate.tsx b/src/Components/Shifting/ShiftDetailsUpdate.tsx index 36d2d120585..9e3dbcfef9c 100644 --- a/src/Components/Shifting/ShiftDetailsUpdate.tsx +++ b/src/Components/Shifting/ShiftDetailsUpdate.tsx @@ -2,6 +2,7 @@ import * as Notification from "../../Utils/Notifications.js"; import { BREATHLESSNESS_LEVEL, + DISCHARGE_REASONS, FACILITY_TYPES, PATIENT_CATEGORIES, SHIFTING_CHOICES_PEACETIME, @@ -282,7 +283,9 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { show={showDischargeModal} onClose={() => setShowDischargeModal(false)} consultationData={consultationData} - discharge_reason="EXP" + discharge_reason={ + DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id + } afterSubmit={() => { handleSubmit(true); }}