diff --git a/packages/esm-patient-search-app/src/patient-search-page/advanced-patient-search.component.tsx b/packages/esm-patient-search-app/src/patient-search-page/advanced-patient-search.component.tsx index 1e2d6f968..63cf6f4dd 100644 --- a/packages/esm-patient-search-app/src/patient-search-page/advanced-patient-search.component.tsx +++ b/packages/esm-patient-search-app/src/patient-search-page/advanced-patient-search.component.tsx @@ -27,7 +27,9 @@ const AdvancedPatientSearchComponent: React.FC = ({ } }); - count += Object.keys(filters.attributes).length ?? 0; + const attributesWithValues = Object.entries(filters.attributes || {}).filter(([key, value]) => value !== ''); + + count += attributesWithValues.length; return count; }, [filters]); @@ -101,6 +103,8 @@ const AdvancedPatientSearchComponent: React.FC = ({ // Person attributes filter if (Object.keys(filters.attributes).length) { for (const [attributeUuid, value] of Object.entries(filters.attributes)) { + if (value === '') continue; + const matchingAttribute = patient.attributes.find((attr) => attr.attributeType.uuid === attributeUuid); if (!matchingAttribute) return false; diff --git a/packages/esm-patient-search-app/src/patient-search-page/refine-search/refine-search.component.tsx b/packages/esm-patient-search-app/src/patient-search-page/refine-search/refine-search.component.tsx index 5a35f1328..da3e975fe 100644 --- a/packages/esm-patient-search-app/src/patient-search-page/refine-search/refine-search.component.tsx +++ b/packages/esm-patient-search-app/src/patient-search-page/refine-search/refine-search.component.tsx @@ -50,22 +50,7 @@ const RefineSearch: React.FC = ({ setFilters, inTabletOrOverl const onSubmit = useCallback( (data: AdvancedPatientSearchState) => { - const cleanedAttributes = Object.entries(data.attributes || {}).reduce( - (acc, [key, value]) => { - if (value) { - acc[key] = value; - } - return acc; - }, - {} as Record, - ); - - const cleanedData = { - ...data, - attributes: cleanedAttributes, - }; - - setFilters(cleanedData); + setFilters(data); setShowRefineSearchDialog(false); }, [setFilters],