From 43941c3d95b4f0ccd544457158aef289b1f14e08 Mon Sep 17 00:00:00 2001 From: sshugsc Date: Mon, 16 Dec 2024 11:15:21 -0800 Subject: [PATCH 1/2] add minimal scope to kbMatches --- app/models/reports/kbMatches.js | 3 ++ app/routes/report/report.js | 57 ++++----------------------------- 2 files changed, 9 insertions(+), 51 deletions(-) diff --git a/app/models/reports/kbMatches.js b/app/models/reports/kbMatches.js index 12f496075..a6d62ab9d 100644 --- a/app/models/reports/kbMatches.js +++ b/app/models/reports/kbMatches.js @@ -46,6 +46,9 @@ module.exports = (sequelize, Sq) => { return {model: sequelize.models[modelName].scope('public'), as: modelName}; }), }, + minimal: { + attributes: {exclude: ['id', 'reportId', 'variantId', 'deletedAt', 'updatedBy']}, + }, extended: { attributes: {exclude: ['id', 'reportId', 'variantId', 'deletedAt', 'updatedBy']}, include: Object.values(KB_PIVOT_MAPPING).map((modelName) => { diff --git a/app/routes/report/report.js b/app/routes/report/report.js index 6c2503f89..eef2f4c4f 100644 --- a/app/routes/report/report.js +++ b/app/routes/report/report.js @@ -105,7 +105,7 @@ router.route('/') .get(async (req, res) => { let { query: { - paginated, limit, offset, sort, project, states, role, searchText, keyVariant, matchingThreshold, category, approvedTherapy, kbVariant, disease, relevance, context, status, reference, sample, evidenceLevel, matchedCancer, pmidRef, variantType, + paginated, limit, offset, sort, project, states, role, searchText, keyVariant, matchingThreshold, kbVariant }, } = req; @@ -125,7 +125,7 @@ router.route('/') try { // validate request query parameters validateAgainstSchema(reportGetSchema, { - paginated, limit, offset, sort, project, states, role, searchText, keyVariant, matchingThreshold, category, approvedTherapy, kbVariant, disease, relevance, context, status, reference, sample, evidenceLevel, matchedCancer, pmidRef, variantType, + paginated, limit, offset, sort, project, states, role, searchText, keyVariant, matchingThreshold, kbVariant }, false); } catch (err) { const message = `Error while validating the query params of the report GET request ${err}`; @@ -184,15 +184,12 @@ router.route('/') ...((kbVariant && matchingThreshold) ? { '$kbMatches.kb_variant$': { [Op.in]: literal( - `(SELECT "kb_variant" - FROM (SELECT "kb_variant", word_similarity('${kbVariant}', "kb_variant") FROM reports_kb_matches) AS subquery + `(SELECT "kb_variant" + FROM (SELECT "kb_variant", word_similarity('${kbVariant}', "kb_variant") FROM reports_kb_matches) AS subquery WHERE word_similarity >= ${matchingThreshold})`, ), }, } : {}), - ...((variantType) ? { - '$kbMatches.variant_type$': {[Op.eq]: `${variantType}`}, - } : {}), }, distinct: 'id', // **searchText with paginated with patientInformation set to required: true @@ -262,51 +259,9 @@ router.route('/') model: db.models.genomicAlterationsIdentified.scope('public'), as: 'genomicAlterationsIdentified', }] : []), - ...((category || approvedTherapy || kbVariant || disease || relevance || context || status || reference || sample || evidenceLevel || matchedCancer || pmidRef || variantType) ? [{ - model: db.models.kbMatches.scope('public'), + ...((kbVariant && matchingThreshold) ? [{ + model: db.models.kbMatches.scope('minimal'), as: 'kbMatches', - include: [ - { - model: db.models.kbMatchedStatements.scope('kbMatchesInclude'), - as: 'kbMatchedStatements', - through: {attributes: []}, - where: { - ...((category) ? { - category: {[Op.eq]: `${category}`}, - } : {}), - ...((approvedTherapy) ? { - approvedTherapy: {[Op.eq]: `${approvedTherapy}`}, - } : {}), - ...((disease) ? { - disease: {[Op.eq]: `${disease}`}, - } : {}), - ...((relevance) ? { - relevance: {[Op.eq]: `${relevance}`}, - } : {}), - ...((context) ? { - context: {[Op.eq]: `${context}`}, - } : {}), - ...((status) ? { - status: {[Op.eq]: `${status}`}, - } : {}), - ...((reference) ? { - reference: {[Op.eq]: `${reference}`}, - } : {}), - ...((sample) ? { - sample: {[Op.eq]: `${sample}`}, - } : {}), - ...((evidenceLevel) ? { - evidence_level: {[Op.eq]: `${evidenceLevel}`}, - } : {}), - ...((matchedCancer) ? { - matched_cancer: {[Op.eq]: `${matchedCancer}`}, - } : {}), - ...((pmidRef) ? { - pmid_ref: {[Op.eq]: `${pmidRef}`}, - } : {}), - }, - }, - ], }] : []), ], }; From 2c337565517b0f484d20053e42766afac109f26d Mon Sep 17 00:00:00 2001 From: sshugsc Date: Mon, 16 Dec 2024 11:26:39 -0800 Subject: [PATCH 2/2] lint & test --- app/routes/report/report.js | 4 ++-- test/routes/report/report.test.js | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/routes/report/report.js b/app/routes/report/report.js index eef2f4c4f..fe416bb81 100644 --- a/app/routes/report/report.js +++ b/app/routes/report/report.js @@ -105,7 +105,7 @@ router.route('/') .get(async (req, res) => { let { query: { - paginated, limit, offset, sort, project, states, role, searchText, keyVariant, matchingThreshold, kbVariant + paginated, limit, offset, sort, project, states, role, searchText, keyVariant, matchingThreshold, kbVariant, }, } = req; @@ -125,7 +125,7 @@ router.route('/') try { // validate request query parameters validateAgainstSchema(reportGetSchema, { - paginated, limit, offset, sort, project, states, role, searchText, keyVariant, matchingThreshold, kbVariant + paginated, limit, offset, sort, project, states, role, searchText, keyVariant, matchingThreshold, kbVariant, }, false); } catch (err) { const message = `Error while validating the query params of the report GET request ${err}`; diff --git a/test/routes/report/report.test.js b/test/routes/report/report.test.js index ab70c114b..ee84ccf82 100644 --- a/test/routes/report/report.test.js +++ b/test/routes/report/report.test.js @@ -68,6 +68,7 @@ describe('/reports/{REPORTID}', () => { const UNREVIEWED_ACCESS = 'unreviewed Access'; const KEYVARIANT = 'uniqueKeyVariant'; + const KBVARIANT = 'uniqueKbVariant'; let project; let project2; @@ -503,7 +504,7 @@ describe('/reports/{REPORTID}', () => { test('/ - kb match - 200 Success', async () => { const res = await request - .get('/api/reports?category=unknown&variantType=cnv') + .get(`/api/reports?kbVariant=${KBVARIANT}&&matchingThreshold=1`) .auth(username, password) .type('json') .expect(HTTP_STATUS.OK); @@ -512,7 +513,7 @@ describe('/reports/{REPORTID}', () => { for (const resReport of res.body.reports) { for (const gAI of resReport.kbMatches) { - expect(gAI.variantType).toEqual('cnv'); + expect(gAI.kbVariant).toEqual(KBVARIANT); } } }, LONGER_TIMEOUT);