Skip to content

Commit

Permalink
remove hardcoded state and district terminologies in codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Jan 30, 2025
1 parent 46877a7 commit 2dd94c4
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 292 deletions.
15 changes: 7 additions & 8 deletions src/Providers/PatientUserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { useAuthContext } from "@/hooks/useAuthUser";

import routes from "@/Utils/request/api";
import query from "@/Utils/request/query";
import { AppointmentPatient } from "@/pages/Patient/Utils";
import { TokenData } from "@/types/auth/otpToken";
import { Patient } from "@/types/emr/newPatient";

export type PatientUserContextType = {
patients?: AppointmentPatient[];
selectedPatient: AppointmentPatient | null;
setSelectedPatient: (patient: AppointmentPatient) => void;
patients?: Patient[];
selectedPatient: Patient | null;
setSelectedPatient: (patient: Patient) => void;
tokenData: TokenData;
};

Expand All @@ -25,9 +25,8 @@ interface Props {
}

export default function PatientUserProvider({ children }: Props) {
const [patients, setPatients] = useState<AppointmentPatient[]>([]);
const [selectedPatient, setSelectedPatient] =
useState<AppointmentPatient | null>(null);
const [patients, setPatients] = useState<Patient[]>([]);
const [selectedPatient, setSelectedPatient] = useState<Patient | null>(null);

const { patientToken: tokenData } = useAuthContext();

Expand All @@ -44,7 +43,7 @@ export default function PatientUserProvider({ children }: Props) {
useEffect(() => {
if (userData?.results && userData.results.length > 0) {
setPatients(userData.results);
const localPatient: AppointmentPatient | undefined = JSON.parse(
const localPatient: Patient | undefined = JSON.parse(
localStorage.getItem("selectedPatient") || "{}",
);
const selectedPatient =
Expand Down
36 changes: 1 addition & 35 deletions src/Utils/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,9 @@ import { UserModel } from "@/components/Users/models";

import { UserBase } from "@/types/user/user";

// To do: Rewrite to check if belongs to same org and in higher
// hierarchy
/* const checkIfStateOrDistrictAdminInSameLocation = (
authUser: UserBaseModel,
targetUser: UserBaseModel,
) => {
const hasLocation = Boolean(
targetUser.state_object || targetUser.district_object,
);
const isStateAdminOfSameState =
authUser.user_type === "StateAdmin" &&
targetUser.state_object?.id === authUser.state;
const isDistrictAdminOfSameDistrict =
authUser.user_type === "DistrictAdmin" &&
targetUser.district_object?.id === authUser.district;
return (
hasLocation && (isStateAdminOfSameState || isDistrictAdminOfSameDistrict)
);
};
*/
export const showUserDelete = (authUser: UserModel, targetUser: UserBase) => {
// Auth user should be higher in hierarchy than target user
// User can't delete their own account
/* if (
USER_TYPES.indexOf(authUser.user_type) <=
USER_TYPES.indexOf(targetUser.user_type) ||
authUser.username === targetUser.username
)
return false; */
// To do: check above
//return checkIfStateOrDistrictAdminInSameLocation(authUser, targetUser);
if (authUser.username === targetUser.username) return false;
return false;
};
Expand All @@ -55,8 +24,5 @@ export const editUserPermissions = (
authUser: UserModel,
targetUser: UserBase,
) => {
if (authUser.username === targetUser.username) return true;
return false;
// To do: check above
//return checkIfStateOrDistrictAdminInSameLocation(authUser, targetUser);
return authUser.username === targetUser.username;
};
9 changes: 3 additions & 6 deletions src/Utils/request/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import {
} from "@/components/Users/models";

import { PaginatedResponse } from "@/Utils/request/types";
import {
AppointmentPatient,
AppointmentPatientRegister,
} from "@/pages/Patient/Utils";
import { AppointmentPatientRegister } from "@/pages/Patient/Utils";
import { Encounter, EncounterEditRequest } from "@/types/emr/encounter";
import { MedicationStatement } from "@/types/emr/medicationStatement";
import { PartialPatientModel, Patient } from "@/types/emr/newPatient";
Expand Down Expand Up @@ -625,7 +622,7 @@ const routes = {
getPatient: {
path: "/api/v1/otp/patient/",
method: "GET",
TRes: Type<PaginatedResponse<AppointmentPatient>>(),
TRes: Type<PaginatedResponse<Patient>>(),
auth: {
key: "Authorization",
value: "Bearer {token}",
Expand All @@ -636,7 +633,7 @@ const routes = {
path: "/api/v1/otp/patient/",
method: "POST",
TBody: Type<Partial<AppointmentPatientRegister>>(),
TRes: Type<AppointmentPatient>(),
TRes: Type<Patient>(),
auth: {
key: "Authorization",
value: "Bearer {token}",
Expand Down
16 changes: 16 additions & 0 deletions src/Utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import dayjs from "@/Utils/dayjs";
import { Time } from "@/Utils/types";
import { Patient } from "@/types/emr/newPatient";
import { PatientModel } from "@/types/emr/patient";
import {
Organization,
OrganizationParent,
} from "@/types/organization/organization";
import { Quantity } from "@/types/questionnaire/quantity";

const DATE_FORMAT = "DD/MM/YYYY";
Expand Down Expand Up @@ -268,3 +272,15 @@ export const conditionalArrayAttribute = <T>(
) => {
return condition ? attributes : [];
};

export const stringifyGeoOrganization = (org: Organization) => {
const levels: string[] = [];

let current: OrganizationParent | undefined = org;
while (current?.name) {
levels.push(current.name);
current = current.parent;
}

return levels.join(", ");
};
22 changes: 0 additions & 22 deletions src/common/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -768,25 +768,3 @@ export const PREVIEWABLE_FILE_EXTENSIONS = [
"gif",
"webp",
] as const;

export const HEADER_CONTENT_TYPES = {
pdf: "application/pdf",
txt: "text/plain",
jpeg: "image/jpeg",
jpg: "image/jpeg",
doc: "application/msword",
xls: "application/vnd.ms-excel",
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
epub: "application/epub+zip",
gif: "image/gif",
html: "text/html",
htm: "text/html",
mp4: "video/mp4",
png: "image/png",
ppt: "application/vnd.ms-powerpoint",
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
svg: "image/svg+xml",
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
} as const;

export const ADMIN_USER_TYPES = ["DistrictAdmin", "StateAdmin"] as const;
7 changes: 1 addition & 6 deletions src/components/Common/FacilitySelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ interface BaseFacilitySelectProps {
disabled?: boolean;
multiple?: boolean;
facilityType?: number;
district?: string;
state?: string;
showAll?: boolean;
showNOptions?: number | undefined;
freeText?: boolean;
Expand Down Expand Up @@ -100,10 +98,7 @@ export const FacilitySelect = ({
onChange={setSelected}
fetchData={facilitySearch}
showNOptions={showNOptions}
optionLabel={(option: any) =>
option.name +
(option.district_object ? `, ${option.district_object.name}` : "")
}
optionLabel={(option: any) => option.name}
compareBy="id"
className={className}
error={errors}
Expand Down
44 changes: 0 additions & 44 deletions src/components/Patient/PatientDetailsTab/Demography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,52 +196,8 @@ export const Demography = (props: PatientProps) => {
value: patientData.permanent_address,
},
...getGeoOrgDetails(patientData.geo_organization),

// TODO: Replace with Geo_Org
// {
// label: t("nationality"),
// value: patientData.nationality,
// },
// {
// label: t("state"),
// value: patientData.state,
// },
// {
// label: t("district"),
// value: patientData.district_object?.name,
// },
// {
// label: t("local_body"),
// value: patientData.local_body_object?.name,
// },
// {
// label: t("ward"),
// value: (
// <>
// {(patientData.ward_object &&
// patientData.ward_object.number +
// ", " +
// patientData.ward_object.name) ||
// "-"}
// </>
// ),
// },
],
},
// {
// id: "volunteer-contact",
// hidden: !patientData.assigned_to_object,
// details: [
// <EmergencyContact
// number={patientData.assigned_to_object?.alt_phone_number}
// name={
// patientData.assigned_to_object
// ? formatName(patientData.assigned_to_object)
// : undefined
// }
// />,
// ],
// },
];

return (
Expand Down
14 changes: 2 additions & 12 deletions src/components/Users/UserListAndCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ export const UserGrid = ({ users }: { users?: UserBase[] }) => (
</div>
);

const UserListHeader = ({
showDistrictColumn,
}: {
showDistrictColumn: boolean;
}) => {
const UserListHeader = () => {
const { t } = useTranslation();
return (
<thead>
Expand All @@ -143,9 +139,6 @@ const UserListHeader = ({
<th className="w-32 px-10 py-3 text-left">{t("status")}</th>
<th className="px-10 py-3 text-left">{t("role")}</th>
<th className="px-4 py-3 text-left">{t("contact_number")}</th>
{showDistrictColumn && (
<th className="px-4 py-3 text-left">{t("district")}</th>
)}
</tr>
</thead>
);
Expand Down Expand Up @@ -195,13 +188,10 @@ const UserListRow = ({ user }: { user: UserBase }) => {
);
};
export const UserList = ({ users }: { users?: UserBase[] }) => {
const showDistrictColumn = users?.some(
(user) => "district_object" in user || "district" in user,
);
return (
<div className="overflow-x-auto rounded-lg border border-gray-200">
<table className="relative min-w-full divide-y divide-gray-200">
<UserListHeader showDistrictColumn={showDistrictColumn ?? false} />
<UserListHeader />
<tbody className="divide-y divide-gray-200 bg-white">
{users?.map((user) => <UserListRow key={user.id} user={user} />)}
</tbody>
Expand Down
6 changes: 0 additions & 6 deletions src/components/Users/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ export type UserFacilityModel = {

export type UserModel = UserBareMinimum & {
external_id: string;
local_body?: number;
district?: number;
state?: number;
video_connect_link: string;
phone_number?: string;
alt_phone_number?: string;
Expand All @@ -51,9 +48,6 @@ export type UserModel = UserBareMinimum & {
};

export interface UserAssignedModel extends UserBareMinimum {
local_body?: number;
district?: number;
state?: number;
phone_number?: string;
alt_phone_number?: string;
video_connect_link: string;
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/sidebar/patient-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PatientSwitcher } from "@/components/ui/sidebar/patient-switcher";

import { usePatientContext } from "@/hooks/usePatientUser";

import { AppointmentPatient } from "@/pages/Patient/Utils";
import { Patient } from "@/types/emr/newPatient";

interface NavigationLink {
name: string;
Expand All @@ -15,7 +15,7 @@ interface NavigationLink {
}

function generatePatientLinks(
selectedUser: AppointmentPatient | null,
selectedUser: Patient | null,
t: TFunction,
): NavigationLink[] {
if (!selectedUser) return [];
Expand Down
12 changes: 3 additions & 9 deletions src/pages/Appointments/AppointmentDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
formatName,
getReadableDuration,
saveElementAsImage,
stringifyGeoOrganization,
} from "@/Utils/utils";
import { AppointmentTokenCard } from "@/pages/Appointments/components/AppointmentTokenCard";
import {
Expand Down Expand Up @@ -211,7 +212,7 @@ const AppointmentDetails = ({
appointment: Appointment;
facility: FacilityData;
}) => {
const { patient, user } = appointment;
const { user } = appointment;
const { t } = useTranslation();

return (
Expand Down Expand Up @@ -331,14 +332,7 @@ const AppointmentDetails = ({
{appointment.patient.address || t("no_address_provided")}
</p>
<p className="text-gray-600">
{[
patient.ward,
patient.local_body,
patient.district,
patient.state,
]
.filter(Boolean)
.join(", ")}
{stringifyGeoOrganization(appointment.patient.geo_organization)}
</p>
<p className="text-gray-600">
{t("pincode")}: {appointment.patient.pincode}
Expand Down
Loading

0 comments on commit 2dd94c4

Please sign in to comment.