Skip to content

Commit

Permalink
Disallow unauthorized view for button related to prescriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed May 22, 2024
1 parent bc0fb3d commit 55a70d4
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,13 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
<div className="overflow-x-auto overflow-y-hidden">
<PrescriptionsTable
is_prn={false}
readonly
prescription_type="DISCHARGE"
/>
</div>
<hr className="my-2 border border-gray-300"></hr>
<div className="overflow-x-auto overflow-y-hidden">
<PrescriptionsTable
is_prn
readonly
prescription_type="DISCHARGE"
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,46 +94,48 @@ export default function MedicineAdministrationTableRow({
onClick={() => setShowDetails(false)}
label={t("close")}
/>
{!props.readonly && (
<>
<Submit
disabled={
prescription.discontinued ||
prescription.prescription_type === "DISCHARGE"
}
variant="danger"
onClick={() => setShowDiscontinue(true)}
>
<CareIcon icon="l-ban" className="text-lg" />
{t("discontinue")}
</Submit>
<Submit
disabled={
prescription.discontinued ||
prescription.prescription_type === "DISCHARGE"
}
variant="secondary"
border
onClick={() => {
setShowDetails(false);
setShowEdit(true);
}}
>
<CareIcon icon="l-pen" className="text-lg" />
{t("edit")}
</Submit>
<Submit
disabled={
prescription.discontinued ||
prescription.prescription_type === "DISCHARGE"
}
onClick={() => setShowAdminister(true)}
>
<CareIcon icon="l-syringe" className="text-lg" />
{t("administer")}
</Submit>
</>
)}
<AuthorizedForConsultationRelatedActions>
{!props.readonly && (
<>
<Submit
disabled={
prescription.discontinued ||
prescription.prescription_type === "DISCHARGE"
}
variant="danger"
onClick={() => setShowDiscontinue(true)}
>
<CareIcon icon="l-ban" className="text-lg" />
{t("discontinue")}
</Submit>
<Submit
disabled={
prescription.discontinued ||
prescription.prescription_type === "DISCHARGE"
}
variant="secondary"
border
onClick={() => {
setShowDetails(false);
setShowEdit(true);
}}
>
<CareIcon icon="l-pen" className="text-lg" />
{t("edit")}
</Submit>
<Submit
disabled={
prescription.discontinued ||
prescription.prescription_type === "DISCHARGE"
}
onClick={() => setShowAdminister(true)}
>
<CareIcon icon="l-syringe" className="text-lg" />
{t("administer")}
</Submit>
</>
)}
</AuthorizedForConsultationRelatedActions>
</div>
</div>
</DialogModal>
Expand Down Expand Up @@ -252,18 +255,20 @@ export default function MedicineAdministrationTableRow({

{/* Action Buttons */}
<td className="space-x-1 pr-2 text-right">
{!props.readonly && (
<ButtonV2
type="button"
size="small"
disabled={prescription.discontinued}
ghost
border
onClick={() => setShowAdminister(true)}
>
{t("administer")}
</ButtonV2>
)}
<AuthorizedForConsultationRelatedActions>
{!props.readonly && (
<ButtonV2
type="button"
size="small"
disabled={prescription.discontinued}
ghost
border
onClick={() => setShowAdminister(true)}
>
{t("administer")}
</ButtonV2>
)}
</AuthorizedForConsultationRelatedActions>
</td>
</tr>
</>
Expand Down
5 changes: 3 additions & 2 deletions src/Components/Medicine/MedicineAdministrationSheet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,7 +90,7 @@ const MedicineAdministrationSheet = ({ readonly, is_prn }: Props) => {
options={
!readonly &&
!!data?.results && (
<>
<AuthorizedForConsultationRelatedActions>
<ButtonV2
id="edit-prescription"
variant="secondary"
Expand All @@ -107,7 +108,7 @@ const MedicineAdministrationSheet = ({ readonly, is_prn }: Props) => {
prescriptions={data.results}
onDone={() => refetch()}
/>
</>
</AuthorizedForConsultationRelatedActions>
)
}
/>
Expand Down
36 changes: 22 additions & 14 deletions src/Components/Medicine/PrescriptionBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down Expand Up @@ -75,20 +76,27 @@ export default function PrescriptionBuilder({
/>
))}
</div>
<ButtonV2
type="button"
onClick={() => 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}
>
<div className="flex w-full justify-start gap-2" id="add-prescription">
<CareIcon icon="l-plus" className="text-lg" />
<span className="font-bold">
{t(is_prn ? "add_prn_prescription" : "add_prescription_medication")}
</span>
</div>
</ButtonV2>
<AuthorizedForConsultationRelatedActions>
<ButtonV2
type="button"
onClick={() => 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}
>
<div
className="flex w-full justify-start gap-2"
id="add-prescription"
>
<CareIcon icon="l-plus" className="text-lg" />
<span className="font-bold">
{t(
is_prn ? "add_prn_prescription" : "add_prescription_medication",
)}
</span>
</div>
</ButtonV2>
</AuthorizedForConsultationRelatedActions>
{showCreate && (
<DialogModal
onClose={() => setShowCreate(false)}
Expand Down
57 changes: 30 additions & 27 deletions src/Components/Medicine/PrescriptionDetailCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -56,33 +57,35 @@ export default function PrescriptionDetailCard({

{!props.readonly &&
prescription.prescription_type !== "DISCHARGE" && (
<div className="flex flex-col-reverse items-end gap-2 sm:flex-row">
<ButtonV2
id="administer-medicine"
disabled={prescription.discontinued}
onClick={props.onAdministerClick}
type="button"
size="small"
variant="secondary"
ghost
border
>
<CareIcon icon="l-syringe" className="text-base" />
{t("administer")}
</ButtonV2>
<ButtonV2
disabled={prescription.discontinued}
type="button"
size="small"
variant="danger"
ghost
border
onClick={props.onDiscontinueClick}
>
<CareIcon icon="l-ban" className="text-base" />
{t("discontinue")}
</ButtonV2>
</div>
<AuthorizedForConsultationRelatedActions>
<div className="flex flex-col-reverse items-end gap-2 sm:flex-row">
<ButtonV2
id="administer-medicine"
disabled={prescription.discontinued}
onClick={props.onAdministerClick}
type="button"
size="small"
variant="secondary"
ghost
border
>
<CareIcon icon="l-syringe" className="text-base" />
{t("administer")}
</ButtonV2>
<ButtonV2
disabled={prescription.discontinued}
type="button"
size="small"
variant="danger"
ghost
border
onClick={props.onDiscontinueClick}
>
<CareIcon icon="l-ban" className="text-base" />
{t("discontinue")}
</ButtonV2>
</div>
</AuthorizedForConsultationRelatedActions>
)}
</div>
</div>
Expand Down

0 comments on commit 55a70d4

Please sign in to comment.