Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict Unauthorized Users from Accessing Facility's Patient Registration #7268

Closed
wants to merge 15 commits into from
Closed
15 changes: 15 additions & 0 deletions src/Components/Common/FacilitySelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import AutoCompleteAsync from "../Form/AutoCompleteAsync";
import { FacilityModel } from "../Facility/models";
import request from "../../Utils/request/request";
import routes from "../../Redux/api";
import useAuthUser from "../../Common/hooks/useAuthUser";

interface FacilitySelectProps {
name: string;
Expand All @@ -16,6 +17,7 @@ interface FacilitySelectProps {
showAll?: boolean;
showNOptions?: number;
freeText?: boolean;
homeFacility?: boolean;
selected?: FacilityModel | FacilityModel[] | null;
setSelected: (selected: FacilityModel | FacilityModel[] | null) => void;
}
Expand All @@ -34,8 +36,11 @@ export const FacilitySelect = (props: FacilitySelectProps) => {
facilityType,
district,
freeText = false,
homeFacility = false,
errors = "",
} = props;
const authUser = useAuthUser();
const showAllFacilityUsers = ["DistrictAdmin", "StateAdmin"];

const facilitySearch = useCallback(
async (text: string) => {
Expand All @@ -44,11 +49,21 @@ export const FacilitySelect = (props: FacilitySelectProps) => {
offset: 0,
search_text: text,
all: searchAll,
name: "",
facility_type: facilityType,
exclude_user: exclude_user,
district,
};

if (
homeFacility &&
!showAllFacilityUsers.includes(authUser.user_type) &&
authUser.home_facility_object?.name
) {
query["name"] = authUser.home_facility_object?.name;
query["limit"] = 1;
}

const { data } = await request(
showAll ? routes.getAllFacilities : routes.getPermittedFacilities,
{ query }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const FacilitiesSelectDialog = (props: Props) => {
errors=""
showAll={false}
multiple={false}
homeFacility={true}
/>
<div className="mt-4 flex flex-col gap-2 sm:flex-row sm:justify-end">
<Cancel onClick={handleCancel} />
Expand Down
10 changes: 10 additions & 0 deletions src/Components/Patient/PatientRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ export const PatientRegister = (props: PatientRegisterProps) => {
}
}, [careExtId, formField]);

useEffect(() => {
const showAllFacilityUsers = ["DistrictAdmin", "StateAdmin"];
if (
!showAllFacilityUsers.includes(authUser.user_type) &&
authUser.home_facility_object?.name
) {
navigate("/facility");
}
}, []);

const headerText = !id ? "Add Details of Patient" : "Update Patient Details";
const buttonText = !id ? "Add Patient" : "Save Details";

Expand Down
Loading