function print(config,msg){ let el=config.document.getElementById(config.debugId); if (el===null) { //alert("Debug section not initialized. Message: "+msg); return; } el.value+="\n"+msg; } function clear(config){ let el=config.document.getElementById(config.debugId); if (el===null) { //alert("Debug section not initialized"); return; } config.document.getElementById(config.debugId).value=""; } function createRowSelector(schemaName,queryName){ let selectRows=new Object(); selectRows.schemaName=schemaName; selectRows.queryName=queryName; return selectRows; } function buildTable(config){ //print(config,'buildTable'); addRow(config,'ParticipantId',[config.id]); let selectRows=createRowSelector('lists',config.setup); selectRows.success=function (data){afterSetup(config,data);} LABKEY.Query.selectRows(selectRows); } function afterSetup(config,data){ //print(config,'afterSetup ['+data.rows.length+']'); config.setupRows=data.rows; let selectRows=createRowSelector('study','DataSets'); selectRows.success=function (data){afterDatasets(config,data);} LABKEY.Query.selectRows(selectRows); } //build a local copy of enum's function afterDatasets(config,data){ //print(config,'afterDatasets ['+data.rows.length+']'); config.datasets=data.rows; //debug mode -> jump ahead //afterEnumValues(config); let selectRows=createRowSelector('ListManager','ListManager'); selectRows.filterArray=[LABKEY.Filter.create('Name','enum', LABKEY.Filter.Types.STARTS_WITH)]; selectRows.success=function (data){afterEnums(config,data);} LABKEY.Query.selectRows(selectRows); //print(config,'enums'); } //parse list of lists; get values function afterEnums(config,data){ //print(config,'afterEnums: '+data.rows.length); config.enums=data.rows; config.enumValues=new Object(); for (row of config.enums){ //print(config,'afterEnums: '+row.Name); config.enumValues[row.Name]=new Object(); } for (lst in config.enumValues){ let selectRows=createRowSelector('lists',lst); selectRows.success=function (data){addEnumValues(config,data);} LABKEY.Query.selectRows(selectRows); } } function addEnumValues(config, data){ //find out the variable name // let varName="NONE"; for (field of data.metaData.fields){ if (field.name=="Key") continue; varName=field.name; } //print(config,'addEnumValues ['+data.queryName+']: '+varName); config.enumValues[data.queryName].map=new Object(); for (row of data.rows) config.enumValues[data.queryName].map[row["Key"]]=row[varName]; waitForEnumCompleted(config); } function waitForEnumCompleted(config){ for (lst in config.enumValues){ if (!("map" in config.enumValues[lst])) return; //print(config,'['+lst+']: '+ // Object.keys(config.enumValues[lst].map).length); } //print(config,"Enum completed"); afterEnumValues(config); } function datasetName(config,id){ for (let i=0;i