Skip to content

Commit

Permalink
fix: misc sonar fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pl-buiquang committed Dec 5, 2024
1 parent e277129 commit 4a5f502
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 56 deletions.
52 changes: 26 additions & 26 deletions src/__tests__/cohortCreation/cohortCreation.test.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { comparatorToFilter, parseOccurence } from 'utils/valueComparator'
import services from 'services/aphp'
import { Hierarchy } from 'types/hierarchy'
import { DataTypes, FhirKey, NewDurationRangeType, NumberAndComparatorDataType } from '../types'
import { b } from 'vitest/dist/chunks/suite.CcK46U-P'

/************************************************************************************/
/* Criteria Form Item Mappers */
Expand Down Expand Up @@ -248,7 +247,7 @@ const parseDocumentAttachment = (value: string) => {
documentAttachment.documentAttachmentMethod = value
} else if (value.startsWith(DocumentAttachmentMethod.INFERENCE_TEMPOREL)) {
documentAttachment.documentAttachmentMethod = DocumentAttachmentMethod.INFERENCE_TEMPOREL
const matchNumber = value.match(/\d+/)
const matchNumber = /\d+/.exec(value)
if (matchNumber) {
documentAttachment.daysOfDelay = matchNumber[0]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import React from 'react'
import { ValueSetStore } from 'state/valueSets'
import {
AutoCompleteItem,
Expand All @@ -9,7 +8,7 @@ import {
NewDurationRangeType,
NumberAndComparatorDataType
} from '../types'
import { ReactNode } from 'react'
import React, { ReactNode } from 'react'
import {
DocumentAttachmentMethod,
DocumentAttachmentMethodLabel,
Expand All @@ -24,7 +23,6 @@ import allDocTypes from 'assets/docTypes.json'
import moment from 'moment'
import { getDurationRangeLabel } from 'utils/age'
import { getConfig } from 'config'
import { prepend } from 'ramda'

/************************************************************************************/
/* Criteria Form Item Chip Display */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import extractFilterParams, { FhirFilter } from 'utils/fhirFilterParser'
import { CriteriaItemType } from 'types'
import { ValueSetStore } from 'state/valueSets'
import { ReactNode } from 'react'
import { isArray, isFunction, isObject, isString } from 'lodash'
import { isArray, isFunction, isString } from 'lodash'
import { BUILD_MAPPERS, BuilderMethod, UNBUILD_MAPPERS } from './buildMappers'

/************************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,13 @@ const FORM_ITEM_RENDERER: { [key in CriteriaFormItemType]: CriteriaFormItemView<
value={props.value}
onChange={(e, value) => props.updateData(value)}
>
{props.definition.choices.map((choice, index) => (
<FormControlLabel key={index} value={choice.id} control={<Radio color="secondary" />} label={choice.label} />
{props.definition.choices.map((choice) => (
<FormControlLabel
key={choice.id}
value={choice.id}
control={<Radio color="secondary" />}
label={choice.label}
/>
))}
</RadioGroup>
)
Expand Down Expand Up @@ -248,7 +253,7 @@ const FORM_ITEM_RENDERER: { [key in CriteriaFormItemType]: CriteriaFormItemView<
return (
<BlockWrapper container alignItems="center">
<CriteriaLabel
label={props.definition.label || ''}
label={props.definition.label ?? ''}
infoIcon={props.definition.extraInfo}
style={{ padding: 0 }}
>
Expand Down Expand Up @@ -282,7 +287,7 @@ const FORM_ITEM_RENDERER: { [key in CriteriaFormItemType]: CriteriaFormItemView<
)
return (
<AsyncAutocomplete
label={props.definition.label || 'Code(s) sélectionné(s)'}
label={props.definition.label ?? 'Code(s) sélectionné(s)'}
variant="outlined"
noOptionsText={props.definition.noOptionsText}
values={valueWithLabels}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type BaseCriteriaItem = {
// for conditionnal fields
displayCondition?: ((data: Record<string, DataTypes>, context: Context) => boolean) | string // the displayCondition is used to hide the field
disableCondition?: ((data: Record<string, DataTypes>, context: Context) => boolean) | string // the disableCondition is used to disable the field
displayValueSummary?: (data: DataTypes) => string | string // the displayValueSummary is used to display a summary of the value
displayValueSummary?: (data: DataTypes) => string // the displayValueSummary is used to display a summary of the value
// for resetting the value of the field
resetCondition?: ((data: Record<string, DataTypes>, context: Context) => boolean) | string // the resetCondition is used to reset the value of the field
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ export const form: () => CriteriaForm<DemographicDataType> = () => ({
)
},
buildInfo: {
// TODO there is orignially a condition where
// criterion.birthdates[0] === null && criterion.birthdates[1] === null
// must be true for the filter to be applied
// check if this is still necessary (cause the durationRange / calendarRange set the value to null when inner fields are null now)
fhirKey: { main: PatientsParamsKeys.DATE_IDENTIFIED, deid: PatientsParamsKeys.DATE_DEIDENTIFIED },
chipDisplayMethodExtraArgs: [{ type: 'string', value: 'Âge' }]
chipDisplayMethodExtraArgs: [{ type: 'string', value: 'Âge' }],
ignoreIf: (data) => {
const typedData = data as DemographicDataType
const birthdates = typedData.birthdates
return birthdates !== null && (birthdates.start !== null || birthdates.end !== null)
}
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/Inputs/CheckedTextfield/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const CheckedTextfield = ({
useEffect(() => {
const regexp = new RegExp(regex, 'gm')

if (!bufferValue || !!bufferValue.match(regexp) === !inverseCheck) {
if (!bufferValue || !!regexp.exec(bufferValue) === !inverseCheck) {
setError(false)
onError(false)
if (extractValidValues && !inverseCheck) {
Expand Down
11 changes: 5 additions & 6 deletions src/components/ui/Inputs/Occurences/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ const OccurenceInput = ({

const checkedValue = (e: React.ChangeEvent<HTMLInputElement>) => {
const newValue = e.target.value === '' ? '0' : e.target.value
if (floatValues && newValue.match(enableNegativeValues ? /^-?\d*\.?\d*$/ : /^\d*\.?\d*$/)) {
return newValue
} else if (
newValue.match(/^\d+$/) ||
if (
(floatValues && (enableNegativeValues ? /^-?\d*\.?\d*$/ : /^\d*\.?\d*$/).exec(newValue)) ||
/^\d+$/.exec(newValue) ||
(enableNegativeValues && newValue === '0' && comparatorValue === Comparators.LESS)
) {
return newValue
Expand Down Expand Up @@ -121,8 +120,8 @@ const OccurenceInput = ({
>
{(Object.keys(Comparators) as (keyof typeof Comparators)[])
.filter((key) => allowBetween || Comparators[key] !== Comparators.BETWEEN)
.map((key, index) => (
<MenuItem key={index} value={Comparators[key]}>
.map((key) => (
<MenuItem key={key} value={Comparators[key]}>
{Comparators[key]}
</MenuItem>
))}
Expand Down
2 changes: 1 addition & 1 deletion src/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { createContext, ReactNode } from 'react'
import { Root } from 'react-dom/client'
import * as R from 'ramda'
import { CONFIG_URL } from 'constants.js'
import { DocumentAttachmentMethod, DocumentAttachmentMethodLabel, LabelObject } from 'types/searchCriterias'
import { LabelObject } from 'types/searchCriterias'
import { birthStatusData, booleanFieldsData, booleanOpenChoiceFieldsData, vmeData } from 'data/questionnaire_data'

type ValueSetConfig = {
Expand Down
11 changes: 5 additions & 6 deletions src/utils/cohortCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { Hierarchy } from 'types/hierarchy'
import { fetchValueSet } from 'services/aphp/callApi'
import { CodeCache } from 'state/valueSets'
import { NewDurationRangeType } from 'components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/CriteriaForm/types'
import { isString } from 'lodash'
import criteriaList, { getAllCriteriaItems } from 'components/CreationCohort/DataList_Criteria'

const REQUETEUR_VERSION = 'v1.5.1'
Expand Down Expand Up @@ -214,8 +213,9 @@ const mapCriteriaToResource = (criteriaType: CriteriaType): ResourceType => {
}

const findQuestionnaireName = (filters: string[]) => {
const regex = /questionnaire.name=(.*)/
for (const item of filters) {
const match = item.match(/questionnaire.name=(.*)/)
const match = regex.exec(item)
if (match?.[1]) {
return match[1]
}
Expand Down Expand Up @@ -544,13 +544,12 @@ export const fetchCriteriasCodes = async (
if (item.type === 'codeSearch') {
const defaultValueSet = item.valueSetIds[0]
for (const criterion of criteriaValues) {
const dataKey = item.valueKey as string
// TODO remove this type casting when using the proper entry type, also make sure that the dataKey is a valid key
const labelValues = criterion[dataKey as keyof SelectedCriteriaType] as unknown as LabelObject[]
const dataKey = item.valueKey as keyof SelectedCriteriaType
const labelValues = criterion[dataKey] as unknown as LabelObject[]
if (labelValues && labelValues.length > 0) {
for (const code of labelValues) {
console.log('fetching code', code)
const codeSystem = code.system || defaultValueSet
const codeSystem = code.system ?? defaultValueSet
const valueSetCodeCache = updatedCriteriaData[codeSystem] ?? []
if (!valueSetCodeCache.find((data) => data.id === code.id)) {
try {
Expand Down

0 comments on commit 4a5f502

Please sign in to comment.