diff --git a/public/locale/en.json b/public/locale/en.json index 17afac442e2..758ef1965db 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -1540,6 +1540,7 @@ "view_all_details": "View All Details", "view_asset": "View Assets", "view_cns": "View CNS", + "view_consultation": "View Latest Encounter", "view_consultation_and_log_updates": "View Consultation / Log Updates", "view_details": "View Details", "view_facility": "View Facility", diff --git a/src/components/Common/AuthorizedButton.tsx b/src/components/Common/AuthorizedButton.tsx new file mode 100644 index 00000000000..2b611a0c9f2 --- /dev/null +++ b/src/components/Common/AuthorizedButton.tsx @@ -0,0 +1,19 @@ +import { Button, ButtonProps } from "@headlessui/react"; + +import AuthorizedChild from "@/CAREUI/misc/AuthorizedChild"; + +import { AuthorizedElementProps } from "@/Utils/AuthorizeFor"; + +export const AuthorizedButton: React.FC< + AuthorizedElementProps & ButtonProps +> = ({ authorizeFor = () => true, ...props }) => { + return ( + + {({ isAuthorized }) => ( + + )} + + ); +}; diff --git a/src/components/Patient/PatientHome.tsx b/src/components/Patient/PatientHome.tsx index 1c992445706..b5cb99b615b 100644 --- a/src/components/Patient/PatientHome.tsx +++ b/src/components/Patient/PatientHome.tsx @@ -5,19 +5,11 @@ import { useTranslation } from "react-i18next"; import Chip from "@/CAREUI/display/Chip"; import CareIcon from "@/CAREUI/icons/CareIcon"; -import { Avatar } from "@/components/Common/Avatar"; -import ButtonV2 from "@/components/Common/ButtonV2"; +import { Button } from "@/components/ui/button"; + +import { AuthorizedButton } from "@/components/Common/AuthorizedButton"; import ConfirmDialog from "@/components/Common/ConfirmDialog"; -import Loading from "@/components/Common/Loading"; -import Page from "@/components/Common/Page"; import UserAutocomplete from "@/components/Common/UserAutocompleteFormField"; -import { patientTabs } from "@/components/Patient/PatientDetailsTab"; -import { isPatientMandatoryDataFilled } from "@/components/Patient/Utils"; -import { - AssignedToObjectModel, - PatientModel, -} from "@/components/Patient/models"; -import { SkillModel, UserBareMinimum } from "@/components/Users/models"; import useAuthUser from "@/hooks/useAuthUser"; @@ -34,6 +26,7 @@ import dayjs from "@/Utils/dayjs"; import routes from "@/Utils/request/api"; import request from "@/Utils/request/request"; import useTanStackQueryInstead from "@/Utils/request/useQuery"; + import { formatDateTime, formatName, @@ -42,7 +35,14 @@ import { isAntenatal, isPostPartum, relativeDate, -} from "@/Utils/utils"; +} from "../../Utils/utils"; +import { Avatar } from "../Common/Avatar"; +import Loading from "../Common/Loading"; +import Page from "../Common/Page"; +import { SkillModel, UserBareMinimum } from "../Users/models"; +import { patientTabs } from "./PatientDetailsTab"; +import { isPatientMandatoryDataFilled } from "./Utils"; +import { AssignedToObjectModel, PatientModel } from "./models"; export const parseOccupation = (occupation: string | undefined) => { return OCCUPATION_TYPES.find((i) => i.value === occupation)?.text; @@ -218,29 +218,55 @@ export const PatientHome = (props: {
- {patientData?.is_active && - (!patientData?.last_consultation || - patientData?.last_consultation?.discharge_date) && ( -
- - navigate( - `/facility/${patientData?.facility}/patient/${id}/consultation`, - ) - } - > - - - {t("add_consultation")} - - -
+ {facilityId === + patientData.facility_object?.id.toString() && + patientData?.is_active && ( + <> + {patientData?.last_consultation && + !patientData?.last_consultation.discharge_date ? ( +
+ +
+ ) : ( +
+ +
+ )} + )}
@@ -366,7 +392,7 @@ export const PatientHome = (props: { className="tooltip-text tooltip-bottom flex flex-col text-xs font-medium" role="tooltip" > - {skillsQuery.data?.results.map((skill) => ( + {skillsQuery.data?.results.map((skill: any) => (
  • {skill.skill_object.name}
  • @@ -463,9 +489,8 @@ export const PatientHome = (props: {
    - navigate(`/patient/${id}/investigation_reports`) } @@ -477,13 +502,12 @@ export const PatientHome = (props: { /> {t("investigations_summary")} - +
    - navigate( `/facility/${patientData?.facility}/patient/${id}/files`, @@ -494,18 +518,17 @@ export const PatientHome = (props: { {t("view_update_patient_files")} - +
    - {NonReadOnlyUsers && ( + {NonReadOnlyUsers(authUser.user_type) && (
    - setOpenAssignVolunteerDialog(true)} disabled={false} authorizeFor={NonReadOnlyUsers} className="w-full bg-white font-semibold text-green-800 hover:bg-secondary-200" - size="large" > {" "} @@ -513,15 +536,14 @@ export const PatientHome = (props: { ? t("update_volunteer") : t("assign_to_volunteer")} - +
    )}
    - - +
    @@ -661,7 +683,7 @@ export const PatientHome = (props: { {patientData.last_consultation?.new_discharge_reason === DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id && (
    - {t("death_report")} - +
    )}