陈昶聿
2 天以前 d9281d43e27ab6c510d390ddb26eaffc8ccc1add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package com.smartor.service;
 
import com.ruoyi.patarchive.domain.PatSpecificArchiveGenerateConfig;
import com.ruoyi.task.domain.ServiceSubtask;
import com.smartor.service.impl.PatSpecificArchiveGenerateServiceImpl;
 
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
 
/**
 * 住院随访生成专科档案逻辑自检(纯 main,不依赖 JUnit / Spring / 数据库)。
 *
 * <p>覆盖:住院随访范围判断、科室/病区/诊断配置匹配、JSON/逗号配置解析、Mapper XML 可解析性。</p>
 */
public final class InhospFollowupArchiveLogicCheck {
 
    private static int passed = 0;
    private static int failed = 0;
 
    private static void check(String key, Object expected, Object actual) {
        boolean ok = expected == null ? actual == null : expected.equals(actual);
        if (ok) {
            passed++;
            System.out.println("  [OK]   " + key + " = " + actual);
        } else {
            failed++;
            System.out.println("  [FAIL] " + key + " 期望=" + expected + " 实际=" + actual);
        }
    }
 
    private static void setField(Object target, String name, Object value) throws Exception {
        Field field = target.getClass().getDeclaredField(name);
        field.setAccessible(true);
        field.set(target, value);
    }
 
    private static ServiceSubtask subtask(String hospType, String serviceType) {
        ServiceSubtask subtask = new ServiceSubtask();
        subtask.setId(1001L);
        subtask.setHospType(hospType);
        subtask.setServiceType(serviceType);
        return subtask;
    }
 
    private static PatSpecificArchiveGenerateConfig config(String deptType, String archiveType,
                                                           String deptCodes, String icd10Codes) {
        PatSpecificArchiveGenerateConfig config = new PatSpecificArchiveGenerateConfig();
        config.setId(1L);
        config.setDeptType(deptType);
        config.setDeptCategory("2");
        config.setArchiveType(archiveType);
        config.setDeptCodes(deptCodes);
        config.setIcd10Codes(icd10Codes);
        return config;
    }
 
    public static void main(String[] args) throws Exception {
        System.out.println("========== 住院随访生成专科档案逻辑自检 ==========");
 
        PatSpecificArchiveGenerateServiceImpl service = new PatSpecificArchiveGenerateServiceImpl();
        setField(service, "inhospFollowupServiceTypes", "2,13,18,19");
 
        Method isInhosp = PatSpecificArchiveGenerateServiceImpl.class
                .getDeclaredMethod("isInhospFollowup", ServiceSubtask.class);
        isInhosp.setAccessible(true);
 
        System.out.println("-- 1) 住院随访范围 --");
        check("出院随访 serviceType=2", true, isInhosp.invoke(service, subtask("2", "2")));
        check("入院随访 serviceType=18", true, isInhosp.invoke(service, subtask("6", "18")));
        check("门诊任务 hospType=1", false, isInhosp.invoke(service, subtask("1", "3")));
        check("宣教任务 serviceType=4", false, isInhosp.invoke(service, subtask("2", "4")));
        check("serviceType 为空", false, isInhosp.invoke(service, subtask("2", null)));
 
        Method match = PatSpecificArchiveGenerateServiceImpl.class.getDeclaredMethod(
                "matchConfig", PatSpecificArchiveGenerateConfig.class,
                String.class, String.class, String.class, String.class);
        match.setAccessible(true);
 
        System.out.println("-- 2) 科室匹配 --");
        PatSpecificArchiveGenerateConfig deptConfig = config("1", "1", "[\"D001\"]", null);
        check("科室 D001 命中", true, match.invoke(service, deptConfig, "D001", null, null, null));
        check("科室 D002 不命中", false, match.invoke(service, deptConfig, "D002", null, null, null));
 
        System.out.println("-- 3) 病区匹配 --");
        PatSpecificArchiveGenerateConfig wardConfig = config("2", "3", "[\"W001\"]", null);
        check("病区 W001 命中", true, match.invoke(service, wardConfig, "D001", "W001", null, null));
        check("科室 D001 对病区配置不命中", false,
                match.invoke(service, wardConfig, "D001", "D001", null, null));
 
        System.out.println("-- 4) 诊断匹配 --");
        PatSpecificArchiveGenerateConfig diagConfig = config("1", "1", null, "[\"E46.x00x003\"]");
        check("诊断码命中", true, match.invoke(service, diagConfig, "D001", null, "E46.x00x003", "营养不良"));
        check("无诊断码时按诊断名称兜底", true,
                match.invoke(service, diagConfig, "D001", null, null, "E46.x00x003"));
        check("诊断不命中", false, match.invoke(service, diagConfig, "D001", null, "R00", "其他"));
 
        System.out.println("-- 5) 配置为空 / 非法 JSON --");
        PatSpecificArchiveGenerateConfig emptyConfig = config("1", "1", null, null);
        check("科室和诊断都为空", false, match.invoke(service, emptyConfig, "D001", null, null, null));
        PatSpecificArchiveGenerateConfig commaConfig = config("1", "1", "D001,D002", null);
        check("逗号分隔配置兜底", true, match.invoke(service, commaConfig, "D002", null, null, null));
 
        System.out.println("-- 6) Mapper XML 可解析性 --");
        String[] xmlFiles = new String[]{
                "smartor/src/main/resources/mapper/smartor/PatMaternityArchiveMapper.xml",
                "smartor/src/main/resources/mapper/smartor/PatChildArchiveMapper.xml",
                "smartor/src/main/resources/mapper/smartor/PatMaternityArchiveDetailMapper.xml",
                "smartor/src/main/resources/mapper/smartor/PatChildArchiveDetailMapper.xml",
                "smartor/src/main/resources/mapper/smartor/PatSpecificArchiveGenerateLogMapper.xml",
                "ruoyi-task/src/main/resources/mapper/task/ServiceSubtaskMapper.xml"
        };
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        for (String xmlFile : xmlFiles) {
            try {
                factory.newDocumentBuilder().parse(new File(xmlFile));
                check(xmlFile, "OK", "OK");
            } catch (Exception e) {
                check(xmlFile, "OK", e.getClass().getSimpleName() + ":" + e.getMessage());
            }
        }
 
        System.out.println("========== 结果:PASS=" + passed + ",FAIL=" + failed + " ==========");
        if (failed > 0) {
            System.exit(1);
        }
    }
}