Commit 87bd72b39e786ad7815607e85766aa13aba2ae1f

Authored by jiangjiazhi
1 parent b8881b6eab

社区服务-如果修改了分娩时间(新生儿出生时间),则产妇和新生儿的每个访视记录的树结构中的天数要根据更改后分娩时间(出生时间)重新计算

Showing 1 changed file with 93 additions and 28 deletions

platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/VisitFacade.java View file @ 87bd72b
... ... @@ -7,6 +7,7 @@
7 7 import com.lyms.platform.common.result.BaseObjectResponse;
8 8 import com.lyms.platform.common.result.BaseResponse;
9 9 import com.lyms.platform.common.utils.DateUtil;
  10 +import com.lyms.platform.common.utils.ExceptionUtils;
10 11 import com.lyms.platform.operate.web.request.BabyVisitAddRequest;
11 12 import com.lyms.platform.operate.web.request.VisitAddRequest;
12 13 import com.lyms.platform.operate.web.request.VisitAddRequest.SimpleVisitPuerpera;
13 14  
14 15  
15 16  
... ... @@ -74,14 +75,14 @@
74 75 if (null != puerperaModel) {
75 76 return doBiz(puerperaModel);
76 77 }
77   - BabyModelQuery babyModelQuery =new BabyModelQuery();
  78 + BabyModelQuery babyModelQuery = new BabyModelQuery();
78 79 babyModelQuery.setYn(YnEnums.YES.getId());
79 80 babyModelQuery.setMphone(cardNo);
80   - List<BabyModel> babyModels = babyService.queryBabyWithQuery(babyModelQuery);
  81 + List<BabyModel> babyModels = babyService.queryBabyWithQuery(babyModelQuery);
