Skip to content

Commit

Permalink
fix: make changes for rights routes following backend refacto (#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
thicham43 authored Dec 14, 2023
1 parent be8f71c commit 8c6a656
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 52 deletions.
56 changes: 25 additions & 31 deletions src/components/Requests/ProjectsTable/VersionRow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,50 +77,46 @@ const VersionRow: React.FC<{ requestId: string; cohortsList: Cohort[] }> = ({ re
</TableHead>
<TableBody>
{cohorts && cohorts.length > 0 ? (
cohorts.map((historyRow) => {
if (!historyRow) return <></>
cohorts.map((cohort) => {
if (!cohort) return <></>

const isError =
!historyRow.fhir_group_id ||
historyRow.request_job_status === JobStatus.pending ||
historyRow.request_job_status === JobStatus.new ||
!!historyRow.request_job_fail_msg
!cohort.fhir_group_id ||
cohort.request_job_status === JobStatus.pending ||
cohort.request_job_status === JobStatus.new ||
!!cohort.request_job_fail_msg

const canExportThisCohort = !!ODD_EXPORT && !isError ? historyRow.rights?.export_csv_nomi : false
const canExportThisCohort = !!ODD_EXPORT && !isError ? cohort.rights?.export_csv_nomi : false

return (
<TableRow key={historyRow.uuid}>
<TableRow key={cohort.uuid}>
<TableCellWrapper align="left" className={classes.tdName}>
{historyRow.fhir_group_id ? (
<Link onClick={() => navigate(`/cohort/${historyRow.fhir_group_id}`)} underline="hover">
{historyRow.name}
{cohort.fhir_group_id ? (
<Link onClick={() => navigate(`/cohort/${cohort.fhir_group_id}`)} underline="hover">
{cohort.name}
</Link>
) : (
<Typography component="span" className={classes.notAllowed}>
{historyRow.name}
{cohort.name}
</Typography>
)}
<IconButton
className={classes.editButton}
size="small"
onClick={() => _handleEditCohort(historyRow)}
>
<IconButton className={classes.editButton} size="small" onClick={() => _handleEditCohort(cohort)}>
<EditIcon />
</IconButton>
</TableCellWrapper>
<TableCellWrapper>
<IconButton onClick={() => onSetCohortFavorite(historyRow)}>
<FavStar favorite={historyRow.favorite} />
<IconButton onClick={() => onSetCohortFavorite(cohort)}>
<FavStar favorite={cohort.favorite} />
</IconButton>
</TableCellWrapper>
<TableCellWrapper>
{historyRow.fhir_group_id ? (
{cohort.fhir_group_id ? (
<Chip label="Terminé" style={{ backgroundColor: '#28a745', color: 'white' }} />
) : historyRow.request_job_status === JobStatus.pending ||
historyRow.request_job_status === JobStatus.new ? (
) : cohort.request_job_status === JobStatus.pending ||
cohort.request_job_status === JobStatus.new ? (
<Chip label="En cours" style={{ backgroundColor: '#ffc107', color: 'black' }} />
) : historyRow.request_job_fail_msg ? (
<Tooltip title={historyRow.request_job_fail_msg}>
) : cohort.request_job_fail_msg ? (
<Tooltip title={cohort.request_job_fail_msg}>
<Chip label="Erreur" style={{ backgroundColor: '#dc3545', color: 'black' }} />
</Tooltip>
) : (
Expand All @@ -130,23 +126,21 @@ const VersionRow: React.FC<{ requestId: string; cohortsList: Cohort[] }> = ({ re
<TableCellWrapper>
<Link
className={classes.versionLabel}
onClick={() => navigate(`/cohort/new/${requestId}/${historyRow.request_query_snapshot}`)}
onClick={() => navigate(`/cohort/new/${requestId}/${cohort.request_query_snapshot}`)}
>
{historyRow.request_query_snapshot?.split('-')[0]}
{cohort.request_query_snapshot?.split('-')[0]}
</Link>
</TableCellWrapper>
<TableCellWrapper>{displayDigit(historyRow.result_size)}</TableCellWrapper>
<TableCellWrapper>{displayDigit(cohort.result_size)}</TableCellWrapper>
<Hidden lgDown>
<TableCellWrapper>{moment(historyRow.modified_at).format('DD/MM/YYYY [à] HH:mm')}</TableCellWrapper>
<TableCellWrapper>{moment(cohort.modified_at).format('DD/MM/YYYY [à] HH:mm')}</TableCellWrapper>
</Hidden>

<TableCellWrapper>
<IconButton
disabled={!canExportThisCohort}
onClick={
canExportThisCohort
? () => setSelectedExportableCohort(historyRow.fhir_group_id ?? '')
: () => null
canExportThisCohort ? () => setSelectedExportableCohort(cohort.fhir_group_id ?? '') : () => null
}
>
<ExportIcon />
Expand Down
2 changes: 1 addition & 1 deletion src/services/aphp/callApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ export const fetchScope: (
if (cohortIds && cohortIds.length > 0) options = [...options, `cohort_id=${cohortIds.join(',')}`] // eslint-disable-line
if (type && type.length > 0) options = [...options, `type_source_value=${type.join(',')}`] // eslint-disable-line

const url: string = isExecutiveUnit ? 'accesses/perimeters/?' : 'accesses/perimeters/read-patient/?'
const url: string = isExecutiveUnit ? 'accesses/perimeters/?' : 'accesses/perimeters/patient-data/rights/?'
const response: AxiosResponse<IScope | unknown> = await apiBackend.get(`${url}${options.reduce(paramsReducer)}`, {
signal: signal
})
Expand Down
12 changes: 6 additions & 6 deletions src/services/aphp/servicePerimeters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,18 @@ const servicesPerimeters: IServicePerimeters = {
return false
}

const caresiteIds = selectedPopulation
const perimetersIds = selectedPopulation
.map((perimeter) => perimeter?.id)
.filter((item: any, index: number, array: any[]) => item && array.indexOf(item) === index)
.join(',')

const rightResponse = await fetchPerimeterAccesses(caresiteIds)
const rightResponse = await fetchPerimeterAccesses(perimetersIds)
const rightsData = (rightResponse.data as any[]) ?? []

let allowSearchIpp = false

rightsData.forEach((right) => {
if (right.right_search_patient_with_ipp) {
if (right.right_search_patients_by_ipp) {
allowSearchIpp = true
}
})
Expand Down Expand Up @@ -287,7 +287,7 @@ const servicesPerimeters: IServicePerimeters = {
if (!defaultPerimetersIds && !noPerimetersIdsFetch) {
const url: string = isExecutiveUnit
? 'accesses/perimeters/?type_source_value=' + servicesPerimeters.getHigherTypes()[0]
: 'accesses/perimeters/read-patient/'
: 'accesses/perimeters/patient-data/rights/'
const rightResponse = await apiBackend.get(url, { signal: signal })
if (rightResponse.status === 200 && rightResponse.data.message === noRightsMessage) {
const noRightError: any = {
Expand Down Expand Up @@ -407,9 +407,9 @@ const servicesPerimeters: IServicePerimeters = {
},

fetchPerimetersRights: async (perimeters) => {
const caresiteIds = perimeters.map((perimeter) => perimeter.id).join(',')
const perimetersIds = perimeters.map((perimeter) => perimeter.id).join(',')

const rightResponse = await fetchPerimeterAccesses(caresiteIds)
const rightResponse = await fetchPerimeterAccesses(perimetersIds)
const rightsData = (rightResponse.data as any[]) ?? []

return perimeters.map((perimeter) => {
Expand Down
16 changes: 2 additions & 14 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,8 @@ export type ScopePage = {
perimeter: ScopeElement
read_role: string
right_read_patient_nominative: boolean
right_read_patient_pseudo_anonymised: boolean
right_search_patient_with_ipp: boolean
right_read_patient_pseudonymized: boolean
right_search_patients_by_ipp: boolean
read_access?: string
read_export?: string
}
Expand All @@ -732,18 +732,6 @@ export type IScope = {
}

export type GroupRights = {
perimeter_id: string
care_site_id: number
provider_id: string
care_site_history_ids: number[]
access_ids: number[]
right_read_patient_nominative: boolean
right_read_patient_pseudo_anonymised: boolean
right_search_patient_with_ipp: boolean
right_export_csv_nominative: boolean
right_export_csv_pseudo_anonymised: boolean
right_transfer_jupyter_nominative: boolean
right_transfer_jupyter_pseudo_anonymised: boolean
export_csv_nomi?: boolean
export_csv_pseudo?: boolean
export_jupyter_nomi?: boolean
Expand Down

0 comments on commit 8c6a656

Please sign in to comment.