Skip to content

Commit

Permalink
🔧 Add index selection in Venn and queryPillSqons support
Browse files Browse the repository at this point in the history
  • Loading branch information
evans-g-crsj committed Jan 31, 2025
1 parent 6a3c513 commit b76bf75
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
15 changes: 13 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,27 @@ export default (keycloak: Keycloak, getProject: (projectId: string) => ArrangerP
res.status(StatusCodes.UNPROCESSABLE_ENTITY).send('Bad Inputs');
return;
}

if (!req.body?.queryPillSqons || req.body.queryPillSqons.length !== req.body.sqons.length) {
res.status(StatusCodes.UNPROCESSABLE_ENTITY).send('Bad Inputs');
return;
}

// Convert sqon(s) with set_id if exists to intelligible sqon for ES query translation.
const { resolvedSqons: sqons, m: mSetItToIds } = await resolveSetsInAllSqonsWithMapper(
req.body.sqons,
null,
req.headers.authorization,
);
const data1 = await venn(sqons);

const index = ['participant', 'file', 'biospecimen'].includes(req.body?.index)
? req.body.index
: 'participant';

const data1 = await venn(sqons, index);
const data2 = data1.map(x => ({ ...x, sqon: replaceIdsWithSetId(x.sqon, mSetItToIds) }));
res.send({
data: reformatVenn(data2),
data: reformatVenn(data2, req.body.queryPillSqons),
});
} catch (e) {
next(e);
Expand Down
25 changes: 15 additions & 10 deletions src/endpoints/venn/venn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type OutputReformattedElement = Output & {
};

type OutputReformatted = {
summary: OutputReformattedElement[];
summary: (OutputReformattedElement & { queryPillSqon?: Sqon })[];
operations: OutputReformattedElement[];
};

Expand Down Expand Up @@ -86,21 +86,20 @@ const setFormulasTrio = (s1: Sqon, s2: Sqon, s3: Sqon) => [
},
];

let nestedFields: string[] = null;
//let nestedFields: string[] = null;

export const venn = async (sqons: Sqon[]): Promise<Output[]> => {
export const venn = async (sqons: Sqon[], index: string): Promise<Output[]> => {
const setFormulas =
sqons.length === 2 ? setFormulasDuo(sqons[0], sqons[1]) : setFormulasTrio(sqons[0], sqons[1], sqons[2]);

const client = EsInstance.getInstance();
const needToFetchMapping = !nestedFields || nestedFields.length === 0;
if (needToFetchMapping) {
nestedFields = await getNestedFieldsForIndex(client, 'participant_centric');
}
const indexName = `${index}_centric`;
//const needToFetchMapping = !nestedFields || nestedFields.length === 0;
const nestedFields = await getNestedFieldsForIndex(client, indexName);

const mSearchBody = setFormulas
.map(x => [
{},
{ index: indexName },
{
track_total_hits: true,
size: 0,
Expand All @@ -124,11 +123,17 @@ export const venn = async (sqons: Sqon[]): Promise<Output[]> => {
}));
};

export const reformatVenn = (data: Output[]): OutputReformatted => {
export const reformatVenn = (data: Output[], queryPillSqons: Sqon[]): OutputReformatted => {
const tables = data.reduce(
(xs: OutputReformatted, x: OutputReformattedElement) => {
const queryPillSqon = {
['Q₁']: queryPillSqons[0],
['Q₂']: queryPillSqons[1],
['Q₃']: queryPillSqons[2],
};

if (['Q₁', 'Q₂', 'Q₃'].some(y => y === x.operation)) {
return { ...xs, summary: [...xs.summary, x] };
return { ...xs, summary: [...xs.summary, { ...x, queryPillSqon: queryPillSqon[x.operation] }] };
}
return { ...xs, operations: [...xs.operations, x] };
},
Expand Down

0 comments on commit b76bf75

Please sign in to comment.