public function dataSet()
{
$data = $this->queryData($this->surgeon, $this->from, $this->to, $this->months, $this->procedures);
$count = array();
$this->padCategories();
// fill up the array with 0, have to send 0 to highcharts if there is no data
foreach ($this->graphConfig['xAxis']['categories'] as $xCat) {
$count[] = 0;
}
$bestvalues = array();
foreach ($data as $row) {
$side = 'right';
if ($row['eye_id'] === '1') {
$side = 'left';
}
$diff = (double) $row['predicted_refraction'] - ((double) $row[$side . '_sphere'] - (double) $row[$side . '_cylinder'] / 2);
$diff = round($diff * 2) / 2;
$diff = array_search($diff, $this->graphConfig['xAxis']['categories']);
if ($diff >= 0 && $diff <= count($this->graphConfig['xAxis']['categories']) - 1) {
if (!array_key_exists($row['patient_id'], $bestvalues)) {
$bestvalues[$row['patient_id']] = $diff;
} elseif ($diff < $bestvalues[$row['patient_id']]) {
$bestvalues[$row['patient_id']] = $diff;
}
}
}
foreach ($bestvalues as $key => $diff) {
if (!array_key_exists("{$diff}", $count)) {
$count["{$diff}"] = 0;
}
++$count["{$diff}"];
}
ksort($count, SORT_NUMERIC);
$dataSet = array();
foreach ($count as $category => $total) {
$rowTotal = array((double) $category, $total);
$dataSet[] = $rowTotal;
}
return $dataSet;
}