diff --git a/modules/instruments/php/instrumentqueryengine.class.inc b/modules/instruments/php/instrumentqueryengine.class.inc index 76d725f4107..eee9e049837 100644 --- a/modules/instruments/php/instrumentqueryengine.class.inc +++ b/modules/instruments/php/instrumentqueryengine.class.inc @@ -1,6 +1,10 @@ pselectCol("SELECT Test_name FROM test_names", []); $dict = []; + + // Use the same option enums for all instruments + $adminoptions = new Enumeration('None', 'Partial', 'All'); + $dataentryoptions = new Enumeration('In Progress', 'Complete'); + $validityoptions = new Enumeration('Questionable', 'Invalid', 'Valid'); + + $cardinality = new Cardinality(Cardinality::SINGLE); + $scope = new Scope(Scope::SESSION); + foreach ($rows as $testname) { try { - $inst = \NDB_BVL_Instrument::factory( + $inst = \NDB_BVL_Instrument::factory( $this->loris, $testname, "", "", ); - $cat = new \LORIS\Data\Dictionary\Category( + $cat = new \LORIS\Data\Dictionary\Category( $testname, $inst->getFullName() ); - $fields = $inst->getDataDictionary(); + + $fields = [ + new DictionaryItem( + $inst->testName.'_Administration', + 'Administration flag for ' . $inst->getFullName(), + $scope, + $adminoptions, + $cardinality, + 'Administration', + ), + new DictionaryItem( + $inst->testName.'_Data_entry', + 'Data entry status for ' . $inst->getFullName(), + $scope, + $dataentryoptions, + $cardinality, + 'Data_entry', + ), + ]; + if ($inst->ValidityEnabled) { + $fields[] = new DictionaryItem( + $inst->testName.'_Validity', + 'Test validity for ' . $inst->getFullName(), + $scope, + $validityoptions, + $cardinality, + 'Validity', + ); + } + $fields = array_merge($fields, $inst->getDataDictionary()); $dict[] = $cat->withItems($fields); } catch (\LorisException $e) { error_log($e); @@ -329,11 +371,25 @@ class InstrumentQueryEngine implements \LORIS\Data\Query\QueryEngine $candData[$dict->getName()] = []; } $sid = $loadedInstrument->getSessionID(); - $candData[$dict->getName()][$sid->__toString()] = [ - 'VisitLabel' => $loadedInstrument->getVisitLabel(), - 'SessionID' => $sid->__toString(), - 'value' => $loadedInstrument->getDictionaryValue($dict), - ]; + switch ($dict->fieldname) { + case 'Administration': + case 'Data_entry': + case 'Validity': + $flags = $loadedInstrument->getFlags()->toArray(); + $candData[$dict->getName()][$sid->__toString()] = [ + 'VisitLabel' => $loadedInstrument->getVisitLabel(), + 'SessionID' => $sid->__toString(), + 'value' => $flags[$dict->fieldname], + ]; + break; + default: + $candData[$dict->getName()][$sid->__toString()] = [ + 'VisitLabel' => $loadedInstrument->getVisitLabel(), + 'SessionID' => $sid->__toString(), + 'value' => $loadedInstrument + ->getDictionaryValue($dict), + ]; + } } } yield "$iCandID" => $candData; diff --git a/php/libraries/NDB_BVL_Instrument.class.inc b/php/libraries/NDB_BVL_Instrument.class.inc index 98aa6e7e01f..83066c59ee2 100644 --- a/php/libraries/NDB_BVL_Instrument.class.inc +++ b/php/libraries/NDB_BVL_Instrument.class.inc @@ -2275,26 +2275,52 @@ abstract class NDB_BVL_Instrument extends NDB_Page (SELECT CommentID FROM load_comment_ids)"; } if ($condition !== null) { - $conditions[] = 'JSON_VALUE(Data, "$.' - . substr( + $fname = substr( $condition->dictionary->getName(), strlen($this->testName)+1 - ) - . '") ' - . \LORIS\Data\Query\SQLQueryEngine::sqlOperator($condition->criteria) - . ' ' - . \LORIS\Data\Query\SQLQueryEngine::sqlValue( - $condition->dictionary, - $condition->criteria, - $params - ) - . ' '; + ); + if ($fname == 'Administration' + || $fname == 'Validity' + || $fname == 'Data_entry' + ) { + $conditions[] = "flag.$fname" + . \LORIS\Data\Query\SQLQueryEngine::sqlOperator( + $condition->criteria + ) + . \LORIS\Data\Query\SQLQueryEngine::sqlValue( + $condition->dictionary, + $condition->criteria, + $params + ) + . ' '; + } else { + + $conditions[] = 'JSON_VALUE(Data, "$.' + . substr( + $condition->dictionary->getName(), + strlen($this->testName)+1 + ) + . '")' + . \LORIS\Data\Query\SQLQueryEngine::sqlOperator( + $condition->criteria + ) + . \LORIS\Data\Query\SQLQueryEngine::sqlValue( + $condition->dictionary, + $condition->criteria, + $params + ) + . ' '; + } + $conditions[] ="t.CommentID NOT LIKE 'DDE_%'"; } $where = 'WHERE ' . join(' AND ', $conditions); $query = "SELECT CandID, SessionID, CommentID, session.Visit_Label as VisitLabel, + flag.Administration, + flag.Data_entry as DataEntry, + flag.Validity, Data FROM flag JOIN session ON (session.ID=flag.SessionID) @@ -2306,12 +2332,18 @@ abstract class NDB_BVL_Instrument extends NDB_Page foreach ($jsondata as $row) { $newinst = clone $this; - $newinst->candID = new CandID(strval($row['CandID'])); - $newinst->commentID = $row['CommentID']; - $newinst->visitLabel = $row['VisitLabel']; - $newinst->sessionID = new SessionID( - strval($row['SessionID']) + $newinst->candID = new CandID(strval($row['CandID'])); + $newinst->commentID = $row['CommentID']; + $newinst->visitLabel = $row['VisitLabel']; + $newinst->sessionID = new SessionID( + strval($row['SessionID']) + ); + $newinst->flags = new \InstrumentFlags( + $row['Data_entry'], + $row['Administration'], + $row['Validity'] ); + unset($row['Data_entry'], $row['Administration'], $row['Validity']); $newinst->instanceData = json_decode( $row['Data'] ?? '{}', true, @@ -2327,11 +2359,21 @@ abstract class NDB_BVL_Instrument extends NDB_Page (SELECT CommentID FROM load_comment_ids)"; } if ($condition !== null) { - $conditions[] = 't.' - . substr( + $fname = substr( $condition->dictionary->getName(), strlen($this->testName)+1 - ) + ); + if ($fname == 'Administration' + || $fname == 'Validity' + || $fname == 'Data_entry' + ) { + $tname = 'f.'; + } else { + $tname = 't.'; + } + + $conditions[] = $tname + . $fname . ' ' . \LORIS\Data\Query\SQLQueryEngine::sqlOperator( $condition->criteria @@ -2343,12 +2385,16 @@ abstract class NDB_BVL_Instrument extends NDB_Page $params ) . ' '; + $conditions[] ="t.CommentID NOT LIKE 'DDE_%'"; } $where = 'WHERE ' . join(' AND ', $conditions); $query = "SELECT session.CandID as CandID, t.CommentID as CommentID, session.Visit_Label as VisitLabel, + f.Administration, + f.Data_entry, + f.Validity, session.ID as SessionID, t.* FROM $this->table t JOIN flag f ON (t.CommentID=f.CommentID) @@ -2365,6 +2411,13 @@ abstract class NDB_BVL_Instrument extends NDB_Page $newinst->sessionID = new SessionID(strval($row['SessionID'])); unset($row['CommentID'], $row['VisitLabel'], $row['SessionID']); + $newinst->flags = new \InstrumentFlags( + $row['Data_entry'], + $row['Administration'], + $row['Validity'] + ); + unset($row['Data_entry'], $row['Administration'], $row['Validity']); + $newinst->instanceData = $row; yield $newinst; @@ -3071,6 +3124,7 @@ abstract class NDB_BVL_Instrument extends NDB_Page return $this->determineDataEntryAllowed(); } + private ?\InstrumentFlags $flags = null; /** * Gets the flags of that instrument * @@ -3078,6 +3132,9 @@ abstract class NDB_BVL_Instrument extends NDB_Page */ public function getFlags(): \InstrumentFlags { + if ($this->flags !== null) { + return $this->flags; + } $row = \NDB_Factory::singleton()->database()->pselectRow( 'SELECT Data_entry as dataentry, @@ -3093,11 +3150,12 @@ abstract class NDB_BVL_Instrument extends NDB_Page $administration = $row['administration'] ?? null; $validity = $row['validity'] ?? null; - return new \InstrumentFlags( + $this->flags = new \InstrumentFlags( $dataentry, $administration, $validity ); + return $this->flags; } /**