Skip to content

Commit

Permalink
feat: added tabs to url - Ref gestion-de-projet#2766
Browse files Browse the repository at this point in the history
  • Loading branch information
ManelleG committed Oct 28, 2024
1 parent 5f8bc10 commit 4857b01
Show file tree
Hide file tree
Showing 17 changed files with 225 additions and 155 deletions.
51 changes: 51 additions & 0 deletions src/__tests__/utilsFunction/tabsUtils.test.ts
Original file line number Diff line number Diff line change
@@ -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
})
})
})
7 changes: 6 additions & 1 deletion src/components/CohortsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ const ResearchTable: React.FC<ResearchTableProps> = ({
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 = () => {
Expand Down
8 changes: 5 additions & 3 deletions src/components/Dashboard/BiologyList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ import {
import { checkIfPageAvailable, 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)
Expand Down Expand Up @@ -203,7 +203,9 @@ const BiologyList = ({ groupId, deidentified }: BiologyListProps) => {
])

useEffect(() => {
setSearchParams({ page: page.toString() })
const existingParams = Object.fromEntries(searchParams.entries())
setSearchParams({ ...existingParams, page: page.toString() })

handlePageError(page, setPage, dispatch, setLoadingStatus)
}, [page])

Expand Down
7 changes: 4 additions & 3 deletions src/components/Dashboard/Documents/Documents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ import { CanceledError } from 'axios'
import { DocumentReference } from 'fhir/r4'

type DocumentsProps = {
groupId?: string
deidentified: boolean
}

const Documents: React.FC<DocumentsProps> = ({ groupId, deidentified }) => {
const Documents: React.FC<DocumentsProps> = ({ 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)
Expand Down Expand Up @@ -234,7 +234,8 @@ const Documents: React.FC<DocumentsProps> = ({ groupId, deidentified }) => {
])

useEffect(() => {
setSearchParams({ page: page.toString() })
const existingParams = Object.fromEntries(searchParams.entries())
setSearchParams({ ...existingParams, page: page.toString() })

handlePageError(page, setPage, dispatch, setLoadingStatus)
}, [page])
Expand Down
11 changes: 5 additions & 6 deletions src/components/Dashboard/FormsList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ import { useSearchParams } from 'react-router-dom'
import { checkIfPageAvailable, 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 existingParams = Object.fromEntries(searchParams.entries())

const [toggleFilterByModal, setToggleFilterByModal] = useState(false)
const [encounterStatusList, setEncounterStatusList] = useState<Hierarchy<any, any>[]>([])
const [questionnaires, setQuestionnaires] = useState<Questionnaire[]>([])
Expand Down Expand Up @@ -142,7 +141,7 @@ const FormsList = ({ groupId }: FormsListProps) => {
}, [orderBy, formName, startDate, endDate, executiveUnits, encounterStatus, ipp, groupId])

useEffect(() => {
setSearchParams({ page: page.toString() })
setSearchParams({ ...existingParams, page: page.toString() })
handlePageError(page, setPage, dispatch, setLoadingStatus)
}, [page])

Expand Down
7 changes: 4 additions & 3 deletions src/components/Dashboard/ImagingList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ import { useSearchParams } from 'react-router-dom'
import { checkIfPageAvailable, 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<ResultsType>({ nb: 0, total: 0, label: 'résultats' })
const [patientsResult, setPatientsResult] = useState<ResultsType>({ nb: 0, total: 0, label: 'patient(s)' })
Expand Down Expand Up @@ -184,7 +184,8 @@ const ImagingList = ({ groupId, deidentified }: ImagingListProps) => {
}, [ipp, nda, startDate, endDate, orderBy, searchInput, executiveUnits, modality, groupId, encounterStatus])

useEffect(() => {
setSearchParams({ page: page.toString() })
const existingParams = Object.fromEntries(searchParams.entries())
setSearchParams({ ...existingParams, page: page.toString() })

handlePageError(page, setPage, dispatch, setLoadingStatus)
}, [page])
Expand Down
19 changes: 9 additions & 10 deletions src/components/Dashboard/MedicationList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ import { selectFiltersAsArray } from 'utils/filters'
import { mapToLabel } from 'mappers/pmsi'
import { useSearchParams } from 'react-router-dom'
import { checkIfPageAvailable, handlePageError } from 'utils/paginationUtils'
import { getMedicationTab } from 'utils/tabsUtils'

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)
Expand All @@ -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<MedicationTab>({
id: ResourceType.MEDICATION_REQUEST,
label: MedicationLabel.PRESCRIPTION
})
const [selectedTab, setSelectedTab] = useState<MedicationTab>(getMedicationTab(tabId))

const [page, setPage] = useState(getPageParam ? parseInt(getPageParam, 10) : 1)
const {
Expand Down Expand Up @@ -228,11 +228,9 @@ const MedicationList = ({ groupId, deidentified }: MedicationListProps) => {
])

useEffect(() => {
handlePageError(page, setPage, dispatch, setLoadingStatus)
setSearchParams({ ...existingParams, page: page.toString(), tabId: selectedTab.id })

const updatedSearchParams = new URLSearchParams(searchParams)
updatedSearchParams.set('page', page.toString())
setSearchParams(updatedSearchParams)
handlePageError(page, setPage, dispatch, setLoadingStatus)
}, [page])

useEffect(() => {
Expand Down Expand Up @@ -300,6 +298,7 @@ const MedicationList = ({ groupId, deidentified }: MedicationListProps) => {
value: TabType<ResourceType.MEDICATION_ADMINISTRATION | ResourceType.MEDICATION_REQUEST, MedicationLabel>
) => {
setSelectedTab(value)
setSearchParams({ ...existingParams, tabId: value.id })
}}
/>
</Grid>
Expand Down
17 changes: 8 additions & 9 deletions src/components/Dashboard/PMSIList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ import { selectFiltersAsArray } from 'utils/filters'
import { mapToLabel, mapToSourceType } from 'mappers/pmsi'
import { useSearchParams } from 'react-router-dom'
import { checkIfPageAvailable, 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)
Expand All @@ -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<PmsiTab>({
id: ResourceType.CONDITION,
label: PMSILabel.DIAGNOSTIC
})
const [selectedTab, setSelectedTab] = useState<PmsiTab>(getPMSITab(tabId))
const sourceType = mapToSourceType(selectedTab.id)

const [page, setPage] = useState(getPageParam ? parseInt(getPageParam, 10) : 1)
Expand Down Expand Up @@ -215,9 +215,7 @@ const PMSIList = ({ groupId, deidentified }: PMSIListProps) => {
])

useEffect(() => {
const updatedSearchParams = new URLSearchParams(searchParams)
updatedSearchParams.set('page', page.toString())
setSearchParams(updatedSearchParams)
setSearchParams({ ...existingParams, page: page.toString(), tabId: selectedTab.id })

handlePageError(page, setPage, dispatch, setLoadingStatus)
}, [page])
Expand Down Expand Up @@ -308,6 +306,7 @@ const PMSIList = ({ groupId, deidentified }: PMSIListProps) => {
active={selectedTab}
onchange={(value: PmsiTab) => {
setSelectedTab(value)
setSearchParams({ ...existingParams, tabId: value.id })
}}
/>
</Grid>
Expand Down
7 changes: 4 additions & 3 deletions src/components/Dashboard/PatientList/PatientList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ import { checkIfPageAvailable, 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)
Expand Down Expand Up @@ -165,7 +165,8 @@ const PatientList = ({ groupId, total, deidentified }: PatientListProps) => {
}, [genders, vitalStatuses, birthdatesRanges, orderBy, searchBy, searchInput, groupId])

useEffect(() => {
setSearchParams({ page: page.toString() })
const existingParams = Object.fromEntries(searchParams.entries())
setSearchParams({ ...existingParams, page: page.toString() })

handlePageError(page, setPage, dispatch, setLoadingStatus)
}, [page])
Expand Down
14 changes: 6 additions & 8 deletions src/components/Patient/PatientMedication/PatientMedication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { SourceType } from 'types/scope'
import { Hierarchy } from 'types/hierarchy'
import { useSearchParams } from 'react-router-dom'
import { checkIfPageAvailable, handlePageError } from 'utils/paginationUtils'
import { getMedicationTab } from 'utils/tabsUtils'

type PatientMedicationProps = {
groupId?: string
Expand All @@ -64,6 +65,8 @@ const PatientMedication = ({ groupId }: PatientMedicationProps) => {
const { classes } = useStyles()
const [searchParams, setSearchParams] = useSearchParams()
const getPageParam = searchParams.get('page')
const tabId = searchParams.get('tabId') ?? undefined
const existingParams = Object.fromEntries(searchParams.entries())
const theme = useTheme()
const isSm = useMediaQuery(theme.breakpoints.down('md'))
const [toggleFilterByModal, setToggleFilterByModal] = useState(false)
Expand All @@ -81,10 +84,7 @@ const PatientMedication = ({ groupId }: PatientMedicationProps) => {
const [page, setPage] = useState(getPageParam ? parseInt(getPageParam, 10) : 1)
const [selectedTab, setSelectedTab] = useState<
TabType<ResourceType.MEDICATION_ADMINISTRATION | ResourceType.MEDICATION_REQUEST, MedicationLabel>
>({
id: ResourceType.MEDICATION_REQUEST,
label: MedicationLabel.PRESCRIPTION
})
>(getMedicationTab(tabId))
const [oldTabs, setOldTabs] = useState<MedicationTab | null>(null)

const {
Expand Down Expand Up @@ -215,10 +215,7 @@ const PatientMedication = ({ groupId }: PatientMedicationProps) => {

useEffect(() => {
setOldTabs(selectedTab)

const updatedSearchParams = new URLSearchParams(searchParams)
updatedSearchParams.set('page', page.toString())
setSearchParams(updatedSearchParams)
setSearchParams({ ...existingParams, page: page.toString(), tabId: selectedTab.id })

handlePageError(page, setPage, dispatch, setLoadingStatus)
}, [page])
Expand Down Expand Up @@ -301,6 +298,7 @@ const PatientMedication = ({ groupId }: PatientMedicationProps) => {
) => {
setOldTabs(selectedTab)
setSelectedTab(value)
setSearchParams({ ...existingParams, tabId: value.id })
}}
/>
</Grid>
Expand Down
Loading

0 comments on commit 4857b01

Please sign in to comment.