Skip to content

Commit

Permalink
[DQT] Fix dictionary builder and dictionary display issues (aces#8116)
Browse files Browse the repository at this point in the history
- backporting fix for the display of the dictionary in the DQT module aces#7098
- in the data_dictionary_builder script, reference the tesname value in parsed instruments (lorisform parser output format) instead of table while keeping it backwards compatible. This is needed because JSONdata instruments do not define a table variable and since [23.0.3] (https://github.com/aces/Loris/pull/7153/files#diff-962394c093e5275dcfa7cc6eca8927b2f8f592f42b7b95ec5921cb7fc0dc8453R88) the lorisform parser exports the test name in its output for this specific reason.
  • Loading branch information
ridz1208 authored Jul 5, 2022
1 parent d04ad08 commit 2e32249
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
1 change: 1 addition & 0 deletions modules/dataquery/jsx/react.fieldselector.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class FieldList extends Component {
// Display the fields using the FieldItem component
for (let i = start; i < filteredItems.length; i += 1) {
fieldName = filteredItems[i].key[1];
desc = filteredItems[i].value.Description;
type = filteredItems[i].value.Type || 'varchar(255)';

// Check if field is a file, if so set flag to true
Expand Down
54 changes: 32 additions & 22 deletions tools/exporters/data_dictionary_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@
);

$DB->delete("parameter_type_category", array("Type" => "Instrument"));

print "Cleared data from BVL instruments\n";

print "Reading instruments\n";
//Read the ip_output.txt staging file.
$fp = fopen(__DIR__."/../ip_output.txt", "r");
if (!$fp) {
print "There was an issue opening the ip_output file. Ensure the
print "There was an issue opening the ip_output file. Ensure the
file exists and the permissions are properly set.\n";
die();
}
Expand All @@ -100,24 +100,34 @@
foreach ($instruments AS $instrument) {
$catId = "";
$table = "";
$testname = "";
$items = explode("\n", trim($instrument));
foreach ($items AS $item) {
$paramId = "";
$bits = explode("{@}", trim($item));
switch($bits[0]){
case "testname":
break;
case "testname":
$testname = $bits[1];
print "Instrument: $testname\n";
break;
case "table":
$table = $bits[1];
print "Instrument: $table\n";
//`testname` was only recently added to the lorisform parser, for
//backwards compatibility, instruments with no testname parameter
//should assume the testname from the `table` name (to maintain
//status quo) although it might be incorrect since instrument names
//and table names could be different by design.
if (empty($testname)) {
$testname = $table;
}
break;

case "title":
$title = $bits[1];
// Check if there's already an entry with the same name and reuse same ID
// insertIgnore does not work here since name is not a Unique key in the database
$catId = $DB->pselectOne(
"SELECT ParameterTypeCategoryID
"SELECT ParameterTypeCategoryID
FROM parameter_type_category
WHERE Name=:name AND Type=:type",
array(
Expand Down Expand Up @@ -153,7 +163,7 @@
// the name from the examiner id
$bits[0] = "varchar(255)";
} else if ($bits[0]=="select") {
$bits[0] = enumizeOptions($bits[3], $table, $bits[1]);
$bits[0] = enumizeOptions($bits[3], $testname, $bits[1]);
} else if ($bits[0]=="textarea") {
$bits[0] ="text";
} else if ($bits[0]=="text") {
Expand All @@ -171,10 +181,10 @@
continue;
}

print "\tInserting $table $bits[1]\n";
print "\tInserting $testname $bits[1]\n";
$bits[2] = htmlspecialchars($bits[2]);
//find values to insert
$Name = $table . "_" . $bits[1];
$Name = $testname . "_" . $bits[1];
if (in_array($Name, $parameterNames, true)) {
// this specific table_field combination was already inserted, skip.
continue;
Expand All @@ -185,7 +195,7 @@
"Type" => $bits[0],
"Description" => $bits[2],
"SourceField" => $bits[1],
"SourceFrom" => $table,
"SourceFrom" => $testname,
"Queryable" => "1",
);

Expand Down Expand Up @@ -225,13 +235,13 @@
}
}

if (empty($table)) {
if (empty($testname)) {
continue;
}

// INSTRUMENT VALIDITY
print "\tInserting validity for $table\n";
$Name = $table . "_Validity";
print "\tInserting validity for $testname\n";
$Name = $testname . "_Validity";

if (in_array($Name, $parameterNames, true)) {
// this specific table_validity combination was already inserted, skip.
Expand All @@ -243,9 +253,9 @@
$query_params = array(
"Name" => $Name,
"Type" => $_type_enum,
"Description" => "Validity of $table",
"Description" => "Validity of $testname",
"SourceField" => "Validity",
"SourceFrom" => $table,
"SourceFrom" => $testname,
"Queryable" => "1",
);

Expand Down Expand Up @@ -275,8 +285,8 @@
);

// INSTRUMENT ADMINISTRATION
print "\tInserting administration for $table\n";
$Name = $table . "_Administration";
print "\tInserting administration for $testname\n";
$Name = $testname . "_Administration";
if (in_array($Name, $parameterNames, true)) {
// this specific table__Administration combination was already inserted, skip.
continue;
Expand All @@ -286,9 +296,9 @@
$query_params = array(
"Name" => $Name,
"Type" => $_type_enum,
"Description" => "Administration for $table",
"Description" => "Administration for $testname",
"SourceField" => "Administration",
"SourceFrom" => $table,
"SourceFrom" => $testname,
"Queryable" => "1",
);

Expand Down Expand Up @@ -346,12 +356,12 @@
* enums
*
* @param string $options The line of the ip_output.txt to enumize
* @param string $table The table containing this line
* @param string $testname The table containing this line
* @param string $name The name of the field being enumized
*
* @return string A valid MySQL format enum field string
*/
function enumizeOptions($options, $table, $name)
function enumizeOptions($options, $testname, $name)
{
$options =explode("{-}", $options);
foreach ($options as $option) {
Expand All @@ -361,7 +371,7 @@ function enumizeOptions($options, $table, $name)
}
}
if (!is_array($enum)) {
echo "$table $name $options\n";
echo "$testname $name $options\n";
}
$enum =implode(",", $enum);
return "enum($enum)";
Expand Down

0 comments on commit 2e32249

Please sign in to comment.