Skip to content

Commit

Permalink
fix: misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pl-buiquang committed Dec 4, 2024
1 parent 41e117a commit ef6287e
Show file tree
Hide file tree
Showing 22 changed files with 149 additions and 98 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/data/cohortCreation/documentCriteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const completeDocumentCriteria: DocumentDataType = {
{ type: 'Comptes Rendus Hospitalisation', label: 'CRH Chirurgie', id: 'crh-chir' }
],
search: 'cancer',
searchBy: SearchByTypes.TEXT,
searchBy: [{ id: SearchByTypes.TEXT, label: 'Corps du document' }],
encounterService: [
{
above_levels_ids: '8312002244',
Expand Down
1 change: 1 addition & 0 deletions src/components/CreationCohort/DataList_Criteria.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const criteriaList: () => CriteriaItemType[] = () => {
},
{
id: CriteriaType.MEDICATION,
types: [CriteriaType.MEDICATION_REQUEST, CriteriaType.MEDICATION_ADMINISTRATION],
title: 'Médicaments (Prescription - Administration)',
color: ODD_MEDICATION ? '#0063AF' : '#808080',
fontWeight: 'bold',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,24 @@ const buildDateFilterValue = (
}

const unbuildDateFilter = (value: string, existingValue?: NewDurationRangeType) => {
const values = value.split(',')
if (values.length > 1) {
const res: NewDurationRangeType = values.reduce(
(acc, val) => unbuildDateFilter(val, acc),
existingValue
) as NewDurationRangeType
return res
}

const date = replaceTime(value.replace(COMPARATORS_REGEX, ''))
const updatedValue = existingValue || { start: null, end: null, includeNull: false }
if (value.includes('ge')) {
updatedValue.start = date
} else if (value.includes('le')) {
updatedValue.end = date
} else if (value.includes('not*')) {
} else if (value.includes('eq*')) {
// TODO this is really bad, but it's the only way to handle the includeNull case for now
// the value matched is derived from the param 'not (xxx eq "*")'
updatedValue.includeNull = true
}
return updatedValue
Expand Down Expand Up @@ -214,6 +225,32 @@ const buildWithDocumentFilter = (withDocument: LabelObject[], daysOfDelay: numbe
return ''
}

const parseDocumentAttachment = (value: string) => {
const documentAttachment: { documentAttachmentMethod: DocumentAttachmentMethod; daysOfDelay: string | null } = {
documentAttachmentMethod: DocumentAttachmentMethod.NONE,
daysOfDelay: null
}
if (value === DocumentAttachmentMethod.ACCESS_NUMBER) {
documentAttachment.documentAttachmentMethod = value
} else if (value.startsWith(DocumentAttachmentMethod.INFERENCE_TEMPOREL)) {
documentAttachment.documentAttachmentMethod = DocumentAttachmentMethod.INFERENCE_TEMPOREL
const matchNumber = value.match(/\d+/)
if (matchNumber) {
documentAttachment.daysOfDelay = matchNumber[0]
}
}

return documentAttachment
}

const unbuildDocumentAttachment = (value: string) => {
return [{ id: parseDocumentAttachment(value).documentAttachmentMethod, label: '' }]
}

const unbuildDaysOfDelay = (value: string) => {
return parseDocumentAttachment(value).daysOfDelay
}

/********************************************************************************************* */
/* Item mapper list */
/********************************************************************************************* */
Expand Down Expand Up @@ -263,8 +300,22 @@ export const UNBUILD_MAPPERS = {
fhirkey: string,
args: Array<DataTypes>
) => {
Promise.resolve((args[0] as LabelObject[]).find((l) => l.id === fhirkey))
return Promise.resolve((args[0] as LabelObject[]).filter((l) => l.id === fhirkey))
},
unbuildDocumentAttachment: async (
val: string,
deid: boolean,
existingValue: DataTypes,
fhirkey: string,
args: Array<DataTypes>
) => Promise.resolve(unbuildDocumentAttachment(val)),
unbuildDaysOfDelay: async (
val: string,
deid: boolean,
existingValue: DataTypes,
fhirkey: string,
args: Array<DataTypes>
) => Promise.resolve(unbuildDaysOfDelay(val)),
unbuildBooleanFromDataNonNullStatus: async (
val: string,
deid: boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const chipForDateLabel = (dateRange: NewDurationRangeType, word?: string) => {
}

const getSearchDocumentLabel = (value: string, searchBy: LabelObject[]) => {
const loc = searchBy.find((l) => l.id === SearchByTypes.TEXT) ? 'document' : 'titre du document'
const loc = searchBy && searchBy.find((l) => l.id === SearchByTypes.TEXT) ? 'document' : 'titre du document'
return `Contient "${value}" dans le ${loc}`
}

Expand Down Expand Up @@ -113,12 +113,13 @@ const getIdsListLabels = (values: string, name: string) => {
return `Contient les ${name} : ${labels}`
}

const getAttachmentMethod = (value: DocumentAttachmentMethod, daysOfDelay: string | null) => {
if (value === DocumentAttachmentMethod.INFERENCE_TEMPOREL) {
const getAttachmentMethod = (value: LabelObject[], daysOfDelay: string | null) => {
const documentAttachementMethod = value.at(0)?.id
if (documentAttachementMethod === DocumentAttachmentMethod.INFERENCE_TEMPOREL) {
return `Rattachement aux documents par ${DocumentAttachmentMethodLabel.INFERENCE_TEMPOREL.toLocaleLowerCase()}${
daysOfDelay !== '' && daysOfDelay !== null ? ` de ${daysOfDelay} jour(s)` : ''
}`
} else if (value === DocumentAttachmentMethod.ACCESS_NUMBER) {
} else if (documentAttachementMethod === DocumentAttachmentMethod.ACCESS_NUMBER) {
return `Rattachement aux documents par ${DocumentAttachmentMethodLabel.ACCESS_NUMBER.toLocaleLowerCase()}`
} else {
return ''
Expand Down Expand Up @@ -177,9 +178,9 @@ const chipFromCodeSearch = (
const displaySystem = (system?: string) => {
switch (system) {
case getConfig().features.medication.valueSets.medicationAtc.url:
return `${getConfig().features.medication.valueSets.medicationAtc.title}: '`
return `${getConfig().features.medication.valueSets.medicationAtc.title}: `
case getConfig().features.medication.valueSets.medicationUcd.url:
return `${getConfig().features.medication.valueSets.medicationUcd.title}: '`
return `${getConfig().features.medication.valueSets.medicationUcd.title}: `
default:
return ''
}
Expand Down Expand Up @@ -272,7 +273,7 @@ export const CHIPS_DISPLAY_METHODS = {
item: GenericCriteriaItem,
valueSets: ValueSetStore,
args: Array<ChipDisplayMethod | DataTypes>
) => getAttachmentMethod(val as DocumentAttachmentMethod, args[0] as string),
) => getAttachmentMethod(val as LabelObject[], args[0] as string),
getSearchDocumentLabel: (
val: DataTypes,
item: GenericCriteriaItem,
Expand All @@ -298,18 +299,8 @@ export const CHIPS_DISPLAY_METHODS = {
args: Array<ChipDisplayMethod | DataTypes>
) => {
return args[1] === args[2]
? (args[0] as ChipDisplayMethod)(
val,
item,
valueSets,
args.slice(3).filter((arg, i) => i % 2 === 0)
)
: (args[0] as ChipDisplayMethod)(
val,
item,
valueSets,
args.slice(3).filter((arg, i) => i % 2 === 1)
)
? (args[0] as ChipDisplayMethod)(args.slice(3).find((arg, i) => i % 2 === 0) as DataTypes, item, valueSets, [])
: (args[0] as ChipDisplayMethod)(args.slice(3).find((arg, i) => i % 2 === 1) as DataTypes, item, valueSets, [])
},
noop: () => undefined
}
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, isString } from 'lodash'
import { isArray, isFunction, isObject, isString } from 'lodash'
import { BUILD_MAPPERS, BuilderMethod, UNBUILD_MAPPERS } from './buildMappers'

/************************************************************************************/
Expand Down Expand Up @@ -46,9 +46,11 @@ const parseFhirKey = (
if ('deid' in fhirKey) {
return deidentified ? fhirKey.deid : fhirKey.main
}
return parseExtraArgs(fhirKey.value1, obj, BUILD_MAPPERS) === parseExtraArgs(fhirKey.value2, obj, BUILD_MAPPERS)
? fhirKey.main
: fhirKey.alt
const arg1 = parseExtraArgs(fhirKey.value1, obj, BUILD_MAPPERS)
const arg2 = parseExtraArgs(fhirKey.value2, obj, BUILD_MAPPERS)
const simplifiedArg1 = isArray(arg1) && arg1.length > 0 && isObject(arg1[0]) && 'id' in arg1[0] ? arg1[0].id : arg1
const simplifiedArg2 = isArray(arg2) && arg2.length > 0 && isObject(arg2[0]) && 'id' in arg2[0] ? arg2[0].id : arg2
return simplifiedArg1 === simplifiedArg2 ? fhirKey.main : fhirKey.alt
}

const buildFilter = (fhirKey: string, value?: string | { filterValue: string; filterKey: string } | null): string => {
Expand Down Expand Up @@ -255,7 +257,7 @@ export const unbuildCriteriaDataFromDefinition = async <T extends SelectedCriter
const allFilters = filters.flatMap((filter) => {
if (filter[0] === FILTER_PARAM_NAME) {
const filterContent = filter[1]
const extractedFilterElements = extractFilterParams(filterContent, { omitOperatorEq: true })
const extractedFilterElements = extractFilterParams(filterContent, { omitOperatorEq: false })
if (extractedFilterElements) {
return (extractQuestionnaireFilterParams(extractedFilterElements) || extractedFilterElements).map(
(filterParam) => {
Expand Down Expand Up @@ -340,7 +342,6 @@ export const criteriasAsArray = (
const extraArgs = (item.buildInfo?.chipDisplayMethodExtraArgs || []).map((arg) =>
parseExtraArgs(arg, selectedCriteria, CHIPS_DISPLAY_METHODS)
)
console.log('displaying chip', item, val, extraArgs)
return chipBuilder(val, item, valuesets, extraArgs)
})
.filter((label) => !!label)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const FORM_ITEM_RENDERER: { [key in CriteriaFormItemType]: CriteriaFormItemView<
multiline={props.definition.multiline}
inverseCheck={props.definition.inverseCheck}
extractValidValues={props.definition.extractValidValues}
displayCheckError={props.definition.displayCheckError}
regex={props.definition.regex}
errorMessage={props.definition.checkErrorMessage}
placeholder={props.definition.placeholder}
Expand All @@ -79,8 +80,9 @@ const FORM_ITEM_RENDERER: { [key in CriteriaFormItemType]: CriteriaFormItemView<
? props.updateData(null)
: props.updateData({ start: range[0] ?? null, end: range[1] ?? null, includeNull: false })
}
unit={props.definition.unit}
onError={(isError) => props.setError(isError ? 'error' : undefined)}
deidentified={props.deidentified}
includeDays={!props.deidentified || !!props.definition.includeDays}
/>
)
},
Expand Down Expand Up @@ -200,6 +202,11 @@ const FORM_ITEM_RENDERER: { [key in CriteriaFormItemType]: CriteriaFormItemView<
placeholder={props.definition.label}
disabled={props.disabled}
fullWidth
InputProps={{
inputProps: {
min: props.definition.min
}
}}
/>
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export type TextWithRegexCriteriaItem = BaseCriteriaItem & {
placeholder?: string
multiline?: boolean
inverseCheck?: boolean
displayCheckError?: boolean
extractValidValues?: boolean
}

Expand All @@ -68,6 +69,7 @@ export type InfoCriteriaItem = BaseCriteriaItem & {

export type NumberCriteriaItem = BaseCriteriaItem & {
type: 'number'
min?: number
}

export type BooleanCriteriaItem = BaseCriteriaItem & {
Expand All @@ -89,6 +91,8 @@ export type NumberWithComparatorCriteriaItem = BaseCriteriaItem & {

export type DurationItem = BaseCriteriaItem & {
type: 'durationRange'
unit?: string
includeDays?: boolean
}

export type CalendarItem = BaseCriteriaItem &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,8 @@ const CriteriaRightPanel: React.FC<CriteriaRightPanelProps> = (props) => {
if (!_criteria) return null

for (const criteriaItem of _criteria) {
const { id, subItems } = criteriaItem
// For medication, we match request and medication administration
if (
id === 'Medication' &&
[CriteriaType.MEDICATION_REQUEST, CriteriaType.MEDICATION_ADMINISTRATION].includes(selectedCriteria.type)
) {
return criteriaItem
}
// For others the id should match the selected criteria type
if (id === selectedCriteria.type) return criteriaItem
const { id, types, subItems } = criteriaItem
if (id === selectedCriteria.type || types?.includes(selectedCriteria.type)) return criteriaItem

// Search subcriterias
if (subItems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export const form: () => CriteriaForm<EncounterDataType> = () => ({
valueKey: 'duration',
type: 'durationRange',
extraLabel: () => 'Durée de la prise en charge',
unit: 'Durée',
includeDays: true,
buildInfo: {
fhirKey: EncounterParamsKeys.DURATION,
chipDisplayMethodExtraArgs: [{ type: 'string', value: 'Prise en charge : ' }]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ export const form: () => CriteriaForm<HospitDataType> = () => ({
valueSetId: getConfig().core.valueSets.encounterStatus.url,
noOptionsText: 'Veuillez entrer un statut de visite associée',
buildInfo: {
fhirKey: {
id: QuestionnaireResponseParamsKeys.ENCOUNTER_STATUS,
type: 'valueCoding'
},
fhirKey: QuestionnaireResponseParamsKeys.ENCOUNTER_STATUS,
chipDisplayMethodExtraArgs: [{ type: 'string', value: 'Statut de la visite associée :' }]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const form: () => CriteriaForm<IPPListDataType> = () => ({
type: 'textWithRegex',
regex: '(?:^|\\D+)?(8\\d{9})(?:$|\\D+)',
placeholder: "Ajouter une liste d'IPP",
displayCheckError: false,
extractValidValues: true,
displayValueSummary: (value) => {
const ippList = (value as string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ export const form: () => CriteriaForm<ImagingDataType> = () => ({
fhirKey: ImagingParamsKeys.WITH_DOCUMENT,
buildMethod: 'buildWithDocument',
buildMethodExtraArgs: [{ type: 'reference', value: 'daysOfDelay' }],
chipDisplayMethodExtraArgs: [{ type: 'reference', value: 'daysOfDelay' }]
chipDisplayMethod: 'getAttachmentMethod',
chipDisplayMethodExtraArgs: [{ type: 'reference', value: 'daysOfDelay' }],
unbuildMethod: 'unbuildDocumentAttachment'
}
},
{
Expand All @@ -186,7 +188,13 @@ export const form: () => CriteriaForm<ImagingDataType> = () => ({
label: 'Plage de jours',
extraLabel: () => 'Plage de jours',
errorType: 'INCOHERENT_AGE_ERROR',
displayCondition: (data) => (data.withDocument as LabelObject[])?.at(0)?.id === 'INFERENCE_TEMPOREL'
displayCondition: (data) => (data.withDocument as LabelObject[])?.at(0)?.id === 'INFERENCE_TEMPOREL',
buildInfo: {
fhirKey: ImagingParamsKeys.WITH_DOCUMENT,
buildMethod: 'noop',
chipDisplayMethod: 'noop',
unbuildMethod: 'unbuildDaysOfDelay'
}
},
{
valueKey: 'studyUid',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export const form: () => CriteriaForm<PregnancyDataType> = () => ({
valueKey: 'foetus',
type: 'numberAndComparator',
label: 'Nombre de fœtus',
allowBetween: true,
buildInfo: {
fhirKey: {
id: 'F_MATER_001017',
Expand All @@ -144,7 +143,6 @@ export const form: () => CriteriaForm<PregnancyDataType> = () => ({
valueKey: 'parity',
type: 'numberAndComparator',
label: 'Parité',
allowBetween: true,
buildInfo: {
fhirKey: {
id: 'F_MATER_001192',
Expand Down
2 changes: 1 addition & 1 deletion src/components/Filters/BirthdatesRangesFilters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const BirthdatesRangesFilter = ({
<InputWrapper>
<DurationRange
active={!disabled}
deidentified={deidentified}
includeDays={!deidentified}
label="Âge"
onError={onError}
value={birthdatesRanges}
Expand Down
Loading

0 comments on commit ef6287e

Please sign in to comment.