Skip to content

Commit

Permalink
test: add test for checkNominativeCriteria into `utils/cohortCreation…
Browse files Browse the repository at this point in the history
….ts` - Ref gestion-de-projet#2708 (#1033)

* test: add test for checkNominativeCriteria into `utils/cohortCreation.ts` - Ref gestion-de-projet#2708
  • Loading branch information
Mehdi-BOUYAHIA authored Aug 21, 2024
1 parent 2240e1e commit 00a618a
Show file tree
Hide file tree
Showing 7 changed files with 5,909 additions and 2,183 deletions.
7,775 changes: 5,597 additions & 2,178 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ sonar.organization=aphp
# Coverage
sonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar.exclusions=dist/**
sonar.coverage.exclusions=**/*.test.*
sonar.coverage.exclusions=**/*.tsx
sonar.coverage.exclusions=**/*.test.*,**/*.tsx,src/__tests__/**
226 changes: 226 additions & 0 deletions src/__tests__/data/cohortCreation..ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
import { CriteriaType, SelectedCriteriaType } from 'types/requestCriterias'

const defaultProcedureCriteria: SelectedCriteriaType = {
id: 1,
error: undefined,
type: CriteriaType.PROCEDURE,
encounterService: undefined,
isInclusive: true,
title: 'Procedure',
occurrence: null,
occurrenceComparator: null,
startOccurrence: [null, null],
endOccurrence: undefined,
encounterStartDate: [null, null],
includeEncounterStartDateNull: true,
encounterEndDate: [null, null],
includeEncounterEndDateNull: true,
encounterStatus: [],
hierarchy: undefined,
code: [],
source: null,
label: undefined
}

const defaultPatientCriteria: SelectedCriteriaType = {
id: 1,
title: 'Patient',
type: CriteriaType.PATIENT,
genders: [],
vitalStatus: [],
age: [null, null],
birthdates: [null, null],
deathDates: [null, null]
}

const defaultEncounterCriteria: SelectedCriteriaType = {
id: 1,
type: CriteriaType.ENCOUNTER,
isInclusive: true,
title: 'critere encouter',
occurrence: null,
occurrenceComparator: null,
startOccurrence: [null, null],
endOccurrence: [null, null],
encounterStartDate: [null, null],
includeEncounterStartDateNull: false,
encounterEndDate: [null, null],
includeEncounterEndDateNull: false,
encounterStatus: [],
age: [null, null],
duration: [null, null],
admissionMode: null,
entryMode: null,
exitMode: null,
priseEnChargeType: null,
typeDeSejour: null,
reason: null,
destination: null,
provenance: null,
admission: null,
encounterService: undefined
}

const defaultIPPCriteria: SelectedCriteriaType = {
id: 1,
type: CriteriaType.IPP_LIST,
isInclusive: true,
title: 'critere IPP',
search: ''
}

export const procedurePeudonimizedCriteria: SelectedCriteriaType[] = [
{
...defaultProcedureCriteria,
startOccurrence: ['2024-08-15', '2024-08-22'],
encounterStartDate: ['2024-08-07', '2024-08-21'],
encounterStatus: [
{
id: 'cancelled',
label: 'Cancelled',
system: 'http://hl7.org/fhir/CodeSystem/encounter-status'
}
],
encounterEndDate: ['2024-08-22', '2024-08-22'],
code: [
{
id: '000212',
label: "000212 - Actes Diagnostiques Sur L'oreille",
system:
'https://www.atih.sante.fr/plateformes-de-transmission-et-logiciels/logiciels-espace-de-telechargement/id_lot/3550'
},
{
id: '000489',
label: '000489 - Actes Thérapeutiques Sur Les Vaisseaux Intracrâniens',
system:
'https://www.atih.sante.fr/plateformes-de-transmission-et-logiciels/logiciels-espace-de-telechargement/id_lot/3550'
}
]
}
]

export const patientPseudonimizedCriteria: SelectedCriteriaType[] = [
{
...defaultPatientCriteria,
genders: [
{
id: 'f',
label: 'Femme'
}
],
vitalStatus: [
{
id: 'alive',
label: 'Vivant'
}
]
}
]

export const patientPseudonimizedAgeCriteria: SelectedCriteriaType[] = [
{
...defaultPatientCriteria,
age: ['0/2/12', '0/5/15']
}
]

export const patientNominativeAge0Criteria: SelectedCriteriaType[] = [
{
...defaultPatientCriteria,
age: ['7/2/12', '0/5/15']
}
]

export const patientNominativeAge1Criteria: SelectedCriteriaType[] = [
{
...defaultPatientCriteria,
age: ['0/2/12', '8/5/15']
}
]

export const patientNominativeBirthdates: SelectedCriteriaType[] = [
{
...defaultPatientCriteria,
birthdates: ['2024-08-15', '2024-08-15']
}
]

export const patientNominativeDeathDates: SelectedCriteriaType[] = [
{
...defaultPatientCriteria,
deathDates: ['2024-08-15', '2024-08-15']
}
]

export const criteriasArrayWtihNominativeData: SelectedCriteriaType[] = [
...procedurePeudonimizedCriteria,
{
...defaultPatientCriteria,
genders: [
{
id: 'f',
label: 'Femme'
}
],
vitalStatus: [
{
id: 'alive',
label: 'Vivant'
}
],
deathDates: ['2024-08-15', '2024-08-15']
}
]

export const criteriaArrayWithNoNominativeData: SelectedCriteriaType[] = [
...procedurePeudonimizedCriteria,
{
...defaultPatientCriteria,
genders: [
{
id: 'f',
label: 'Femme'
}
],
vitalStatus: [
{
id: 'alive',
label: 'Vivant'
}
],
age: ['0/1/2', '0/5/15']
}
]

export const ippNominativeCriteria: SelectedCriteriaType[] = [
{
...defaultIPPCriteria,
search: '800000000, 800000001,8514257145'
}
]

export const ippEmptyCriteria: SelectedCriteriaType[] = [
{
...defaultIPPCriteria
}
]

export const encounterPseudonimizedCriteria: SelectedCriteriaType[] = [
{
...defaultEncounterCriteria
}
]

export const encounterPseudoAgeCriteria: SelectedCriteriaType[] = [
{
...defaultEncounterCriteria,
age: ['0/1/2', '0/5/15']
}
]

export const encounterNominativeAgeCriteria: SelectedCriteriaType[] = [
{
...defaultEncounterCriteria,
age: ['2/1/2', '5/5/15']
}
]
1 change: 0 additions & 1 deletion src/types/requestCriterias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ export type EncounterDataType = CommonCriteriaDataType &
destination: LabelObject[] | null
provenance: LabelObject[] | null
admission: LabelObject[] | null
encounterService: Hierarchy<ScopeElement, string>[] | null
}

export type PregnancyDataType = CommonCriteriaDataType &
Expand Down
83 changes: 83 additions & 0 deletions src/utils/cohortCreation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { SelectedCriteriaType } from 'types/requestCriterias'
import {
procedurePeudonimizedCriteria,
ippNominativeCriteria,
ippEmptyCriteria,
encounterPseudonimizedCriteria,
encounterPseudoAgeCriteria,
encounterNominativeAgeCriteria,
patientPseudonimizedCriteria,
patientPseudonimizedAgeCriteria,
patientNominativeAge0Criteria,
patientNominativeAge1Criteria,
patientNominativeBirthdates,
patientNominativeDeathDates,
criteriasArrayWtihNominativeData,
criteriaArrayWithNoNominativeData
} from '../__tests__/data/cohortCreation.'
import { checkNominativeCriteria } from './cohortCreation'

describe('test of checkNominativeCriteria', () => {
it('should return false if selectedCriteria is an empty array', () => {
const selectedCriteria: SelectedCriteriaType[] = []
expect(checkNominativeCriteria(selectedCriteria)).toBe(false)
})
it("should return false if selectedCriteria contain procedure pseudonimized criteria", () => {
const selectedCriteria: SelectedCriteriaType[] = procedurePeudonimizedCriteria
console.log('procedurePeudonimizedCriteria', procedurePeudonimizedCriteria[0])
expect(checkNominativeCriteria(selectedCriteria)).toBe(false)
})
it("should return false if selectedCriteria contain patient pseudonimized criteria", () => {
const selectedCriteria: SelectedCriteriaType[] = patientPseudonimizedCriteria
expect(checkNominativeCriteria(selectedCriteria)).toBe(false)
})
it("should return false if selectedCriteria contains patient.age pseudonimized", () => {
const selectedCriteria: SelectedCriteriaType[] = patientPseudonimizedAgeCriteria
expect(checkNominativeCriteria(selectedCriteria)).toBe(false)
})
it("should return true if selectedCriteria contain patient.age[0] nominative", () => {
const selectedCriteria: SelectedCriteriaType[] = patientNominativeAge0Criteria
expect(checkNominativeCriteria(selectedCriteria)).toBe(true)
})
it("should return true if selectedCriteria contain patient.age[1] nominative", () => {
const selectedCriteria: SelectedCriteriaType[] = patientNominativeAge1Criteria
expect(checkNominativeCriteria(selectedCriteria)).toBe(true)
})
it('should return true if selectedCriteria contains a patient birthdates', () => {
const selectedCriteria: SelectedCriteriaType[] = patientNominativeBirthdates
expect(checkNominativeCriteria(selectedCriteria)).toBe(true)
})
it('should return true if selectedCriteria contains a patient deathDates', () => {
const selectedCriteria: SelectedCriteriaType[] = patientNominativeDeathDates
expect(checkNominativeCriteria(selectedCriteria)).toBe(true)
})
it('should return true if selectedCriteria contains a nominative criteria', () => {
const selectedCriteria: SelectedCriteriaType[] = criteriasArrayWtihNominativeData
console.log('selectedCriteria', selectedCriteria[0], selectedCriteria[1])
expect(checkNominativeCriteria(selectedCriteria)).toBe(true)
})
it("should return false if selectedCriteria doesn't contains a nominative criteria", () => {
const selectedCriteria: SelectedCriteriaType[] = criteriaArrayWithNoNominativeData
expect(checkNominativeCriteria(selectedCriteria)).toBe(false)
})
it('should return true if selectedCriteria contains a nominative IPP.search', () => {
const selectedCriteria: SelectedCriteriaType[] = ippNominativeCriteria
expect(checkNominativeCriteria(selectedCriteria)).toBe(true)
})
it('should return true if selectedCriteria contains an IPP criteria', () => {
const selectedCriteria: SelectedCriteriaType[] = ippEmptyCriteria
expect(checkNominativeCriteria(selectedCriteria)).toBe(true)
})
it('should return false if selectedCriteria contains an encounter pseudonimized criteria', () => {
const selectedCriteria: SelectedCriteriaType[] = encounterPseudonimizedCriteria
expect(checkNominativeCriteria(selectedCriteria)).toBe(false)
})
it('should return false if selectedCriteria contains a peudonimize encounter.age', () => {
const selectedCriteria: SelectedCriteriaType[] = encounterPseudoAgeCriteria
expect(checkNominativeCriteria(selectedCriteria)).toBe(false)
})
it('should return true if selectedCriteria contains a nominative encounter.age', () => {
const selectedCriteria: SelectedCriteriaType[] = encounterNominativeAgeCriteria
expect(checkNominativeCriteria(selectedCriteria)).toBe(true)
})
})
2 changes: 1 addition & 1 deletion src/utils/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const unbuildLabelObjectFilter = (currentCriterion: any, filterName: stri
}
}

export const buildEncounterServiceFilter = (criterion: Hierarchy<ScopeElement, string>[] | undefined) => {
export const buildEncounterServiceFilter = (criterion?: Hierarchy<ScopeElement, string>[]) => {
return criterion && criterion.length > 0 ? `${criterion.map((item) => item.id).reduce(searchReducer)}` : ''
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/perimeters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SourceType } from 'types/scope'
import { Back_API_Response, CustomError } from 'types'
import { PERIMETER_SOURCE_TYPE_HIERARCHY } from 'constants.js'

const SOURCE_TYPES_LEVELS: string[] = PERIMETER_SOURCE_TYPE_HIERARCHY.split(',')
const SOURCE_TYPES_LEVELS: string[] = (PERIMETER_SOURCE_TYPE_HIERARCHY || '').split(',')

export const getScopeLevelBySourceType = (type: SourceType) => {
// TODO: Refactor this function to use an external mapping file/configuration
Expand Down

0 comments on commit 00a618a

Please sign in to comment.