Skip to content

Commit

Permalink
Merge branch 'main' into new-logic
Browse files Browse the repository at this point in the history
  • Loading branch information
its-kios09 authored Jan 28, 2025
2 parents ebfd029 + c6c3f94 commit 1d42b39
Show file tree
Hide file tree
Showing 16 changed files with 21,331 additions and 26 deletions.
20,824 changes: 20,824 additions & 0 deletions packages/esm-billing-app/src/hooks/payload.json

Large diffs are not rendered by default.

57 changes: 39 additions & 18 deletions packages/esm-billing-app/src/hooks/useInterventions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ export const toQueryParams = (q: Record<string, any>) => {
);
};

type Data = {
status: string;
data: Array<{
interventionName: string;
interventionCode: string;
interventionPackage: string;
interventionSubPackage: string;
interventionDescription?: string;
insuranceSchemes: Array<{
rules: Array<{
ruleName: string;
ruleCode: string;
value: string;
}>;
}>;
}>;
};
export const useInterventions = (filters: InterventionsFilter) => {
const fetcher = (url: string) => {
return openmrsFetch(url, {
Expand All @@ -36,29 +53,33 @@ export const useInterventions = (filters: InterventionsFilter) => {
});
};

const url = `${restBaseUrl}/insuranceclaims/claims/interventions/query${toQueryParams(filters)}`;
const { isLoading, error, data } = useSWR<
FetchResponse<{
status: string;
data: Array<{
interventionName: string;
interventionCode: string;
interventionPackage: string;
interventionSubPackage: string;
interventionDescription?: string;
}>;
}>
>(url, fetcher);
const url = `${restBaseUrl}/kenyaemr/sha-interventions${toQueryParams({
...filters,
synchronize: false,
})}`;
const { isLoading, error, data } = useSWR<{ data: Data }>(url, async (url: string) => {
const payload = require('./payload.json');
return { data: payload };
});

return {
isLoading,
interventions: (data?.data?.data ?? []).map(
({ interventionCode, interventionName, interventionPackage, interventionSubPackage, interventionDescription }) =>
interventions: (data?.data as Data | undefined)?.data
?.filter((d) => d.interventionPackage === filters.package_code)
?.map(
({
interventionCode,
subCategoryBenefitsPackage: interventionSubPackage,
interventionName,
} as SHAIntervention),
),
interventionPackage,
interventionSubPackage,
interventionDescription,
}) =>
({
interventionCode,
subCategoryBenefitsPackage: interventionSubPackage,
interventionName,
} as SHAIntervention),
),
error,
};
};
9 changes: 3 additions & 6 deletions packages/esm-billing-app/src/hooks/usePackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ import { Package } from '../types';
* @returns
*/
const usePackages = () => {
const url = `${restBaseUrl}/insuranceclaims/claims/benefit-package`;
const url = `${restBaseUrl}/kenyaemr/sha-benefits-package?synchronize=false`;

const { data, isLoading, error } = useSWR<FetchResponse<Array<{ code: string; name: string; description: string }>>>(
url,
openmrsFetch,
);
const { data, isLoading, error } = useSWR<FetchResponse<{ shaBenefitsPackage: string }>>(url, openmrsFetch);

return {
isLoading,
packages: (data?.data ?? []).map(
packages: (data?.data.shaBenefitsPackage ? JSON.parse(data?.data.shaBenefitsPackage) : []).map(
(category) =>
({
uuid: `${category.code}`,
Expand Down
2 changes: 2 additions & 0 deletions packages/esm-billing-app/src/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
{
"component": "billingOverviewLink",
"name": "billing-overview-link",
"order": 0,
"slot": "billing-dashboard-link-slot"
},
{
Expand Down Expand Up @@ -189,6 +190,7 @@
{
"component": "claimsManagementOverviewDashboardLink",
"name": "claims-management-overview-link",
"order": 0,
"slot": "claims-management-dashboard-link-slot"
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ExtensionSlot, useExtensionStore } from '@openmrs/esm-framework';
import React, { useEffect } from 'react';
import { BrowserRouter, Route, Routes } from 'react-router-dom';

const HomeRoot = () => {
const baseName = window.getOpenmrsSpaBase() + 'home';

return (
<BrowserRouter basename={baseName}>
<Routes>
<Route path="/" element={<ExtensionSlot name="home-dashboard-slot" />} />
<Route path="/providers/*" element={<ExtensionSlot name="providers-dashboard-slot" />} />
<Route path="/referrals/*" element={<ExtensionSlot name="referrals-slot" />} />
<Route path="/bed-admission/*" element={<ExtensionSlot name="bed-admission-dashboard-slot" />} />
{/* Patient services Routes */}
<Route path="/appointments/*" element={<ExtensionSlot name="clinical-appointments-dashboard-slot" />} />
<Route path="/service-queues/*" element={<ExtensionSlot name="service-queues-dashboard-slot" />} />
{/* Diagnostics routes */}
<Route path="/lab-manifest/*" element={<ExtensionSlot name="lab-manifest-slot" />} />
<Route path="/laboratory/*" element={<ExtensionSlot name="laboratory-dashboard-slot" />} />
<Route path="/procedure/*" element={<ExtensionSlot name="procedure-dashboard-slot" />} />
<Route path="/imaging-orders/*" element={<ExtensionSlot name="imaging-dashboard-slot" />} />
{/* lINKAGE services Routes */}
<Route path="/pharmacy/*" element={<ExtensionSlot name="pharmacy-dashboard-slot" />} />
<Route path="/case-management/*" element={<ExtensionSlot name="case-management-dashboard-slot" />} />
<Route path="/peer-calendar/*" element={<ExtensionSlot name="peer-calendar-dashboard-slot" />} />
{/* Billing routes */}
<Route path="/billing/*" element={<ExtensionSlot name="billing-dashboard-slot" />} />
</Routes>
</BrowserRouter>
);
};

export default HomeRoot;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import DashboardGroupExtension from './dashboard-group-extension.component';
import { CarbonIconType } from '@carbon/react/icons';
import { createDashboardGroup as cdg } from '@openmrs/esm-patient-common-lib';
type Conf = {
title: string;
slotName: string;
isExpanded?: boolean;
icon?: CarbonIconType;
};

const createDashboardGroup = ({ slotName, title, isExpanded, icon }: Conf) => {
const DashboardGroup = ({ basePath }: { basePath: string }) => {
return (
<DashboardGroupExtension
title={title}
slotName={slotName}
basePath={basePath}
isExpanded={isExpanded}
icon={icon}
/>
);
};
return DashboardGroup;
};

export default createDashboardGroup;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { BrowserRouter } from 'react-router-dom';
import { LinkExtension } from './link-extension.component';
import { type CarbonIconType } from '@carbon/react/icons';

type LinkConfig = {
route: string;
title: string;
otherRoutes?: Array<string>;
icon?: CarbonIconType;
};

const createLeftPanelLink = (config: LinkConfig) => {
return () => (
<BrowserRouter>
<LinkExtension route={config.route} title={config.title} otherRoutes={config.otherRoutes} icon={config.icon} />
</BrowserRouter>
);
};

export default createLeftPanelLink;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import PatientChartDasboardExtension, { DashboardExtensionProps } from './patient-chart-dashboard.component';
import { BrowserRouter } from 'react-router-dom';

const createPatientChartDashboardExtension = (props: Omit<DashboardExtensionProps, 'basePath'>) => {
return ({ basePath }: { basePath: string }) => {
return (
<BrowserRouter>
<PatientChartDasboardExtension
basePath={basePath}
title={props.title}
path={props.path}
moduleName={props.moduleName}
icon={props.icon}
/>
</BrowserRouter>
);
};
};

export default createPatientChartDashboardExtension;
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Accordion, AccordionItem } from '@carbon/react';
import { CarbonIconType } from '@carbon/react/icons';
import { ExtensionSlot } from '@openmrs/esm-framework';
import { registerNavGroup } from '@openmrs/esm-patient-common-lib';
import React, { useEffect } from 'react';
import styles from './nav.scss';
type Props = {
title: string;
slotName?: string;
basePath: string;
isExpanded?: boolean;
icon?: CarbonIconType;
};
const DashboardGroupExtension: React.FC<Props> = ({ basePath, title, isExpanded, slotName, icon }) => {
useEffect(() => {
registerNavGroup(slotName);
}, [slotName]);
return (
<Accordion>
<AccordionItem
className={styles.item}
open={isExpanded ?? true}
title={
<span className={styles.itemTitle}>
{icon && React.createElement(icon)}
{title}
</span>
}
style={{ border: 'none' }}>
<ExtensionSlot name={slotName ?? title} state={{ basePath }} />
</AccordionItem>
</Accordion>
);
};

export default DashboardGroupExtension;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './link-extension.component';
export * from './utils';
export { default as createDashboardGroup } from './create-dasboard-group';
export { default as createLeftPanelLink } from './create-left-panel-link';
export { default as PatientChartDasboardExtension } from './patient-chart-dashboard.component';
export { default as createPatientChartDashboardExtension } from './create-patient-chart-dashboard-meta';
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ConfigurableLink } from '@openmrs/esm-framework';
import React, { ReactNode, useCallback, useMemo } from 'react';
import { useLocation } from 'react-router-dom';
import { parseParams } from './utils';
import { CarbonIconType } from '@carbon/react/icons';
import styles from './nav.scss';
export interface LinkConfig {
route: string;
title: string;
otherRoutes?: Array<string>;
icon?: CarbonIconType;
}

export const LinkExtension: React.FC<LinkConfig> = ({ route, title, otherRoutes = [], icon }) => {
const spaBasePath = window.getOpenmrsSpaBase();
const location = useLocation();
const path = useMemo(() => location.pathname.replace(spaBasePath, ''), [spaBasePath, location]);
// Parse params to see if the current route matches the location path
const matcher = useCallback(
(route: string) => {
const staticMatch = `/${route}/`.replaceAll('//', '/') === `/${path}/`.replaceAll('//', '/'); // Exact match for static routes
const paramMatch = !staticMatch && parseParams(route, path) !== null; // Check parameterized match if not exact

return staticMatch || paramMatch;
},
[path],
);
// Check if the route is active
const isActive = matcher(route);
const isOtherRoutesActive = useMemo(() => {
return otherRoutes.some(matcher);
}, [otherRoutes, matcher]);
// Generate the `to` URL for the ConfigurableLink
const to = useMemo(() => {
return (spaBasePath + route).replaceAll('//', '/');
}, [spaBasePath, route]);

return (
<ConfigurableLink
to={to}
className={`cds--side-nav__link ${isActive || isOtherRoutesActive ? 'active-left-nav-link' : ''} ${
styles.itemTitle
}`}>
{icon && React.createElement(icon)}
{title}
</ConfigurableLink>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@use '@carbon/layout';
@use '@carbon/type';

.itemTitle {
display: flex;
flex-direction: row;
gap: layout.$spacing-05;
align-items: center;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { CarbonIconType } from '@carbon/react/icons';
import { ConfigurableLink } from '@openmrs/esm-framework';
import classNames from 'classnames';
import last from 'lodash-es/last';
import React, { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation } from 'react-router-dom';
import styles from './nav.scss';

export interface DashboardExtensionProps {
path: string;
title: string;
basePath: string;
moduleName?: string;
icon?: CarbonIconType;
}

const PatientChartDasboardExtension = ({
path,
title,
basePath,
moduleName = '@openmrs/esm-patient-chart-app',
icon,
}: DashboardExtensionProps) => {
const { t } = useTranslation(moduleName);
const location = useLocation();
const navLink = useMemo(() => decodeURIComponent(last(location.pathname.split('/'))), [location.pathname]);

return (
<div key={path}>
<ConfigurableLink
className={classNames('cds--side-nav__link', { 'active-left-nav-link': path === navLink }, styles.itemTitle)}
to={`${basePath}/${encodeURIComponent(path)}`}>
{icon && React.createElement(icon)}
{t(title)}
</ConfigurableLink>
</div>
);
};

export default PatientChartDasboardExtension;
Loading

0 comments on commit 1d42b39

Please sign in to comment.