CardController.java 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. package com.yihu.ehr.patient.controller;
  2. import com.yihu.ehr.systemdict.service.ConventionalDictEntryClient;
  3. import com.yihu.ehr.agModel.patient.CardDetailModel;
  4. import com.yihu.ehr.agModel.patient.CardModel;
  5. import com.yihu.ehr.constants.AgAdminConstants;
  6. import com.yihu.ehr.constants.ApiVersion;
  7. import com.yihu.ehr.organization.service.OrganizationClient;
  8. import com.yihu.ehr.patient.service.CardClient;
  9. import com.yihu.ehr.model.dict.MConventionalDict;
  10. import com.yihu.ehr.model.org.MOrganization;
  11. import com.yihu.ehr.model.patient.MAbstractCard;
  12. import com.yihu.ehr.util.datetime.DateTimeUtil;
  13. import com.yihu.ehr.util.rest.Envelop;
  14. import com.yihu.ehr.controller.BaseController;
  15. import io.swagger.annotations.Api;
  16. import io.swagger.annotations.ApiOperation;
  17. import io.swagger.annotations.ApiParam;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.http.ResponseEntity;
  20. import org.springframework.util.StringUtils;
  21. import org.springframework.web.bind.annotation.*;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. /**
  25. * Created by AndyCai on 2016/1/21.
  26. */
  27. @RequestMapping(ApiVersion.Version1_0 + "/admin")
  28. @RestController
  29. @Api(value = "card", description = "就诊卡管理(旧)", tags = {"就诊卡管理(旧)"})
  30. public class CardController extends BaseController {
  31. @Autowired
  32. private CardClient cardClient;
  33. @Autowired
  34. private ConventionalDictEntryClient conventionalDictEntryClient;
  35. @Autowired
  36. private OrganizationClient orgClient;
  37. /**
  38. * 根据身份证好查询相对应的卡列表
  39. *
  40. * @param idCardNo
  41. * @param number
  42. * @param cardType
  43. * @param page
  44. * @param rows
  45. * @return
  46. * @throws Exception
  47. */
  48. @RequestMapping(value = "/cards/binding", method = RequestMethod.GET)
  49. @ApiOperation(value = "根据身份证好查询相对应的卡列表")
  50. public Envelop searchCardBinding(
  51. @ApiParam(name = "id_card_no", value = "身份证号", defaultValue = "")
  52. @RequestParam(value = "id_card_no") String idCardNo,
  53. @ApiParam(name = "number", value = "卡号", defaultValue = "")
  54. @RequestParam(value = "number") String number,
  55. @ApiParam(name = "card_type", value = "卡类别", defaultValue = "")
  56. @RequestParam(value = "card_type") String cardType,
  57. @ApiParam(name = "page", value = "当前页", defaultValue = "")
  58. @RequestParam(value = "page") Integer page,
  59. @ApiParam(name = "rows", value = "行数", defaultValue = "")
  60. @RequestParam(value = "rows") Integer rows) throws Exception {
  61. ResponseEntity<List<MAbstractCard>> responseEntity = cardClient.searchCardBinding(idCardNo, number, cardType, page, rows);
  62. List<MAbstractCard> mAbstractCards=responseEntity.getBody();
  63. List<CardModel> cardModels = new ArrayList<>();
  64. for (MAbstractCard info : mAbstractCards) {
  65. CardModel cardModel = convertToModel(info, CardModel.class);
  66. cardModel.setCreateDate(DateToString(info.getCreateDate(),AgAdminConstants.DateFormat));
  67. MConventionalDict dict =null;
  68. if(!StringUtils.isEmpty(cardModel.getCardType())) {
  69. dict = conventionalDictEntryClient.getCardType(cardModel.getCardType());
  70. cardModel.setTypeName(dict.getValue());
  71. }
  72. if (!StringUtils.isEmpty(cardModel.getStatus())) {
  73. dict = conventionalDictEntryClient.getCardStatus(cardModel.getStatus());
  74. cardModel.setStatusName(dict.getValue());
  75. }
  76. if(!StringUtils.isEmpty(cardModel.getReleaseOrg())) {
  77. MOrganization organization = orgClient.getOrg(cardModel.getReleaseOrg());
  78. cardModel.setReleaseOrgName(organization.getFullName());
  79. }
  80. cardModels.add(cardModel);
  81. }
  82. Envelop envelop = getResult(cardModels, getTotalCount(responseEntity), page, rows);
  83. return envelop;
  84. }
  85. /**
  86. * 查询未绑定的卡列表
  87. *
  88. * @param number
  89. * @param cardType
  90. * @param page
  91. * @param rows
  92. * @return
  93. * @throws Exception
  94. */
  95. @RequestMapping(value = "/cards/un_binding", method = RequestMethod.GET)
  96. @ApiOperation(value = "查询未绑定的卡列表")
  97. public Envelop searchCardUnBinding(
  98. @ApiParam(name = "number", value = "卡号", defaultValue = "")
  99. @RequestParam(value = "number") String number,
  100. @ApiParam(name = "card_type", value = "卡类别", defaultValue = "")
  101. @RequestParam(value = "card_type") String cardType,
  102. @ApiParam(name = "page", value = "当前页", defaultValue = "")
  103. @RequestParam(value = "page") Integer page,
  104. @ApiParam(name = "rows", value = "行数", defaultValue = "")
  105. @RequestParam(value = "rows") Integer rows) throws Exception {
  106. ResponseEntity<List<MAbstractCard>> responseEntity = cardClient.searchCardUnBinding(number, cardType, page, rows);
  107. List<MAbstractCard> mAbstractCards =responseEntity.getBody();
  108. List<CardModel> cardModels = new ArrayList<>();
  109. for (MAbstractCard info : mAbstractCards){
  110. CardModel cardModel = convertToModel(info, CardModel.class);
  111. cardModel.setCreateDate(info.getCreateDate() == null?"": DateTimeUtil.simpleDateTimeFormat(info.getCreateDate()).substring(0, 10) );
  112. MConventionalDict dict =null;
  113. if(!StringUtils.isEmpty(cardModel.getCardType())) {
  114. dict = conventionalDictEntryClient.getCardType(cardModel.getCardType());
  115. cardModel.setTypeName(dict.getValue());
  116. }
  117. if (!StringUtils.isEmpty(cardModel.getStatus())) {
  118. dict = conventionalDictEntryClient.getCardStatus(cardModel.getStatus());
  119. cardModel.setStatusName(dict.getValue());
  120. }
  121. if(!StringUtils.isEmpty(cardModel.getReleaseOrg())) {
  122. MOrganization organization = orgClient.getOrg(cardModel.getReleaseOrg());
  123. cardModel.setReleaseOrgName(organization.getFullName());
  124. }
  125. cardModels.add(cardModel);
  126. }
  127. Envelop envelop = getResult(cardModels, getTotalCount(responseEntity), page, rows);
  128. return envelop;
  129. }
  130. /**
  131. * 根据卡号和卡类型查找卡
  132. *
  133. * @param id
  134. * @param cardType
  135. * @return
  136. * @throws Exception
  137. */
  138. @RequestMapping(value = "/cards/{id}", method = RequestMethod.GET)
  139. @ApiOperation(value = "根据卡号和卡类型查找卡")
  140. public Envelop getCard(
  141. @ApiParam(name = "id", value = "卡号", defaultValue = "")
  142. @PathVariable(value = "id") String id,
  143. @ApiParam(name = "card_type", value = "卡类别", defaultValue = "")
  144. @RequestParam(value = "card_type") String cardType) throws Exception {
  145. MAbstractCard cardInfo = cardClient.getCard(id, cardType);
  146. CardDetailModel detailModel = convertToModel(cardInfo,CardDetailModel.class);
  147. if(detailModel==null)
  148. {
  149. return failed("数据获取失败!");
  150. }
  151. detailModel.setCreateDate(DateToString(cardInfo.getCreateDate(), AgAdminConstants.DateFormat));
  152. detailModel.setReleaseDate(DateToString(cardInfo.getReleaseDate(),AgAdminConstants.DateTimeFormat));
  153. detailModel.setValidityDateBegin(DateToString(cardInfo.getValidityDateBegin(),AgAdminConstants.DateTimeFormat));
  154. detailModel.setValidityDateEnd(DateToString(cardInfo.getValidityDateEnd(),AgAdminConstants.DateTimeFormat));
  155. MConventionalDict dict=null;
  156. if (!StringUtils.isEmpty(detailModel.getCardType())) {
  157. dict = conventionalDictEntryClient.getCardType(detailModel.getCardType());
  158. detailModel.setTypeName(dict.getValue());
  159. }
  160. if (!StringUtils.isEmpty(detailModel.getStatus())) {
  161. dict = conventionalDictEntryClient.getCardStatus(detailModel.getStatus());
  162. detailModel.setStatusName(dict.getValue());
  163. }
  164. if (!StringUtils.isEmpty(detailModel.getReleaseOrg())){
  165. MOrganization organization = orgClient.getOrg(detailModel.getReleaseOrg());
  166. detailModel.setReleaseOrgName(organization.getFullName());
  167. }
  168. return success(detailModel);
  169. }
  170. /**
  171. * 根据卡编号和卡类型解绑卡
  172. *
  173. * @param id
  174. * @param cardType
  175. * @return
  176. * @throws Exception
  177. */
  178. @RequestMapping(value = "/cards/detach/{id}", method = RequestMethod.PUT)
  179. @ApiOperation(value = "根据卡号和卡类型解绑卡")
  180. public boolean detachCard(
  181. @ApiParam(name = "id", value = "卡号", defaultValue = "")
  182. @PathVariable(value = "id") String id,
  183. @ApiParam(name = "card_type", value = "卡类别", defaultValue = "")
  184. @RequestParam(value = "card_type") String cardType) throws Exception {
  185. return cardClient.detachCard(id, cardType);
  186. }
  187. /**
  188. * 根据卡编号,身份证号,卡类型绑定卡
  189. *
  190. * @param id
  191. * @param idCardNo
  192. * @param cardType
  193. * @return
  194. * @throws Exception
  195. */
  196. @RequestMapping(value = "/cards/attach/{id}", method = RequestMethod.PUT)
  197. @ApiOperation(value = "根据卡编号(卡主键,卡的唯一标识),身份证号,卡类型绑定卡")
  198. public boolean attachCard(
  199. @ApiParam(name = "id", value = "卡号", defaultValue = "")
  200. @PathVariable(value = "id") String id,
  201. @ApiParam(name = "id_card_no", value = "身份证号", defaultValue = "")
  202. @RequestParam(value = "id_card_no") String idCardNo,
  203. @ApiParam(name = "card_type", value = "卡类别", defaultValue = "")
  204. @RequestParam(value = "card_type") String cardType) throws Exception {
  205. return cardClient.attachCard(id, idCardNo, cardType);
  206. }
  207. }