<?php

namespace app\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "{{%labresultmapping}}".
 *
 * @property integer $lab_result_mapng_id
 * @property string $lab_result_mapng_test
 * @property string $lab_result_mapng_result
 * @property string $status
 * @property integer $create_time
 * @property integer $create_user
 * @property integer $update_time
 * @property integer $update_user
 * @property integer $record_date
 */
class Labresultmapping extends \yii\db\ActiveRecord
{
	/**
	 * @inheritdoc
	 */
    public static function tableName()
	{
		return '{{%labresultmapping}}';
	}

	/**
	 * @inheritdoc
	 */
	public function behaviors()
	{
		return [
			[
				'class' => TimestampBehavior::className(),
				'createdAtAttribute' => 'create_time',
				'updatedAtAttribute' => 'update_time',
				'value' => date('U'),
			]
		];
	}

	/**
	 * @inheritdoc
	 */
	public function rules()
	{
		return [
			[['lab_result_mapng_test', 'lab_result_mapng_result'], 'required'],
			[['create_time', 'create_user', 'update_time', 'update_user', 'record_date'], 'integer'],
			[['lab_result_mapng_test', 'lab_result_mapng_result'], 'string', 'max' => 11],
			[['status'], 'string', 'max' => 1],
			[['lab_result_mapng_test', 'lab_result_mapng_result'], 'unique', 'targetAttribute' => ['lab_result_mapng_test', 'lab_result_mapng_result'], 'message' => 'The combination of Test Code and Lab Result has already been taken.'],
			[['record_date'], 'default', 'value' => strtotime(date('Y/m/d'))],
		];
	}

	/**
	 * @inheritdoc
	 */
	public function attributeLabels()
	{
		return [
			'lab_result_mapng_id' => Yii::t('app', 'Lab Result Mapng ID'),
			'lab_result_mapng_test' => Yii::t('app', 'Lab Test'),
			'lab_result_mapng_result' => Yii::t('app', 'Lab Result'),
			'status' => Yii::t('app', 'Status'),
			'create_time' => Yii::t('app', 'Create Time'),
			'create_user' => Yii::t('app', 'Create User'),
			'update_time' => Yii::t('app', 'Update Time'),
			'update_user' => Yii::t('app', 'Update User'),
			'record_date' => Yii::t('app', 'Record Date'),
		];
	}

    public function getTests()
    {
        $query = $this->hasOne(Labmaster::className(), ['lab_test_code' => 'lab_result_mapng_test']);
        return $query;
    }

    public function getTestName()
    {
    	$model = $this->tests;
        return $model ? $model->lab_test_name:'';
    }
}
