Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

[FIX] Implemented logic to handle cases where no diagnosis/assessment exist in the graph #350

Merged
merged 6 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 5 additions & 13 deletions components/QueryForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@
@update-categorical-field="updateField"
/>
<div>
<hr>
</div>
<b-row>
<h5>Imaging fields</h5>
</b-row>
<hr>
</div>
<b-row>
<h5>Imaging fields</h5>
</b-row>
rmanaem marked this conversation as resolved.
Show resolved Hide resolved
<categorical-field
name="Imaging modality"
data-cy="modality-field"
Expand Down Expand Up @@ -168,14 +168,6 @@ export default {
return url.endsWith('/') ? `${url}query/?` : `${url}/query/?`;
},
},
mounted() {
if (Object.keys(this.categoricalOptions.Diagnosis).length <= 1) {
this.displayToast('Failed to retrieve diagnosis options');
}
if (Object.keys(this.categoricalOptions['Assessment tool']).length <= 1) {
this.displayToast('Failed to retrieve assessment tool options');
}
},
methods: {
updateField(name, input) {
switch (name) {
Expand Down
10 changes: 0 additions & 10 deletions cypress/component/QueryForm.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,6 @@ describe('Query form', () => {
cy.get('[data-cy=submit-query]').click();
cy.wrap(getStub).should('have.been.calledWith', 'http://my.site.org/query/?');
});
it('Displays a toast when diagnosis and assessment tool options are not retrieved', () => {
props.categoricalOptions.Diagnosis = { All: null };
props.categoricalOptions['Assessment tool'] = { All: null };
cy.mount(QueryForm, {
stubs,
propsData: props,
});
cy.contains('#b-toaster-top-right', 'Failed to retrieve diagnosis options');
cy.contains('#b-toaster-top-right', 'Failed to retrieve assessment tool options');
});
it('Displays the healthy control tooltip', () => {
cy.mount(QueryForm, {
stubs,
Expand Down
32 changes: 31 additions & 1 deletion cypress/e2e/APIRequest.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mixedResponse } from '../fixtures/example-responses';
import { mixedResponse, emptyDiagnosisOptions, emptyAssessmentToolOptions } from '../fixtures/example-responses';

describe('API request', () => {
it('Intercepts the request sent to the API and asserts over the request url', () => {
Expand All @@ -19,4 +19,34 @@ describe('API request', () => {
cy.get('[data-cy="submit-query"]').click();
cy.wait('@call').its('request.url').should('contains', '&min_age=10&max_age=30');
});
it('Empty responses for diagnosis and Assessment make a toast appear', () => {
cy.intercept({
method: 'GET',
url: '/attributes/nb:Diagnosis',
}, emptyDiagnosisOptions).as('getDiagnosisOptions');
cy.intercept({
method: 'GET',
url: '/attributes/nb:Assessment',
}, emptyAssessmentToolOptions).as('getAssessmentToolOptions');
cy.visit('/');
cy.wait('@getDiagnosisOptions');
cy.contains('#b-toaster-top-right', 'No diagnosis options were available');
cy.wait('@getAssessmentToolOptions');
cy.contains('#b-toaster-top-right', 'No assessment tool options were available');
});
it('Failed responses for diagnosis and assessment make an error toast appear', () => {
cy.intercept({
method: 'GET',
url: '/attributes/nb:Diagnosis',
}, { statusCode: 500 }).as('getDiagnosisOptions');
cy.intercept({
method: 'GET',
url: '/attributes/nb:Assessment',
}, { statusCode: 500 }).as('getAssessmentToolOptions');
cy.visit('/');
cy.wait('@getDiagnosisOptions');
cy.contains('#b-toaster-top-right', 'Failed to retrieve diagnosis options');
cy.wait('@getAssessmentToolOptions');
cy.contains('#b-toaster-top-right', 'Failed to retrieve assessment tool options');
});
});
8 changes: 8 additions & 0 deletions cypress/fixtures/example-responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,11 @@ export const mixedResponse = [
},

];

export const emptyDiagnosisOptions = {
'nb:Diagnosis': [],
};

export const emptyAssessmentToolOptions = {
'nb:Assessment': [],
};
50 changes: 40 additions & 10 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,39 @@ export default {
async fetch() {
const apiQueryURL = this.$config.apiQueryURL.endsWith('/') ? `${this.$config.apiQueryURL}` : `${this.$config.apiQueryURL}/`;

const diagnosisResponse = await this.$axios.get(`${apiQueryURL}attributes/nb:Diagnosis`);
const diagnosisOptions = diagnosisResponse.data['nb:Diagnosis'].reduce((tempArray, diagnosis) => ({
...tempArray,
[diagnosis.Label]: diagnosis.TermURL,
}), {});
let diagnosisOptions = {};
try {
const diagnosisResponse = await this.$axios.get(`${apiQueryURL}attributes/nb:Diagnosis`);
if (diagnosisResponse.data['nb:Diagnosis'].length === 0) {
this.displayToast('No diagnosis options were available', 'Info', 'info');
} else {
diagnosisOptions = diagnosisResponse.data['nb:Diagnosis'].reduce((tempArray, diagnosis) => ({
...tempArray,
[diagnosis.Label]: diagnosis.TermURL,
}), {});
}
} catch (err) {
this.displayToast('Failed to retrieve diagnosis options');
}

diagnosisOptions.All = null;
this.categoricalOptions.Diagnosis = diagnosisOptions;

const assessmentResponse = await this.$axios.get(`${apiQueryURL}attributes/nb:Assessment`);
const assessmentOptions = assessmentResponse.data['nb:Assessment'].reduce((tempArray, assessment) => ({
...tempArray,
[assessment.Label]: assessment.TermURL,
}), {});
let assessmentOptions = {};
try {
const assessmentResponse = await this.$axios.get(`${apiQueryURL}attributes/nb:Assessment`);
if (assessmentResponse.data['nb:Assessment'].length === 0) {
this.displayToast('No assessment tool options were available', 'Info', 'info');
} else {
assessmentOptions = assessmentResponse.data['nb:Assessment']?.reduce((tempArray, assessment) => ({
...tempArray,
[assessment.Label]: assessment.TermURL,
}), {});
}
} catch (err) {
this.displayToast('Failed to retrieve assessment tool options');
}

assessmentOptions.All = null;
this.categoricalOptions['Assessment tool'] = assessmentOptions;

Expand Down Expand Up @@ -188,6 +208,16 @@ export default {
dismissAlert() {
this.alertDismissed = true;
},
displayToast(message, title = 'Error', variant = 'danger') {
this.$bvToast.toast(message, {
appendToast: true,
autoHideDelay: '5000',
noCloseButton: true,
solid: true,
title,
variant,
});
},
},
};
</script>
Expand Down