Skip to content

Commit

Permalink
refactor: change 'any' types (#952)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentGouyon authored and Mehdi-BOUYAHIA committed Feb 29, 2024
1 parent 510ef7f commit eb2e975
Show file tree
Hide file tree
Showing 15 changed files with 351 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const PopulationCard: React.FC<PopulationCardPropsType> = (props) => {
const selectionAndPopulationWithRightError = [...selectedItems, ...populationWithRightError]

const _onChangePopulation = async (selectedPopulations: ScopeTreeRow[]) => {
dispatch<any>(buildCohortCreation({ selectedPopulation: selectedPopulations }))
dispatch(buildCohortCreation({ selectedPopulation: selectedPopulations }))
}

const setUpdatedItems = (updatedSelection: ScopeTreeRow[]) => {
Expand Down
5 changes: 3 additions & 2 deletions src/components/Dashboard/ExportModal/ExportModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useEffect, useRef } from 'react'
import { isAxiosError } from 'axios'

import {
Accordion,
Expand Down Expand Up @@ -139,8 +140,8 @@ const ExportModal: React.FC<ExportModalProps> = ({ cohortId, open, handleClose }
tables: settings?.tables
})

if (response && response.error) {
setExportResponse({ status: 'error', detail: response.error.detail })
if (isAxiosError(response)) {
setExportResponse({ status: 'error', detail: response.message })
} else {
setExportResponse({ status: 'finish', detail: '' })
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Filters/MedicationFilters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ const MedicationFilters: React.FC<MedicationFiltersProps> = ({
const { classes } = useStyles()

const [_nda, setNda] = useState<string>(filters.nda)
const [_startDate, setStartDate] = useState<any>(filters.startDate)
const [_endDate, setEndDate] = useState<any>(filters.endDate)
const [_startDate, setStartDate] = useState<string | null>(filters.startDate)
const [_endDate, setEndDate] = useState<string | null>(filters.endDate)
const [_selectedPrescriptionTypes, setSelectedPrescriptionTypes] = useState<any[]>(filters.selectedPrescriptionTypes)
const [_selectedAdministrationRoutes, setSelectedAdministrationRoutes] = useState<any[]>(
filters.selectedAdministrationRoutes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { Autocomplete, CircularProgress, TextField } from '@mui/material'

import { displaySystem } from 'utils/displayValueSetSystem'

import { ValueSetSystem } from 'types'
import { cancelPendingRequest } from 'utils/abortController'

interface ElementType {
id: string
label: string
system: ValueSetSystem
system?: string
}

type InputAutocompleteAsyncProps = {
Expand All @@ -23,7 +22,7 @@ type InputAutocompleteAsyncProps = {
onChange?: (e: any, value: any) => void
renderInput?: any
autocompleteOptions?: ElementType[]
getAutocompleteOptions?: (searchValue: string, signal: AbortSignal) => Promise<any>
getAutocompleteOptions?: (searchValue: string, signal: AbortSignal) => Promise<ElementType[]>
noOptionsText?: string
helperText?: string
}
Expand Down Expand Up @@ -93,7 +92,7 @@ const InputAutocompleteAsync: FC<InputAutocompleteAsyncProps> = (props) => {
onChange={onChange}
options={options ?? []}
isOptionEqualToValue={(option, value) => option.id === value.id}
getOptionLabel={(option) => `${displaySystem(option.system)}${option.label} `}
getOptionLabel={(option) => `${displaySystem(option?.system)}${option.label} `}
renderInput={(params) => (
<TextField
{...params}
Expand Down
2 changes: 1 addition & 1 deletion src/services/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export interface IServiceCohorts {
cohortId: number
motivation: string
tables: string[]
}) => Promise<any>
}) => Promise<Export>
}
```

Expand Down
257 changes: 129 additions & 128 deletions src/services/aphp/callApi.ts

Large diffs are not rendered by default.

26 changes: 18 additions & 8 deletions src/services/aphp/serviceCohortCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { AxiosResponse } from 'axios'
import apiBack from '../apiBackend'

import {
Cohort,
CountCohort,
DatedMeasure,
FetchRequest,
HierarchyElement,
HierarchyElementWithSystem,
QuerySnapshotInfo,
Expand Down Expand Up @@ -52,12 +55,17 @@ export interface IServiceCohortCreation {
cohortName?: string,
cohortDescription?: string,
globalCount?: boolean
) => Promise<any>
) => Promise<AxiosResponse<Cohort> | null>

/**
* Cette fonction permet de récupérer le count d'une requête
*/
countCohort: (requeteurJson?: string, snapshotId?: string, requestId?: string, uuid?: string) => Promise<any>
countCohort: (
requeteurJson?: string,
snapshotId?: string,
requestId?: string,
uuid?: string
) => Promise<CountCohort | null>

/**
* Cette fonction permet de créer un état de `snapshot` pour l'historique d'une requête
Expand All @@ -72,7 +80,7 @@ export interface IServiceCohortCreation {
/**
* Permet de récupérer toutes les informations utiles pour l'utilisation du requeteur
*/
fetchRequest: (requestId: string, snapshotId?: string) => Promise<any>
fetchRequest: (requestId: string, snapshotId?: string) => Promise<FetchRequest>

fetchSnapshot: (snapshotId: string) => Promise<Snapshot>

Expand Down Expand Up @@ -132,7 +140,7 @@ const servicesCohortCreation: IServiceCohortCreation = {
if (!requeteurJson || !datedMeasureId || !snapshotId || !requestId) return null
if (globalCount === undefined) globalCount = false

const cohortResult = await apiBack.post('/cohort/cohorts/', {
const cohortResult = await apiBack.post<Cohort>('/cohort/cohorts/', {
dated_measure_id: datedMeasureId,
request_query_snapshot_id: snapshotId,
request_id: requestId,
Expand All @@ -157,7 +165,7 @@ const servicesCohortCreation: IServiceCohortCreation = {
byrequest: 0,
count_outdated: measureResult?.data?.count_outdated,
shortCohortLimit: measureResult?.data?.cohort_limit
}
} as CountCohort
} else {
if (!requeteurJson || !snapshotId || !requestId) return null

Expand All @@ -172,7 +180,7 @@ const servicesCohortCreation: IServiceCohortCreation = {
uuid: measureResult?.data?.uuid,
count_outdated: measureResult?.data?.count_outdated,
shortCohortLimit: measureResult?.data?.cohort_limit
}
} as CountCohort
}
},

Expand Down Expand Up @@ -224,7 +232,9 @@ const servicesCohortCreation: IServiceCohortCreation = {
// clean Global count
currentSnapshot = {
...currentSnapshot,
dated_measures: currentSnapshot.dated_measures.filter((dated_measure: any) => dated_measure.mode !== 'Global')
dated_measures: currentSnapshot.dated_measures.filter(
(dated_measure: DatedMeasure) => dated_measure.mode !== 'Global'
)
}

shortCohortLimit =
Expand All @@ -242,7 +252,7 @@ const servicesCohortCreation: IServiceCohortCreation = {
count: currentSnapshot ? currentSnapshot.dated_measures[0] : {},
shortCohortLimit,
count_outdated
}
} as FetchRequest
return result
},

Expand Down
87 changes: 38 additions & 49 deletions src/services/aphp/serviceCohorts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
DocumentsData,
ImagingData,
CohortImaging,
CohortComposition
CohortComposition,
Export
} from 'types'
import {
getGenderRepartitionMapAphp,
Expand All @@ -32,8 +33,8 @@ import {
} from './callApi'

import apiBackend from '../apiBackend'
import { Binary, DocumentReference, Extension, ParametersParameter, Patient } from 'fhir/r4'
import { CanceledError } from 'axios'
import { Binary, DocumentReference, Extension, ImagingStudy, ParametersParameter, Patient } from 'fhir/r4'
import { AxiosError, AxiosResponse, CanceledError, isAxiosError } from 'axios'
import {
VitalStatus,
SearchCriterias,
Expand Down Expand Up @@ -139,7 +140,7 @@ export interface IServiceCohorts {
},
groupId?: string,
signal?: AbortSignal
) => Promise<DocumentsData> | Promise<SearchInputError> | Promise<CanceledError<any>>
) => Promise<DocumentsData> | Promise<SearchInputError>

/**
* Retourne la liste d'objets d'Imagerie liés à une cohorte
Expand All @@ -153,7 +154,7 @@ export interface IServiceCohorts {
},
groupId?: string,
signal?: AbortSignal
) => Promise<ImagingData> | Promise<CanceledError<any>>
) => Promise<ImagingData>

/**
* Permet de vérifier si le champ de recherche textuelle est correct
Expand Down Expand Up @@ -207,7 +208,11 @@ export interface IServiceCohorts {
* - motivation: Raison de l'export
* - tables: Liste de tables demandées dans l'export
*/
createExport: (args: { cohortId: number; motivation: string; tables: string[] }) => Promise<any>
createExport: (args: {
cohortId: number
motivation: string
tables: string[]
}) => Promise<AxiosResponse<Export> | AxiosError>
}

const servicesCohorts: IServiceCohorts = {
Expand Down Expand Up @@ -259,32 +264,29 @@ const servicesCohorts: IServiceCohorts = {
const agePyramidData =
patientsResp.data.resourceType === 'Bundle'
? getAgeRepartitionMapAphp(
patientsResp.data.meta?.extension?.find((facet: any) => facet.url === ChartCode.agePyramid)?.extension
patientsResp.data.meta?.extension?.find((facet) => facet.url === ChartCode.agePyramid)?.extension
)
: undefined

const genderRepartitionMap =
patientsResp.data.resourceType === 'Bundle'
? getGenderRepartitionMapAphp(
patientsResp.data.meta?.extension?.find((facet: any) => facet.url === ChartCode.genderRepartition)
?.extension
patientsResp.data.meta?.extension?.find((facet) => facet.url === ChartCode.genderRepartition)?.extension
)
: undefined

const monthlyVisitData =
encountersResp.data.resourceType === 'Bundle'
? getVisitRepartitionMapAphp(
encountersResp.data.meta?.extension?.find((facet: any) => facet.url === ChartCode.monthlyVisits)
?.extension
encountersResp.data.meta?.extension?.find((facet) => facet.url === ChartCode.monthlyVisits)?.extension
)
: undefined

const visitTypeRepartitionData =
encountersResp.data.resourceType === 'Bundle'
? getEncounterRepartitionMapAphp(
encountersResp.data.meta?.extension?.find(
(facet: Extension) => facet.url === ChartCode.visitTypeRepartition
)?.extension
encountersResp.data.meta?.extension?.find((facet) => facet.url === ChartCode.visitTypeRepartition)
?.extension
)
: undefined

Expand Down Expand Up @@ -440,7 +442,12 @@ const servicesCohorts: IServiceCohorts = {
])

const imagingList = getApiResponseResources(imagingResponse) ?? []
const completeImagingList = (await getResourceInfos(imagingList, deidentified, groupId, signal)) as CohortImaging[]
const completeImagingList = await getResourceInfos<ImagingStudy, CohortImaging>(
imagingList,
deidentified,
groupId,
signal
)

const totalImaging = imagingResponse.data?.resourceType === 'Bundle' ? imagingResponse.data?.total : 0
const totalAllImaging =
Expand Down Expand Up @@ -529,12 +536,12 @@ const servicesCohorts: IServiceCohorts = {
: totalPatientDocs

const documentsList = getApiResponseResources(docsList) ?? []
const filledDocumentsList = (await getResourceInfos(
const filledDocumentsList = await getResourceInfos<DocumentReference, CohortComposition>(
documentsList,
deidentified,
groupId,
signal
)) as CohortComposition[]
)

return {
totalDocs: totalDocs ?? 0,
Expand Down Expand Up @@ -619,18 +626,18 @@ const servicesCohorts: IServiceCohorts = {
return documentBinaries && documentBinaries.length > 0 ? documentBinaries[0] : undefined
},

fetchCohortsRights: async (cohorts) => {
fetchCohortsRights: async (cohorts): Promise<Cohort[]> => {
try {
const ids = cohorts
.map((cohort) => cohort.fhir_group_id)
.filter((id) => id !== undefined || id !== '')
.filter((i) => i !== '') as string[]
.filter((i): i is string => i !== '')
if (ids.length === 0) return []
const rightsResponse = await fetchCohortAccesses(ids)
return cohorts.map((cohort) => {
return {
...cohort,
rights: rightsResponse.data.find((right: any) => right.cohort_id == cohort.fhir_group_id)?.rights
rights: rightsResponse.data.find((right) => right.cohort_id == cohort.fhir_group_id)?.rights
}
})
} catch (error) {
Expand All @@ -639,40 +646,22 @@ const servicesCohorts: IServiceCohorts = {
}
},

createExport: async (args) => {
createExport: async (args): Promise<AxiosResponse<Export> | AxiosError> => {
try {
const { cohortId, motivation, tables } = args

const exportResponse = await new Promise((resolve) => {
resolve(
apiBackend.post('/exports/', {
cohort_id: cohortId,
motivation,
tables: tables.map((table: string) => ({
omop_table_name: table
})),
nominative: true, // Nominative should always be true when exporting a CSV (see issue #1113)
output_format: 'csv'
})
)
return await apiBackend.post<Export>('/exports/', {
cohort_id: cohortId,
motivation,
tables: tables.map((table) => ({
omop_table_name: table
})),
nominative: true, // Nominative should always be true when exporting a CSV (see issue #1113)
output_format: 'csv'
})
.then((values) => {
return values
})
.catch((error) => {
return error
})

// @ts-ignore
if (exportResponse && exportResponse && exportResponse.status !== 201) {
// @ts-ignore
return { error: exportResponse && exportResponse.response.data }
} else {
// @ts-ignore
return exportResponse && exportResponse.data
}
} catch (error) {
return { error }
if (isAxiosError(error)) return error
else throw error
}
}
}
Expand Down
Loading

0 comments on commit eb2e975

Please sign in to comment.