<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Healthcareutilization;
use app\base\Converter;

/**
 * HealthcareutilizationSearch represents the model behind the search form about `app\models\Healthcareutilization`.
 */
class HealthcareutilizationSearch extends Healthcareutilization
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['health_care_utilization_id', 'health_care_utilization_q1a', 'health_care_utilization_q2a', 'health_care_utilization_q3a', 'health_care_utilization_q4a', 'health_care_utilization_q5a', 'health_care_utilization_q6a', 'create_time', 'create_user', 'update_time', 'update_user'], 'integer'],
            [['health_care_utilization_survey', 'health_care_utilization_part_id', 'status','record_date','visit_code'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Healthcareutilization::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);
        if(empty($params))
            $params = Yii::$app->request->post();
        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'health_care_utilization_id' => $this->health_care_utilization_id,
            'health_care_utilization_q1a' => $this->health_care_utilization_q1a,
			'health_care_utilization_q2a' => $this->health_care_utilization_q2a,
			'health_care_utilization_q3a' => $this->health_care_utilization_q3a,
            'health_care_utilization_q4a' => $this->health_care_utilization_q4a,
            'health_care_utilization_q5a' => $this->health_care_utilization_q5a,
            'health_care_utilization_q6a' => $this->health_care_utilization_q6a,
			'health_care_utilization_q7' => $this->health_care_utilization_q7,
            'health_care_utilization_q8a' => $this->health_care_utilization_q8a,
			'visit_code' => $this->visit_code,
            'create_time' => $this->create_time,
            'create_user' => $this->create_user,
            'update_time' => $this->update_time,
            'update_user' => $this->update_user,
			'record_date' => Converter::toUnixTimeformat($this->record_date),
        ]);

        $query->andFilterWhere(['like', 'health_care_utilization_survey', $this->health_care_utilization_survey])
            ->andFilterWhere(['like', 'health_care_utilization_part_id', $this->health_care_utilization_part_id])
            ->andFilterWhere(['like', 'health_care_utilization_q1a', $this->health_care_utilization_q1a])
            ->andFilterWhere(['like', 'health_care_utilization_q2a', $this->health_care_utilization_q2a])            
            ->andFilterWhere(['like', 'status', $this->status]);

        return $dataProvider;
    }
}
