|  | @ -3,11 +3,14 @@ package com.yihu.wlyy.service.app.family;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.patient.Patient;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.patient.PatientFamilyMember;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.patient.SignFamily;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.patient.invitation.PatientInvitationLog;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.patient.PatientDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.patient.PatientFamilyMemberDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.patient.PatientInvitationLogDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.BaseService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.app.sign.FamilyContractService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.common.SMSService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.IdCardUtil;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.MD5;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.json.JSONArray;
 | 
	
	
		
			
				|  | @ -35,6 +38,8 @@ public class FamilyMemberService extends BaseService {
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     SMSService smsService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PatientInvitationLogDao patientInviteLogDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     FamilyContractService contractService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     JdbcTemplate jdbcTemplate;
 | 
	
	
		
			
				|  | @ -48,7 +53,11 @@ public class FamilyMemberService extends BaseService {
 | 
	
		
			
				|  |  |      * @param member  成员
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public int addMember(String patient, String member, String captcha, String password, int relation) {
 | 
	
		
			
				|  |  |     public int addMember(String patient, String member, String captcha, String password, int relation) throws Exception {
 | 
	
		
			
				|  |  |         if (patient.equals(member)) {
 | 
	
		
			
				|  |  |             return 0;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Patient p = patientDao.findByCode(patient);
 | 
	
		
			
				|  |  |         Patient m = patientDao.findByCode(member);
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -111,7 +120,7 @@ public class FamilyMemberService extends BaseService {
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public int modifyFamilyRelation(String patient, String member, int relation) {
 | 
	
		
			
				|  |  |     public int modifyFamilyRelation(String patient, String member, int relation) throws Exception {
 | 
	
		
			
				|  |  |         Patient p = patientDao.findByCode(patient);
 | 
	
		
			
				|  |  |         Patient m = patientDao.findByCode(member);
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -190,9 +199,9 @@ public class FamilyMemberService extends BaseService {
 | 
	
		
			
				|  |  |             result.put("isRegister", 0);
 | 
	
		
			
				|  |  |         } else {
 | 
	
		
			
				|  |  |             result.put("isRegister", 1);
 | 
	
		
			
				|  |  |             result.put("mobile", StringUtils.isEmpty(p.getMobile()) ? "" :p.getMobile());
 | 
	
		
			
				|  |  |             result.put("name", StringUtils.isEmpty(p.getName()) ? "" :p.getName());
 | 
	
		
			
				|  |  |             result.put("code", StringUtils.isEmpty(p.getCode()) ? "" :p.getCode());
 | 
	
		
			
				|  |  |             result.put("mobile", StringUtils.isEmpty(p.getMobile()) ? "" : p.getMobile());
 | 
	
		
			
				|  |  |             result.put("name", StringUtils.isEmpty(p.getName()) ? "" : p.getName());
 | 
	
		
			
				|  |  |             result.put("code", StringUtils.isEmpty(p.getCode()) ? "" : p.getCode());
 | 
	
		
			
				|  |  |             result.put("photo", StringUtils.isEmpty(p.getPhoto()) ? "" : p.getPhoto());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -205,7 +214,7 @@ public class FamilyMemberService extends BaseService {
 | 
	
		
			
				|  |  |      * @param patient 居民
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONArray getPatientFamilyMembers(String patient) {
 | 
	
		
			
				|  |  |     public JSONArray getPatientFamilyMembers(String patient, String doctorCode) {
 | 
	
		
			
				|  |  |         JSONArray resultArray = new JSONArray();
 | 
	
		
			
				|  |  |         String sql = "select * " +
 | 
	
		
			
				|  |  |                 " from " +
 | 
	
	
		
			
				|  | @ -224,12 +233,25 @@ public class FamilyMemberService extends BaseService {
 | 
	
		
			
				|  |  |                 List<SignFamily> signs = contractService.findAllSignByPatient(map.get("code").toString());
 | 
	
		
			
				|  |  |                 boolean ssSign = false;
 | 
	
		
			
				|  |  |                 boolean jtSign = false;
 | 
	
		
			
				|  |  |                 int status = 0;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 for (SignFamily sign : signs) {
 | 
	
		
			
				|  |  |                     if (sign.getType() == 1) {
 | 
	
		
			
				|  |  |                     if (sign.getType() == 1 && sign.getStatus() > 0) {
 | 
	
		
			
				|  |  |                         ssSign = true;
 | 
	
		
			
				|  |  |                     } else {
 | 
	
		
			
				|  |  |                         jtSign = false;
 | 
	
		
			
				|  |  |                         status = 3;
 | 
	
		
			
				|  |  |                     } else if (sign.getType() == 2 && sign.getStatus() > 0) {
 | 
	
		
			
				|  |  |                         jtSign = true;
 | 
	
		
			
				|  |  |                         status = 3;
 | 
	
		
			
				|  |  |                     } else if (sign.getStatus() == 0) {
 | 
	
		
			
				|  |  |                         status = 2;
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if (StringUtils.isEmpty(doctorCode)) {
 | 
	
		
			
				|  |  |                     List<PatientInvitationLog> patientInviteLog = patientInviteLogDao.getPatientInviteLog(doctorCode,
 | 
	
		
			
				|  |  |                             patient, map.get("code").toString());
 | 
	
		
			
				|  |  |                     if (patientInviteLog != null && patientInviteLog.size() > 0 && status != 0) {
 | 
	
		
			
				|  |  |                         status = 1;
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -237,11 +259,20 @@ public class FamilyMemberService extends BaseService {
 | 
	
		
			
				|  |  |                 obj.put("name", map.get("name"));
 | 
	
		
			
				|  |  |                 obj.put("sex", map.get("sex"));
 | 
	
		
			
				|  |  |                 obj.put("birthday", map.get("birthday"));
 | 
	
		
			
				|  |  |                 obj.put("idcard", map.get("idcard"));
 | 
	
		
			
				|  |  |                 obj.put("idcard", StringUtils.isEmpty(String.valueOf(map.get("idcard"))) ? "" : map.get("idcard").toString());
 | 
	
		
			
				|  |  |                 obj.put("photo", map.get("photo"));
 | 
	
		
			
				|  |  |                 obj.put("mobile", map.get("mobile"));
 | 
	
		
			
				|  |  |                 obj.put("address", map.get("address"));
 | 
	
		
			
				|  |  |                 obj.put("familyRelation", map.get("family_relation"));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if (StringUtils.isEmpty(doctorCode)) {
 | 
	
		
			
				|  |  |                     obj.put("relaholder", map.get("family_relation"));
 | 
	
		
			
				|  |  |                     obj.put("addressCode", "");
 | 
	
		
			
				|  |  |                     obj.put("addressName", StringUtils.isEmpty(String.valueOf(map.get("address"))) ? "" : map.get("address"));
 | 
	
		
			
				|  |  |                     obj.put("status", status);
 | 
	
		
			
				|  |  |                     obj.put("source", 1);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if (ssSign && jtSign) {
 | 
	
		
			
				|  |  |                     obj.put("signType", 3);
 | 
	
		
			
				|  |  |                 } else if (!ssSign && jtSign) {
 | 
	
	
		
			
				|  | @ -266,7 +297,7 @@ public class FamilyMemberService extends BaseService {
 | 
	
		
			
				|  |  |      * @param relation 关系 1父亲 2母亲 3老公 4老婆 5儿子 6女儿 7其他
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public int familyRelationTrans(Patient patient, int relation) {
 | 
	
		
			
				|  |  |     public int familyRelationTrans(Patient patient, int relation) throws Exception {
 | 
	
		
			
				|  |  |         int relationTrans = 0;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         switch (relation) {
 | 
	
	
		
			
				|  | @ -279,6 +310,13 @@ public class FamilyMemberService extends BaseService {
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     relationTrans = 0;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 if(relationTrans == 0) {
 | 
	
		
			
				|  |  |                     if (IdCardUtil.getSexForIdcard(StringUtils.isEmpty(patient.getIdcard()) ? "" : patient.getIdcard()).equals("1")) {
 | 
	
		
			
				|  |  |                         relationTrans = 6;
 | 
	
		
			
				|  |  |                     } else if (IdCardUtil.getSexForIdcard(StringUtils.isEmpty(patient.getIdcard()) ? "" : patient.getIdcard()).equals("2")) {
 | 
	
		
			
				|  |  |                         relationTrans = 5;
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 3:
 | 
	
		
			
				|  |  |                 relationTrans = 4;
 | 
	
	
		
			
				|  | @ -290,11 +328,18 @@ public class FamilyMemberService extends BaseService {
 | 
	
		
			
				|  |  |             case 6:
 | 
	
		
			
				|  |  |                 if (patient.getSex() == 1) {
 | 
	
		
			
				|  |  |                     relationTrans = 1;
 | 
	
		
			
				|  |  |                 } else if (patient.getSex() == 1) {
 | 
	
		
			
				|  |  |                 } else if (patient.getSex() == 2) {
 | 
	
		
			
				|  |  |                     relationTrans = 2;
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     relationTrans = 0;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 if(relationTrans == 0) {
 | 
	
		
			
				|  |  |                     if (IdCardUtil.getSexForIdcard(StringUtils.isEmpty(patient.getIdcard()) ? "" : patient.getIdcard()).equals("1")) {
 | 
	
		
			
				|  |  |                         relationTrans = 2;
 | 
	
		
			
				|  |  |                     } else if (IdCardUtil.getSexForIdcard(StringUtils.isEmpty(patient.getIdcard()) ? "" : patient.getIdcard()).equals("2")) {
 | 
	
		
			
				|  |  |                         relationTrans = 1;
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 |