11import { useMemo , useState , forwardRef , useImperativeHandle , useEffect , useCallback , useRef } from 'react'
2- import { Chip , FillerCell , HelpwaveLogo , LoadingContainer , SearchBar , ProgressIndicator , Tooltip , Drawer , TableProvider , TableDisplay , TableColumnSwitcher , TablePagination , IconButton , useLocale } from '@helpwave/hightide'
2+ import type { IdentifierFilterValue , FilterListItem , FilterListPopUpBuilderProps } from '@helpwave/hightide'
3+ import { Chip , FillerCell , HelpwaveLogo , LoadingContainer , SearchBar , ProgressIndicator , Tooltip , Drawer , TableProvider , TableDisplay , TableColumnSwitcher , TablePagination , IconButton , useLocale , FilterList } from '@helpwave/hightide'
34import { PlusIcon } from 'lucide-react'
4- import { Sex , PatientState , type GetPatientsQuery , type TaskType , PropertyEntity , type FullTextSearchInput , type LocationType } from '@/api/gql/generated'
5+ import type { LocationType } from '@/api/gql/generated'
6+ import { Sex , PatientState , type GetPatientsQuery , type TaskType , PropertyEntity , type FullTextSearchInput , FieldType } from '@/api/gql/generated'
57import { usePropertyDefinitions , usePatientsPaginated , useRefreshingEntityIds } from '@/data'
68import { PatientDetailView } from '@/components/patients/PatientDetailView'
79import { LocationChips } from '@/components/locations/LocationChips'
@@ -15,6 +17,8 @@ import { getPropertyColumnsForEntity } from '@/utils/propertyColumn'
1517import { useStorageSyncedTableState } from '@/hooks/useTableState'
1618import { usePropertyColumnVisibility } from '@/hooks/usePropertyColumnVisibility'
1719import { columnFiltersToFilterInput , paginationStateToPaginationInput , sortingStateToSortInput } from '@/utils/tableStateToApi'
20+ import { getPropertyFilterFn as getPropertyDatatype } from '@/utils/propertyFilterMapping'
21+ import { UserSelectFilterPopUp } from './UserSelectFilterPopUp'
1822
1923export type PatientViewModel = {
2024 id : string ,
@@ -190,7 +194,7 @@ export const PatientList = forwardRef<PatientListRef, PatientListProps>(({ initi
190194 }
191195
192196 const patientPropertyColumns = useMemo < ColumnDef < PatientViewModel > [ ] > (
193- ( ) => getPropertyColumnsForEntity < PatientViewModel > ( propertyDefinitionsData , PropertyEntity . Patient ) ,
197+ ( ) => getPropertyColumnsForEntity < PatientViewModel > ( propertyDefinitionsData , PropertyEntity . Patient , false ) ,
194198 [ propertyDefinitionsData ]
195199 )
196200
@@ -211,7 +215,6 @@ export const PatientList = forwardRef<PatientListRef, PatientListProps>(({ initi
211215 minSize : 200 ,
212216 size : 250 ,
213217 maxSize : 300 ,
214- filterFn : 'text' ,
215218 } ,
216219 {
217220 id : 'state' ,
@@ -229,7 +232,6 @@ export const PatientList = forwardRef<PatientListRef, PatientListProps>(({ initi
229232 minSize : 120 ,
230233 size : 144 ,
231234 maxSize : 180 ,
232- filterFn : 'singleTag' ,
233235 meta : {
234236 filterData : {
235237 tags : allPatientStates . map ( state => ( { label : translation ( 'patientState' , { state : state as string } ) , tag : state } ) ) ,
@@ -272,7 +274,6 @@ export const PatientList = forwardRef<PatientListRef, PatientListProps>(({ initi
272274 minSize : 160 ,
273275 size : 160 ,
274276 maxSize : 200 ,
275- filterFn : 'singleTag' ,
276277 meta : {
277278 filterData : {
278279 tags : [
@@ -299,7 +300,6 @@ export const PatientList = forwardRef<PatientListRef, PatientListProps>(({ initi
299300 minSize : 200 ,
300301 size : 260 ,
301302 maxSize : 320 ,
302- filterFn : 'text' as const ,
303303 } ,
304304 ...( [ 'CLINIC' , 'WARD' , 'ROOM' , 'BED' ] as const ) . map ( ( kind ) : ColumnDef < PatientViewModel > => ( {
305305 id : `location-${ kind } ` ,
@@ -322,7 +322,6 @@ export const PatientList = forwardRef<PatientListRef, PatientListProps>(({ initi
322322 minSize : 160 ,
323323 size : 220 ,
324324 maxSize : 300 ,
325- filterFn : 'text' as const ,
326325 } ) ) ,
327326 {
328327 id : 'birthdate' ,
@@ -351,7 +350,6 @@ export const PatientList = forwardRef<PatientListRef, PatientListProps>(({ initi
351350 minSize : 200 ,
352351 size : 200 ,
353352 maxSize : 200 ,
354- filterFn : 'date' as const ,
355353 } ,
356354 {
357355 id : 'tasks' ,
@@ -395,6 +393,62 @@ export const PatientList = forwardRef<PatientListRef, PatientListProps>(({ initi
395393 } ) ) ,
396394 ] , [ translation , allPatientStates , patientPropertyColumns , refreshingPatientIds , rowLoadingCell , dateFormat ] )
397395
396+ const availableFilters : FilterListItem [ ] = useMemo ( ( ) => [
397+ {
398+ id : 'name' ,
399+ label : translation ( 'name' ) ,
400+ dataType : 'text' ,
401+ tags : [ ] ,
402+ } ,
403+ {
404+ id : 'state' ,
405+ label : translation ( 'status' ) ,
406+ dataType : 'singleTag' ,
407+ tags : allPatientStates . map ( state => ( { label : translation ( 'patientState' , { state : state as string } ) , tag : state } ) ) ,
408+ } ,
409+ {
410+ id : 'sex' ,
411+ label : translation ( 'sex' ) ,
412+ dataType : 'singleTag' ,
413+ tags : [
414+ { label : translation ( 'male' ) , tag : Sex . Male } ,
415+ { label : translation ( 'female' ) , tag : Sex . Female } ,
416+ { label : translation ( 'diverse' ) , tag : Sex . Unknown } ,
417+ ] ,
418+ } ,
419+ ...( [ 'CLINIC' , 'WARD' , 'ROOM' , 'BED' ] as const ) . map ( ( kind ) : FilterListItem => ( {
420+ id : `location-${ kind } ` ,
421+ label : translation ( LOCATION_KIND_HEADERS [ kind ] as 'locationClinic' | 'locationWard' | 'locationRoom' | 'locationBed' ) ,
422+ dataType : 'text' ,
423+ tags : [ ] ,
424+ } ) ) ,
425+ {
426+ id : 'birthdate' ,
427+ label : translation ( 'birthdate' ) ,
428+ dataType : 'date' ,
429+ tags : [ ] ,
430+ } ,
431+ {
432+ id : 'tasks' ,
433+ label : translation ( 'tasks' ) ,
434+ dataType : 'number' ,
435+ tags : [ ] ,
436+ } ,
437+ ...propertyDefinitionsData ?. propertyDefinitions . map ( def => {
438+ const dataType = getPropertyDatatype ( def . fieldType )
439+ return {
440+ id : `property_${ def . id } ` ,
441+ label : def . name ,
442+ dataType,
443+ tags : def . options . map ( ( opt , idx ) => ( {
444+ label : opt ,
445+ tag : `${ def . id } -opt-${ idx } ` ,
446+ } ) ) ,
447+ popUpBuilder : def . fieldType === FieldType . FieldTypeUser ? ( props : FilterListPopUpBuilderProps ) => ( < UserSelectFilterPopUp { ...props } /> ) : undefined ,
448+ }
449+ } ) ?? [ ] ,
450+ ] , [ allPatientStates , propertyDefinitionsData ?. propertyDefinitions , translation ] )
451+
398452 const onRowClick = useCallback ( ( row : Row < PatientViewModel > ) => handleEdit ( row . original ) , [ handleEdit ] )
399453 const fillerRowCell = useCallback ( ( ) => ( < FillerCell className = "min-h-8" /> ) , [ ] )
400454
@@ -431,6 +485,14 @@ export const PatientList = forwardRef<PatientListRef, PatientListProps>(({ initi
431485 value = { searchQuery }
432486 onChange = { ( e ) => setSearchQuery ( e . target . value ) }
433487 onSearch = { ( ) => null }
488+ containerProps = { { className : 'max-w-80' } }
489+ />
490+ < FilterList
491+ value = { filters as IdentifierFilterValue [ ] }
492+ onValueChange = { value => {
493+ setFilters ( value )
494+ } }
495+ availableItems = { availableFilters }
434496 />
435497 < TableColumnSwitcher />
436498 </ div >
0 commit comments