Skip to content

Commit

Permalink
fix: criteria type/resource matching
Browse files Browse the repository at this point in the history
  • Loading branch information
pl-buiquang committed Dec 3, 2024
1 parent 6ee1564 commit 4167555
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,17 @@ export const constructFhirFilterForType = <T extends SelectedCriteriaType>(
.reduce(
(accumulator: string, currentValue: string): string =>
accumulator ? `${accumulator}&${currentValue}` : currentValue,
criteriaForm.buildInfo?.defaultFilter ?? ''
criteriaForm.buildInfo.defaultFilter ?? ''
)
}

export const unbuildCriteriaDataFromDefinition = async <T extends SelectedCriteriaType>(
element: RequeteurCriteriaType,
type: CriteriaType,
criteriaDefinition: CriteriaForm<T>
): Promise<SelectedCriteriaType> => {
const emptyCriterion: T = { ...criteriaDefinition.initialData } as T
emptyCriterion.id = element._id
emptyCriterion.type = type as SelectedCriteriaType['type']
emptyCriterion.type = criteriaDefinition.buildInfo.type[element.resourceType] as SelectedCriteriaType['type']
emptyCriterion.title = element.name
emptyCriterion.isInclusive = element.isInclusive

Expand Down Expand Up @@ -317,9 +316,7 @@ export const criteriasAsArray = (
valuesets: ValueSetStore
): ReactNode[] => {
const criteriaDef = criteriaDefinitions.find((criterion) =>
isString(criterion.formDefinition?.buildInfo?.criteriaType)
? criterion.formDefinition?.buildInfo?.criteriaType === selectedCriteria.type
: criterion.formDefinition?.buildInfo?.criteriaType.includes(selectedCriteria.type)
Object.values(criterion.formDefinition?.buildInfo?.type || {}).includes(selectedCriteria.type)
)?.formDefinition
if (!criteriaDef) return []

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactNode } from 'react'
import { ScopeElement } from 'types'
import { Hierarchy } from 'types/hierarchy'
import { Comparators, CriteriaType } from 'types/requestCriterias'
import { Comparators, CriteriaType, ResourceType } from 'types/requestCriterias'
import { SourceType } from 'types/scope'
import { LabelObject } from 'types/searchCriterias'
import { CHIPS_DISPLAY_METHODS } from './mappers/chipDisplayMapper'
Expand Down Expand Up @@ -324,10 +324,9 @@ export type CriteriaForm<T> = {
warningAlert?: ReactNode[]
initialData: Omit<T, 'id'>
errorMessages: { [key: string]: string }
buildInfo?: {
buildInfo: {
defaultFilter?: string
criteriaType: CriteriaType | CriteriaType[]
resourceType: string | string[]
type: Partial<Record<ResourceType, CriteriaType>>
// should return true if the criteria is to be unbuild for the current fhir filter
subType?: string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ export const form: () => CriteriaForm<ObservationDataType> = () => ({
NO_ERROR: ''
},
buildInfo: {
criteriaType: CriteriaType.OBSERVATION,
resourceType: ResourceType.OBSERVATION,
type: { [ResourceType.OBSERVATION]: CriteriaType.OBSERVATION },
defaultFilter: `subject.active=true&${ObservationParamsKeys.VALIDATED_STATUS}=${BiologyStatus.VALIDATED}`
},
itemSections: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ export const form: () => CriteriaForm<CcamDataType> = () => ({
NO_ERROR: ''
},
buildInfo: {
criteriaType: CriteriaType.PROCEDURE,
resourceType: ResourceType.PROCEDURE,
type: { [ResourceType.PROCEDURE]: CriteriaType.PROCEDURE },
defaultFilter: 'subject.active=true'
},
itemSections: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ export const form: () => CriteriaForm<Cim10DataType> = () => ({
NO_ERROR: ''
},
buildInfo: {
criteriaType: CriteriaType.CONDITION,
resourceType: ResourceType.CONDITION,
type: { [ResourceType.CONDITION]: CriteriaType.CONDITION },
defaultFilter: 'subject.active=true'
},
itemSections: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export const form: () => CriteriaForm<DemographicDataType> = () => ({
NO_ERROR: ''
},
buildInfo: {
criteriaType: CriteriaType.PATIENT,
resourceType: ResourceType.PATIENT,
type: { [ResourceType.PATIENT]: CriteriaType.PATIENT },
defaultFilter: 'active=true'
},
itemSections: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export const form: () => CriteriaForm<DocumentDataType> = () => ({
NO_ERROR: ''
},
buildInfo: {
criteriaType: CriteriaType.DOCUMENTS,
resourceType: ResourceType.DOCUMENTS,
type: { [ResourceType.DOCUMENTS]: CriteriaType.DOCUMENTS },
defaultFilter: 'type:not=doc-impor&contenttype=text/plain&subject.active=true'
},
itemSections: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ export const form: () => CriteriaForm<EncounterDataType> = () => ({
NO_ERROR: ''
},
buildInfo: {
criteriaType: CriteriaType.ENCOUNTER,
resourceType: ResourceType.ENCOUNTER,
type: { [ResourceType.ENCOUNTER]: CriteriaType.ENCOUNTER },
defaultFilter: 'subject.active=true'
},
itemSections: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ export const form: () => CriteriaForm<GhmDataType> = () => ({
</div>
],
buildInfo: {
criteriaType: CriteriaType.CLAIM,
resourceType: ResourceType.CLAIM,
type: { [ResourceType.CLAIM]: CriteriaType.CLAIM },
defaultFilter: 'patient.active=true'
},
errorMessages: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ export const form: () => CriteriaForm<HospitDataType> = () => ({
infoAlert: ['Tous les éléments des champs multiples sont liés par une contrainte OU'],
errorMessages: {},
buildInfo: {
criteriaType: CriteriaType.HOSPIT,
resourceType: ResourceType.QUESTIONNAIRE_RESPONSE,
type: { [ResourceType.QUESTIONNAIRE_RESPONSE]: CriteriaType.HOSPIT },
defaultFilter: `subject.active=true&questionnaire.name=${FormNames.HOSPIT}&status=in-progress,completed`,
subType: FormNames.HOSPIT
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export const form: () => CriteriaForm<IPPListDataType> = () => ({
search: ''
},
buildInfo: {
criteriaType: CriteriaType.IPP_LIST,
resourceType: ResourceType.IPP_LIST // TODO should be ResourceType.PATIENT
type: { [ResourceType.IPP_LIST]: CriteriaType.IPP_LIST } // TODO should be ResourceType.PATIENT
},
errorMessages: {
AT_LEAST_ONE_IPP: 'Merci de renseigner au moins un IPP'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ export const form: () => CriteriaForm<ImagingDataType> = () => ({
ADVANCED_INPUTS_ERROR: "Erreur d'entrées avancées"
},
buildInfo: {
criteriaType: CriteriaType.IMAGING,
resourceType: ResourceType.IMAGING,
type: { [ResourceType.IMAGING]: CriteriaType.IMAGING },
defaultFilter: 'patient.active=true'
},
itemSections: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ export const form: () => CriteriaForm<MedicationDataType> = () => ({
NO_ERROR: ''
},
buildInfo: {
criteriaType: [CriteriaType.MEDICATION_ADMINISTRATION, CriteriaType.MEDICATION_REQUEST],
resourceType: [ResourceType.MEDICATION_ADMINISTRATION, ResourceType.MEDICATION_REQUEST],
type: {
[ResourceType.MEDICATION_ADMINISTRATION]: CriteriaType.MEDICATION_ADMINISTRATION,
[ResourceType.MEDICATION_REQUEST]: CriteriaType.MEDICATION_REQUEST
},
defaultFilter: 'subject.active=true'
},
itemSections: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ export const form: () => CriteriaForm<PregnancyDataType> = () => ({
NO_ERROR: ''
},
buildInfo: {
criteriaType: CriteriaType.PREGNANCY,
resourceType: ResourceType.QUESTIONNAIRE_RESPONSE,
type: { [ResourceType.QUESTIONNAIRE_RESPONSE]: CriteriaType.PREGNANCY },
defaultFilter: `subject.active=true&questionnaire.name=${FormNames.PREGNANCY}&status=in-progress,completed`,
subType: FormNames.PREGNANCY
},
Expand Down
1 change: 1 addition & 0 deletions src/types/requestCriterias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export enum ImagingParamsKeys {
}

export enum CriteriaType {
UNKNOWN = 'Unknown',
REQUEST = 'Request',
IPP_LIST = 'IPPList',
PATIENT = 'Patient',
Expand Down
16 changes: 4 additions & 12 deletions src/utils/cohortCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ export const constructFhirFilter = (
allcriterias: CriteriaItemType[]
): string => {
const formDefinition = allcriterias.find((crit) =>
isString(crit.formDefinition?.buildInfo?.criteriaType)
? crit.formDefinition?.buildInfo?.criteriaType === criteria.type
: crit.formDefinition?.buildInfo?.criteriaType.includes(criteria.type)
Object.values(crit.formDefinition?.buildInfo?.type || {}).includes(criteria.type)
)?.formDefinition
if (!formDefinition) {
console.error('No form definition found for criteria type', criteria.type)
Expand Down Expand Up @@ -229,17 +227,15 @@ export const unbuildCriteriaData = async (
critieriaDefinitions: CriteriaItemType[]
): Promise<SelectedCriteriaType> => {
const criteriaDefinition = critieriaDefinitions.filter((item) =>
isString(item.formDefinition?.buildInfo?.resourceType)
? item.formDefinition?.buildInfo?.resourceType === element.resourceType
: item.formDefinition?.buildInfo?.resourceType.includes(element.resourceType)
Object.keys(item.formDefinition?.buildInfo.type || {}).includes(element.resourceType)
)

if (criteriaDefinition.length === 0) {
throw new Error('Criteria definition not found')
}

if (criteriaDefinition.length === 1 && criteriaDefinition[0].formDefinition) {
return unbuildCriteriaDataFromDefinition(element, criteriaDefinition[0].id, criteriaDefinition[0].formDefinition)
return unbuildCriteriaDataFromDefinition(element, criteriaDefinition[0].formDefinition)
}

const splittedFilters = element.filterFhir.split('&')
Expand All @@ -249,11 +245,7 @@ export const unbuildCriteriaData = async (
(item) => item.formDefinition?.buildInfo?.subType === subType
)
if (questionnaireDefinition?.formDefinition) {
return unbuildCriteriaDataFromDefinition(
element,
questionnaireDefinition.id,
questionnaireDefinition.formDefinition
)
return unbuildCriteriaDataFromDefinition(element, questionnaireDefinition.formDefinition)
}
}
throw new Error('Criteria subtype definition not found')
Expand Down

0 comments on commit 4167555

Please sign in to comment.