PatientArchivesSevice.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package com.yihu.jw.service;
  2. import com.yihu.base.mysql.query.BaseJpaService;
  3. import com.yihu.jw.dao.PatientArchivesDao;
  4. import com.yihu.jw.dao.PatientArchivesInfoDao;
  5. import com.yihu.jw.entity.archives.PatientArchives;
  6. import com.yihu.jw.entity.archives.PatientArchivesInfo;
  7. import com.yihu.jw.iot.company.IotCompanyDO;
  8. import com.yihu.jw.restmodel.archives.PatientArchivesInfoVO;
  9. import com.yihu.jw.restmodel.archives.PatientArchivesVO;
  10. import com.yihu.jw.restmodel.common.Envelop;
  11. import com.yihu.jw.restmodel.iot.company.IotCompanyTypeVO;
  12. import com.yihu.jw.restmodel.iot.company.IotCompanyVO;
  13. import com.yihu.jw.rm.archives.PatientArchivesMapping;
  14. import com.yihu.jw.rm.iot.IotRequestMapping;
  15. import org.apache.commons.lang.StringUtils;
  16. import org.springframework.beans.BeanUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19. import org.springframework.transaction.annotation.Transactional;
  20. import java.awt.*;
  21. import java.text.ParseException;
  22. import java.util.ArrayList;
  23. import java.util.Collection;
  24. import java.util.List;
  25. /**
  26. * Created by Trick on 2018/2/7.
  27. */
  28. @Service
  29. @Transactional
  30. public class PatientArchivesSevice extends BaseJpaService<PatientArchives,PatientArchivesDao> {
  31. @Autowired
  32. private PatientArchivesInfoDao patientArchivesInfoDao;
  33. @Autowired
  34. private PatientArchivesDao patientArchivesDao;
  35. /**
  36. * 分页查找健康档案
  37. * @param page
  38. * @param size
  39. * @param status
  40. * @param name
  41. * @return
  42. * @throws ParseException
  43. */
  44. public Envelop<PatientArchivesVO> queryPatientArchivesPage(Integer page, Integer size, String status,String cancelReseanType ,String name) throws ParseException {
  45. String filters = "";
  46. String semicolon = "";
  47. if(StringUtils.isNotBlank(name)){
  48. filters = "patientName?"+name+"";
  49. semicolon = ";";
  50. }
  51. if(StringUtils.isNotBlank(status)){
  52. filters += semicolon +"status="+status;
  53. semicolon = ";";
  54. }
  55. if(StringUtils.isBlank(cancelReseanType)){
  56. filters+= semicolon + "cancelReseanType="+cancelReseanType+"";
  57. semicolon = ";";
  58. }
  59. String sorts = "-createTime";
  60. //得到list数据
  61. List<PatientArchivesVO> list = search(null, filters, sorts, page, size);
  62. //获取总数
  63. long count = getCount(filters);
  64. //DO转VO
  65. List<PatientArchivesVO> patientArchivesVOs = convertToModelVOs(list,new ArrayList<>(list.size()));
  66. return Envelop.getSuccessListWithPage(PatientArchivesMapping.api_success,patientArchivesVOs, page, size,count);
  67. }
  68. /**
  69. * 获取档案详情
  70. * @return
  71. * @throws ParseException
  72. */
  73. public Envelop<PatientArchivesInfoVO> queryPatientArchivesInfoPage(String code) throws ParseException {
  74. List<PatientArchivesInfo> list = patientArchivesInfoDao.findByCodeOrderByLevel1(code);
  75. List<PatientArchivesInfoVO> patientArchivesinfoVOs = convertToModelVOs2(list,new ArrayList<>(list.size()));
  76. return Envelop.getSuccessList(PatientArchivesMapping.api_success,patientArchivesinfoVOs);
  77. }
  78. public Envelop<Boolean> createPatientArchives(PatientArchives patientArchives,List<PatientArchivesInfo> list){
  79. patientArchivesDao.save(patientArchives);
  80. patientArchivesInfoDao.save(list);
  81. Envelop envelop = new Envelop();
  82. envelop.setObj(true);
  83. return envelop;
  84. }
  85. public Envelop<Boolean> updatePatientArchives(PatientArchives patientArchives,List<PatientArchivesInfo> list){
  86. patientArchivesDao.save(patientArchives);
  87. patientArchivesInfoDao.deleteByArchivesCode(patientArchives.getId());
  88. patientArchivesInfoDao.save(list);
  89. Envelop envelop = new Envelop();
  90. envelop.setObj(true);
  91. return envelop;
  92. }
  93. /**
  94. * 转换
  95. * @param sources
  96. * @param targets
  97. * @return
  98. */
  99. public List<PatientArchivesVO> convertToModelVOs(Collection sources, List<PatientArchivesVO> targets){
  100. sources.forEach(one -> {
  101. PatientArchivesVO target = new PatientArchivesVO();
  102. BeanUtils.copyProperties(one, target);
  103. targets.add(target);
  104. });
  105. return targets;
  106. }
  107. /**
  108. * 转换
  109. * @param sources
  110. * @param targets
  111. * @return
  112. */
  113. public List<PatientArchivesInfoVO> convertToModelVOs2(Collection sources, List<PatientArchivesInfoVO> targets){
  114. sources.forEach(one -> {
  115. PatientArchivesInfoVO target = new PatientArchivesInfoVO();
  116. BeanUtils.copyProperties(one, target);
  117. targets.add(target);
  118. });
  119. return targets;
  120. }
  121. }