赵文轩
2024-06-13 04bb7fde019613c8795399c67455677e5436349c
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
package com.ltkj.web.controller.his;
 
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.utils.SecurityUtils;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.hisDto.*;
import com.ltkj.hosp.service.*;
import com.ltkj.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/* @Authot:zjh
 * @Date:  2024-05-30
 * */
 
@Component
public class HisApiMethod {
    @Autowired
    private HisApiMethodService controller;
    @Resource
    private ITjOrderService orderService;
    @Autowired
    private ITjCustomerService customerService;
    @Resource
    private ITjOrderDetailService detailService;
    @Resource
    private ITjProjectService projectService;
    @Resource
    private ITbTransitionService tbTransitionService;
    @Autowired
    private HisApiConfigService hisApiConfigService;
    @Autowired
    private HisApiGetMethodService hisApiGetMethodService;
    @Resource
    private ISysConfigService configService;
 
    //将方法返回值解析成json格式
    public JSONObject getJSONObject(String builder) {
        String Response = JSONUtil.parseObj(builder).getStr("Response");
        return JSONUtil.parseObj(Response);
    }
 
    //获取方法返回值信息
    public String getAjaxResult(AjaxResult result) {
        return result.get("data").toString();
    }
 
    //对接his总接口  注册挂号接诊申请单操作
    @Transactional
    public AjaxResult HisApiMethods(TjCustomer customer, Long orderId) {
 
        Date dates = new Date();
        final String date = DateUtil.format(dates, "yyyy-MM-dd HH:mm:ss");
        AjaxResult result = controller.Outpincreateapply(customer);
        String result1 = getAjaxResult(result);
        JSONObject object = getJSONObject(result1);
        String code = object.getStr("ResultCode");
        if (code.equals("0")) {
            JSONArray resultDatass = object.getJSONArray("ResultData");
            Map<String, Object> resultData = (Map<String, Object>) resultDatass.get(0);
            if (null != resultData && resultData.size() > 0) {
                String pationid = resultData.get("PationId").toString();
                if (null != pationid) {
                    customer.setPationId(pationid);
                    customerService.updateById(customer);
                    /*                  String key = configService.selectConfigByKey("getInfoFromSqlData");
                    if (null != key && key.equals("Y")) {
                        OutpinregapplyDto outpinregapplyDto = new OutpinregapplyDto();
                        outpinregapplyDto.setPationid(pationid);
                        outpinregapplyDto.setSqysbm(SecurityUtils.getUsername());
                        outpinregapplyDto.setMzksbm("0101");
                        outpinregapplyDto.setCzybm("00029");
                        outpinregapplyDto.setSfjz("0");
                        outpinregapplyDto.setGhzlbm("01");
                        outpinregapplyDto.setYwckbm("0001");
                        outpinregapplyDto.setSflstd("0");
                        outpinregapplyDto.setGhrq(date);
                        //门诊挂号
                        AjaxResult ajaxResult = controller.Outpinregapply(outpinregapplyDto);
                        String result2 = getAjaxResult(ajaxResult);
                        JSONObject object1 = getJSONObject(result2);
                        String code1 = object1.getStr("ResultCode");
                        if (code1.equals("0")) {
                            JSONArray resultDatas = object1.getJSONArray("ResultData");
                            if (null != resultDatas && resultDatas.size() > 0) {
                                //门诊医生接诊
                                controller.Outpinconapply(customer.getCardId(), date, SecurityUtils.getUsername());
                            }
                        }
                    }
*/
 
                    //检验申请
                    OutpintestapplyDto dto = new OutpintestapplyDto();
                    dto.setHisRegistrationId(customer.getCardId());
                    dto.setSfjz(customer.getCusIdcard());
                    dto.setSqysbm(SecurityUtils.getUsername());
                    dto.setMzksbm("0101");
                    dto.setSjrq(date);
                    dto.setCzybm("00029");
                    dto.setCzyksbm("0101");
                    dto.setSfjz("1");
                    List<TbTransition> detailList = tbTransitionService.getTbTransitionListByCusId(customer.getCusIdcard(), customer.getCardId());
                    List<OutpintestapplyDetailsDto> detailsDtos = new ArrayList<>();
                    if (null != detailList && detailList.size() > 0) {
                        LambdaQueryWrapper<TjProject> wq = new LambdaQueryWrapper<>();
                        wq.in(TjProject::getProId, detailList.stream().map(TbTransition::getParentProId).collect(Collectors.toList()));
                        wq.groupBy(TjProject::getHisXmbm);
                        wq.in(TjProject::getDeptId, "241","317");
                        List<TjProject> projects = projectService.list(wq);
                        if (null != projects && projects.size() > 0) {
                            for (TjProject project : projects) {
                                if (0 == project.getProParentId() && project.getProPrice().compareTo(BigDecimal.ZERO) != 0) {
                                    if (null != project.getHisXmbm()) {
                                        OutpintestapplyDetailsDto detailsDto = new OutpintestapplyDetailsDto();
                                        detailsDto.setMxfyxmbm(project.getHisXmbm());
                                        if(project.getSfzhfy().equals("Y")){
                                        detailsDto.setSfzhfy("1");
                                        }else {
                                            detailsDto.setSfzhfy("0");
                                        }
                                        detailsDto.setSl(1);
                                        detailsDtos.add(detailsDto);
                                    }
                                }
                            }
                        }
                    }
                    if (detailsDtos.size()==0) {
                        OutpintestapplyDetailsDto detailsDto = new OutpintestapplyDetailsDto();
                        detailsDto.setMxfyxmbm("");
                        detailsDto.setSfzhfy("");
                        detailsDto.setSl(0);
                        detailsDtos.add(detailsDto);
                    }
                    dto.setDetails(detailsDtos);
                    AjaxResult ajaxResult1 = controller.Outpintestapply(dto);
                    String result5 = getAjaxResult(ajaxResult1);
                    JSONObject object3 = getJSONObject(result5);
                    String code3 = object3.getStr("ResultCode");
                    if (code3.equals("0")) {
                        Map<String, Object> datas = object3.getJSONObject("ResultData");
                        datas.put("cardId", customer.getCardId());
                        JSONObject object4 = JSONUtil.parseObj(datas);
                        LambdaQueryWrapper<HisApiConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>();
                        lambdaQueryWrapper.eq(HisApiConfig::getApiMethod, "Outpintestapply");
                        HisApiConfig hisApiConfig = hisApiConfigService.getOne(lambdaQueryWrapper);
                        hisApiGetMethodService.save(object4, "Outpintestapply", hisApiConfig,JSONUtil.toJsonStr(BeanUtil.beanToMap(dto)));
 
                    }else {
                        return AjaxResult.success();
                    }
                    //门诊检查申请
                    OutpinexamapplyDto outpinexamapplyDto = new OutpinexamapplyDto();
                    outpinexamapplyDto.setHisRegistrationId(customer.getCardId());
                    outpinexamapplyDto.setSfzh(customer.getCusIdcard());
                    outpinexamapplyDto.setSqysbm(SecurityUtils.getUsername());
                    outpinexamapplyDto.setMzksbm("0101");
                    outpinexamapplyDto.setCzybm("00029");
                    outpinexamapplyDto.setCzyksbm("0101");
                    List<TbTransition> detailLists = tbTransitionService.getTbTransitionListByCusId(customer.getCusIdcard(), customer.getCardId());
                    List<OutpintestapplyDetailsDto> detailsDtoss = new ArrayList<>();
                    if (null != detailLists && detailLists.size() > 0) {
                        LambdaQueryWrapper<TjProject> wq = new LambdaQueryWrapper<>();
                        wq.in(TjProject::getProId, detailLists.stream().map(TbTransition::getParentProId).collect(Collectors.toList()));
                        wq.groupBy(TjProject::getHisXmbm);
                        wq.in(TjProject::getDeptId, "247", "248", "249", "250", "251", "252", "271", "273", "274", "275","298");
                        List<TjProject> projects = projectService.list(wq);
                        if (null != projects && projects.size() > 0) {
                            for (TjProject project : projects) {
                                if (0 == project.getProParentId() && project.getProPrice().compareTo(BigDecimal.ZERO) != 0) {
                                    if (null != project.getHisXmbm()) {
                                        OutpintestapplyDetailsDto detailsDto = new OutpintestapplyDetailsDto();
                                        detailsDto.setMxfyxmbm(project.getHisXmbm());
                                        if(project.getSfzhfy().equals("Y")){
                                        detailsDto.setSfzhfy("1");
                                        }else {
                                            detailsDto.setSfzhfy("0");
                                        }
                                        detailsDto.setSl(1);
                                        detailsDtoss.add(detailsDto);
                                    }
 
                                }
                            }
                        }
                    }
                    if (detailsDtoss.size()==0) {
                        OutpintestapplyDetailsDto detailsDto = new OutpintestapplyDetailsDto();
                        detailsDto.setMxfyxmbm("");
                        detailsDto.setSfzhfy("");
                        detailsDto.setSl(0);
                        detailsDtoss.add(detailsDto);
                    }
                    outpinexamapplyDto.setDetails(detailsDtoss);
                    AjaxResult ajaxResult2 = controller.Outpinexamapply(outpinexamapplyDto);
                    String result6 = getAjaxResult(ajaxResult2);
                    JSONObject object5 = getJSONObject(result6);
                    String code4 = object5.getStr("ResultCode");
                    if (code4.equals("0")) {
                        Map<String, Object> map = object5.getJSONObject("ResultData");
                        map.put("cardId", customer.getCardId());
                        JSONObject jsonObject = JSONUtil.parseObj(map);
                        LambdaQueryWrapper<HisApiConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>();
                        lambdaQueryWrapper.eq(HisApiConfig::getApiMethod, "Outpinexamapply");
                        HisApiConfig hisApiConfig = hisApiConfigService.getOne(lambdaQueryWrapper);
                        hisApiGetMethodService.save(jsonObject, "Outpinexamapply", hisApiConfig,JSONUtil.toJsonStr(BeanUtil.beanToMap(outpinexamapplyDto)));
 
                    }else {
                        return AjaxResult.success();
                    }
 
                    //门诊治疗处置申请
                    OutpintreatapplyDto dao = new OutpintreatapplyDto();
                    dao.setHisRegistrationId(customer.getCardId());
                    dao.setSfzh(customer.getCusIdcard());
                    dao.setSqysbm(SecurityUtils.getUsername());
                    dao.setMzksbm("0101");
                    dao.setSjrq(date);
                    dao.setCzybm("00029");
                    dao.setCzyksbm("0101");
                    List<TbTransition> details = tbTransitionService.getTbTransitionListByCusId(customer.getCusIdcard(), customer.getCardId());
                    List<OutpintestapplyDetailsDto> detailDtos = new ArrayList<>();
                    if (null != details && details.size() > 0) {
                        LambdaQueryWrapper<TjProject> wq = new LambdaQueryWrapper<>();
                        wq.in(TjProject::getProId, details.stream().map(TbTransition::getParentProId).collect(Collectors.toList()));
                        wq.groupBy(TjProject::getHisXmbm);
                        wq.in(TjProject::getDeptId, "100", "240", "253", "254", "255", "257", "258", "259", "269", "270");
                        List<TjProject> projects = projectService.list(wq);
                        if (null != projects && projects.size() > 0) {
                            for (TjProject project : projects) {
                                if (0 == project.getProParentId() && project.getProPrice().compareTo(BigDecimal.ZERO) != 0) {
                                    if (null != project.getHisXmbm()) {
                                        OutpintestapplyDetailsDto detailsDto = new OutpintestapplyDetailsDto();
                                        detailsDto.setMxfyxmbm(project.getHisXmbm());
                                        if (project.getSfzhfy().equals("Y")) {
                                            detailsDto.setSfzhfy("1");
                                        } else {
                                            detailsDto.setSfzhfy("0");
                                        }
                                        detailsDto.setSl(1);
                                        detailDtos.add(detailsDto);
                                    }
                                }
                            }
                        }
                    }
                    if (detailDtos.size()==0) {
                        OutpintestapplyDetailsDto detailsDto = new OutpintestapplyDetailsDto();
                        detailsDto.setMxfyxmbm("");
                        detailsDto.setSfzhfy("");
                        detailsDto.setSl(0);
                        detailDtos.add(detailsDto);
                    }
                    dao.setDetails(detailDtos);
                    AjaxResult mzylyzsq1 = controller.Outpintreatapply(dao);
                    String mzylyzsq2 = getAjaxResult(mzylyzsq1);
                    JSONObject mzylyzsq3 = getJSONObject(mzylyzsq2);
                    String code5 = mzylyzsq3.getStr("ResultCode");
                    if (code5.equals("0")) {
                        Map<String, Object> map = mzylyzsq3.getJSONObject("ResultData");
                        map.put("cardId", customer.getCardId());
                        JSONObject jsonObject = JSONUtil.parseObj(map);
                        LambdaQueryWrapper<HisApiConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>();
                        lambdaQueryWrapper.eq(HisApiConfig::getApiMethod, "Outpintreatapply");
                        HisApiConfig hisApiConfig = hisApiConfigService.getOne(lambdaQueryWrapper);
                        hisApiGetMethodService.save(jsonObject, "Outpintreatapply", hisApiConfig,JSONUtil.toJsonStr(BeanUtil.beanToMap(dao)));
                    }else {
                        return AjaxResult.error();
                    }
                    return AjaxResult.success();
                }
            }
        }
        return AjaxResult.error();
    }
 
 
    //退费后取消接诊作废申请单等操作
    @Transactional
    public boolean ZfHisApiMethods(TjCustomer customer, TjOrder order) {
        Date dates = new Date();
        final String date = DateUtil.format(dates, "yyyy-MM-dd HH:mm:ss");
 
        String jcsqdh = orderService.getHuoQuJcsqdh(order.getCardId());
 
        String jysqdh = orderService.getHuoQuJysqdh(order.getCardId());
 
 
        String zlsqdh = orderService.getHuoQuZlsqdh(order.getCardId());
 
        //2.1.6.5 作废门诊检查申请
        if (null !=jcsqdh){
            AjaxResult result = controller.Outpindelexamapply(order.getCardId(), "00029", jcsqdh);
            String result1 = getAjaxResult(result);
            JSONObject object = getJSONObject(result1);
            String code = object.getStr("ResultCode");
            if (code.equals("0")) {
                orderService.delHuoQuJcsqdh(order.getCardId());
            }else {
                return false;
            }
        }
 
 
        //2.1.6.3 作废门诊检验申请
 
        AjaxResult ajaxResult =null;
        String result2 =null;
        JSONObject object1 =null;
        String code1 =null;
 
        if(null !=jysqdh){
             ajaxResult = controller.Outpindeltestapply(order.getCardId(), "00029", jysqdh);
             result2 = getAjaxResult(ajaxResult);
             object1 = getJSONObject(result2);
             code1 = object1.getStr("ResultCode");
            if (code1.equals("0")) {
                orderService.delHuoQuJysqdh(order.getCardId());
            }else {
                return false;
            }
        }
 
        //2.1.6.9 作废门诊治疗处置申请
        if(null !=zlsqdh){
            ajaxResult = controller.Outpintdelreatapply(order.getCardId(), "00029", zlsqdh);
            result2 = getAjaxResult(ajaxResult);
            object1 = getJSONObject(result2);
            code1 = object1.getStr("ResultCode");
            if (!code1.equals("0")){
                return false;
            }
        }
        //2.1.3 门诊医生取消接诊
        ajaxResult = controller.Outpinunconapply(order.getCardId(), date, "00029");
        result2 = getAjaxResult(ajaxResult);
        object1 = getJSONObject(result2);
        code1 = object1.getStr("ResultCode");
        if (!code1.equals("0")){
            return false;
        }
        return true;
    }
 
 
    //获取门诊结算记录
    @Transactional
    public void getHisMzJsJl(TjOrder order) {
        Date dates = new Date();
        final String date = DateUtil.format(dates, "yyyy-MM-dd HH:mm:ss");
 
    }
 
}