81 82  
82   - if(CollectionUtils.isNotEmpty(babyModels)){
  83 + if (CollectionUtils.isNotEmpty(babyModels)) {
83 84 VisitResult data = new VisitResult();
84   - BabyModel babyModel = babyModels.get(0);
  85 + BabyModel babyModel = babyModels.get(0);
85 86 data.convertToResult1(babyModel, CommonsHelper.fullAddress(babyModel, basicConfigService));
86 87 data.setData(Collections.EMPTY_LIST);
87 88 return new BaseObjectResponse().setData(data).setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功");
... ... @@ -144,7 +145,7 @@
144 145 // 获取患者id
145 146 String parentId = visitRequest.getParentId();
146 147 String checkTime = visitRequest.getCheckTime();
147   - if (StringUtils.isNotEmpty(checkTime)&&null!=visitRequest.getPatients().getDueDate()) {
  148 + if (StringUtils.isNotEmpty(checkTime) && null != visitRequest.getPatients().getDueDate()) {
148 149 boolean f = DateUtil.parseYMD(checkTime).before(visitRequest.getPatients().getDueDate());
149 150 if (f) {
150 151 return new BaseResponse().setErrorcode(ErrorCodeConstants.PARAMETER_ERROR).setErrormsg("检查时间必须大于分娩时间");
... ... @@ -162,7 +163,13 @@
162 163 SimpleVisitPuerpera srcModel = visitRequest.new SimpleVisitPuerpera(model);
163 164 // 和数据库里面的对象比较如果不等就表示有修改需存入到数据库中
164 165 if (!destModel.equals(srcModel)) {
165   - Patients patients = visitRequest.getPatients();
  166 + Patients patients = visitRequest.getPatients();
  167 + //判断分娩日期是否修改
  168 + if (null != model.getDueDate() && !visitRequest.getDueDate().equals(DateUtil.getyyyy_MM_dd(model.getDueDate()))) {
  169 + //修改访视后的天数
  170 + updateVisitDays(model.getId(), patients.getDueDate());
  171 + }
  172 +
166 173 patients.setCreated(new Date());
167 174 patients.setModified(new Date());
168 175 patientsService.updatePatient(patients/*.build()*/);
... ... @@ -173,7 +180,7 @@
173 180 } else {
174 181 // 表示是新的产妇直接新增
175 182 // parentId = puerperaService.addPuerpera(visitRequest.getPuerpera().build()).getId();
176   - parentId= addOnePatients(visitRequest.getPatients());
  183 + parentId = addOnePatients(visitRequest.getPatients());
177 184 }
178 185  
179 186 // 如果为空表示新增
... ... @@ -187,7 +194,7 @@
187 194 visitModel.setId(null);
188 195 visitService.addVisit(visitModel);
189 196 } else {
190   - VisitModel visitModel = visitRequest.getRequestVisit();
  197 + VisitModel visitModel = visitRequest.getRequestVisit();
191 198 visitModel.setModified(new Date());
192 199 visitService.updateVisit(visitModel);
193 200 }
194 201  
195 202  
196 203  
197 204  
... ... @@ -200,28 +207,83 @@
200 207 }
201 208  
202 209 /**
  210 + * 修改访视的天数
203 211 *
  212 + * @param parentId 产妇id
  213 + * @param dueDate 分娩日期
  214 + */
  215 + private void updateVisitDays(String parentId, Date dueDate) {
  216 + VisitQuery visitQuery = new VisitQuery();
  217 + visitQuery.setParentId(parentId);
  218 +
  219 + List<VisitModel> list = visitService.queryVisit(visitQuery);
  220 + if (CollectionUtils.isNotEmpty(list)) {
  221 + for (VisitModel visitModel : list) {
  222 + try {
  223 + visitModel.setDays((DateUtil.getDays(dueDate, DateUtil.parseYMD(visitModel.getChecktime())) + 1) + "");
  224 + visitService.updateVisit(visitModel);
  225 + } catch (Exception e) {
  226 + ExceptionUtils.catchException(e, "updateVisitDays by parentId : " + parentId + " and visit model id:" + visitModel.getId());
  227 + }
  228 + }
  229 + }
  230 + updateBabyVisitDays(parentId, dueDate, null);
  231 + }
  232 +
  233 + /**
  234 + * 修改小孩的访视天数
  235 + */
  236 + private void updateBabyVisitDays(String parentId, Date dueDate, String id) {
  237 + BabyModelQuery babyModelQuery = new BabyModelQuery();
  238 + if (StringUtils.isNotEmpty(parentId)) {
  239 + babyModelQuery.setParentId(parentId);
  240 + }
  241 + if (StringUtils.isNotEmpty(id)) {
  242 + babyModelQuery.setId(id);
  243 + }
  244 + babyModelQuery.setYn(YnEnums.YES.getId());
  245 + List<BabyModel> babyModels = babyService.queryBabyWithQuery(babyModelQuery);
  246 + if (CollectionUtils.isNotEmpty(babyModels)) {
  247 + for (BabyModel babyModel : babyModels) {
  248 + List<BabyVisitModel> babyVisits = babyVisitService.findAllVisitByParentId(babyModel.getId());
  249 + if (CollectionUtils.isNotEmpty(babyVisits)) {
  250 + for (BabyVisitModel babyVisitModel : babyVisits) {
  251 + babyVisitModel.setDays((DateUtil.getDays(dueDate, babyVisitModel.getCurrentVisit()) + 1) + "");
  252 + babyVisitService.updateOneBabyVisit(babyVisitModel, babyVisitModel.getId());
  253 + }
  254 + }
  255 + //id为空表示是产妇预产期修改引发的修改小孩,如果id不为空。表示小孩数据已修改 不用在修改小孩的数据
  256 + if (StringUtils.isEmpty(id)) {
  257 + babyModel.setBirth(dueDate);
  258 + babyService.updateOneBaby(babyModel, babyModel.getId());
  259 + }
  260 + }
  261 + }
  262 + }
  263 +
  264 +
  265 + /**
204 266 * 增加一个患者并根据患者的手机号去关联小孩的数据
205 267 *
206 268 * @param patients
207 269 * @return
208 270 */
209   - public String addOnePatients(Patients patients){
  271 + public String addOnePatients(Patients patients) {
210 272 patients.setType(3);
211 273 patients.setYn(YnEnums.YES.getId());
212 274 patients.setId(null);
213 275 patients.setCreated(new Date());
214 276 patients.setModified(new Date());
215 277 patients.setIsVisit(VisitStatusEnums.UNVISIT.getId());
216   - String parentId = patientsService.addPatient(patients).getId();
  278 + String parentId = patientsService.addPatient(patients).getId();
217 279  
218 280 BabyModelQuery babyModelQuery = new BabyModelQuery();
219 281 babyModelQuery.setMphone(patients.getPhone());
220 282 babyModelQuery.setYn(YnEnums.YES.getId());
221 283 BabyModel babyModel = new BabyModel();
222 284 babyModel.setParentId(parentId);
223   - babyService.findAndModify(babyModelQuery.convertToQuery(),babyModel);
224   - return parentId;
  285 + babyService.findAndModify(babyModelQuery.convertToQuery(), babyModel);
  286 + return parentId;
225 287 }
226 288  
227 289 /**
... ... @@ -241,9 +303,9 @@
241 303  
242 304 String babyId = babyVisitAddRequest.getParentId();
243 305 String currentTime = babyVisitAddRequest.getCurrentVisit();
244   - if (StringUtils.isNotEmpty(currentTime)&&StringUtils.isNotEmpty(babyVisitAddRequest.getBirth())) {
245   - Date currentVisit = DateUtil.parseYMD(babyVisitAddRequest.getCurrentVisit());
246   - Date birth = DateUtil.parseYMD(babyVisitAddRequest.getBirth());
  306 + if (StringUtils.isNotEmpty(currentTime) && StringUtils.isNotEmpty(babyVisitAddRequest.getBirth())) {
  307 + Date currentVisit = DateUtil.parseYMD(babyVisitAddRequest.getCurrentVisit());
  308 + Date birth = DateUtil.parseYMD(babyVisitAddRequest.getBirth());
247 309 boolean f = currentVisit.before(birth);
248 310 if (f) {
249 311 return new BaseResponse().setErrorcode(ErrorCodeConstants.PARAMETER_ERROR).setErrormsg("检查时间必须大于小孩出生时间");
250 312  
251 313  
... ... @@ -265,14 +327,18 @@
265 327 babyModel.setVisitstatus(VisitStatusEnums.UNVISIT.getId());
266 328 babyId = babyService.addOneBaby(babyModel).getId();
267 329 } else {
268   - BabyModel babyModel= babyVisitAddRequest.getBabyModel();
  330 + BabyModel babyModel = babyVisitAddRequest.getBabyModel();
269 331 PatientsQuery patientsQuery = new PatientsQuery();
270 332 patientsQuery.setPhone(babyModel.getMphone());
271 333 patientsQuery.setType(3);
272 334 List<Patients> patientses = patientsService.queryPatient(patientsQuery);
273   - if(CollectionUtils.isNotEmpty(patientses)){
  335 + if (CollectionUtils.isNotEmpty(patientses)) {
274 336 babyModel.setParentId(patientses.get(0).getId());
275 337 }
  338 + BabyModel babyModel1 = babyService.getOneBabyById(babyId);
  339 + if ((null != babyModel.getBirth() && null == babyModel1.getBirth()) || (!DateUtil.getyyyy_MM_dd(babyModel.getBirth()).equals(DateUtil.getyyyy_MM_dd(babyModel1.getBirth())))) {
  340 + updateBabyVisitDays(null, babyModel.getBirth(), babyModel1.getId());
  341 + }
276 342 //修改小孩基本信息
277 343 babyService.updateOneBaby(babyModel, babyId);
278 344 }
279 345  
280 346  
... ... @@ -293,17 +359,16 @@
293 359 return new BaseResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功");
294 360 }
295 361  
296   - public String getFindTips(String parentId,boolean isM) {
  362 + public String getFindTips(String parentId, boolean isM) {
297 363  
298 364 VisitQuery visitQuery = new VisitQuery();
299 365 visitQuery.setParentId(parentId);
300   - int count =0;
301   - if(isM){
  366 + int count = 0;
  367 + if (isM) {
302 368  
303   - count= visitService.queryVisitCount(visitQuery);
304   - }else
305   - {
306   - count=babyVisitService.queryVisitCount(visitQuery);
  369 + count = visitService.queryVisitCount(visitQuery);
  370 + } else {
  371 + count = babyVisitService.queryVisitCount(visitQuery);
307 372 }
308 373  
309 374 return count <= 0 ? "未访视" : "访视" + count + "次";
310 375  
311 376  
... ... @@ -327,15 +392,15 @@
327 392 return findBabyVisit(babyModel);
328 393 }
329 394  
330   - PatientsQuery patientsQuery =new PatientsQuery();
  395 + PatientsQuery patientsQuery = new PatientsQuery();
331 396 patientsQuery.setYn(YnEnums.YES.getId());
332 397 patientsQuery.setType(3);
333 398 patientsQuery.setPhone(cardNo);
334 399  
335   - List<Patients> patientses = patientsService.queryPatient(patientsQuery);
  400 + List<Patients> patientses = patientsService.queryPatient(patientsQuery);
336 401  
337   - if(CollectionUtils.isNotEmpty(patientses)){
338   - Patients patients = patientses.get(0);
  402 + if (CollectionUtils.isNotEmpty(patientses)) {
  403 + Patients patients = patientses.get(0);
339 404 BabyVisitResult babyVisitResult = new BabyVisitResult();
340 405 babyVisitResult.convertToResult1(patients, CommonsHelper.fullAddress(patients, basicConfigService));
341 406 babyVisitResult.setData(Collections.EMPTY_LIST);