From 6788f09f505e776ddcfe2f0e8e770637510615ee Mon Sep 17 00:00:00 2001 From: adipaul1981 Date: Wed, 16 Mar 2022 12:14:12 -0400 Subject: [PATCH] fix (#56) --- .../family-clinical-data/generateFamilySqon.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/reports/family-clinical-data/generateFamilySqon.ts b/src/reports/family-clinical-data/generateFamilySqon.ts index 72cdfbf..784630c 100644 --- a/src/reports/family-clinical-data/generateFamilySqon.ts +++ b/src/reports/family-clinical-data/generateFamilySqon.ts @@ -4,9 +4,9 @@ import { buildQuery } from '@arranger/middleware'; import { getExtendedConfigs, getNestedFields } from '../../utils/arrangerUtils'; import { executeSearch } from '../../utils/esUtils'; import { Client } from '@elastic/elasticsearch'; -import { Sqon } from '../../utils/setsTypes'; import { resolveSetsInSqon } from '../../utils/sqonUtils'; import { ProjectType } from '../types'; +import { Sqon } from '../../utils/setsTypes'; /** * Generate a sqon from the family_id of all the participants in the given `sqon`. @@ -16,6 +16,7 @@ import { ProjectType } from '../types'; * @param {object} normalizedConfigs - the normalized report configuration. * @param {string} userId - the user id. * @param {string} accessToken - the user access token. + * @param {string} program - the program the report will run on. * @returns {object} - A sqon of all the `family_id`. */ export default async ( @@ -31,6 +32,10 @@ export default async ( const nestedFields = getNestedFields(extendedConfig); const newSqon = await resolveSetsInSqon(sqon, userId, accessToken); const query = buildQuery({ nestedFields, filters: newSqon }); + + const participantIds = (sqon.content || []).filter(e => (e.content?.field || '') === 'participant_id')[0].content + .value; + const field = program.toLowerCase() === ProjectType.include ? 'family.family_id' : 'family_id'; const esRequest = { query, @@ -45,7 +50,7 @@ export default async ( const familyIds = buckets.map(b => b.key); return { - op: 'and', + op: 'or', content: [ { op: 'in', @@ -54,6 +59,13 @@ export default async ( value: familyIds, }, }, + { + op: 'in', + content: { + field: 'participant_id', + value: participantIds, + }, + }, ], }; };