OEModule\OphCiExamination\components\VisualOutcomeReport::dataSet PHP Method

dataSet() public method

public dataSet ( ) : array
return array
    public function dataSet()
    {
        $data = $this->queryData($this->surgeon, $this->from, $this->to, $this->months, $this->method, $this->type);
        $dataCheck = array();
        $dataSet = array();
        $eyeDiffs = array();
        $bestValues = array();
        foreach ($data as $row) {
            if (!isset($dataCheck[$row['id']])) {
                //Do we have data for this operation?
                $dataCheck[$row['id']] = array();
            }
            if (!isset($dataCheck[$row['id']][$row['eye_id']])) {
                //and specifically for this eye in the op
                $dataCheck[$row['id']][$row['eye_id']] = array();
            }
            if (!isset($dataCheck[$row['id']][$row['eye_id']][$row['method_id']]) || $this->method === 'best') {
                //and then for this method
                $dataCheck[$row['id']][$row['eye_id']][$row['method_id']] = true;
                if ($this->method === 'best') {
                    $diffForEye = $row['pre_value'] - $row['post_value'];
                    if (!isset($eyeDiffs[$row['id'] . '_' . $row['eye_id']])) {
                        $eyeDiffs[$row['id'] . '_' . $row['eye_id']] = $diffForEye;
                        $bestValues[$row['id'] . '_' . $row['eye_id']] = array($this->convertVisualAcuity($row['pre_value']), $this->convertVisualAcuity($row['post_value']));
                    } elseif ($diffForEye > $eyeDiffs[$row['id'] . '_' . $row['eye_id']]) {
                        $eyeDiffs[$row['id'] . '_' . $row['eye_id']] = $diffForEye;
                        $bestValues[$row['id'] . '_' . $row['eye_id']] = array($this->convertVisualAcuity($row['pre_value']), $this->convertVisualAcuity($row['post_value']));
                    }
                } else {
                    //get the pre/post values now. Only the first time, order in SQL query means the first one we come
                    //across is the one closest to the op pre and post.
                    $dataSet[] = array($this->convertVisualAcuity($row['pre_value']), $this->convertVisualAcuity($row['post_value']));
                }
            }
        }
        $counts = array();
        $dataSet = array_merge($dataSet, array_values($bestValues));
        foreach ($dataSet as $data) {
            if (!array_key_exists($data[0] . '_' . $data[1], $counts)) {
                $counts[$data[0] . '_' . $data[1]] = 0;
            }
            ++$counts[$data[0] . '_' . $data[1]];
        }
        $matrix = array();
        foreach ($counts as $key => $count) {
            $xAxsis = null;
            $yAxsis = null;
            $points = explode('_', $key);
            $xPoint = (double) $points[0];
            $yPoint = (double) $points[1];
            if ($xPoint <= 0) {
                $xAxsis = 5;
            }
            if ($xPoint >= 0 && $xPoint <= 0.3) {
                $xAxsis = 4;
            }
            if ($xPoint > 0.3 && $xPoint <= 0.6) {
                $xAxsis = 3;
            }
            if ($xPoint > 0.6 && $xPoint <= 0.9) {
                $xAxsis = 2;
            }
            if ($xPoint > 0.9 && $xPoint <= 1.2) {
                $xAxsis = 1;
            }
            if ($xPoint > 1.2) {
                $xAxsis = 0;
            }
            // yAxsis
            if ($yPoint <= 0) {
                $yAxsis = 5;
            }
            if ($yPoint >= 0 && $yPoint <= 0.3) {
                $yAxsis = 4;
            }
            if ($yPoint > 0.3 && $yPoint <= 0.6) {
                $yAxsis = 3;
            }
            if ($yPoint > 0.6 && $yPoint <= 0.9) {
                $yAxsis = 2;
            }
            if ($yPoint > 0.9 && $yPoint <= 1.2) {
                $yAxsis = 1;
            }
            if ($yPoint > 1.2) {
                $yAxsis = 0;
            }
            if (isset($matrix[$xAxsis][$yAxsis])) {
                $matrix[$xAxsis][$yAxsis] += $count;
            } else {
                $matrix[$xAxsis][$yAxsis] = $count;
            }
        }
        $returnData = array();
        foreach ($matrix as $xCoord => $bubbleX) {
            foreach ($bubbleX as $yCoord => $value) {
                $returnData[] = array($xCoord, $yCoord, $value);
                $this->totalEyes += $value;
            }
        }
        return $returnData;
    }