Skip to content

Commit

Permalink
Added logic for showing "Track Shifting" button when patient has acti…
Browse files Browse the repository at this point in the history
…ve shifting (#6318)

* logic for track shifting button

* removed console log

* cypress fix

* cypress fix

---------

Co-authored-by: Rithvik Nishad <[email protected]>
Co-authored-by: Mohammed Nihal <[email protected]>
  • Loading branch information
3 people authored Sep 26, 2023
1 parent f0d3470 commit 269d00f
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 14 deletions.
2 changes: 2 additions & 0 deletions cypress/e2e/patient_spec/patient_crud.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -69,6 +70,7 @@ describe("Patient Creation with consultation", () => {
patientPage.interceptFacilities();
patientPage.visitUpdatePatientUrl();
patientPage.verifyStatusCode();
patientPage.patientformvisibility();
updatePatientPage.enterPatientDetails(
"Test E2E User Edited",
"O+",
Expand Down
2 changes: 0 additions & 2 deletions cypress/pageobject/Facility/FacilityCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions cypress/pageobject/Patient/PatientConsultation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions cypress/pageobject/Patient/PatientCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
67 changes: 55 additions & 12 deletions src/Components/Facility/ConsultationDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -79,6 +83,7 @@ export const ConsultationDetails = (props: any) => {
{} as ConsultationModel
);
const [patientData, setPatientData] = useState<PatientModel>({});
const [activeShiftingData, setActiveShiftingData] = useState<Array<any>>([]);
const [openDischargeSummaryDialog, setOpenDischargeSummaryDialog] =
useState(false);
const [openDischargeDialog, setOpenDischargeDialog] = useState(false);
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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 <Loading />;
}
Expand Down Expand Up @@ -265,17 +292,33 @@ export const ConsultationDetails = (props: any) => {
<div className="-right-6 top-0 flex w-full flex-col space-y-1 sm:w-min sm:flex-row sm:items-center sm:space-y-0 sm:divide-x-2 lg:absolute xl:right-0">
{!consultationData.discharge_date && (
<div className="flex w-full flex-col px-2 sm:flex-row">
<ButtonV2
onClick={() =>
navigate(
`/facility/${patientData.facility}/patient/${patientData.id}/shift/new`
)
}
className="btn btn-primary m-1 w-full hover:text-white"
>
<CareIcon className="care-l-ambulance h-5 w-5" />
Shift Patient
</ButtonV2>
{hasActiveShiftingRequest() ? (
<ButtonV2
onClick={() =>
navigate(
`/shifting/${
activeShiftingData[activeShiftingData.length - 1].id
}`
)
}
className="btn btn-primary m-1 w-full hover:text-white"
>
<CareIcon className="care-l-ambulance h-5 w-5" />
Track Shifting
</ButtonV2>
) : (
<ButtonV2
onClick={() =>
navigate(
`/facility/${patientData.facility}/patient/${patientData.id}/shift/new`
)
}
className="btn btn-primary m-1 w-full hover:text-white"
>
<CareIcon className="care-l-ambulance h-5 w-5" />
Shift Patient
</ButtonV2>
)}
<button
onClick={() => {
triggerGoal("Doctor Connect Clicked", {
Expand Down

0 comments on commit 269d00f

Please sign in to comment.