2024-12-25 03:04:59 +00:00
< ? php
namespace frontend\modules\surgical\models ;
use common\models\CaseSurgical ;
use yii\data\ActiveDataProvider ;
use yii\helpers\ArrayHelper ;
use yii\db\Expression ;
use Yii ;
class CaseSurgicalSearch extends CaseSurgical
{
public $patient_name ;
public $hospital ;
public $register_at ;
public $charge_user_id ;
public $cut_start ;
public $cut_end ;
public $send_at ;
public function rules ()
{
return ArrayHelper :: merge ( parent :: rules (), [
2025-03-22 10:12:00 +00:00
[[ 'patient_name' , 'hospital' , 'register_at' , 'cut_start' , 'cut_end' , 'status_id' , 'is_use_specimen' ], 'safe' ]
2024-12-25 03:04:59 +00:00
]);
}
public function attributeLabels ()
{
return [
'register_at' => 'วันที่ลงทะเบียน' ,
'hospital' => 'โรงพยาบาล' ,
'patient_name' => 'ชื่อ-นามสกุล' ,
];
}
public function search ( $params )
{
$query = CaseSurgical :: find () -> joinWith ([ 'hospital' ]);
/*
* -> alias ( 't' ) -> joinWith ([
'surgicalOperate AS so' ,
//'patient AS p',
'hospital as h'
]) -> orderBy ([ 'so.cut_start' => SORT_DESC ])
*/
$dataProvider = new ActiveDataProvider ([
'query' => $query ,
'sort' => [
'defaultOrder' => [
'register_at' => SORT_DESC ,
]
]
]);
//$dataProvider->sort->defaultOrder = ['id' => SORT_DESC];
$this -> load ( $params );
//$query->joinWith('patient.hospital as h', 'true', 'LEFT JOIN');
//$query->leftJoin("send_case as s", "s.id_case=so.id_case and s.send_role = 'surgical' ");
/**
* @ todo ต้องลงเริ่มตัดก่อนหรือเปล่า
*/
//$query->andFilterWhere(['is not', 'so.cut_start', new Expression('NULL')]);
$query //->andFilterWhere(['like', new Expression('(CAST(case_surgical.given_name as nvarchar) + \' \' + CAST(case_surgical.surname as nvarchar))'), $this->patient_name])
-> andFilterWhere ([ 'like' , new Expression ( 'CONCAT(case_surgical.given_name,case_surgical.surname)' ), $this -> patient_name ])
//->andFilterWhere(['like', new Expression('(CONCAT(case_surgical.given_name as nvarchar) , \' \' , CAST(case_surgical.surname as nvarchar))'), $this->patient_name]);
-> andFilterWhere ([ 'case_surgical.charge_user_id' => $this -> charge_user_id ])
-> andFilterWhere ([ 'like' , 'case_surgical.hospital_id' , $this -> hospital ])
-> andFilterWhere ([ 'like' , 'case_surgical.id_case' , $this -> id_case ])
-> andFilterWhere ([ 'like' , 'case_surgical.age' , $this -> age ])
-> andFilterWhere ([ 'status_id' => $this -> status_id ])
2025-03-22 10:12:00 +00:00
-> andFilterWhere ([ 'is_use_specimen' => $this -> is_use_specimen ])
2024-12-25 03:04:59 +00:00
-> andFilterWhere ([ '=' , new Expression ( 'CAST(register_at AS date)' ), Yii :: $app -> pathology -> searchDate ( $this -> register_at )])
-> andFilterWhere ([ '=' , new Expression ( 'CAST(report_at AS date)' ), Yii :: $app -> pathology -> searchDate ( $this -> report_at )])
-> andFilterWhere ([ 'like' , 'so.cut_start' , Yii :: $app -> pathology -> searchDate ( $this -> cut_start )])
-> andFilterWhere ([ 'like' , 'so.cut_end' , Yii :: $app -> pathology -> searchDate ( $this -> cut_end )]);
return $dataProvider ;
}
2025-03-22 10:12:00 +00:00
}