diff --git a/web/components/patients/PatientDataEditor.tsx b/web/components/patients/PatientDataEditor.tsx index e51198e..3d93665 100644 --- a/web/components/patients/PatientDataEditor.tsx +++ b/web/components/patients/PatientDataEditor.tsx @@ -47,6 +47,13 @@ const convertBirthdateStringToDate = (birthdate: string | null | undefined): Dat return new Date(birthdate) } +const normalizeBirthdateValue = (value: Date | string | null | undefined): string | null => { + if (!value) return null + if (value instanceof Date) return toISODate(value) + const s = String(value) + return s.length >= 10 ? s.slice(0, 10) : s +} + export const PatientDataEditor = ({ id, initialCreateData = {}, @@ -112,7 +119,7 @@ export const PatientDataEditor = ({ const data: CreatePatientInput = { firstname: values.firstname, lastname: values.lastname, - birthdate: values.birthdate, + birthdate: toISODate(values.birthdate)!, sex: values.sex, assignedLocationIds: values.assignedLocationIds, clinicId: values.clinic!.id, @@ -312,12 +319,12 @@ export const PatientDataEditor = ({ {...focusableElementProps} {...interactionStates} value={convertBirthdateStringToDate(dataProps.value) ?? null} onValueChange={(value) => { - if(!value) return - dataProps.onValueChange(value) + const normalized = normalizeBirthdateValue(value) + if (normalized) dataProps.onValueChange(normalized) }} onEditComplete={(value) => { - if(!value) return - dataProps.onEditComplete(value) + const normalized = normalizeBirthdateValue(value) + if (normalized) dataProps.onEditComplete(normalized) }} mode="date" /> diff --git a/web/components/patients/PatientDetailView.tsx b/web/components/patients/PatientDetailView.tsx index a0ebcf0..3fbd189 100644 --- a/web/components/patients/PatientDetailView.tsx +++ b/web/components/patients/PatientDetailView.tsx @@ -19,6 +19,9 @@ import { useUpdatePatient } from '@/data' export const toISODate = (d: Date | string | null | undefined): string | null => { if (!d) return null + if (typeof d === 'string' && d.length >= 10 && d[10] === 'T') { + return d.slice(0, 10) + } const date = typeof d === 'string' ? new Date(d) : d if (!(date instanceof Date) || isNaN(date.getTime())) return null const year = date.getFullYear() diff --git a/web/components/tables/PatientList.tsx b/web/components/tables/PatientList.tsx index 781d26c..06ad2fb 100644 --- a/web/components/tables/PatientList.tsx +++ b/web/components/tables/PatientList.tsx @@ -89,7 +89,20 @@ export const PatientList = forwardRef(({ initi PatientState.Dead, PatientState.Wait, ], []) - const patientStates = allPatientStates + + const apiFiltering = useMemo(() => columnFiltersToFilterInput(filters), [filters]) + const patientStates = useMemo(() => { + const stateFilter = apiFiltering.find( + f => f.column === 'state' && + (f.operator === 'TAGS_SINGLE_EQUALS' || f.operator === 'TAGS_SINGLE_CONTAINS') && + f.parameter?.searchTags != null && + f.parameter.searchTags.length > 0 + ) + if (!stateFilter?.parameter?.searchTags) return allPatientStates + const allowed = new Set(allPatientStates as unknown as string[]) + const filtered = (stateFilter.parameter.searchTags as string[]).filter(s => allowed.has(s)) + return filtered.length > 0 ? (filtered as PatientState[]) : allPatientStates + }, [apiFiltering, allPatientStates]) const searchInput: FullTextSearchInput | undefined = searchQuery ? { @@ -97,8 +110,6 @@ export const PatientList = forwardRef(({ initi includeProperties: true, } : undefined - - const apiFiltering = useMemo(() => columnFiltersToFilterInput(filters), [filters]) const apiSorting = useMemo(() => sortingStateToSortInput(sorting), [sorting]) const apiPagination = useMemo(() => paginationStateToPaginationInput(pagination), [pagination]) @@ -205,7 +216,7 @@ export const PatientList = forwardRef(({ initi { id: 'state', header: translation('status'), - accessorFn: ({ state }) => [state], + accessorFn: ({ state }) => state, cell: ({ row }) => { if (refreshingPatientIds.has(row.original.id)) return rowLoadingCell return ( @@ -228,7 +239,7 @@ export const PatientList = forwardRef(({ initi { id: 'sex', header: translation('sex'), - accessorFn: ({ sex }) => [sex], + accessorFn: ({ sex }) => sex, cell: ({ row }) => { if (refreshingPatientIds.has(row.original.id)) return rowLoadingCell const sex = row.original.sex diff --git a/web/utils/tableStateToApi.ts b/web/utils/tableStateToApi.ts index a613b4b..c7342bc 100644 --- a/web/utils/tableStateToApi.ts +++ b/web/utils/tableStateToApi.ts @@ -84,6 +84,12 @@ function toFilterParameter(value: TableFilterValue): FilterParameter { if (Array.isArray(p['searchTags'])) { param.searchTags = (p['searchTags'] as unknown[]).filter((t): t is string => typeof t === 'string') } + if (Array.isArray(p['searchTagsContains']) && (param.searchTags == null || param.searchTags.length === 0)) { + param.searchTags = (p['searchTagsContains'] as unknown[]).filter((t): t is string => typeof t === 'string') + } + if (param.searchTags == null && p['searchTag'] != null) { + param.searchTags = [String(p['searchTag'])] + } if (typeof p['propertyDefinitionId'] === 'string') { param.propertyDefinitionId = p['propertyDefinitionId'] }