<?php

namespace app\models;

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

/**
 * This is the model class for table "cms_baseline_depression".
 *
 * The followings are the available columns in table 'cms_baseline_depression':
 * @property integer $depression_id
 * @property string $depression_survey
 * @property string $depression_part_id
 * @property integer $depression_q1
 * @property integer $depression_q2
 * @property integer $depression_q3
 * @property integer $depression_q4
 * @property integer $depression_q5
 * @property integer $depression_q6
 * @property integer $depression_q7
 * @property integer $depression_q8
 * @property string $status
 * @property integer $create_time
 * @property integer $create_user
 * @property integer $update_time
 * @property integer $update_user
 */
 
class Depression extends \yii\db\ActiveRecord
{
	public $often = [0 => "Not at all", 1 => "Several days", 2 => "More than half the days", 3 => "Nearly every day"];
	public $q10= [0 => "Not difficult at all", 1 => "Somewhat difficult", 2 => "Very difficult", 3 => "Extremely difficult"];
	Public $visit;
	
	/**
	 * @inheritdoc
	 */
    public static function tableName()
	{
		return '{{%baseline_depression}}';
	}

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

	/**
	 * @inheritdoc
	 */
	public function rules()
	{
		return [
			[['depression_survey','depression_loc', 'depression_part_id', 'depression_q1', 'depression_q2', 'depression_q3', 'depression_q4', 'depression_q5','depression_q6','depression_q7','depression_q8','depression_q9','visit_code'], 'required', 'message' => 'Cannot be blank.'],
			[['create_time', 'create_user', 'update_time', 'update_user'], 'integer', 'message' => 'Must be an integer'],
          
	
           [['depression_q10'], 'required', 'message' => 'Cannot be blank.', 'when' => function ($model) {
				return ($model->depression_q1 != 0 || $model->depression_q2 != 0 || $model->depression_q3 != 0 || $model->depression_q4 != 0 || $model->depression_q5 != 0 || $model->depression_q6 != 0 || $model->depression_q7 != 0 || $model->depression_q8 != 0 || $model->depression_q9 != 0);
			}, 'whenClient' => "function (attribute, value) {
				return ($('#depression-depression_q1').val() != 0 || $('#depression-depression_q2').val() != 0 || $('#depression-depression_q3').val() != 0 || $('#depression-depression_q4').val() != 0 || $('#depression-depression_q5').val() != 0 || $('#depression-depression_q6').val() != 0 || $('#depression-depression_q7').val() != 0 || $('#depression-depression_q8').val() != 0 || $('#depression-depression_q9').val() != 0) ;
			}"],
			[['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 [
			'depression_id' => Yii::t('app', 'Depression ID'),
			'depression_survey' => Yii::t('app', 'Survey'),
			'depression_loc' => Yii::t('app', 'Location'),
			'depression_part_id' => Yii::t('app', 'ICC Client ID'),
			
'visit_code' => Yii::t('app', 'Visit'),
			'depression_q1' => Yii::t('app', '1. Little interest or pleasure in doing things'),
			'depression_q2' => Yii::t('app', '2. Feeling down, depressed, or hopeless'),
			'depression_q3' => Yii::t('app', '3. Trouble falling or staying asleep, or sleeping too much'),
			'depression_q4' => Yii::t('app', '4. Feeling tired or having little energy'),
			'depression_q5' => Yii::t('app', '5. Poor appetite or overeating'),
			'depression_q6' => Yii::t('app', '6. Feeling bad about yourself - or that you are a failure or have let yourself or your family down'),
			'depression_q7' => Yii::t('app', '7. Trouble concentrating on things, such as reading the newspaper or watching television'),
			'depression_q8' => Yii::t('app', '8. Moving or speaking so slowly that other people could have noticed? Or the opposite – being so fidgety or restless that you have been moving around a lot more than usual'),
			'depression_q9' => Yii::t('app', '9. Thoughts that you would be better off dead or of hurting yourself in some way'),
			'depression_q10' => Yii::t('app', '10. Thinking about the problems you reported as bothersome in the questions I just asked, how difficult have these problems made it for you to do your work, take care of things at home, or get along with other people?'),
			
			'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 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 "-";
	}	
	
}