Skip to content
Snippets Groups Projects
Commit c6e2fab6 authored by David Mendez's avatar David Mendez
Browse files

eubopen compound: refactor generation of report card structure by using async functions

parent ed5d846f
No related branches found
No related tags found
1 merge request!88Changes for the Midterm Review
......@@ -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>
......
......@@ -13,9 +13,7 @@ const methods = {
generateReportCardStructure(
itemID,
prefName,
isChemicalProbe,
isNegativeControl,
showCellHeatlhAndViabilityData
{ isChemicalProbe, isNegativeControl, showCellHeatlhAndViabilityData }
) {
const basePageStructure = [
{
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment