Skip to content

Commit

Permalink
Merge pull request #1028 from griffithlab/feature/asco-sources
Browse files Browse the repository at this point in the history
Switches to using ASCO IDs instead of Numbers throughout the client
  • Loading branch information
jmcmichael authored Jan 17, 2019
2 parents a752259 + 9b3d558 commit fbc5fd2
Show file tree
Hide file tree
Showing 23 changed files with 569 additions and 246 deletions.
2 changes: 1 addition & 1 deletion src/app/views/add/evidence/AddEvidenceController.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
controllerAs: 'vm'
})
.state('add.evidence.basic', {
url: '/basic?geneId&variantId&geneName&variantName&diseaseName&pubmedId&sourceSuggestionId&variantOrigin&evidenceType&evidenceDirection&evidenceLevel&clinicalSignificance',
url: '/basic?geneId&variantId&geneName&variantName&diseaseName&pubmedId&sourceType&sourceId&variantOrigin&evidenceType&evidenceDirection&evidenceLevel&clinicalSignificance&isSuggestedSource',
template: '<add-evidence-basic></add-evidence-basic>',
data: {
titleExp: '"Add Evidence"',
Expand Down
187 changes: 127 additions & 60 deletions src/app/views/add/evidence/addEvidenceBasic.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@
vm.newEvidence = {
gene: '',
variant: '',
pubmed_id: '',
source: {citation_id: '', source_type: ''},
description: '',
disease: {
name: ''
},
disease_name: '',
noDoid: false,
//pubchem_id: '',
drugs: [],
drug_interaction_type: null,
rating: '',
Expand All @@ -96,7 +95,7 @@
vm.newEvidence.comment = { title: 'Additional Comments', text:'' };
vm.newEvidence.drugs = [];

vm.newEvidence.source_suggestion_id = _.isUndefined($stateParams.sourceSuggestionId) ? null : Number($stateParams.sourceSuggestionId);
vm.newEvidence.source_suggestion_id = _.isUndefined($stateParams.sourceId) ? null : Number($stateParams.sourceId);

vm.formErrors = {};
vm.formMessages = {};
Expand Down Expand Up @@ -204,60 +203,122 @@
}
}
},

{
key: 'pubmed_id',
type: 'publication',
key: 'source.source_type',
type: 'horizontalSelectHelp',
wrapper: 'attributeDefinition',
controller: /* @ngInject */ function($scope, $stateParams, ConfigService, _) {
if($stateParams.sourceType) {
var st = $stateParams.sourceType;
var permitted = _.keys(ConfigService.evidenceAttributeDescriptions.source_type);
if(_.includes(permitted, st)) {
$scope.model.source_type = st;
$scope.to.data.attributeDefinition = $scope.to.data.attributeDefinitions[st];
// update source field info
// this unfortunately reproduces code in onChange below, but updating value above doesn't trigger onChange...
var sourceField = _.find($scope.fields, { key: 'source.citation_id'});
sourceField.templateOptions.data.sourceType = st;
} else {
console.warn('Ignoring pre-population of Source Type with invalid value: ' + st);
}
}
},
templateOptions: {
label: 'Pubmed ID',
value: 'vm.newEvidence.pubmed_id',
minLength: 1,
label: 'Source Type',
required: true,
options: [{ value: '', label: 'Please select a Source Type' }].concat(make_options(descriptions.source_type)),
valueProp: 'value',
labelProp: 'label',
helpText: help['Source Type'],
data: {
description: '--'
attributeDefinition: '&nbsp;',
attributeDefinitions: descriptions.source_type
},
helpText: help['Pubmed ID']
},
modelOptions: {
updateOn: 'default blur',
allowInvalid: false,
debounce: {
default: 300,
blur: 0
}
},
controller: /* @ngInject */ function($scope, $stateParams) {
if($stateParams.pubmedId) {
$scope.model.pubmed_id = $stateParams.pubmedId;
onChange: function(value, options, scope) {
// field value is showing up undefined here for some reason, accessing it via options
var val = options.value();
// set attribute definition
options.templateOptions.data.attributeDefinition = options.templateOptions.data.attributeDefinitions[val];
// set source_type on citation_id and clear field
var sourceField = _.find(scope.fields, { key: 'source.citation_id'});
sourceField.value('');
sourceField.templateOptions.data.citation = '--';
if(val) { sourceField.templateOptions.data.sourceType = val; }
else { sourceField.templateOptions.data.sourceType = undefined; }
}
}
},
{
key: 'source.citation_id',
type: 'publication',
templateOptions: {
label: 'Source ID',
required: true,
data: {
citation: '--',
sourceType: undefined,
},
},
validators: {
validPubmedId: {
asyncValidators: {
validId: {
expression: function($viewValue, $modelValue, scope) {
if ($viewValue.length > 0) {
if ($viewValue.match(/[^0-9]+/)) { return false; }
var deferred = $q.defer();
var type = scope.model.source.source_type;
var deferred = $q.defer();
if ($viewValue.length > 0 && type !== '') {
if ($viewValue.match(/[^0-9]+/)) { return false; } // must be number
scope.options.templateOptions.loading = true;
Publications.verify($viewValue).then(
var reqObj = {
citationId: $viewValue,
sourceType: type
};
Publications.verify(reqObj).then(
function (response) {
scope.options.templateOptions.loading = false;
scope.options.templateOptions.data.description = response.description;
deferred.resolve(response);
scope.options.templateOptions.data.citation = response.citation;
deferred.resolve(true);
},
function (error) {
scope.options.templateOptions.loading = false;
scope.options.templateOptions.data.description = '--';
deferred.reject(error);
if(error.status === 404) {
scope.options.templateOptions.data.citation = 'No ' + type + ' source found with specified ID.';
} else {
scope.options.templateOptions.data.citation = 'Error fetching source, check console log for details.';
}
deferred.reject(false);
}
);
return deferred.promise;
} else {
scope.options.templateOptions.data.description = '--';
return true;
deferred.resolve(true);
}
return deferred.promise;
},
message: '"This does not appear to be a valid Pubmed ID."'
message: '"This does not appear to be a valid source ID."'
}
},
controller: /* @ngInject */ function($scope, $stateParams) {
if($stateParams.sourceId) {
// get citation
Sources.get($stateParams.sourceId)
.then(function(response){
$scope.model.source = response;
$scope.to.data.citation = response.citation;
});
}
},
expressionProperties: {
'templateOptions.disabled': 'to.data.sourceType === "" || to.data.sourceType === undefined',
'templateOptions.label': 'to.data.sourceType ? to.data.sourceType === "ASCO" ? "ASCO Web ID" : "PubMed ID" : "Source ID"',
'templateOptions.placeholder': 'to.data.sourceType ? to.data.sourceType === "ASCO" ? "Search by ASCO Abstract Number" : "Search by PubMed ID" : "Please select Source Type"',
// ng expressions here don't have access to config help objects, so we must clumsily insert them into the expression here
'templateOptions.helpText': 'to.data.sourceType ? to.data.sourceType === "ASCO" ? "' + help['SourceASCO'] + '" : "' + help['SourcePubMed'] + '" : "Please enter a Source Type before entering a Source ID."',
},
modelOptions: {
debounce: {
default: 300,
blur: 0
},
updateOn: 'default blur'
}
},
{ // duplicates warning row
Expand All @@ -268,28 +329,31 @@
vm.pubmedName = '';

function searchForDups(values) {
vm.duplicates = [];
if(_.every(values, function(val) { return _.isString(val) && val.length > 0; })) {
vm.duplicates = [];
Search.post({
'operator': 'AND',
'queries': [
{
'field': 'gene_name',
'condition': {'name': 'contains', 'parameters': [values[0]]}
},
{
'field': 'variant_name',
'condition': {'name': 'contains', 'parameters': [values[1]]}
},
{
'field': 'pubmed_id',
'condition': {'name': 'is', 'parameters': [values[2]]
}
}
],
'entity': 'evidence_items',
'save': false
})
'operator': 'AND',
'queries': [
{
'field': 'gene_name',
'condition': {'name': 'contains', 'parameters': [values[0]]}
},
{
'field': 'variant_name',
'condition': {'name': 'contains', 'parameters': [values[1]]}
},
{
'field': 'source_type',
'condition': {'name': 'is_equal_to', 'parameters': [values[2]]}
},
{
'field': 'citation_id',
'condition': {'name': 'is_equal_to', 'parameters': [values[3]]}
}
],
'entity': 'evidence_items',
'save': false
})
.then(function (response) {
vm.duplicates = response.results;
});
Expand All @@ -301,7 +365,8 @@
$scope.$watchGroup([
'model.gene.name',
'model.variant.name',
'model.pubmed_id'
'model.source_type',
'model.source.citation_id'
], searchForDups);
}
},
Expand All @@ -323,6 +388,7 @@
},
templateOptions: {
label: 'Variant Origin',
required: true,
value: 'vm.newEvidence.variant_origin',
options: [{ value: '', label: 'Please select a Variant Origin' }].concat(make_options(descriptions.variant_origin)),
valueProp: 'value',
Expand Down Expand Up @@ -593,8 +659,8 @@
'templateOptions.options': function($viewValue, $modelValue, scope) {
return _.filter(scope.to.clinicalSignificanceOptions, function(option) {
return !!(option.type === scope.model.evidence_type ||
option.type === 'default' ||
option.type === 'N/A');
option.type === 'default' ||
option.type === 'N/A');
});
},
'templateOptions.disabled': 'model.evidence_type === ""' // deactivate if evidence_type unselected
Expand Down Expand Up @@ -656,7 +722,7 @@
},
hideExpression: function($viewValue, $modelValue, scope) {
return !(scope.model.evidence_type === 'Predictive' && // evidence type must be predictive
_.without(scope.model.drugs, '').length > 1);
_.without(scope.model.drugs, '').length > 1);
}
},
{
Expand Down Expand Up @@ -752,6 +818,7 @@
newEvidence.evidenceId = newEvidence.id;
newEvidence.drugs = _.without(newEvidence.drugs, '');
newEvidence.phenotypes = _.without(newEvidence.phenotypes, '');

if(newEvidence.drugs.length < 2) { newEvidence.drug_interaction_type = null; } // delete interaction if only 1 drug
// convert variant name to object, if a string
// TODO: figure out how to handle this more elegantly using angular-formly config object
Expand Down
27 changes: 23 additions & 4 deletions src/app/views/browse/directives/browseGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,27 @@
],
'sources': [
{
name: 'pubmed_id',
displayName: 'Pubmed ID',
name: 'source_type',
displayName: 'Type',
enableFiltering: true,
allowCellFocus: false,
cellTemplate: 'app/views/events/common/genericHighlightCell.tpl.html',
type: 'string',
width: '8%',
filter: {
type: uiGridConstants.filter.SELECT,
term: null,
disableCancelFilterButton: false,
selectOptions: [
{ value: null, label: '--' },
{ value: '0', label: 'PubMed'},
{ value: '1', label: 'ASCO'}
]
}
},
{
name: 'citation_id',
displayName: 'Citation ID',
enableFiltering: true,
allowCellFocus: false,
cellTemplate: 'app/views/events/common/genericHighlightCell.tpl.html',
Expand All @@ -770,7 +789,7 @@
enableFiltering: true,
allowCellFocus: false,
type: 'string',
width: '20%',
width: '15%',
cellTemplate: 'app/views/browse/directives/browseGridTooltipCell.tpl.html',
filter: {
condition: uiGridConstants.filter.CONTAINS
Expand All @@ -794,7 +813,7 @@
type: 'string',
enableFiltering: true,
allowCellFocus: false,
width: '15%',
width: '12%',
cellTemplate: 'app/views/browse/directives/browseGridTooltipCell.tpl.html',
filter: {
condition: uiGridConstants.filter.CONTAINS
Expand Down
Loading

0 comments on commit fbc5fd2

Please sign in to comment.