private function updateMeasurementReference($measurement_id, $eye_id)
 {
     $existing = $this->dbConnection->createCommand()->select(array('fm.id fm_id', 'mr.id mr_id'))->from('ophinvisualfields_field_measurement fm')->join('patient_measurement pm', 'pm.id = fm.patient_measurement_id')->join('measurement_reference mr', 'mr.patient_measurement_id = pm.id and mr.event_id = :event_id')->join('event ev', 'ev.id = mr.event_id')->where('fm.eye_id = :eye_id and mr.event_id = :event_id', array(':eye_id' => $eye_id, ':event_id' => $this->event_id))->queryRow();
     if ($existing) {
         if ($existing['fm_id'] != $measurement_id) {
             MeasurementReference::model()->deleteByPk($existing['mr_id']);
         } else {
             // Nothing to do
             return;
         }
     }
     if ($measurement_id) {
         OphInVisualfields_Field_Measurement::model()->findByPk($measurement_id)->attach($this->event);
     }
 }
예제 #2
0
 public function run($args)
 {
     $event_type_id = EventType::model()->find('class_name = :classname', array(':classname' => 'OphInVisualfields'))->id;
     $patient_ids = Yii::app()->db->createCommand()->selectDistinct('patient_id')->from('measurement_reference mr')->join('patient_measurement pm', 'pm.id = mr.patient_measurement_id')->queryColumn();
     foreach ($patient_ids as $patient_id) {
         $criteria = new CDbCriteria();
         $criteria->condition = 'event_type_id = :event_type_id AND patient_id = :patient_id';
         $criteria->join = 'join episode ep on ep.id = t.episode_id';
         $criteria->order = 'event_date desc';
         $criteria->limit = '3';
         $criteria->params = array(':patient_id' => $patient_id, ':event_type_id' => $event_type_id);
         $events = Event::model()->findAll($criteria);
         foreach ($events as $event) {
             echo ' - ' . $event->id . "\n";
             MeasurementReference::model()->deleteAll('event_id = ?', array($event->id));
             $event->deleted = 1;
             $event->save();
         }
         echo "{$patient_id}\n";
     }
 }