|
|
@@ -0,0 +1,277 @@
|
|
|
+package thyyxxk.webserver.service.chronicDisease;
|
|
|
+
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import thyyxxk.webserver.config.exception.ExceptionEnum;
|
|
|
+import thyyxxk.webserver.constants.YbTjConstant;
|
|
|
+import thyyxxk.webserver.dao.his.chronicDisease.ChronicDiseaseDao;
|
|
|
+import thyyxxk.webserver.dao.his.chronicDisease.CrmPatientMiDao;
|
|
|
+import thyyxxk.webserver.dao.his.chronicDisease.CrmPatientTzxxDao;
|
|
|
+import thyyxxk.webserver.dao.his.inpatient.casefrontsheet.SheetCreatedDao;
|
|
|
+import thyyxxk.webserver.entity.ResultVo;
|
|
|
+import thyyxxk.webserver.entity.chronicDisease.CrmPatientMi;
|
|
|
+import thyyxxk.webserver.entity.chronicDisease.CrmPatientTzxx;
|
|
|
+import thyyxxk.webserver.entity.dictionary.CodeName;
|
|
|
+import thyyxxk.webserver.utils.ResultVoUtil;
|
|
|
+import thyyxxk.webserver.utils.StringUtil;
|
|
|
+import thyyxxk.webserver.utils.YbReportUtil;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ClassName ChronicDiseaseService
|
|
|
+ * @Author Administrator
|
|
|
+ * @Date 2023/11/23 14:37
|
|
|
+ * @Version 1.0
|
|
|
+ * @Description 慢特病管理
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class ChronicDiseaseService {
|
|
|
+
|
|
|
+ private static Map<String, List<CodeName>> crmDictionary;
|
|
|
+
|
|
|
+ private final ChronicDiseaseDao dao;
|
|
|
+ private final CrmPatientMiDao cpmDao;
|
|
|
+ private final SheetCreatedDao createdDao;
|
|
|
+ private final CrmPatientTzxxDao tzxxDao;
|
|
|
+
|
|
|
+ public ChronicDiseaseService(ChronicDiseaseDao dao, CrmPatientMiDao cpmDao, SheetCreatedDao createdDao, CrmPatientTzxxDao tzxxDao) {
|
|
|
+ this.dao = dao;
|
|
|
+ this.cpmDao = cpmDao;
|
|
|
+ this.createdDao = createdDao;
|
|
|
+ this.tzxxDao = tzxxDao;
|
|
|
+ if (crmDictionary == null) {
|
|
|
+ crmDictionary = new HashMap<>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据关键字查询慢特病基本信息
|
|
|
+ * @param keyCode 关键字
|
|
|
+ * @return 慢特病基本信息
|
|
|
+ */
|
|
|
+ public ResultVo<CrmPatientMi> selectCrmPatientMiByCode(String keyCode){
|
|
|
+ if(StringUtil.isBlank(keyCode)){
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询的慢特病基本信息关键字不存在");
|
|
|
+ }
|
|
|
+ CrmPatientMi mi = cpmDao.selectCrmPatientMiByCode(keyCode);
|
|
|
+ if(null == mi){
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, keyCode + "查询的慢特病基本信息不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtil.notBlank(mi.getChronicDiseaseType())){
|
|
|
+ mi.setChronicDiseaseTypeArr(Arrays.asList(mi.getChronicDiseaseType().split(",")));
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success(mi);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新慢特病基本信息
|
|
|
+ * @param crmMi 慢特病基本信息
|
|
|
+ * @return map
|
|
|
+ */
|
|
|
+ public ResultVo<Map<String, Object>> updateCrmPatientMi(CrmPatientMi crmMi){
|
|
|
+
|
|
|
+ String msg = callCheckParamForCrm(crmMi);
|
|
|
+ if(StringUtil.notBlank(msg)){
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ CrmPatientMi mi = cpmDao.selectCrmPatientMiByPId(crmMi.getPId());
|
|
|
+ if(null == mi){
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, crmMi.getSocialNo() + "慢特病基本信息不存在,更新失败!");
|
|
|
+ }
|
|
|
+ CrmPatientTzxx crmTzXx = tzxxDao.selectCrmTzxxByPid(crmMi.getPId(), crmMi.getVisitTimes());
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ try{
|
|
|
+ cpmDao.deleteCrmPatientMiByPId(crmMi.getPId());
|
|
|
+ tzxxDao.deleteCrmTzxxByPid(crmMi.getPId(), crmMi.getVisitTimes());
|
|
|
+ int num = cpmDao.insert(crmMi);
|
|
|
+ CrmPatientTzxx tzXx = getCrmPatientTzxx(crmMi);
|
|
|
+ int nom = tzxxDao.insert(tzXx);
|
|
|
+ if(num == 0){
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "更新慢特病基本信息失败!");
|
|
|
+ }
|
|
|
+ resultMap.put("cg", "更新慢特病基本信息成功!");
|
|
|
+ return ResultVoUtil.success(resultMap);
|
|
|
+ } catch(Exception e){
|
|
|
+ log.info("更新慢特病基本信息失败:" + e.getMessage());
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "更新慢特病基本信息失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增慢特病基本信息
|
|
|
+ * @param crmMi 慢特病基本信息
|
|
|
+ * @return map
|
|
|
+ */
|
|
|
+ public ResultVo<Map<String, Object>> saveCrmPatientMi(CrmPatientMi crmMi){
|
|
|
+
|
|
|
+ String msg = callCheckParamForCrm(crmMi);
|
|
|
+
|
|
|
+ if(StringUtil.notBlank(msg)){
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ try{
|
|
|
+ if(StringUtil.notBlank(crmMi.getPId())){
|
|
|
+ CrmPatientMi mi = cpmDao.selectCrmPatientMiByPId(crmMi.getPId());
|
|
|
+ if(null != mi){
|
|
|
+ cpmDao.deleteCrmPatientMiByPId(crmMi.getPId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 新增的时候添加pId
|
|
|
+ String pId = YbTjConstant.CRM_YY_TH + YbReportUtil.generateUkStr(1, 8);
|
|
|
+ crmMi.setPId(pId);
|
|
|
+ }
|
|
|
+ CrmPatientTzxx crmTzXx = tzxxDao.selectCrmTzxxByPid(crmMi.getPId(), crmMi.getVisitTimes());
|
|
|
+ if(null != crmTzXx){
|
|
|
+ tzxxDao.deleteCrmTzxxByPid(crmMi.getPId(), crmMi.getVisitTimes());
|
|
|
+ }
|
|
|
+ CrmPatientTzxx tzXx = getCrmPatientTzxx(crmMi);
|
|
|
+ int num = cpmDao.insert(crmMi);
|
|
|
+ int nom = tzxxDao.insert(tzXx);
|
|
|
+ if(num == 0){
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存慢特病基本信息失败!");
|
|
|
+ }
|
|
|
+ resultMap.put("cg", "保存慢特病基本信息成功!");
|
|
|
+ return ResultVoUtil.success(resultMap);
|
|
|
+ } catch(Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存慢特病基本信息失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @NotNull
|
|
|
+ private static CrmPatientTzxx getCrmPatientTzxx(CrmPatientMi crmMi) {
|
|
|
+ CrmPatientTzxx tzXx = new CrmPatientTzxx();
|
|
|
+ tzXx.setPId(crmMi.getPId());
|
|
|
+ tzXx.setVisitTimes(crmMi.getVisitTimes());
|
|
|
+ tzXx.setVisitDate(crmMi.getVisitDate());
|
|
|
+ tzXx.setInputId(crmMi.getCreatId());
|
|
|
+ tzXx.setHeight(crmMi.getHeight());
|
|
|
+ tzXx.setWeight(crmMi.getWeight());
|
|
|
+ tzXx.setTemperature(crmMi.getTemperature());
|
|
|
+ tzXx.setHeartRate(crmMi.getHeartRate());
|
|
|
+ tzXx.setBloodPressureLow(crmMi.getBloodPressureLow());
|
|
|
+ tzXx.setBloodPressureHigh(crmMi.getBloodPressureHigh());
|
|
|
+ tzXx.setBloodSugar(crmMi.getBloodSugar());
|
|
|
+ tzXx.setBloodOxygen(crmMi.getBloodOxygen());
|
|
|
+ tzXx.setRespiratoryRate(crmMi.getRespiratoryRate());
|
|
|
+ return tzXx;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<Map<String, List<CodeName>>> getCrmDictionary(){
|
|
|
+ if (crmDictionary.isEmpty()) {
|
|
|
+ // 性别字典
|
|
|
+ crmDictionary.put("getSexCode", createdDao.getSexCode());
|
|
|
+ // 婚姻状况字典
|
|
|
+ crmDictionary.put("getMarriageCode", createdDao.getMarriageCode());
|
|
|
+ // 来源途径
|
|
|
+ crmDictionary.put("getAdmissWay", createdDao.getAdmissWay());
|
|
|
+ // 联系人关系字典
|
|
|
+ crmDictionary.put("getRelations", createdDao.getRelations());
|
|
|
+ // 职业字典
|
|
|
+ crmDictionary.put("getOccupation", createdDao.getOccupation());
|
|
|
+ // 国家字典
|
|
|
+ crmDictionary.put("getCountry", createdDao.getCountry());
|
|
|
+ // 民族字典
|
|
|
+ crmDictionary.put("getNation", createdDao.getNation());
|
|
|
+ // 慢特病类型字典
|
|
|
+ crmDictionary.put("getCrmClass", dao.getCrmClass());
|
|
|
+ // 省
|
|
|
+ crmDictionary.put("getProvince", dao.getProvince());
|
|
|
+ // 市
|
|
|
+ crmDictionary.put("getCity", dao.getCity(""));
|
|
|
+ // 区
|
|
|
+ crmDictionary.put("getArea", dao.getArea(""));
|
|
|
+ // 证件类型字典
|
|
|
+ crmDictionary.put("getPsnCertType", dao.getPsnCertType());
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success(crmDictionary);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据code查询市信息
|
|
|
+ * @param code 编码
|
|
|
+ * @return CodeName 市信息
|
|
|
+ */
|
|
|
+ public ResultVo<List<CodeName>> getCrmCityByCode(String code){
|
|
|
+ return ResultVoUtil.success(dao.getCity(code));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据code查询区信息
|
|
|
+ * @param code 编码
|
|
|
+ * @return CodeName 区信息
|
|
|
+ */
|
|
|
+ public ResultVo<List<CodeName>> getCrmAreaByCode(String code){
|
|
|
+ return ResultVoUtil.success(dao.getArea(code));
|
|
|
+ }
|
|
|
+
|
|
|
+ private String callCheckParamForCrm(@NotNull CrmPatientMi crmMi) {
|
|
|
+ String msg = "";
|
|
|
+ String s = "^\\d+$";
|
|
|
+ String s1 = "^\\d+(\\.\\d+)?$";
|
|
|
+ String sfz15 = "^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{2}$";
|
|
|
+ String sfz18 = "^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$";
|
|
|
+ if(StringUtil.isBlank(crmMi.getSocialNo())){
|
|
|
+ msg = "保存慢特病基本信息失败,证件号为空,请检查!";
|
|
|
+ } else if(StringUtil.isBlank(crmMi.getPName())){
|
|
|
+ msg = "保存慢特病基本信息失败,用户名称为空,请检查!";
|
|
|
+ } else if(StringUtil.isBlank(crmMi.getPType())){
|
|
|
+ msg = "保存慢特病基本信息失败,病人来源为空,请检查!";
|
|
|
+ } else if(StringUtil.notBlank(String.valueOf(crmMi.getHeight()))){
|
|
|
+ if(!crmMi.getHeight().toString().matches(s1)){
|
|
|
+ msg = "保存慢特病基本信息失败,病人身高填写不符合(仅限纯数字以及小数点),请检查!";
|
|
|
+ }
|
|
|
+ } else if(StringUtil.notBlank(String.valueOf(crmMi.getWeight()))){
|
|
|
+ if(!String.valueOf(crmMi.getWeight()).matches(s1)){
|
|
|
+ msg = "保存慢特病基本信息失败,病人体重填写不符合(仅限纯数字以及小数点),请检查!";
|
|
|
+ }
|
|
|
+ } else if(StringUtil.notBlank(String.valueOf(crmMi.getTemperature()))){
|
|
|
+ if(!String.valueOf(crmMi.getTemperature()).matches(s1)){
|
|
|
+ msg = "保存慢特病基本信息失败,病人体温填写不符合(仅限纯数字以及小数点),请检查!";
|
|
|
+ }
|
|
|
+ } else if(StringUtil.notBlank(String.valueOf(crmMi.getHeartRate()))){
|
|
|
+ if(!String.valueOf(crmMi.getHeartRate()).matches(s)){
|
|
|
+ msg = "保存慢特病基本信息失败,病人心率填写不符合(仅限纯数字),请检查!";
|
|
|
+ }
|
|
|
+ } else if(StringUtil.notBlank(String.valueOf(crmMi.getBloodSugar()))){
|
|
|
+ if(!String.valueOf(crmMi.getBloodSugar()).matches(s1)){
|
|
|
+ msg = "保存慢特病基本信息失败,病人血糖填写不符合(仅限纯数字以及小数点),请检查!";
|
|
|
+ }
|
|
|
+ } else if(StringUtil.notBlank(String.valueOf(crmMi.getBloodPressureLow()))){
|
|
|
+ if(!String.valueOf(crmMi.getBloodPressureLow()).matches(s)){
|
|
|
+ msg = "保存慢特病基本信息失败,病人舒张血压填写不符合(仅限纯数字),请检查!";
|
|
|
+ }
|
|
|
+ } else if(StringUtil.notBlank(String.valueOf(crmMi.getBloodPressureHigh()))){
|
|
|
+ if(!String.valueOf(crmMi.getBloodPressureHigh()).matches(s)){
|
|
|
+ msg = "保存慢特病基本信息失败,病人收缩血压填写不符合(仅限纯数字),请检查!";
|
|
|
+ }
|
|
|
+ } else if("1".equals(crmMi.getCertificateType())){
|
|
|
+ if(crmMi.getSocialNo().length() == 15){
|
|
|
+ if(!String.valueOf(crmMi.getBloodPressureHigh()).matches(sfz15)){
|
|
|
+ msg = "保存慢特病基本信息失败,病人身份证号码(15位)填写不符合,请检查!";
|
|
|
+ }
|
|
|
+ } else if(crmMi.getSocialNo().length() == 18) {
|
|
|
+ if(!String.valueOf(crmMi.getBloodPressureHigh()).matches(sfz18)){
|
|
|
+ msg = "保存慢特病基本信息失败,病人身份证号码(18位)填写不符合,请检查!";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ msg = "保存慢特病基本信息失败,病人身份证号码填写不符合(不是15或18位数),请检查!";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|