PatientArchivesSevice.java 4.5 KB

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