<?php

namespace app\models;

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

/**
 * This is the model class for table "cms_baseline_preartbeliefs".
 *
 * The followings are the available columns in table 'cms_baseline_preartbeliefs':
 * @property integer $health_seeking_id
 * @property string $health_seeking_survey
 * @property string $health_seeking_part_id
 * @property integer $health_seeking_q1
 * @property integer $health_seeking_q2
 * @property integer $health_seeking_q3
 * @property integer $health_seeking_q4
 * @property integer $health_seeking_q5
 * @property integer $health_seeking_q6
 * @property integer $health_seeking_q7
 * @property integer $health_seeking_q8
 * @property string $status
 * @property integer $create_time
 * @property integer $create_user
 * @property integer $update_time
 * @property integer $update_user
 */
 
class Healthseeking extends \yii\db\ActiveRecord
{
	public $agree = [5 => "Strongly Agree", 4 => "Agree", 3 => "Uncertain", 2 => "Disagree", 1 => "Strongly Disagree"];
	public $gender = [1 => "Male", 2 => "Female", 3 => "Hijra/Transgender"];
	public $marstatus = [1 => 'Never Married', 2 => 'Currently Married', 3 => 'Widowed', 4 => 'Divorced', 5 => 'Separated'];
	Public $sexori = [1 => 'Straight (heterosexual)', 2 => 'Kothi', 3 => 'Panthi', 4 => 'DD', 5 => 'Gay', 6 => 'Bisexual', 7 => 'Hijra', 8 => 'MSM', 9 => 'Lesbian', 996 => 'Other'];	
	public $group = ["IDU" => "IDU", "MSM" => "MSM"];
	//Public $age;
	/**
	 * @inheritdoc
	 */
    public static function tableName()
	{
		return '{{%healthseeking}}';
	}

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

	/**
	 * @inheritdoc
	 */
	public function rules()
	{
		return [
			[['health_seeking_survey','health_seeking_loc', 'health_seeking_part_id','health_seeking_gender', 'health_seeking_sexual_orientation', 'health_seeking_marital_status', 'health_seeking_age','health_seeking_group', 'health_seeking_q1', 'health_seeking_q2', 'health_seeking_q3', 'health_seeking_q4', 'health_seeking_q5','health_seeking_q6','health_seeking_q7','health_seeking_q8','health_seeking_q9','health_seeking_q10','health_seeking_q11','health_seeking_q12','health_seeking_q13','health_seeking_q14','health_seeking_q15','health_seeking_q16','health_seeking_q17','health_seeking_q18','health_seeking_q19', 'health_seeking_q20', 'health_seeking_q21','health_seeking_q22','health_seeking_q23','health_seeking_q24'], 'required', 'message' => 'Cannot be blank.'],		
		           
            [['health_seeking_starttime','health_seeking_endtime','create_time', 'create_user', 'update_time', 'update_user'], 'safe'],	
            
            [['health_seeking_age'], 'ageValidate'],			
			[['status'], 'string', 'max' => 1],
			[['record_date'], 'default', 'value' => strtotime(date('Y/m/d'))],
			[['health_seeking_date'], 'default', 'value' => strtotime(date('Y/m/d'))],
			[['health_seeking_endtime'], 'default', 'value' => strtotime(date('Y/m/d H:i:s'))],
			
		];
	}
  
  public function ageValidate($attribute, $params) {
        if($this->health_seeking_part_id != "") :
			$Regmodel = Registration::find()->where(["corfrm_pid" => $this->health_seeking_part_id])->one();
	        if($Regmodel !== null)		
                $Age =	($Regmodel->corfrm_q4)+3;			
				if ($this->health_seeking_age < $Regmodel->corfrm_q4)
	        	$this->addError($attribute, 'Age can not be less than the Client age ' .$Regmodel->corfrm_q4. ' mentioned in Registration form. Please double check your answer.');
			    elseif ($this->health_seeking_age > ($Regmodel->corfrm_q4)+3)
				$this->addError($attribute, 'Age can not be greater than ' .$Age.'.The client age mentioned in Registration form is ' .$Regmodel->corfrm_q4. '. Please double check your answer.');
        endif;
	}
	
