zhaowenxuan
2024-12-02 b98bda282397df60077efbe4c1ad35a44bdfffb9
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package com.ltkj.web.controller.pacs;
 
import cn.hutool.core.util.XmlUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ltkj.common.core.domain.entity.SysDept;
import com.ltkj.hosp.domain.TbTransition;
import com.ltkj.hosp.domain.TjCustomer;
import com.ltkj.hosp.domain.TjOrder;
import com.ltkj.hosp.domain.TjProject;
import com.ltkj.hosp.service.*;
import com.ltkj.hosp.sqlDomain.LtkjExamJcbgd;
import com.ltkj.hosp.sqlDomain.LtkjExamJcsqd;
import com.ltkj.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @Company: 西安路泰科技有限公司
 * @Author: zhaowenxuan
 * @Date: 2024/12/2 14:36
 */
@RestController
@RequestMapping("/pacs/InvokeRisService")
public class PacsServiceController {
 
    @Autowired
    private ISysDeptService deptService;
    @Autowired
    private ITjProjectService projectService;
    @Autowired
    private ITbTransitionService transitionService;
    @Autowired
    private ITjCustomerService customerService;
    @Autowired
    private ITjOrderService tjOrderService;
    @Autowired
    private LtkjExamJcsqdService ltkjExamJcsqdService;
    @Autowired
    private LtkjExamJcbgdService ltkjExamJcbgdService;
 
