|  | @ -1,28 +1,29 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.patient.service.personal_Info;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.patient.BasePatientFamilyMemberDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.patient.PatientMedicareCardDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.exception.business.patient.PatientCardAlreadyExistException;
 | 
	
		
			
				|  |  | import com.yihu.jw.exception.business.patient.PatientCardFormatInvalidException;
 | 
	
		
			
				|  |  | import com.yihu.jw.exception.business.patient.PatientCardNotFoundException;
 | 
	
		
			
				|  |  | import com.yihu.jw.exception.business.patient.PatientNotFoundException;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientMedicareCardDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.service.BasePatientMedicardCardService;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.util.JavaBeanUtils;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.util.PinYinUtil;
 | 
	
		
			
				|  |  | import netscape.javascript.JSObject;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | import org.springframework.util.Assert;
 | 
	
		
			
				|  |  | import org.springframework.util.CollectionUtils;
 | 
	
		
			
				|  |  | import org.springframework.util.StringUtils;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import javax.validation.constraints.NotNull;
 | 
	
		
			
				|  |  | import java.util.ArrayList;
 | 
	
		
			
				|  |  | import java.util.HashMap;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | import java.util.regex.Matcher;
 | 
	
		
			
				|  |  | import java.util.regex.Pattern;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
	
		
			
				|  | @ -42,6 +43,22 @@ public class PatientMedicareCardService extends BasePatientMedicardCardService<P
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private JdbcTemplate jdbcTemplate;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 校验卡号是否正确,长度不小于6并且只支持数字、字母、下划线
 | 
	
		
			
				|  |  |      * @param cardNumber
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public void checkCardNumber(String cardNumber){
 | 
	
		
			
				|  |  |         Assert.notNull(cardNumber,"卡号不可为空!");
 | 
	
		
			
				|  |  |         Assert.state(cardNumber.length() > 6,"卡号长度不能小于6位数!");
 | 
	
		
			
				|  |  |         String regex = "^\\w+";
 | 
	
		
			
				|  |  |         Pattern pattern = Pattern.compile(regex);
 | 
	
		
			
				|  |  |         Matcher matcher = pattern.matcher(cardNumber);
 | 
	
		
			
				|  |  |         if (!matcher.matches()) {
 | 
	
		
			
				|  |  |             throw new RuntimeException("卡号格式不正确,请输入数字或数字与字母的组合!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 绑定医保卡,需要密码
 | 
	
		
			
				|  |  |      *
 | 
	
	
		
			
				|  | @ -53,8 +70,8 @@ public class PatientMedicareCardService extends BasePatientMedicardCardService<P
 | 
	
		
			
				|  |  |     public void bindMedicareCard(String patientCode, String idcard,String medicareCardNumber,String cityCode) {
 | 
	
		
			
				|  |  |         Assert.notNull(patientCode,"居民code不可为空!");
 | 
	
		
			
				|  |  |         Assert.notNull(idcard,"身份证号不可为空!");
 | 
	
		
			
				|  |  |         Assert.notNull(medicareCardNumber,"医(社)保卡号不可为空!");
 | 
	
		
			
				|  |  |         Assert.notNull(medicareCardNumber,"城市code不可为空!");
 | 
	
		
			
				|  |  |         checkCardNumber(medicareCardNumber);
 | 
	
		
			
				|  |  |         PatientMedicareCardDO card = makeCardInfo(patientCode,idcard,medicareCardNumber);
 | 
	
		
			
				|  |  |         card.setParentType(PatientMedicareCardDO.ParentType.CareCard.getType());
 | 
	
		
			
				|  |  |         card.setType(PatientMedicareCardDO.Type.MedicareCard.getType());
 | 
	
	
		
			
				|  | @ -75,6 +92,7 @@ public class PatientMedicareCardService extends BasePatientMedicardCardService<P
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 绑定就诊卡,需要机构和备注
 | 
	
		
			
				|  |  |      * 同一个医院同一个居民只能存在一张就诊卡。
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param patientCode
 | 
	
		
			
				|  |  |      * @param idcard
 | 
	
	
		
			
				|  | @ -84,7 +102,17 @@ public class PatientMedicareCardService extends BasePatientMedicardCardService<P
 | 
	
		
			
				|  |  |     public void bindPatientIDCard(String patientCode, String idcard,String medicareCardNumber,String orgCode,String remark) {
 | 
	
		
			
				|  |  |         Assert.notNull(patientCode,"居民code不可为空!");
 | 
	
		
			
				|  |  |         Assert.notNull(idcard,"身份证号不可为空!");
 | 
	
		
			
				|  |  |         Assert.notNull(medicareCardNumber,"就诊卡号不可为空!");
 | 
	
		
			
				|  |  |         // 校验卡号格式
 | 
	
		
			
				|  |  |         checkCardNumber(medicareCardNumber);
 | 
	
		
			
				|  |  |         // 校验就诊卡号是否存在
 | 
	
		
			
				|  |  |         boolean exist = basePatientMedicareCardDao.existsByCodeAndOrgCodeAndDel(medicareCardNumber,orgCode,"1");
 | 
	
		
			
				|  |  |         if(exist){
 | 
	
		
			
				|  |  |             throw new PatientCardAlreadyExistException("当前医院就诊卡号已存在,请更改!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         boolean isOneCardOnly = basePatientMedicareCardDao.existsByPatientCodeAndOrgCodeAndDel(patientCode,orgCode,"1");
 | 
	
		
			
				|  |  |         if(isOneCardOnly){
 | 
	
		
			
				|  |  |             throw new PatientCardAlreadyExistException("同一家医院一个居民只能拥有一张就诊卡,请更改!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         PatientMedicareCardDO card = makeCardInfo(patientCode,idcard,medicareCardNumber);
 | 
	
		
			
				|  |  |         card.setParentType(PatientMedicareCardDO.ParentType.CareCard.getType());
 | 
	
		
			
				|  |  |         card.setType(PatientMedicareCardDO.Type.PatientIDCard.getType());
 | 
	
	
		
			
				|  | @ -221,4 +249,24 @@ public class PatientMedicareCardService extends BasePatientMedicardCardService<P
 | 
	
		
			
				|  |  |         result.put("sorted", PinYinUtil.pingYinSortReturnJSON(citylist));
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 判断卡号是否存在,就诊卡除外
 | 
	
		
			
				|  |  |      * @param card
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public boolean isCardExist(String card){
 | 
	
		
			
				|  |  |         Assert.notNull(card,"卡号不可为空!");
 | 
	
		
			
				|  |  |         String sql = "SELECT " +
 | 
	
		
			
				|  |  |                 " count(id) " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 " patient_medicare_card " +
 | 
	
		
			
				|  |  |                 " WHERE " +
 | 
	
		
			
				|  |  |                 " !(parent_type = '"+PatientMedicareCardDO.ParentType.CareCard.getType()+"' AND type = '"+ PatientMedicareCardDO.Type.PatientIDCard.getType() +"') and code = '"+ card + "'";
 | 
	
		
			
				|  |  |         Integer count = jdbcTemplate.queryForObject(sql,Integer.class);
 | 
	
		
			
				|  |  |         if(count > 0){
 | 
	
		
			
				|  |  |             return true;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return false;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |