| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- <?php
- namespace app\api\servies\link;
- use app\api\dao\link\LinkDao;
- use app\api\servies\ZskkDefaultService;
- use think\facade\Config;
- use think\facade\Log;
- use think\Db;
- use think\db\exception;
- /**
- * 后台控制器基类
- * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
- */
- class LinkService extends ZskkDefaultService {
- protected $logName = "LinkService";
- private $linkDao = null;
- public function __construct(LinkDao $linkDao) {
- parent::__construct();
- $this->linkDao = $linkDao;
- }
- public function getPacsInstitutionExam()
- {
- $institution = $this->linkDao->getAllIns();
- $allIns = [];
- foreach ($institution as $k=>$v)
- {
- $allIns[$v['id']] = $v['name'];
- }
- $exam = $this->linkDao->getinsExam();
- rsort($exam);
- $arr = [];
- foreach ($exam as $k=>$v)
- {
- if(empty($allIns[$v['institution_id']] ?? ''))
- {
- continue;
- }
- $arr[] = ['name'=>$allIns[$v['institution_id']] ,'num'=> $v['num']];
- }
- return $arr;
- }
- public function getPacsAgeExam()
- {
- $data = $this->linkDao->getPacsAgeExam();
- $arr = $this->statisticsAge($data);
- return $arr;
- }
- public function getPacsDateExam()
- {
- $data = $this->linkDao->getPacsDateExam();
- return $data;
- }
- /**
- * 统计年龄分布
- */
- function statisticsAge($data) {
- $ageStats = [];
- foreach ($data as $row) {
- $age = $this->normalizeAge($row['age']);
- $count = (int)$row['row_cnt'];
- // 跳过无效年龄
- if ($age === null) {
- continue;
- }
- // 累加相同年龄的数量
- if (!isset($ageStats[$age])) {
- $ageStats[$age] = 0;
- }
- $ageStats[$age] += $count;
- }
- // 转换为所需格式并按年龄排序
- $result = [];
- ksort($ageStats);
- foreach ($ageStats as $age => $count) {
- $result[] = [
- 'age' => $age,
- 'count' => $count
- ];
- }
- return $result;
- }
- function normalizeAge($ageStr) {
- if (empty($ageStr) || $ageStr === 'NULL' || $ageStr === '不详') {
- return null;
- }
- $ageStr = trim($ageStr);
- // 处理 Y 结尾的年龄(如 27Y, 83Y)
- if (preg_match('/^(\d+)Y$/i', $ageStr, $matches)) {
- return (int)$matches[1];
- }
- // 处理"岁"结尾的年龄(如 31岁, 72岁)
- if (preg_match('/^(\d+)岁/', $ageStr, $matches)) {
- return (int)$matches[1];
- }
- // 处理小数格式(如 74.00, 64.00)
- if (preg_match('/^(\d+)\.?\d*$/', $ageStr, $matches)) {
- return (int)$matches[1];
- }
- // 处理纯数字(如 48, 179)
- if (is_numeric($ageStr)) {
- return (int)$ageStr;
- }
- // 处理月份(如 3月28天, 10M)- 转换为 0 岁
- if (preg_match('/月|M$/i', $ageStr)) {
- return 0;
- }
- // 处理天数或小时(如 19天, 0小时19分钟)- 转换为 0 岁
- if (preg_match('/天|小时|分钟|D$/i', $ageStr)) {
- return 0;
- }
- // 其他无法识别的格式返回 null
- return null;
- }
- public function getPacsCount()
- {
- $info = Db::query("SELECT TRUNC(createdAt,'MM') AS month_begin,COUNT(*) AS cnt FROM pacs.query_study_logs GROUP BY TRUNC(createdAt,'MM') ORDER BY month_begin");
- $all = 0;
- foreach ($info as $k=>$v)
- {
- $info[$k]['month_begin'] = (explode(' ',$v['month_begin'])[0] ?? '');
- $all += $v['cnt'];
- }
- $project = $this->linkDao->countExam();
- $data = ['image'=>$all,'project'=>$project,'list'=>$info];
- return $data;
- }
- public function getPacsResult()
- {
- $arr = $this->linkDao->getReportResult();
- $data = ['阴性'=>0,'阳性'=>0,'其他'=>0];
- foreach ($arr as $k=>$v)
- {
- if($v['report_result'] == '1')
- {
- $data['阴性'] += $v['cnt'];
- }elseif ($v['report_result'] == '2')
- {
- $data['阳性'] += $v['cnt'];
- }else{
- $data['其他'] += $v['cnt'];
- }
- }
- $return = $this->makeData($data);
- return $return;
- }
- public function makeData($arr)
- {
- $data = [];
- foreach ($arr as $k=>$v)
- {
- $data[] = ['name'=>$k,'value'=>$v];
- }
- return $data;
- }
- public function getPacsSex()
- {
- $arr = $this->linkDao->getSexData();
- $data = ['男'=>0,'女'=>0,'其他'=>0];
- foreach ($arr as $k=>$v)
- {
- if($v['sex'] == 'M' || $v['sex'] == '男' )
- {
- $data['男'] += $v['cnt'];
- }elseif ($v['sex'] == 'F' || $v['sex'] == '女')
- {
- $data['女'] += $v['cnt'];
- }else{
- $data['其他'] += $v['cnt'];
- }
- }
- $return = $this->makeData($data);
- return $return;
- }
- public function getMiddleProjectList()
- {
- $list = $this->linkDao->getMiddleProjectList();
- return $list;
- }
- public function getPacsMapExam()
- {
- $institution = $this->linkDao->getAllIns();
- $allIns = [];
- foreach ($institution as $k=>$v)
- {
- $allIns[$v['id']] = $v;
- }
- $exam = $this->linkDao->getInsExam();
- rsort($exam);
- $arr = [];
- foreach ($exam as $k=>$v)
- {
- if(empty($allIns[$v['institution_id']] ?? ''))
- {
- continue;
- }
- $arr[] = ['num'=>$v['num'],'lng'=>$allIns[$v['institution_id']]['lng'],'lat'=>$allIns[$v['institution_id']]['lat'],'NAME'=>$allIns[$v['institution_id']]['name']];
- }
- return $arr;
- }
- }
|