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

Extending the Cohort Generation page with a pertaining cohort covariates checkbox #2982

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions js/pages/cohort-definitions/cohort-definition-manager.html
Original file line number Diff line number Diff line change
Expand Up @@ -793,4 +793,13 @@ <h3 data-bind="text: ko.i18n('cohortDefinitions.cohortDefinitionManager.panels.a
</div>
</script>

<script type="text/html" id="generation-checkbox-retainCovariates">
<span>
<input class="hover-toolbox" type="checkbox" data-bind="attr:{ id: $data.sourceKey } , checked: retainCovariates, tooltip: 'Generate with Retain Covariates', eventListener: [
{event: 'mouseover', selector: 'input', callback: $component.addToolTipCovariates },
{event: 'mouseout', selector: 'input', callback: $component.removeToolTipCovariates },
{event: 'mouseup', selector: 'input', callback: $component.handleRetainCovariates }]" data-placement="right"/>
</span>
</script>

<!-- /ko -->
99 changes: 92 additions & 7 deletions js/pages/cohort-definitions/cohort-definition-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ define(['jquery', 'knockout', 'text!./cohort-definition-manager.html',
'utilities/sql',
'components/conceptset/conceptset-list',
'components/name-validation',
'components/versions/versions'
'components/versions/versions',
'databindings/tooltipBinding'
], function (
$,
ko,
Expand Down Expand Up @@ -583,10 +584,6 @@ define(['jquery', 'knockout', 'text!./cohort-definition-manager.html',

this.sourcesTableOptions = commonUtils.getTableOptions('S');
this.sourcesColumns = [{
sortable: false,
className: 'generation-buttons-column',
render: () => `<span data-bind="template: { name: 'generation-buttons', data: $data }"></span>`
}, {
title: `<span>${ko.i18n('cohortDefinitions.cohortDefinitionManager.panels.sourceName', 'Source Name')()}</span>`,
data: 'name'
}, {
Expand All @@ -604,6 +601,17 @@ define(['jquery', 'knockout', 'text!./cohort-definition-manager.html',
}, {
title: ko.i18n('cohortDefinitions.cohortDefinitionManager.panels.generationDuration', 'Generation Duration'),
data: 'executionDuration'
}, {
title: ko.i18n('cohortDefinitions.cohortDefinitionManager.panels.retainCovariates', 'Retain Covariates'),
data: 'retainCovariates',
sortable: false,
tooltip: 'Generate with Retain Covariates',
render: () =>
`<span data-bind="template: {name: 'generation-checkbox-retainCovariates', data: $data }"></span>`
},{
sortable: false,
className: 'generation-buttons-column',
render: () => `<span data-bind="template: { name: 'generation-buttons', data: $data }"></span>`
}];

this.stopping = ko.pureComputed(() => this.cohortDefinitionSourceInfo().reduce((acc, target) => ({...acc, [target.sourceKey]: ko.observable(false)}), {}));
Expand Down Expand Up @@ -653,6 +661,7 @@ define(['jquery', 'knockout', 'text!./cohort-definition-manager.html',
source.personCount(commaFormatted(info.personCount));
source.recordCount(commaFormatted(info.recordCount));
source.failMessage(info.failMessage);
source.retainCovariates(info.chooseCovariates);
}
}
});
Expand Down Expand Up @@ -1094,13 +1103,25 @@ define(['jquery', 'knockout', 'text!./cohort-definition-manager.html',
if (this.selectedSource() && this.selectedSource().sourceId === source.sourceId) {
this.toggleCohortReport(null);
}
cohortDefinitionService.generate(this.currentCohortDefinition().id(), source.sourceKey)
cohortDefinitionService.generate(this.currentCohortDefinition().id(), source.sourceKey, source.retainCovariates())
.catch(this.authApi.handleAccessDenied)
.then(({data}) => {
jobDetailsService.createJob(data);
});
}

handleCheckboxCovariates(source) {
const targetSource = this.getSourceKeyInfo(source.sourceKey);
targetSource.retainCovariates(targetSource.retainCovariates());
const restSourceInfos = this.cohortDefinitionSourceInfo().filter(
(d) => {
return d.sourceKey !== source.sourceKey;
}
);

this.cohortDefinitionSourceInfo([...restSourceInfos, targetSource])
}

cancelGenerate (source) {
this.stopping()[source.sourceKey](true);
cohortDefinitionService.cancelGenerate(this.currentCohortDefinition().id(), source.sourceKey);
Expand Down Expand Up @@ -1261,6 +1282,8 @@ define(['jquery', 'knockout', 'text!./cohort-definition-manager.html',
}
cdsi.failMessage = ko.observable(sourceInfo.failMessage);
cdsi.createdBy = ko.observable(sourceInfo.createdBy);
cdsi.retainCovariates = ko.observable(sourceInfo?.retainCovariates || sourceInfo.chooseCovariates || false);
cdsi.tooltipCovariates = ko.observable(sourceInfo?.tooltipCovariates || null);
} else {
cdsi.isValid = ko.observable(false);
cdsi.isCanceled = ko.observable(false);
Expand All @@ -1271,6 +1294,8 @@ define(['jquery', 'knockout', 'text!./cohort-definition-manager.html',
cdsi.recordCount = ko.observable('n/a');
cdsi.failMessage = ko.observable(null);
cdsi.createdBy = ko.observable(null);
cdsi.retainCovariates = ko.observable(false);
cdsi.tooltipCovariates = ko.observable(null);
}
return cdsi;
}
Expand Down Expand Up @@ -1316,6 +1341,23 @@ define(['jquery', 'knockout', 'text!./cohort-definition-manager.html',

async prepareCohortDefinition(cohortDefinitionId, conceptSetId, selectedSourceId, sourceKey, versionNumber) {
this.isLoading(true);
ko.bindingHandlers.tooltip = {
init: function (element, valueAccessor) {
const value = ko.utils.unwrapObservable(valueAccessor());
$("[aria-label='Retain Covariates']").attr('data-original-title', 'Generate with Retain Covariates').bstooltip({
html: true,
container:'body',
});
$(element).attr('data-original-title', value).bstooltip({
html: true,
container:'body'
});
},
update: function (element, valueAccessor) {
const value = ko.utils.unwrapObservable(valueAccessor());
$(element).attr('data-original-title', value);
}
}
if(parseInt(cohortDefinitionId) === 0) {
this.setNewCohortDefinition();
} else if (versionNumber) {
Expand Down Expand Up @@ -1348,6 +1390,49 @@ define(['jquery', 'knockout', 'text!./cohort-definition-manager.html',
}
}

addToolTipCovariates(source){
const targetSource = this.getSourceKeyInfo(source?.sourceKey);
targetSource?.tooltipCovariates('Results with retained Covariates');
const restSourceInfos = this.cohortDefinitionSourceInfo().filter(
(d) => {
return d.sourceKey !== source?.sourceKey;
}
);
this.cohortDefinitionSourceInfo([
...restSourceInfos,
targetSource
])
}

removeToolTipCovariates(source){
const targetSource = this.getSourceKeyInfo(source?.sourceKey);
targetSource?.tooltipCovariates(null);
const restSourceInfos = this.cohortDefinitionSourceInfo().filter(
(d) => {
return d?.sourceKey !== source?.sourceKey;
}
);
this.cohortDefinitionSourceInfo([
...restSourceInfos,
targetSource
])
}

handleRetainCovariates(source) {
const targetSource = this.getSourceKeyInfo(source?.sourceKey);
targetSource.retainCovariates(!targetSource.retainCovariates());
targetSource?.tooltipCovariates(null);
const restSourceInfos = this.cohortDefinitionSourceInfo().filter(
(d) => {
return d?.sourceKey !== source?.sourceKey;
}
);
this.cohortDefinitionSourceInfo([
...restSourceInfos,
targetSource
])
}

checkifDataLoaded(cohortDefinitionId, conceptSetId, sourceKey) {
if (this.currentCohortDefinition() && this.currentCohortDefinition().id() == cohortDefinitionId) {
if (this.currentConceptSet() && this.currentConceptSet().id == conceptSetId) {
Expand Down Expand Up @@ -1411,7 +1496,7 @@ define(['jquery', 'knockout', 'text!./cohort-definition-manager.html',
getStatusTemplate(item) {
return item.status === 'FAILED' ? 'failed-status-tmpl' : 'success-status-tmpl';
}

showExitMessage(sourceKey) {
const info = this.cohortDefinitionSourceInfo().find(i => i.sourceKey === sourceKey) || { failMessage: ko.i18n('cohortDefinitions.cohortDefinitionManager.failedWithoutAnyMessage', 'Failed without any message')() };
this.exitMessage(info.failMessage);
Expand Down
4 changes: 2 additions & 2 deletions js/services/CohortDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ define(function (require, exports) {
}


function generate(cohortDefinitionId, sourceKey) {
return httpService.doGet(`${config.webAPIRoot}cohortdefinition/${cohortDefinitionId}/generate/${sourceKey}`);
function generate(cohortDefinitionId, sourceKey, retainCohortCovariates) {
return httpService.doGet(`${config.webAPIRoot}cohortdefinition/${cohortDefinitionId}/generate/${sourceKey}?retainCohortCovariates=${retainCohortCovariates}`);
}


Expand Down
Loading