|
|
<?php
|
|
|
|
|
|
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
|
|
|
use app\admin\model\Department;
|
|
|
use app\admin\model\Drugs;
|
|
|
use app\admin\model\User;
|
|
|
use app\admin\model\User_Role;
|
|
|
use app\lib\enum\ExceptionType;
|
|
|
use app\lib\exception\HtmlException;
|
|
|
use app\lib\exception\JsonException;
|
|
|
use app\lib\exception\Success;
|
|
|
use app\lib\validate\IdMustBePositiveInt;
|
|
|
use app\viewModel\PatientMedicalView;
|
|
|
use think\Request;
|
|
|
use think\Session;
|
|
|
|
|
|
class PatientMedical extends BaseController
|
|
|
{
|
|
|
public function index(){
|
|
|
$map = [];
|
|
|
if (Request::instance()->isPost()) {
|
|
|
$input = Request::instance()->param();
|
|
|
}
|
|
|
else {
|
|
|
$input = Request::instance()->get();
|
|
|
}
|
|
|
if (!empty($input['code'])){
|
|
|
$map['code'] = $input['code'];
|
|
|
}
|
|
|
$patient = \app\admin\model\PatientInfo::where($map)->column('id');
|
|
|
$patientId['id'] = ['in',$patient];
|
|
|
$medicals = \app\admin\model\PatientMedical::viewQuery(PatientMedicalView::CLASS,"patientDrugsDepartmentList")
|
|
|
->where(['patient_id'=>$patientId['id']])
|
|
|
->paginate(10,false,[
|
|
|
"query" => [
|
|
|
'code' => $map['code'],
|
|
|
]
|
|
|
]);
|
|
|
// $medicalInfos = [];
|
|
|
// foreach($medicals as $key => $medical){
|
|
|
// $medicalInfos[$medical['patientName']][] = $medical;
|
|
|
// }
|
|
|
$total = $medicals->total();
|
|
|
$page = $medicals->render();
|
|
|
$this->assign('page',$page);
|
|
|
$this->assign('total',$total);
|
|
|
$this->assign('code',$map['code']);
|
|
|
$this->assign('medicals',$medicals);
|
|
|
return $this->fetch();
|
|
|
}
|
|
|
|
|
|
//添加药单
|
|
|
public function addMedical(){
|
|
|
if(Request::instance()->isPost()){
|
|
|
$input = Request::instance()->param();
|
|
|
//流水号
|
|
|
$patientId = \app\admin\model\PatientInfo::where(['code'=>$input['code']])->column('id');
|
|
|
if(empty($patientId)){
|
|
|
throw new HtmlException('不存在该患者信息');
|
|
|
}
|
|
|
//药品id与单价
|
|
|
foreach ($input['drugs'] as $key=>$temp){
|
|
|
$drugs[$key] = Drugs::where(['name'=>$temp])->column('id');
|
|
|
if(empty($drugs[$key])){
|
|
|
throw new HtmlException('请检查药品名是否正确');
|
|
|
}
|
|
|
$unitPrice[$key] = Drugs::where(['name'=>$temp])->column('price');
|
|
|
}
|
|
|
//药品价格
|
|
|
foreach ($input['quantity'] as $key=>$temp){
|
|
|
$price[$key] = $unitPrice[$key][0]*$temp;
|
|
|
// p($unitPrice[$key][0]);
|
|
|
// p($temp);
|
|
|
}
|
|
|
//职工id
|
|
|
$doctorId = Session::get('id');
|
|
|
// $drugs['id'] = ['in',$drugs];
|
|
|
for($i=1,$sure=1;$i<=$input['drugsNumber'];$i++){
|
|
|
//判断条件:患者id、药品id
|
|
|
$patientMedical = \app\admin\model\PatientMedical::where(['patient_id'=>$patientId[0],'drugs_id'=>$drugs[$i][0]])->find();
|
|
|
// p($drugs[$i][0]);
|
|
|
//注意id 当已存在该药品的数据则将data保存在原id;无则增加id
|
|
|
$id = count(\app\admin\model\PatientMedical::where(1)->select());
|
|
|
if(!empty($patientMedical)){
|
|
|
//注意价格与数量 在原有的基础上增加
|
|
|
$data = [
|
|
|
'id' => $patientMedical['id'],
|
|
|
'patient_id' => $patientId[0],
|
|
|
'doctor_id' => $doctorId,
|
|
|
'drugs_id' => $drugs[$i][0],
|
|
|
'quantity' => $patientMedical['quantity'] + $input['quantity'][$i],
|
|
|
'price' => $patientMedical['price']+$price[$i],
|
|
|
];
|
|
|
$patientMedical->save($data);
|
|
|
// $sure=$i;
|
|
|
}
|
|
|
else{
|
|
|
$data = new \app\admin\model\PatientMedical([
|
|
|
'id' => $id+1,
|
|
|
'patient_id' => $patientId[0],
|
|
|
'doctor_id' => $doctorId,
|
|
|
'drugs_id' => $drugs[$i][0],
|
|
|
'quantity' => $input['quantity'][$i],
|
|
|
'price' => $price[$i],
|
|
|
]);
|
|
|
$data->save();
|
|
|
}
|
|
|
}
|
|
|
return $this->success('添加成功');
|
|
|
}
|
|
|
return $this->fetch();
|
|
|
}
|
|
|
|
|
|
//删除患者药单
|
|
|
public function delHandle($id){
|
|
|
$res = \app\admin\model\PatientMedical::where(['id' => $id])->delete();
|
|
|
if($res == 0)
|
|
|
{
|
|
|
throw new JsonException('1','删除失败!');
|
|
|
}
|
|
|
throw new Success('删除成功!');
|
|
|
}
|
|
|
|
|
|
} |