diff --git a/components/report_cards/chemical_probe/EubopenCompoundReportCard.vue b/components/report_cards/chemical_probe/EubopenCompoundReportCard.vue index 44e580cf25a425c2d74b11fd8b86cdf3dd34fe66..b6751539b19ea2c1b5df7d956fc952c1698bf5e0 100644 --- a/components/report_cards/chemical_probe/EubopenCompoundReportCard.vue +++ b/components/report_cards/chemical_probe/EubopenCompoundReportCard.vue @@ -37,79 +37,94 @@ export default { return state[this.storeModuleName].reportCardStructure }, }), - mounted() { - const docSource = [ - 'pref_name', - '_metadata.eubopen.is_probe', - '_metadata.eubopen.is_control', - ] - const entityID = EntityNames.EubopenCompound.entityID - const indexName = IndexNames.getIndexNameFromEntityID(entityID) + async mounted() { + try { + const paramsFromCompound = await this.getOptionalSectionsParams() + const showCellHeatlhAndViabilityData = await this.hasCellHeatlhAndViabilityData() + const reportCardStructure = CompoundReportCardGenerator.generateReportCardStructure( + this.itemID, + paramsFromCompound.prefName, + { + isChemicalProbe: paramsFromCompound.isChemicalProbe, + isNegativeControl: paramsFromCompound.isNegativeControl, + showCellHeatlhAndViabilityData, + } + ) - ESProxyService.getESDocument(indexName, this.itemID, docSource) - .then((response) => { - const sourceObtained = response.data._source - const prefName = ObjectPropertyAccess.getPropertyPalue( - sourceObtained, - 'pref_name', - '', - false - ) + this.$store.dispatch( + `${this.storeModuleName}/setReportCardStructure`, + reportCardStructure + ) - const isChemicalProbe = ObjectPropertyAccess.getPropertyPalue( - sourceObtained, - '_metadata.eubopen.is_probe', - false - ) + this.$store.dispatch(`${this.storeModuleName}/setStructureReady`, true) + } catch (error) { + ErrorTracking.trackError(error, this) - const isNegativeControl = ObjectPropertyAccess.getPropertyPalue( - sourceObtained, - '_metadata.eubopen.is_control', - false - ) + RequestNotifications.dispatchRequestErrorNotification( + error, + this.$store.dispatch, + `There was an error while loading the page structure` + ) + } + }, + methods: { + async getOptionalSectionsParams() { + const docSource = [ + 'pref_name', + '_metadata.eubopen.is_probe', + '_metadata.eubopen.is_control', + ] + const entityID = EntityNames.EubopenCompound.entityID + const indexName = IndexNames.getIndexNameFromEntityID(entityID) + + const compoundData = await ESProxyService.getESDocument( + indexName, + this.itemID, + docSource + ) - const cellHeatlhAndViabilityDataPath = `/eubopen/visualisations/compound/cell_viability_and_health_data/${this.itemID}` + const prefName = ObjectPropertyAccess.getPropertyPalue( + compoundData, + 'pref_name', + '' + ) - ESProxyService.getGenericData(cellHeatlhAndViabilityDataPath) - .then((response) => { - const numDataPoints = response.data.num_datapoints - const showCellHeatlhAndViabilityData = numDataPoints > 0 - const reportCardStructure = CompoundReportCardGenerator.generateReportCardStructure( - this.itemID, - prefName, - isChemicalProbe, - isNegativeControl, - showCellHeatlhAndViabilityData - ) - this.$store.dispatch( - `${this.storeModuleName}/setReportCardStructure`, - reportCardStructure - ) + const isChemicalProbe = ObjectPropertyAccess.getPropertyPalue( + compoundData, + '_metadata.eubopen.is_probe', + false + ) - this.$store.dispatch( - `${this.storeModuleName}/setStructureReady`, - true - ) - }) - .catch((error) => { - ErrorTracking.trackError(error, this) + const isNegativeControl = ObjectPropertyAccess.getPropertyPalue( + compoundData, + '_metadata.eubopen.is_control', + false + ) - RequestNotifications.dispatchRequestErrorNotification( - error, - this.$store.dispatch, - `Target Classifications: There was an error while loading the Cell Viability and Health Data!` - ) - }) - }) - .catch((error) => { - ErrorTracking.trackError(error, this) + return { + prefName, + isChemicalProbe, + isNegativeControl, + } + }, + async hasCellHeatlhAndViabilityData() { + const chemblIDResponse = await ESProxyService.getESDocument( + IndexNames.getIndexNameFromEntityID( + EntityNames.EubopenCompound.entityID + ), + this.itemID, + ['molecule_chembl_id'] + ) + + const chemblID = chemblIDResponse.data._source.molecule_chembl_id + const cellHeatlhAndViabilityDataPath = `/eubopen/visualisations/compound/cell_viability_and_health_data/${chemblID}` + const cellHealthAndViabilityData = await ESProxyService.getGenericData( + cellHeatlhAndViabilityDataPath + ) - RequestNotifications.dispatchRequestErrorNotification( - error, - this.$store.dispatch, - `There was an error while loading the page structure` - ) - }) + const numDataPoints = cellHealthAndViabilityData.data.num_datapoints + return numDataPoints > 0 + }, }, } </script> diff --git a/report_cards_structure/CompoundReportCardGenerator.js b/report_cards_structure/CompoundReportCardGenerator.js index 1cd992833068d170be6eec24a9ac3aea4de083f7..39e60db027e7528eea8533028b025d015ecd7c61 100644 --- a/report_cards_structure/CompoundReportCardGenerator.js +++ b/report_cards_structure/CompoundReportCardGenerator.js @@ -13,9 +13,7 @@ const methods = { generateReportCardStructure( itemID, prefName, - isChemicalProbe, - isNegativeControl, - showCellHeatlhAndViabilityData + { isChemicalProbe, isNegativeControl, showCellHeatlhAndViabilityData } ) { const basePageStructure = [ {