From 8c6a656ebc184971f7dfd463bafe1ad648486c10 Mon Sep 17 00:00:00 2001 From: Thicham Date: Thu, 14 Dec 2023 10:19:56 +0100 Subject: [PATCH] fix: make changes for rights routes following backend refacto (#906) --- .../ProjectsTable/VersionRow/index.tsx | 56 +++++++++---------- src/services/aphp/callApi.ts | 2 +- src/services/aphp/servicePerimeters.ts | 12 ++-- src/types.ts | 16 +----- 4 files changed, 34 insertions(+), 52 deletions(-) diff --git a/src/components/Requests/ProjectsTable/VersionRow/index.tsx b/src/components/Requests/ProjectsTable/VersionRow/index.tsx index 794ca8be2..1e50b5687 100644 --- a/src/components/Requests/ProjectsTable/VersionRow/index.tsx +++ b/src/components/Requests/ProjectsTable/VersionRow/index.tsx @@ -77,50 +77,46 @@ const VersionRow: React.FC<{ requestId: string; cohortsList: Cohort[] }> = ({ re {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 ( - + - {historyRow.fhir_group_id ? ( - navigate(`/cohort/${historyRow.fhir_group_id}`)} underline="hover"> - {historyRow.name} + {cohort.fhir_group_id ? ( + navigate(`/cohort/${cohort.fhir_group_id}`)} underline="hover"> + {cohort.name} ) : ( - {historyRow.name} + {cohort.name} )} - _handleEditCohort(historyRow)} - > + _handleEditCohort(cohort)}> - onSetCohortFavorite(historyRow)}> - + onSetCohortFavorite(cohort)}> + - {historyRow.fhir_group_id ? ( + {cohort.fhir_group_id ? ( - ) : historyRow.request_job_status === JobStatus.pending || - historyRow.request_job_status === JobStatus.new ? ( + ) : cohort.request_job_status === JobStatus.pending || + cohort.request_job_status === JobStatus.new ? ( - ) : historyRow.request_job_fail_msg ? ( - + ) : cohort.request_job_fail_msg ? ( + ) : ( @@ -130,23 +126,21 @@ const VersionRow: React.FC<{ requestId: string; cohortsList: Cohort[] }> = ({ re 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]} - {displayDigit(historyRow.result_size)} + {displayDigit(cohort.result_size)} - {moment(historyRow.modified_at).format('DD/MM/YYYY [à] HH:mm')} + {moment(cohort.modified_at).format('DD/MM/YYYY [à] HH:mm')} setSelectedExportableCohort(historyRow.fhir_group_id ?? '') - : () => null + canExportThisCohort ? () => setSelectedExportableCohort(cohort.fhir_group_id ?? '') : () => null } > diff --git a/src/services/aphp/callApi.ts b/src/services/aphp/callApi.ts index e7bf75d2b..51a6ee06b 100644 --- a/src/services/aphp/callApi.ts +++ b/src/services/aphp/callApi.ts @@ -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 = await apiBackend.get(`${url}${options.reduce(paramsReducer)}`, { signal: signal }) diff --git a/src/services/aphp/servicePerimeters.ts b/src/services/aphp/servicePerimeters.ts index 5f92abad0..9bd05deac 100644 --- a/src/services/aphp/servicePerimeters.ts +++ b/src/services/aphp/servicePerimeters.ts @@ -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 } }) @@ -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 = { @@ -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) => { diff --git a/src/types.ts b/src/types.ts index 99e79cfe7..5f2d5046d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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 } @@ -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