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

Refactor care config to use camelCase variables and remove useConfig hook #8450

Merged
merged 4 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ REACT_GITHUB_URL=
# OHCN URL (default: https://ohc.network?ref=care)
REACT_OHCN_URL=

# Site URL (default: care.ohc.network)
REACT_SITE_URL=
# Plausible site domain (default: care.ohc.network)
REACT_PLAUSIBLE_SITE_DOMAIN=

# Analytics server URL (default: https://plausible.10bedicu.in)
REACT_ANALYTICS_SERVER_URL=
# Plausible server URL (default: https://plausible.10bedicu.in)
REACT_PLAUSIBLE_SERVER_URL=

# Header logo URLs
REACT_HEADER_LOGO_LIGHT=
REACT_HEADER_LOGO_DARK=

# Main logo URLs
REACT_MAIN_LOGO_LIGHT=
REACT_MAIN_LOGO_DARK=
# Main logo (JSON string with light and dark properties)
REACT_HEADER_LOGO=

# Main logo (JSON string with light and dark properties)
REACT_MAIN_LOGO=
Comment on lines +20 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add examples when the we are expecting structures.


# State logo (JSON string with light and dark properties)
REACT_STATE_LOGO=
Expand Down Expand Up @@ -66,7 +65,7 @@ REACT_ENABLE_ABDM=true
REACT_ENABLE_SCRIBE=true
REACT_WARTIME_SHIFTING=true

# JWT token refresh interval (in milliseconds)
# JWT token refresh interval (in milliseconds) (default: 5 minutes)
REACT_JWT_TOKEN_REFRESH_INTERVAL=

# Minimum encounter date (default: 2020-01-01)
Expand Down
10 changes: 9 additions & 1 deletion .storybook/vite.config.mts
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
import path from "node:path";

