Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix/DEVSU-2492 add minimal scope to kbmatch #411

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/models/reports/kbMatches.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
57 changes: 6 additions & 51 deletions app/routes/report/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
elewis2 marked this conversation as resolved.
Show resolved Hide resolved
},
} = req;

Expand All @@ -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}`;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}`},
} : {}),
},
},
],
}] : []),
],
};
Expand Down
5 changes: 3 additions & 2 deletions test/routes/report/report.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe('/reports/{REPORTID}', () => {
const UNREVIEWED_ACCESS = 'unreviewed Access';

const KEYVARIANT = 'uniqueKeyVariant';
const KBVARIANT = 'uniqueKbVariant';

let project;
let project2;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Loading