The followings are the available columns in table 'unique_codes':
Inheritance: extends BaseActiveRecord
Example #1
0
 protected function getUniqueCode()
 {
     $userUniqueCode = UniqueCodeMapping::model()->findByAttributes(array('user_id' => $this->id));
     return $userUniqueCode->unique_code_id;
 }
Example #2
0
 /**
  * @param $event
  */
 public function getUniqueCodeForCviEvent($event)
 {
     $eventUniqueCodeId = \UniqueCodeMapping::model()->findAllByAttributes(array('event_id' => $event->id));
     $eventUniqueCode = \UniqueCodes::model()->findByPk($eventUniqueCodeId[0]->unique_code_id);
     $salt = isset(\Yii::app()->params['portal']['credentials']['client_id']) ? \Yii::app()->params['portal']['credentials']['client_id'] : '';
     $check_digit1 = new \CheckDigitGenerator(\Yii::app()->params['institution_code'] . $eventUniqueCode->code, $salt);
     $check_digit2 = new \CheckDigitGenerator($eventUniqueCode->code . $event->episode->patient->dob, $salt);
     $finalEventUniqueCode = \Yii::app()->params['institution_code'] . $check_digit1->generateCheckDigit() . '-' . $eventUniqueCode->code . '-' . $check_digit2->generateCheckDigit();
     return $finalEventUniqueCode;
 }
 /**
  * Update Unique code for the event associated the specific procedures.
  */
 private function updateUniqueCode($event)
 {
     foreach ($this->unique_code_elements as $unique) {
         if ($event->eventType->class_name === $unique['event']) {
             foreach ($event->getElements() as $element) {
                 if (in_array(Helper::getNSShortname($element), $unique['element'])) {
                     $event_unique_code = UniqueCodeMapping::model()->findAllByAttributes(array('event_id' => $event->id));
                     if (!$event_unique_code) {
                         $this->createNewUniqueCodeMapping($event->id, null);
                     }
                 }
             }
         }
     }
 }
Example #4
0
 /**
  * Getting the unused active unique codes.
  *
  * @return type
  */
 private function getActiveUnusedUniqueCode()
 {
     UniqueCodeMapping::model()->lock();
     //Yii::app()->db->createCommand("LOCK TABLES unique_codes READ, unique_codes_mapping WRITE")->execute();
     $record = Yii::app()->db->createCommand()->select('unique_codes.id as id')->from('unique_codes')->leftJoin('unique_codes_mapping', 'unique_code_id=unique_codes.id')->where('unique_codes_mapping.id is null')->andWhere('active = 1')->limit(1)->queryRow();
     UniqueCodeMapping::model()->unlock();
     //Yii::app()->db->createCommand("UNLOCK TABLES")->execute();
     if ($record) {
         return $record["id"];
     }
 }