DoctorEndPoint.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. package com.yihu.ehr.basic.user.controller;
  2. import com.fasterxml.jackson.core.type.TypeReference;
  3. import com.yihu.ehr.basic.fileresource.service.FileResource;
  4. import com.yihu.ehr.basic.fileresource.service.XFileResourceRepository;
  5. import com.yihu.ehr.basic.getui.ConstantUtil;
  6. import com.yihu.ehr.basic.org.model.OrgDept;
  7. import com.yihu.ehr.basic.org.model.OrgMemberRelation;
  8. import com.yihu.ehr.basic.org.model.Organization;
  9. import com.yihu.ehr.basic.org.service.OrgDeptService;
  10. import com.yihu.ehr.basic.org.service.OrgMemberRelationService;
  11. import com.yihu.ehr.basic.org.service.OrgService;
  12. import com.yihu.ehr.basic.patient.service.DemographicService;
  13. import com.yihu.ehr.basic.user.entity.Doctors;
  14. import com.yihu.ehr.basic.user.entity.User;
  15. import com.yihu.ehr.basic.user.service.DoctorService;
  16. import com.yihu.ehr.basic.user.service.RoleUserService;
  17. import com.yihu.ehr.basic.user.service.RolesService;
  18. import com.yihu.ehr.basic.user.service.UserService;
  19. import com.yihu.ehr.basic.util.IdcardValidator;
  20. import com.yihu.ehr.commons.constants.BasicServiceApi;
  21. import com.yihu.ehr.constants.ApiVersion;
  22. import com.yihu.ehr.constants.ServiceApi;
  23. import com.yihu.ehr.controller.EnvelopRestEndPoint;
  24. import com.yihu.ehr.entity.patient.DemographicInfo;
  25. import com.yihu.ehr.model.org.MOrgDeptJson;
  26. import com.yihu.ehr.model.user.MDoctor;
  27. import com.yihu.ehr.util.datetime.DateUtil;
  28. import com.yihu.ehr.util.id.BizObject;
  29. import com.yihu.ehr.util.phonics.PinyinUtil;
  30. import com.yihu.ehr.util.rest.Envelop;
  31. import io.swagger.annotations.Api;
  32. import io.swagger.annotations.ApiOperation;
  33. import io.swagger.annotations.ApiParam;
  34. import org.apache.commons.codec.digest.DigestUtils;
  35. import org.slf4j.Logger;
  36. import org.slf4j.LoggerFactory;
  37. import org.springframework.beans.factory.annotation.Autowired;
  38. import org.springframework.beans.factory.annotation.Value;
  39. import org.springframework.http.MediaType;
  40. import org.springframework.transaction.annotation.Propagation;
  41. import org.springframework.transaction.annotation.Transactional;
  42. import org.springframework.util.StringUtils;
  43. import org.springframework.web.bind.annotation.*;
  44. import javax.servlet.http.HttpServletRequest;
  45. import javax.servlet.http.HttpServletResponse;
  46. import java.text.ParseException;
  47. import java.util.ArrayList;
  48. import java.util.Date;
  49. import java.util.List;
  50. import java.util.Map;
  51. /**
  52. * 2017-02-04 add by hzp
  53. */
  54. @RestController
  55. @RequestMapping(ApiVersion.Version1_0)
  56. @Api(value = "doctors", description = "医生管理接口", tags = {"基础信息-医生管理"})
  57. public class DoctorEndPoint extends EnvelopRestEndPoint {
  58. Logger logger = LoggerFactory.getLogger(DoctorEndPoint.class);
  59. @Autowired
  60. DoctorService doctorService;
  61. @Autowired
  62. private UserService userManager;
  63. @Autowired
  64. private OrgDeptService orgDeptService;
  65. @Autowired
  66. private OrgMemberRelationService relationService;
  67. @Value("${default.password}")
  68. private String default_password = "12345678";
  69. @Autowired
  70. private DemographicService demographicService;
  71. @Autowired
  72. private OrgService orgService;
  73. @Autowired
  74. private RolesService rolesService;
  75. @Autowired
  76. private RoleUserService roleUserService;
  77. @Autowired
  78. private IdcardValidator idcardValidator;
  79. @Autowired
  80. private XFileResourceRepository resourceRepository;
  81. @Value("${fast-dfs.public-server}")
  82. private String fastDfsPublicServers;
  83. @RequestMapping(value = ServiceApi.Doctors.Doctors, method = RequestMethod.GET)
  84. @ApiOperation(value = "获取医生列表", notes = "根据查询条件获取医生列表在前端表格展示")
  85. public List<MDoctor> searchDoctors(
  86. @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "")
  87. @RequestParam(value = "fields", required = false) String fields,
  88. @ApiParam(name = "filters", value = "过滤器,为空检索所有条件", defaultValue = "")
  89. @RequestParam(value = "filters", required = false) String filters,
  90. @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "")
  91. @RequestParam(value = "sorts", required = false) String sorts,
  92. @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
  93. @RequestParam(value = "size", required = false) int size,
  94. @ApiParam(name = "page", value = "页码", defaultValue = "1")
  95. @RequestParam(value = "page", required = false) int page,
  96. @ApiParam(name = "orgCode", value = "机构编码", defaultValue = "")
  97. @RequestParam(value = "orgCode", required = false) String orgCode,
  98. HttpServletRequest request,
  99. HttpServletResponse response) throws ParseException {
  100. List<Doctors> doctorsList = new ArrayList<>();
  101. if (!StringUtils.isEmpty(orgCode)) {
  102. String[] orgCodes = orgCode.split(",");
  103. String filter = "";
  104. if (!StringUtils.isEmpty(filters)) {
  105. filter = filters.substring(filters.indexOf("?") + 1, filters.indexOf(";"));
  106. }
  107. doctorsList = doctorService.searchDoctors(filter, orgCodes, page, size);
  108. Long totalCount = doctorService.getDoctorsCount(filter, orgCodes);
  109. pagedResponse(request, response, totalCount, page, size);
  110. } else {
  111. doctorsList = doctorService.search(fields, filters, sorts, page, size);
  112. pagedResponse(request, response, doctorService.getCount(filters), page, size);
  113. }
  114. for (Doctors doctors : doctorsList) {
  115. User user = userManager.getUserByDoctorId(doctors.getId().toString());
  116. if (user != null) {
  117. doctors.setUserId(user.getId());
  118. }
  119. }
  120. return (List<MDoctor>) convertToModels(doctorsList, new ArrayList<MDoctor>(doctorsList.size()), MDoctor.class, fields);
  121. }
  122. @RequestMapping(value = ServiceApi.Doctors.Doctors, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  123. @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  124. @ApiOperation(value = "创建医生", notes = "创建医生信息")
  125. public MDoctor createDoctor(
  126. @ApiParam(name = "doctor_json_data", value = "", defaultValue = "")
  127. @RequestBody String doctoJsonData,
  128. @ApiParam(name = "model", value = "所属机构部门关系", defaultValue = "")
  129. @RequestParam("model") String model) throws Exception {
  130. List<MOrgDeptJson> orgDeptJsonList = objectMapper.readValue(model, new TypeReference<List<MOrgDeptJson>>() {
  131. });
  132. MOrgDeptJson mOrgDeptJson = orgDeptJsonList.get(0);
  133. Organization organization = orgService.getOrgById(mOrgDeptJson.getOrgId());
  134. OrgDept orgDept = orgDeptService.searchBydeptId(Integer.parseInt(mOrgDeptJson.getDeptIds().split(",")[0]));
  135. Doctors doctor = toEntity(doctoJsonData, Doctors.class);
  136. if (!idcardValidator.isValidatedAllIdcard(doctor.getIdCardNo())){
  137. return null;
  138. }
  139. doctor.setStatus("1");
  140. doctor.setPyCode(PinyinUtil.getPinYinHeadChar(doctor.getName(), false));
  141. doctor.setOrgId(organization.getId().toString());
  142. doctor.setOrgCode(organization.getOrgCode());
  143. doctor.setOrgFullName(organization.getFullName());
  144. doctor.setDeptName(orgDept.getName());
  145. doctor.setInsertTime(new Date());
  146. Doctors d = doctorService.save(doctor);
  147. String idCardNo = d.getIdCardNo();
  148. User user = null;
  149. if (!StringUtils.isEmpty(idCardNo)) {
  150. //通过身份证 判断居民是否存在
  151. user = userManager.getUserByIdCardNo(idCardNo);
  152. }
  153. String defaultPassword = "";
  154. if (user == null) {
  155. user = new User();
  156. user.setId(getObjectId(BizObject.User));
  157. user.setCreateDate(new Date());
  158. if (!StringUtils.isEmpty(doctor.getIdCardNo()) && doctor.getIdCardNo().length() > 9) {
  159. defaultPassword = doctor.getIdCardNo().substring(doctor.getIdCardNo().length() - 8);
  160. user.setPassword(DigestUtils.md5Hex(defaultPassword));
  161. } else {
  162. user.setPassword(DigestUtils.md5Hex(default_password));
  163. }
  164. if (StringUtils.isEmpty(d.getRoleType())) {
  165. user.setUserType("5");
  166. } else {
  167. user.setUserType(d.getRoleType());
  168. }
  169. user.setIdCardNo(d.getIdCardNo());
  170. user.setDoctorId(d.getId().toString());
  171. user.setEmail(d.getEmail());
  172. user.setGender(d.getSex());
  173. user.setTelephone(d.getPhone());
  174. user.setLoginCode(d.getIdCardNo());
  175. user.setRealName(d.getName());
  176. user.setProvinceId(0);
  177. user.setCityId(0);
  178. user.setAreaId(0);
  179. user.setActivated(true);
  180. user.setImgRemotePath(d.getPhoto());
  181. user.setUserType(ConstantUtil.DOCTORUSERTYPEID);
  182. user = userManager.saveUser(user);
  183. //卫生人员初始化授权
  184. userManager.initializationAuthorization(Integer.valueOf(ConstantUtil.DOCTORUSERTYPEID),user.getId());
  185. } else {
  186. //todo 是否修改user信息
  187. //......
  188. defaultPassword = user.getPassword();
  189. }
  190. d.setUserId(user.getId());
  191. d.setInsertTime(new Date());
  192. d = doctorService.save(d);
  193. //创建居民
  194. DemographicInfo demographicInfo = new DemographicInfo();
  195. if (!StringUtils.isEmpty(doctor.getIdCardNo()) && doctor.getIdCardNo().length() > 9) {
  196. defaultPassword = doctor.getIdCardNo().substring(doctor.getIdCardNo().length() - 8);
  197. demographicInfo.setPassword(DigestUtils.md5Hex(defaultPassword));
  198. } else {
  199. demographicInfo.setPassword(DigestUtils.md5Hex(default_password));
  200. }
  201. demographicInfo.setRegisterTime(new Date());
  202. demographicInfo.setIdCardNo(d.getIdCardNo());
  203. demographicInfo.setName(d.getName());
  204. demographicInfo.setTelephoneNo("{\"联系电话\":\"" + d.getPhone() + "\"}");
  205. demographicInfo.setGender(d.getSex());
  206. demographicService.savePatient(demographicInfo);
  207. //创建用户与机构关系
  208. orgMemberRelationInfo(orgDeptJsonList, user, d);
  209. //TODO 角色有可能没有关联机构,此部分需要待确认 根据机构获取医生角色id,保存到role_users表中,appId是健康上饶APP对应的id:WYo0l73F8e
  210. // List<String> orgList = orgService.getOrgList(orgDeptJsonList);
  211. // if (null != orgList && orgList.size() > 0) {
  212. // List<Roles> rolesList = rolesService.findByCodeAndAppIdAndOrgCode(orgList, "WYo0l73F8e", "Doctor");
  213. // if (null != rolesList && rolesList.size() > 0) {
  214. // roleUserService.batchCreateRoleUsersRelation(user.getId(), String.valueOf(rolesList.get(0).getId()));
  215. // } else {
  216. // // 不存在 则往角色表中插入该应用的医生角色
  217. // Roles roles = new Roles();
  218. // roles.setCode("Doctor");
  219. // roles.setName("医生");
  220. // roles.setAppId("WYo0l73F8e");
  221. // roles.setType("1");
  222. // roles.setOrgCode(orgList.get(0));
  223. // roles = rolesService.save(roles);
  224. // roleUserService.batchCreateRoleUsersRelation(user.getId(), String.valueOf(roles.getId()));
  225. // }
  226. // }
  227. return convertToModel(doctor, MDoctor.class);
  228. }
  229. @RequestMapping(value = ServiceApi.Doctors.Doctors, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  230. @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  231. @ApiOperation(value = "修改医生", notes = "重新绑定医生信息")
  232. public MDoctor updateDoctor(
  233. @ApiParam(name = "doctor_json_data", value = "", defaultValue = "")
  234. @RequestBody String doctoJsonData,
  235. @ApiParam(name = "model", value = "json数据模型", defaultValue = "")
  236. @RequestParam("model") String model) throws Exception {
  237. List<MOrgDeptJson> orgDeptJsonList = objectMapper.readValue(model, new TypeReference<List<MOrgDeptJson>>() {
  238. });
  239. MOrgDeptJson mOrgDeptJson = orgDeptJsonList.get(0);
  240. Organization organization = orgService.getOrgById(mOrgDeptJson.getOrgId());
  241. OrgDept orgDept = orgDeptService.searchBydeptId(Integer.parseInt(mOrgDeptJson.getDeptIds().split(",")[0]));
  242. Doctors doctors = toEntity(doctoJsonData, Doctors.class);
  243. doctors.setOrgId(organization.getId().toString());
  244. doctors.setOrgCode(organization.getOrgCode());
  245. doctors.setOrgFullName(organization.getFullName());
  246. doctors.setDeptName(orgDept.getName());
  247. doctors.setUpdateTime(new Date());
  248. doctorService.save(doctors);
  249. //同时修改用户表
  250. User user = userManager.getUserByIdCardNo(doctors.getIdCardNo());
  251. if (!StringUtils.isEmpty(user)) {
  252. user.setRealName(doctors.getName());
  253. user.setGender(doctors.getSex());
  254. user.setTelephone(doctors.getPhone());
  255. user.setImgRemotePath(doctors.getPhoto());
  256. userManager.save(user);
  257. }
  258. //修改居民
  259. DemographicInfo demographicInfo = demographicService.getDemographicInfoByIdCardNo(doctors.getIdCardNo());
  260. if (!StringUtils.isEmpty(demographicInfo)) {
  261. demographicInfo.setName(doctors.getName());
  262. demographicInfo.setGender(doctors.getSex());
  263. demographicInfo.setTelephoneNo("{\"联系电话\":\"" + doctors.getPhone() + "\"}");
  264. demographicService.save(demographicInfo);
  265. }
  266. //修改用户与机构关系
  267. orgMemberRelationInfo(orgDeptJsonList, user, doctors);
  268. return convertToModel(doctors, MDoctor.class);
  269. }
  270. @RequestMapping(value = ServiceApi.Doctors.DoctorsExistence, method = RequestMethod.GET)
  271. @ApiOperation(value = "判断医生code是否存在")
  272. public boolean isDoctorCodeExists(
  273. @ApiParam(name = "doctor_code", value = "医生code", defaultValue = "")
  274. @PathVariable(value = "doctor_code") String doctorCode) {
  275. return doctorService.getByCode(doctorCode) != null;
  276. }
  277. @RequestMapping(value = ServiceApi.Doctors.DoctorAdmin, method = RequestMethod.GET)
  278. @ApiOperation(value = "根据id获取获取医生信息")
  279. public MDoctor getDoctor(
  280. @ApiParam(name = "doctor_id", value = "", defaultValue = "")
  281. @PathVariable(value = "doctor_id") Long doctorId) {
  282. Doctors doctors = doctorService.getDoctor(doctorId);
  283. MDoctor doctorModel = convertToModel(doctors, MDoctor.class);
  284. return doctorModel;
  285. }
  286. @RequestMapping(value = ServiceApi.Doctors.DoctorAdmin, method = RequestMethod.DELETE)
  287. @ApiOperation(value = "删除医生", notes = "根据id删除医生")
  288. public boolean deleteDoctor(
  289. @ApiParam(name = "doctor_id", value = "医生编号", defaultValue = "")
  290. @PathVariable(value = "doctor_id") Long doctorId) throws Exception {
  291. doctorService.deleteDoctor(doctorId);
  292. return true;
  293. }
  294. @RequestMapping(value = ServiceApi.Doctors.DoctorAdmin, method = RequestMethod.PUT)
  295. @ApiOperation(value = "改变医生状态", notes = "根据id更新医生")
  296. public boolean updDoctorStatus(
  297. @ApiParam(name = "doctor_id", value = "id", defaultValue = "")
  298. @PathVariable(value = "doctor_id") Long doctorId,
  299. @ApiParam(name = "status", value = "状态", defaultValue = "")
  300. @RequestParam(value = "status") String status) throws Exception {
  301. doctorService.updDoctorStatus(doctorId, status);
  302. return true;
  303. }
  304. @RequestMapping(value = ServiceApi.Doctors.DoctorPhoneExistence, method = RequestMethod.POST)
  305. @ApiOperation("获取已存在电话号码")
  306. public List idExistence(
  307. @ApiParam(name = "phones", value = "phones", defaultValue = "")
  308. @RequestBody String phones) throws Exception {
  309. List existPhones = doctorService.idExist(toEntity(phones, String[].class));
  310. return existPhones;
  311. }
  312. @RequestMapping(value = ServiceApi.Doctors.DoctorBatch, method = RequestMethod.POST)
  313. @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  314. @ApiOperation("批量导入医生")
  315. public boolean createDoctorsPatch(
  316. @ApiParam(name = "doctors", value = "医生JSON", defaultValue = "")
  317. @RequestBody String doctors) throws Exception {
  318. List<Map<String, Object>> doctorMapList = objectMapper.readValue(doctors, new TypeReference<List>() {
  319. });
  320. String idCardNosStr = doctorService.addDoctorBatch(doctorMapList);
  321. List list = new ArrayList<>();
  322. if (!"".equals(idCardNosStr)) {
  323. idCardNosStr = "[" + idCardNosStr.substring(0, idCardNosStr.length() - 1) + "]";
  324. list = doctorService.getIdByIdCardNos(toEntity(idCardNosStr, String[].class));
  325. }
  326. Doctors d;
  327. for (int i = 0; i < list.size(); i++) {
  328. Object[] objectList = (Object[]) list.get(i);
  329. if (null != objectList) {
  330. d = new Doctors();
  331. //INSERT INTO users(login_code, real_name, gender, tech_title, email, telephone, password,doctor_id
  332. d.setId(Long.parseLong(objectList[0].toString()));
  333. d.setName(objectList[3].toString());
  334. d.setCode(objectList[22].toString());//卫统没有医生code
  335. d.setSex(objectList[5].toString());
  336. if (null != objectList[7]) {
  337. d.setSkill(objectList[7].toString());
  338. }
  339. if (null != objectList[9]) {
  340. d.setEmail(objectList[9].toString());
  341. }
  342. if (null != objectList[10]) {
  343. d.setPhone(objectList[10].toString());
  344. }
  345. d.setIdCardNo(objectList[22].toString());
  346. //根据身份证和电话号码,判断账户表中是否存在该用户。若存在 将用户表与医生表关联;若不存在,为该医生初始化账户。
  347. StringBuffer stringBuffer = new StringBuffer();
  348. if (!StringUtils.isEmpty(d.getIdCardNo())) {
  349. stringBuffer.append("idCardNo=" + d.getIdCardNo() + ";");
  350. }
  351. if (!StringUtils.isEmpty(d.getPhone())) {
  352. stringBuffer.append("telephone=" + d.getPhone() + ";");
  353. }
  354. String filters = stringBuffer.toString();
  355. List<User> userList = userManager.search("", filters, "", 1, 1);
  356. String userId = "";
  357. //若存在 将用户表与医生表关联
  358. if (null != userList && userList.size() > 0) {
  359. for (User user : userList) {
  360. user.setDoctorId(String.valueOf(d.getId()));
  361. user.setUserType(ConstantUtil.DOCTORUSERTYPEID);
  362. user = userManager.saveUser(user);
  363. userId = user.getId();
  364. }
  365. } else {
  366. //若不存在,为该医生初始化账户。
  367. User user = new User();
  368. user.setId(getObjectId(BizObject.User));
  369. user.setLoginCode(d.getIdCardNo());
  370. user.setTelephone(d.getPhone());
  371. user.setRealName(d.getName());
  372. user.setIdCardNo(d.getIdCardNo());
  373. user.setGender(d.getSex());
  374. user.setTechTitle(d.getSkill());
  375. user.setEmail(d.getEmail());
  376. String defaultPassword = "";
  377. if (!StringUtils.isEmpty(d.getIdCardNo()) && d.getIdCardNo().length() > 9) {
  378. defaultPassword = d.getIdCardNo().substring(d.getIdCardNo().length() - 8);
  379. user.setPassword(DigestUtils.md5Hex(defaultPassword));
  380. } else {
  381. user.setPassword(DigestUtils.md5Hex(default_password));
  382. }
  383. user.setCreateDate(DateUtil.strToDate(DateUtil.getNowDateTime()));
  384. user.setActivated(true);
  385. user.setUserType(ConstantUtil.DOCTORUSERTYPEID);
  386. user.setDoctorId(d.getId() + "");
  387. user.setProvinceId(0);
  388. user.setCityId(0);
  389. user.setAreaId(0);
  390. user = userManager.saveUser(user);
  391. userId = user.getId();
  392. }
  393. //卫生人员初始化授权
  394. userManager.initializationAuthorization(Integer.valueOf(ConstantUtil.DOCTORUSERTYPEID),userId);
  395. String orgId = "";
  396. if (!StringUtils.isEmpty(objectList[23])) {
  397. orgId = objectList[23].toString();
  398. }
  399. String deptCode = "";
  400. if (!StringUtils.isEmpty(objectList[37])) {
  401. deptCode = objectList[37].toString();
  402. }
  403. int deptId = orgDeptService.getOrgDeptByOrgIdAndDeptCode(orgId, deptCode);
  404. String deptName="";
  405. if (!StringUtils.isEmpty(objectList[27])) {
  406. deptName =objectList[27].toString();
  407. }
  408. OrgMemberRelation memberRelation = new OrgMemberRelation();
  409. // 同步科室医生信息到福州总部,随后返回总部的科室医生信息
  410. // 对 主任医师、副主任医师、主治医师、医师 才做同步
  411. Map<String, Object> deptDoc = doctorService.syncDoctor(d, String.valueOf(orgId), deptName);
  412. if ("10000".equals(deptDoc.get("Code").toString())) {
  413. memberRelation.setJkzlUserId(deptDoc.get("userId").toString());
  414. memberRelation.setJkzlDoctorUid(deptDoc.get("doctorUid").toString());
  415. memberRelation.setJkzlDoctorSn(deptDoc.get("doctorSn").toString());
  416. memberRelation.setJkzlHosDeptId(deptDoc.get("hosDeptId").toString());
  417. }
  418. memberRelation.setOrgId(orgId);
  419. if (!StringUtils.isEmpty(objectList[25])) {
  420. memberRelation.setOrgName(objectList[25].toString());
  421. }
  422. memberRelation.setDeptId(deptId);//卫统数据-机构没有关联科室,卫生人员提供的科室代码在系统字典中管理--考虑是否改为字典编码值
  423. memberRelation.setDeptName(deptName);
  424. memberRelation.setUserId(String.valueOf(userId));
  425. memberRelation.setUserName(d.getName());
  426. memberRelation.setStatus(0);
  427. relationService.save(memberRelation);
  428. }
  429. }
  430. return true;
  431. }
  432. @RequestMapping(value = ServiceApi.Doctors.DoctorOnePhoneExistence, method = RequestMethod.GET)
  433. @ApiOperation("根据过滤条件判断是否存在")
  434. public boolean isExistence(
  435. @ApiParam(name = "filters", value = "filters", defaultValue = "")
  436. @RequestParam(value = "filters") String filters) throws Exception {
  437. List<Doctors> doctor = doctorService.search("", filters, "", 1, 1);
  438. return doctor != null && doctor.size() > 0;
  439. }
  440. @RequestMapping(value = ServiceApi.Doctors.DoctorEmailExistence, method = RequestMethod.POST)
  441. @ApiOperation("获取已存在邮箱")
  442. public List emailsExistence(
  443. @ApiParam(name = "emails", value = "emails", defaultValue = "")
  444. @RequestBody String emails) throws Exception {
  445. List existPhones = doctorService.emailsExistence(toEntity(emails, String[].class));
  446. return existPhones;
  447. }
  448. @RequestMapping(value = ServiceApi.Doctors.DoctorsIdCardNoExistence, method = RequestMethod.GET)
  449. @ApiOperation(value = "判断身份证号码是否存在")
  450. public boolean isCardNoExists(
  451. @ApiParam(name = "doctor_idCardNo", value = "身份证号码", defaultValue = "")
  452. @PathVariable(value = "doctor_idCardNo") String idCardNo) {
  453. return doctorService.getByIdCardNo(idCardNo) != null;
  454. }
  455. @RequestMapping(value = ServiceApi.Doctors.DoctoridCardNoExistence, method = RequestMethod.POST)
  456. @ApiOperation("获取已存在身份证号码")
  457. public List idCardNoExistence(
  458. @ApiParam(name = "idCardNos", value = "idCardNos", defaultValue = "")
  459. @RequestBody String idCardNos) throws Exception {
  460. List existidCardNos = doctorService.idCardNosExist(toEntity(idCardNos, String[].class));
  461. return existidCardNos;
  462. }
  463. @RequestMapping(value = "/getStatisticsDoctorsByRoleType", method = RequestMethod.GET)
  464. @ApiOperation("根据角色获取医院、医生总数")
  465. public List getStatisticsDoctorsByRoleType(
  466. @ApiParam(name = "roleType", value = "roleType", defaultValue = "")
  467. @RequestParam(value = "roleType") String roleType) throws Exception {
  468. List<Object> statisticsDoctors = doctorService.getStatisticsDoctorsByRoleType(roleType);
  469. return statisticsDoctors;
  470. }
  471. //创建用户与机构的关联
  472. private void orgMemberRelationInfo(List<MOrgDeptJson> orgDeptJsonList, User user, Doctors doctor) throws Exception {
  473. if (null != orgDeptJsonList && orgDeptJsonList.size() > 0) {
  474. String[] orgIds = new String[orgDeptJsonList.size()];
  475. for (int i = 0; i < orgDeptJsonList.size(); i++) {
  476. orgIds[i] = orgDeptJsonList.get(i).getOrgId();
  477. }
  478. relationService.updateByOrgId(orgIds, user.getId());
  479. }
  480. for (MOrgDeptJson orgDeptJson : orgDeptJsonList) {
  481. Organization organization = orgService.getOrgById(orgDeptJson.getOrgId());
  482. String deptIds = orgDeptJson.getDeptIds();
  483. if (!StringUtils.isEmpty(deptIds)) {
  484. String[] deptIdArr = deptIds.split(",");
  485. for (String deptId : deptIdArr) {
  486. OrgDept orgDept = orgDeptService.searchBydeptId(Integer.parseInt(deptId));
  487. if (null != organization && null != orgDept) {
  488. OrgMemberRelation memberRelation = new OrgMemberRelation();
  489. // 同步科室医生信息到福州总部,随后返回总部的科室医生信息
  490. // 对 主任医师、副主任医师、主治医师、医师 才做同步
  491. if ("1".equals(doctor.getLczc()) || "2".equals(doctor.getLczc()) || "3".equals(doctor.getLczc()) || "4".equals(doctor.getLczc())) {
  492. Map<String, Object> deptDoc = doctorService.syncDoctor(doctor, orgDeptJson.getOrgId(), orgDept.getName());
  493. if ("10000".equals(deptDoc.get("Code").toString())) {
  494. memberRelation.setJkzlUserId(deptDoc.get("userId").toString());
  495. memberRelation.setJkzlDoctorUid(deptDoc.get("doctorUid").toString());
  496. memberRelation.setJkzlDoctorSn(deptDoc.get("doctorSn").toString());
  497. memberRelation.setJkzlHosDeptId(deptDoc.get("hosDeptId").toString());
  498. }
  499. }
  500. memberRelation.setOrgId(orgDeptJson.getOrgId());
  501. memberRelation.setOrgName(organization.getFullName());
  502. memberRelation.setDeptId(Integer.parseInt(deptId));
  503. memberRelation.setDeptName(orgDept.getName());
  504. memberRelation.setUserId(user.getId());
  505. memberRelation.setUserName(user.getRealName());
  506. memberRelation.setStatus(0);
  507. relationService.save(memberRelation);
  508. }
  509. }
  510. }
  511. }
  512. }
  513. @RequestMapping(value = ServiceApi.Doctors.DoctorOnlyUpdateD, method = RequestMethod.POST)
  514. @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  515. @ApiOperation(value = "更新医生信息,只更新医生表信息", notes = "只更新医生表信息")
  516. public Envelop updateDoctor(
  517. @ApiParam(name = "id", value = "", defaultValue = "")
  518. @RequestParam(value = "id", required = true) Long id,
  519. @ApiParam(name = "name", value = "", defaultValue = "")
  520. @RequestParam(value = "photo", required = false) String photo,
  521. @ApiParam(name = "skill", value = "", defaultValue = "")
  522. @RequestParam(value = "skill", required = false) String skill,
  523. @ApiParam(name = "officeTel", value = "", defaultValue = "")
  524. @RequestParam(value = "officeTel", required = false) String officeTel,
  525. @ApiParam(name = "workPortal", value = "", defaultValue = "")
  526. @RequestParam(value = "workPortal", required = false) String workPortal) throws Exception {
  527. Doctors doctors = doctorService.getDoctor(id);
  528. if (!StringUtils.isEmpty(photo)) {
  529. doctors.setPhoto(saveImgFileSource(photo));
  530. }
  531. if (!StringUtils.isEmpty(skill)) {
  532. doctors.setSkill(skill);
  533. }
  534. if (!StringUtils.isEmpty(officeTel)) {
  535. doctors.setOfficeTel(officeTel);
  536. }
  537. if (!StringUtils.isEmpty(workPortal)) {
  538. doctors.setWorkPortal(workPortal);
  539. }
  540. doctors.setUpdateTime(new Date());
  541. doctorService.save(doctors);
  542. //更改用户表里的头像
  543. User user = userManager.getUserByIdCardNo(doctors.getIdCardNo());
  544. if (!StringUtils.isEmpty(user)) {
  545. user.setImgRemotePath(doctors.getPhoto());
  546. userManager.save(user);
  547. }
  548. MDoctor doctorModel = convertToModel(doctors, MDoctor.class);
  549. doctorModel.setPhoto(photo);
  550. return success(doctorModel);
  551. }
  552. @RequestMapping(value = ServiceApi.Doctors.DoctorByIdCardNo, method = RequestMethod.GET)
  553. @ApiOperation(value = "根据身份证获取获取医生信息")
  554. public MDoctor getDoctorByIdCardNo(
  555. @ApiParam(name = "idCardNo", value = "", defaultValue = "")
  556. @PathVariable(value = "idCardNo") String idCardNo) {
  557. Doctors doctors = doctorService.getByIdCardNo(idCardNo);
  558. MDoctor doctorModel = convertToModel(doctors, MDoctor.class);
  559. return doctorModel;
  560. }
  561. /**
  562. * 健康上饶app,前端单独调用头像上传接口,将头像的路径传到后端。后端需要将路径保存到fileResource表中,再将id存到用户表
  563. * http://172.19.103.52:80/group1/M00/26/AF/rBFuWFr5BkWAZfYmAAAeqtdiKIY039.png
  564. *
  565. * @param path
  566. * @return
  567. */
  568. public String saveImgFileSource(String path) throws Exception {
  569. //获取用户头像,保存至file_resource
  570. FileResource fileResource = new FileResource();
  571. fileResource.setId(getObjectId(BizObject.FileResource));
  572. //获取groupName
  573. String[] str = path.split("/");
  574. String groupName = str[3];
  575. String remoteFileName = path.substring(path.indexOf(groupName)+ groupName.length()+1);
  576. //保存到resource表中
  577. fileResource.setStoragePath(groupName + ":" + remoteFileName);
  578. fileResource.setCreateDate(new Date());
  579. fileResource.setMime("user");
  580. fileResource.setObjectId("");
  581. return resourceRepository.save(fileResource).getId();
  582. }
  583. @RequestMapping(value = BasicServiceApi.Doctors.GetDoctorById, method = RequestMethod.GET)
  584. @ApiOperation(value = "补充健康上饶-根据id获取获取医生信息--因为头像的获取方式与基础信息管理不同,基础信息管理在app-admin处理了图片路径")
  585. public MDoctor GetDoctorById(
  586. @ApiParam(name = "doctor_id", value = "", defaultValue = "")
  587. @PathVariable(value = "doctor_id") Long doctorId) throws Exception{
  588. Doctors doctors = doctorService.getDoctor(doctorId);
  589. if(null!=doctors&&!StringUtils.isEmpty(doctors.getPhoto())){
  590. doctors.setPhoto(getImgPathByFileResource(doctors.getPhoto()));
  591. }
  592. MDoctor doctorModel = convertToModel(doctors, MDoctor.class);
  593. return doctorModel;
  594. }
  595. /**
  596. * 健康上饶app,根据fileResourceId获取图片路径
  597. *
  598. * @param fileResourceId
  599. * @return
  600. */
  601. public String getImgPathByFileResource(String fileResourceId) throws Exception {
  602. FileResource fileResource = resourceRepository.findById(fileResourceId);
  603. String path = null == fileResource ? "" : fileResource.getStoragePath();
  604. if (!StringUtils.isEmpty(path)) {
  605. return fastDfsPublicServers + "/" + path.replace(":", "/");
  606. }
  607. return "";
  608. }
  609. }