Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ following the documentation.
**PHP instruments** behave slightly differently than LINST instruments and
require more manual steps for installation. In order to be able to generate the
SQL table for PHP instruments, they must first be parsed. The LORIS codebase
includes a tool under the `tools/` directory called the `lorisform_parser.php`
includes a tool under the `tools/` directory called the `ip_output_builder.php`
allowing for a PHP instrument to be parsed into an intermediary serialized format
and automatically stored in the `tools/ip_output.txt` file.

Expand All @@ -48,11 +48,11 @@ Follow the steps below to install a new PHP instrument.
1. Move your newly created instrument `NDB_BVL_Instrument_TEST_NAME.class.inc`
into the `project/instruments/` directory.
2. Navigate to the LORIS `tools/` directory.
3. Run the instrument through the `lorisform_parser.php` to parse the PHP
3. Run the instrument through the `ip_output_builder.php` to parse the PHP
instrument into the intermediary serialed format.
```
ls ../project/instruments/NDB_BVL_Instrument_TEST_NAME.class.inc | php lorisform_parser.php
```
```
php ip_output_builder.php --one-instrument=TEST_NAME
```
4. Run the `generate_tables_sql.php` tool to converted the serialized format
into an SQL `CREATE TABLE` SQL patch. The patch will be created in the `project/`
directory by default.
Expand All @@ -64,10 +64,9 @@ Follow the steps below to install a new PHP instrument.
6. Register the instrument in the `test_names` table of the database by running
the following command. Make sure to replace the `'TEST_NAME'` value with the
actual test name used in your instrument.

```
INSERT INTO test_names (Test_name,Sub_group) SELECT 'TEST_NAME', ID FROM test_subgroups WHERE Subgroup_name='Instruments';
```
```
INSERT INTO test_names (Test_name,Sub_group) SELECT 'TEST_NAME', ID FROM test_subgroups WHERE Subgroup_name='Instruments';
```

> _**Note:** The `Sub_group` entry in the query above is necessary for the
> instrument registration. See the [Instrument Grouping](#instrument-grouping)
Expand Down Expand Up @@ -119,7 +118,3 @@ assigned to categories and sorted accordingly on the user's interface.
New entries can be added to the `test_subgroups` table to create new categories
and instruments can be assigned a category by updating the `Sub_group` column
in the `test_names` table with the desired `ID` from the `test_subgroups` table.




4 changes: 2 additions & 2 deletions modules/datadict/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The module displays and manages the data dictionary for fields
already stored in the LORIS `parameter_type` table. This table is
generally autopopulated and provides a dictionary for imaging headers
(populated by the imaging pipeline) and behavioural instruments
(populated by the `lorisform_parser.php` script).
(populated by the `tools/ip_output_builder.php` script).

It does not provide a way to enter new fields into the data dictionary,
or describe the data dictionary for arbitrary SQL fields which are
Expand All @@ -34,7 +34,7 @@ The data comes from two sources:
1. The LORIS imaging pipeline scripts, which must be setup separately
2. The `tools/data_dictionary_builder.php` script, which loads the
behavioural data dictionary based on the `ip_output.txt` file created
by `tools/lorisform_parser.php`
by `tools/ip_output_builder.php`

## Interactions with LORIS

Expand Down
2 changes: 1 addition & 1 deletion php/libraries/LorisFormDictionaryImpl.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use \LORIS\Data\Scope;
use \LORIS\Data\Cardinality;
/**
* Helper to extract a dictionary from a LorisForm, primarily
* used by instruments. This is based on lorisform_parser.php
* used by instruments. This is based on ip_output_builder.php
*
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
*/
Expand Down
2 changes: 1 addition & 1 deletion php/libraries/NDB_BVL_Instrument.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ abstract class NDB_BVL_Instrument extends NDB_Page

/**
* True if the instrument page is being loaded by a script
* such as the lorisform_parser where all elements should be added to form,
* such as the ip_output_builder where all elements should be added to form,
* ignoring age-dependent or other conditional display logic in the form.
* To be called from within individual instrument forms.
*/
Expand Down
7 changes: 6 additions & 1 deletion php/libraries/NDB_BVL_Instrument_LINST.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ use \LORIS\Data\Types\DateType;
*/
class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
{
/**
* Line read size buffer.
*/
public const int LINE_BUFFER_SIZE = 131072;

public $InstrumentType = 'LINST';

public $LinstQuestions = [];
Expand Down Expand Up @@ -394,7 +399,7 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
];

// Buffer = 128KB
while (($line = fgets($fp, 131072)) !== false) {
while (($line = fgets($fp, self::LINE_BUFFER_SIZE)) !== false) {
$pieces = preg_split("/{@}/", $line);
$this->LinstLines[] = $pieces;

Expand Down
4 changes: 2 additions & 2 deletions tools/exporters/data_dictionary_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* Input:
* data_dictionary_builder.php takes as input the ip_output.txt file (generated
* by lorisform_parser.php) and inserts records for each field of each
* by tools/ip_output_builder.php) and inserts records for each field of each
* discovered NDB_BVL_Instrument. To be complete, this tool must be run on an
* ip_output.txt file that was constructed from all instruments.
*
Expand Down Expand Up @@ -116,7 +116,7 @@
break;
case "table":
$table = $bits[1];
//`testname` was only recently added to the lorisform parser, for
//`testname` was only recently added to the ip_output_builder, 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
Expand Down
8 changes: 7 additions & 1 deletion tools/generate_tables_sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/**
* The script generate_tables_sql.php takes the ip_output.txt file generated from
* lorisform_parser.php and outputs an sql build file for the table of each
* ip_output_builder.php and outputs an sql build file for the table of each
* instrument it finds in the ip_output.txt file. These sql files are output
* to the tables_sql/ subdirectory.
*
Expand Down Expand Up @@ -34,6 +34,12 @@
$tblCount = 0;
$parameterCount = 0;
foreach ($instruments as $instrument) {
// skip last line (empty instrument)
if (empty($instrument)) {
continue;
}

// parse instrument
$catId = "";
$output = "";
$items = explode("\n", trim($instrument));
Expand Down
16 changes: 14 additions & 2 deletions tools/generate_tables_sql_and_testNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/**
* The script generate_tables_sql_and_testNames.php takes
* the ip_output.txt file generated from lorisform_parser.php
* the ip_output.txt file generated from ip_output_builder.php
* and outputs an sql build file for the table of each instrument
* it finds in the ip_output.txt file.
* These sql files are output to the tables_sql/ subdirectory.
Expand All @@ -21,14 +21,23 @@

require_once __DIR__ . "/generic_includes.php";

$data = stream_get_contents(STDIN);
// read ip_output.txt
$fp = fopen(__DIR__ . "/ip_output.txt", "r");
$data = fread($fp, filesize(__DIR__ . "/ip_output.txt"));
fclose($fp);

$instruments = explode("{-@-}", trim($data));

$tblCount = 0;
$parameterCount = 0;
$pages = [];
foreach ($instruments as $instrument) {
// skip last line (empty instrument)
if (empty($instrument)) {
continue;
}

// parse instrument
$catId = "";
$output = "";
$items = explode("\n", trim($instrument));
Expand Down Expand Up @@ -71,6 +80,9 @@
continue 2;
break;

case "testname":
continue 2;

// generate specific column definitions for specific HTML elements
default:
if ($bits[1] == "") {
Expand Down
Loading
Loading