-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'detail-page' into aidbox-forms
- Loading branch information
Showing
10 changed files
with
454 additions
and
14 deletions.
There are no files selected for viewing
15 changes: 12 additions & 3 deletions
15
src/components/BaseLayout/PageContainer/PageContainerContent/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
import { S } from "./styles"; | ||
|
||
export type PageContainerContentProps = React.HTMLAttributes<HTMLDivElement> & { | ||
/* Page content max width */ | ||
maxWidth?: number | string; | ||
|
||
/** | ||
* PageContainerContent (level=2) can be nested in other PageContainerContent (level=1) | ||
* e.g. ResourceListPageContent use PageContainerContent (level=2) | ||
* | ||
* Styles of the PageContainerContent will be adjusted for provided level. | ||
*/ | ||
level?: 1 | 2; | ||
}; | ||
|
||
export function PageContainerContent(props: PageContainerContentProps) { | ||
const { maxWidth, ...rest } = props; | ||
const { maxWidth, level = 1, ...rest } = props; | ||
|
||
return ( | ||
<S.PageContentContainer> | ||
<S.PageContent {...rest} $maxWidth={maxWidth} /> | ||
<S.PageContentContainer $level={level}> | ||
<S.PageContent {...rest} $maxWidth={maxWidth} $level={level} /> | ||
</S.PageContentContainer> | ||
); | ||
} |
18 changes: 15 additions & 3 deletions
18
src/components/BaseLayout/PageContainer/PageContainerContent/styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
import styled from 'styled-components'; | ||
import styled, { css } from 'styled-components'; | ||
|
||
import { maxWidthStyles } from '../PageContainerHeader/styles'; | ||
|
||
export const S = { | ||
PageContentContainer: styled.div` | ||
PageContentContainer: styled.div<{ $level: 1 | 2 }>` | ||
padding: 0 24px; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
${({ $level }) => | ||
$level === 2 && | ||
css` | ||
padding: 0; | ||
`} | ||
`, | ||
PageContent: styled.div<{ $maxWidth?: number | string }>` | ||
PageContent: styled.div<{ $level: 1 | 2, $maxWidth?: number | string }>` | ||
flex: 1; | ||
display: flex; | ||
flex-direction: column; | ||
padding: 32px 0; | ||
gap: 24px 0; | ||
width: 100%; | ||
${({ $level }) => | ||
$level === 2 && | ||
css` | ||
padding: 0; | ||
`} | ||
${maxWidthStyles} | ||
`, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { Encounter, Patient } from 'fhir/r4b'; | ||
|
||
import { DetailPage, Tab } from 'src/uberComponents/DetailPage'; | ||
import { compileAsFirst, formatPeriodDateTime } from 'src/utils'; | ||
|
||
import { PatientOverview } from './PatientOverviewDynamic'; | ||
import { ResourceListPageContent } from 'src/uberComponents/ResourceListPageContent'; | ||
import { navigationAction, questionnaireAction } from 'src/uberComponents'; | ||
import { t, Trans } from '@lingui/macro'; | ||
import { SearchBarColumnType } from 'src/components/SearchBar/types'; | ||
import { PlusOutlined } from '@ant-design/icons'; | ||
|
||
const getName = compileAsFirst<Patient, string>("Patient.name.given.first() + ' ' + Patient.name.family"); | ||
|
||
function PatientEncounter({ patient }: { patient: Patient }) { | ||
return ( | ||
<ResourceListPageContent<Encounter> | ||
resourceType="Encounter" | ||
searchParams={{ patient: patient.id! }} | ||
getTableColumns={() => [ | ||
{ | ||
title: 'Practitioner', | ||
dataIndex: 'practitioner', | ||
key: 'practitioner', | ||
render: (_text: any, { resource }) => resource.participant?.[0]?.individual?.display, | ||
}, | ||
{ | ||
title: 'Status', | ||
dataIndex: 'status', | ||
key: 'status', | ||
render: (_text: any, { resource }) => { | ||
return resource.status; | ||
}, | ||
}, | ||
{ | ||
title: 'Date', | ||
dataIndex: 'date', | ||
key: 'date', | ||
width: 250, | ||
render: (_text: any, { resource }) => formatPeriodDateTime(resource.period), | ||
}, | ||
]} | ||
getFilters={() => [ | ||
{ | ||
id: 'name', | ||
searchParam: '_ilike', | ||
type: SearchBarColumnType.STRING, | ||
placeholder: t`Find encounter`, | ||
placement: ['search-bar', 'table'], | ||
}, | ||
{ | ||
id: 'status', | ||
searchParam: 'status', | ||
type: SearchBarColumnType.CHOICE, | ||
placeholder: t`Choose status`, | ||
options: [ | ||
{ | ||
value: { | ||
Coding: { | ||
code: 'in-progress', | ||
display: 'In progress', | ||
}, | ||
}, | ||
}, | ||
{ | ||
value: { | ||
Coding: { | ||
code: 'finished', | ||
display: 'Finished', | ||
}, | ||
}, | ||
}, | ||
], | ||
placement: ['table', 'search-bar'], | ||
}, | ||
]} | ||
getRecordActions={(record) => [navigationAction('Open', `/patients2/${record.resource.id}/encounter`)]} | ||
getHeaderActions={() => [ | ||
questionnaireAction(<Trans>Create encounter</Trans>, 'encounter-create', { icon: <PlusOutlined /> }), | ||
]} | ||
getBatchActions={() => [questionnaireAction(<Trans>Finish encounters</Trans>, '')]} | ||
getReportColumns={(bundle) => [ | ||
{ | ||
title: t`Number of Encounters`, | ||
value: bundle.total, | ||
}, | ||
]} | ||
/> | ||
); | ||
} | ||
|
||
const tabs: Array<Tab<Patient>> = [ | ||
{ | ||
path: '', | ||
label: 'Overview', | ||
component: ({ resource }) => <PatientOverview patient={resource} />, | ||
}, | ||
{ | ||
path: 'encounter', | ||
label: 'Encounter', | ||
component: ({ resource }) => <PatientEncounter patient={resource} />, | ||
}, | ||
]; | ||
|
||
export function NewPatientDetails() { | ||
return ( | ||
<DetailPage<Patient> | ||
resourceType="Patient" | ||
getSearchParams={({ id }) => ({ _id: id })} | ||
getTitle={({ resource, bundle }) => getName(resource, { bundle })!} | ||
tabs={tabs} | ||
basePath="patients2" | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { Bundle, Resource } from 'fhir/r4b'; | ||
import { useEffect, useState } from 'react'; | ||
import { useParams, Route, Routes, useLocation, Link, useNavigate, Params } from 'react-router-dom'; | ||
|
||
import { SearchParams, RenderRemoteData, useService, WithId } from '@beda.software/fhir-react'; | ||
|
||
import { PageContainer } from 'src/components'; | ||
import { RouteItem } from 'src/components/BaseLayout/Sidebar/SidebarTop'; | ||
import { Tabs } from 'src/components/Tabs'; | ||
import { getFHIRResources } from 'src/services'; | ||
import { compileAsFirst } from 'src/utils'; | ||
|
||
interface DetailContext<R extends Resource> { | ||
resource: R; | ||
bundle: Bundle<R>; | ||
} | ||
|
||
export interface Tab<R extends Resource> { | ||
label: string; | ||
path?: string; | ||
component: (context: DetailContext<R>) => JSX.Element; | ||
} | ||
|
||
interface DetailPageProps<R extends Resource> { | ||
resourceType: R['resourceType']; | ||
getSearchParams: (params: Readonly<Params<string>>) => SearchParams; | ||
getTitle: (context: DetailContext<R>) => string; | ||
tabs: Array<Tab<R>>; | ||
basePath: string; | ||
extractPrimaryResource?: (bundle: Bundle<R>) => R; | ||
} | ||
|
||
interface PageTabsProps<R extends Resource> { | ||
tabs: Array<Tab<R>>; | ||
basePath: string; | ||
} | ||
|
||
export function PageTabs<R extends Resource>({ tabs, basePath }: PageTabsProps<R>) { | ||
const location = useLocation(); | ||
const params = useParams<{ id: string }>(); | ||
const navigate = useNavigate(); | ||
|
||
const menuItems: RouteItem[] = tabs.map(({ label, path }) => ({ | ||
label, | ||
path: `/${basePath}/${params.id}/${path}`, | ||
})); | ||
|
||
const [currentPath, setCurrentPath] = useState(location?.pathname); | ||
|
||
useEffect(() => { | ||
setCurrentPath(location?.pathname); | ||
}, [location]); | ||
|
||
return ( | ||
<Tabs | ||
boxShadow={false} | ||
activeKey={currentPath.split('/').slice(0, 4).join('/')} | ||
items={menuItems.map((route) => ({ | ||
key: route.path, | ||
label: <Link to={route.path}>{route.label}</Link>, | ||
}))} | ||
onTabClick={(path) => navigate(path)} | ||
/> | ||
); | ||
} | ||
|
||
export function DetailPage<R extends Resource>({ | ||
resourceType, | ||
getSearchParams, | ||
getTitle, | ||
tabs, | ||
basePath, | ||
extractPrimaryResource, | ||
}: DetailPageProps<R>) { | ||
const params = useParams(); | ||
const [response] = useService(() => getFHIRResources(resourceType, getSearchParams(params))); | ||
const defaultExtractPrimaryResource = compileAsFirst<Bundle<WithId<R>>, R>( | ||
'Bundle.entry.resource.where(resourceType=%resourceType).first()', | ||
); | ||
return ( | ||
<RenderRemoteData remoteData={response}> | ||
{(bundle) => { | ||
let resource: R | undefined = undefined; | ||
if (extractPrimaryResource) { | ||
resource = extractPrimaryResource(bundle); | ||
} else { | ||
resource = defaultExtractPrimaryResource(bundle, { resourceType }); | ||
} | ||
if (typeof resource === 'undefined') { | ||
return <p>NASTY ERROR</p>; | ||
} | ||
const context: DetailContext<R> = { resource, bundle }; | ||
return ( | ||
<PageContainer | ||
title={getTitle(context)} | ||
layoutVariant="with-tabs" | ||
headerContent={<PageTabs tabs={tabs} basePath={basePath} />} | ||
> | ||
<Routes> | ||
{tabs.map(({ path, component }) => ( | ||
<Route path={'/' + path} element={component(context)} key={path} /> | ||
))} | ||
</Routes> | ||
</PageContainer> | ||
); | ||
}} | ||
</RenderRemoteData> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.