/**
  * @return mixed|string
  */
 public function renderSearch()
 {
     $visualAcuityMethods = OphCiExamination_VisualAcuity_Method::model()->findAll();
     return $this->app->controller->renderPartial($this->searchTemplate, array('report' => $this, 'methods' => $visualAcuityMethods));
 }
 /**
  * @param $userId
  * @param $visualAcuity
  * @param $unit
  * @param $vaData
  * @param $eyeLabel
  * @param $near
  *
  * @throws \CDbException
  * @throws \Exception
  */
 protected function addVisualAcuityReading($userId, $visualAcuity, $unit, $vaData, $eyeLabel, $near = false)
 {
     $vaReading = new \OEModule\OphCiExamination\models\OphCiExamination_VisualAcuity_Reading();
     if ($near) {
         $vaReading = new \OEModule\OphCiExamination\models\OphCiExamination_NearVisualAcuity_Reading();
     }
     $vaReading->element_id = $visualAcuity->id;
     $baseValue = \OEModule\OphCiExamination\models\OphCiExamination_VisualAcuityUnitValue::model()->getBaseValue($unit->id, $vaData['reading']);
     $vaReading->value = $baseValue;
     $vaReading->method_id = \OEModule\OphCiExamination\models\OphCiExamination_VisualAcuity_Method::model()->find('name = :name', array('name' => $vaData['method']))->id;
     if ($eyeLabel === 'left') {
         $vaReading->side = \OEModule\OphCiExamination\models\OphCiExamination_VisualAcuity_Reading::LEFT;
     } else {
         $vaReading->side = \OEModule\OphCiExamination\models\OphCiExamination_VisualAcuity_Reading::RIGHT;
     }
     $vaReading->created_user_id = $vaReading->last_modified_user_id = $userId;
     if (!$vaReading->save(true, null, true)) {
         throw new \CDbException('Visual Acuity Reading failed: ' . print_r($vaReading->getErrors(), true));
     }
 }
 /**
  * To get the visual acuity from the element based on the all episodes for the patient
  * @param \Patient $patient
  * @param $side
  * @param $type
  * @param $element
  * @return null
  * @throws \Exception
  */
 public function getMostRecentVAForPatient(\Patient $patient, $side, $type, $element)
 {
     if (!in_array($type, array(static::$AIDED_VA_TYPE, static::$UNAIDED_VA_TYPE))) {
         throw new \Exception("Invalid type for VA {$type}");
     }
     $checkFunc = 'has' . ucfirst($side);
     if (!$element->{$checkFunc}()) {
         return null;
     }
     $method_type = $type == static::$AIDED_VA_TYPE ? models\OphCiExamination_VisualAcuity_Method::$AIDED_FLAG_TYPE : models\OphCiExamination_VisualAcuity_Method::$UNAIDED_FLAG_TYPE;
     $methods = models\OphCiExamination_VisualAcuity_Method::model()->findAll('type=?', array($method_type));
     $best_reading = $element->getBestReadingByMethods($side, $methods);
     return $best_reading;
 }