DoctorEndPoint.java 30 KB

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