/** @type {import('vite').UserConfig} */
export default {};
export default {
resolve: {
alias: {
"@careConfig": path.resolve(__dirname, "../care.config.ts"),
},
},
};
184 changes: 88 additions & 96 deletions care.config.ts
Original file line number Diff line number Diff line change
@@ -1,103 +1,95 @@
export interface Logo {
const env = import.meta.env;

interface ILogo {
light: string;
dark: string;
}

export interface CareConfig {
dashboard_url?: string;
github_url: string;
ohcn_url: string;
site_url: string;
analytics_server_url: string;
main_logo: Logo;
state_logo?: Logo;
custom_logo?: Logo;
custom_logo_alt?: Logo;
custom_description?: string;
gmaps_api_key: string;
gov_data_api_key: string;
recaptcha_site_key: string;
sentry_dsn: string;
sentry_environment: string;
header_logo: Logo;
kasp_enabled: boolean;
kasp_string: string;
kasp_full_string: string;
sample_format_asset_import: string;
sample_format_external_result_import: string;
enable_hcx: boolean;
enable_abdm: boolean;
enable_scribe: boolean;
wartime_shifting: boolean;
jwt_token_refresh_interval?: number;
min_encounter_date: string;
}
const logo = (value?: string, fallback?: ILogo) => {
return value ? (JSON.parse(value) as ILogo) : fallback;
};

export const careConfig: CareConfig = {
dashboard_url: import.meta.env.REACT_DASHBOARD_URL,
github_url:
import.meta.env.REACT_GITHUB_URL || "https://github.com/ohcnetwork",
ohcn_url: import.meta.env.REACT_OHCN_URL || "https://ohc.network?ref=care",
site_url: import.meta.env.REACT_SITE_URL || "care.ohc.network",
analytics_server_url:
import.meta.env.REACT_ANALYTICS_SERVER_URL ||
"https://plausible.10bedicu.in",
header_logo: {
light:
import.meta.env.REACT_HEADER_LOGO_LIGHT ||
"https://cdn.ohc.network/header_logo.png",
dark:
import.meta.env.REACT_HEADER_LOGO_DARK ||
"https://cdn.ohc.network/header_logo.png",
},
main_logo: {
light:
import.meta.env.REACT_MAIN_LOGO_LIGHT ||
"https://cdn.ohc.network/light-logo.svg",
dark:
import.meta.env.REACT_MAIN_LOGO_DARK ||
"https://cdn.ohc.network/black-logo.svg",
const careConfig = {
apiUrl: env.REACT_CARE_API_URL,

urls: {
dashboard: env.REACT_DASHBOARD_URL,
github: env.REACT_GITHUB_URL || "https://github.com/ohcnetwork",
ohcn: env.REACT_OHCN_URL || "https://ohc.network?ref=care",
},
state_logo: import.meta.env.REACT_STATE_LOGO
? JSON.parse(import.meta.env.REACT_STATE_LOGO)
: undefined,
custom_logo: import.meta.env.REACT_CUSTOM_LOGO
? JSON.parse(import.meta.env.REACT_CUSTOM_LOGO)
: undefined,
custom_logo_alt: import.meta.env.REACT_CUSTOM_LOGO_ALT
? JSON.parse(import.meta.env.REACT_CUSTOM_LOGO_ALT)
: undefined,
custom_description: import.meta.env.REACT_CUSTOM_DESCRIPTION,
gmaps_api_key:
import.meta.env.REACT_GMAPS_API_KEY ||
"AIzaSyDsBAc3y7deI5ZO3NtK5GuzKwtUzQNJNUk",
gov_data_api_key:
import.meta.env.REACT_GOV_DATA_API_KEY ||

headerLogo: logo(env.REACT_HEADER_LOGO, {
light: "https://cdn.ohc.network/header_logo.png",
dark: "https://cdn.ohc.network/header_logo.png",
}),
mainLogo: logo(env.REACT_MAIN_LOGO, {
light: "https://cdn.ohc.network/light-logo.svg",
dark: "https://cdn.ohc.network/black-logo.svg",
}),
stateLogo: logo(env.REACT_STATE_LOGO),
customLogo: logo(env.REACT_CUSTOM_LOGO),
customLogoAlt: logo(env.REACT_CUSTOM_LOGO_ALT),
customDescription: env.REACT_CUSTOM_DESCRIPTION,

gmapsApiKey:
env.REACT_GMAPS_API_KEY || "AIzaSyDsBAc3y7deI5ZO3NtK5GuzKwtUzQNJNUk",

govDataApiKey:
env.REACT_GOV_DATA_API_KEY ||
"579b464db66ec23bdd000001cdd3946e44ce4aad7209ff7b23ac571b",
recaptcha_site_key:
import.meta.env.REACT_RECAPTCHA_SITE_KEY ||
"6LdvxuQUAAAAADDWVflgBqyHGfq-xmvNJaToM0pN",
sentry_dsn:
import.meta.env.REACT_SENTRY_DSN ||
"https://[email protected]/5183632",
sentry_environment: import.meta.env.REACT_SENTRY_ENVIRONMENT || "staging",
kasp_enabled: import.meta.env.REACT_KASP_ENABLED === "true",
kasp_string: import.meta.env.REACT_KASP_STRING || "KASP",
kasp_full_string:
import.meta.env.REACT_KASP_FULL_STRING ||
"Karunya Arogya Suraksha Padhathi",
sample_format_asset_import:
import.meta.env.REACT_SAMPLE_FORMAT_ASSET_IMPORT ||
"/asset-import-template.xlsx",
sample_format_external_result_import:
import.meta.env.REACT_SAMPLE_FORMAT_EXTERNAL_RESULT_IMPORT ||
"/External-Results-Template.csv",
enable_hcx: import.meta.env.REACT_ENABLE_HCX === "true",
enable_abdm: import.meta.env.REACT_ENABLE_ABDM === "true" || true,
enable_scribe: import.meta.env.REACT_ENABLE_SCRIBE === "true",
wartime_shifting: import.meta.env.REACT_WARTIME_SHIFTING === "true",
jwt_token_refresh_interval: import.meta.env.REACT_JWT_TOKEN_REFRESH_INTERVAL
? parseInt(import.meta.env.REACT_JWT_TOKEN_REFRESH_INTERVAL)
: undefined,
min_encounter_date: import.meta.env.REACT_MIN_ENCOUNTER_DATE || "2020-01-01",
};
reCaptchaSiteKey:
env.REACT_RECAPTCHA_SITE_KEY || "6LdvxuQUAAAAADDWVflgBqyHGfq-xmvNJaToM0pN",

kasp: {
enabled: env.REACT_KASP_ENABLED === "true",
string: env.REACT_KASP_STRING || "KASP",
fullString:
env.REACT_KASP_FULL_STRING || "Karunya Arogya Suraksha Padhathi",
},

sampleFormats: {
assetImport:
env.REACT_SAMPLE_FORMAT_ASSET_IMPORT || "/asset-import-template.xlsx",
externalResultImport:
env.REACT_SAMPLE_FORMAT_EXTERNAL_RESULT_IMPORT ||
"/External-Results-Template.csv",
},

wartimeShifting: env.REACT_WARTIME_SHIFTING === "true",

auth: {
tokenRefreshInterval: env.REACT_JWT_TOKEN_REFRESH_INTERVAL
? parseInt(env.REACT_JWT_TOKEN_REFRESH_INTERVAL)
: 5 * 60e3,
},

minEncounterDate: new Date(env.REACT_MIN_ENCOUNTER_DATE || "2020-01-01"),

// Plugins related configs...

plausible: {
server: env.REACT_PLAUSIBLE_SERVER_URL || "https://plausible.10bedicu.in",
domain: env.REACT_PLAUSIBLE_SITE_DOMAIN || "care.ohc.network",
},

sentry: {
dsn:
env.REACT_SENTRY_DSN ||
"https://[email protected]/5183632",
environment: env.REACT_SENTRY_ENVIRONMENT || "staging",
},

hcx: {
enabled: env.REACT_ENABLE_HCX === "true",
},

abdm: {
enabled: (env.REACT_ENABLE_ABDM ?? "true") === "true",
},

scribe: {
enabled: env.REACT_ENABLE_SCRIBE === "true",
},
} as const;

export default careConfig;
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<meta property="og:title" content="%REACT_APP_TITLE%" />
<meta property="og:description" content="%REACT_APP_META_DESCRIPTION%" />
<meta property="og:image" content="%REACT_APP_COVER_IMAGE%" />
<meta property=" og:url" content="%REACT_PUBLIC_URL%" />
<meta property="og:url" content="%REACT_PUBLIC_URL%" />
<meta property="og:site_name" content="%REACT_APP_TITLE%" />
<meta name="twitter:title" content="%REACT_APP_TITLE%" />
<meta name="twitter:description" content="%REACT_APP_META_DESCRIPTION%" />
Expand Down
21 changes: 8 additions & 13 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
import { Suspense } from "react";
import Routers from "./Routers";
import {
AppConfigProvider,
AuthUserProvider,
HistoryAPIProvider,
} from "./Providers";
import ThemedFavicon from "./CAREUI/misc/ThemedFavicon";
import Intergrations from "./Integrations";
import Loading from "./Components/Common/Loading";
import HistoryAPIProvider from "./Providers/HistoryAPIProvider";
import AuthUserProvider from "./Providers/AuthUserProvider";

const App = () => {
return (
<Suspense fallback={<Loading />}>
<ThemedFavicon />
<HistoryAPIProvider>
<AppConfigProvider>
<AuthUserProvider unauthorized={<Routers.SessionRouter />}>
<Routers.AppRouter />
</AuthUserProvider>
<AuthUserProvider unauthorized={<Routers.SessionRouter />}>
<Routers.AppRouter />
</AuthUserProvider>

{/* Integrations */}
<Intergrations.Sentry disabled={!import.meta.env.PROD} />
<Intergrations.Plausible />
</AppConfigProvider>
{/* Integrations */}
<Intergrations.Sentry disabled={!import.meta.env.PROD} />
<Intergrations.Plausible />
</HistoryAPIProvider>
</Suspense>
);
Expand Down
53 changes: 25 additions & 28 deletions src/Common/constants.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CareConfig } from "../../care.config";
import { PatientCategory } from "../Components/Facility/models";
import { SortOption } from "../Components/Common/SortDropdown";
import { dateQueryString } from "../Utils/utils";
Expand All @@ -9,6 +8,7 @@ import {
ConsentHIType,
ConsentPurpose,
} from "../Components/ABDM/types/consent";
import careConfig from "@careConfig";

export const RESULTS_PER_PAGE_LIMIT = 14;
export const PAGINATION_LIMIT = 36;
Expand Down Expand Up @@ -217,33 +217,30 @@ export const DISCHARGED_PATIENT_SORT_OPTIONS: SortOption[] = [
{ isAscending: false, value: "-name" },
];

export const getBedTypes = ({
kasp_enabled,
kasp_string,
}: Pick<CareConfig, "kasp_enabled" | "kasp_string">) => {
const kaspBedTypes = kasp_enabled
? [
{ id: 40, text: kasp_string + " Ordinary Beds" },
{ id: 60, text: kasp_string + " Oxygen beds" },
{ id: 50, text: kasp_string + " ICU (ICU without ventilator)" },
{ id: 70, text: kasp_string + " ICU (ICU with ventilator)" },
]
: [];

return [
{ id: 1, text: "Ordinary Beds" },
{ id: 150, text: "Oxygen beds" },
{ id: 10, text: "ICU (ICU without ventilator)" },
{ id: 20, text: "Ventilator (ICU with ventilator)" },
{ id: 30, text: "Covid Ordinary Beds" },
{ id: 120, text: "Covid Oxygen beds" },
{ id: 110, text: "Covid ICU (ICU without ventilator)" },
{ id: 100, text: "Covid Ventilators (ICU with ventilator)" },
...kaspBedTypes,
{ id: 2, text: "Hostel" },
{ id: 3, text: "Single Room with Attached Bathroom" },
];
};
const { kasp } = careConfig;

const KASP_BED_TYPES = kasp.enabled
? [
{ id: 40, text: kasp.string + " Ordinary Beds" },
{ id: 60, text: kasp.string + " Oxygen beds" },
{ id: 50, text: kasp.string + " ICU (ICU without ventilator)" },
{ id: 70, text: kasp.string + " ICU (ICU with ventilator)" },
]
: [];

export const BED_TYPES: OptionsType[] = [
{ id: 1, text: "Ordinary Beds" },
{ id: 150, text: "Oxygen beds" },
{ id: 10, text: "ICU (ICU without ventilator)" },
{ id: 20, text: "Ventilator (ICU with ventilator)" },
{ id: 30, text: "Covid Ordinary Beds" },
{ id: 120, text: "Covid Oxygen beds" },
{ id: 110, text: "Covid ICU (ICU without ventilator)" },
{ id: 100, text: "Covid Ventilators (ICU with ventilator)" },
...KASP_BED_TYPES,
{ id: 2, text: "Hostel" },
{ id: 3, text: "Single Room with Attached Bathroom" },
];

export const DOCTOR_SPECIALIZATION: Array<OptionsType> = [
{ id: 1, text: "General Medicine" },
Expand Down
16 changes: 0 additions & 16 deletions src/Common/hooks/useConfig.ts

This file was deleted.

Loading
Loading