录医案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.7 KiB

9 months ago
<?php
/**
*
*/
include_once(SERVER_ROOT."/model/mBase.php");
class mCase extends mBase {
private $obj;
private $tbl;
private $case_herb_tbl;
private $herb_tbl;
private $collect_log_tbl;
public function __construct() {
$this->obj = new dCase();
$this->tbl = 'tcm_case';
$this->case_herb_tbl = 'tcm_case_herb';
$this->herb_tbl = 'tcm_herb';
$this->collect_log_tbl = 'tcm_collect_log';
}
public function createCase($info){
return $this->obj->insert($this->tbl, $info);
}
public function updateCase($id,$data){
return $this->obj->update($this->tbl, $data, array('sql'=>'`id`=?', 'vals'=>array($id)));
}
public function updateCaseSearchNum($id){
return $this->obj->increase($this->tbl, array('sql'=>'`id`=?', 'vals'=>array($id)),'search_num');
}
public function getCaseByName($name,$start,$pagesize) {
$sql = " `name` like '%{$name}%'";
$res = $this->obj->selectAll($this->tbl, array('sql'=>$sql, 'vals'=>array()), 'search_num desc,sort asc ', array($start, $pagesize));
if(empty($res)) return array();
return $res;
}
public function getCaseById($id){
return $this->obj->select($this->tbl, array('sql'=>'`id`=?','vals'=>array($id)));
}
public function getCaseInfo($id) {
//药方信息
$case = $this->getCaseById($id);
//药方药材信息
$case_herb = $this->getCaseHerbByCaseId($case['id']);
//药材名称
$herb_ids = array_column($case_herb,'herb_id');
$herb = $this->getHerbByIds($herb_ids);
$data = array(
'case' => $case,
'case_herb' => $case_herb,
'herb' => array_column($herb,null,'id'),
);
return $data;
}
public function getCaseByIds($ids){
return $this->obj->selectIn($this->tbl, array('id'=>$ids));
}
public function createCaseHerb($info){
return $this->obj->mutiInsert($this->case_herb_tbl, $info);
}
public function getCaseHerbByCaseId($case_id){
return $this->obj->selectAll($this->case_herb_tbl, array('sql'=>'`case_id`=?','vals'=>array($case_id)), 'sort asc ');
}
public function compareCaseHerb($old_data,$new_data){
$old_num = count($old_data);
$new_num = count($new_data);
//需要删除
if($old_num>=$new_num){
foreach ($old_data as $key => $value) {
if(!isset($new_data[$key])){
$this->obj->delete($this->case_herb_tbl, array('sql'=>'`id`=?', 'vals'=>array($value['id'])));
continue;
}
$this->obj->update($this->case_herb_tbl, $new_data[$key], array('sql'=>'`id`=?', 'vals'=>array($value['id'])));
}
}else{
foreach ($new_data as $key => $value) {
if(!isset($old_data[$key])){
$this->obj->insert($this->case_herb_tbl, $value);
continue;
}
$this->obj->update($this->case_herb_tbl, $value, array('sql'=>'`id`=?', 'vals'=>array($old_data[$key]['id'])));
}
}
return true;
}
public function createHerb($info){
return $this->obj->insert($this->herb_tbl, $info);
}
public function getHerbByName($name){
return $this->obj->select($this->herb_tbl, array('sql'=>'`name`=?', 'vals'=>array($name)));
}
public function getHerbByIds($ids){
return $this->obj->selectIn($this->herb_tbl, array('id'=>$ids));
}
public function getCollectLog($start,$pagesize) {
return $this->obj->selectAll($this->collect_log_tbl, array(), 'collect_time desc ', array($start, $pagesize));
}
9 months ago
}