Skip to content

Commit

Permalink
added admit patient button in completed shifting cards
Browse files Browse the repository at this point in the history
  • Loading branch information
khavinshankar committed Apr 25, 2023
1 parent bb472f4 commit 0676157
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/Common/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { OptionsType, USER_TYPES, UserRole } from "./constants";

/* eslint-disable react-hooks/exhaustive-deps */
import { useEffect } from "react";
import { OptionsType } from "./constants";

export interface statusType {
aborted?: boolean;
Expand Down Expand Up @@ -69,3 +70,9 @@ export const deepEqual = (x: any, y: any): boolean => {

return false;
};

export const checkAuthority = (type: UserRole, cutoff: UserRole) => {
const userAuthority = USER_TYPES.indexOf(type);
const cutoffAuthority = USER_TYPES.indexOf(cutoff);
return userAuthority >= cutoffAuthority;
};
57 changes: 55 additions & 2 deletions src/Components/Shifting/ShiftingBoard.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import React, { useEffect, useState } from "react";
import * as Notification from "../../Utils/Notifications.js";

import { classNames, formatDate } from "../../Utils/utils";
import {
completeTransfer,
downloadShiftRequests,
listShiftRequests,
} from "../../Redux/actions";
import { useDispatch, useSelector } from "react-redux";
import { useDrag, useDrop } from "react-dnd";
import { useEffect, useState } from "react";

import ButtonV2 from "../Common/components/ButtonV2";
import { CSVLink } from "react-csv";
import CareIcon from "../../CAREUI/icons/CareIcon";
import CircularProgress from "../Common/components/CircularProgress";
import ConfirmDialogV2 from "../Common/ConfirmDialogV2";
import { checkAuthority } from "../../Common/utils";
import moment from "moment";
import { navigate } from "raviger";
import { transferPatient } from "../../Redux/actions";
import useConfig from "../../Common/hooks/useConfig";
import { useDispatch } from "react-redux";
import { useTranslation } from "react-i18next";

const limit = 14;
Expand All @@ -41,6 +45,8 @@ const reduceLoading = (action: string, current: any) => {

const ShiftCard = ({ shift, filter }: any) => {
const dispatch: any = useDispatch();
const state: any = useSelector((state) => state);
const { currentUser } = state;
const { wartime_shifting } = useConfig();
const [modalFor, setModalFor] = useState({
externalId: undefined,
Expand All @@ -51,6 +57,7 @@ const ShiftCard = ({ shift, filter }: any) => {
item: shift,
collect: (monitor) => ({ isDragging: !!monitor.isDragging() }),
}));
const [isPatientTransfering, setIsPatientTransfering] = useState(false);
const { t } = useTranslation();

const handleTransferComplete = (shift: any) => {
Expand All @@ -61,6 +68,9 @@ const ShiftCard = ({ shift, filter }: any) => {
);
});
};

console.log(shift);

return (
<div ref={drag} className="w-full mt-2">
<div
Expand Down Expand Up @@ -199,6 +209,49 @@ const ShiftCard = ({ shift, filter }: any) => {
</dl>
</div>

{shift?.status === "COMPLETED" &&
shift?.assigned_facility &&
(checkAuthority(currentUser?.data?.user_type, "DistrictAdmin") ||
currentUser?.data?.home_facility ===
shift?.assigned_facility) && (
<div className="mt-2 flex">
<ButtonV2
loading={isPatientTransfering}
disabled={
shift?.origin_facility !==
shift?.patient_object?.facility &&
shift?.assigned_facility === shift?.patient_object?.facility
}
onClick={async () => {
setIsPatientTransfering(true);
const data = {
date_of_birth: moment(
shift?.patient_object?.date_of_birth
).format("YYYY-MM-DD"),
facility: shift?.assigned_facility,
};
const res = await dispatch(
transferPatient(data, { id: shift?.patient })
);
setIsPatientTransfering(false);
if (res && res.data && res.status === 200) {
Notification.Success({
msg: "Patient admitted successfully",
});
} else {
Notification.Error({
msg: "Patient admission failed",
});
}
}}
className="w-full mr-2"
>
<CareIcon className="care-l-user-injured text-lg" />
<span>{t("admit_patient")}</span>
</ButtonV2>
</div>
)}

<div className="mt-2 flex">
<button
onClick={(_) => navigate(`/shifting/${shift.external_id}`)}
Expand Down
1 change: 1 addition & 0 deletions src/Locale/en/Common.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"last_modified": "Last Modified",
"patient_address": "Patient Address",
"all_details": "All Details",
"admit_patient": "Admit Patient",
"confirm": "Confirm",
"refresh_list": "Refresh List",
"last_edited": "Last Edited",
Expand Down

0 comments on commit 0676157

Please sign in to comment.