|
@@ -0,0 +1,167 @@
|
|
|
+package thyyxxk.wxservice_server.controller;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
|
|
|
+import thyyxxk.wxservice_server.constant.AgnterRelations;
|
|
|
+import thyyxxk.wxservice_server.dao.ChronicDiseaseDao;
|
|
|
+import thyyxxk.wxservice_server.entity.PureCodeName;
|
|
|
+import thyyxxk.wxservice_server.entity.ResultVo;
|
|
|
+import thyyxxk.wxservice_server.entity.chronicdisease.CrmPatientMi;
|
|
|
+import thyyxxk.wxservice_server.utils.*;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/chronicDisease")
|
|
|
+public class ChronicDiseaseController {
|
|
|
+ private final ChronicDiseaseDao dao;
|
|
|
+ @Value("${chronicUrl}")
|
|
|
+ private String chronicUrl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public ChronicDiseaseController(ChronicDiseaseDao dao) {
|
|
|
+ this.dao = dao;
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/getCrmDictionary")
|
|
|
+ public ResultVo<Map<String, List<PureCodeName>>> getCrmDictionary() {
|
|
|
+ ResultVo<Map<String, List<PureCodeName>>> response = new RestTemplate()
|
|
|
+ .getForObject(chronicUrl + "/getCrmDictionary", ResultVo.class);
|
|
|
+ if (null == response) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ if (response.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, response.getMessage());
|
|
|
+ }
|
|
|
+ Map<String, List<PureCodeName>> map = response.getData();
|
|
|
+ map.remove("getOccupation");
|
|
|
+ map.remove("getCountry");
|
|
|
+ map.remove("getNation");
|
|
|
+ map.remove("getProvince");
|
|
|
+ map.remove("getCity");
|
|
|
+ map.remove("getArea");
|
|
|
+ return ResultVoUtil.success(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/selectCrmPatientMiByCode")
|
|
|
+ public ResultVo<CrmPatientMi> selectCrmPatientMiByCode(@RequestParam("keyCode") String keyCode) {
|
|
|
+ ResultVo<LinkedHashMap<String, Object>> response = new RestTemplate().getForObject(
|
|
|
+ chronicUrl + "/selectCrmPatientMiByCode?keyCode=" + keyCode, ResultVo.class);
|
|
|
+ log.info("【{}】获取慢病信息:{}", keyCode, JSONObject.toJSON(response));
|
|
|
+ if (null == response || response.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
|
+ return getBasePatientInfo(keyCode);
|
|
|
+ }
|
|
|
+ LinkedHashMap map = response.getData();
|
|
|
+ String json = JSON.toJSONString(map);
|
|
|
+ CrmPatientMi crmPatientMi = JSONObject.parseObject(json, CrmPatientMi.class);
|
|
|
+ crmPatientMi.setSexLabel(filterSex(crmPatientMi.getSex()));
|
|
|
+ crmPatientMi.setTypeLabel(filterPType(crmPatientMi.getPType()));
|
|
|
+ crmPatientMi.setChronicDiseaseTypeLabel(
|
|
|
+ filterChronicDiseaseType(crmPatientMi.getChronicDiseaseType()));
|
|
|
+ AgnterRelations relation = AgnterRelations.get(crmPatientMi.getRelCode());
|
|
|
+ if (null != relation) {
|
|
|
+ crmPatientMi.setRelLabel(relation.getName());
|
|
|
+ }
|
|
|
+ if (null != crmPatientMi.getLastDate()) {
|
|
|
+ crmPatientMi.setLastDate(crmPatientMi.getLastDate().split(" ")[0]);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success(crmPatientMi);
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResultVo<CrmPatientMi> getBasePatientInfo(String patientId) {
|
|
|
+ CrmPatientMi crmPatientMi = dao.selectPatientBaseInfo(patientId);
|
|
|
+ if (null == crmPatientMi) {
|
|
|
+ return ResultVoUtil.success(new CrmPatientMi());
|
|
|
+ }
|
|
|
+ int age = IdCardUtil.getAgeByIdCard(crmPatientMi.getSocialNo());
|
|
|
+ crmPatientMi.setAge(age == 0 ? null : age);
|
|
|
+ crmPatientMi.setSexLabel(filterSex(crmPatientMi.getSex()));
|
|
|
+ return ResultVoUtil.success(crmPatientMi);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/saveCrmPatientMi")
|
|
|
+ public ResultVo<String> saveCrmPatientMi(@RequestBody CrmPatientMi params) {
|
|
|
+ if (null == params.getVisitTimes()) {
|
|
|
+ params.setVisitTimes(0);
|
|
|
+ }
|
|
|
+ if (null == params.getVisitDate()) {
|
|
|
+ params.setVisitDate(DateUtil.formatDatetime(new Date()));
|
|
|
+ }
|
|
|
+ JSONObject response = new RestTemplate()
|
|
|
+ .postForObject(chronicUrl + "/saveCrmPatientMi", params, JSONObject.class);
|
|
|
+ log.info("提交慢病患者信息:\n参数:{}\n结果:{}", JSONObject.toJSON(params), response);
|
|
|
+ if (null == response) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ if (response.getInteger("code") != 200) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, response.getString("message"));
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success(response.getString("data"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private String filterSex(String sex) {
|
|
|
+ if (StringUtil.isBlank(sex)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ switch (sex) {
|
|
|
+ case "1":
|
|
|
+ return "男";
|
|
|
+ case "2":
|
|
|
+ return "女";
|
|
|
+ default:
|
|
|
+ return "未知";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String filterPType(String pType) {
|
|
|
+ if (StringUtil.isBlank(pType)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ switch (pType) {
|
|
|
+ case "1":
|
|
|
+ return "门诊";
|
|
|
+ case "2":
|
|
|
+ return "住院";
|
|
|
+ case "3":
|
|
|
+ return "健康体检";
|
|
|
+ case "4":
|
|
|
+ return "慢病中心";
|
|
|
+ case "5":
|
|
|
+ return "医联体";
|
|
|
+ case "9":
|
|
|
+ return "其他途径";
|
|
|
+ default:
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String filterChronicDiseaseType(String type) {
|
|
|
+ if (StringUtil.isBlank(type)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ switch (type) {
|
|
|
+ case "01":
|
|
|
+ return "糖尿病";
|
|
|
+ case "02":
|
|
|
+ return "高血压";
|
|
|
+ case "03":
|
|
|
+ return "慢阻肺";
|
|
|
+ case "04":
|
|
|
+ return "脑卒中";
|
|
|
+ case "05":
|
|
|
+ return "肿瘤";
|
|
|
+ default:
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|