public function updateProject($projectid, $postArr, $piArr = array(), $doctorArr = array(), $patientArr = array(), $tplArr = array()) { $retArr = array('status' => 0, 'message' => '', 'project' => null); $postArr = $this->removeArrayNull($postArr); //数据检查===================================== if (empty($postArr) || !$projectid) { $retArr['message'] = '数据不合法'; return $retArr; } $old = $this->getProject($projectid); if (!$old) { $retArr['message'] = '项目不存在'; return $retArr; } $postArr['utime'] = date("Y-m-d H:i:s"); if (!empty($postArr['name'])) { $oldt = $this->getProject(null, array('hospitalid' => $old['hospitalid'], 'name' => $postArr['name'])); if ($oldt) { $this->appendPI($old['id'], $piArr); $this->appendDoctor($old['id'], $old['userid'], $doctorArr); $this->appendPatient($old['id'], $old['userid'], $patientArr); $this->appendTpl($old['id'], $tplArr); $retArr['project'] = $old; $retArr['message'] = '项目名称不可用'; return $retArr; } } //数据检查==================================end $ok = $this->updateData($this->tProject, $postArr, $projectid); if (CUtil::NoFalse($ok)) { $this->appendPI($old['id'], $piArr); $this->appendDoctor($old['id'], $old['userid'], $doctorArr); $this->appendPatient($old['id'], $old['userid'], $patientArr); $this->appendTpl($old['id'], $tplArr); $project = $this->getProject($projectid); $retArr['project'] = $project; $retArr['status'] = 1; $retArr['message'] = '更新成功'; } else { $retArr['message'] = '系统繁忙,请稍后再试'; } return $retArr; }
public function saveTplReport($reportid = null, $periodid = null, $postArr = array(), $details = array()) { $logfile = 'MTpl'; $retArr = array('status' => 0, 'message' => '数据不合法', 'report' => null); //数据检查 $postArr = $this->removeArrayNull($postArr); if (!empty($details)) { if (empty($details['detailid']) || empty($details['answer'])) { $retArr['message'] = '报告单数据不合法'; return $retArr; } } if (empty($postArr) || empty($postArr['tplid']) || empty($postArr['hospitalid']) || empty($postArr['userid'])) { $retArr['message'] = '数据不完整'; return $retArr; } if (empty($postArr['patientid'])) { $retArr['message'] = '无病人信息,不能继续'; return $retArr; } $tpl = $this->getTpl($postArr['tplid'], null, array('join_detail' => true)); if (!$tpl) { $retArr['message'] = 'tpl不存在'; return $retArr; } $postArr['utime'] = date("Y-m-d H:i:s"); //end 数据检查 //业务上的数据检查 if (!$reportid) { //针对添加作数据检查 /*if(!$periodid){ $retArr['message'] = '周期不存在'; return $retArr; }*/ $periodinfo = $this->getAtom($this->tPeriod, $periodid); if (!$periodinfo) { /*$retArr['message'] = '周期不存在'; return $retArr;*/ $periodinfo = array('periodname' => '', 'tplid' => $postArr['tplid'], 'id' => 0); } $postArr['title'] = $periodinfo['periodname']; $postArr['periodid'] = $periodid; $period = intval($tpl['period']); //周期长度 $freqs = 1; //intval($tpl['freqs']); //频次 一律为1 if ($periodinfo || 0 == $period) { //一次性 //修改于公元2015年12月21日 //必经之路 // $_wh_old_rpt = array('userid'=>$postArr['userid'],'tplid'=>$postArr['tplid']); $_wh_old_rpt = array('tplid' => $postArr['tplid'], 'periodid' => $periodid); } else { //计算当前时间处于第几个周期,并得到这个周期的开始日期 $t_start = strtotime(date("Y-m-d", strtotime($tpl['ctime']))); $s_period = intval((time() - $t_start) / (86400 * $period)); $last_p_s = date("Y-m-d 00:00:00", $t_start + 86400 * $period); //最近一个周期的起始时间 $_wh_old_rpt = array('userid' => $postArr['userid'], 'tplid' => $postArr['tplid'], 'utime>' => $last_p_s); } // $old = $this->getTplReport(null,$_wh_old_rpt,array('aggregated'=>true,'order'=>'id desc')); $old = $this->getTplReport(null, $_wh_old_rpt, array('aggregated' => true, 'order' => 'id desc')); if ($old) { //如果已经存在一分报告 //获取已填写的次数 $cnteds = $this->getCount($this->tReport, $_wh_old_rpt); $utime = $old['utime']; //上次保存时间 if (1 || 0 == $period || $cnteds >= $freqs) { // if($freqs > 1) return; //如果是多次就返回,因为不知道更新哪条好(也可以更新最后一条) $reportid = $old['id']; //最近一周期已经填写过了就不能再添加了,赋值reportid是为了接下来作更新操作 } /* switch($period){ case 0: $reportid = $old['id']; break; //一次性的就不能再添加了 case -1: if(CTime::IsToday($utime) && $cnteds>=$freqs){//是今天 $reportid = $old['id']; } break; case -7: if(CTime::IsWeek($utime)){//是本周 $reportid = $old['id']; } break; case -30: if(CTime::IsMonth($utime)){//是本月 $reportid = $old['id']; } break; case -365: if(CTime::IsYear($utime)){//是当年 $reportid = $old['id']; } break; }*/ } } //end 业务上的数据检查 CLog::WriteLog(array('msg' => 'commit数据', 'reportid' => $reportid, 'periodid' => $periodid, 'postArr' => $postArr, 'details' => $details), $logfile); if ($reportid) { $ok = $this->updateData($this->tReport, $postArr, $reportid); } else { $postArr['ctime'] = $postArr['utime']; $ok = $reportid = $this->addAtom($this->tReport, $postArr); } if (CUtil::NoFalse($ok)) { $report = $this->getTplReport($reportid, null, array('aggregated' => true)); //更新报告值===================================== if ($details) { $valueArr = CUtil::formArrayFormatting($details, 0); CLog::WriteLog(array('msg' => 'commit值', 'valueArr' => $valueArr), $logfile); $tpl_did_arr = $this->getArrayColumn($valueArr, 'detailid'); $detailArr = $this->getData($this->tTdetail, array('id in' => $tpl_did_arr), array('limit' => count($tpl_did_arr), 'keyas' => 'id')); $termid_arr = $this->getArrayColumn($detailArr, 'termid'); $MTerm = $this->LoadApiModelMedical('term'); $termArr = $MTerm->getTerms($termid_arr, null, array('limit' => count($termid_arr), 'only_data' => true, 'keyas' => 'id', 'fields' => '^ctime,utime')); // print_r($termArr); foreach ($valueArr as $k => &$r0005) { if (empty($r0005['detailid'])) { unset($valueArr[$k]); continue; } //检查detailid在数据库中是否存在,不存在则删除 if (!isset($detailArr[$r0005['detailid']])) { unset($valueArr[$k]); continue; } //检查指标是否在指标库中存在,存在则将termid及输入类型存放tpl_report_detail中 $detail = $detailArr[$r0005['detailid']]; if (isset($termArr[$detail['termid']])) { $term = $termArr[$detail['termid']]; $r0005['termid'] = $term['id']; $r0005['itype'] = $term['itype']; $r0005['vtype'] = $term['vtype']; } $r0005 = $this->removeArrayNull($r0005); } if (!empty($valueArr)) { $_wh_ = array('reportid' => $reportid); //查询详情(tpl_detail)的条件 $oldValArr = $this->getMore($this->tRdetail, $_wh_, array('only_data' => true, 'keyas' => 'id', 'aggregated' => true, 'limit' => 1000)); // $this->deleteData($this->tRdetail, $_wh_, 1000); $sorter = 127; foreach ($valueArr as $r0003) { $r0003['tplid'] = $postArr['tplid']; $r0003['reportid'] = $reportid; $r0003['sorter'] = $sorter; $r0003['utime'] = date("Y-m-d H:i:s"); $_old_id = intval($r0003['id']); unset($r0003['id']); if (0 == $_old_id) { //表示是新增的 $old_rdetail = $this->getAtom($this->tRdetail, array('reportid' => $reportid, 'detailid' => $r0003['detailid'])); if ($old_rdetail) { //如果是同一报告中的同一指标已存在,那只能修改 // print_r($r0003);itype // echo 'eeeeeeeeeeeeeeeee'; $this->updateData($this->tRdetail, $r0003, $old_rdetail['id']); } else { $this->addAtom($this->tRdetail, $r0003); } } else { $r0003['id'] = $_old_id; if (isset($oldValArr[$_old_id])) { $r0003 = array_merge($oldValArr[$_old_id], $r0003); //原id存在 } $this->updateData($this->tRdetail, $r0003, $_old_id); } $sorter--; } //填充未填写的值 if (isset($tpl['tpl_detail'])) { $tplValList = $tpl['tpl_detail']; foreach ($tplValList as $tplVal) { $_detailid = $tplVal['id']; $_old = $this->getAtom($this->tRdetail, array('reportid' => $reportid, 'detailid' => $_detailid)); if (!$_old) { $blankArr = array('reportid' => $reportid, 'detailid' => $_detailid, 'tplid' => $tplVal['tplid'], 'termid' => $tplVal['termid'], 'utime' => date('Y-m-d H:i:s')); $this->addAtom($this->tRdetail, $blankArr); } } } //end 填充未填写的值 } } //更新报告值==================================end $retArr['report'] = $report; $retArr['status'] = 1; $retArr['message'] = '更新成功'; } return $retArr; }