Files
xk-api-yii/member/modules/v1/controllers/PatientController.php

186 lines
5.9 KiB
PHP

<?php
namespace member\modules\v1\controllers;
use common\core\BaseAppController;
use common\helpers\ArrayHelper;
use common\helpers\FuncHelper;
use common\models\UserPatient;
use member\models\forms\HealthForm;
use member\models\forms\PatientForm;
use yii\base\Exception;
/**
* @doc-module 就诊人管理
*/
class PatientController extends BaseAppController
{
/**
* @doc-name 就诊人列表
* @doc-desc 默认都是已认证
* @doc-return mixed UserPatient{*} 就诊人列表
*/
public function actionList()
{
$all = UserPatient::find()->with(['healthInquiry'])->where([
'user_id' => \Yii::$app->user->identity->id,
'is_delete' => 0
])->orderBy('id desc')->asArray()->all();
return $all;
}
/**
* @doc-name 就诊人保存
* @doc-param int id 存在则编辑信息 / optional
* @doc-param int name 姓名
* @doc-param string id_card 患者身份证
* @doc-param int age 年龄
* @doc-param int sex 性别,1男2女
* @doc-param int relation 关系,通过关系接口获取
* @doc-param string mobile 患者手机号
* @doc-param int is_default 是否默认 0 optional
* @doc-param int family_status 家庭遗传史0无1有 0 optional
* @doc-param string family_history 家庭遗传史选项,选项添加不用保存后台,["选项1","选项2"] [] optional
* @doc-param int allergic_status 过敏史0无1有 0 optional
* @doc-param string allergic_history 过敏史选项,选项添加不用保存后台,["选项1","选项2"] [] optional
* @doc-param int person_status 既往史0无1有 0 optional
* @doc-param string person_history 既往史选项,选项添加不用保存后台,["选项1","选项2"] [] optional
* @doc-param int liver_function 肝功能0正常1异常 0 optional
* @doc-param string liver_index 肝功能异常指标 0 optional
* @doc-param int renal_function 肾功能0正常1异常 0 optional
* @doc-param string renal_index 肾功能异常指标 0 optional
*/
public function actionSave()
{
$form = new PatientForm();
$form->attributes = \Yii::$app->request->post();
return $form->save();
}
/**
* @doc-name 切换默认接诊人
* @doc-param int up_id 就诊人id
*/
public function actionChangePatient()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post,[
['up_id','required']
]);
$form = new PatientForm();
$form->attributes = $post;
return $form->change();
}
/**
* @doc-name 就诊人关系
* @doc-return int key 建
* @doc-return int value 值
*/
public function actionRelation()
{
return [
['key'=> 0,'text'=>'本人'],
['key'=> 1,'text'=>'丈夫'],
['key'=> 2,'text'=>'妻子'],
['key'=> 3,'text'=>'爸爸'],
['key'=> 4,'text'=>'妈妈'],
['key'=> 5,'text'=>'儿子'],
['key'=> 6,'text'=>'女儿'],
['key'=> 7,'text'=>'其他'],
];
}
/**
* @doc-name 就诊人详情
* @doc-param int id 就诊人id
* @doc-return mixed UserPatient{*,age-int-年龄} 就诊人详情
*/
public function actionInfo()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post,[
['id','required']
]);
$patient = UserPatient::find()->where([
'id' => $post['id'],
'user_id' => \Yii::$app->user->identity->id,
'is_delete' => 0,
])->one();
if(!$patient){
throw new Exception('就诊人不存在');
}
return ArrayHelper::toArray($patient,[
UserPatient::class => [
'id','name','id_card','sex','relation','mobile','is_default',
'avatar'=>function($model){
if (empty($model->avatar)){
return 'https://hbimg.huabanimg.com/2dbbc9177be8b9912b2a0d881200dd47ccb84d92710aa-IepOs1_fw658';
}
return $model->avatar;
},
'age' => function($model){
return FuncHelper::getAgeFromIdNo($model->id_card);
},
]
]);
}
/**
* @doc-name 编辑就诊人信息
* @doc-param int up_id 就诊人id
* @doc-param string avatar 头像
*/
public function actionEditPatient()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post,[
['up_id','required'],
['avatar','required']
]);
$userPatient=UserPatient::find()->where([
'id'=>$post['up_id'],
'user_id'=>\Yii::$app->user->identity->getId(),
])->one();
if (!$userPatient) throw new \yii\db\Exception('就诊人不存在');
UserPatient::updateAll([
'avatar'=>$post['avatar'],
],
['id'=>$post['up_id'],'user_id'=>\Yii::$app->user->identity->getId()]);
return ['编辑成功'];
}
/**
* @doc-name 删除就诊人
* @doc-param int id 就诊人id
*/
public function actionDel()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post,[
['id','required'],
]);
$PatientForm=new PatientForm();
$PatientForm->attributes=$post;
return $PatientForm->del();
}
/**
* @doc-name 查看基本健康信息
* @doc-param int user_patient_id 就诊人id
* @doc-return mixed @UserPatientHealthInquiry{*} 健康信息
*/
public function actionHealthInfo()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post,[
['user_patient_id','required'],
]);
$HealthForm=new HealthForm();
$HealthForm->attributes=$post;
return $HealthForm->info();
}
}