From 11664931a0e0f8bd0012e6f7e0f996f08546f6f1 Mon Sep 17 00:00:00 2001 From: Bodhish Thomas Date: Sun, 5 Jan 2025 16:30:11 +0530 Subject: [PATCH 1/2] Enhance organization management by adding new organization types and updating related components. Refactor organization level retrieval to use metadata for improved localization. Remove deprecated organization levels constant and clean up unused code in various components. --- public/locale/en.json | 13 ++++++ src/common/constants.tsx | 9 ---- src/components/Facility/FacilityHome.tsx | 10 ++--- .../Patient/PatientDetailsTab/Demography.tsx | 43 ++----------------- src/pages/Organization/OrganizationIndex.tsx | 8 ++-- src/pages/Organization/OrganizationView.tsx | 16 ++++--- .../components/OrganizationLayout.tsx | 6 +-- .../components/OrganizationSelector.tsx | 24 +++++------ src/pages/UserDashboard.tsx | 5 +-- src/types/organization/organization.ts | 23 +++++----- 10 files changed, 62 insertions(+), 95 deletions(-) diff --git a/public/locale/en.json b/public/locale/en.json index 1a858bb77a8..20885bf0435 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -224,6 +224,19 @@ "SPO2_LEVEL_MODERATE_HYPOXEMIA": "Moderate Hypoxemia", "SPO2_LEVEL_NORMAL": "Normal", "SPO2_LEVEL_SEVERE_HYPOXEMIA": "Severe Hypoxemia", + "SYSTEM__govt_org_type__block_panchayat": "Block Panchayat", + "SYSTEM__govt_org_type__corporation": "Corporation", + "SYSTEM__govt_org_type__default": "State", + "SYSTEM__govt_org_type__district": "District", + "SYSTEM__govt_org_type__grama_panchayat": "Grama Panchayat", + "SYSTEM__govt_org_type__local_body": "Local Body", + "SYSTEM__govt_org_type__muncipality": "Muncipality", + "SYSTEM__govt_org_type__state": "State", + "SYSTEM__govt_org_type__ward": "Ward", + "SYSTEM__org_type__default": "Organization", + "SYSTEM__org_type__govt": "Government", + "SYSTEM__org_type__role": "Role", + "SYSTEM__org_type__team": "Team", "Submit": "Submit", "TELEMEDICINE": "Telemedicine", "TRANSPORTATION TO BE ARRANGED": "Transportation", diff --git a/src/common/constants.tsx b/src/common/constants.tsx index b31691bda30..39fe769520c 100644 --- a/src/common/constants.tsx +++ b/src/common/constants.tsx @@ -1762,12 +1762,3 @@ export const ADMIN_USER_TYPES = ["DistrictAdmin", "StateAdmin"] as const; * @deprecated use `LocalStorageKeys.patientTokenKey` instead */ export const CarePatientTokenKey = LocalStorageKeys.patientTokenKey; - -// organization_levels map based of type. for govt -// thought: This might be better placed in the organization types files -export const ORGANIZATION_LEVELS = { - govt: ["State", "District", "LocalBody", "Ward"], - team: ["Team"], - role: ["Role"], - other: ["Other"], -}; diff --git a/src/components/Facility/FacilityHome.tsx b/src/components/Facility/FacilityHome.tsx index 615952be3ba..85d688d1740 100644 --- a/src/components/Facility/FacilityHome.tsx +++ b/src/components/Facility/FacilityHome.tsx @@ -38,7 +38,7 @@ import type { Organization, OrganizationParent, } from "@/types/organization/organization"; -import { getOrgLevelLabel } from "@/types/organization/organization"; +import { getOrgLabel } from "@/types/organization/organization"; import type { UserModel } from "../Users/models"; @@ -77,7 +77,7 @@ const renderGeoOrganizations = (geoOrg: Organization) => { const parentDetails = orgParents.map((org) => { return { - label: getOrgLevelLabel(org.org_type, org.level_cache), + label: getOrgLabel(org.org_type, org.metadata), value: org.name, }; }); @@ -85,14 +85,14 @@ const renderGeoOrganizations = (geoOrg: Organization) => { return parentDetails .reverse() .concat({ - label: getOrgLevelLabel(geoOrg.org_type, geoOrg.level_cache), + label: getOrgLabel(geoOrg.org_type, geoOrg.metadata), value: geoOrg.name, }) .map((org, index) => ( - {org.value} + {org.value} {index < parentDetails.length - 1 && ( - + )} )); diff --git a/src/components/Patient/PatientDetailsTab/Demography.tsx b/src/components/Patient/PatientDetailsTab/Demography.tsx index e472da1b474..f970011e221 100644 --- a/src/components/Patient/PatientDetailsTab/Demography.tsx +++ b/src/components/Patient/PatientDetailsTab/Demography.tsx @@ -16,7 +16,7 @@ import { formatPatientAge } from "@/Utils/utils"; import { Organization, OrganizationParent, - getOrgLevelLabel, + getOrgLabel, } from "@/types/organization/organization"; export const Demography = (props: PatientProps) => { @@ -25,34 +25,6 @@ export const Demography = (props: PatientProps) => { const [activeSection, _setActiveSection] = useState(null); - // useEffect(() => { - // setAssignedVolunteerObject(patientData.assigned_to_object); - - // const observedSections: Element[] = []; - // const sections = document.querySelectorAll("div[id]"); - // const observer = new IntersectionObserver( - // (entries) => { - // entries.forEach((entry) => { - // if (entry.isIntersecting) { - // setActiveSection(entry.target.id); - // } - // }); - // }, - // { - // threshold: 0.6, - // }, - // ); - - // sections.forEach((section) => { - // observer.observe(section); - // observedSections.push(section); - // }); - - // return () => { - // observedSections.forEach((section) => observer.unobserve(section)); - // }; - // }, [patientData.assigned_to_object]); - const patientGender = GENDER_TYPES.find( (i) => i.id === patientData.gender, )?.text; @@ -137,15 +109,6 @@ export const Demography = (props: PatientProps) => { details: (React.ReactNode | { label: string; value: React.ReactNode })[]; }; - // const orgParents: OrganizationParent[] = []; - // let currentParent = org.parent; - // while (currentParent) { - // if (currentParent.id) { - // orgParents.push(currentParent); - // } - // currentParent = currentParent.parent; - // } - const getGeoOrgDetails = (geoOrg: Organization) => { const orgParents: OrganizationParent[] = []; let currentParent = geoOrg.parent; @@ -158,13 +121,13 @@ export const Demography = (props: PatientProps) => { const parentDetails = orgParents.map((org) => { return { - label: getOrgLevelLabel(org.org_type, org.level_cache), + label: getOrgLabel(org.org_type, org.metadata), value: org.name, }; }); return parentDetails.reverse().concat({ - label: getOrgLevelLabel(geoOrg.org_type, geoOrg.level_cache), + label: getOrgLabel(geoOrg.org_type, geoOrg.metadata), value: geoOrg.name, }); }; diff --git a/src/pages/Organization/OrganizationIndex.tsx b/src/pages/Organization/OrganizationIndex.tsx index ddd3abbab0d..1719b70caab 100644 --- a/src/pages/Organization/OrganizationIndex.tsx +++ b/src/pages/Organization/OrganizationIndex.tsx @@ -17,8 +17,10 @@ import { Skeleton } from "@/components/ui/skeleton"; import Page from "@/components/Common/Page"; import query from "@/Utils/request/query"; -import type { Organization } from "@/types/organization/organization"; -import { getOrgLevel } from "@/types/organization/organization"; +import { + type Organization, + getOrgLabel, +} from "@/types/organization/organization"; import organizationApi from "@/types/organization/organizationApi"; export default function OrganizationIndex() { @@ -88,7 +90,7 @@ export default function OrganizationIndex() { {org.name} - {getOrgLevel(org.org_type, org.level_cache)} + {getOrgLabel(org.org_type, org.metadata)} diff --git a/src/pages/Organization/OrganizationView.tsx b/src/pages/Organization/OrganizationView.tsx index 92a0b741eca..cd2c1b492a4 100644 --- a/src/pages/Organization/OrganizationView.tsx +++ b/src/pages/Organization/OrganizationView.tsx @@ -12,7 +12,7 @@ import { Input } from "@/components/ui/input"; import Pagination from "@/components/Common/Pagination"; import query from "@/Utils/request/query"; -import { Organization, getOrgLevel } from "@/types/organization/organization"; +import { Organization, getOrgLabel } from "@/types/organization/organization"; import organizationApi from "@/types/organization/organizationApi"; import OrganizationLayout from "./components/OrganizationLayout"; @@ -95,12 +95,14 @@ export default function OrganizationView({ id, navOrganizationId }: Props) { {orgChild.org_type} - - {getOrgLevel( - orgChild.org_type, - orgChild.level_cache, - )} - + {orgChild.metadata?.govt_org_type && ( + + {getOrgLabel( + orgChild.org_type, + orgChild.metadata, + )} + + )} +