	/**
	 * @inheritdoc
	 */
	public function attributeLabels()
	{
		return [
'health_seeking_id' => Yii::t('app', 'Healthseeking ID'),
'health_seeking_survey' => Yii::t('app', 'Survey'),
'health_seeking_loc' => Yii::t('app', 'Location'),
'health_seeking_part_id' => Yii::t('app', 'ICC Client ID'),
			
'health_seeking_starttime' => Yii::t('app', 'Start time'),
'health_seeking_endtime' => Yii::t('app', 'End time'),

'health_seeking_group' => Yii::t('app', 'Group'),
'health_seeking_age' => Yii::t('app', 'Age'),
'health_seeking_gender' => Yii::t('app', 'Gender'),
'health_seeking_sexual_orientation' => Yii::t('app', 'Sexual Orientation'),
'health_seeking_marital_status' => Yii::t('app', 'Marital Status'),						

'health_seeking_q1' => Yii::t('app', '1. I like to come to this clinic'),
'health_seeking_q2' => Yii::t('app', '2. The clinic is open during convenient times for me'),
'health_seeking_q3' => Yii::t('app', '3. I feel safe with the staff and counselor at the clinic'),
'health_seeking_q4' => Yii::t('app', '4. The counselor has a positive attitude towards me'),
'health_seeking_q5' => Yii::t('app', '5. The counselor is supportive and understanding of my problems'),
'health_seeking_q6' => Yii::t('app', '6. I feel fully informed about HIV/AIDS after the counseling session'),
'health_seeking_q7' => Yii::t('app', '7. The counselor does not allow me to take independent decisions'),
'health_seeking_q8' => Yii::t('app', '8. The counselor helped me create a personalized dietary and medication plan'),
'health_seeking_q9' => Yii::t('app', '9. The counselor motivates me to improve my drug adherence'),
'health_seeking_q10' => Yii::t('app', '10. The counselor encourages me to disclose my HIV status to my partner/ spouse'),
'health_seeking_q11' => Yii::t('app', '11. The counselor motivates me to reduce risky sexual behaviour'),
'health_seeking_q12' => Yii::t('app', '12. I want to achieve 100% drug adherence'),
'health_seeking_q13' => Yii::t('app', '13. I do not eat my medicines on time every day'),
'health_seeking_q14' => Yii::t('app', '14. I want to stop/ reduce my consumption of illicit drugs/ alcohol'),
'health_seeking_q15' => Yii::t('app', '15. I want to reduce the number of sexual partners I engage with'),
'health_seeking_q16' => Yii::t('app', '16. I would use condoms every time I engage in sexual activity'),
'health_seeking_q17' => Yii::t('app', '17. I would use condoms to protect my spouse/ partner from HIV'),
'health_seeking_q18' => Yii::t('app', '18. I would disclose my HIV status to my spouse/ partner'),
'health_seeking_q19' => Yii::t('app', '19. I am motivated to change my behaviour to improve my health condition'),
'health_seeking_q20' => Yii::t('app', '20. I am able to make good health related decisions independently'),
'health_seeking_q21' => Yii::t('app', '21. I have not seen positive changes in my health behaviour after my counseling sessions'),
'health_seeking_q22' => Yii::t('app', '22. I would recommend my counselor to family/ friends/ colleagues who have HIV'),
'health_seeking_q23' => Yii::t('app', '23. I would bring along ‘at risk’ family members /members of my community for counseling and testing to this clinic'),
'health_seeking_q24' => Yii::t('app', '24. I will continue visiting this site counselor'),			
			
'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'),
			
		];
	}
	
}