From 522b376e0e91461106f40f10d4aae0e8f8ec7064 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 30 Jan 2025 16:59:49 +0530 Subject: [PATCH 1/4] Remove pincode autofill feature --- src/components/Facility/FacilityForm.tsx | 70 +--------------- .../Patient/PatientRegistration.tsx | 41 ---------- src/hooks/useStateAndDistrictFromPincode.ts | 79 ------------------- 3 files changed, 4 insertions(+), 186 deletions(-) delete mode 100644 src/hooks/useStateAndDistrictFromPincode.ts diff --git a/src/components/Facility/FacilityForm.tsx b/src/components/Facility/FacilityForm.tsx index 1aea913355c..9f8e1264124 100644 --- a/src/components/Facility/FacilityForm.tsx +++ b/src/components/Facility/FacilityForm.tsx @@ -32,8 +32,6 @@ import { Textarea } from "@/components/ui/textarea"; import { FacilityModel } from "@/components/Facility/models"; -import { useStateAndDistrictFromPincode } from "@/hooks/useStateAndDistrictFromPincode"; - import { FACILITY_FEATURE_TYPES, FACILITY_TYPES } from "@/common/constants"; import { validatePincode } from "@/common/validation"; @@ -44,7 +42,6 @@ import validators from "@/Utils/validators"; import GovtOrganizationSelector from "@/pages/Organization/components/GovtOrganizationSelector"; import { BaseFacility } from "@/types/facility/facility"; import { Organization } from "@/types/organization/organization"; -import organizationApi from "@/types/organization/organizationApi"; interface FacilityProps { organizationId?: string; @@ -52,22 +49,14 @@ interface FacilityProps { onSubmitSuccess?: () => void; } -function extractHierarchyLevels(org: Organization | undefined): Organization[] { - const levels: Organization[] = []; - while (org && org.level_cache >= 0) { - levels.unshift(org as Organization); - org = org.parent as Organization | undefined; - } - return levels; -} - -export default function FacilityForm(props: FacilityProps) { +export default function FacilityForm({ + facilityId, + onSubmitSuccess, +}: FacilityProps) { const { t } = useTranslation(); const queryClient = useQueryClient(); const [isGettingLocation, setIsGettingLocation] = useState(false); - const { facilityId, organizationId, onSubmitSuccess } = props; const [selectedLevels, setSelectedLevels] = useState([]); - const [showAutoFilledPincode, setShowAutoFilledPincode] = useState(false); const facilityFormSchema = z.object({ facility_type: z.string().min(1, t("facility_type_required")), @@ -172,41 +161,6 @@ export default function FacilityForm(props: FacilityProps) { } }; - const { stateOrg, districtOrg } = useStateAndDistrictFromPincode({ - pincode: form.watch("pincode")?.toString() || "", - }); - - const { data: org } = useQuery({ - queryKey: ["organization", organizationId], - queryFn: query(organizationApi.get, { - pathParams: { id: organizationId }, - }), - enabled: !!organizationId && !facilityId, - }); - - useEffect(() => { - if (facilityId) return; - const orgLevels = extractHierarchyLevels(org); - const districtMatch = - districtOrg && orgLevels.some((level) => level.name === districtOrg.name); - const levels: Organization[] = []; - if (districtMatch) return; - if (stateOrg) levels.push(stateOrg); - if (districtOrg) levels.push(districtOrg); - if (!stateOrg && !districtOrg && org) levels.push(org); - - setSelectedLevels(levels); - - if (levels.length == 2) { - setShowAutoFilledPincode(true); - const timer = setTimeout(() => { - setShowAutoFilledPincode(false); - }, 5000); - return () => clearTimeout(timer); - } - return () => setShowAutoFilledPincode(false); - }, [stateOrg, districtOrg, organizationId, facilityId]); - // Update form when facility data is loaded useEffect(() => { if (facilityData) { @@ -367,22 +321,6 @@ export default function FacilityForm(props: FacilityProps) { /> - {showAutoFilledPincode && ( -
-
- )} )} /> diff --git a/src/components/Patient/PatientRegistration.tsx b/src/components/Patient/PatientRegistration.tsx index 35b4615db69..be1ec63e249 100644 --- a/src/components/Patient/PatientRegistration.tsx +++ b/src/components/Patient/PatientRegistration.tsx @@ -8,7 +8,6 @@ import { isValidPhoneNumber } from "react-phone-number-input"; import { toast } from "sonner"; import { z } from "zod"; -import CareIcon from "@/CAREUI/icons/CareIcon"; import SectionNavigator from "@/CAREUI/misc/SectionNavigator"; import Autocomplete from "@/components/ui/autocomplete"; @@ -42,7 +41,6 @@ import Page from "@/components/Common/Page"; import DuplicatePatientDialog from "@/components/Facility/DuplicatePatientDialog"; import useAppHistory from "@/hooks/useAppHistory"; -import { useStateAndDistrictFromPincode } from "@/hooks/useStateAndDistrictFromPincode"; import { BLOOD_GROUP_CHOICES, // DOMESTIC_HEALTHCARE_SUPPORT_CHOICES, @@ -83,7 +81,6 @@ export default function PatientRegistration( const [suppressDuplicateWarning, setSuppressDuplicateWarning] = useState(!!patientId); const [selectedLevels, setSelectedLevels] = useState([]); - const [showAutoFilledPincode, setShowAutoFilledPincode] = useState(false); const formSchema = useMemo( () => @@ -191,28 +188,6 @@ export default function PatientRegistration( }, }); - const { stateOrg, districtOrg } = useStateAndDistrictFromPincode({ - pincode: form.watch("pincode")?.toString() || "", - }); - - useEffect(() => { - // Fill by pincode for patient registration - if (patientId) return; - const levels: Organization[] = []; - if (stateOrg) levels.push(stateOrg); - if (districtOrg) levels.push(districtOrg); - setSelectedLevels(levels); - - if (levels.length == 2) { - setShowAutoFilledPincode(true); - const timer = setTimeout(() => { - setShowAutoFilledPincode(false); - }, 5000); - return () => clearTimeout(timer); - } - return () => setShowAutoFilledPincode(false); - }, [stateOrg, districtOrg, patientId]); - function onSubmit(values: z.infer) { if (patientId) { updatePatient({ ...values, ward_old: undefined }); @@ -664,22 +639,6 @@ export default function PatientRegistration( /> - {showAutoFilledPincode && ( -
-
- )} )} /> diff --git a/src/hooks/useStateAndDistrictFromPincode.ts b/src/hooks/useStateAndDistrictFromPincode.ts deleted file mode 100644 index 1e8b31f3207..00000000000 --- a/src/hooks/useStateAndDistrictFromPincode.ts +++ /dev/null @@ -1,79 +0,0 @@ -import careConfig from "@careConfig"; -import { useQuery } from "@tanstack/react-query"; -import { t } from "i18next"; -import { useEffect } from "react"; -import { toast } from "sonner"; - -import { useOrganization } from "@/hooks/useOrganization"; - -import { validatePincode } from "@/common/validation"; - -import { getPincodeDetails } from "@/Utils/utils"; - -interface UseStateAndDistrictProps { - pincode: string; -} - -interface PincodeResponse { - statename: string; - districtname: string; -} - -export function useStateAndDistrictFromPincode({ - pincode, -}: UseStateAndDistrictProps) { - const { - data: pincodeDetails, - isLoading: isPincodeLoading, - isError: isPincodeError, - } = useQuery({ - queryKey: ["pincode-details", pincode], - queryFn: () => getPincodeDetails(pincode, careConfig.govDataApiKey), - enabled: pincode !== "" && validatePincode(pincode), - }); - - const stateName = pincodeDetails?.statename; - const districtName = pincodeDetails?.districtname; - - const { - organizations: stateOrgs, - isLoading: isStateLoading, - isError: isStateError, - } = useOrganization({ - orgType: "govt", - parentId: "", - name: stateName, - enabled: !!stateName, - }); - - const stateOrg = stateOrgs?.[0]; - - const { - organizations: districtOrgs, - isLoading: isDistrictLoading, - isError: isDistrictError, - } = useOrganization({ - orgType: "govt", - parentId: stateOrg?.id, - name: districtName, - enabled: !!stateOrg?.id && !!districtName, - }); - - useEffect(() => { - if (isStateError || isPincodeError) { - toast.info(t("pincode_state_auto_fill_error")); - } - if (isDistrictError && !isStateError) { - toast.info(t("pincode_district_auto_fill_error")); - } - }, [isStateError, isPincodeError, isDistrictError]); - - const districtOrg = districtOrgs[0]; - - return { - stateOrg, - districtOrg, - isLoading: isPincodeLoading || isStateLoading || isDistrictLoading, - isError: isPincodeError || isStateError || isDistrictError, - }; -} From 437bede2fb68aad10da61e3f5368b15f28299a16 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 30 Jan 2025 17:01:28 +0530 Subject: [PATCH 2/4] remove unused functions --- src/Utils/utils.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/Utils/utils.ts b/src/Utils/utils.ts index 64d8aeca38b..b19ce967866 100644 --- a/src/Utils/utils.ts +++ b/src/Utils/utils.ts @@ -1,6 +1,5 @@ import { differenceInMinutes, format } from "date-fns"; import { toPng } from "html-to-image"; -import { toast } from "sonner"; import dayjs from "@/Utils/dayjs"; import { Time } from "@/Utils/types"; @@ -105,18 +104,6 @@ export const classNames = (...classes: (string | boolean | undefined)[]) => { return classes.filter(Boolean).join(" "); }; -export const getPincodeDetails = async (pincode: string, apiKey: string) => { - const response = await fetch( - `https://api.data.gov.in/resource/6176ee09-3d56-4a3b-8115-21841576b2f6?api-key=${apiKey}&format=json&filters[pincode]=${pincode}&limit=1`, - ); - const data = await response.json(); - if (!data.records || data.records.length === 0) { - toast.error("Invalid pincode"); - return null; - } - return data.records[0]; -}; - export const isUserOnline = (user: { last_login: DateLike }) => { return user.last_login ? dayjs().subtract(5, "minutes").isBefore(user.last_login) From 2dd94c4cc1e18d861df228ca6a46895e1d3ee2dc Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 30 Jan 2025 20:41:36 +0530 Subject: [PATCH 3/4] remove hardcoded state and district terminologies in codebase --- src/Providers/PatientUserProvider.tsx | 15 ++-- src/Utils/permissions.ts | 36 +-------- src/Utils/request/api.tsx | 9 +-- src/Utils/utils.ts | 16 ++++ src/common/constants.tsx | 22 ----- src/components/Common/FacilitySelect.tsx | 7 +- .../Patient/PatientDetailsTab/Demography.tsx | 44 ---------- src/components/Users/UserListAndCard.tsx | 14 +--- src/components/Users/models.tsx | 6 -- src/components/ui/sidebar/patient-nav.tsx | 4 +- src/pages/Appointments/AppointmentDetail.tsx | 12 +-- src/pages/Encounters/EncounterShow.tsx | 81 ------------------- .../Facility/hooks/useFacilityFilters.ts | 23 ------ src/pages/Patient/Utils.tsx | 20 ----- .../PatientRegistration.tsx | 8 +- .../PublicAppointments/PatientSelect.tsx | 13 ++- src/types/emr/patient.ts | 3 - src/types/scheduling/schedule.ts | 4 +- 18 files changed, 45 insertions(+), 292 deletions(-) delete mode 100644 src/pages/Facility/hooks/useFacilityFilters.ts diff --git a/src/Providers/PatientUserProvider.tsx b/src/Providers/PatientUserProvider.tsx index 1ae9a9af8f1..2319d9a2d45 100644 --- a/src/Providers/PatientUserProvider.tsx +++ b/src/Providers/PatientUserProvider.tsx @@ -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; }; @@ -25,9 +25,8 @@ interface Props { } export default function PatientUserProvider({ children }: Props) { - const [patients, setPatients] = useState([]); - const [selectedPatient, setSelectedPatient] = - useState(null); + const [patients, setPatients] = useState([]); + const [selectedPatient, setSelectedPatient] = useState(null); const { patientToken: tokenData } = useAuthContext(); @@ -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 = diff --git a/src/Utils/permissions.ts b/src/Utils/permissions.ts index b8b521c758b..9dd82d9c1f6 100644 --- a/src/Utils/permissions.ts +++ b/src/Utils/permissions.ts @@ -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; }; @@ -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; }; diff --git a/src/Utils/request/api.tsx b/src/Utils/request/api.tsx index 0e3aab2f217..45eddeedb24 100644 --- a/src/Utils/request/api.tsx +++ b/src/Utils/request/api.tsx @@ -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"; @@ -625,7 +622,7 @@ const routes = { getPatient: { path: "/api/v1/otp/patient/", method: "GET", - TRes: Type>(), + TRes: Type>(), auth: { key: "Authorization", value: "Bearer {token}", @@ -636,7 +633,7 @@ const routes = { path: "/api/v1/otp/patient/", method: "POST", TBody: Type>(), - TRes: Type(), + TRes: Type(), auth: { key: "Authorization", value: "Bearer {token}", diff --git a/src/Utils/utils.ts b/src/Utils/utils.ts index 621068156f7..add2677343b 100644 --- a/src/Utils/utils.ts +++ b/src/Utils/utils.ts @@ -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"; @@ -268,3 +272,15 @@ export const conditionalArrayAttribute = ( ) => { 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(", "); +}; diff --git a/src/common/constants.tsx b/src/common/constants.tsx index 820ace57839..ac4db173498 100644 --- a/src/common/constants.tsx +++ b/src/common/constants.tsx @@ -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; diff --git a/src/components/Common/FacilitySelect.tsx b/src/components/Common/FacilitySelect.tsx index 74eb8ac4231..4209de3fc89 100644 --- a/src/components/Common/FacilitySelect.tsx +++ b/src/components/Common/FacilitySelect.tsx @@ -17,8 +17,6 @@ interface BaseFacilitySelectProps { disabled?: boolean; multiple?: boolean; facilityType?: number; - district?: string; - state?: string; showAll?: boolean; showNOptions?: number | undefined; freeText?: boolean; @@ -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} diff --git a/src/components/Patient/PatientDetailsTab/Demography.tsx b/src/components/Patient/PatientDetailsTab/Demography.tsx index b6028112aa1..c71f7a32d24 100644 --- a/src/components/Patient/PatientDetailsTab/Demography.tsx +++ b/src/components/Patient/PatientDetailsTab/Demography.tsx @@ -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: [ - // , - // ], - // }, ]; return ( diff --git a/src/components/Users/UserListAndCard.tsx b/src/components/Users/UserListAndCard.tsx index da6489af294..ee6753c1472 100644 --- a/src/components/Users/UserListAndCard.tsx +++ b/src/components/Users/UserListAndCard.tsx @@ -128,11 +128,7 @@ export const UserGrid = ({ users }: { users?: UserBase[] }) => ( ); -const UserListHeader = ({ - showDistrictColumn, -}: { - showDistrictColumn: boolean; -}) => { +const UserListHeader = () => { const { t } = useTranslation(); return ( @@ -143,9 +139,6 @@ const UserListHeader = ({ {t("status")} {t("role")} {t("contact_number")} - {showDistrictColumn && ( - {t("district")} - )} ); @@ -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 (
- + {users?.map((user) => )} diff --git a/src/components/Users/models.tsx b/src/components/Users/models.tsx index 43c3f6a2ec3..f7a7307e7f7 100644 --- a/src/components/Users/models.tsx +++ b/src/components/Users/models.tsx @@ -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; @@ -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; diff --git a/src/components/ui/sidebar/patient-nav.tsx b/src/components/ui/sidebar/patient-nav.tsx index bc7c9772fce..823256c49f8 100644 --- a/src/components/ui/sidebar/patient-nav.tsx +++ b/src/components/ui/sidebar/patient-nav.tsx @@ -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; @@ -15,7 +15,7 @@ interface NavigationLink { } function generatePatientLinks( - selectedUser: AppointmentPatient | null, + selectedUser: Patient | null, t: TFunction, ): NavigationLink[] { if (!selectedUser) return []; diff --git a/src/pages/Appointments/AppointmentDetail.tsx b/src/pages/Appointments/AppointmentDetail.tsx index 96d6732d15e..2809c96dbe1 100644 --- a/src/pages/Appointments/AppointmentDetail.tsx +++ b/src/pages/Appointments/AppointmentDetail.tsx @@ -54,6 +54,7 @@ import { formatName, getReadableDuration, saveElementAsImage, + stringifyGeoOrganization, } from "@/Utils/utils"; import { AppointmentTokenCard } from "@/pages/Appointments/components/AppointmentTokenCard"; import { @@ -211,7 +212,7 @@ const AppointmentDetails = ({ appointment: Appointment; facility: FacilityData; }) => { - const { patient, user } = appointment; + const { user } = appointment; const { t } = useTranslation(); return ( @@ -331,14 +332,7 @@ const AppointmentDetails = ({ {appointment.patient.address || t("no_address_provided")}

- {[ - patient.ward, - patient.local_body, - patient.district, - patient.state, - ] - .filter(Boolean) - .join(", ")} + {stringifyGeoOrganization(appointment.patient.geo_organization)}

{t("pincode")}: {appointment.patient.pincode} diff --git a/src/pages/Encounters/EncounterShow.tsx b/src/pages/Encounters/EncounterShow.tsx index 5776ed85fe8..c07f8e611e4 100644 --- a/src/pages/Encounters/EncounterShow.tsx +++ b/src/pages/Encounters/EncounterShow.tsx @@ -56,31 +56,6 @@ export const EncounterShow = (props: Props) => { ...pluginTabs, }; - // if (Object.keys(tabs).includes(tab.toUpperCase())) { - // tab = tab.toUpperCase(); - // } - // const [showDoctors, setShowDoctors] = useState(false); - // const [patientData, setPatientData] = useState(); - // const [activeShiftingData, setActiveShiftingData] = useState>([]); - - // const getPatientGender = (patientData: any) => - // GENDER_TYPES.find((i) => i.id === patientData.gender)?.text; - - // const getPatientAddress = (patientData: any) => - // `${patientData.address},\n${patientData.ward_object?.name},\n${patientData.local_body_object?.name},\n${patientData.district_object?.name},\n${patientData.state_object?.name}`; - - // const getPatientComorbidities = (patientData: any) => { - // if (patientData?.medical_history?.length) { - // return humanizeStrings( - // patientData.medical_history.map((item: any) => item.disease), - // ); - // } else { - // return "None"; - // } - // }; - - // const authUser = useAuthUser(); - const { data: encounterData, isLoading } = useQuery({ queryKey: ["encounter", encounterId], queryFn: query(routes.encounter.get, { @@ -92,62 +67,6 @@ export const EncounterShow = (props: Props) => { enabled: !!encounterId, }); - // const encounterQuery = useTanStackQueryInstead(routes.encounter.get, { - // pathParams: { id: consultationId }, - // }); - - // const consultationData = encounterQuery.data; - // const bedId = consultationData?.current_bed?.bed_object?.id; - - // const isCameraAttached = useTanStackQueryInstead(routes.listAssetBeds, { - // prefetch: !!bedId, - // query: { bed: bedId }, - // }).data?.results.some((a) => a.asset_object.asset_class === "ONVIF"); - - // const patientDataQuery = useTanStackQueryInstead(routes.getPatient, { - // pathParams: { id: consultationQuery.data?.patient ?? "" }, - // prefetch: !!consultationQuery.data?.patient, - // onResponse: ({ data }) => { - // if (!data) { - // return; - // } - // setPatientData({ - // ...data, - // gender: getPatientGender(data), - // address: getPatientAddress(data), - // comorbidities: getPatientComorbidities(data), - // is_declared_positive: data.is_declared_positive ? "Yes" : "No", - // is_vaccinated: patientData?.is_vaccinated ? "Yes" : "No", - // } as any); - // }, - // }); - - // const fetchData = useCallback( - // async (id: string) => { - // // Get shifting data - // const shiftRequestsQuery = await request(routes.listShiftRequests, { - // query: { patient: id }, - // }); - // if (shiftRequestsQuery.data?.results) { - // setActiveShiftingData(shiftRequestsQuery.data.results); - // } - // }, - // [consultationId, patientData?.is_vaccinated], - // ); - - // useEffect(() => { - // const id = patientDataQuery.data?.id; - // if (!id) { - // return; - // } - // fetchData(id); - // triggerGoal("Patient Consultation Viewed", { - // facilityId: facilityId, - // consultationId: consultationId, - // userId: authUser.id, - // }); - // }, [patientDataQuery.data?.id]); - if (isLoading || !encounterData) { return ; } diff --git a/src/pages/Facility/hooks/useFacilityFilters.ts b/src/pages/Facility/hooks/useFacilityFilters.ts deleted file mode 100644 index cb3fae51ff2..00000000000 --- a/src/pages/Facility/hooks/useFacilityFilters.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { useState } from "react"; - -interface Filters { - district: string; - local_body: string; - page: string; - limit: string; - [key: string]: string; -} - -interface Props { - initialFilters: Filters; - qParams: Partial; -} - -export function useFacilityFilters({ initialFilters }: Props) { - const [filters, setFilters] = useState(initialFilters); - - return { - filters, - setFilters, - }; -} diff --git a/src/pages/Patient/Utils.tsx b/src/pages/Patient/Utils.tsx index 68f3ae524a3..76910dffe96 100644 --- a/src/pages/Patient/Utils.tsx +++ b/src/pages/Patient/Utils.tsx @@ -1,5 +1,3 @@ -import { Organization } from "@/types/organization/organization"; - export type AppointmentPatientRegister = { name: string; gender: string; @@ -10,21 +8,3 @@ export type AppointmentPatientRegister = { geo_organization?: string; pincode?: string; }; - -export type AppointmentPatient = { - id: string; - external_id: string; - name: string; - phone_number: string; - emergency_phone_number: string; - address: string; - date_of_birth?: string; - year_of_birth?: string; - state: number; - district: number; - local_body: number; - ward: number; - pincode: number; - gender: string; - geo_organization: Organization; -}; diff --git a/src/pages/PublicAppointments/PatientRegistration.tsx b/src/pages/PublicAppointments/PatientRegistration.tsx index 855e3fe1336..db65c045a48 100644 --- a/src/pages/PublicAppointments/PatientRegistration.tsx +++ b/src/pages/PublicAppointments/PatientRegistration.tsx @@ -33,10 +33,8 @@ import mutate from "@/Utils/request/mutate"; import { HTTPError } from "@/Utils/request/types"; import { dateQueryString } from "@/Utils/utils"; import GovtOrganizationSelector from "@/pages/Organization/components/GovtOrganizationSelector"; -import { - AppointmentPatient, - AppointmentPatientRegister, -} from "@/pages/Patient/Utils"; +import { AppointmentPatientRegister } from "@/pages/Patient/Utils"; +import { Patient } from "@/types/emr/newPatient"; import PublicAppointmentApi from "@/types/scheduling/PublicAppointmentApi"; import { Appointment, @@ -174,7 +172,7 @@ export function PatientRegistration(props: PatientRegistrationProps) { Authorization: `Bearer ${tokenData.token}`, }, })(body), - onSuccess: (data: AppointmentPatient) => { + onSuccess: (data: Patient) => { toast.success(t("patient_created_successfully")); publish("patient:upsert", data); createAppointment({ diff --git a/src/pages/PublicAppointments/PatientSelect.tsx b/src/pages/PublicAppointments/PatientSelect.tsx index 75c8422c8ba..0385c3ffd4f 100644 --- a/src/pages/PublicAppointments/PatientSelect.tsx +++ b/src/pages/PublicAppointments/PatientSelect.tsx @@ -14,8 +14,7 @@ import { usePatientContext } from "@/hooks/usePatientUser"; import routes from "@/Utils/request/api"; import mutate from "@/Utils/request/mutate"; import query from "@/Utils/request/query"; -import { PaginatedResponse } from "@/Utils/request/types"; -import { AppointmentPatient } from "@/pages/Patient/Utils"; +import { Patient } from "@/types/emr/newPatient"; import PublicAppointmentApi from "@/types/scheduling/PublicAppointmentApi"; import { Appointment, @@ -55,9 +54,7 @@ export default function PatientSelect({ ); } - const { data: patientData, isLoading } = useQuery< - PaginatedResponse - >({ + const { data: patientData, isLoading } = useQuery({ queryKey: ["otp-patient"], queryFn: query(routes.otp.getPatient, { headers: { @@ -106,11 +103,11 @@ export default function PatientSelect({ ); }; - const getPatienDoBorAge = (patient: AppointmentPatient) => { + const getPatienDoBorAge = (patient: Patient) => { if (patient.date_of_birth) { return dayjs(patient.date_of_birth).format("DD MMM YYYY"); } - const yearOfBirth = parseInt(patient.year_of_birth ?? ""); + const yearOfBirth = patient.year_of_birth; const age = dayjs().year() - yearOfBirth; return `${age} years`; }; @@ -178,7 +175,7 @@ export default function PatientSelect({ {patient.phone_number}

- {getPatienDoBorAge(patient as AppointmentPatient)} + {getPatienDoBorAge(patient)} {t(`GENDER__${patient.gender}`)} diff --git a/src/types/emr/patient.ts b/src/types/emr/patient.ts index eebe4b9e305..0724dd45eb5 100644 --- a/src/types/emr/patient.ts +++ b/src/types/emr/patient.ts @@ -56,9 +56,6 @@ export interface PatientModel { transit_details?: string; present_health?: string; has_SARI?: boolean; - local_body?: number; - district?: number; - state?: number; nationality?: string; passport_no?: string; ration_card_category?: (typeof RATION_CARD_CATEGORY)[number] | null; diff --git a/src/types/scheduling/schedule.ts b/src/types/scheduling/schedule.ts index 62fe2793a3c..cc895624513 100644 --- a/src/types/scheduling/schedule.ts +++ b/src/types/scheduling/schedule.ts @@ -1,7 +1,7 @@ import { DayOfWeek } from "@/CAREUI/interactive/WeekdayCheckbox"; import { Time } from "@/Utils/types"; -import { AppointmentPatient } from "@/pages/Patient/Utils"; +import { Patient } from "@/types/emr/newPatient"; import { FacilityBareMinimum } from "@/types/facility/facility"; import { UserBase } from "@/types/user/user"; @@ -140,7 +140,7 @@ export type AppointmentStatus = (typeof AppointmentStatuses)[number]; export interface Appointment { id: string; token_slot: TokenSlot; - patient: AppointmentPatient; + patient: Patient; booked_on: string; status: AppointmentNonCancelledStatus; reason_for_visit: string; From fb769098a395b364a1bf7b7512331304384da8b5 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Fri, 31 Jan 2025 14:43:19 +0530 Subject: [PATCH 4/4] fix the cypress --- cypress/e2e/facility_spec/facility_creation.cy.ts | 2 ++ cypress/pageObject/facility/FacilityCreation.ts | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/facility_spec/facility_creation.cy.ts b/cypress/e2e/facility_spec/facility_creation.cy.ts index fd4c3f97c50..d6fca2832b6 100644 --- a/cypress/e2e/facility_spec/facility_creation.cy.ts +++ b/cypress/e2e/facility_spec/facility_creation.cy.ts @@ -3,6 +3,8 @@ import { generatePhoneNumber } from "@/utils/commonUtils"; import { generateFacilityData } from "@/utils/facilityData"; const LOCATION_HIERARCHY = { + state: "Kerala", + district: "Ernakulam", localBody: "Aluva", ward: "4", }; diff --git a/cypress/pageObject/facility/FacilityCreation.ts b/cypress/pageObject/facility/FacilityCreation.ts index 8f7e0edf319..054cb3539e9 100644 --- a/cypress/pageObject/facility/FacilityCreation.ts +++ b/cypress/pageObject/facility/FacilityCreation.ts @@ -126,7 +126,18 @@ export class FacilityCreation { .should("not.be.empty"); } - fillLocationHierarchy(location: { localBody: string; ward: string }) { + fillLocationHierarchy(location: { + state: string; + district: string; + localBody: string; + ward: string; + }) { + cy.typeAndSelectOption('[data-cy="select-state"]', location.state, false); + cy.typeAndSelectOption( + '[data-cy="select-district"]', + location.district, + false, + ); // Don't verify selection for local body (false parameter) cy.typeAndSelectOption( '[data-cy="select-local_body"]',