<?php

namespace app\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use app\base\Converter;

/**
 * This is the model class for table "cms_baseline_qualityoflife".
 *
 * The followings are the available columns in table 'cms_baseline_qualityoflife':
 * @property integer $quality_of_life_id
 * @property string $quality_of_life_survey
 * @property string $quality_of_life_part_id
 * @property integer $quality_of_life_q1
 * @property integer $quality_of_life_q2
 * @property integer $quality_of_life_q3
 * @property integer $quality_of_life_q4
 * @property integer $quality_of_life_q5
 * @property integer $quality_of_life_q6
 * @property string $status
 * @property integer $create_time
 * @property integer $create_user
 * @property integer $update_time
 * @property integer $update_user
 */
 
class Qualityoflife extends \yii\db\ActiveRecord
{
	public $yes_no_limit = [0 => "No", 1 => "Yes, limits a little", 2 => "Yes, limits a lot", 998 => "Refused"];
	public $yes_none_limit = [0 => "None", 1 => "Yes, limited a little", 2 => "Yes, limited a lot", 998 => "Refused"];
    Public $visit;
	
	/**
	 * @inheritdoc
	 */
    public static function tableName()
	{
		return '{{%baseline_qualityoflife}}';
	}

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

	/**
	 * @inheritdoc
	 */
	public function rules()
	{
		return [
			[['quality_of_life_survey','quality_of_life_loc', 'quality_of_life_part_id', 'quality_of_life_q1', 'quality_of_life_q2', 'quality_of_life_q3', 'quality_of_life_q4', 'quality_of_life_q5','quality_of_life_q6','visit_code'], 'required', 'message' => 'Cannot be blank.'],
			[['quality_of_life_q6', 'create_time', 'create_user', 'update_time', 'update_user'], 'integer', 'message' => 'Must be an integer'],		
			[['quality_of_life_q6'], 'string', 'max' => 3],
			[['quality_of_life_q6'], 'number','min'=>0,'tooSmall'=>'Negative value not allowed','max'=>100,'tooBig'=>'Maximum value is {max}', 'when' => function ($model) {
				return $model->quality_of_life_q6 != '998';
			}, 'whenClient' => "function (attribute, value) {
				return $('#qualityoflife-quality_of_life_q6').val() != '998';
			}"],	
			[['visit_code'], 'integer', 'message' => 'Must be an integer'],
			[['status'], 'string', 'max' => 1],
			[['record_date'], 'default', 'value' => strtotime(date('Y/m/d'))],
			
				];
	}

	
	/**
	 * @inheritdoc
	 */
	public function attributeLabels()
	{
		return [
			'quality_of_life_id' => Yii::t('app', 'Qualityoflife ID'),
			'quality_of_life_survey' => Yii::t('app', 'Survey'),
			'quality_of_life_loc' => Yii::t('app', 'Location'),
			'quality_of_life_part_id' => Yii::t('app', 'ICC Client ID'),
			
'visit_code' => Yii::t('app', 'Visit'),
			'quality_of_life_q1' => Yii::t('app', '1. Does your health now limit you in walking more than 50-100 meters?'),
			'quality_of_life_q2' => Yii::t('app', '2. Does your health now limit you in bathing or dressing yourself?'),
			'quality_of_life_q3' => Yii::t('app', '3. Does your health now limit you in work or other regular activities?'),
			'quality_of_life_q4' => Yii::t('app', '4. How much are you limited in your daily activities by pain or discomfort?'),
			'quality_of_life_q5' => Yii::t('app', '5. How much are you limited in your daily activities by anxiety or depression?'),
			'quality_of_life_q6' => Yii::t('app', '6. We would like you to indicate on this scale how good or bad your own health is today, in your opinion. Please do this by indicating which point on the scale indicates how good or bad your health state is today.'),
			
			'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'),
		];
	}
public function getVisits($id)
	{
		$Gmodel = \app\models\Visitmaster::find()->where(['NOT', ['visit_interval' => null]])->andWhere(["status" => 1])->andWhere(["visit_code" => $id])->one();
		if($Gmodel !== null) {			
				return $Gmodel->visit_name;
		} else
			return "-";
	}	
	
}