From 269d00ff74901614198bb6b2db1542291f767e00 Mon Sep 17 00:00:00 2001 From: "Tasnimul H. Tauhid" Date: Tue, 26 Sep 2023 18:52:38 +0530 Subject: [PATCH 1/4] Added logic for showing "Track Shifting" button when patient has active shifting (#6318) * logic for track shifting button * removed console log * cypress fix * cypress fix --------- Co-authored-by: Rithvik Nishad Co-authored-by: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> --- cypress/e2e/patient_spec/patient_crud.cy.ts | 2 + .../pageobject/Facility/FacilityCreation.ts | 2 - .../pageobject/Patient/PatientConsultation.ts | 1 + cypress/pageobject/Patient/PatientCreation.ts | 4 ++ .../Facility/ConsultationDetails/index.tsx | 67 +++++++++++++++---- 5 files changed, 62 insertions(+), 14 deletions(-) diff --git a/cypress/e2e/patient_spec/patient_crud.cy.ts b/cypress/e2e/patient_spec/patient_crud.cy.ts index b55732fa440..b22ccdbce13 100644 --- a/cypress/e2e/patient_spec/patient_crud.cy.ts +++ b/cypress/e2e/patient_spec/patient_crud.cy.ts @@ -33,6 +33,7 @@ describe("Patient Creation with consultation", () => { it("Create a new patient with no consultation", () => { patientPage.createPatient(); patientPage.selectFacility("dummy facility"); + patientPage.patientformvisibility(); patientPage.enterPatientDetails( phone_number, emergency_phone_number, @@ -69,6 +70,7 @@ describe("Patient Creation with consultation", () => { patientPage.interceptFacilities(); patientPage.visitUpdatePatientUrl(); patientPage.verifyStatusCode(); + patientPage.patientformvisibility(); updatePatientPage.enterPatientDetails( "Test E2E User Edited", "O+", diff --git a/cypress/pageobject/Facility/FacilityCreation.ts b/cypress/pageobject/Facility/FacilityCreation.ts index b6285bff72b..42ec6d8fd7c 100644 --- a/cypress/pageobject/Facility/FacilityCreation.ts +++ b/cypress/pageobject/Facility/FacilityCreation.ts @@ -191,9 +191,7 @@ class FacilityPage { } verifyfacilitycreateassetredirection() { - cy.intercept("GET", "**/api/v1/facility/**").as("getNewAssets"); cy.url().should("include", "/assets/new"); - cy.wait("@getNewAssets").its("response.statusCode").should("eq", 200); } verifyassetfacilitybackredirection() { diff --git a/cypress/pageobject/Patient/PatientConsultation.ts b/cypress/pageobject/Patient/PatientConsultation.ts index c0ba0c260d8..b1c95d19140 100644 --- a/cypress/pageobject/Patient/PatientConsultation.ts +++ b/cypress/pageobject/Patient/PatientConsultation.ts @@ -16,6 +16,7 @@ export class PatientConsultationPage { } fillIllnessHistory(history: string) { + cy.wait(5000); cy.get("#history_of_present_illness").scrollIntoView(); cy.get("#history_of_present_illness").should("be.visible"); cy.get("#history_of_present_illness").click().type(history); diff --git a/cypress/pageobject/Patient/PatientCreation.ts b/cypress/pageobject/Patient/PatientCreation.ts index 9b8df4a287e..4fcd43dc490 100644 --- a/cypress/pageobject/Patient/PatientCreation.ts +++ b/cypress/pageobject/Patient/PatientCreation.ts @@ -124,4 +124,8 @@ export class PatientPage { verifyStatusCode() { cy.wait("@getFacilities").its("response.statusCode").should("eq", 200); } + + patientformvisibility() { + cy.get("[data-testid='current-address']").scrollIntoView(); + } } diff --git a/src/Components/Facility/ConsultationDetails/index.tsx b/src/Components/Facility/ConsultationDetails/index.tsx index c23bf071fa1..403f1752704 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"; @@ -79,6 +83,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); @@ -140,6 +145,15 @@ 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); + } } else { navigate("/not-found"); } @@ -168,6 +182,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 +292,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 + + )}