From 8ea6b2e18527d23a542b5bab8bde243ecb7211c2 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期三, 20 五月 2026 14:40:19 +0800
Subject: [PATCH] 【丽水】随访统计超链接 指标统计超链接

---
 smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java |  145 ++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 121 insertions(+), 24 deletions(-)

diff --git a/smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java
index 1c4d159..0a1c316 100644
--- a/smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java
@@ -699,7 +699,7 @@
                     i = serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
                     addServiceSubtaskPreachform(serviceSubtask, null);
                 }
-            } else if (serviceSubtask.getTaskSituation() == 6) {
+            } else if (serviceSubtask.getTaskSituation() != null && serviceSubtask.getTaskSituation() == 6) {
                 //璇存槑璇ユ偅鑰呮槸琚繃婊ょ殑锛屼笉鐢ㄥ啀鎵ц浜�
                 serviceSubtask.setCreateBy(serviceTask.getCreateBy());
                 serviceSubtask.setCreateTime(new Date());
@@ -1432,6 +1432,40 @@
     }
 
     /**
+     * 缁熶竴鏇存柊pat_med_inhosp鐨刢heck_flag
+     *
+     * @param patMedInhosp 鎮h�呬綇闄㈣褰�
+     * @param type         1=deptcheck_flag, 2=wardcheck_flag, 3=diagcheck_flag, 4=inDeptcheck_flag, 5=inWardcheck_flag
+     * @param flagValue    瑕佽缃殑鍊�
+     * @param remark       澶囨敞淇℃伅
+     */
+    private void updateCheckFlag(PatMedInhosp patMedInhosp, Integer type, String flagValue, String remark) {
+        PatMedInhosp updateObj = new PatMedInhosp();
+        updateObj.setInhospid(patMedInhosp.getInhospid());
+        switch (type) {
+            case 1:
+                updateObj.setDeptcheckFlag(flagValue);
+                break;
+            case 2:
+                updateObj.setWardcheckFlag(flagValue);
+                break;
+            case 3:
+                updateObj.setDiagcheckFlag(flagValue);
+                break;
+            case 4:
+                updateObj.setInDeptcheckFlag(flagValue);
+                break;
+            case 5:
+                updateObj.setInWardcheckFlag(flagValue);
+                break;
+        }
+        if (StringUtils.isNotEmpty(remark)) {
+            updateObj.setRemark(remark + " (type=" + type + ")");
+        }
+        patMedInhospMapper.updatePatMedInhosp(updateObj);
+    }
+
+    /**
      * 鍩轰簬瑙勫垯鐨勪换鍔$敓鎴愭柟娉�
      * 鏍规嵁鎮h�呯闄㈢瀹ゆ垨鐥呭尯鏌ヨservice_task_rule锛岃幏鍙杁eptRule銆亀radRule銆乨iagRule
      * 鏍规嵁瑙勫垯鍊煎喅瀹氳皟鐢ㄥ摢涓柟娉曠敓鎴愰殢璁夸换鍔�
@@ -1474,47 +1508,108 @@
                     // 鏈夎鍒欙紝鎸夎鍒欐墽琛�
                     log.info("銆愬熀浜庤鍒欍�戞偅鑰厈}鏌ヨ鍒拌鍒欙細deptRule={}, wradRule={}, diagRule={}", patMedInhosp1.getInhospid(), rule.getDeptRule(), rule.getWradRule(), rule.getDiagRule());
 
-                    // 鍒ゆ柇鏄惁鏈夎鍒欎负"1"锛堥鍏堟墽琛岋級
-                    boolean hasPrimaryRule = "1".equals(rule.getDeptRule()) || "1".equals(rule.getWradRule()) || "1".equals(rule.getDiagRule());
+                    boolean deptIsPrimary = "1".equals(rule.getDeptRule());
+                    boolean wardIsPrimary = "1".equals(rule.getWradRule());
+                    boolean diagIsPrimary = "1".equals(rule.getDiagRule());
+                    boolean deptIsSecondary = "2".equals(rule.getDeptRule());
+                    boolean wardIsSecondary = "2".equals(rule.getWradRule());
+                    boolean diagIsSecondary = "2".equals(rule.getDiagRule());
+
+                    boolean hasPrimaryRule = deptIsPrimary || wardIsPrimary || diagIsPrimary;
 
                     if (hasPrimaryRule) {
-                        // 鏈夐瑕佽鍒欙紝鍙墽琛岄瑕佽鍒欏搴旂殑鏂规硶
-                        int generatedCount = 0;
+                        // 绗竴姝ワ細鎵ц鎵�鏈夎鍒�=1鐨勬柟娉曪紝姣忎釜鐙珛璁板綍鎴愬姛/澶辫触
+                        int deptGenCount = 0;
+                        int wardGenCount = 0;
+                        int diagGenCount = 0;
 
-                        // 鎸夐『搴忥細绉戝 -> 鐥呭尯 -> 鐤剧梾
-                        if ("1".equals(rule.getDeptRule())) {
+                        if (deptIsPrimary) {
                             log.info("銆愬熀浜庤鍒欍�戞墽琛岀瀹ら瑕佽鍒�");
-                            generatedCount += addDeptSubTaskForPatient(patMedInhosp1, patArchive, config);
+                            deptGenCount = addDeptSubTaskForPatient(patMedInhosp1, patArchive, config);
                         }
 
                         if (!active.equals("xh")) {
-                            if ("1".equals(rule.getWradRule())) {
+                            if (wardIsPrimary) {
                                 log.info("銆愬熀浜庤鍒欍�戞墽琛岀梾鍖洪瑕佽鍒�");
-                                generatedCount += addWardSubTaskForPatient(patMedInhosp1, patArchive, config);
+                                wardGenCount = addWardSubTaskForPatient(patMedInhosp1, patArchive, config);
                             }
 
-                            if ("1".equals(rule.getDiagRule())) {
+                            if (diagIsPrimary) {
                                 log.info("銆愬熀浜庤鍒欍�戞墽琛岀柧鐥呴瑕佽鍒�");
-                                generatedCount += addIcd10SubTaskForPatient(patMedInhosp1, patArchive, config);
+                                diagGenCount = addIcd10SubTaskForPatient(patMedInhosp1, patArchive, config);
                             }
                         }
 
-                        // 濡傛灉棣栬瑙勫垯鐢熸垚鐨勫瓙浠诲姟涓虹┖锛屽垯璋冪敤鍏朵粬娆¤瑙勫垯鐨勬柟娉�
-                        if (generatedCount == 0) {
-                            log.info("銆愬熀浜庤鍒欍�戦瑕佽鍒欐湭鐢熸垚瀛愪换鍔★紝寮�濮嬫墽琛屾瑕佽鍒�");
+                        int primaryGeneratedCount = deptGenCount + wardGenCount + diagGenCount;
+                        log.info("銆愬熀浜庤鍒欍�戦瑕佽鍒欐墽琛岀粨鏋�: deptGen={}, wardGen={}, diagGen={}, total={}", deptGenCount, wardGenCount, diagGenCount, primaryGeneratedCount);
 
-                            if (!"1".equals(rule.getDeptRule()) && StringUtils.isNotEmpty(rule.getDeptRule())) {
+                        // 绗簩姝ワ細鍒ゆ柇棣栬瑙勫垯鏄惁鏈変换鎰忎竴涓敓鎴愭垚鍔�
+                        if (primaryGeneratedCount > 0) {
+                            // 鑷冲皯鏈変竴涓瑕佽鍒欑敓鎴愭垚鍔�
+                            // 鈥斺�� 灏�=2鐨勬瑕佽鍒欏搴攆lag璁句负"2"锛堣烦杩囷級
+                            log.info("銆愬熀浜庤鍒欍�戦瑕佽鍒欐湁鎴愬姛(count={})锛屽皢娆¤瑙勫垯瀵瑰簲flag璁句负2", primaryGeneratedCount);
+                            if (deptIsSecondary) {
+                                updateCheckFlag(patMedInhosp1, 1, "2", "棣栬瑙勫垯宸茬敓鎴愶紝娆¤瑙勫垯璺宠繃");
+                            }
+                            if (!active.equals("xh")) {
+                                if (wardIsSecondary) {
+                                    updateCheckFlag(patMedInhosp1, 2, "2", "棣栬瑙勫垯宸茬敓鎴愶紝娆¤瑙勫垯璺宠繃");
+                                }
+                                if (diagIsSecondary) {
+                                    updateCheckFlag(patMedInhosp1, 3, "2", "棣栬瑙勫垯宸茬敓鎴愶紝娆¤瑙勫垯璺宠繃");
+                                }
+                            }
+                            // 鈥斺�� 瀵逛簬=1涓旂敓鎴愭垚鍔熺殑锛屽皢鍏跺搴攆lag璁句负"1"
+                            if (deptIsPrimary && deptGenCount > 0) {
+                                updateCheckFlag(patMedInhosp1, 1, "1", "绉戝棣栬瑙勫垯鐢熸垚鎴愬姛");
+                            }
+                            if (!active.equals("xh")) {
+                                if (wardIsPrimary && wardGenCount > 0) {
+                                    updateCheckFlag(patMedInhosp1, 2, "1", "鐥呭尯棣栬瑙勫垯鐢熸垚鎴愬姛");
+                                }
+                                if (diagIsPrimary && diagGenCount > 0) {
+                                    updateCheckFlag(patMedInhosp1, 3, "1", "鐤剧梾棣栬瑙勫垯鐢熸垚鎴愬姛");
+                                }
+                            }
+                            // 鈥斺�� 瀵逛簬=1浣嗙敓鎴愬け璐ョ殑锛屽皢鍏跺搴攆lag璁句负"2"
+                            if (deptIsPrimary && deptGenCount == 0) {
+                                updateCheckFlag(patMedInhosp1, 1, "2", "绉戝棣栬瑙勫垯鐢熸垚澶辫触");
+                            }
+                            if (!active.equals("xh")) {
+                                if (wardIsPrimary && wardGenCount == 0) {
+                                    updateCheckFlag(patMedInhosp1, 2, "2", "鐥呭尯棣栬瑙勫垯鐢熸垚澶辫触");
+                                }
+                                if (diagIsPrimary && diagGenCount == 0) {
+                                    updateCheckFlag(patMedInhosp1, 3, "2", "鐤剧梾棣栬瑙勫垯鐢熸垚澶辫触");
+                                }
+                            }
+                        } else {
+                            // 鎵�鏈夐瑕佽鍒欏叏閮ㄥけ璐ワ紝灏�=1鐨刦lag璁句负"2"锛岀劧鍚庢墽琛�=2鐨勬柟娉�
+                            log.info("銆愬熀浜庤鍒欍�戦瑕佽鍒欏叏閮ㄥけ璐ワ紝灏�=1鐨刦lag璁句负2锛屽紑濮嬫墽琛屾瑕佽鍒�");
+                            if (deptIsPrimary) {
+                                updateCheckFlag(patMedInhosp1, 1, "2", "绉戝棣栬瑙勫垯鍏ㄩ儴澶辫触");
+                            }
+                            if (!active.equals("xh")) {
+                                if (wardIsPrimary) {
+                                    updateCheckFlag(patMedInhosp1, 2, "2", "鐥呭尯棣栬瑙勫垯鍏ㄩ儴澶辫触");
+                                }
+                                if (diagIsPrimary) {
+                                    updateCheckFlag(patMedInhosp1, 3, "2", "鐤剧梾棣栬瑙勫垯鍏ㄩ儴澶辫触");
+                                }
+                            }
+                            // 鎵ц娆¤瑙勫垯(=2)鐨勬柟娉�
+                            if (deptIsSecondary) {
                                 log.info("銆愬熀浜庤鍒欍�戞墽琛岀瀹ゆ瑕佽鍒�");
                                 addDeptSubTaskForPatient(patMedInhosp1, patArchive, config);
                             }
 
                             if (!active.equals("xh")) {
-                                if (!"1".equals(rule.getWradRule()) && StringUtils.isNotEmpty(rule.getWradRule())) {
+                                if (wardIsSecondary) {
                                     log.info("銆愬熀浜庤鍒欍�戞墽琛岀梾鍖烘瑕佽鍒�");
                                     addWardSubTaskForPatient(patMedInhosp1, patArchive, config);
                                 }
 
-                                if (!"1".equals(rule.getDiagRule()) && StringUtils.isNotEmpty(rule.getDiagRule())) {
+                                if (diagIsSecondary) {
                                     log.info("銆愬熀浜庤鍒欍�戞墽琛岀柧鐥呮瑕佽鍒�");
                                     addIcd10SubTaskForPatient(patMedInhosp1, patArchive, config);
                                 }
@@ -1606,6 +1701,8 @@
             if (StringUtils.isNotEmpty(errorreason)) {
                 PatMedInhosp patMedInhosp = patMedInhospMapper.selectPatMedInhospByInhospid(patMedInhosp1.getInhospid());
                 patMedInhosp1.setWardcheckFlag("2");
+                patMedInhosp1.setDeptcheckFlag(patMedInhosp.getDeptcheckFlag());
+                patMedInhosp1.setDiagcheckFlag(patMedInhosp.getDiagcheckFlag());
                 patMedInhosp1.setLongTaskReason(StringUtils.isNotEmpty(patMedInhosp.getLongTaskReason()) ? patMedInhosp.getLongTaskReason() + errorreason : errorreason);
                 patMedInhospMapper.updatePatMedInhosp(patMedInhosp1);
             } else {
@@ -1656,9 +1753,9 @@
 
             if (CollectionUtils.isEmpty(serviceTaskdiags)) {
                 PatMedInhosp patMedInhosp = patMedInhospMapper.selectPatMedInhospByInhospid(patMedInhosp1.getInhospid());
-                patMedInhosp1.setDiagcheckFlag("2");
-                patMedInhosp1.setLongTaskReason("璇ユ偅鑰呮墍鎮g柧鐥呮湭閰嶇疆闀挎湡浠诲姟;");
-                patMedInhospMapper.updatePatMedInhosp(patMedInhosp1);
+                patMedInhosp.setDiagcheckFlag("2");
+                patMedInhosp.setLongTaskReason("璇ユ偅鑰呮墍鎮g柧鐥呮湭閰嶇疆闀挎湡浠诲姟;");
+                patMedInhospMapper.updatePatMedInhosp(patMedInhosp);
             } else {
                 int flag = 0;
                 for (ServiceTaskdiag serviceTaskdiag1 : serviceTaskdiags) {
@@ -1675,9 +1772,9 @@
                 if (flag == 0) {
                     log.error("璇ョ瀹ゆ垨鐥呭尯瀵逛簬鎮h�呮墍鎮g柧鐥呮湭閰嶇疆闀挎湡浠诲姟,鎮h�咃細{}", patMedInhosp1.getInhospid());
                     PatMedInhosp patMedInhosp = patMedInhospMapper.selectPatMedInhospByInhospid(patMedInhosp1.getInhospid());
-                    patMedInhosp1.setDiagcheckFlag("2");
-                    patMedInhosp1.setLongTaskReason("璇ョ瀹ゆ垨鐥呭尯瀵逛簬鎮h�呮墍鎮g柧鐥呮湭閰嶇疆闀挎湡浠诲姟;");
-                    patMedInhospMapper.updatePatMedInhosp(patMedInhosp1);
+                    patMedInhosp.setDiagcheckFlag("2");
+                    patMedInhosp.setLongTaskReason("璇ョ瀹ゆ垨鐥呭尯瀵逛簬鎮h�呮墍鎮g柧鐥呮湭閰嶇疆闀挎湡浠诲姟;");
+                    patMedInhospMapper.updatePatMedInhosp(patMedInhosp);
                 }
             }
         } catch (Exception e) {

--
Gitblit v1.9.3