Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions web/components/patients/PatientDataEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"
/>
Expand Down
3 changes: 3 additions & 0 deletions web/components/patients/PatientDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 16 additions & 5 deletions web/components/tables/PatientList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,27 @@ export const PatientList = forwardRef<PatientListRef, PatientListProps>(({ 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
? {
searchText: searchQuery,
includeProperties: true,
}
: undefined

const apiFiltering = useMemo(() => columnFiltersToFilterInput(filters), [filters])
const apiSorting = useMemo(() => sortingStateToSortInput(sorting), [sorting])
const apiPagination = useMemo(() => paginationStateToPaginationInput(pagination), [pagination])

Expand Down Expand Up @@ -205,7 +216,7 @@ export const PatientList = forwardRef<PatientListRef, PatientListProps>(({ initi
{
id: 'state',
header: translation('status'),
accessorFn: ({ state }) => [state],
accessorFn: ({ state }) => state,
cell: ({ row }) => {
if (refreshingPatientIds.has(row.original.id)) return rowLoadingCell
return (
Expand All @@ -228,7 +239,7 @@ export const PatientList = forwardRef<PatientListRef, PatientListProps>(({ 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
Expand Down
6 changes: 6 additions & 0 deletions web/utils/tableStateToApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
Expand Down
Loading