diff --git a/src/CAREUI/misc/AuthorizedChild.tsx b/src/CAREUI/misc/AuthorizedChild.tsx index ce9ec69d546..935f0c51f3c 100644 --- a/src/CAREUI/misc/AuthorizedChild.tsx +++ b/src/CAREUI/misc/AuthorizedChild.tsx @@ -1,4 +1,7 @@ +import { ReactNode } from "react"; +import useAuthUser from "../../Common/hooks/useAuthUser"; import { useIsAuthorized } from "../../Common/hooks/useIsAuthorized"; +import useSlug from "../../Common/hooks/useSlug"; import { AuthorizedForCB } from "../../Utils/AuthorizeFor"; interface Props { @@ -12,3 +15,20 @@ const AuthorizedChild = (props: Props) => { }; export default AuthorizedChild; + +export const AuthorizedForConsultationRelatedActions = (props: { + children: ReactNode; +}) => { + const me = useAuthUser(); + const facilityId = useSlug("facility"); + + if ( + me.home_facility_object?.id === facilityId || + me.user_type === "DistrictAdmin" || + me.user_type === "StateAdmin" + ) { + return props.children; + } + + return null; +}; diff --git a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx index e9e658cee4f..a7e52257e28 100644 --- a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx +++ b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx @@ -249,7 +249,6 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
@@ -257,7 +256,6 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
diff --git a/src/Components/Medicine/MedicineAdministrationSheet/AdministrationTableRow.tsx b/src/Components/Medicine/MedicineAdministrationSheet/AdministrationTableRow.tsx index 4fc7a97f56b..13f5191f429 100644 --- a/src/Components/Medicine/MedicineAdministrationSheet/AdministrationTableRow.tsx +++ b/src/Components/Medicine/MedicineAdministrationSheet/AdministrationTableRow.tsx @@ -14,6 +14,7 @@ import CareIcon from "../../../CAREUI/icons/CareIcon"; import EditPrescriptionForm from "../EditPrescriptionForm"; import AdministrationEventSeperator from "./AdministrationEventSeperator"; import AdministrationEventCell from "./AdministrationEventCell"; +import { AuthorizedForConsultationRelatedActions } from "../../../CAREUI/misc/AuthorizedChild"; interface Props { prescription: Prescription; @@ -93,46 +94,48 @@ export default function MedicineAdministrationTableRow({ onClick={() => setShowDetails(false)} label={t("close")} /> - {!props.readonly && ( - <> - setShowDiscontinue(true)} - > - - {t("discontinue")} - - { - setShowDetails(false); - setShowEdit(true); - }} - > - - {t("edit")} - - setShowAdminister(true)} - > - - {t("administer")} - - - )} + + {!props.readonly && ( + <> + setShowDiscontinue(true)} + > + + {t("discontinue")} + + { + setShowDetails(false); + setShowEdit(true); + }} + > + + {t("edit")} + + setShowAdminister(true)} + > + + {t("administer")} + + + )} + @@ -252,18 +255,20 @@ export default function MedicineAdministrationTableRow({ {/* Action Buttons */} - {!props.readonly && ( - setShowAdminister(true)} - > - {t("administer")} - - )} + + {!props.readonly && ( + setShowAdminister(true)} + > + {t("administer")} + + )} + diff --git a/src/Components/Medicine/MedicineAdministrationSheet/index.tsx b/src/Components/Medicine/MedicineAdministrationSheet/index.tsx index c1917cef41d..59d3976d763 100644 --- a/src/Components/Medicine/MedicineAdministrationSheet/index.tsx +++ b/src/Components/Medicine/MedicineAdministrationSheet/index.tsx @@ -13,6 +13,7 @@ import useRangePagination from "../../../Common/hooks/useRangePagination"; import MedicineAdministrationTable from "./AdministrationTable"; import Loading from "../../Common/Loading"; import ScrollOverlay from "../../../CAREUI/interactive/ScrollOverlay"; +import { AuthorizedForConsultationRelatedActions } from "../../../CAREUI/misc/AuthorizedChild"; interface Props { readonly?: boolean; @@ -89,7 +90,7 @@ const MedicineAdministrationSheet = ({ readonly, is_prn }: Props) => { options={ !readonly && !!data?.results && ( - <> + { prescriptions={data.results} onDone={() => refetch()} /> - + ) } /> diff --git a/src/Components/Medicine/PrescriptionBuilder.tsx b/src/Components/Medicine/PrescriptionBuilder.tsx index d5388dfa44a..972a74159d2 100644 --- a/src/Components/Medicine/PrescriptionBuilder.tsx +++ b/src/Components/Medicine/PrescriptionBuilder.tsx @@ -11,6 +11,7 @@ import { useTranslation } from "react-i18next"; import useQuery from "../../Utils/request/useQuery"; import MedicineRoutes from "./routes"; import useSlug from "../../Common/hooks/useSlug"; +import { AuthorizedForConsultationRelatedActions } from "../../CAREUI/misc/AuthorizedChild"; interface Props { prescription_type?: Prescription["prescription_type"]; @@ -75,20 +76,27 @@ export default function PrescriptionBuilder({ /> ))} - setShowCreate(true)} - variant="secondary" - className="mt-4 w-full bg-gray-200 text-gray-700 hover:bg-gray-300 hover:text-gray-900 focus:bg-gray-100 focus:text-gray-900" - disabled={disabled} - > -
- - - {t(is_prn ? "add_prn_prescription" : "add_prescription_medication")} - -
-
+ + setShowCreate(true)} + variant="secondary" + className="mt-4 w-full bg-gray-200 text-gray-700 hover:bg-gray-300 hover:text-gray-900 focus:bg-gray-100 focus:text-gray-900" + disabled={disabled} + > +
+ + + {t( + is_prn ? "add_prn_prescription" : "add_prescription_medication", + )} + +
+
+
{showCreate && ( setShowCreate(false)} diff --git a/src/Components/Medicine/PrescriptionDetailCard.tsx b/src/Components/Medicine/PrescriptionDetailCard.tsx index 166408e6292..630ab324662 100644 --- a/src/Components/Medicine/PrescriptionDetailCard.tsx +++ b/src/Components/Medicine/PrescriptionDetailCard.tsx @@ -5,6 +5,7 @@ import ReadMore from "../Common/components/Readmore"; import ButtonV2 from "../Common/components/ButtonV2"; import { useTranslation } from "react-i18next"; import RecordMeta from "../../CAREUI/display/RecordMeta"; +import { AuthorizedForConsultationRelatedActions } from "../../CAREUI/misc/AuthorizedChild"; export default function PrescriptionDetailCard({ prescription, @@ -56,33 +57,35 @@ export default function PrescriptionDetailCard({ {!props.readonly && prescription.prescription_type !== "DISCHARGE" && ( -
- - - {t("administer")} - - - - {t("discontinue")} - -
+ +
+ + + {t("administer")} + + + + {t("discontinue")} + +
+
)} diff --git a/src/Components/Medicine/PrescriptionsTable.tsx b/src/Components/Medicine/PrescriptionsTable.tsx index d61275c42c1..f842ccc654b 100644 --- a/src/Components/Medicine/PrescriptionsTable.tsx +++ b/src/Components/Medicine/PrescriptionsTable.tsx @@ -3,12 +3,8 @@ import ResponsiveMedicineTable from "./ResponsiveMedicineTables"; import { formatDateTime } from "../../Utils/utils"; import { Prescription } from "./models"; import CareIcon from "../../CAREUI/icons/CareIcon"; -import ButtonV2, { Cancel, Submit } from "../Common/components/ButtonV2"; -import SlideOver from "../../CAREUI/interactive/SlideOver"; -import MedicineAdministration from "./MedicineAdministration"; -import DiscontinuePrescription from "./DiscontinuePrescription"; +import { Cancel } from "../Common/components/ButtonV2"; import RecordMeta from "../../CAREUI/display/RecordMeta"; -import AdministerMedicine from "./AdministerMedicine"; import DialogModal from "../Common/Dialog"; import PrescriptionDetailCard from "./PrescriptionDetailCard"; import { useTranslation } from "react-i18next"; @@ -19,21 +15,14 @@ import MedicineRoutes from "./routes"; interface Props { is_prn?: boolean; prescription_type?: Prescription["prescription_type"]; - onChange?: () => void; - readonly?: boolean; } export default function PrescriptionsTable({ is_prn = false, prescription_type = "REGULAR", - onChange, - readonly, }: Props) { const consultation = useSlug("consultation"); const { t } = useTranslation(); - const [showBulkAdminister, setShowBulkAdminister] = useState(false); - const [showDiscontinueFor, setShowDiscontinueFor] = useState(); - const [showAdministerFor, setShowAdministerFor] = useState(); const [detailedViewFor, setDetailedViewFor] = useState(); const { data } = useQuery(MedicineRoutes.listPrescriptions, { @@ -57,42 +46,6 @@ export default function PrescriptionsTable({ return (
- {data?.results && ( - - { - setShowBulkAdminister(false); - onChange?.(); - }} - /> - - )} - {showDiscontinueFor && ( - { - setShowDiscontinueFor(undefined); - if (success) onChange?.(); - }} - key={showDiscontinueFor.id} - /> - )} - {showAdministerFor && ( - { - setShowAdministerFor(undefined); - if (success) onChange?.(); - }} - key={showAdministerFor.id} - /> - )} {detailedViewFor && ( setDetailedViewFor(undefined)} @@ -111,27 +64,6 @@ export default function PrescriptionsTable({ onClick={() => setDetailedViewFor(undefined)} label={t("close")} /> - setShowDiscontinueFor(detailedViewFor)} - > - - {t("discontinue")} - - setShowAdministerFor(detailedViewFor)} - > - - {t("administer")} -
@@ -148,34 +80,6 @@ export default function PrescriptionsTable({ - {prescription_type === "REGULAR" && ( -
- - - {t("edit_prescriptions")} - {t("edit")} - - setShowBulkAdminister(true)} - className="w-full lg:w-auto" - > - - - {t("administer_medicines")} - - {t("administer")} - -
- )}
@@ -209,63 +113,6 @@ export default function PrescriptionsTable({ } objectKeys={Object.values(tkeys)} fieldsToDisplay={[2, 3]} - actions={ - !readonly - ? (med: Prescription) => { - if (med.prescription_type === "DISCHARGE") { - return ( -
- - {t("discharge_prescription")} - -
- ); - } - - if (med.discontinued) { - return ( -
- - {t("discontinued")} -
- ); - } - - return ( -
- { - e.stopPropagation(); - setShowAdministerFor(med); - }} - > - - {t("administer")} - - { - e.stopPropagation(); - setShowDiscontinueFor(med); - }} - > - - {t("discontinue")} - -
- ); - } - : undefined - } /> {data?.results.length === 0 && (
diff --git a/src/Components/Medicine/PrescrpitionTimeline.tsx b/src/Components/Medicine/PrescrpitionTimeline.tsx index 9422d349b3a..f26957f63c6 100644 --- a/src/Components/Medicine/PrescrpitionTimeline.tsx +++ b/src/Components/Medicine/PrescrpitionTimeline.tsx @@ -15,6 +15,7 @@ import ConfirmDialog from "../Common/ConfirmDialog"; import request from "../../Utils/request/request"; import RecordMeta from "../../CAREUI/display/RecordMeta"; import CareIcon from "../../CAREUI/icons/CareIcon"; +import { AuthorizedForConsultationRelatedActions } from "../../CAREUI/misc/AuthorizedChild"; interface MedicineAdministeredEvent extends TimelineEvent<"administered"> { administration: MedicineAdministrationRecord; @@ -131,15 +132,17 @@ const MedicineAdministeredNode = ({ actions={ !event.cancelled && !hideArchive && ( - setShowArchiveConfirmation(true)} - > - Archive - + + setShowArchiveConfirmation(true)} + > + Archive + + ) } isLast={isLastNode}