Skip to content

Commit

Permalink
select all
Browse files Browse the repository at this point in the history
  • Loading branch information
aetchego committed Nov 13, 2024
1 parent 63754c2 commit 6f1adca
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { ScopeElement } from 'types'
import CalendarRange from 'components/ui/Inputs/CalendarRange'

import { CriteriaType, SelectedCriteriaTypesWithAdvancedInputs } from 'types/requestCriterias'
import { BlockWrapper } from 'components/ui/Layout'
import { DurationRangeType } from 'types/searchCriterias'
import { CriteriaLabel } from 'components/ui/CriteriaLabel'
import { getOccurenceDateLabel } from 'utils/requestCriterias'
import ExecutiveUnitsInput from 'components/ui/Inputs/ExecutiveUnits'
import { InputWrapper } from 'components/ui/Inputs'

type AdvancedInputsProps = {
sourceType: SourceType
Expand Down Expand Up @@ -43,7 +43,7 @@ const AdvancedInputs = ({ sourceType, selectedCriteria, onChangeValue, onError }
}

return (
<Grid container direction="column">
<>
<Grid
item
container
Expand All @@ -62,78 +62,80 @@ const AdvancedInputs = ({ sourceType, selectedCriteria, onChangeValue, onError }
</Grid>

<Collapse in={checked} unmountOnExit>
<BlockWrapper style={{ margin: '1em 1em 2em', width: 'calc(100% - 2em)' }}>
<ExecutiveUnitsInput
sourceType={sourceType}
value={selectedCriteria?.encounterService || []}
onChange={_onSubmitExecutiveUnits}
/>
</BlockWrapper>
<Grid container direction="column" padding="0 1em" gap="10px">
<InputWrapper>
<ExecutiveUnitsInput
sourceType={sourceType}
value={selectedCriteria?.encounterService || []}
onChange={_onSubmitExecutiveUnits}
/>
</InputWrapper>

<BlockWrapper style={{ margin: '1em 1em 2em', width: 'calc(100% - 2em)' }}>
<CriteriaLabel label="Prise en charge" infoIcon="Ne concerne pas les consultations" />
<FormLabel style={{ padding: '0 0 1em', fontWeight: 600, fontSize: 12 }} component="legend">
Début de prise en charge
</FormLabel>
<CalendarRange
inline
value={selectedCriteria?.encounterStartDate}
onChange={(newDate) => {
onChangeValue('encounterStartDate', newDate)
}}
onError={(isError) => onError(isError)}
includeNullValues={selectedCriteria.includeEncounterStartDateNull}
onChangeIncludeNullValues={(includeNullValues) =>
onChangeValue('includeEncounterStartDateNull', includeNullValues)
}
/>
<FormLabel style={{ padding: '1em 0', fontWeight: 600, fontSize: 12 }} component="legend">
Fin de prise en charge
</FormLabel>
<CalendarRange
inline
value={selectedCriteria?.encounterEndDate}
onChange={(newDate) => {
onChangeValue('encounterEndDate', newDate)
}}
onError={(isError) => onError(isError)}
includeNullValues={selectedCriteria.includeEncounterEndDateNull}
onChangeIncludeNullValues={(includeNullValues) =>
onChangeValue('includeEncounterEndDateNull', includeNullValues)
}
/>
</BlockWrapper>
<InputWrapper>
<CriteriaLabel label="Prise en charge" infoIcon="Ne concerne pas les consultations" />
<FormLabel style={{ fontWeight: 600, fontSize: 12 }} component="legend">
Début de prise en charge
</FormLabel>
<CalendarRange
inline
value={selectedCriteria?.encounterStartDate}
onChange={(newDate) => {
onChangeValue('encounterStartDate', newDate)
}}
onError={(isError) => onError(isError)}
includeNullValues={selectedCriteria.includeEncounterStartDateNull}
onChangeIncludeNullValues={(includeNullValues) =>
onChangeValue('includeEncounterStartDateNull', includeNullValues)
}
/>
<FormLabel style={{ fontWeight: 600, fontSize: 12 }} component="legend">
Fin de prise en charge
</FormLabel>
<CalendarRange
inline
value={selectedCriteria?.encounterEndDate}
onChange={(newDate) => {
onChangeValue('encounterEndDate', newDate)
}}
onError={(isError) => onError(isError)}
includeNullValues={selectedCriteria.includeEncounterEndDateNull}
onChangeIncludeNullValues={(includeNullValues) =>
onChangeValue('includeEncounterEndDateNull', includeNullValues)
}
/>
</InputWrapper>

{selectedCriteria.type !== CriteriaType.IMAGING && (
<>
<BlockWrapper style={{ margin: '1em 1em 2em', width: 'calc(100% - 2em)' }}>
<CriteriaLabel label={getOccurenceDateLabel(selectedCriteria.type)} />
<CalendarRange
inline
value={selectedCriteria?.startOccurrence}
onChange={(newDate) => {
onChangeValue('startOccurrence', newDate)
}}
onError={(isError) => onError(isError)}
/>
</BlockWrapper>
{selectedCriteria.type === CriteriaType.MEDICATION_REQUEST && (
<BlockWrapper style={{ margin: '1em 1em 2em', width: 'calc(100% - 2em)' }}>
<CriteriaLabel label={getOccurenceDateLabel(selectedCriteria.type, true)} />
{selectedCriteria.type !== CriteriaType.IMAGING && (
<>
<InputWrapper>
<CriteriaLabel label={getOccurenceDateLabel(selectedCriteria.type)} sx={{ paddingBottom: 0 }} />
<CalendarRange
inline
value={selectedCriteria?.endOccurrence ?? [null, null]}
value={selectedCriteria?.startOccurrence}
onChange={(newDate) => {
onChangeValue('endOccurrence', newDate)
onChangeValue('startOccurrence', newDate)
}}
onError={(isError) => onError(isError)}
/>
</BlockWrapper>
)}
</>
)}
</InputWrapper>
{selectedCriteria.type === CriteriaType.MEDICATION_REQUEST && (
<InputWrapper>
<CriteriaLabel label={getOccurenceDateLabel(selectedCriteria.type, true)} sx={{ paddingBottom: 0 }} />
<CalendarRange
inline
value={selectedCriteria?.endOccurrence ?? [null, null]}
onChange={(newDate) => {
onChangeValue('endOccurrence', newDate)
}}
onError={(isError) => onError(isError)}
/>
</InputWrapper>
)}
</>
)}
</Grid>
</Collapse>
</Grid>
</>
)
}

Expand Down
17 changes: 11 additions & 6 deletions src/components/SearchValueSet/ValueSetTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react'
import React, { useEffect, useMemo, useState } from 'react'

import {
Checkbox,
Expand Down Expand Up @@ -58,8 +58,6 @@ const ValueSetRow = ({
if (loading.expand === LoadingStatus.SUCCESS) setInternalLoading(false)
}, [loading.expand])

console.log('test label')

return (
<>
<RowContainerWrapper container color={path.length % 2 === 0 ? '#f3f5f9' : '#fff'}>
Expand Down Expand Up @@ -137,6 +135,11 @@ const ValueSetTable = ({
onExpand,
onChangePage
}: ValueSetTableProps) => {
const tree = useMemo(() => {
console.log('test exp change')
return mode === SearchMode.RESEARCH || isHierarchy ? hierarchy.tree : hierarchy.tree[0].subItems || []
}, [hierarchy])

return (
<Grid container direction="column" justifyContent="space-between">
<Grid item>
Expand All @@ -151,19 +154,21 @@ const ValueSetTable = ({
{hierarchy.count ? `${hierarchy.count} résultat(s)` : ` Aucun résultat à afficher`}
</Typography>
<Checkbox
color="secondary"
checked={selectAllStatus === SelectedStatus.SELECTED}
indeterminate={selectAllStatus === SelectedStatus.INDETERMINATE}
indeterminateIcon={<IndeterminateCheckBoxOutlined style={{ color: 'rgba(0,0,0,0.6)' }} />}
onChange={(event, checked) => onSelectAll(checked)}
onChange={(event, checked) => {
if (mode === SearchMode.RESEARCH) onSelectAll(checked)
else onSelect(hierarchy.tree[0], checked)
}}
/>
</Grid>
</TableCell>
</TableRow>
)}
{loading.list === LoadingStatus.SUCCESS && (
<div style={{ maxHeight: '70vh', overflow: 'auto' }}>
{hierarchy.tree.map((item) =>
{tree.map((item) =>
item ? (
<ValueSetRow
mode={mode}
Expand Down
110 changes: 59 additions & 51 deletions src/components/ui/Inputs/ExecutiveUnits/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { Chip, CircularProgress, Grid, IconButton, Tooltip, Typography } from '@mui/material'
import { CircularProgress, FormLabel, Grid, IconButton, Tooltip, Typography } from '@mui/material'
import React, { useEffect, useState } from 'react'
import { LoadingStatus, ScopeElement } from 'types'
import InfoIcon from '@mui/icons-material/Info'
import { InputWrapper } from 'components/ui/Inputs'
import EditIcon from '@mui/icons-material/Edit'
import { ExecutiveUnitsWrapper } from './styles'
import { SourceType } from 'types/scope'
import { Hierarchy } from 'types/hierarchy'
import servicesPerimeters from 'services/aphp/servicePerimeters'
import { getScopeLevelBySourceType } from 'utils/perimeters'
import { CriteriaLabel } from 'components/ui/CriteriaLabel'
import ScopeTree from 'components/ScopeTree'
import Panel from 'components/ui/Panel'
import CloseIcon from '@mui/icons-material/Close'
import MoreHorizIcon from '@mui/icons-material/MoreHoriz'
import CodesWithSystems from 'components/Hierarchy/CodesWithSystems'
import { SearchOutlined } from '@mui/icons-material'

type ExecutiveUnitsProps = {
value: Hierarchy<ScopeElement, string>[]
Expand All @@ -33,9 +35,10 @@ const ExecutiveUnits = ({
const [confirmedPopulation, setConfirmedPopulation] = useState<Hierarchy<ScopeElement, string>[]>(value)
const [loading, setLoading] = useState(disabled ? LoadingStatus.SUCCESS : LoadingStatus.FETCHING)
const [open, setOpen] = useState(false)
const [isExtended, setIsExtended] = useState(false)

const handleDelete = (id: string) => {
const newSelectedPopulation = selectedPopulation.filter((item) => item.id !== id)
const handleDelete = (node: Hierarchy<ScopeElement>) => {
const newSelectedPopulation = selectedPopulation.filter((item) => item.id !== node.id)
setSelectedPopulation(newSelectedPopulation)
setConfirmedPopulation(newSelectedPopulation)
}
Expand All @@ -54,7 +57,8 @@ const ExecutiveUnits = ({
}, [confirmedPopulation])

return (
<InputWrapper>
<>
<InputWrapper>
<Grid item container alignContent="center" alignItems={'center'}>
{isCriterion ? (
<CriteriaLabel style={{ padding: 0 }} label="Unité exécutrice" />
Expand All @@ -75,54 +79,58 @@ const ExecutiveUnits = ({
>
<InfoIcon fontSize="small" color="primary" style={{ marginLeft: 4 }} />
</Tooltip>
</Grid>

<Grid item container direction="row" alignItems="center">
<ExecutiveUnitsWrapper>
<Grid container>
{!confirmedPopulation.length && 'Sélectionner une unité exécutrice'}
{confirmedPopulation.map((unit) => (
<Chip
disabled={disabled}
sx={{
fontWeight: 700,
fontSize: 11,
height: 25,
color: '#153D8A',
backgroundColor: 'rgba(0, 0, 0, 0.10)',
marginTop: '4px'
}}
key={unit.id}
label={`${unit.source_value} - ${unit.name}`}
onDelete={() => {
handleDelete(unit.id)
}}
/>
))}
</Grid>
<IconButton onClick={() => setOpen(true)} disabled={disabled}>
{loading === LoadingStatus.SUCCESS && <EditIcon />}
</Grid>
<Grid
container
alignItems={value.length ? 'flex-start' : 'center'}
border="1px solid rgba(0, 0, 0, 0.25)"
borderRadius="4px"
padding="9px 3px 9px 12px"
>
<Grid container alignItems="center" item xs={10}>
{!confirmedPopulation.length && <FormLabel component="legend">Sélectionner une unité exécutrice</FormLabel>}
<CodesWithSystems
disabled={disabled}
codes={confirmedPopulation}
isExtended={isExtended}
onDelete={handleDelete}
/>
</Grid>
<Grid item xs={2} container justifyContent="flex-end">
{isExtended && (
<IconButton size="small" sx={{ color: '#5BC5F2' }} onClick={() => setIsExtended(false)}>
<CloseIcon />
</IconButton>
)}
{!isExtended && (
<IconButton size="small" sx={{ color: '#5BC5F2' }} onClick={() => setIsExtended(true)}>
<MoreHorizIcon />
</IconButton>
)}
<IconButton sx={{ color: '#5BC5F2' }} size="small" onClick={() => setOpen(true)} disabled={disabled}>
{loading === LoadingStatus.FETCHING && <CircularProgress size={24} />}
{loading === LoadingStatus.SUCCESS && <SearchOutlined />}
</IconButton>
</ExecutiveUnitsWrapper>
<Panel
title="Sélectionner une unité exécutrice"
open={open}
onConfirm={() => {
setConfirmedPopulation(selectedPopulation)
setOpen(false)
}}
onClose={() => setOpen(false)}
>
<ScopeTree
baseTree={population}
selectedNodes={confirmedPopulation}
onSelect={setSelectedPopulation}
sourceType={sourceType}
/>
</Panel>
</Grid>
</Grid>
</InputWrapper>
<Panel
title="Sélectionner une unité exécutrice"
open={open}
onConfirm={() => {
setConfirmedPopulation(selectedPopulation)
setOpen(false)
}}
onClose={() => setOpen(false)}
>
<ScopeTree
baseTree={population}
selectedNodes={confirmedPopulation}
onSelect={setSelectedPopulation}
sourceType={sourceType}
/>
</Panel>
</InputWrapper>
</>
)
}

Expand Down
Loading

0 comments on commit 6f1adca

Please sign in to comment.