function renderMessages(id, messages) { if (messages && messages.length > 0) { let errorDiv = document.createElement('div'); let style='padding: 10px; background-color: #ffe5e5;' style+='color: #d83f48; font-weight: bold;'; errorDiv.setAttribute('style', style); errorDiv.innerHTML = messages.join('
'); document.getElementById(id).appendChild(errorDiv); } }; function validateChartConfig(chartConfig, aes, scales, measureStore) { let hasNoDataMsg = LABKEY.vis.GenericChartHelper.validateResponseHasData(measureStore, false); if (hasNoDataMsg != null) return {"success": false, "messages": [hasNoDataMsg]}; let measureNames = Object.keys(chartConfig.measures); for (let i = 0; i < measureNames.length; i++) { let measureProps = chartConfig.measures[measureNames[i]]; if (measureProps && measureProps.name && measureStore.records()[0][measureProps.name] == undefined){ let retVal=new Object(); retVal.success=false; retVal.messages=['The measure, ' + measureProps.label + ', is not available. It may have been renamed or removed.'] return retVal; } } let messages = []; let axisMeasureNames = ['x', 'xSub', 'y']; for (let i = 0; i < axisMeasureNames.length; i++) { if (measureNames.indexOf(axisMeasureNames[i]) > 0) { let validation = LABKEY.vis.GenericChartHelper.validateAxisMeasure( chartConfig.renderType, chartConfig, axisMeasureNames[i], aes, scales, measureStore.records()); if (validation.message != null) messages.push(validation.message); if (!validation.success) return {"success": false, "messages": messages}; } } return {"success": true, "messages": messages}; } function selectRowsCallback(renderConfig, measureStore) { let responseMetaData = measureStore.getResponseMetadata(); for (let f in measureStore) document.getElementById('debugCode').value+='\n '+f+' '+typeof(f); let record=measureStore.records()[1]; for (let f in record) document.getElementById('debugCode').value+='\n '+f+ ' ' +typeof(f); //try something stupid let participantField=document.getElementById('participantField').innerHTML; let participantCode=document.getElementById('participantCode').innerHTML; let visitField=document.getElementById('visitField').innerHTML; let visitCode=document.getElementById('visitCode').innerHTML; let selectedParticipantData=new Array(); let otherParticipantData=new Array(); let i=0; let maxValue=-1e30; while (imaxValue) maxValue=record['value'].value; continue; } record[participantField].value=renderConfig.labelOthers; if (!pMatch || sMatch) otherParticipantData.push(record); measureStore.records().splice(i,1); } document.getElementById('debugCode').value+='\nrecords: '+otherParticipantData.length; document.getElementById('debugCode').value+='\nownData: '+selectedParticipantData.length; document.getElementById('debugCode').value+='\nmaxValue: '+maxValue; for (let i=0;i chartConfig.geomOptions.binThreshold) { chartConfig.geomOptions.binned = true; } let scales = LABKEY.vis.GenericChartHelper.generateScales( chartType, chartConfig.measures, chartConfig.scales, aes, measureStore); let geom = LABKEY.vis.GenericChartHelper.generateGeom( chartType, chartConfig.geomOptions); document.getElementById('debugCode').value+='\n geom color '+geom.color; let labels = LABKEY.vis.GenericChartHelper.generateLabels( chartConfig.labels); if (chartType == 'bar_chart' || chartType == 'pie_chart') { let dimName = null, subDimName = null; measureName = null, aggType = 'COUNT'; if (chartConfig.measures.x) { dimName = chartConfig.measures.x.converted ? chartConfig.measures.x.convertedName : chartConfig.measures.x.name; } if (chartConfig.measures.xSub) { subDimName = chartConfig.measures.xSub.converted ? chartConfig.measures.xSub.convertedName : chartConfig.measures.xSub.name; } if (chartConfig.measures.y) { measureName = chartConfig.measures.y.converted ? chartConfig.measures.y.convertedName : chartConfig.measures.y.name; if (Ext4.isDefined(chartConfig.measures.y.aggregate)) { aggType = chartConfig.measures.y.aggregate; } else if (measureName != null) { aggType = 'SUM'; } } data = LABKEY.vis.getAggregateData(data, dimName, subDimName, measureName, aggType, '[Blank]', false); } let plotConfig = LABKEY.vis.GenericChartHelper.generatePlotConfig( renderConfig.chartId,chartConfig, labels, aes, scales, geom, data); document.getElementById('debugCode').value+='\n plotConfig layers: '+plotConfig.layers.length; for (let i=0;i 0) { let filters = []; for (let i = 0; i < queryConfig.filterArray.length; i++) { let f = queryConfig.filterArray[i]; filters.push(LABKEY.Filter.create( f.name, f.value, LABKEY.Filter.getFilterTypeForURLSuffix(f.type))); } queryConfig.filterArray = filters; } queryConfig.success = function(data){ selectRowsCallback(renderConfig,data);}; queryConfig.containerPath = LABKEY.ActionURL.getContainer(); LABKEY.Query.MeasureStore.selectRows(queryConfig); } }; function plotParticipant() { let participantField=document.getElementById('participantField').innerHTML; let participantCode=document.getElementById('participantCode').innerHTML; let visitField=document.getElementById('visitField').innerHTML; let visitCode=document.getElementById('visitCode').innerHTML; let visitValue=parseInt(visitCode.split('_')[1])+1; document.getElementById('debugCode').value+='\n'+visitValue; let organs=["3","4","5"]; for (let i=0;i < organs.length; i++){ let renderConfig=new Object(); //all additional configuration stuff goes in here renderConfig.chartId='SUVparticipant_organ'+organs[i]; renderConfig.width=500; renderConfig.participantCode=document.getElementById("participantCode").innerHTML; renderConfig.visitCode=document.getElementById("visitCode").innerHTML; renderConfig.labelOthers='other visits'; renderConfig.plot="percentile"; renderConfig.max=10; renderConfig.title="SUV cumulative distribution"; renderConfig.visitThreshold=visitValue; // When all the dependencies are loaded we then load the data via the MeasureStore selectRows API. // The queryConfig object stores all the information needed to make a selectRows request let queryConfig = new Object; queryConfig.schemaName="study"; queryConfig.queryName="SUVQuantiles"; queryConfig.viewName=null; queryConfig.dataRegionName="Dataset"; queryConfig.queryLabel="SUVQuantiles"; queryConfig.parameters= new Object(); queryConfig.requiredVersion=13.2; queryConfig.maxRows=-1; queryConfig.sort="lsid"; queryConfig.method="POST"; queryConfig.columns=["SequenceNum","percentile","value",participantField,visitField]; queryConfig.filterArray=new Array(); queryConfig.filterArray.push({ "name":"patientCode", "value":renderConfig.participantCode, "type":"eq"}); //queryConfig.filterArray.push({ // "name":"visitCode", // "value":renderConfig.visitCode, // "type":"eq"}); queryConfig.filterArray.push({ "name":"organ", "value":organs[i], "type":"eq"}); if (queryConfig.filterArray && queryConfig.filterArray.length > 0) { let filters = []; for (let i = 0; i < queryConfig.filterArray.length; i++) { let f = queryConfig.filterArray[i]; filters.push(LABKEY.Filter.create( f.name, f.value, LABKEY.Filter.getFilterTypeForURLSuffix(f.type))); } queryConfig.filterArray = filters; } queryConfig.success = function(data){ selectRowsCallback(renderConfig,data);}; queryConfig.containerPath=LABKEY.ActionURL.getContainer(); LABKEY.Query.MeasureStore.selectRows(queryConfig); } }; function plotTime() { let participantField=document.getElementById('participantField').innerHTML; let participantCode=document.getElementById('participantCode').innerHTML; let visitField=document.getElementById('visitField').innerHTML; let visitCode=document.getElementById('visitCode').innerHTML; let visitValue=parseInt(visitCode.split('_')[1])+1; document.getElementById('debugCode').value+='\n'+visitValue; let organs=["3","4","5"]; for (let i=0;i < organs.length; i++){ let renderConfig=new Object(); //all additional configuration stuff goes in here renderConfig.chartId='SUVparticipant_organ'+organs[i]; renderConfig.width=500; renderConfig.participantCode=document.getElementById("participantCode").innerHTML; renderConfig.visitCode=document.getElementById("visitCode").innerHTML; renderConfig.labelOthers='others'; renderConfig.suv=95; renderConfig.plot="time"; if (organs[i]=="4") renderConfig.suv=70; renderConfig.max=-1; renderConfig.visitThreshold=visitValue; renderConfig.title="Quantitative inflamation time-curve"; // When all the dependencies are loaded we then load the data via the MeasureStore selectRows API. // The queryConfig object stores all the information needed to make a selectRows request let queryConfig = new Object; queryConfig.schemaName="study"; queryConfig.queryName="SUVQuantiles"; queryConfig.viewName=null; queryConfig.dataRegionName="Dataset"; queryConfig.queryLabel="SUVQuantiles"; queryConfig.parameters= new Object(); queryConfig.requiredVersion=13.2; queryConfig.maxRows=-1; queryConfig.sort="lsid"; queryConfig.method="POST"; queryConfig.columns=["SequenceNum","value",participantField]; queryConfig.filterArray=new Array(); //queryConfig.filterArray.push({ // "name":"patientCode", // "value":renderConfig.participantCode, // "type":"eq"}); queryConfig.filterArray.push({ "name":"percentile", "value":renderConfig.suv, "type":"eq"}); queryConfig.filterArray.push({ "name":"organ", "value":organs[i], "type":"eq"}); if (queryConfig.filterArray && queryConfig.filterArray.length > 0) { let filters = []; for (let i = 0; i < queryConfig.filterArray.length; i++) { let f = queryConfig.filterArray[i]; filters.push(LABKEY.Filter.create( f.name, f.value, LABKEY.Filter.getFilterTypeForURLSuffix(f.type))); } queryConfig.filterArray = filters; } queryConfig.success = function(data){ selectRowsCallback(renderConfig,data);}; queryConfig.containerPath = LABKEY.ActionURL.getContainer(); LABKEY.Query.MeasureStore.selectRows(queryConfig); } };