123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253 |
- var crfVisit={};
- //crfVisit.config=new Object();
- crfVisit.setDebug=
- function(debug=null){
- if (debug){
- this.print=function(msg){debug.this.print(msg);};
- this.clear=function(){debug.clear();}
- return;
- }
- //provide default functions if not debug object is available
- this.print=function(msg){console.log(msg);}
- this.clear=function(){;}
- }
- crfVisit.setDebug();
- crfVisit.init=
- function(cb=null){
- let that=this;
- let action=function(){that.scriptsLoaded(cb);};
- let dependencies=new Array();
- dependencies.push('crf/runQuery.js');
- dependencies.push("crf/crfReviewSection.js");
- dependencies.push("crf/participantIdManager.js");
- dependencies.push("crf/variableList.js");
- dependencies.push("crf/webdav.js");
- dependencies.push("crf/crfPrint.js");
- dependencies.push("crf/crfSetup.js");
- dependencies.push("crf/crfData.js");
- dependencies.push("crf/crfHTML.js");
- dependencies.push("crf/generateRegistration.js");
- LABKEY.Utils.requiresScript(dependencies,action);
- }
- crfVisit.scriptsLoaded=
- function(cb=null){
- participantIdManager.set(crfSetup,crfData);
- webdav.set(this);
- crfReviewSection.set(this);
- crfPrint.set(this);
- crfData.setSetup(crfSetup);
- crfHTML.init();
- generateRegistration.init();
- let initRegistration=function(){generateRegistration.init(cb);};
- let initIdManager=function(){participantIdManager.init(initRegistration);};
- let action=function(){crfData.init(initIdManager)};
- crfSetup.init(action);
- }
- crfVisit.getContainer=
- function(label){
- return crfSetup.getContainer(label);
- }
- crfVisit.getCrfRefFirst=
- function(){
- //crfRef is part of html call and gets stored in the page
- return this.crfRef;
- }
- crfVisit.getCrfRef=
- function (){
- //'crfRefId'
- return crfData.getCrfEntry()['entryId'];
- }
- crfVisit.getCrfRefData=
- function(){
- let parentCrf=crfData.getCrfEntry()['parentCrf'];
- if (parentCrf!=undefined) return parentCrf;
- return this.getCrfRef();
- }
- crfVisit.onFailure=
- function(errorInfo, options, responseObj){
-
- if (errorInfo && errorInfo.exception)
- alert("Failure: " + errorInfo.exception);
- else
- alert("Failure: " + responseObj.statusText);
- }
- crfVisit.doNothing=
- function (){
- this.print('doNothing called');
- }
- crfVisit.getIdManager=
- function(){
- if (!("idManager" in this)){
- participantIdManager.masterForm=this.masterForm;
- this.idManager=participantIdManager.getObject();
- }
- return this.idManager;
- }
- crfVisit.getSetupObject=
- function(){
- if (!("setups" in this))
- this.setups=new Object();
- return this.setups;
- }
- crfVisit.getStoredSetup=
- function(sectionId){
- let sObj=this.getSetupObject();
- if (sectionId in sObj) return sObj[sectionId];
- return null;
- }
- crfVisit.addSetup=
- function(sectionId,setup){
- let sObj=this.getSetupObject();
- sObj[sectionId]=setup;
- }
-
- crfVisit.makeSetup=
- function(sectionId,listName){
- //generate setup object whcih should contain fields:
- //readonlyFlag - whether the dataset is writeable
- //filters - selection fields that allow creation of LABKEY.Filter.create()
- //getInputId - formating of unique ids for html elements
- //
- let fName='[Setup]';
- this.print(fName+' '+sectionId+'/'+listName);
- let setup=new Object();
- setup.queryName=listName;
- setup.readonlyFlag=function(vName){return false};
- setup.filters=new Object();
- setup.filters['crfRef']=this.getCrfRef();
- setup.getInputId=function(vName){return sectionId+"_"+vName;}
- setup.sectionId=sectionId;
- setup.isReview=false;
- this.addSetup(sectionId,setup);
- setup.setVariables=new Object();
- return setup;
-
- }
- crfVisit.makeFullAccessSetup=
- function(sectionId,listName){
- //addApply - whether a submit/Save button is generated
- let setup=this.makeSetup(sectionId,listName);
- setup.addApply="Save";
- return setup;
- }
- crfVisit.makeReadonlySetup=
- function(sectionId,listName){
- let setup=this.makeSetup(sectionId,listName);
- //see definition of setup object above, change readonly flag
- setup.readonlyFlag=function(vName){return true};
- return setup;
- }
- crfVisit.getSetup=
- function(sectionId,listName,writeAccess=true){
- //change to section granulated permission of type EDIT, COMMENT, READ
- //let formStatus=config.formConfig.formStatus;
- //equivalent to READ
- let setup=this.getStoredSetup(sectionId);
- if (setup) return setup;
- if (!writeAccess)
- //if (formStatus=="Submitted")
- return this.makeReadonlySetup(sectionId,listName);
- //if (formStatus=="Approved")
- // return readonlySetup(listName);
- return this.makeFullAccessSetup(sectionId,listName);
- }
- crfVisit.generateSection=
- function(formSetupEntry){
- let that=this;
- let listName=crfSetup.getMap('inputLists')[formSetupEntry['queryName']];
- let sectionId="section"+formSetupEntry['Key'];
- //if (!listName) is for debugSection
- if (!listName){
- listName="debugSection";
- }
- let fName='[generateSection/'+listName+']';
- let sectionTitle=formSetupEntry['title'];
- let accessModeColumn=this.role+'Mode';
- let accessMode=formSetupEntry[accessModeColumn];
- //this will fix it for later use as well
- this.print(fName+' title '+sectionTitle);
- let tb=crfHTML.createTable(this.masterForm);
- tb.className='t2';
- let row=tb.insertRow();
- let cell=crfHTML.createTblHeader(null,row);
- cell.setAttribute("colspan","4");
- cell.style.fontSize="20px";
- cell.style.textAlign="center";
- crfHTML.createTextNode(sectionTitle,null,cell);
- cell=row.insertCell();
- let input=crfHTML.createButton(null,cell);
- input.value="Show";
- input.id="toggle"+sectionId+"VisbilityButton";
- input.onclick=function(){that.toggleVisibility(sectionId,input.id)};
- let div=crfHTML.createDiv(sectionId,this.masterForm);
- div.style.display="none";
- //here divert for debugArea
- if (listName=="debugSection"){
- let debugArea=crfHTML.createTextArea(null,div);
- debugArea.rows=10;
- debugArea.cols=95;
- debugArea.id=this.debugId;
- return;
- }
- let additionalData=crfSetup.getAdditionalData(listName);
- let divTable=crfHTML.createDiv(sectionId+"Table",null,div);
-
- if ("showFlag" in additionalData) {
- additionalData.divName=sectionId+"SubDiv";
- additionalData.divQueryName=sectionId+"SubDivList";
- let div1=crfHTML.createDiv(additionalData.divName,null,div);
- div1.style.display="none";
- let div2=crfHTML.createDiv(additionalData.divQueryName,null,div1);
- }
- this.print(fName+" generate master table");
- let writeMode=accessMode=="EDIT";
- let setup=this.getSetup(sectionId,listName,writeMode);
- setup.setVariables=variableList.parseVariables(formSetupEntry['variableDefinition']);
-
- if ("isReview" in additionalData){
- crfReviewSection.set(this);
- let action=function(){crfReviewSection.CB();};
- crfReviewSection.generateSection(listName,div.id,action);
- return;
- }
- //master table is unique per visit
-
- setup.unique=true;
- this.generateTable(listName,divTable.id,additionalData,setup);
-
- this.print("generate master table: done");
- let generateSubTable=true;
- //generateSubTable equivalent to read/write access to section
- if (accessMode != "EDIT")
- generateSubTable=false;
-
- if (! ("showFlag" in additionalData) ) generateSubTable=false;
-
- if (generateSubTable){
- let qName=additionalData.queryName;
- let dName=additionalData.divName;
-
- let subsectionId='sub'+sectionId;
- let xsetup=this.makeFullAccessSetup(subsectionId,qName);
- //only set master query for additionalData
- xsetup.masterQuery=listName;
- //if (readonly) setup=readonlySetup(config);
- xsetup.subTable=true;
- this.generateTable(qName,dName,additionalData,xsetup);
- //generateTable(formSetupEntry,qName,dName,additionalData,setup);
- }
- this.print("generate review");
- let divReviewList=crfHTML.createDiv(sectionId+"ReviewList",null,div);
- let divReview=crfHTML.createDiv(sectionId+"Review",null,div);
- //assume we already have listId (content of config.setupQueryName is listId)
- //we need listName also
- //qconfig.queryName=config.setupQueryName;
- this.generateReview(divReview.id,divReviewList.id,listName,accessMode);
- if (accessMode!='GENERATE') return;
- this.print('Adding generate button');
- //add generateButton
- let divGenerateButton=crfHTML.createDiv(listName+"GenerateButton",null,div);
- this.print('Adding generate button completed to here');
- let cb=function(){that.onGenerateQuery(listName);};
- this.generateButton(divGenerateButton.id,'Generate','Generate '+listName,'onGenerateQuery',cb);
- this.print(fName+' adding generate button completed');
- }
- crfVisit.generateReview=
- function(divReviewId,divReviewListId, listName, accessMode){
- let qMapInvert=crfSetup.invertMap(crfSetup.getMap('inputLists'));
- let listId=qMapInvert[listName]
- //listId is a number->should it be queryName?
-
- let fName='[generateReview]';
- this.print(fName+" list "+listId+'/'+listName);
- let reviewSetup=new Object();
- reviewSetup.setVariables=new Object();
- reviewSetup.readonlyFlag=function(vName){
- if (vName=="queryName") return true;
- if (vName=="queryname") return true;
- if (vName=="ModifiedBy") return true;
- return false;};
- reviewSetup.addApply="Add Review";
- reviewSetup.reviewTable=true;
- let generateTableFlag=true;
- let formStatus=crfData.getCrfEntry()['FormStatus'];
- //COMMENTS allowed or not
- //three levels of access: EDIT, COMMENT, READ
- if (accessMode == "READ"){
- //if (formStatus == "Approved" ){
- delete reviewSetup.addApply;
- reviewSetup.readonlyFlag=function(vName){return false;}
- generateTableFlag=false;
- }
-
- reviewSetup.filters=new Object();
- reviewSetup.filters["crfRef"]=this.crfRef;
- if (crfData.getCrfEntry()['parentCrf']){
- let parentCrf=crfData.getCrfEntry()['parentCrf'];
- reviewSetup.filters["crfRef"]=this.crfRef+";"+parentCrf;
- }
- reviewSetup.filters["queryName"]=listId;//entry in reviewComments list is queryname, all in small caps
- //needs listName, in argument
-
- reviewSetup.getInputId=function(vName){return listName+"_add"+vName};
- reviewSetup.divReviewListId=divReviewListId;
- reviewSetup.isReview=true;
- this.addSetup(divReviewId,reviewSetup);
- let msg="Review: divId: "+divReviewId;
- msg+=" inputId: "+reviewSetup.getInputId;
- this.print(msg);
-
- this.updateListDisplay(divReviewListId,"reviewComments",reviewSetup.filters,true);
- if (! generateTableFlag) return;
-
- this.generateTable("reviewComments",divReviewId,new Object(),reviewSetup);
- }
- //>>>>>>>>>>trigger visibility of additional lists
- crfVisit.setListVisibility=
- function(input,setup,readonlyFlag){
- let fName="[setListVisibility/"+setup.queryName+"]";
- this.print(fName);
- let additionalData=crfSetup.getAdditionalData(setup.queryName);
-
- let x = crfHTML.getElement(additionalData.divName);
- this.print(fName+": Div: "+x);
- x.style.display="none";
- let sText;
- if (readonlyFlag) sText=input.innerText;
- else sText=input.options[input.selectedIndex].text;
-
- this.print(fName+": Selected option text: "+sText);
- if (sText == additionalData.showFlagValue){
- let filters=new Object();
- if ("filters" in additionalData) filters=additionalData.filters;
- x.style.display = "block";
- this.updateListDisplay(additionalData.divQueryName,
- additionalData.queryName,filters,readonlyFlag);
- }
- }
- //>>have list refresh when data is added (not optimal yet)
- //
- crfVisit.updateListDisplay=
- function(divName,queryName,filters,readonlyFlag){
- //use Labkey.QueryWebPart to show list
- let fName="[updateListDisplay]";
- this.print(fName+": UpdateListDisplay: Query - "+queryName
- +" div - "+divName);
- if (divName=="NONE") return;
- let crfRef=this.getCrfRef();
- let div=crfHTML.getElement(divName);
- this.print(fName+": generating WebPart: "+queryName);
-
- var qconfig=new Object();
- qconfig.renderTo=divName;
- //point to data container
- qconfig.containerPath=this.getContainer('data');
- qconfig.schemaName='lists';
- qconfig.queryName=queryName;
- qconfig.buttonBarPosition='top';
- qconfig.filters=[];
- for (f in filters){
- let fType=LABKEY.Filter.Types.EQUAL;
- this.print(fName+' filter ['+f+'] '+filters[f]+'/'+typeof(filters[f])+' ['+fType+']');
-
- if (variableList.isFilterList(filters[f])){
- fType=LABKEY.Filter.Types.IN;
- }
- qconfig.filters.push(LABKEY.Filter.create(f, filters[f],fType));
- }
- let that=this;
- qconfig.success=function(data){that.updateSuccess(data);};
- qconfig.failure=function(errorInfo,options,responseObj){that.onFailure(errorInfo,options,responseObj);};
- //show only print button
- if (readonlyFlag){
- qconfig.buttonBar=new Object();
- qconfig.buttonBar.items=["print"];
- }
- LABKEY.QueryWebPart(qconfig);
-
- }
- crfVisit.updateSuccess=
- function(data){
- this.print("Update success");
- }
- //TODO: this should trigger a data refresh on section, ie populateData(field)
- crfVisit.toggleVisibility=
- function(sectionId,buttonName){
- let fName='[toggleVisibility/'+sectionId+']';
- this.print(fName);
- let x = crfHTML.getElement(sectionId);
- if (x.style.display === "none") {
- //exclude non data sections (like debug)...
- this.print(fName+': issuing setData(populateSection)');
- x.style.display = "block";
- crfHTML.getElement(buttonName).value="Hide";
- let that=this;
- let cb=function(){that.populateSection(sectionId);};
- crfData.setData(this.crfRef,cb);
- } else {
- x.style.display = "none";
- crfHTML.getElement(buttonName).value="Show";
- }
- }
- crfVisit.generateButton=
- function(divName,caption,label,callbackLabel,callback=null){
- this.print("generateButtonX");
-
- let tb=crfHTML.createTable(divName);
- tb.className="t2";
-
- let r1=tb.insertRow();
- let th=crfHTML.createTblHeader(null,r1);
- th.innerHTML=caption;
- //*!*
- let c2=r1.insertCell();
- let i1=crfHTML.createButton(null,c2);
- i1.value=label;
- i1.style.fontSize="20px";
- let that=this;
- if (callback)
- i1.onclick=callback;
- else
- i1.onclick=function(){that[callbackLabel]();};
- i1.id='button_'+callbackLabel;
- let c1=r1.insertCell();
- c1.setAttribute("colspan","1");
- //this is only for saveReview?
- c1.id=divName+'_reportField';
- //c1.id=config.submitReportId;
-
- }
- crfVisit.generateSubQuery=
- function(input, setup, readonlyFlag){
- let fName="[generateSubQuery]";
- if (setup.isReview) return;
- if (!(setup.queryName in crfSetup.getAdditionalDataObject())){
- this.print(fName+': no additionalData entry (probably a subquery)');
- return;
- }
- let additionalData=crfSetup.getAdditionalData(setup.queryName);
- if (!("showFlag" in additionalData))
- return;
- this.print(fName);
-
- let expId=setup.getInputId(additionalData.showFlag);
- if (expId!=input.id) {
- this.print(fName+": ignoring field "+input.id+"/"+expId);
- return;
- }
- this.print(fName+": Setting onChange to "+input.id);
- if (readonlyFlag)
- return;
- let that=this;
- input.onchange=function(){that.setListVisibility(input,setup,readonlyFlag)};
- }
- //>>populate fields
- //
- //
- //split to field generation and field population
- //
- crfVisit.addFieldRow=
- function(tb,field,setup,additionalData){
- let fName="[addFieldRow/"+setup.queryName+':'+field.name+']';
- let vName=field.name;
- let vType=field.type;
- let isLookup=("lookup" in field);
- this.print(fName+": ["+vName+"/"+vType+'/'+isLookup+"]");
- let row=tb.insertRow();
- let cell=crfHTML.createTblHeader(null,row);
- cell.style.width='300px';
-
- let text = crfHTML.createTextNode(field.shortCaption,null,cell);
-
-
- let input=null;
- let colSpan="3";
- let cell1=row.insertCell();
- cell1.colSpan=colSpan;
- let readonlyFlag=setup.readonlyFlag(vName);
- //set the html input object
- while (1){
- if (readonlyFlag){
- input=crfHTML.createLabel('Loading',null,cell1);
- break;
- }
-
- //lookup
- if (isLookup){
- let lookup=field["lookup"];
- //get all values from config.formConfig.lookup[X]
- let lObject=crfData.getLookup(lookup.queryName);
- input = crfHTML.createSelect(lObject.LUT,null,cell1);
- break;
- }
- //date
- if (vType=="date"){
- input = crfHTML.createDate(null,cell1);
- break;
- }
- //string
- if (vType=="string"){
- //we have to make sure UNDEF is carried to below
- //since we are adapting file to either show
- //current file or allow user to select a file
- //
- //TODO change this so one can always select file
- //but also show the selected file
- if(vName.search("reviewComment")>-1){
- input = crfHTML.createTextArea(null,cell1);
- input.cols="65";
- input.rows="5";
- break;
- }
- input=crfHTML.createTextInput(null,cell1);
-
- if (vName.search('_file_')<0) break;
- cell1.setAttribute('colspan',"1");
- let cell2=row.insertCell();
- cell2.setAttribute('colspan',"2");
- let input1=crfHTML.createFileInput(null,cell2);
- input1.id=setup.getInputId(vName)+'_file_';
- break;
-
- }
- if (vType=="float"){
- input = crfHTML.createTextInput(null,cell1);
- break;
- }
-
-
- if (vType=="boolean"){
- input = crfHTML.createCheckbox(null,cell1);
- this.print("Creating checkbox");
- break;
- }
- break;
- }
-
- input.id=setup.getInputId(vName);
- this.print(fName+': adding element '+input.id);
- this.print(fName+': listing element '+crfHTML.getElement(input.id));
-
- //connect associated list
- this.generateSubQuery(input,setup,readonlyFlag);
- if (readonlyFlag) {
- this.print(fName+': exiting(readonlyFlag)');
- return;
- }
-
- }
- crfVisit.addSpecialFieldRows=
- function(tb,specFieldSetup,setup){
- //tb is the table, specFieldSetup is a row from the table where special fields are being setup
- //the first column is fieldUID, which is a colon joined amalgation of queryName:fieldName
- let fieldUID=specFieldSetup["fieldUID"];
- let x=fieldUID.split(':');
- let fieldName=x[1];
- let fName="[addSpecialFieldRow/"+fieldUID+"]";
- let q=variableList.parseVariables(specFieldSetup['actionParameters']);
- this.print(fName);
- let type=specFieldSetup['actionType'];
- this.print(fName+' type '+type);
- if (type=='textArea' || type=="textAreaFromVariableDefinition"){
- let row=tb.insertRow();
- let cell1=row.insertCell();
- cell1.colSpan="4";
- cell1.style.textAlign="justify";
- cell1.style.padding="10px";
- cell1.style.backgroundColor="#e0e0e0";
- cell1.innerText=q['description'];
- if (type!='textAreaFromVariableDefinition') return;
- let varName=q['varName'];
- //get the value. But sometimes and particularly in this case, there are two rows for the same query
- //one should rely on formSetup variable definition
- let value=setup.setVariables[varName];
- let code=q['pattern'];
- code=code.replace(varName,value);
- this.print(fName+' using ['+varName+'] '+value+' pattern '+q['pattern']+' code '+code);
- cell1.innerText=q[code];
-
- }
- //copyCrfEntry in populateSpecialField
- if (specFieldSetup['actionType']=='generationObject'){
- //only in EDIT mode!!
- let ro=setup.readonlyFlag(fieldName);
- if (ro) return;
- generateRegistration.set(this);
- q['setup']=setup;
- let gc=generateRegistration.getObject(q,setup.getInputId(fieldName));
- let that=this;
- let action=function(){that.doNothing();};
- if ('mailRecipient' in q){
- gc.callback=function(data){that.sendEmail(data,q['mailRecipient'],action,q['subject']);};
- }
- else
- gc.callback=function(data){that.doNothing();};
- if ("addData" in q){
- vars=q["addData"].split(',');
- gc.addData=new Array();
- for (let v in vars){
- let s=vars[v]
- //variable name can be written as A/B where A is the name in addData and B is the variable name in crfEntry
- //useful for mocking up crfId from daughter crf-s such as registration
- let sArray=s.split('/');
- let sTarget=sArray[0];
- let sSource=sArray[sArray.length-1];
- gc.addData[sTarget]=crfData.getCrfEntry()[sSource];
- this.print(fName+" addData ["+sTarget+"]: "+gc.addData[sTarget]);
- }
- }
- let row=tb.insertRow();
- let cell=crfHTML.createTblHeader(null,row);
- crfHTML.createTextNode("Automatic ID generator",null,cell);
- let cell1=row.insertCell();
- cell1.colSpan="3";
- let b=crfHTML.createButton(null,cell1);
- b.id="generateIdButton";
- b.onclick=function(){generateRegistration.execute(gc);};
- b.value="Generate ID";
- }
- }
- crfVisit.populateFieldRow=
- function(entry,field,setup){
- this.populateField(entry,field,setup);
- this.populateSubQuery(entry,field,setup);
- this.populateSpecialFields(entry,field,setup);
- }
- crfVisit.populateSubQuery=
- function(entry,field,setup){
- let fName='[populateSubQuery/'+setup.queryName+':'+field.name+']';
- if (setup.isReview) return;
-
- if (!(setup.queryName in crfSetup.getAdditionalDataObject())){
- let msg=fName+': no additionalData entry for '+setup.queryName;
- msg+=' (probably a subquery)';
- this.print(msg);
- return;
- }
- //find if field is connected to a sub array
- //find queryName
- //
- let additionalData=crfSetup.getAdditionalData(setup.queryName);
- this.print(fName);
- //let flag=additionalData.showFlag;
-
- if (!("showFlag" in additionalData)) return;
- let eId=setup.getInputId(additionalData.showFlag);
- let id=setup.getInputId(field.name);
-
- if (eId!=id) {
- this.print(fName+": ignoring field "+id+"/"+eId);
- return;
- }
-
- this.print(fName+': id '+id);
- //hard to estimate readonlyFlag
- //
- let input=crfHTML.getElement(id);
- let eType=input.nodeName.toLowerCase();
- let readonlyFlag=eType!="select";
- this.setListVisibility(input,setup,readonlyFlag);
- }
- crfVisit.clearField=
- function(field,setup){
- let foo=new Object();
- this.populateField(foo,field,setup);
- }
- crfVisit.populateField=
- function(entry,field,setup){
- let vName=field.name;
- let fName='[populateFieldName/'+vName+']';
- let varValue="UNDEF";
- //if (vName in setup.filters) varValue=setup.filters[vName];
- if (vName in entry) varValue=entry[vName];
- //if part of the filter, set it to value
- if (vName in setup.filters) varValue=setup.filters[vName];
-
- let isLookup=("lookup" in field);
-
- this.print(fName+' v='+varValue+'/'+isLookup+' ['+
- setup.getInputId(field.name)+']');
-
- let vType=field.type;
- let id=setup.getInputId(vName);
- let input=crfHTML.getElement(id);
-
- //date
- if (vType=="date"){
- if (varValue=="UNDEF") varValue=new Date();
- else varValue=new Date(varValue);
- }
-
- //lookup for readonly
- if (isLookup && varValue!="UNDEF"){
- let lookup=field["lookup"];
- //get all values from config.formConfig.lookup[X]
- let lObject=crfData.getLookup(lookup.queryName);
- varValue=lObject.LUT[varValue];
- }
- this.print('Element: '+id+'/'+input);
- //figure out the element type
- let eType=input.nodeName.toLowerCase();
- this.print('Element type: '+eType);
- //change varValue for printing
- if (varValue=="UNDEF") varValue="";
- //HTMLTextArea, createElement(textArea)
- if (eType==="textarea"){
- input.value=varValue;
- return;
- }
- //Text, createTextNode
- if (eType==="#text"){
- input.nodeValue=varValue;
- return;
- }
- //HTMLLabelElement, createElement('label')
- if (eType==="label"){
- input.innerText=varValue;
- return;
- }
- //HTMLSelectElement, createElement('select')
- if (eType==="select"){
- input.selectedIndex=0;
- for (let i=0;i<input.options.length;i++){
- let v=input.options[i].text;
- if (v!=varValue) continue;
- input.selectedIndex=i;
- break;
- }
- return;
- }
- if (eType!="input"){
- this.print('Unknown type: '+eType+' encountered, igonring');
- return;
- }
-
- //HTMLInputElement
- let type=input.type;
- if (type=="date"){
- input.valueAsDate=varValue;
- return;
- }
- //string,float
- if (type=="text"){
- input.value=varValue;
- return;
- }
- //boolean
- if (type=="checkbox"){
- input.checked=varValue;
- return;
- }
- this.print('Unknown input type: '+type+'. Ignoring.');
- }
- crfVisit.populateSpecialFields=
- function(entry,field,setup){
- let fName='[populateSpecialFields]';
- let fieldUID=setup.queryName+':'+field.name;
- let specialFields=crfSetup.getEntryMap('specialFields:fieldUID');
- if (!(fieldUID in specialFields)) return;
- let specFieldSetup=specialFields[fieldUID];
- //q is not used by copyCrfEntry, keeping it here for future reference
- let q=variableList.parseVariables(specFieldSetup['actionParameters']);
- let type=specFieldSetup['actionType'];
- if (type=='copyCrfEntry'){
- let el=crfHTML.getElement(setup.getInputId(field.name));
- let varName=field.name;
- if ("varName" in q) varName=q["varName"];
- let id=crfData.getCrfEntry()[varName];
- el.value=id;
- this.print(fName+' specialFields ['+field.name+'] '+id+'/'+el.value);
- }
- }
- crfVisit.populateTable=
- function(listName,writeMode,setup){
- //function populateTable(formSetupEntry){
- //let listName=config.formConfig.queryMap[formSetupEntry['queryName']];
- //let accessMode=config.formConfig.operator+'Mode';
- //let writeMode=formSetupEntry[accessMode]=='EDIT';
- let fName='[populateTable/'+listName+']';
- //should contain formSetup key
-
-
- //data snapshot
- let fQuery=crfData.getQuerySnapshot(listName);
- let queryLayout=crfData.getQueryLayout(listName);
- //here I assume that listName was parsed during setDataLayout and setData
- //so that rows was set (even if they are empty)
- this.print(fName+"]: nrows "+fQuery.rows.length);
-
- let entry=this.selectEntry(fQuery.rows,setup);
-
- if (!entry) entry=new Object();
- let fields=queryLayout.fields;
-
- for (f in fields){
- let field=fields[f];
- //each field is a new row
- this.print(fName+": Adding field: "+f+'/'+field.name+' hidden: '+field.hidden+' type:'+field.type);
- if (field.hidden) continue;
- if (field.name=="crfRef") continue;
- if (field.name in setup.setVariables) continue;
- this.populateFieldRow(entry,field,setup);
-
- }
- }
- crfVisit.generateTable=
- function(listName,divName,additionalData,setup){
- let fName="[generateTable/"+listName+"]";
- this.print(fName);
- //is listName and setup.queryName a duplicate of the same value
- this.print(fName+': setup.queryName '+setup.queryName);
- //assume data is set in config.formConfig.dataQueries[data.queryName].rows;
- let populateData=true;
- if ("subTable" in setup){
- this.print(fName+" is subTable");
- populateData=false;
- }
- let entry=new Object();
- //data snapshot
- let fQuerySnapshot=crfData.getQuerySnapshot(listName);
- let queryLayout=crfData.getQueryLayout(listName);
- //here I assume that listName was parsed during setDataLayout and setData
- //so that rows was set (even if they are empty)
- this.print(fName+": Nrows "+fQuerySnapshot.rows.length);
-
- if (fQuerySnapshot.rows.length>0)
- entry=fQuerySnapshot.rows[0];
-
- if ("reviewTable" in setup){
- entry['reviewComment']='';
- delete entry["ModifiedBy"];
- }
-
- let tb=crfHTML.createTable(divName);
- tb.className="t2";
- //this are the fields (probably constant)
- let fields=queryLayout.fields;
-
- for (f in fields){
- let field=fields[f];
- let fieldUID=listName+":"+field.name;
- //each field is a new row
- this.print(fName+": Adding field: "+f+'/'+field.name+' ('+fieldUID+').');
- //unique name
- if (field.hidden) continue;
- if (field.name=="crfRef") continue;
- if (field.name in setup.setVariables) continue;
- this.addFieldRow(tb,field,setup,additionalData);
- if (populateData) this.populateFieldRow(entry,field,setup);
- let specialFields=crfSetup.getEntryMap('specialFields:fieldUID');
- if (fieldUID in specialFields){
- let specFieldSetup=specialFields[fieldUID];
- this.addSpecialFieldRows(tb,specFieldSetup,setup);
- }
-
- }
- //finish of if apply button is not required
- if (!("addApply" in setup)) {
- this.print(fName+"populateTable: done");
- return;
- }
-
- let row=tb.insertRow();
- let th=crfHTML.createTblHeader(null,row);
- th.innerHTML=setup.addApply;
- let cell=row.insertCell();
- //cell.setAttribute("colspan","2");
- let input=crfHTML.createButton(null,cell);
- input.value=setup.addApply;
- let cell1=row.insertCell();
- cell1.setAttribute("colspan","2");
- cell1.id=setup.getInputId("rerviewLastSave");
- cell1.innerHTML="No recent update";
- //saveReview is a generic name for saving content of the html page to a list entry
- let that=this;
- input.onclick=function(){that.saveReview(listName,cell1.id,setup)};
- }
- crfVisit.setEntryFromElement=
- function(entry,elementId, field){
- //set value to entry from element using representation (field) from labkey
- //
- //
-
- let fName='setEntryFromElement';
- let el=crfHTML.getElement(elementId);
-
- if (!el) {
- this.print(fName+" element: "+elementId+" not found");
- return;
- }
- this.print(fName+" element: "+elementId);
-
- let vName=field.name;
- let vType=field.type;
- let eType=el.nodeName.toLowerCase();
- if (eType==="select"){
- entry[vName]=el.options[el.selectedIndex].value;
- return;
- }
- if (eType==="td"){
- entry[vName]=el.innerText;
- return;
- }
-
- if (vType=="date"){
- let date=el.valueAsDate;
- if (!date) return;
- date.setUTCHours(12);
- entry[vName]=date.toString();
- this.print(fName+" setting date to "+entry[vName]);
- return;
- }
- if (vType=="string"){
- entry[vName]=el.value;
-
- if (vName.search('_file_')<0)
- return;
-
- //upload file
- let id1=elementId+'_file_';
- let input1=crfHTML.getElement(id1);
- this.print(fName+' attachment field: '+input1.value);
- //entry[vName]=el.files[0].stream();
- let ctx=new Object();
- ctx['dirName']='consent';
- ctx['ID']=entry['crfRef'];
- //should point to data container
- ctx['project']=getContainer('data');
- //need ID->crf!
- //assume crfRef will get set before this
- //element is encountered
- this.uploadFile(input1,ctx);
- let fv=el.value;
- let suf=fv.split('.').pop();
- entry[vName]=entry['crfRef']+'.'+suf;
- return;
-
- }
- if (vType=="float" || vType=="int"){
- entry[vName]=el.value;
-
- if (vName=="queryName") {
- this.print(fName+' parsing queryName: '+el.innerText);
- let qMapInverse=crfSetup.invertMap(crfSetup.getMap('inputLists'));
- entry[vName]=qMapInverse[el.innerText];
- //use queryMap lookup
- }
- return;
- }
- if (vType=="boolean"){
- entry[vName]=el.checked;
- return;
- }
- return;
- }
- crfVisit.selectEntry=
- function(fRows,setup){
- let fName='[selectEntry]';
- if (!("unique" in setup)) return null;
- if (fRows.length==0) return null;
- keys=Object.keys(setup.setVariables);
-
- if (keys.length==0)
- return fRows[0];
-
- for (let i=0;i<fRows.length;i++){
- for (let v in setup.setVariables){
- this.print(fName+' row '+i+' ['+v+'] '+fRows[i][v]+'/'+setup.setVariables[v]);
- if (fRows[i][v]==setup.setVariables[v]){
- this.print(fName+' using '+i);
- return fRows[i];
- }
- }
- }
- return null;
- }
- crfVisit.saveReview=
- function(queryName,elementId,setup){
- //loads any queryName
- let debug=true;
- let fName='[saveReview/'+queryName+']';
- this.print(fName+" elementId "+elementId);
- let unique=("unique" in setup);
-
- //data snapshot
- let fQuerySnapshot=crfData.getQuerySnapshot(queryName);
- let nRows=fQuerySnapshot.rows.length;
-
- //data layout
- let queryLayout=crfData.getQueryLayout(queryName);
- //determine mode based on entry uniqueness and presence of data
- let entry=this.selectEntry(fQuerySnapshot.rows,setup);
- let mode='update';
- if (!entry){
- entry=new Object();
- mode='insert';
- }
- this.print(fName+' unique '+unique+' mode '+mode+' nRows '+nRows);
- entry.crfRef=this.getCrfRefData();
- this.print(fName+" set crfRef="+entry.crfRef);
- let fields=queryLayout.fields;
- for (f in fields){
- let field=fields[f];
- this.print(fName+" saveReview field: "+field.name);
- if (field.hidden) continue;
- if (field.name in setup.setVariables){
- entry[field.name]=setup.setVariables[field.name];
- continue;
- }
-
- let vName=field.name;
- let vType=field.type;
- this.print(fName+" vType: "+vType);
-
- if (vName=="crfRef") continue;
- //need to save queryName for reviewComments
-
- let eId=setup.getInputId(vName);
- //copy values from form to entry
- this.setEntryFromElement(entry,eId,field,setup);
- //clear field value
- if (!unique) this.clearField(field,setup);
- }
- let that=this;
- let action=function(data){that.updateLastSavedFlag(data,setup,elementId)};
- runQuery.modifyRows(mode,'lists',queryName,[entry],action,crfSetup.getContainer('data'));
- }
- crfVisit.updateLastSavedFlag=
- function(data,setup,elementId){
- let fName='[updateLastSavedFlag]';
- this.print(fName+" update last saved flag to "+elementId);
- let el=crfHTML.getElement(elementId);
- let dt=new Date();
- el.innerHTML="Last saved "+dt.toString();
- if (data.queryName=="reviewComments"){
- this.updateListDisplay(setup.divReviewListId,"reviewComments",setup.filters,true);
- }
- //refresh stored data!
- let writeMode=!setup.readonlyFlag();
- let that=this;
- let cb=function(){that.populateTable(data.queryName,writeMode,setup);};
- if ("unique" in setup)
- crfData.setData(this.crfRef,cb);
- if ("masterQuery" in setup){
- let ad=crfSetup.getAdditionalData(setup.masterQuery);
- this.print('Updating list display: '+setup.queryName+'/'+ad.queryName);
- this.updateListDisplay(ad.divQueryName,ad.queryName,ad.filters,false);
- }
- }
- //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- //generic form status switch statementes
- crfVisit.changeFormStatusAndNotify=
- function(actionName){
- let fName='[changeStatusAndNotify]';
- this.print(fName);
- let targetStatus=crfSetup.getTargetStatus(actionName);
- let targetRecipient=crfSetup.getTargetRecipient(actionName);
- let actionSettings=crfSetup.getActionSettings(actionName);
- let action=new Object();
- action.name=actionName;
- let finalStep=function(){that.redirect();};
- if (variableList.hasVariable(actionSettings,"finalStep")){
- this.print(fName+' adjusting finalStep');
- //set to doNothing to remain on submit window
- if (actionSettings.finalStep=="doNothing"){
- finalStep=function(){that.doNothing();};
- }
- }
- this.print(fName+' action '+actionName+' targetStatus '+targetStatus);
- let that=this;
- action.cb=function(data){that.sendEmail(data,targetRecipient,finalStep,actionName);}
- this.updateFlag(targetStatus,action);//Approved
- }
- crfVisit.updateFlag=
- function(flag,action){
- let fName='[updateFlag]';
- let entry=crfData.getCrfEntry();
- entry.FormStatus=flag;
- let uId=LABKEY.Security.currentUser.id;
- entry[this.role]=uId;
- this.print(fName+': Form: '+entry.Form);
- this.print(fName+": set form status to "+entry.FormStatus);
- let that=this;
- let cb=function(data){that.completeWithFlag(data,action);};
- runQuery.modifyRows('update','lists','crfEntry',[entry],cb,crfSetup.getContainer('data'));
-
- }
- crfVisit.completeWithFlag=
- function(data,action){
- let fName='[completeWithFlag]';
- this.print(fName+': nrows '+data.rows.length);
- let fentry=data.rows[0];
- this.print(fName+': form status '+fentry.FormStatus);
- this.print(fName+': form '+fentry.Form);
- let crfStatus=crfData.createCrfStatus(fentry);
- crfStatus.operator=this.role;
- crfStatus.action=action.name;
- let that=this;
- let cb=function(){that.doNothing();};
- if (action.cb) cb=action.cb;
- runQuery.insertRows('lists','crfStatus',[crfStatus],cb,crfSetup.getContainer('data'));
- }
- //******************************************upload to database *********************
- crfVisit.onDatabaseUpload=
- function(){
- let actionName='onDatabaseUpload';
- let fName='['+actionName+']';
- this.print(fName);
- let pM=this.getIdManager();
- let participantId=participantIdManager.getParticipantIdFromCrfEntry(pM);
-
- let that=this;
- let crfRef=this.crfRef;
-
- //load lists and study data
- //check what needs to be updated and upload
- //a (reverse) sequence of functions
- let completeUpload=function(){that.changeFormStatusAndNotify(actionName);};
- let uploadData=function(){crfData.uploadData(participantId,crfRef,completeUpload);};
- let loadStudy=function(){crfData.setData(crfRef,uploadData,'study');}
- crfData.setData(crfRef,loadStudy,'lists');
- }
- //*************************update for further review *************************
- crfVisit.onUpdateForReview=
- function(){
- let actionName='onUpdateForReview';
- this.changeFormStatusAndNotify(actionName);
- }
- //************************************************ submit *******************************************
- crfVisit.onSubmit=
- function(){
- //update list storage and change status
- this.hideErr();
- this.clearErr();
- this.printErr("onSubmit");
- let that=this;
- let actionName='onSubmit';
- let action=function(){that.verifyData(actionName);};
- crfData.setData(this.crfRef,action);
-
- }
- crfVisit.verifyData=
- function(actionName){
- let fName='[verifyData/'+actionName+']';
- let qList=crfData.getActiveQueries();
- let that=this;
- let doNothing=function(data){that.doNothing();};
- let pM=this.getIdManager();
- let fieldName=participantIdManager.getCrfEntryFieldName(pM);
- let setId=crfData.getCrfEntry()[fieldName];
- this.print(fName+' crfEntry ['+fieldName+'] '+crfData.getCrfEntry()[fieldName]);
-
- if (!setId){
- this.printErr('Missing ID !');
- return false;
- }
- for (let qId in qList){
- let entry=qList[qId];
- let q=entry['queryName'];
- let qData=crfData.getQuerySnapshot(q);
- if (q=="reviewComments") continue;
- //copy snapshot to history
- if (qData.rows.length==0){
- this.print(fName+' no rows for '+q);
- }
- else
- runQuery.insertRows('lists',q+'History',qData.rows,doNothing,this.getContainer('data'));
- //if it doesn't have additionalData, it is a sub query
- if (!(q in crfSetup.getAdditionalDataObject())){
- continue;
- }
- if (qData.rows.length<1){
- this.printErr('Missing entry for query '+q);
- return false;
- }
- }
- //this is necessary only for Generated to Generation completed step
- let actionSettings=crfSetup.getActionSettings(actionName);
- if (variableList.hasVariable(actionSettings,"updateRegistration")){
- //if updateRegistrationFormId is set, only update when submit is used on that form
- if (variableList.hasVariable(actionSettings,"updateRegistrationFormId")){
- let formId=crfData.getCrfEntry()['Form'];
- if (actionSettings['updateRegistrationFormId']==formId)
- this.updateRegistration();
- }
- else
- this.updateRegistration();
- }
- this.changeFormStatusAndNotify(actionName);
- }
- crfVisit.getEmail=
- function(recipientCode){
- this.print('getEmail w/'+recipientCode);
- let recipients=new Array();
- let typeTo=LABKEY.Message.recipientType.to;
- let create=LABKEY.Message.createRecipient;
- let userMap=crfSetup.getEntryMap('users');
- let currentUser=userMap[LABKEY.Security.currentUser.id];
- let currentSite=this.siteEntry;
- let formCreator=userMap[crfData.getCrfEntry()['UserId']];
- let userRows=crfSetup.getRows('users');
- let parentUser=null;
- if ("parentCrfData" in crfSetup){
- let parentCrf=crfSetup.getRows('parentCrfData');
- parentUser=userMap[parentCrf.rows[0].UserId];
- }
-
- let recipientCategories=recipientCode.split(',');
- for (let i=0;i<recipientCategories.length;i++){
- let recipient=recipientCategories[i];
- this.print('Checking '+recipient);
- if (recipient=='crfEditor'){
- this.print('Adding :'+formCreator.Email);
- recipients.push(create(typeTo,formCreator.Email));
- if (!parentUser) continue;
- this.print('Adding :'+parentUser.Email);
- recipients.push(create(typeTo,parentUser.Email));
- continue;
- }
- //Monitor or Sponsor
- let fList=recipient+'s';
- let fRows=crfSetup.getRows(fList);
- for (let i=0;i<fRows.length;i++){
- this.print('Checking '+fRows[i].User+'/'+fRows[i].Site);
- if (fRows[i].Site!=currentSite.siteNumber) continue;
- let targetUser=userMap[fRows[i].User];
- recipients.push(create(typeTo,targetUser.Email));
- }
- }
- return recipients;
- }
- crfVisit.sendEmail=
- function(data,recipient='crfEditor',cb=null,subj='Form submitted'){
- this.print('sendEmail; recipient: '+recipient);
- let that=this;
- if (!cb)
- cb=function(){that.redirect();};
- let cvar='sendEmail';
- let cval=crfSetup.getSettings(cvar);
- if (cval){
- this.print(cvar+' set to '+cval);
- if (cval=='FALSE'){
- this.print('Skipping sending emails');
- cb();
- return;
- }
- }
- if (recipient==null){
- this.print('Skipping sending emails w/ no recipients');
- cb();
- return;
- }
- this.print('send email '+data.rows.length);
- let crf=data.rows[0]['entryId'];
- let formId=data.rows[0]['Form'];
- let link=LABKEY.ActionURL.getBaseURL();
- link+=LABKEY.ActionURL.getContainer();
- link+='/crf_tecant-visit.view?';
- link+='entryId='+crf;
- link+='&formId='+formId;
- link+='&role='+recipient;
- //debug
- let recipients=this.getEmail(recipient);
- //from crfManagers list
-
- let typeHtml=LABKEY.Message.msgType.html;
- let typePlain=LABKEY.Message.msgType.plain;
- let msg1=LABKEY.Message.createMsgContent(typePlain,link);
- //let cb=doNothing;
- //let cb=redirect;
- LABKEY.Message.sendMessage({
- msgFrom:'labkey@fmf.uni-lj.si',
- msgSubject:subj,
- msgRecipients:recipients,
- msgContent:[msg1],
- success: cb
- });
- }
- crfVisit.hideErr=
- function(){
- let el=crfHTML.getElement("errorDiv");
- el.style.display="none";
- }
- crfVisit.clearErr=
- function(){
- let el=crfHTML.getElement("errorTxt");
- el.value="";
- }
- crfVisit.showErr=
- function(){
- let el=crfHTML.getElement("errorDiv");
- el.style.display="block";
- }
- crfVisit.printErr=
- function(msg){
- this.showErr();
- el=crfHTML.getElement("errorTxt");
- el.style.color="red";
- el.value+="\n"+msg;
- }
- //**************************************************
- //
- crfVisit.onRemoveCRF=
- function(){
- let fName='[onRemoveCRF]';
- let crfRef=this.crfRef;
- this.print(fName+' starting loop');
- let actionName='onRemoveCRF';
- let that=this;
- let notify=function(){that.changeFormStatusAndNotify(actionName);};
- //let removeCrfEntry=function(){crfData.removeCrfEntry(notify);};
- let removeData=function(){crfData.removeData(notify);};
- let setStudyData=function(){crfData.setData(crfRef,removeData,'study');};
- let action=setStudyData;
- let actionSettings=crfSetup.getActionSettings(actionName);
- if (variableList.hasVariable(actionSettings,'removeWithParentCrf')){
- //if some query needs to be deleted with parent crf, insert this as an intermediate action
- let q=actionSettings['removeWithParentCrf'];
- let parentCrf=crfData.getCrfEntry()['parentCrf'];
- if (parentCrf){
- let setParentStudyData=function(){crfData.setDataForQuery(q,parentCrf,removeData,'study');};
- let setStudyData1=function(){crfData.setData(crfRef,setParentStudyData);}
- action=function(){crfData.setDataForQuery(q,parentCrf,setStudyData1);};
- }
- }
- crfData.setData(crfRef,action);
- }
- crfVisit.redirect=
- function(){
- let formUrl="participantPortal";
- let params=new Object();
- params.name=formUrl;
- //params.pageId="CRF";
- //points to crf container
- let containerPath=crfSetup.getContainer('CRF');
-
- // This changes the page after building the URL.
- //Note that the wiki page destination name is set in params.
-
- //let homeURL = LABKEY.ActionURL.buildURL("project", formUrl , containerPath, params);
- let homeURL = LABKEY.ActionURL.buildURL("crf", formUrl , containerPath, params);
- this.print("Redirecting to "+homeURL);
- window.location = homeURL;
- }
- //master section, entry point from html files
- crfVisit.generateMasterForm=
- function(){
- let that=this;
- let action=function(){that.setFormConfig();}
- this.init(action);
- }
- //helper function to set basic parameters on web page
- //(fields defined in html file)
- crfVisit.populateBasicData=
- function(){
- let staticData=new Object();
- let titles=new Object();
- staticData['version']='0.16.3'
- titles['version']='Software version';
- let varRows=crfSetup.getRows('crfStaticVariables');
- for (let i=0;i<varRows.length;i++){
- let vName=varRows[i].staticVariable;
- let val=crfData.getCrfEntry()[vName];
- if (val==undefined) continue;
- staticData[vName]=val;
- titles[vName]=varRows[i].Title;
- }
- staticData['investigatorName']=this.userEntry['DisplayName'];
- titles['investigatorName']='Investigator';
- staticData['email']=this.userEntry['Email'];
- titles['email']='Email';
- staticData['siteName']=this.siteEntry['siteName'];
- titles['siteName']='Site';
- staticData['sitePhone']=this.siteEntry['sitePhone'];
- titles['sitePhone']='Telephone(site)';
- for (f in staticData){
- this.addStaticData(f,titles[f],staticData[f]);
- }
- let formId=crfData.getCrfEntry()['Form'];
- let formEntry=crfSetup.getEntryMap('dataForms')[formId];
- crfHTML.getElement('formTitle').innerText=formEntry['formName'];
- }
- crfVisit.addStaticData=
- function(f,title,value){
- let el=crfHTML.getElement(f);
- //populate only
- if (el!=undefined){
- el.innerText=value;
- return;
- }
-
- //add row to table if element cannot be found
- let table=crfHTML.getElement('staticTable');
- let row=table.insertRow();
- let cell=row.insertCell();
- cell.innerText=title;
- let cell1=row.insertCell();
- cell1.id=f;
- cell1.style.fontWeight='bold';
- //populate
- cell1.innerText=value;
- }
- //come here after the layout is read from labkey page
- //
- crfVisit.generateErrorMsg=
- function(msg){
- let txt=crfHTML.createParagraph(msg,this.masterForm);
- this.generateButton("submitDiv",'Exit','Exit','redirect');
- }
- crfVisit.checkPermissions=
- function(){
- //check if user has permission on the form
- let userMap=crfSetup.getEntryMap('users');
- let currentUser=userMap[LABKEY.Security.currentUser.id];
- let currentSite=this.siteEntry;
- let formCreator=userMap[crfData.getCrfEntry()['UserId']];
- let formCreatorId=formCreator.UserId;
- //let formSite=config.formConfig.crfEntry.Site;
- let fList=this.role+'s';
- let fRows=crfSetup.getRows(fList);
- //let currentSiteId=-1;
-
- //depending on operator mode, we should decide what is right
- let operator=this.role;
- if (this.role=='crfEditor'){
- //editor can only edit its own forms
- if (currentUser.UserId!=formCreatorId){
- let msg='User '+currentUser.DisplayName;
- msg+=' has no permission on this form';
- this.generateErrorMsg(msg);
- return false;
- }
- return true;
- }
- if (operator=='crfMonitor' || operator=='crfSponsor'){
- //monitor can look at forms based on his site
- //find monitor line
- let operatorSites=new Array();
- for (let i=0;i<fRows.length;i++){
- if (fRows[i].User!=currentUser.UserId) continue;
- operatorSites.push(fRows[i].Site);
- }
- this.print('operator Site: '+operatorSites.length);
- if (operatorSites.length==0){
- let msg='User '+currentUser.DisplayName;
- msg+=' is not a '+operator;
- this.generateErrorMsg(msg);
- return false;
- }
- //implementation of currentSite in operatorSites
- if (!operatorSites.includes(currentSite.siteNumber)){
- let msg='User '+currentUser.DisplayName;
- msg+=' is not a '+operator+' for site ';
- msg+=currentSite.siteName+'('+currentSite.siteNumber+')';
- msg+='/'+operatorSites.join(',');
- this.generateErrorMsg(msg);
- return false;
- }
- }
- this.print('User '+currentUser.DisplayName+'/'+
- currentSite['siteName']+
- ' acting as '+this.role);
- return true;
- }
- crfVisit.afterConfig=
- function(){
- let fName='[afterConfig]';
- this.print(fName);
-
- this.populateBasicData();
- if (!this.checkPermissions()) return;
- crfSetup.parseButtons();
-
- let formStatus=crfSetup.getRows('formStatus')[0]['formStatus'];
- //let functionArray=new Array();
- this.print("Generating buttons for formStatus \""+ formStatus+"\"");
- let allButtonRows=crfSetup.getRows('crfButtons');
- let buttonRows=new Array();
-
- //specifying role=X in actionSettings will limit button to that role
- for (let i=0;i<allButtonRows.length;i++){
- let action=allButtonRows[i]['action'];
- //filter on actionSettings
- let as=crfSetup.getActionSettings[action];
- if (variableList.hasVariable(as,'role')){
- this.print('Role['+this.role+'/'+as['role']+'] limited for action '+action);
- //mismatch skips addition of button to buttonRows
- if (this.role!=as['role']) continue;
- }
- buttonRows.push(allButtonRows[i]);
- }
- for (let i=0;i<buttonRows.length;i++){
- let bt=buttonRows[i];
- //if (typeof window[bt.action]==="function"){
- this.generateButton("submitDiv",bt.caption,bt.label,bt.action,null);
- //}
- //else{
- // this.print('No match for function :'+bt.action+
- // ' obj: '+window[bt.action]);
- //}
- }
- this.print('Here');
- //here we should get data. For now, just initialize objects that will hold data
- let that=this;
- let action=function(){that.afterDataLayout();};
- let formId=crfData.getCrfEntry()['Form'];
- crfData.setDataLayout(formId,this.role,action);//callback is afterDataLayout
- }
- crfVisit.afterDataLayout=
- function(){
- let that=this;
- let action=function(){that.afterData();};
- //let action=function(){that.doNothing();};
- crfData.setData(this.crfRef,action);//callback is afterData
- }
- crfVisit.updateRegistration=
- function(){
- let fName="[updateRegistration]";
- this.print(fName);
- let pM=this.getIdManager();
- let idFieldName=participantIdManager.getCrfEntryFieldName(pM,"STUDY");
- //have to reload query data
- let regQueryPars=variableList.parseVariables(crfSetup.getSettings('registrationQuery'));
- let regQuery=regQueryPars['query'];
- let fQuery=crfData.getQuerySnapshot(regQuery);
- if (fQuery.rows.length==0) {
- this.print(fName+" registration is empty");
- return; //registration is empty
- }
- let regEntry=fQuery.rows[0];
- for (x in regEntry){
- this.print(fName+" ["+x+"] "+regEntry[x]);
- }
- let studyId=fQuery.rows[0][idFieldName];
- if (!studyId) {
- this.print(fName+" study id not set ("+idFieldName+'/'+studyId+")");
- return; //study id not set
- }
-
- //set
- participantIdManager.setParticipantIdToCrfEntry(pM,studyId,"STUDY");
- //this will only update crfEntry in memory, but not on LabKey,
- //we are counting on updateFlag to follow updateRegistration
- //update parentCRF as well, here we schedule update of data entry as well
- if ("parentCrfData" in crfSetup){
- let parentCrfEntry=crfSetup.getRows('parentCrfData')[0];
- parentCrfEntry[idFieldName]=studyId;
- let that=this;
- let action={name:"updateRegistration",cb:function(){that.doNothing();}};
- let cb=function(data){that.completeWithFlag(data,action);};
- this.modifyRows('update','lists','crfEntry',[parentCrfEntry],cb,crfSetup.getContainer('CRF'));
- }
-
- }
- crfVisit.afterData=
- function(){
- let fName='afterData';
- this.configureIdManager();
- this.generateSections();
- }
- crfVisit.configureIdManager=
- function(){
- let idMode=this.formEntry['idMode'];
- //set default value if no value is in the list (read value is null)
- if (!idMode) idMode="STUDY:EDIT";
- this.print(fName+': idMode '+idMode);
- //add print to config so participantManager can use it
- let pM=this.getIdManager();
- //extend object
- let that=this;
- let action=new Object();
- action.name='updateCrfEntry';
- action.cb=function(){that.doNothing();};
- let formStatus=crfData.getCrfEntry()['FormStatus'];
- pM.updateCrfEntry=function(){that.updateFlag(formStatus,action);};
- let idModeArray=idMode.split(':');
- pM.mode="STUDY";
- if (idModeArray.includes("LOCAL")) {
- pM.mode="LOCAL";
- //OK, but check if CRF or registration indicate that study id is already set
- participantIdManager.verifyCrfStudyId(pM);
- //study id should already be set by updateRegistration
- //verifyRegistration(pM);
- }
- if (idModeArray.includes("READONLY")){
- pM.readOnly="TRUE";
- }
-
- let pId=participantIdManager.getParticipantIdFromCrfEntry(pM);
- if (!pId){
- participantIdManager.setEditMode(pM);
- }
- else{
- let label=pId;
- if (pM.mode=="STUDY"){
- let loc=participantIdManager.getParticipantIdFromCrfEntry(pM,'LOCAL');
- label=pId+':'+loc;
- pM.readOnly="true";
- }
- participantIdManager.setLabelMode(pM,label);
- //in STUDY mode also change LOCAL ID from crfEntry
-
- }
- }
- crfVisit.generateSections=
- function(){
- let accessMode=this.role+'Mode';
- let formId=crfData.getCrfEntry()['Form'];
- let rowsSetup=crfSetup.selectFormSetupRows(formId);
- for (let i=0;i<rowsSetup.length;i++){
- let entry=rowsSetup[i];
- //debug
- let queryName=crfSetup.getMap('inputLists')[entry['queryName']];
- this.print(fName+" ["+queryName+"]: showFlag: "+entry["showFlag"]);
- this.print(fName+" ["+queryName+"]: accessMode: "+entry[accessMode]);
- const nData=crfData.getQuerySnapshot(queryName).rows.length;
- this.print(fName+" ["+queryName+"]: nData: "+nData);
- //skip sections
- //also from fields
- if (entry[accessMode]=="NONE") continue;
-
- //section fits one dataset/list
- this.generateSection(entry);
- }
- }
- crfVisit.populateSection=
- function(sectionId){
- let fName='[populateSection/'+sectionId+']';
- this.print(fName);
- //old setting
- let entry=crfSetup.findSetupRow(sectionId);
- //ignore names without associated entry in formSetup
- if (!entry){
- this.print(fName+': no matching FormSetup entry found');
- return;
- }
- //populate comes after generate, we should be pretty safe in taking
- //already generated additionalData
- let queryName=crfSetup.getMap('inputLists')[entry['queryName']];
- if (!(queryName in crfSetup.getAdditionalDataObject())){
- this.print(fName+': no additionalData generated for '+queryName);
- return;
- }
-
- let additionalData=crfSetup.getAdditionalData(queryName);
- this.print(fName+': using additionalData '+additionalData);
- if ("isReview" in additionalData){
- let action=function(){crfReviewSection.CB();};
- crfReviewSection.generateSection(queryName,queryName,action);
- return;
- }
- let accessMode=this.role+'Mode';
- let aM=entry[accessMode];
- this.print(fName+': accessMode '+aM);
- if (aM!='GENERATE'){
- let writeMode=entry[accessMode]=='EDIT';
- this.print(fName+': mode='+writeMode);
- let setup=this.getStoredSetup(sectionId);
- this.populateTable(queryName,writeMode,setup);
- return;
- }
- //deal with generate
- //
- //already available -> shift to READ mode
- let divTable=queryName+'Table';
- let divObj=crfHTML.getElement(divTable);
- let divRev=crfHTML.getElement(queryName+'Review');
- let divRLi=crfHTML.getElement(queryName+'ReviewList');
- let divGBu=crfHTML.getElement(queryName+'GenerateButton');
- this.print('div GBU: '+divGBu);
- divObj.style.display="block";
- divRev.style.display="block";
- divRLi.style.display="block";
- if (divGBu!=undefined) divGBu.style.display="none";
- let nData=crfData.getQuerySnapshot(queryName).rows.length;
- let setup=this.getSetup(sectionId,queryName,0);
- this.print('['+queryName+']: nrows '+nData);
- if (nData>0){
- this.populateTable(queryName,0,setup);
- return;
- }
- //hide table
- divObj.style.display="none";
- divRev.style.display="none";
- divRLi.style.display="none";
- if (divGBu!=undefined) divGBu.style.display="block";
- //add buttons?
- //is button already generated?
-
- //populateTable(entry);
-
- }
- //******* generateQuery infrastructure *********************
- crfVisit.onGenerateQuery=
- function(queryName){
- let fName='[onGenerateQuery]';
- this.print(fName+' '+queryName);
- //
- let cfgRows=crfSetup.getRows('generateConfigData');
- // //queryName to queryId?
- let qMapInverse=crfSetup.invertMap(crfSetup.getMap('inputLists'));
- let queryId=qInverseMap[queryName];
- let cfgRow=crfSetup.getEntryMap('generateConfigData')[queryId];
-
- if (!cfgRow){
- this.print('generateConfig for queryName['+queryId+']='+queryName+' not found');
- return;
- }
- //let formRows=crfSetup.selectFormSetupRows(cfgRow.formId);
- //
- // //check if all required datasets were at least saved
- this.checkGenerationFields(cfgRow);
- }
- crfVisit.checkGenerationFields=
- function(entry){
- //entry is generateConfig row
- let fName='[checkGenerationFields]';
- let mailRecipient=crfRow.emailRecipient;
- let qMap=crfSetup.getMap('inputLists');
- let qName=qMap[entry['queryId']];
- //list of queries that are part of Registration form
- this.print(fName);
- this.print(fName+' setRecipient: '+mailRecipient);
- let formId=entry['formId'];
- this.print(fName+" Checking form w/id "+formId);
- let formRows=this.selectFormSetupRows(formId);
- //registration rows
- for (let i=0;i<formRows.length;i++){
- let row=formRows[i];
- let queryId=row.queryName;
- if (queryId==entry.queryId) continue;
- let fQuery=crfData.getQuerySnapshot(qMap[queryId]);
- this.print('Checking '+qMap[queryId]+' nrows: '+fQuery.rows.length);
- if (fQuery.rows.length==0){
- this.generateError(qName,qMap[queryId]);
- return;
- }
- }
- this.generateMessage(qName,'Vailidation OK');
- this.print('callback: set recipient: '+mailRecipient);
- let that=this;
- let cb=function(){that.prepareForm(entry,mailRecipient);};
- this.generateListEntry(entry.formId,qName,cb);
- }
- crfVisit.prepareForm=
- function(entry,mailRecipient){
- //entry is generateConfig row
- let fName="[prepareForm]";
- let formId=entry['formId'];
- this.print(fName+' recipient '+mailRecipient);
- //look for existing registration entry
- let that=this;
- let action=function(data){that.generateForm(data,entry,mailRecipient);};
- let formFilter=LABKEY.Filter.create('Form',formId);
- let parentCrfFilter=LABKEY.Filter.create('parentCrf',this.crfRef);
- let filters=[formFilter,parentCrfFilter];
- this.selectRows('lists','crfEntry',filters,action,crfSetup.getContainer('data'));
- }
- crfVisit.generateError=
- function(queryName,fQueryName){
- let elName=queryName+'GenerateButton'+'_reportField';
- let el=crfHTML.getElement(elName);
- el.innerText='Error: '+fQueryName+' was not set';
- el.style.color='red';
- }
- crfVisit.generateMessage=
- function(queryName,msg){
- let elName=queryName+'GenerateButton'+'_reportField';
- let el=crfHTML.getElement(elName);
- el.innerText=msg;
- el.style.color='green';
- }
- crfVisit.generateForm=
- function(data,entry,mailRecipient){
- //entry is generateConfig entry
- let fName='[generateForm]';
- this.print(fName+' recipient: '+mailRecipient);
- //
- const nData=data.rows.length;
- this.print(fName+' Registration: '+nData+' rows');
- //we have to generate masterQuery with parentCrf and crfRef
- //and crfEntry with new entryId and parentCrf equal to crfRef
- let queryName=crfSetup.getMap('inputLists')[entry['queryId']];
- if (nData>0) {
- this.generateMessage(queryName,'Registration already generated.');
- return;
- }
- let formId=entry['formId'];
- let formEntry=crfSetup.getMap('dataForms')[formId];
- let formName=formEntry.formName;
- let crfBase=crfData.getCrfEntry();
- let crfEntry=new Object();
- //add new reference
- crfEntry.entryId=Date.now();
- crfEntry.parentCrf=this.crfRef;
- crfEntry["Date"]=new Date();
- crfEntry["View"]="[VIEW]";
- crfEntry.formStatus=1;//In progress
- //checks for both field presence (if not in query, undefined) and field value (if not set, null)
- this.print(fName+' setup status: '+entry.formStatus);
- if (entry.formStatus){
- crfEntry.formStatus=entry.formStatus;
- }
- //get local Id
- let pM=this.getIdManager();
-
- crfEntry[participantIdManager.getCrfEntryFieldName(pM)]=participantIdManager.getParticipantIdFromCrfEntry(pM);
- // //set other variables
- //requires studyData as part of formConfig
- // let studyData=config.formConfig.studyData;
- this.print('Adding study: '+crfBase.EudraCTNumber);
- crfEntry.EudraCTNumber=crfBase.EudraCTNumber;
- crfEntry.StudyCoordinator=crfBase.StudyCoordinator;
- crfEntry.StudySponsor=crfBase.StudySponsor;
- crfEntry.RegulatoryNumber=crfBase.RegulatoryNumber;
- //
- // //find sponsor for site
- let site=crfBase.Site;
- let crfSponsors=crfSetup.getRows('crfSponsors');
- let userMap=crfSetup.getEntryMap('users');
- let sponsorId=null;
- for (let i=0;i<crfSponsors.length;i++){
- //take first matching sponsor
- if (crfSponsors[i].Site!=site) contnue;
- sponsorId=crfSponsors[i].User;
- //finds first
- break;
- }
- let sponsor=userMap[sponsorId];
- this.print('Selecting '+sponsor.DisplayName+' as sponsor');
- //different user than the original form...
- //should be set to the study sponsor
- crfEntry.UserId=sponsor.UserId;
- crfEntry.Site=site;
- // //set formId to one found through registration search
- crfEntry.Form=formId;
- ////
- let crfStatus=crfData.createCrfStatus(crfEntry);
- crfStatus.operator=this.role;
- crfStatus.action='generateForm';
- let that=this;
- let action=function(){that.doNothing();};
- let cb=function(data){that.sendEmail(data,mailRecipient,action,formName+' generated');}
- let containerPath=crfSetup.getContainer('data');
- let pass=function(data){runQuery.insertRows('lists','crfStatus',[crfStatus],cb,containerPath);};
- runQuery.insertRows('lists','crfEntry',[crfEntry],pass,crfSetup.getContainer('data'));
- }
- crfVisit.generateListEntry=
- function(formId,queryName,cb){
- //check if registration was already generated
- let formRows=crfSetup.selectFormSetupRows(formId);
- let nData=crfData.getQuerySnapshot(queryName).rows.length;
- if (nData>0) return;
- //create new list entry
- let pM=this.getIdManager();
-
- let e2=new Object();
- e2.crfRef=this.getCrfRef();
- e2.registrationStatus=0;
- e2.submissionDate=new Date();
- e2[participantIdManager.getCrfEntryFieldName(pM)]=participantIdManager.getParticipantIdFromCrfEntry(pM);
- this.print('set values');
- runQuery.insertRows('lists',queryName,[e2],cb,crfSetup.getContainer('data'));
- }
-
- // ******************** end form generator (Registration) ********************
- //jump to populate table/generate review, etc defined at the begining of the file
- //entry point from generateMasterForm
- crfVisit.setFormConfig=
- function(){
- let fName="[setFormConfig]";
- let crfRef=this.crfRef;
- let that=this;
- let afterCrfEntry=function(){that.afterCrfEntry();};
- let action=function(){crfData.setCrfEntry(crfRef,afterCrfEntry);};//afterCrfEntry
- crfSetup.setContainers(action);
- }
- crfVisit.afterCrfEntry=
- function(){
- let fName='[afterCRFEntry]';
- this.print("Setting crfEntry (x) to "+crfData.getCrfEntry()["entryId"]);
- //for empty records or those with parentCrf not set, parentCrf comes up as null
- //nevertheless, with two equal signs, check against undefined also works
- crfSetup.formStatus=crfData.getCrfEntry()['FormStatus'];
- let parentCrf=crfData.getCrfEntry()['parentCrf'];
- this.print('parentCrf set to '+parentCrf);
- if (parentCrf) crfSetup.parentCrf=parentCrf;
- let that=this;
- let action=function(){that.parseSetup();};
- crfSetup.parseSetup(action);
- }
- crfVisit.parseSetup=
- function(){
- //debug
- let fName='[parseSetup]';
- let varRows=crfSetup.getRows('crfStaticVariables');
- let studyVars=crfSetup.getRows('studyData')[0];
- for (let i=0;i<varRows.length;i++){
- let vName=varRows[i].staticVariable;
- this.print(fName+' '+vName+': '+studyVars[vName]);
- }
- //parse site
- this.siteEntry=crfSetup.getEntryMap('siteData')[crfData.getCrfEntry()['Site']];
- this.print("Setting site name to "+this.siteEntry['siteName']);
- //study
- this.print("XSetting participantField to "+studyVars["SubjectColumnName"]);
-
- //parse user
- this.userEntry=crfSetup.getEntryMap('users')[crfData.getCrfEntry()['UserId']];
- this.print("Setting user to "+this.userEntry["DisplayName"]);
- this.print('Setting operator to: '+this.role);
-
- //point formId to point to form set in crfEntry
- let formId=crfData.getCrfEntry()['Form'];
- this.formEntry=crfSetup.getEntryMap('dataForms')[formId];
- let accessModeColumn=this.role+'Status';
- let targetStatus=this.formEntry[accessModeColumn];
- let formStatus=crfData.getCrfEntry()['FormStatus'];
- this.print(fName+' comparing status '+formStatus+'/'+targetStatus);
- if (targetStatus!=formStatus){
- let statusMap=crfSetup.getEntryMap('formStatusAll');
- let targetEntry=statusMap[targetStatus];
- let actualEntry=statusMap[formStatus];
- alert('Form status ['+actualEntry.formStatus+'] not suitable to be operated by '+this.role+' targeting status ['+targetEntry.formStatus+']');
- this.redirect();
- }
- crfSetup.setAdditionalData(this.crfRef,formId);
-
- this.afterConfig();
- }
- crfVisit.uploadFile=
- function(inputElement,context){
- //context should have ID and dirName attributes;
- //path will be dirName/ID/fieldName_ID.suf
- //where suf is identical to localPath content picked from
- //inputElement
- this.print('uploadFile: '+inputElement.value+'/');
- if (inputElement.type=="text") return;
- this.print('uploadFile: '+inputElement.files+'/');
- this.print('uploadFile: '+inputElement.files.length+'/');
- if (inputElement.files.length>0){
- let file=inputElement.files[0];
- this.print('uploadFile: '+inputElement.value+'/'+file.size);
- webdav.uploadFile(file,context);
- }
- }
- crfVisit.printForm=
- function(){
- crfPrint.printForm();
- }
|