diff --git a/src/__tests__/utilsFunction/paginationUtils.test.ts b/src/__tests__/utilsFunction/paginationUtils.test.ts index 338880542..fc83fbd86 100644 --- a/src/__tests__/utilsFunction/paginationUtils.test.ts +++ b/src/__tests__/utilsFunction/paginationUtils.test.ts @@ -1,4 +1,4 @@ -import { checkIfPageAvailable, handlePageError } from 'utils/paginationUtils' +import { checkIfPageAvailable, cleanSearchParams, getCleanGroupId, handlePageError } from 'utils/paginationUtils' import { vi } from 'vitest' describe('checkIfPageAvailable', () => { @@ -45,3 +45,63 @@ describe('handlePageError', () => { expect(dispatch).toHaveBeenCalled() }) }) + +describe('test of getCleanGroupId function', () => { + it('should return no groupId if perimeter is empty or null', () => { + const groupId = '' + expect(getCleanGroupId(groupId)).toBeUndefined() + + const groupId2 = null + expect(getCleanGroupId(groupId2)).toBeUndefined() + }) + it('should return no groupId if perimeter ids make no sense', () => { + const groupId = ',,,,' + expect(getCleanGroupId(groupId)).toBeUndefined() + + const groupId2 = ';;;;' + expect(getCleanGroupId(groupId2)).toBeUndefined() + + const groupId3 = '-,--' + expect(getCleanGroupId(groupId3)).toBeUndefined() + }) + it('should only return numbers separated by commas if groupId is a mess', () => { + const groupId = '12345,,nimp,;,8zhbea,,' + expect(getCleanGroupId(groupId)).toBe('12345') + }) + it('should return the right ids separated by commas', () => { + const groupId = '123,456' + expect(getCleanGroupId(groupId)).toBe('123,456') + }) + it('should not return commas that are at the beginning or at the end', () => { + const groupId = ',123,456,' + expect(getCleanGroupId(groupId)).toBe('123,456') + }) +}) + +describe('test of cleanSearchParams function', () => { + it('should return the right url params', () => { + const page = '3' + const tabId = 'MedicationRequest' + const groupId = '123456' + + expect(cleanSearchParams({ page, tabId, groupId })).toStrictEqual({ + groupId: '123456', + page: '3', + tabId: 'MedicationRequest' + }) + }) + it('should not return groupId in the params if groupId makes no sense or is undefined', () => { + const page = '1' + const groupId2 = 'rijfn236e53:;a' + const groupId3 = ',,,' + + expect(cleanSearchParams({ page })).toStrictEqual({ page: '1' }) + expect(cleanSearchParams({ page, groupId: groupId2 })).toStrictEqual({ page: '1' }) + expect(cleanSearchParams({ page, groupId: groupId3 })).toStrictEqual({ page: '1' }) + }) + it('should not return tabId in the params if tabId is undefined', () => { + const page = '1' + + expect(cleanSearchParams({ page })).toStrictEqual({ page: '1' }) + }) +}) diff --git a/src/__tests__/utilsFunction/tabsUtils.test.ts b/src/__tests__/utilsFunction/tabsUtils.test.ts new file mode 100644 index 000000000..5efbf3099 --- /dev/null +++ b/src/__tests__/utilsFunction/tabsUtils.test.ts @@ -0,0 +1,51 @@ +import { PMSILabel } from 'types/patient' +import { MedicationLabel, ResourceType } from 'types/requestCriterias' +import { getMedicationTab, getPMSITab } from 'utils/tabsUtils' + +const pmsiDefaultTab = { label: PMSILabel.DIAGNOSTIC, id: ResourceType.CONDITION } + +describe('test of getPMSITab', () => { + it('should return default tabId is empty', () => { + const tabId = '' + expect(getPMSITab(tabId)).toStrictEqual(pmsiDefaultTab) + }) + it('should return default tabId doesnt exist in PMSITabs', () => { + const tabId = 'whatever' + expect(getPMSITab(tabId)).toStrictEqual(pmsiDefaultTab) + }) + it('should return the tab matching to the id given', () => { + const tabId = ResourceType.PROCEDURE + expect(getPMSITab(tabId)).toStrictEqual({ label: PMSILabel.CCAM, id: ResourceType.PROCEDURE }) + }) + it('should return the tab matching to the id given even if the casing is wrong', () => { + const tabId = ResourceType.PROCEDURE.toLocaleUpperCase() + expect(getPMSITab(tabId)).toStrictEqual({ label: PMSILabel.CCAM, id: ResourceType.PROCEDURE }) + }) +}) + +const medicationDefaultTab = { label: MedicationLabel.PRESCRIPTION, id: ResourceType.MEDICATION_REQUEST } + +describe('test of getMedicationTab', () => { + it('should return default tabId is empty', () => { + const tabId = '' + expect(getMedicationTab(tabId)).toStrictEqual(medicationDefaultTab) + }) + it('should return default tabId doesnt exist in MedicationTabs', () => { + const tabId = 'test' + expect(getMedicationTab(tabId)).toStrictEqual(medicationDefaultTab) + }) + it('should return the tab matching to the id given', () => { + const tabId = ResourceType.MEDICATION_ADMINISTRATION + expect(getMedicationTab(tabId)).toStrictEqual({ + label: MedicationLabel.ADMINISTRATION, + id: ResourceType.MEDICATION_ADMINISTRATION + }) + }) + it('should return the tab matching to the id given even if the casing is wrong', () => { + const tabId = ResourceType.MEDICATION_ADMINISTRATION.toLocaleUpperCase() + expect(getMedicationTab(tabId)).toStrictEqual({ + label: MedicationLabel.ADMINISTRATION, + id: ResourceType.MEDICATION_ADMINISTRATION + }) + }) +}) diff --git a/src/components/CohortsTable/index.tsx b/src/components/CohortsTable/index.tsx index 4630f0d81..916084d19 100644 --- a/src/components/CohortsTable/index.tsx +++ b/src/components/CohortsTable/index.tsx @@ -106,7 +106,12 @@ const ResearchTable: React.FC = ({ row.request_job_status === CohortJobStatus.FAILED ) return - navigate(`/cohort/${row.group_id}`) + + const searchParams = new URLSearchParams() + if (row.group_id) { + searchParams.set('groupId', row.group_id) + } + navigate(`/cohort?${searchParams.toString()}`) } const handleClickOpenDialog = () => { diff --git a/src/components/Dashboard/BiologyList/index.tsx b/src/components/Dashboard/BiologyList/index.tsx index 5e73af3ed..34a4947aa 100644 --- a/src/components/Dashboard/BiologyList/index.tsx +++ b/src/components/Dashboard/BiologyList/index.tsx @@ -36,19 +36,19 @@ import { fetchLoincCodes as fetchLoincCodesApi, fetchAnabioCodes as fetchAnabioCodesApi } from 'services/aphp/serviceBiology' -import { checkIfPageAvailable, handlePageError } from 'utils/paginationUtils' +import { checkIfPageAvailable, cleanSearchParams, handlePageError } from 'utils/paginationUtils' type BiologyListProps = { - groupId?: string deidentified?: boolean } -const BiologyList = ({ groupId, deidentified }: BiologyListProps) => { +const BiologyList = ({ deidentified }: BiologyListProps) => { const theme = useTheme() const isMd = useMediaQuery(theme.breakpoints.down('lg')) const dispatch = useAppDispatch() const [searchParams, setSearchParams] = useSearchParams() const getPageParam = searchParams.get('page') + const groupId = searchParams.get('groupId') ?? undefined const [toggleFilterByModal, setToggleFilterByModal] = useState(false) const [toggleSaveFiltersModal, setToggleSaveFiltersModal] = useState(false) @@ -203,7 +203,8 @@ const BiologyList = ({ groupId, deidentified }: BiologyListProps) => { ]) useEffect(() => { - setSearchParams({ page: page.toString() }) + setSearchParams(cleanSearchParams({ page: page.toString(), groupId: groupId })) + handlePageError(page, setPage, dispatch, setLoadingStatus) }, [page]) diff --git a/src/components/Dashboard/Documents/Documents.tsx b/src/components/Dashboard/Documents/Documents.tsx index 4a6c2366a..49bd8fc98 100644 --- a/src/components/Dashboard/Documents/Documents.tsx +++ b/src/components/Dashboard/Documents/Documents.tsx @@ -43,19 +43,19 @@ import EncounterStatusFilter from 'components/Filters/EncounterStatusFilter' import { SourceType } from 'types/scope' import { Hierarchy } from 'types/hierarchy' import { useSearchParams } from 'react-router-dom' -import { checkIfPageAvailable, handlePageError } from 'utils/paginationUtils' +import { checkIfPageAvailable, cleanSearchParams, handlePageError } from 'utils/paginationUtils' import { CanceledError } from 'axios' import { DocumentReference } from 'fhir/r4' type DocumentsProps = { - groupId?: string deidentified: boolean } -const Documents: React.FC = ({ groupId, deidentified }) => { +const Documents: React.FC = ({ deidentified }) => { const dispatch = useAppDispatch() const [searchParams, setSearchParams] = useSearchParams() const getPageParam = searchParams.get('page') + const groupId = searchParams.get('groupId') ?? undefined const [toggleFilterByModal, setToggleFilterByModal] = useState(false) const [toggleSaveFiltersModal, setToggleSaveFiltersModal] = useState(false) @@ -234,7 +234,7 @@ const Documents: React.FC = ({ groupId, deidentified }) => { ]) useEffect(() => { - setSearchParams({ page: page.toString() }) + setSearchParams(cleanSearchParams({ page: page.toString(), groupId: groupId })) handlePageError(page, setPage, dispatch, setLoadingStatus) }, [page]) diff --git a/src/components/Dashboard/FormsList/index.tsx b/src/components/Dashboard/FormsList/index.tsx index d84171b7e..289ec9748 100644 --- a/src/components/Dashboard/FormsList/index.tsx +++ b/src/components/Dashboard/FormsList/index.tsx @@ -22,19 +22,17 @@ import { Questionnaire } from 'fhir/r4' import MaternityFormFilter from 'components/Filters/MaternityFormFilter' import DataTableForms from 'components/DataTable/DataTableForms' import { useSearchParams } from 'react-router-dom' -import { checkIfPageAvailable, handlePageError } from 'utils/paginationUtils' +import { checkIfPageAvailable, cleanSearchParams, handlePageError } from 'utils/paginationUtils' import Chip from 'components/ui/Chip' -type FormsListProps = { - groupId?: string -} - -const FormsList = ({ groupId }: FormsListProps) => { +const FormsList = () => { const theme = useTheme() const isSm = useMediaQuery(theme.breakpoints.down('md')) const dispatch = useAppDispatch() const [searchParams, setSearchParams] = useSearchParams() const pageParam = searchParams.get('page') + const groupId = searchParams.get('groupId') ?? undefined + const [toggleFilterByModal, setToggleFilterByModal] = useState(false) const [encounterStatusList, setEncounterStatusList] = useState[]>([]) const [questionnaires, setQuestionnaires] = useState([]) @@ -142,7 +140,8 @@ const FormsList = ({ groupId }: FormsListProps) => { }, [orderBy, formName, startDate, endDate, executiveUnits, encounterStatus, ipp, groupId]) useEffect(() => { - setSearchParams({ page: page.toString() }) + setSearchParams(cleanSearchParams({ page: page.toString(), groupId: groupId })) + handlePageError(page, setPage, dispatch, setLoadingStatus) }, [page]) diff --git a/src/components/Dashboard/ImagingList/index.tsx b/src/components/Dashboard/ImagingList/index.tsx index 642fb597f..cf9d350a8 100644 --- a/src/components/Dashboard/ImagingList/index.tsx +++ b/src/components/Dashboard/ImagingList/index.tsx @@ -36,18 +36,18 @@ import { SourceType } from 'types/scope' import { Hierarchy } from 'types/hierarchy' import { AppConfig } from 'config' import { useSearchParams } from 'react-router-dom' -import { checkIfPageAvailable, handlePageError } from 'utils/paginationUtils' +import { checkIfPageAvailable, cleanSearchParams, handlePageError } from 'utils/paginationUtils' type ImagingListProps = { - groupId?: string deidentified?: boolean } -const ImagingList = ({ groupId, deidentified }: ImagingListProps) => { +const ImagingList = ({ deidentified }: ImagingListProps) => { const appConfig = useContext(AppConfig) const dispatch = useAppDispatch() const [searchParams, setSearchParams] = useSearchParams() const getPageParam = searchParams.get('page') + const groupId = searchParams.get('groupId') ?? undefined const [searchResults, setSearchResults] = useState({ nb: 0, total: 0, label: 'résultats' }) const [patientsResult, setPatientsResult] = useState({ nb: 0, total: 0, label: 'patient(s)' }) @@ -184,7 +184,7 @@ const ImagingList = ({ groupId, deidentified }: ImagingListProps) => { }, [ipp, nda, startDate, endDate, orderBy, searchInput, executiveUnits, modality, groupId, encounterStatus]) useEffect(() => { - setSearchParams({ page: page.toString() }) + setSearchParams(cleanSearchParams({ page: page.toString(), groupId: groupId })) handlePageError(page, setPage, dispatch, setLoadingStatus) }, [page]) diff --git a/src/components/Dashboard/MedicationList/index.tsx b/src/components/Dashboard/MedicationList/index.tsx index 611002641..420d172c3 100644 --- a/src/components/Dashboard/MedicationList/index.tsx +++ b/src/components/Dashboard/MedicationList/index.tsx @@ -34,15 +34,15 @@ import useSearchCriterias, { initMedSearchCriterias } from 'reducers/searchCrite import { cancelPendingRequest } from 'utils/abortController' import { selectFiltersAsArray } from 'utils/filters' import { mapToLabel } from 'mappers/pmsi' +import { checkIfPageAvailable, cleanSearchParams, handlePageError } from 'utils/paginationUtils' +import { getMedicationTab } from 'utils/tabsUtils' import { useSearchParams } from 'react-router-dom' -import { checkIfPageAvailable, handlePageError } from 'utils/paginationUtils' type MedicationListProps = { - groupId?: string deidentified?: boolean } -const MedicationList = ({ groupId, deidentified }: MedicationListProps) => { +const MedicationList = ({ deidentified }: MedicationListProps) => { const theme = useTheme() const isSm = useMediaQuery(theme.breakpoints.down('md')) const [toggleFilterByModal, setToggleFilterByModal] = useState(false) @@ -55,11 +55,11 @@ const MedicationList = ({ groupId, deidentified }: MedicationListProps) => { const dispatch = useAppDispatch() const [searchParams, setSearchParams] = useSearchParams() const getPageParam = searchParams.get('page') + const groupId = searchParams.get('groupId') ?? undefined + const tabId = searchParams.get('tabId') ?? undefined + const existingParams = Object.fromEntries(searchParams.entries()) - const [selectedTab, setSelectedTab] = useState({ - id: ResourceType.MEDICATION_REQUEST, - label: MedicationLabel.PRESCRIPTION - }) + const [selectedTab, setSelectedTab] = useState(getMedicationTab(tabId)) const [page, setPage] = useState(getPageParam ? parseInt(getPageParam, 10) : 1) const { @@ -228,11 +228,9 @@ const MedicationList = ({ groupId, deidentified }: MedicationListProps) => { ]) useEffect(() => { - handlePageError(page, setPage, dispatch, setLoadingStatus) + setSearchParams(cleanSearchParams({ page: page.toString(), tabId: selectedTab.id, groupId: groupId })) - const updatedSearchParams = new URLSearchParams(searchParams) - updatedSearchParams.set('page', page.toString()) - setSearchParams(updatedSearchParams) + handlePageError(page, setPage, dispatch, setLoadingStatus) }, [page]) useEffect(() => { @@ -300,6 +298,7 @@ const MedicationList = ({ groupId, deidentified }: MedicationListProps) => { value: TabType ) => { setSelectedTab(value) + setSearchParams({ ...existingParams, tabId: value.id }) }} /> diff --git a/src/components/Dashboard/PMSIList/index.tsx b/src/components/Dashboard/PMSIList/index.tsx index b03004e16..805570757 100644 --- a/src/components/Dashboard/PMSIList/index.tsx +++ b/src/components/Dashboard/PMSIList/index.tsx @@ -39,14 +39,14 @@ import { cancelPendingRequest } from 'utils/abortController' import { selectFiltersAsArray } from 'utils/filters' import { mapToLabel, mapToSourceType } from 'mappers/pmsi' import { useSearchParams } from 'react-router-dom' -import { checkIfPageAvailable, handlePageError } from 'utils/paginationUtils' +import { checkIfPageAvailable, cleanSearchParams, handlePageError } from 'utils/paginationUtils' +import { getPMSITab } from 'utils/tabsUtils' type PMSIListProps = { - groupId?: string deidentified?: boolean } -const PMSIList = ({ groupId, deidentified }: PMSIListProps) => { +const PMSIList = ({ deidentified }: PMSIListProps) => { const [toggleFilterByModal, setToggleFilterByModal] = useState(false) const [toggleSaveFiltersModal, setToggleSaveFiltersModal] = useState(false) const [toggleSavedFiltersModal, setToggleSavedFiltersModal] = useState(false) @@ -57,11 +57,11 @@ const PMSIList = ({ groupId, deidentified }: PMSIListProps) => { const dispatch = useAppDispatch() const [searchParams, setSearchParams] = useSearchParams() const getPageParam = searchParams.get('page') + const groupId = searchParams.get('groupId') ?? undefined + const tabId = searchParams.get('tabId') ?? undefined + const existingParams = Object.fromEntries(searchParams.entries()) - const [selectedTab, setSelectedTab] = useState({ - id: ResourceType.CONDITION, - label: PMSILabel.DIAGNOSTIC - }) + const [selectedTab, setSelectedTab] = useState(getPMSITab(tabId)) const sourceType = mapToSourceType(selectedTab.id) const [page, setPage] = useState(getPageParam ? parseInt(getPageParam, 10) : 1) @@ -215,9 +215,7 @@ const PMSIList = ({ groupId, deidentified }: PMSIListProps) => { ]) useEffect(() => { - const updatedSearchParams = new URLSearchParams(searchParams) - updatedSearchParams.set('page', page.toString()) - setSearchParams(updatedSearchParams) + setSearchParams(cleanSearchParams({ page: page.toString(), tabId: selectedTab.id, groupId: groupId })) handlePageError(page, setPage, dispatch, setLoadingStatus) }, [page]) @@ -308,6 +306,7 @@ const PMSIList = ({ groupId, deidentified }: PMSIListProps) => { active={selectedTab} onchange={(value: PmsiTab) => { setSelectedTab(value) + setSearchParams({ ...existingParams, tabId: value.id }) }} /> diff --git a/src/components/Dashboard/PatientList/PatientList.tsx b/src/components/Dashboard/PatientList/PatientList.tsx index 10d9260b1..e75183ea6 100644 --- a/src/components/Dashboard/PatientList/PatientList.tsx +++ b/src/components/Dashboard/PatientList/PatientList.tsx @@ -49,18 +49,18 @@ import { ResourceType } from 'types/requestCriterias' import List from 'components/ui/List' import { useAppDispatch, useAppSelector } from 'state' import { useSearchParams } from 'react-router-dom' -import { checkIfPageAvailable, handlePageError } from 'utils/paginationUtils' +import { checkIfPageAvailable, cleanSearchParams, handlePageError } from 'utils/paginationUtils' type PatientListProps = { total: number - groupId?: string deidentified?: boolean | null } -const PatientList = ({ groupId, total, deidentified }: PatientListProps) => { +const PatientList = ({ total, deidentified }: PatientListProps) => { const dispatch = useAppDispatch() const [searchParams, setSearchParams] = useSearchParams() const getPageParam = searchParams.get('page') + const groupId = searchParams.get('groupId') ?? undefined const [toggleFilterByModal, setToggleFilterByModal] = useState(false) const [toggleSaveFiltersModal, setToggleSaveFiltersModal] = useState(false) @@ -165,7 +165,7 @@ const PatientList = ({ groupId, total, deidentified }: PatientListProps) => { }, [genders, vitalStatuses, birthdatesRanges, orderBy, searchBy, searchInput, groupId]) useEffect(() => { - setSearchParams({ page: page.toString() }) + setSearchParams(cleanSearchParams({ page: page.toString(), groupId: groupId })) handlePageError(page, setPage, dispatch, setLoadingStatus) }, [page]) diff --git a/src/components/Dashboard/Preview/Preview.tsx b/src/components/Dashboard/Preview/Preview.tsx index 507ce4caa..2b27d4ced 100644 --- a/src/components/Dashboard/Preview/Preview.tsx +++ b/src/components/Dashboard/Preview/Preview.tsx @@ -1,4 +1,4 @@ -import React, { useContext } from 'react' +import React, { useContext, useEffect } from 'react' import { CircularProgress, Grid, @@ -31,6 +31,8 @@ import displayDigit from 'utils/displayDigit' import { SimpleChartDataType, GenderRepartitionType, AgeRepartitionType, VisiteRepartitionType } from 'types' import LocationMap from 'components/Dashboard/Preview/LocationMap' import { AppConfig } from 'config' +import { useSearchParams } from 'react-router-dom' +import { getCleanGroupId } from 'utils/paginationUtils' const MAP_WARNING_PERSON_COUNT_THRESHOLD = 1000000 @@ -113,8 +115,14 @@ const Preview: React.FC = ({ }) => { const { classes } = useStyles() const appConfig = useContext(AppConfig) + const [searchParams, setSearchParams] = useSearchParams() + const groupIds = searchParams.get('groupId') ?? undefined const { vitalStatusData, genderData } = getGenderRepartitionSimpleData(genderRepartitionMap) + useEffect(() => { + setSearchParams({ ...(groupIds && getCleanGroupId(groupIds) && { groupId: getCleanGroupId(groupIds) }) }) + }, []) + return ( diff --git a/src/components/Patient/PatientBiology/PatientBiology.tsx b/src/components/Patient/PatientBiology/PatientBiology.tsx index 0fbae1ca8..a42bd3348 100644 --- a/src/components/Patient/PatientBiology/PatientBiology.tsx +++ b/src/components/Patient/PatientBiology/PatientBiology.tsx @@ -42,16 +42,13 @@ import EncounterStatusFilter from 'components/Filters/EncounterStatusFilter' import { SourceType } from 'types/scope' import { Hierarchy } from 'types/hierarchy' import { useSearchParams } from 'react-router-dom' -import { checkIfPageAvailable, handlePageError } from 'utils/paginationUtils' +import { checkIfPageAvailable, cleanSearchParams, handlePageError } from 'utils/paginationUtils' -type PatientBiologyProps = { - groupId?: string -} - -const PatientBiology = ({ groupId }: PatientBiologyProps) => { +const PatientBiology = () => { const { classes } = useStyles() const [searchParams, setSearchParams] = useSearchParams() const getPageParam = searchParams.get('page') + const groupId = searchParams.get('groupId') ?? undefined const theme = useTheme() const isMd = useMediaQuery(theme.breakpoints.down('lg')) @@ -166,9 +163,8 @@ const PatientBiology = ({ groupId }: PatientBiologyProps) => { }, [nda, loinc, anabio, startDate, endDate, executiveUnits, validatedStatus, orderBy, searchInput, encounterStatus]) useEffect(() => { - const updatedSearchParams = new URLSearchParams(searchParams) - updatedSearchParams.set('page', page.toString()) - setSearchParams(updatedSearchParams) + setSearchParams(cleanSearchParams({ page: page.toString(), groupId: groupId })) + handlePageError(page, setPage, dispatch, setLoadingStatus) }, [page]) diff --git a/src/components/Patient/PatientDocs/PatientDocs.tsx b/src/components/Patient/PatientDocs/PatientDocs.tsx index 32d7a6f8d..93b59f682 100644 --- a/src/components/Patient/PatientDocs/PatientDocs.tsx +++ b/src/components/Patient/PatientDocs/PatientDocs.tsx @@ -24,7 +24,6 @@ import { SearchByTypes, FilterByDocumentStatus } from 'types/searchCriterias' -import { PatientTypes } from 'types/patient' import Modal from 'components/ui/Modal' import Button from 'components/ui/Button' import Searchbar from 'components/ui/Searchbar' @@ -51,12 +50,13 @@ import services from 'services/aphp' import { SourceType } from 'types/scope' import { Hierarchy } from 'types/hierarchy' import { useSearchParams } from 'react-router-dom' -import { checkIfPageAvailable, handlePageError } from 'utils/paginationUtils' +import { checkIfPageAvailable, cleanSearchParams, handlePageError } from 'utils/paginationUtils' -const PatientDocs: React.FC = ({ groupId }) => { +const PatientDocs = () => { const dispatch = useAppDispatch() const [searchParams, setSearchParams] = useSearchParams() const getPageParam = searchParams.get('page') + const groupId = searchParams.get('groupId') ?? undefined const [toggleFilterByModal, setToggleFilterByModal] = useState(false) const [toggleSaveFiltersModal, setToggleSaveFiltersModal] = useState(false) const [toggleSavedFiltersModal, setToggleSavedFiltersModal] = useState(false) @@ -190,9 +190,7 @@ const PatientDocs: React.FC = ({ groupId }) => { ]) useEffect(() => { - const updatedSearchParams = new URLSearchParams(searchParams) - updatedSearchParams.set('page', page.toString()) - setSearchParams(updatedSearchParams) + setSearchParams(cleanSearchParams({ page: page.toString(), groupId: groupId })) handlePageError(page, setPage, dispatch, setLoadingStatus) }, [page]) diff --git a/src/components/Patient/PatientForms/MaternityForms/index.tsx b/src/components/Patient/PatientForms/MaternityForms/index.tsx index ea6fad97d..8b5a9c71d 100644 --- a/src/components/Patient/PatientForms/MaternityForms/index.tsx +++ b/src/components/Patient/PatientForms/MaternityForms/index.tsx @@ -23,16 +23,16 @@ import services from 'services/aphp' import EncounterStatusFilter from 'components/Filters/EncounterStatusFilter' import { SourceType } from 'types/scope' import { Hierarchy } from 'types/hierarchy' +import { useSearchParams } from 'react-router-dom' +import { getCleanGroupId } from 'utils/paginationUtils' -type PatientFormsProps = { - groupId?: string -} - -const MaternityForm = ({ groupId }: PatientFormsProps) => { +const MaternityForm = () => { const [toggleModal, setToggleModal] = useState(false) const dispatch = useAppDispatch() + const [searchParams, setSearchParams] = useSearchParams() const patient = useAppSelector((state) => state.patient) + const groupId = searchParams.get('groupId') ?? undefined const [loadingStatus, setLoadingStatus] = useState(LoadingStatus.FETCHING) const [questionnaires, setQuestionnaires] = useState([]) @@ -93,6 +93,8 @@ const MaternityForm = ({ groupId }: PatientFormsProps) => { useEffect(() => { setLoadingStatus(LoadingStatus.IDDLE) + setSearchParams({ ...(groupId && getCleanGroupId(groupId) && { groupId: getCleanGroupId(groupId) }) }) + fetch() }, []) diff --git a/src/components/Patient/PatientForms/index.tsx b/src/components/Patient/PatientForms/index.tsx index f3a2c7853..72ef6090a 100644 --- a/src/components/Patient/PatientForms/index.tsx +++ b/src/components/Patient/PatientForms/index.tsx @@ -4,10 +4,6 @@ import { BlockWrapper } from 'components/ui/Layout' import Select from 'components/ui/Searchbar/Select' import MaternityForm from './MaternityForms' -type PatientFormsProps = { - groupId?: string -} - const formTypes = [ { id: 'maternity', @@ -15,7 +11,7 @@ const formTypes = [ } ] -const PatientForms = ({ groupId }: PatientFormsProps) => { +const PatientForms = () => { const [formType, setFormType] = useState('maternity') return ( @@ -23,7 +19,7 @@ const PatientForms = ({ groupId }: PatientFormsProps) => {