149 lines
4.9 KiB
PHP
149 lines
4.9 KiB
PHP
<?php
|
|
|
|
namespace common\models\oldDb;
|
|
|
|
use yii\behaviors\TimestampBehavior;
|
|
use yii\db\ActiveRecord;
|
|
|
|
class Prescription extends \common\modelsgii\oldDb\Prescription
|
|
{
|
|
const RECIPE_SYNC = 'PrescriptionSync';//处方同步医网信
|
|
const AUTO_EXPIRE = 'PrescriptionAutoExpire'; //处方自动失效
|
|
|
|
public function behaviors()
|
|
{
|
|
return [
|
|
[
|
|
'class' => TimestampBehavior::class,
|
|
'attributes' => [
|
|
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at','updated_at'],
|
|
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
|
|
],
|
|
],
|
|
];
|
|
}
|
|
|
|
//关联用户
|
|
public function getUser()
|
|
{
|
|
return $this->hasOne(User::class, ['id' => 'user_id']);
|
|
}
|
|
|
|
//诊所
|
|
public function getStore(){
|
|
return $this->hasOne(Store::class, ['id' => 'store_id']);
|
|
}
|
|
//就诊人
|
|
public function getPatients()
|
|
{
|
|
return $this->hasOne(UserPatient::class, ['id' => 'up_id']);
|
|
}
|
|
|
|
|
|
//就诊人
|
|
public function getUserPatient()
|
|
{
|
|
return $this->hasOne(UserPatient::class, ['id' => 'up_id']);
|
|
}
|
|
|
|
//医生
|
|
public function getDoctorInfo()
|
|
{
|
|
return $this->hasOne(DoctorInfo::class, ['su_id' => 'su_id']);
|
|
}
|
|
|
|
//登录用户
|
|
public function getServiceUser()
|
|
{
|
|
return $this->hasOne(ServiceUser::class, ['id' => 'su_id']);
|
|
}
|
|
|
|
//药师
|
|
public function getPharmacistInfo()
|
|
{
|
|
return $this->hasOne(PharmacistrInfo::class, ['su_id' => 'pharmacist_id']);
|
|
}
|
|
|
|
//挂号
|
|
public function getRegister()
|
|
{
|
|
return $this->hasOne(Register::class, ['id' => 'register_id']);
|
|
}
|
|
|
|
//转诊记录
|
|
public function getTransferPrescription()
|
|
{
|
|
return $this->hasOne(TransferPrescription::class, ['id' => 'transfer_prescription_id']);
|
|
}
|
|
|
|
//导出处方
|
|
public static function inventory($params,$store_id)
|
|
{
|
|
//统计时间范围
|
|
if (!empty($params['start_time']) && !empty($params['end_time'])) {
|
|
$params['start_time'] = strtotime($params['start_time']);
|
|
$params['end_time'] = strtotime($params['end_time']);
|
|
}
|
|
else{
|
|
$params['start_time'] = strtotime(date('Y-m-d'));
|
|
$params['end_time'] = strtotime(date('Y-m-d',strtotime("-31 day")));
|
|
}
|
|
|
|
$where = $andWhere = [];
|
|
if($store_id){
|
|
$where['store_id'] = $store_id;
|
|
}
|
|
$where['is_deleted'] = 0;
|
|
$andWhere = ['between', 'yii_prescription.created_at', $params['start_time'], $params['end_time']];
|
|
if($params['status']){
|
|
$where['yii_prescription.status'] = $params['status'];
|
|
}
|
|
if (!empty($params['prescription_no'])) {//处方编号
|
|
$where['yii_prescription.prescription_no'] = $params['prescription_no'];
|
|
}
|
|
$name = $params['name'];
|
|
if($name){
|
|
$where['yii_user_patient.name'] = $name;
|
|
}
|
|
$doctor = $params['doctor'];
|
|
if($doctor){
|
|
$where['yii_doctor_info.name'] = $doctor;
|
|
}
|
|
if (!empty($params['clinical_diagnose'])) {//临床诊断
|
|
$where['yii_prescription.clinical_diagnose'] = $params['clinical_diagnose'];
|
|
}
|
|
if (!empty($params['is_dispense'])) {//是否配药
|
|
$where['yii_prescription.is_dispense'] = $params['is_dispense'];
|
|
}
|
|
//查询数据
|
|
$list=Prescription::find()->where($where)->andWhere($andWhere)->joinWith(['doctorInfo','userPatient'])->asArray()->all();
|
|
//把结果按照显示顺序存到返回的数组中
|
|
if(!empty($list)){
|
|
foreach ($list as $key => $value){
|
|
|
|
$inventory[$key]['prescription_no'] = $value['prescription_no'];
|
|
$inventory[$key]['doctor'] = $value['doctorInfo']['name']??'无';
|
|
$inventory[$key]['patient'] = $value['userPatient']['name']??'无';
|
|
|
|
//订单状态
|
|
if ($value['status']==0 ){
|
|
$inventory[$key]['prescription_status'] ='待审核';
|
|
}elseif ($value['status']==1){
|
|
$inventory[$key]['prescription_status'] ='已通过';
|
|
}elseif ($value['status']==2){
|
|
$inventory[$key]['prescription_status'] ='未通过';
|
|
}else{
|
|
$inventory[$key]['prescription_status'] ='未知';
|
|
}
|
|
|
|
$inventory[$key]['total_pay_price'] = $value['total_pay_price']??'无';
|
|
$inventory[$key]['is_dispense'] = $value['is_dispense']==0?'未取药':'已取药';//是否取药
|
|
$inventory[$key]['created_at'] = date('Y-m-d H:i:s',$value['created_at']);//下单时间
|
|
}
|
|
|
|
}else{
|
|
$inventory[0]['prescription_no']= '无数据导出';
|
|
}
|
|
return $inventory;
|
|
}
|
|
} |