Skip to content

Commit

Permalink
fix (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
adipaul1981 authored Mar 16, 2022
1 parent 54c8990 commit 6788f09
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/reports/family-clinical-data/generateFamilySqon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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 (
Expand All @@ -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,
Expand All @@ -45,7 +50,7 @@ export default async (
const familyIds = buckets.map(b => b.key);

return {
op: 'and',
op: 'or',
content: [
{
op: 'in',
Expand All @@ -54,6 +59,13 @@ export default async (
value: familyIds,
},
},
{
op: 'in',
content: {
field: 'participant_id',
value: participantIds,
},
},
],
};
};

0 comments on commit 6788f09

Please sign in to comment.