Skip to content

Commit

Permalink
Fix order of operations + Revert change to NDB_BVL_Instrument_LINST
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffersoncasimir committed Feb 3, 2025
1 parent 6ae6550 commit c7767cb
Show file tree
Hide file tree
Showing 4 changed files with 17,498 additions and 24 deletions.
47 changes: 26 additions & 21 deletions php/libraries/InstrumentDataParser.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ class InstrumentDataParser extends CSVParser

/**
* Get the session ID from PSCID and Visit_label
* TODO: Timepoint/getTimepointFormPSCIDandVisitLabel(,)
*
* @param string $pscID candidate PSCID
* @param string $visitLabel session Visit_label
Expand Down Expand Up @@ -301,21 +300,7 @@ class InstrumentDataParser extends CSVParser
try {
foreach ($instrumentData as $data) {
try {
$battery = new \NDB_BVL_Battery();
$battery->selectBattery(
new \SessionID(strval($data['SessionID']))
);
$commentID = $battery->addInstrument(
$loris,
$this->instrumentName
);

$instrument = \NDB_BVL_Instrument::factory(
$loris,
$this->instrumentName,
$commentID
);

// Prepare row data
$rowData = array_reduce(
$instrumentHeaders,
function ($columns, $columnName) use ($data) {
Expand All @@ -328,24 +313,44 @@ class InstrumentDataParser extends CSVParser
[]
);

$instrument->form->getGroupValues(
array_keys($rowData),
$out
// Create generic instrument
$instrument = \NDB_BVL_Instrument::factory(
$loris,
$this->instrumentName,
''
);

// Change below is expected state for validation
// Populate instrument with data
// Change below is expected to allow population
$_FILES = [];
$_REQUEST = $rowData;
$_POST = $rowData;

$instrument->form->getGroupValues(
array_keys($rowData),
$out
);

// Generate CommentID for instrument
$battery = new \NDB_BVL_Battery();
$battery->selectBattery(
new \SessionID(strval($data['SessionID']))
);
$commentID = $battery->addInstrument(
$loris,
$this->instrumentName
);
$instrument->commentID = $commentID;

// Validate and save
$success = $instrument->save();

if (!$success) {
throw new RuntimeException(
"This row failed data validation."
);
} else {
// Link file entry to DataID
// Success - Link file entry to DataID
$query = "SELECT DataID
FROM flag
WHERE CommentID = :commentID";
Expand Down
5 changes: 2 additions & 3 deletions php/libraries/NDB_BVL_Instrument_LINST.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
//If this is an OR rule using two different controllers
//explode it at the pipe.
//ex: q_1{@}=={@}yes|q_2{@}=={@}yes
if (str_contains($rule, "|")
&& stristr(substr($rule, strpos($rule, "|")), "{@}")
) {
$s_r = strpos($rule, "|");
if ($s_r !== false && stristr(substr($rule, $s_r), "{@}")) {
$rules_array = explode("|", $rule);
} else {
//Otherwise its a regular rule. ex: q_1{@}=={@}yes
Expand Down
Loading

0 comments on commit c7767cb

Please sign in to comment.