lgy 3 minggu lalu
induk
melakukan
26b306b343

+ 63 - 0
server/application/api/controller/link/LinkController.php

@@ -0,0 +1,63 @@
+<?php
+namespace app\api\controller\link;
+
+use app\api\controller\ZskkDefaultController;
+use app\api\servies\dict\DictService;
+use app\api\servies\link\LinkService;
+use think\Exception;
+use think\facade\Request;
+
+
+class LinkController extends ZskkDefaultController
+{
+    protected $needToken = false;
+    protected $logName = "LinkController";
+
+    public function getPacsInstitutionExam(LinkService  $linkService)
+    {
+        $data = $linkService->getPacsInstitutionExam();
+        return $this->success($data);
+    }
+
+    public function getPacsDateExam(LinkService  $linkService)
+    {
+        $list = $linkService->getPacsDateExam();
+        return $this->success($list);
+    }
+
+    public function getPacsAgeExam(LinkService  $linkService)
+    {
+        $list = $linkService->getPacsAgeExam();
+        return $this->success($list);
+    }
+
+    public function getPacsCount(LinkService  $linkService)
+    {
+        $list = $linkService->getPacsCount();
+        return $this->success($list);
+    }
+
+    public function getPacsResult(LinkService  $linkService)
+    {
+        $list = $linkService->getPacsResult();
+        return $this->success($list);
+    }
+
+    public function getPacsSex(LinkService  $linkService)
+    {
+        $list = $linkService->getPacsSex();
+        return $this->success($list);
+    }
+
+    public function getMiddleProjectList(LinkService  $linkService)
+    {
+        $list = $linkService->getMiddleProjectList();
+        return $this->success($list);
+    }
+
+    public function getPacsMapExam(LinkService  $linkService)
+    {
+        $list = $linkService->getPacsMapExam();
+        return $this->success($list);
+    }
+}

+ 73 - 0
server/application/api/dao/link/LinkDao.php

@@ -0,0 +1,73 @@
+<?php
+
+namespace app\api\dao\link;
+use app\api\actions\ZskkCache;
+use app\api\dao\ZskkDefaultDao;
+use app\api\model\exam\ExamModel;
+use app\api\model\institution\InstitutionModel;
+use app\api\model\report\ReportModel;
+
+
+/**
+ * 后台控制器基类
+ * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
+ */
+
+class LinkDao extends ZskkDefaultDao {
+
+    protected $flag = true;
+    protected $logName = "LinkDao";
+    protected $institution;
+    protected $examModel;
+    protected $reportModel;
+
+    public function __construct(InstitutionModel $institutionModel,ExamModel $examModel,ReportModel $reportModel)
+    {
+        parent::__construct();
+        $this->institution = $institutionModel;
+        $this->examModel = $examModel;
+        $this->reportModel = $reportModel;
+    }
+
+    public function getAllIns()
+    {
+        return $this->institution->cache('3600')->select();
+    }
+
+    public function getinsExam()
+    {
+        return $this->examModel->field('count(*) AS num,institution_id')->group('institution_id')->select();
+    }
+    public function getPacsDateExam()
+    {
+        $data = $this->examModel->field("TO_CHAR(TRUNC(createdat,'MM'),'yyyy/mm') AS month_begin,   COUNT(*) AS row_cnt")->group("TO_CHAR(TRUNC(createdat,'MM'),'yyyy/mm')")->order('month_begin')->select();
+        return $data;
+    }
+
+    public function getPacsAgeExam()
+    {
+        $data = $this->examModel->field("age,   COUNT(*) AS row_cnt")->group("age")->order('age')->select();
+        return $data;
+    }
+
+    public function countExam()
+    {
+        return $this->examModel->count();
+    }
+
+    public function getSexData()
+    {
+        $arr = $this->examModel->group('sex')->field('sex,count(*) AS cnt')->select();
+        return $arr;
+    }
+
+    public function getReportResult()
+    {
+        return $this->examModel->alias('e')->join(['report'=>'r'],'r.exam_id=e.id','left')->field('r.report_result,count(*) AS cnt')->group('r.report_result')->select();
+    }
+
+    public function getMiddleProjectList()
+    {
+        return $this->examModel->alias('e')->join(['institution'=>'i'],'i.id=e.institution_id')->field('i.name AS ORGNAME,e.EXAM_CLASS,e.NAME,e.EXAM_CLASS,e.CREATEDAT AS STUDYTIME,e.exam_project AS EXAM_ITEMNAME')->order('e.CREATEDAT desc')->limit(10)->select();
+    }
+}

+ 232 - 0
server/application/api/servies/link/LinkService.php

@@ -0,0 +1,232 @@
+<?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;
+    }
+}

+ 4 - 4
server/config/database.php

@@ -13,9 +13,9 @@ return [
     // 数据库类型
     'type'            => 'think\oracle\W7Connection',
     // 服务器地址
-    'hostname'        => '192.168.7.11',
+    'hostname'        => '10.217.218.6',
     // 数据库名
-    'database'        => 'PACSONLINE_PRO',
+    'database'        => 'PACS',
     // 用户名
     'username'        => 'PACS',
     // 密码
@@ -66,7 +66,7 @@ return [
         // 服务器地址
         'hostname'        => '10.217.218.6',
         // 数据库名
-        'database'        => 'PACSONLINE_PRO',
+        'database'        => 'PACS',
         // 用户名
         'username'        => 'PACS',
         // 密码
@@ -80,7 +80,7 @@ return [
         // 服务器地址
         'hostname'        => '10.217.218.6',
         // 数据库名
-        'database'        => 'PACSONLINE_PRO',
+        'database'        => 'PACS',
         // 用户名
         'username'        => 'PACS',
         // 密码

+ 8 - 0
server/route/route.php

@@ -238,6 +238,14 @@ Route::group('', function () {
     Route::post('applets/saveAutograph', 'app\api\controller\applets\AppletsController/save_autograph');
     Route::post('applets/autographSwitch', 'app\api\controller\applets\AppletsController/autograph_switch');
     Route::post('applets/getAutograph', 'app\api\controller\applets\AppletsController/getAutograph');
+    Route::get('bi/getPacsInstitutionExam', 'app\api\controller\link\LinkController/getPacsInstitutionExam');
+    Route::get('bi/getPacsDateExam', 'app\api\controller\link\LinkController/getPacsDateExam');
+    Route::get('bi/getPacsAgeExam', 'app\api\controller\link\LinkController/getPacsAgeExam');
+    Route::get('bi/getPacsCount', 'app\api\controller\link\LinkController/getPacsCount');
+    Route::get('bi/getPacsResult', 'app\api\controller\link\LinkController/getPacsResult');
+    Route::get('bi/getPacsSex', 'app\api\controller\link\LinkController/getPacsSex');
+    Route::get('bi/getMiddleProjectList', 'app\api\controller\link\LinkController/getMiddleProjectList');
+    Route::get('bi/getPacsMapExam', 'app\api\controller\link\LinkController/getPacsMapExam');
 })->header('Access-Control-Allow-Headers','X-Requested-With,Content-Type,zskk-random,zskk_institution,zskk-signature,zskk-timestamp,zskk-token,zskk-version')
     ->allowCrossDomain();