Skip to content

Commit

Permalink
refactor: remove some any types + add some function typing
Browse files Browse the repository at this point in the history
* refactor(serviceCohorts): remove type any

* refactor: add simple status type

* refactor: add some return type on utils functions

* refactor: add some more types

* refactor: some more typing

* build: disable eslint any check

* fix: fix secure type into populationCard.tsx

---------

Co-authored-by: Salah-BOUYAHIA <salah.bouyahia-ext@aphp.fr>
  • Loading branch information
pl-buiquang and Mehdi-BOUYAHIA authored May 30, 2023
1 parent f791547 commit 6b15bfc
Show file tree
Hide file tree
Showing 51 changed files with 350 additions and 318 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
],
"react/no-unknown-property": 0,
"react/prop-types": 0,
// TODO set this rule to 2 and fix all the errors
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/camelcase": 0,
"@typescript-eslint/explicit-function-return-type": 0,
Expand Down
26 changes: 13 additions & 13 deletions src/components/CreationCohort/ControlPanel/ControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
} from 'state/cohortCreation'
import { MeState } from 'state/me'

import { RequestType } from 'types'
import { CohortCreationCounterType, RequestType, SimpleStatus } from 'types'

import useStyle from './styles'

Expand All @@ -50,11 +50,11 @@ const ControlPanel: React.FC<{
const classes = useStyle()
const dispatch = useAppDispatch()
const [openModal, onSetOpenModal] = useState<'executeCohortConfirmation' | null>(null)
const [oldCount, setOldCount] = useState<any | null>(null)
const [oldCount, setOldCount] = useState<CohortCreationCounterType | null>(null)
const [openShareRequestModal, setOpenShareRequestModal] = useState<boolean>(false)
const [shareSuccessOrFailMessage, setShareSuccessOrFailMessage] = useState<'success' | 'error' | null>(null)
const [shareSuccessOrFailMessage, setShareSuccessOrFailMessage] = useState<SimpleStatus>(null)
const wrapperSetShareSuccessOrFailMessage = useCallback(
(val: any) => {
(val: SimpleStatus) => {
setShareSuccessOrFailMessage(val)
},
[setShareSuccessOrFailMessage]
Expand Down Expand Up @@ -94,7 +94,7 @@ const ControlPanel: React.FC<{
selectedPopulation === null
? null
: selectedPopulation
.map((population: any) => population && population.access)
.map((population) => population && population.access)
.filter((elem) => elem && elem === 'Pseudonymisé').length > 0

const checkIfLogicalOperatorIsEmpty = () => {
Expand Down Expand Up @@ -258,18 +258,18 @@ const ControlPanel: React.FC<{
<Grid container alignItems="center" style={{ width: 'fit-content' }}>
<Typography className={clsx(classes.boldText, classes.patientTypo, classes.blueText)}>
{includePatient !== undefined && includePatient !== null ? displayDigit(includePatient) : '-'}
{oldCount !== null
? (includePatient ?? 0) - oldCount?.includePatient > 0
? ` (+${(includePatient ?? 0) - oldCount?.includePatient})`
: ` (${(includePatient ?? 0) - oldCount?.includePatient})`
{oldCount !== null && !!oldCount.includePatient
? (includePatient ?? 0) - oldCount.includePatient > 0
? ` (+${(includePatient ?? 0) - oldCount.includePatient})`
: ` (${(includePatient ?? 0) - oldCount.includePatient})`
: ''}
</Typography>
{oldCount !== null && (
{oldCount !== null && !!oldCount.includePatient && (
<Tooltip
title={`Le delta ${
(includePatient ?? 0) - oldCount?.includePatient > 0
? ` (+${(includePatient ?? 0) - oldCount?.includePatient})`
: ` (${(includePatient ?? 0) - oldCount?.includePatient})`
(includePatient ?? 0) - oldCount.includePatient > 0
? ` (+${(includePatient ?? 0) - oldCount.includePatient})`
: ` (${(includePatient ?? 0) - oldCount.includePatient})`
} est la différence de patient entre le ${lastUpdatedOldCount?.format(
'DD/MM/YYYY'
)} et la date du jour.`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { DocType, SearchByTypes, SelectedCriteriaType } from 'types'
import docTypes from 'assets/docTypes.json'

import useStyles from './styles'
import { ReactJSXElement } from '@emotion/react/types/jsx-namespace'

type CriteriaCardContentProps = {
currentCriteria: SelectedCriteriaType
Expand All @@ -23,7 +24,7 @@ type CriteriaCardContentProps = {
const CriteriaCardContent: React.FC<CriteriaCardContentProps> = ({ currentCriteria }) => {
const _displayCardContent = (_currentCriteria: SelectedCriteriaType) => {
if (!_currentCriteria) return []
let content: any[] = []
let content: Array<ReactJSXElement | string | number | boolean | null> = []

const reducer = (accumulator: any, currentValue: any) =>
accumulator ? `${accumulator} - ${currentValue}` : currentValue ? currentValue : accumulator
Expand All @@ -42,7 +43,7 @@ const CriteriaCardContent: React.FC<CriteriaCardContentProps> = ({ currentCriter
)

let _data: any = null
const _searchDataFromCriteria = (_criteria: any[], type: string) => {
const _searchDataFromCriteria = (_criteria: CriteriaItemType[], type: string) => {
for (const _criterion of _criteria) {
if (_criterion.id === 'Medication' && ('MedicationRequest' === type || 'MedicationAdministration' === type)) {
_data = _criterion.data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const OperatorItem: React.FC<OperatorItemProps> = ({

const displayingItem = criteriaGroup.filter((_criteriaGroup: CriteriaGroupType) => _criteriaGroup.id === itemId)

let timeout: any = null
let timeout: NodeJS.Timeout | null = null

const [isExpanded, onExpand] = useState(false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const LogicalOperatorItem: React.FC<LogicalOperatorItemProps> = ({ itemId }) =>
const classes = useStyles()
const dispatch = useAppDispatch()

let timeout: any = null
let timeout: NodeJS.Timeout | null = null

const isMainOperator = itemId === 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const PopulationCard: React.FC = () => {
if (_selectedPopulations === null) return

_selectedPopulations = filterScopeTree(_selectedPopulations)
if (_selectedPopulations === null) return
_selectedPopulations = _selectedPopulations.map((_selectedPopulation: ScopeTreeRow) => ({
..._selectedPopulation,
subItems: []
Expand Down Expand Up @@ -118,8 +119,8 @@ const PopulationCard: React.FC = () => {
{isExtended ? (
<>
{selectedPopulation &&
selectedPopulation.map((pop: any, index: number) => (
<Chip className={classes.populationChip} key={`${index}-${pop.name}`} label={pop.name} />
selectedPopulation.map((pop, index: number) => (
<Chip className={classes.populationChip} key={`${index}-${pop?.name}`} label={pop?.name} />
))}
<IconButton
size="small"
Expand All @@ -133,7 +134,7 @@ const PopulationCard: React.FC = () => {
{selectedPopulation &&
selectedPopulation
.slice(0, 4)
.map((pop: any, index: number) =>
.map((pop, index: number) =>
pop ? (
<Chip className={classes.populationChip} key={`${index}-${pop.name}`} label={pop.name} />
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const columns = [
}
]

const EventSequenceTable: React.FC<{ temporalConstraints: TemporalConstraintsType[]; onChangeConstraints: any }> = ({
temporalConstraints,
onChangeConstraints
}) => {
const EventSequenceTable: React.FC<{
temporalConstraints: TemporalConstraintsType[]
onChangeConstraints: (c: TemporalConstraintsType[]) => void
}> = ({ temporalConstraints, onChangeConstraints }) => {
const { selectedCriteria } = useAppSelector((state) => state.cohortCreation.request)

const classes = useStyles()
Expand All @@ -60,12 +60,12 @@ const EventSequenceTable: React.FC<{ temporalConstraints: TemporalConstraintsTyp
onChangeConstraints(remainingConstraints)
}

const findCriteriaTitle = (id: any) => {
const findCriteriaTitle = (id: number | 'All') => {
const criteria = selectedCriteria.find((criteria) => criteria.id === id)
return criteria?.title
}

const durationMeasurementInFrench = (key: any) => {
const durationMeasurementInFrench = (key: string) => {
let keyInFrench
if (key === 'days') {
keyInFrench = 'jour(s)'
Expand All @@ -81,9 +81,9 @@ const EventSequenceTable: React.FC<{ temporalConstraints: TemporalConstraintsTyp
return keyInFrench
}

const storeNonZeroMinDuration = (temporalConstraint: any) => {
const storeNonZeroMinDuration = (temporalConstraint: TemporalConstraintsType) => {
const minDuration = temporalConstraint.timeRelationMinDuration
let nonZeroMinDuration: any = {}
let nonZeroMinDuration: { keys?: string; values?: number } = {}

if (temporalConstraint.constraintType === 'directChronologicalOrdering' && minDuration) {
for (const [key, value] of Object.entries(minDuration)) {
Expand All @@ -100,9 +100,9 @@ const EventSequenceTable: React.FC<{ temporalConstraints: TemporalConstraintsTyp
return nonZeroMinDuration
}

const storeNonZeroMaxDuration = (temporalConstraint: any) => {
const storeNonZeroMaxDuration = (temporalConstraint: TemporalConstraintsType) => {
const maxDuration = temporalConstraint.timeRelationMaxDuration
let nonZeroMaxDuration: any = {}
let nonZeroMaxDuration: { keys?: string; values?: number } = {}

if (temporalConstraint.constraintType === 'directChronologicalOrdering' && maxDuration) {
for (const [key, value] of Object.entries(maxDuration)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
InputLabel,
MenuItem,
Select,
SelectChangeEvent,
Typography
} from '@mui/material'

Expand Down Expand Up @@ -41,7 +42,7 @@ const timeMeasurements = [

const TemporalConstraintConfig: React.FC<{
newConstraintsList: TemporalConstraintsType[]
onChangeNewConstraintsList: any
onChangeNewConstraintsList: (c: TemporalConstraintsType[]) => void
}> = ({ newConstraintsList, onChangeNewConstraintsList }) => {
const classes = useStyles()

Expand Down Expand Up @@ -92,13 +93,13 @@ const TemporalConstraintConfig: React.FC<{
const selectableCriteria1 = getSelectableCriteria(secondCriteriaValue)
const selectableCriteria2 = getSelectableCriteria(firstCriteriaValue)

const onChangeMinTimeMeasurement = (event: React.ChangeEvent<{ value: any }>) => {
setMinTimeMeasurement(event.target.value as string)
const onChangeMinTimeMeasurement = (event: SelectChangeEvent) => {
setMinTimeMeasurement(event.target.value)
setMinTime(1)
}

const onChangeMaxTimeMeasurement = (event: React.ChangeEvent<{ value: any }>) => {
setMaxTimeMeasurement(event.target.value as string)
const onChangeMaxTimeMeasurement = (event: SelectChangeEvent) => {
setMaxTimeMeasurement(event.target.value)
setMaxTime(1)
}

Expand Down Expand Up @@ -239,7 +240,7 @@ const TemporalConstraintConfig: React.FC<{
<Select
disabled={!isFirstTimeValueChecked}
value={minTimeMeasurement}
onChange={onChangeMinTimeMeasurement as any}
onChange={onChangeMinTimeMeasurement}
error={incorrectTimingError}
variant="standard"
>
Expand Down Expand Up @@ -274,7 +275,7 @@ const TemporalConstraintConfig: React.FC<{
<Select
disabled={!isSecondTimeValueChecked}
value={maxTimeMeasurement}
onChange={onChangeMaxTimeMeasurement as any}
onChange={onChangeMaxTimeMeasurement}
error={incorrectTimingError}
variant="standard"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const TemporalConstraint: React.FC<{
<RadioGroup
row
value={radioValues}
onChange={(e: any) => onChangeValue(e.target.value)}
onChange={(e) => onChangeValue(e.target.value as unknown as TemporalConstraintsType['constraintType'])}
style={{ margin: '1em', justifyContent: 'space-around' }}
>
<FormControlLabel value="none" control={<Radio />} label="Aucune contrainte sur les séjours" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const ModalCohortTitle: React.FC<{
<TextField
placeholder="Nom de la cohorte"
value={title}
onChange={(e: any) => onChangeTitle(e.target.value)}
onChange={(e) => onChangeTitle(e.target.value)}
autoFocus
id="title"
margin="normal"
Expand All @@ -77,7 +77,7 @@ const ModalCohortTitle: React.FC<{
<TextField
placeholder="Description"
value={description}
onChange={(e: any) => onChangeDescription(e.target.value)}
onChange={(e) => onChangeDescription(e.target.value)}
id="description"
margin="normal"
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const RequestForm: React.FC<RequestFormProps> = ({
<TextField
placeholder="Nom de la requête"
value={currentRequest.name}
onChange={(e: any) => onChangeValue('name', e.target.value)}
onChange={(e) => onChangeValue('name', e.target.value)}
autoFocus
id="title"
margin="normal"
Expand Down Expand Up @@ -76,7 +76,7 @@ const RequestForm: React.FC<RequestFormProps> = ({
<TextField
placeholder="Nom du nouveau projet"
value={projectName}
onChange={(e: any) => onChangeProjectName(e.target.value)}
onChange={(e) => onChangeProjectName(e.target.value)}
id="project_name"
margin="normal"
fullWidth
Expand All @@ -90,7 +90,7 @@ const RequestForm: React.FC<RequestFormProps> = ({
<TextField
placeholder="Description"
value={currentRequest.description}
onChange={(e: any) => onChangeValue('description', e.target.value)}
onChange={(e) => onChangeValue('description', e.target.value)}
id="description"
margin="normal"
fullWidth
Expand Down
6 changes: 3 additions & 3 deletions src/components/DataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const DataTable: React.FC<DataTableProps> = ({
}) => {
const classes = useStyles()

const createSortHandler = (property: any) => () => {
const createSortHandler = (property: string) => () => {
if (setOrder) {
const isAsc: boolean = order?.orderBy === property && order?.orderDirection === 'asc'
const _orderDirection = isAsc ? 'desc' : 'asc'
Expand Down Expand Up @@ -72,7 +72,7 @@ const DataTable: React.FC<DataTableProps> = ({
<TableSortLabel
active={order?.orderBy === column.code}
direction={order?.orderBy === column.code ? order?.orderDirection : 'asc'}
onClick={createSortHandler(column.code)}
onClick={createSortHandler(column.code || '')}
>
{column.label}
</TableSortLabel>
Expand All @@ -91,7 +91,7 @@ const DataTable: React.FC<DataTableProps> = ({
className={classes.multiple}
active={order?.orderBy === subColumn.code}
direction={order?.orderBy === subColumn.code ? order?.orderDirection : 'asc'}
onClick={createSortHandler(subColumn.code)}
onClick={createSortHandler(subColumn.code || '')}
>
{subColumn.label}
</TableSortLabel>
Expand Down
2 changes: 1 addition & 1 deletion src/components/DataTable/DataTableMedication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const DataTableMedicationLine: React.FC<{

const prescriptionType =
medication.resourceType === 'MedicationRequest' &&
(medication.extension?.find((extension: any) => extension.url === 'type') || {}).valueString
(medication.extension?.find((extension) => extension.url === 'type') || {}).valueString
const administrationRoute =
medication.resourceType === 'MedicationRequest'
? medication.dosageInstruction?.[0]?.route?.text
Expand Down
6 changes: 3 additions & 3 deletions src/components/DataTable/DataTableObservation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ const DataTableObservationLine: React.FC<{

const nda = observation.NDA
const date = observation.effectiveDateTime
const libelleANABIO = observation.code?.coding?.find((code: any) => code.id === 'CODE ANABIO')?.display
const codeLOINC = observation.code?.coding?.find((code: any) => code.id === 'CODE LOINC')?.code
const libelleLOINC = observation.code?.coding?.find((code: any) => code.id === 'CODE LOINC')?.display
const libelleANABIO = observation.code?.coding?.find((code) => code.id === 'CODE ANABIO')?.display
const codeLOINC = observation.code?.coding?.find((code) => code.id === 'CODE LOINC')?.code
const libelleLOINC = observation.code?.coding?.find((code) => code.id === 'CODE LOINC')?.display
const result = observation.valueQuantity
? observation.valueQuantity.code
? observation.valueQuantity.code
Expand Down
3 changes: 2 additions & 1 deletion src/components/ErrorView/styles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Theme } from '@mui/material'
import { makeStyles } from '@mui/styles'
import { smallDrawerWidth, largeDrawerWidth } from 'components/Routes/LeftSideBar/LeftSideBar'

export default makeStyles((theme: any) => ({
export default makeStyles((theme: Theme) => ({
appBar: {
height: '100vh',
marginLeft: smallDrawerWidth,
Expand Down
2 changes: 1 addition & 1 deletion src/components/MasterChips/MasterChips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import useStyles from './styles'
export type MasterChipsProps = {
chips: {
label: string
onDelete?: (id?: any) => void
onDelete?: () => void
}[]
}
const MasterChips: React.FC<MasterChipsProps> = ({ chips }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom'

import { Dialog, DialogTitle, DialogContent, DialogActions, Button, Grid, CircularProgress } from '@mui/material'

import { RequestType, Provider } from 'types'
import { RequestType, Provider, SimpleStatus } from 'types'

import { useAppSelector } from 'state'
import { RequestState } from 'state/request'
Expand All @@ -17,8 +17,8 @@ const ERROR_USER_SHARE_LIST = 'error_user_share_list'

const ModalShareRequest: React.FC<{
requestShare?: RequestType | null
shareSuccessOrFailMessage?: 'success' | 'error' | null
parentStateSetter: (val: any) => void
shareSuccessOrFailMessage?: SimpleStatus
parentStateSetter: (val: SimpleStatus) => void
onClose: () => void
}> = ({ requestShare, onClose, parentStateSetter }) => {
const { requestState } = useAppSelector<{ requestState: RequestState }>((state) => ({ requestState: state.request }))
Expand All @@ -31,7 +31,7 @@ const ModalShareRequest: React.FC<{
const [currentRequest, setCurrentRequest] = useState<RequestType | null | undefined>(selectedCurrentRequest)
const [currentUserToShare, setCurrentUserToShare] = useState<Provider[] | null>(null)
const [error, setError] = useState<'error_title' | 'error_user_share_list' | null>(null)
const [shareMessage, setShareMessage] = useState<'success' | 'error' | null>(null)
const [shareMessage, setShareMessage] = useState<SimpleStatus>(null)

useEffect(() => {
parentStateSetter(shareMessage)
Expand Down
Loading

0 comments on commit 6b15bfc

Please sign in to comment.