From 6063cf35a56d893de6b1cc3876ecd86b453df652 Mon Sep 17 00:00:00 2001 From: "Tasnimul H. Tauhid" Date: Thu, 21 Sep 2023 16:20:32 +0530 Subject: [PATCH 1/4] logic for track shifting button --- .../Facility/ConsultationDetails/index.tsx | 68 +++++++++++++++---- 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/src/Components/Facility/ConsultationDetails/index.tsx b/src/Components/Facility/ConsultationDetails/index.tsx index 356257f9ac6..3991e644bdb 100644 --- a/src/Components/Facility/ConsultationDetails/index.tsx +++ b/src/Components/Facility/ConsultationDetails/index.tsx @@ -5,7 +5,11 @@ import { SYMPTOM_CHOICES, } from "../../../Common/constants"; import { ConsultationModel, ICD11DiagnosisModel } from "../models"; -import { getConsultation, getPatient } from "../../../Redux/actions"; +import { + getConsultation, + getPatient, + listShiftRequests, +} from "../../../Redux/actions"; import { statusType, useAbortableEffect } from "../../../Common/utils"; import { lazy, useCallback, useState } from "react"; import ToolTip from "../../Common/utils/Tooltip"; @@ -63,6 +67,7 @@ export const ConsultationDetails = (props: any) => { {} as ConsultationModel ); const [patientData, setPatientData] = useState({}); + const [activeShiftingData, setActiveShiftingData] = useState>([]); const [openDischargeSummaryDialog, setOpenDischargeSummaryDialog] = useState(false); const [openDischargeDialog, setOpenDischargeDialog] = useState(false); @@ -124,6 +129,16 @@ export const ConsultationDetails = (props: any) => { }; setPatientData(data); } + + // Get shifting data + const shiftingRes = await dispatch( + listShiftRequests({ patient: id }, "shift-list-call") + ); + if (shiftingRes?.data?.results) { + const data = shiftingRes.data.results; + setActiveShiftingData(data); + console.log(data); + } } else { navigate("/not-found"); } @@ -168,6 +183,19 @@ export const ConsultationDetails = (props: any) => { const SelectedTab = TABS[tab]; + const hasActiveShiftingRequest = () => { + if (activeShiftingData.length > 0) { + return [ + "PENDING", + "APPROVED", + "DESTINATION APPROVED", + "PATIENT TO BE PICKED UP", + ].includes(activeShiftingData[activeShiftingData.length - 1].status); + } + + return false; + }; + if (isLoading) { return ; } @@ -265,17 +293,33 @@ export const ConsultationDetails = (props: any) => {
{!consultationData.discharge_date && (
- - navigate( - `/facility/${patientData.facility}/patient/${patientData.id}/shift/new` - ) - } - className="btn btn-primary m-1 w-full hover:text-white" - > - - Shift Patient - + {hasActiveShiftingRequest() ? ( + + navigate( + `/shifting/${ + activeShiftingData[activeShiftingData.length - 1].id + }` + ) + } + className="btn btn-primary m-1 w-full hover:text-white" + > + + Track Shifting + + ) : ( + + navigate( + `/facility/${patientData.facility}/patient/${patientData.id}/shift/new` + ) + } + className="btn btn-primary m-1 w-full hover:text-white" + > + + Shift Patient + + )}