Skip to content

Commit

Permalink
[Battery] Potential improvement for battery assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
ridz1208 committed Dec 22, 2020
1 parent 9562e53 commit dee413d
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions php/libraries/NDB_BVL_Battery.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,6 @@ class NDB_BVL_Battery
);
}

// assert that the current battery is empty
if (count($currentTests) > 0) {
throw new Exception(
"Battery is not empty - will not clobber an existing battery."
);
}

// determine the list of instruments to register
$neededTests = $this->lookupBattery(
$this->age,
Expand All @@ -152,13 +145,32 @@ class NDB_BVL_Battery
$firstVisit
);

// assert that the current battery is empty
if (count($currentTests) > 0) {
$neededTests = $this->getBatteryDifference($neededTests);
}

// loop over the list of instruments
foreach ($neededTests AS $testName) {
// add the instrument
$this->addInstrument($testName);
} // end looping over the list of instruments
} // end createBattery()

/**
* Computes the difference between the existing battery and the
* theoretical battery and returns only the missing tests as an array
*
* @param array $currentBattery
* @param array $lookupBattery
*
* @return array
*/
function getBatteryDifference(array $currentBattery=[], array $lookupBattery=[]) : array
{
return array_unique(array_diff($lookupBattery, $currentBattery));
}

/**
* Adds the specified instrument to the current battery, so long
* as it is not already there (singleton model)
Expand Down

0 comments on commit dee413d

Please sign in to comment.