陈昶聿
2 天以前 c4dc6a5d66524d08b768046d9d2d5974bf96f45c
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
package com.smartor.service.impl;
 
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DtoConversionUtils;
import com.ruoyi.outpatientvisit.api.OuthospDataFacade;
import com.ruoyi.outpatientvisit.domain.PatMedOuthosp;
import com.ruoyi.patarchive.mapper.PatArchiveMapper;
import com.smartor.service.IPatMedOuthospService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.*;
import java.util.stream.Collectors;
import com.ruoyi.common.core.domain.entity.PatArchive;
import com.ruoyi.task.domain.entity.ServiceSubtaskEntity;
import com.ruoyi.task.domain.ServiceSubtask;
import com.ruoyi.task.domain.ServiceTask;
import com.ruoyi.task.domain.ServiceTaskdept;
import com.ruoyi.task.mapper.ServiceSubtaskMapper;
import com.ruoyi.task.mapper.ServiceTaskdeptMapper;
import com.ruoyi.task.mapper.ServiceTaskdiagMapper;
import com.ruoyi.task.mapper.ServiceTaskMapper;
 
/**
 * {@link IPatMedOuthospService} 的<b>委托实现</b> —— 门急诊随访模块化的过渡件。
 *
 * <h3>它做两件事</h3>
 * <ol>
 *   <li><b>已迁的 4 个方法 → 委托模块</b>:
 *       {@code insert} / {@code update} / {@code selectExistingSerialnums} / {@code dealOutpatientInfo}
 *       转发到 {@link OuthospDataFacade}(SQL 唯一收敛在模块里);</li>
 *   <li><b>未迁的 3 个方法 → 保留原生</b>:{@code dealPatMedOuthosp} /
 *       {@code followUpByPatMedOuthosp} / {@code followUpAgainByPatMedOuthosp}
 *       及它们的私有依赖({@code addDays} / {@code writeInSubTask} / {@code boxedServiceSubtask})。
 *       这条是"<b>单患者按需随访</b>"链路(依赖 {@code serviceSubtaskMapper}、
 *       景宁站点白名单等),与已迁的"扫全量"是两条不同的入口。</li>
 * </ol>
 *
 * <h3>⚠️ 未迁部分逐字来自基线 {@code b25c3b51}</h3>
 * 由 {@code sql/_probe/gen_outhosp_delegating_impl.py} 从基线自动提取,
 * <b>不是手抄</b> —— 这类代码手抄出错不会编译报错,只会静默改变业务行为。
 * 改动未迁部分时必须同步更新该探针的期望。
 *
 * <h3>将来动作</h3>
 * 调用方逐个改为直接依赖模块门面后,本类与 {@link IPatMedOuthospService} 一起删除。
 */
@Slf4j
@Service
public class PatMedOuthospServiceDelegatingImpl implements IPatMedOuthospService {
 
    /** 模块门面:已迁方法的唯一出口 */
    @Autowired
    private OuthospDataFacade outhospDataFacade;
 
    // ==== 以下依赖仅供【未迁】的单患者按需随访链路使用 ====
    @Autowired
    private ServiceSubtaskMapper serviceSubtaskMapper;
    @Autowired
    private ServiceTaskMapper serviceTaskMapper;
    @Autowired
    private ServiceTaskdeptMapper serviceTaskdeptMapper;
    @Autowired
    private ServiceTaskdiagMapper serviceTaskdiagMapper;
    @Autowired
    private PatArchiveMapper patArchiveMapper;
 
    /**
     * 列表查询 —— 供【未迁】的单患者按需随访链路内部使用。
     * <p>
     * 原实现里它是本类的 {@code selectPatMedOuthospList};现已迁入模块的
     * {@code OuthospDataService#selectList},故这里只做内部转发。
     * <p>
     * ⚠️ 注意它与 Controller 用的是同一个方法 —— 后者会做展示富化(仅当 pageNum != null)。
     * 本链路不设 pageNum,故不会富化,与原实现一致。
     */
    private List<PatMedOuthosp> selectPatMedOuthospList(PatMedOuthosp query) {
        return outhospDataFacade.selectList(query);
    }
 
