Ver código fonte

Fill database with pId set by manager object, fix pId after first visit, fix pId after completed registration, shift collection of ids to be source from registrationQuery, now part of crfSettings

Andrej Studen 2 anos atrás
pai
commit
f705b33bc1
1 arquivos alterados com 59 adições e 11 exclusões
  1. 59 11
      web/crf/crfVisit.js

+ 59 - 11
web/crf/crfVisit.js

@@ -1554,11 +1554,22 @@ function updateLastSavedFlag(data,setup,elementId){
 
 //******************************************upload to database *********************
 
-
 function onDatabaseUpload(){
 	let fName='[onDatabaseUpload]';
 	print(fName);
 	config.upload=new Object();
+   let fc=new Object();
+   let pM=getParticipantManagerObject(config);
+   fc.participantId=pM.getParticipantIdFromCrfEntry();
+	print(fName+' id '+fc.participantId);
+   afterParticipantId(fc);
+}
+
+
+function onDatabaseUpload1(){
+	let fName='[onDatabaseUpload]';
+	print(fName);
+	config.upload=new Object();
 	//figure out the participantId
 	
 	let masterQueryId=config.formConfig.form["masterQuery"];
@@ -2371,7 +2382,7 @@ function populateBasicData(){
    let titles=new Object();
    staticData['version']=config.formConfig.softwareVersion;	
    titles['version']='Software version';
-	let varRows=config.formConfig['crfStaticVariables'].rows;
+   let varRows=config.formConfig['crfStaticVariables'].rows;
    for (let i=0;i<varRows.length;i++){
       let vName=varRows[i].staticVariable;
       let val=config.formConfig.crfEntry[vName];
@@ -2554,6 +2565,35 @@ function afterDataLayout(){
 	setData(afterData);//callback is afterData
 }
 
+function verifyCrfStudyId(pM){
+
+   //is studyId already set for the crf
+   let studyId=pM.getParticipantIdFromCrfEntry('STUDY');
+   if (!studyId) return;
+   pM.mode="STUDY";
+   pM.readOnly="TRUE";
+}
+
+function verifyRegistration(pM){
+   //if registration is in, 
+   //then local id should not be changed any longer
+   let idFieldName=pM.getCrfEntryFieldName("STUDY");
+   let registrationQuery=config.formConfig.settings['registrationQuery'];
+   if (!registrationQuery) return; //LOCAL is OK
+   let fQuery=config.formConfig.dataQueries[registrationQuery];
+   if (!fQuery) return; //no registration query, then it should be ignored
+   if (fQuery.rows.length==0) return; //registration is empty
+
+   let studyId=fQuery.rows[0][idFieldName];
+   if (!studyId) return; //study id not set
+   //set 
+   pM.mode="STUDY";
+   pM.readOnly="TRUE";
+   //set crf (this happens later, but probably before the form will be corrected)
+   pM.setParticipantIdToCrfEntry(studyId,"STUDY");
+   pM.updateCrfEntry();
+}
+
 function afterData(){
 	let fName='afterData';
 	//operatorBasedAccessMode	
@@ -2565,29 +2605,37 @@ function afterData(){
    if (!idMode) idMode="STUDY:EDIT";
 
    print(fName+': idMode '+idMode);
-   //generateParticipantEntryField();
    //add print to config so participantManager can use it
    config.print=print;
    let pM=getParticipantManagerObject(config);
-   //if (allowNewLocalId=="TRUE") pM.allowNewLocalId=true;
+   pM.updateCrfEntry=function(){updateFlag(config.formConfig.crfEntry['FormStatus'],doNothing);};   
+
    let idModeArray=idMode.split(':');
+   pM.mode="STUDY";
    if (idModeArray.includes("LOCAL")) {
       pM.mode="LOCAL";
-   }
-   else {
-      pM.mode="STUDY";
+      //OK, but check if CRF or registration indicate that study id is already set
+      verifyCrfStudyId(pM);
+      verifyRegistration(pM);
    }
    if (idModeArray.includes("READONLY")){
       pM.readOnly="TRUE";
    }
-   pM.updateCrfEntry=function(){updateFlag(config.formConfig.crfEntry['FormStatus'],doNothing);};   
    
    let pId=pM.getParticipantIdFromCrfEntry();
    if (!pId){
       pM.setEditMode();
    }
    else{
-      pM.setLabelMode(pId);
+      let label=pId;
+      if (pM.mode=="STUDY"){
+         let loc=pM.getParticipantIdFromCrfEntry('LOCAL');
+         label=pId+':'+loc;
+         pM.readOnly="true";
+      }
+      pM.setLabelMode(label);
+      //in STUDY mode also change LOCAL ID from crfEntry
+      
    }
 
 	for (let i=0;i<rowsSetup.length;i++){
@@ -3099,9 +3147,9 @@ function addStudyData(){
 	e.columns=columnModel;
 
    //also collect ids already in study
-   let demoQuery=config.formConfig.settings['demographicQuery'];
+   let demoQuery=config.formConfig.settings['registrationQuery'];
 
-   queryArray.push(makeQuery(targetObject,'data',demoQuery,'demographicData',[]));
+   queryArray.push(makeQuery(targetObject,'data',demoQuery,'registrationData',[]));
    queryArray[queryArray.length-1].schemaName='study';