    @PostMapping("QueryOrder")
    public String queryOrder(@RequestBody String json){
        Map<String, Object> map = XmlUtil.xmlToMap(json);
        JSONObject parseObj = JSONUtil.parseObj(map);
        String hospitalID = parseObj.getStr("HospitalID");
        // 必填 查询ID,根据IDType给
        String queryID = parseObj.getStr("QueryID");
        // 必填 ID类别 1病人id,2申请单号,根据业务情况可以扩展其他类型。
        String idType = parseObj.getStr("IDType");
        // 非必填 病人类型O:门诊,I:住院,P:体检
        String patType = parseObj.getStr("PatType");
        // 非必填 检查类别:US(超声)、ES(内镜)、CT、CR、DX等
        String modality = parseObj.getStr("Modality");
        // 必填 申请单状态:1已登记,0 未登记,2.全部
        String orderSatus = parseObj.getStr("OrderSatus");
        TjCustomer customer = null;
        switch (idType){
            case "1":
                customer = customerService.getById(queryID);
        }
        HashMap<String, Object> hashMap = new HashMap<>();
        if (customer == null){
            HashMap<String, Object> result = new HashMap<>();
            result.put("Code",500);
            result.put("Message","未查询到人员信息");
            hashMap.put("ResultInfor",result);
            return XmlUtil.mapToXmlStr(hashMap);
        }
        List<TjOrder> list = tjOrderService.list(new LambdaQueryWrapper<TjOrder>().eq(TjOrder::getUserId, customer.getCusId()).orderByDesc(TjOrder::getCreateTime));
        if (list.isEmpty()){
            HashMap<String, Object> result = new HashMap<>();
            result.put("Code",500);
            result.put("Message","未查询到记录信息");
            hashMap.put("ResultInfor",result);
            return XmlUtil.mapToXmlStr(hashMap);
        }
        TjOrder tjOrder = list.get(0);
        List<TbTransition> detailList = transitionService.getTbTransitionListByCusId(customer.getCusIdcard(), tjOrder.getCardId());
        LambdaQueryWrapper<TjProject> wq = new LambdaQueryWrapper<>();
        wq.in(TjProject::getProId, detailList.stream().map(TbTransition::getParentProId).collect(Collectors.toList()));
        wq.in(TjProject::getDeptId, deptService.getJcDeptIds());
        List<TjProject> projects = projectService.list(wq);
 
 
        HashMap<String, Object> patientInfo = new HashMap<>();
        patientInfo.put("PatientId",customer.getCusId());
        patientInfo.put("VisitNo",tjOrder.getTjNumber());
        patientInfo.put("PatType","P");
        patientInfo.put("PatientName",customer.getCusName());
        if (customer.getCusSex() == 0) patientInfo.put("PatientSex","M");
        else if (customer.getCusSex() == 1) patientInfo.put("PatientSex","F");
        else patientInfo.put("PatientSex","O");
        patientInfo.put("PatBirthday",customer.getCusBrithday());
        patientInfo.put("IdCard",customer.getCusIdcard());
 
//        ArrayList<HashMap<String, Object>> examItems = new ArrayList<>();
        String examItems = "";
        for (TjProject project : projects) {
            HashMap<String, Object> examItem = new HashMap<>();
            examItem.put("HisID", tjOrder.getTjNumber() + String.valueOf(project.getProId()).substring(String.valueOf(project.getProId()).length() - 4));
            examItem.put("EmergencyFlag", "0");
            examItem.put("ExamItemID", project.getHisXmbm());
            examItem.put("ExamItemName", project.getHisXmmc());
            examItem.put("OrderDT", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tjOrder.getCreateTime()));
            SysDept dept = deptService.getById(project.getDeptId());
            examItem.put("Modality", dept.getModality());
            examItems += "<ExamItem>"+
                    XmlUtil.mapToXmlStr(examItem)
                            .replaceAll("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>","")
                            .replaceAll("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>","")
                            .replaceAll("<xml>","")
                            .replaceAll("</xml>","")
                    +"</ExamItem>";
        }
        hashMap.put("ExamItemList", examItems);
        hashMap.put("PatientInfor",patientInfo);
        HashMap<String, Object> result = new HashMap<>();
        result.put("Code",1);
        result.put("Message","查询成功");
        hashMap.put("ResultInfor",result);
        return XmlUtil.mapToXmlStr(hashMap)
                .replaceAll("&lt;","<").replaceAll("&gt;",">");
    }
 
    @PostMapping("ReportVerifyUpload")
    public String reportVerifyUpload(@RequestBody String json){
        Map<String, Object> map = XmlUtil.xmlToMap(json);
        HashMap<String, Object> reportInfor = (HashMap<String, Object>) map.get("ReportInfor");
        // cus_id
        String patientId = reportInfor.get("PatientId").toString();
        String reportID = reportInfor.get("ReportID").toString();
        // 报告医生
        String reportDR = reportInfor.get("ReportDR").toString();
        // 报告医生id
        String reportDRCode = reportInfor.get("ReportDRCode").toString();
        // 报告时间
        String reportDT = reportInfor.get("ReportDT").toString();
        // 审核医师
        String verifyDR = reportInfor.get("VerifyDR").toString();
        // 审核医师编号
        String verifyDRCode = reportInfor.get("VerifyDRCode").toString();
        // 审核时间
        String verifyDT = reportInfor.get("VerifyDT").toString();
        // 检查所见
        String studyResult = reportInfor.get("StudyResult").toString();
        // 诊断结果
        String diagResult = reportInfor.get("DiagResult").toString();
        // 如果返回格式为
//        <ApplyInfos>
//          <HisID>HIS或体检申请单号</HisID>
//          <HisID>HIS或体检申请单号</HisID>
//          <HisID>HIS或体检申请单号</HisID>
//      </ApplyInfos>
        HashMap<String, Object> hashMap = (HashMap<String, Object>) map.get("ApplyInfos");
        ArrayList<String> strings = (ArrayList<String>) hashMap.get("HisID");
        for (String s : strings) {
            LtkjExamJcsqd jcsqd = ltkjExamJcsqdService.getOne(new LambdaQueryWrapper<LtkjExamJcsqd>().eq(LtkjExamJcsqd::getTmh, s));
            LtkjExamJcbgd jcbgd = new LtkjExamJcbgd();
            jcbgd.setTjh(jcsqd.getTjh());
            jcbgd.setTmh(s);
            jcbgd.setXmdm(jcsqd.getJcxmid());
            jcbgd.setXmmc(jcsqd.getJcxmmc());
            jcbgd.setBgNr(diagResult);
            jcbgd.setShysxm(verifyDR);
            jcbgd.setShysdm(verifyDRCode);
            jcbgd.setYxzd(studyResult);
            jcbgd.setYxbx(diagResult);
            jcbgd.setZdsj(reportDT);
            jcbgd.setSqsj(jcsqd.getSqsj());
            jcbgd.setJcbw(jcsqd.getJcxmmc());
            ltkjExamJcbgdService.save(jcbgd);
            jcsqd.setBgys(reportDR);
            jcsqd.setBgysid(reportDRCode);
            jcsqd.setJgsj(reportDT);
            jcsqd.setBw(jcsqd.getJcxmmc());
            jcsqd.setJgzt(studyResult);
            jcsqd.setJgbx(diagResult);
            ltkjExamJcsqdService.updateById(jcsqd);
        }
        HashMap<String, Object> result = new HashMap<>();
        result.put("Code",1);
        result.put("Message","查询成功");
        return XmlUtil.mapToXmlStr(hashMap)
                .replaceAll("&lt;","<").replaceAll("&gt;",">");
    }
}