    // ======================================================================
    // 已迁:委托模块
    // ======================================================================
 
    @Override
    public int insertPatMedOuthosp(PatMedOuthosp patMedOuthosp) {
        return outhospDataFacade.insert(patMedOuthosp);
    }
 
    @Override
    public int updatePatMedOuthosp(PatMedOuthosp patMedOuthosp) {
        return outhospDataFacade.update(patMedOuthosp);
    }
 
    @Override
    public Set<String> selectExistingSerialnums(String admitDateStr, Collection<String> serialnums) {
        return outhospDataFacade.selectExistingSerialnums(admitDateStr, serialnums);
    }
 
 
    // ======================================================================
    // 未迁:单患者按需随访(逐字来自基线 b25c3b51)
    // ======================================================================
 
    public Integer dealPatMedOuthosp(PatMedOuthosp patMedOuthosp, Integer visitTimeNum){
            Integer num = 0;
 
            //景宁 存在相同诊断的门诊记录则新增再次随访,否则新增随访
            if(ObjectUtils.isNotEmpty(patMedOuthosp.getOrgid()) &&
                    patMedOuthosp.getOrgid().equals("47255004333112711A1001")){
                PatMedOuthosp patMedOuthospVo = new PatMedOuthosp();
                List<PatMedOuthosp> patMedOuthosps = new ArrayList<>();
                patMedOuthospVo.setOrgid(patMedOuthosp.getOrgid());
                patMedOuthospVo.setPatid(patMedOuthosp.getPatid());
                patMedOuthospVo.setIcd10code(patMedOuthosp.getIcd10code());
                // 同一个患者 + 同一个诊断,历史上已经有门诊随访记录(排除本次就诊,本次在调用前已落库)
                patMedOuthosps = selectPatMedOuthospList(patMedOuthospVo);
                Long currentId = patMedOuthosp.getId();
                List<Long> ids = patMedOuthosps.stream().map(PatMedOuthosp::getId).filter(ObjectUtils::isNotEmpty)
                        .filter(id -> !id.equals(currentId))
                        .distinct()
                        .collect(Collectors.toList());
                ServiceSubtaskEntity serviceSubtask = new ServiceSubtaskEntity();
                //景宁 只要存在相同诊断、患者的门诊记录则当再次随访处理
                serviceSubtask.setInhospids(ids);
                serviceSubtask.setServiceType("3");
                List<ServiceSubtask> serviceSubtasks = CollectionUtils.isEmpty(ids)
                        ? new ArrayList<>()
                        : serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtask);
                if(CollectionUtils.isEmpty(serviceSubtasks)){
                    num = followUpByPatMedOuthosp(patMedOuthosp, visitTimeNum);
                }else {
                    num = followUpAgainByPatMedOuthosp(patMedOuthosp, visitTimeNum, ids);
                }
            }else {
                ServiceSubtaskEntity serviceSubtask = new ServiceSubtaskEntity();
                serviceSubtask.setInhospid(patMedOuthosp.getId());
                serviceSubtask.setServiceType("3");
                serviceSubtask.setVisitCount(1);
                List<ServiceSubtask> serviceSubtasks = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtask);
                if(CollectionUtils.isEmpty(serviceSubtasks)){
                    num = followUpByPatMedOuthosp(patMedOuthosp, visitTimeNum);
                }else {
                    num = followUpAgainByPatMedOuthosp(patMedOuthosp, visitTimeNum, null);
                }
            }
            return num;
        }
 
    public Integer followUpByPatMedOuthosp(PatMedOuthosp patMedOuthosp, Integer visitTimeNum) {
    //        if(ObjectUtils.isEmpty(patMedOuthosp.getFudate())){
                Date adminDate = patMedOuthosp.getAdmitdate();
                Date fuDate = addDays(adminDate, visitTimeNum);
                patMedOuthosp.setFudate(fuDate);
    //        }
 
            PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedOuthosp.getPatid());
 
            //根据患者科室,获取该疾病的长期任务
            ServiceTaskdept serviceTaskdept = new ServiceTaskdept();
            serviceTaskdept.setLongtask(1L);
            serviceTaskdept.setDeptCode(patMedOuthosp.getDeptcode());
            serviceTaskdept.setServiceType("3");
            List<ServiceTaskdept> serviceTaskdeptList = serviceTaskdeptMapper.selectServiceTaskdeptList(serviceTaskdept);
            if (CollectionUtils.isEmpty(serviceTaskdeptList) || serviceTaskdeptList.size() == 0) {
                patMedOuthosp.setDeptcheckFlag("2");
                patMedOuthosp.setRemark("通过部门,没有找到门诊随访任务ID");
                updatePatMedOuthosp(patMedOuthosp);
            } else {
                for (ServiceTaskdept serviceTaskdept1 : serviceTaskdeptList) {
                    writeInSubTask(serviceTaskdept1.getTaskId(), true, patMedOuthosp, patArchive, 1);
                }
            }
 
            // 根据患者的疾病,获取该疾病的长期任务
    //        ServiceTaskdiag serviceTaskdiag = new ServiceTaskdiag();
    //        serviceTaskdiag.setLongtask(1L);
    //        serviceTaskdiag.setIcd10code(patMedOuthosp.getIcd10code());
    //        List<ServiceTaskdiag> serviceTaskdiags = serviceTaskdiagMapper.selectServiceTaskdiagList(serviceTaskdiag);
    //        //如果部门模板为空(将deptIsNull设置为true)
    //        if (org.apache.commons.collections4.CollectionUtils.isEmpty(serviceTaskdiags) || serviceTaskdiags.size() == 0) {
    //            patMedOuthosp.setDiagcheckFlag("2");
    //            patMedOuthosp.setRemark("通过icd10,没有找到门诊随访任务ID");
    //            updatePatMedOuthosp(patMedOuthosp);
    //        } else {
    //            for (ServiceTaskdiag serviceTaskdept1 : serviceTaskdiags) {
    //                writeInSubTask(serviceTaskdept1.getTaskId(), true, patMedOuthosp, patArchive, 2);
    //            }
    //        }
            return 1;
        }
 
    public Integer followUpAgainByPatMedOuthosp(PatMedOuthosp patMedOuthosp, Integer visitTimeNum, List<Long> inhospids) {
            Date adminDate = patMedOuthosp.getAdmitdate();
            Date newDate = addDays(adminDate, visitTimeNum);
 
            Integer i = 0;
            String deptcode = patMedOuthosp.getDeptcode();
            Long patid = patMedOuthosp.getPatid();
            //查看有无进行中的任务
            ServiceSubtaskEntity serviceSubtaskEntity0 = new ServiceSubtaskEntity();
            serviceSubtaskEntity0.setOrgid(patMedOuthosp.getOrgid());
            serviceSubtaskEntity0.setSendstates(new ArrayList<>(Arrays.asList(1L, 2L, 3L, 7L)));
            serviceSubtaskEntity0.setPatid(patid);
            //景宁根据诊断再次随访
            if(ObjectUtils.isNotEmpty(patMedOuthosp.getOrgid()) &&
                    patMedOuthosp.getOrgid().equals("47255004333112711A1001") && !CollectionUtils.isEmpty(inhospids)){
                serviceSubtaskEntity0.setInhospids(inhospids);
            }else {
                serviceSubtaskEntity0.setLeaveldeptcode(deptcode);
            }
 
            serviceSubtaskEntity0.setSort(0);
            List<ServiceSubtask> serviceSubtaskList0 = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskEntity0);
            if (!CollectionUtils.isEmpty(serviceSubtaskList0)) {
                for (ServiceSubtask serviceSubtask0 : serviceSubtaskList0) {
                    serviceSubtask0.setSendstate(6L);
                    serviceSubtask0.setUpdateTime(new Date());
                    serviceSubtask0.setFinishtime(adminDate);
                    serviceSubtaskMapper.updateServiceSubtask(serviceSubtask0);
 
                    ServiceSubtask serviceSubtask1 = DtoConversionUtils.sourceToTarget(serviceSubtask0, ServiceSubtask.class);
                    serviceSubtask1.setId(null);
                    serviceSubtask1.setSendstate(2L);
                    serviceSubtask1.setUpid(serviceSubtask0.getId().intValue());
                    //老数据的visit_count可能为空,默认按第1次算
                    Integer visitCount = ObjectUtils.isEmpty(serviceSubtask0.getVisitCount()) ? 1 : serviceSubtask0.getVisitCount();
                    serviceSubtask1.setVisitCount(visitCount + 1);
                    serviceSubtask1.setVisitType(serviceSubtask0.getVisitType());
                    serviceSubtask1.setVisitDeptCode(serviceSubtask0.getVisitDeptCode());
                    serviceSubtask1.setVisitDeptName(serviceSubtask0.getVisitDeptName());
                    //新任务科室是当前出院科室
                    serviceSubtask1.setLeaveldeptcode(patMedOuthosp.getDeptcode());
                    serviceSubtask1.setCreateTime(new Date());
                    serviceSubtask1.setUpdateTime(new Date());
                    serviceSubtask1.setFinishtime(null);
                    serviceSubtask1.setAdmindate(adminDate);
 
                    serviceSubtask1.setVisitTime(newDate);
                    serviceSubtask1.setLongSendTime(newDate);
                    i = i + serviceSubtaskMapper.insertServiceSubtask(serviceSubtask1);
                }
            } else {
                //查看已完成的任务
    //            ServiceSubtaskEntity serviceSubtaskEntity = new ServiceSubtaskEntity();
    //            serviceSubtaskEntity0.setOrgid(patMedOuthosp.getOrgid());
    //            serviceSubtaskEntity.setSendstates(new ArrayList<>(Arrays.asList(6L)));
    //            serviceSubtaskEntity.setPatid(patid);
    //            serviceSubtaskEntity.setDeptcode(deptcode);
    //            serviceSubtaskEntity.setSort(0);
    //            List<ServiceSubtask> serviceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskEntity);
    //            if(!CollectionUtils.isEmpty(serviceSubtaskList)){
    //                ServiceSubtask serviceSubtask = serviceSubtaskList.get(0);
    //                serviceSubtask.setSendstate(2L);
    //                serviceSubtask.setCreateTime(new Date());
    //                serviceSubtask.setUpdateTime(new Date());
    //
    //                serviceSubtask.setVisitTime(newDate);
    //                serviceSubtask.setLongSendTime(newDate);
    //                i = serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
    //            }
            }
            return i;
        }
 
    private void writeInSubTask(Long taskid, Boolean check, PatMedOuthosp patMedOuthosp, PatArchive patArchive, Integer type) {
 
            ServiceTask st = new ServiceTask();
            st.setTaskid(taskid);
            st.setSendState(2L);
            List<ServiceTask> serviceTasks = serviceTaskMapper.selectServiceTaskList(st);
            if (org.apache.commons.collections4.CollectionUtils.isEmpty(serviceTasks)) {
                log.info("该患者疾病随访长期任务不存在,任务ID为:{}", taskid);
                if (type == 1) patMedOuthosp.setDiagcheckFlag("2");
                if (type == 2) patMedOuthosp.setDeptcheckFlag("2");
                patMedOuthosp.setRemark("该患者门诊随访长期任务不存在,任务ID为:" + taskid);
                updatePatMedOuthosp(patMedOuthosp);
                return;
            }
            ServiceTask serviceTask = serviceTasks.get(0);
            //封装serviceSubtask
            ServiceSubtask serviceSubtask = boxedServiceSubtask(serviceTask, patMedOuthosp, patArchive);
            Integer i = 0;
            //先判断一下,是否需要校验
            if (check) {
                //在新增之前,先通过患者ID,sendstate=2查询一下,在所有长期任务中,是不是还有该患者待执行的任务,有的话,比较之前的endtime是否小于当前的endtaime,如果之前的小于现在的,则直接将之前的停掉(原因再入院)
                ServiceSubtaskEntity subtask = new ServiceSubtaskEntity();
                subtask.setPatid(patArchive.getId());
                subtask.setSendstate(2L);
                subtask.setTaskid(taskid);
                List<ServiceSubtask> selectServiceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(subtask);
                log.info("该患者待执行的任务:{}", CollectionUtils.isEmpty(selectServiceSubtaskList) ? null : selectServiceSubtaskList.size());
                if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(selectServiceSubtaskList) && selectServiceSubtaskList.size() > 0) {
                    for (ServiceSubtask serviceSubtask1 : selectServiceSubtaskList) {
                        if (Objects.isNull(serviceSubtask1.getLongSendTime())) {
                            //不是长期任务,不处理
                            continue;
                        }
 
                        //将之前的停掉
                        serviceSubtask1.setSendstate(6L);
                        serviceSubtask1.setRemark("患者已经回院复诊");
                        serviceSubtask1.setResult("success");
                        serviceSubtask1.setFinishtime(new Date());
                        serviceSubtask1.setUpdateBy(serviceTask.getUpdateBy());
                        serviceSubtaskMapper.updateServiceSubtask(serviceSubtask1);
                        //重新新增子任务
                        i = serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
                    }
                } else {
                    if (StringUtils.isEmpty(serviceSubtask.getPhone())) {
                        serviceSubtask.setRemark("手机号为空");
                        serviceSubtask.setSendstate(4L);
                        serviceSubtask.setResult("error");
    //                    serviceSubtask.setFinishtime(new Date());
                    }
                    serviceSubtask.setCreateBy(serviceTask.getCreateBy());
                    serviceSubtask.setCreateTime(new Date());
                    i = serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
                }
            } else {
                if (StringUtils.isEmpty(serviceSubtask.getPhone())) {
                    serviceSubtask.setRemark("手机号为空");
                    serviceSubtask.setSendstate(4L);
                    serviceSubtask.setResult("error");
    //                serviceSubtask.setFinishtime(new Date());
 
                }
                serviceSubtask.setCreateBy(serviceTask.getCreateBy());
                serviceSubtask.setCreateTime(new Date());
                i = serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
            }
            if (i == 1) {
                //将check_flag改成1(已处理)
                PatMedOuthosp patMedOuthosp1 = new PatMedOuthosp();
                patMedOuthosp1.setId(patMedOuthosp.getId());
                if (type == 1) patMedOuthosp1.setDiagcheckFlag("2");
                if (type == 2) patMedOuthosp1.setDeptcheckFlag("2");
                updatePatMedOuthosp(patMedOuthosp1);
            } else {
                //生成子任务失败,
                log.info("生成子任务失败serviceSubtask的taskid为:{},patid为:{}", serviceSubtask.getTaskid(), serviceSubtask.getPatid());
                PatMedOuthosp pmo = new PatMedOuthosp();
                pmo.setGuid(patMedOuthosp.getGuid());
                pmo.setSerialnum(patMedOuthosp.getSerialnum());
                if (type == 1) pmo.setDiagcheckFlag("2");
                if (type == 2) pmo.setDeptcheckFlag("2");
                pmo.setRemark("生成子任务失败");
                updatePatMedOuthosp(pmo);
            }
        }
 
    public ServiceSubtask boxedServiceSubtask(ServiceTask serviceTask, PatMedOuthosp patMedOuthosp, PatArchive patArchive) {
            ServiceSubtask serviceSubtask = DtoConversionUtils.sourceToTarget(serviceTask, ServiceSubtask.class);
            serviceSubtask.setTaskid(serviceTask.getTaskid());
            serviceSubtask.setOrgid(serviceTask.getOrgid());
            serviceSubtask.setCampusid(serviceTask.getCampusid());
            if (StringUtils.isNotEmpty(serviceTask.getLibtemplateid()))
                serviceSubtask.setLibtemplateid(Long.valueOf(serviceTask.getLibtemplateid()));
            serviceSubtask.setDrcode(patMedOuthosp.getDrcode());
            serviceSubtask.setDrname(patMedOuthosp.getDrname());
            serviceSubtask.setLeaveldeptcode(patMedOuthosp.getDeptcode());
            serviceSubtask.setInhospid(patMedOuthosp.getId());
            serviceSubtask.setHospno(patMedOuthosp.getOuthospno());
            serviceSubtask.setLeaveldeptname(patMedOuthosp.getDeptname());
            serviceSubtask.setTemplateid(serviceTask.getTemplateid());
            serviceSubtask.setTemplatename(serviceTask.getTemplatename());
            serviceSubtask.setPatid(patArchive.getId());
            serviceSubtask.setSendname(patArchive.getName());
            serviceSubtask.setSfzh(patArchive.getIdcardno());
            serviceSubtask.setLeavediagname(patMedOuthosp.getDiagname());
            serviceSubtask.setLeaveicd10code(patMedOuthosp.getIcd10code());
            serviceSubtask.setSfzh(patArchive.getIdcardno());
            serviceSubtask.setPhone(patArchive.getTelcode());
            if (StringUtils.isBlank(patArchive.getTelcode())) serviceSubtask.setPhone(patArchive.getRelativetelcode());
            serviceSubtask.setSex(patArchive.getSex());
            serviceSubtask.setAge(patArchive.getAge());
            serviceSubtask.setSendstate(2L);
            serviceSubtask.setServiceType(serviceTask.getServiceType());
            serviceSubtask.setPreachform(serviceTask.getPreachform());
            serviceSubtask.setHospType("1");
            serviceSubtask.setCreateTime(new Date());
            serviceSubtask.setUpdateTime(new Date());
            serviceSubtask.setUpdateBy(serviceTask.getUpdateBy());
            serviceSubtask.setUpdateTime(new Date());
            serviceSubtask.setVisitDeptCode(patMedOuthosp.getDeptcode());
            serviceSubtask.setVisitDeptName(patMedOuthosp.getDeptname());
            serviceSubtask.setUpdateTime(new Date());
            serviceSubtask.setAdmindate(patMedOuthosp.getAdmitdate());
            //设置发送时间
            if (serviceTask.getSendDay() == null) serviceTask.setSendDay(1L);
            Date newDate = addDays(patMedOuthosp.getAdmitdate(), serviceTask.getSendDay().intValue());
            if (patMedOuthosp.getFudate() != null) {
                //如果门诊表有指定随访时间,那就用指定的
                newDate = patMedOuthosp.getFudate();
            }
            serviceSubtask.setLongSendTime(newDate);
            serviceSubtask.setVisitTime(newDate);
            //患者发送时间
            if (StringUtils.isNotEmpty(patArchive.getNotrequiredFlag()) && patArchive.getNotrequiredFlag().equals("1")) {
                String remark = patArchive.getNotrequiredreason();
                serviceSubtask.setRemark(remark);
                serviceSubtask.setResult("error");
    //            serviceSubtask.setFinishtime(new Date());
                //不执行
                serviceSubtask.setSendstate(4L);
            }
            return serviceSubtask;
        }
 
    private Date addDays(Date date, Integer days) {
            if (days == null) {
                days = 1;
            }
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.DAY_OF_MONTH, days);
            return calendar.getTime();
        }
}