Browse Source

Merge branch 'dev' of lyr/patient-co-management into dev

lyr 8 years ago
parent
commit
8f63b37fb2

+ 1 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/DoctorAdminTeamDao.java

@ -75,4 +75,5 @@ public interface DoctorAdminTeamDao extends
    AdminTeam findByLeaderCode(@Param("leaderCode") String leaderCode);
    List<AdminTeam> findByOrgCode(String orgCode);
}

+ 135 - 79
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java

@ -2,6 +2,7 @@ package com.yihu.wlyy.service.app.sign;
import java.util.*;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.dict.SystemDict;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
@ -472,6 +473,91 @@ public class FamilyContractService extends BaseService {
        return json;
    }
    /**
     * 申请签约
     *
     * @param doctor     签约医生
     * @param patient    居民code
     * @param doctorType 医生类型
     * @return
     */
    public int sign(String doctor, String patient, int doctorType) {
        Patient p = patientDao.findByCode(patient);
        if (p == null) {
            return -1;
        }
        SignFamily sc = signFamilyDao.findByIdcard(p.getIdcard());
        //判断身份证号是否已签约
        if (sc != null) {
            return -2;
        }
        Doctor d = doctorDao.findByCode(doctor);
        if (d == null) {
            return -3;
        }
        SignFamily sf = new SignFamily();
        sf.setCode(getCode());
        // 设置两网编码
        sf.setLwCode(sc != null ? sc.getCode() : null);
        sf.setCzrq(new Date());
        sf.setPatientApplyDate(new Date());
        if (doctorType == 2) {
            sf.setDoctor(doctor);
            sf.setDoctorName(d.getName());
        } else {
            sf.setDoctorHealth(doctor);
            sf.setDoctorHealthName(d.getName());
        }
        sf.setMobile(p.getMobile());
        sf.setName(p.getName());
        sf.setIdcard(p.getIdcard());
        sf.setOpenid(p.getOpenid());
        sf.setPatient(patient);
        sf.setHospital(d.getHospital());
        sf.setHospitalName(d.getHosptialName());
        sf.setSsc(p.getSsc());
        sf.setStatus(0);//0为初始状态
        sf.setType(2);// 设置为家庭签约
        sf.setSignType("1");//用户申请
        sf.setSignSource("2");//签约来源【1 社区签约 2 移动签约】
        //******************扣费接口**********************/
        sf.setExpensesStatus("0");   //扣费状态 【0未扣费 1已扣费 2已退费】
        SignFamily temp = signFamilyDao.save(sf);
        if (temp != null) {
            // 添加签约消息
            Message message = new Message();
            message.setCzrq(new Date());
            message.setContent("您有一条新的家庭签约申请!");
            message.setRead(1);//设置未读
            message.setReceiver(doctor);//设置接受医生的code
            message.setSender(patient);//设置发送的用户
            message.setSenderName(p.getName());
            message.setCode(getCode());
            message.setSenderPhoto(p.getPhoto());
            message.setTitle("家庭签约申请");
            message.setType(1);//家庭签约信息
            message.setReadonly(1);//是否只读消息
            message.setSignStatus("1");//新的签约
            message.setSex(p.getSex());
            message.setOver("1");//未处理
            message.setData(temp.getCode());
            messageDao.save(message);
            // 发送消息给医生
            PushMsgTask.getInstance().put(doctor, MessageType.MESSAGE_TYPE_DOCTOR_NEW_SIGN_WEB.D_SW_01.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_SIGN_WEB.家庭签约.name(), "您有一条新的家庭签约申请!", patient);
        }
        return 1;
    }
    /**
     * 取消签约申请
     *
@ -639,15 +725,13 @@ public class FamilyContractService extends BaseService {
    synchronized public SignFamily agent(String access_token, String name,
                                         String doctor, String doctorName,
                                         String doctorHealth, String doctorHealthName,
                                         String majorDoctor,
                                         String majorDoctorName,
                                         String hospital, String hospitalName,
                                         String idcard, String ssc,
                                         String mobile,
                                         String emerMobile, String images,
                                         String healthLabel, String customLabel, String disease,
                                         String expenses, String signDoctorCode,
                                         String signDoctorName, String signDoctorLevel, String customGroup) throws Exception {
                                         String signDoctorName, String signDoctorLevel, long adminTeamCode) throws Exception {
        // 查询是否有家庭签约
        SignFamily sc = signFamilyDao.findByIdcard(idcard);
        if (sc != null) {
@ -669,13 +753,22 @@ public class FamilyContractService extends BaseService {
        sf.setCzrq(new Date());
        //设置全科医生的行政团队
        sf.setAdminTeamId(doctorAdminTeamDao.findIdByLeaderCode(doctor));
        sf.setAdminTeamId(adminTeamCode);
        AdminTeam team = doctorAdminTeamDao.findOne(adminTeamCode);
        Doctor docLeader = doctorDao.findByCode(team.getLeaderCode());
        //设置签约医生
        sf.setSignDoctorCode(docLeader.getCode());
        sf.setSignDoctorName(docLeader.getName());
        sf.setSignDoctorLevel(String.valueOf(docLeader.getLevel()));
        sf.setDoctor(doctor);
        sf.setDoctorName(doctorName);
        sf.setDoctorHealth(doctorHealth);
        sf.setDoctorHealthName(doctorHealthName);
        sf.setExpensesType(StringUtils.isEmpty(expenses) ? "01" : expenses);
        sf.setFamilyCode(createSignCode(doctor, hospital));
        sf.setDoctorHealthName(doctorHealthName);
        sf.setEmerMobile(emerMobile);
        sf.setEnd(DateUtil.strToDateShort(DateUtil.getNextYear(DateUtil.getNowDateShort(), 1)));
        sf.setName(name);
@ -696,9 +789,6 @@ public class FamilyContractService extends BaseService {
        sf.setApplyDate(new Date());
        sf.setType(2);// 设置为家庭签约
        sf.setSignType("2");//手工带签
        sf.setSignDoctorCode(doctor);
        sf.setSignDoctorLevel("2");
        sf.setSignDoctorName(doctorName);
        sf.setAgentDoctorCode(signDoctorCode);
        sf.setAgentDoctorLevel(signDoctorLevel);
        sf.setAgentDoctorName(signDoctorName);
@ -718,17 +808,14 @@ public class FamilyContractService extends BaseService {
            patient.setMobile(mobile);
            patient.setBirthday(ie.getBirthday());
            patient.setSex(ie.getGender());
            String password=idcard.substring(idcard.length()-6);
            String salt= UUID.randomUUID().toString().replace("-","");
            String password = idcard.substring(idcard.length() - 6);
            String salt = UUID.randomUUID().toString().replace("-", "");
            patient.setSalt(salt);
            patient.setPassword(MD5.GetMD5Code(password+salt));
            patient.setPassword(MD5.GetMD5Code(password + salt));
            patient.setStatus(1);
            patient.setDisease(0);
        }
        //病人疾病更新
//        if (!StringUtils.isEmpty(disease)) {
//            patient.setDisease(Integer.valueOf(disease));
//        }
        // 保存用户信息
        patientDao.save(patient);
@ -774,22 +861,6 @@ public class FamilyContractService extends BaseService {
        wlyyDoctorTeamDoctor.setCzrq(new Date());
        doctorTeamDoctor.save(wlyyDoctorTeamDoctor);
//        if (StringUtils.isNotEmpty(disease) && !disease.equals("0")) {
//            //如果有选择病种
//            //添加专科医生
//            wlyyDoctorTeamDoctor = new DoctorTeamMember();
//            wlyyDoctorTeamDoctor.setTeam(doctorTeamCode);
//            wlyyDoctorTeamDoctor.setMemberCode(majorDoctor);
//            wlyyDoctorTeamDoctor.setSignType("2");//家庭签约
//            wlyyDoctorTeamDoctor.setName(majorDoctorName);
//            wlyyDoctorTeamDoctor.setDel("1");
//            wlyyDoctorTeamDoctor.setType(1);
//            wlyyDoctorTeamDoctor.setCode(getCode());
//            wlyyDoctorTeamDoctor.setCzrq(new Date());
//
//            doctorTeamDoctor.save(wlyyDoctorTeamDoctor);
//        }
        //添加患者和团队的关系
        DoctorTeamMember wlyyDoctorTeamPatient = new DoctorTeamMember();
        wlyyDoctorTeamPatient.setTeam(doctorTeamCode);
@ -843,12 +914,14 @@ public class FamilyContractService extends BaseService {
    public int handleSign(String signType,
                          String access_token,
                          String doctor,
                          String doctorName,
                          String healthDoctor,
                          String healthDoctorName,
                          long msgid,
                          String patientCard, int type,
                          String healthLabel, String customLabel, String disease,
                          String majorDoctor, String majorhDoctorName, String customGroup, String expenses) throws Exception {
                          String expenses, long adminTeamCode) throws Exception {
        if (type != 1 && type != 2) {
            return -1;
        }
@ -871,10 +944,6 @@ public class FamilyContractService extends BaseService {
        if (type == 1) {
            List<SystemDict> systemDicts = systemDictDao.findByDictName("SIGN_YEAR");
            String year = systemDicts.get(0).getCode();
            //病人疾病更新
//            if (!StringUtils.isEmpty(disease)) {
//                p.setDisease(Integer.valueOf(disease));
//            }
            //签约类型:1三师签约,2家庭签约
            // 改为签约生效
@ -884,18 +953,30 @@ public class FamilyContractService extends BaseService {
            sf.setSignType("1");//患者发起签约
            sf.setExpensesType(StringUtils.isEmpty(expenses) ? "01" : expenses);//收费类别
            sf.setEnd(DateUtil.strToDateShort(DateUtil.getNextYear(DateUtil.getNowDateShort(), 1)));
            //设置签约人  患者发起的签约 默认签约人是全科医生
            sf.setSignDoctorCode(sf.getDoctor());
            sf.setSignDoctorName(sf.getDoctorName());
            sf.setSignDoctorLevel("2");
            // 更新健康管理师
            sf.setDoctorHealth(healthDoctor);
            sf.setDoctorHealthName(healthDoctorName);
            sf.setAdminTeamId(adminTeamCode);
            if (StringUtils.isNotEmpty(doctor)) {
                //设置全科医生
                sf.setDoctor(doctor);
                sf.setDoctorName(doctorName);
            } else {
                // 更新健康管理师
                sf.setDoctorHealth(healthDoctor);
                sf.setDoctorHealthName(healthDoctorName);
            }
            AdminTeam team = doctorAdminTeamDao.findOne(adminTeamCode);
            Doctor docLeader = doctorDao.findByCode(team.getLeaderCode());
            //设置签约医生
            sf.setSignDoctorCode(docLeader.getCode());
            sf.setSignDoctorName(docLeader.getName());
            sf.setSignDoctorLevel(String.valueOf(docLeader.getLevel()));
            sf.setCzrq(new Date());
            sf.setSignYear(year);//设置签约年度
            sf.setApplyDate(new Date());
            Doctor doctor = doctorDao.findByCode(sf.getDoctor());
            sf.setFamilyCode(createSignCode(sf.getDoctor(), doctor.getHospital()));
            Doctor doc = doctorDao.findByCode(sf.getDoctor());
            sf.setFamilyCode(createSignCode(sf.getDoctor(), doc.getHospital()));
            //建立团队
            DoctorTeam doctorTeam = new DoctorTeam();
            String doctorTeamCode = getCode();
@ -942,20 +1023,6 @@ public class FamilyContractService extends BaseService {
            wlyyDoctorTeamPatient.setCzrq(new Date());
            doctorTeamDoctor.save(wlyyDoctorTeamPatient);
//            if (StringUtils.isNotEmpty(disease) && !disease.equals("0")) {
//                //如果有选择病种
//                //添加专科医生
//                wlyyDoctorTeamDoctor = new DoctorTeamMember();
//                wlyyDoctorTeamDoctor.setTeam(doctorTeamCode);
//                wlyyDoctorTeamDoctor.setMemberCode(majorDoctor);
//                wlyyDoctorTeamDoctor.setSignType("2");//家庭签约
//                wlyyDoctorTeamDoctor.setName(majorhDoctorName);
//                wlyyDoctorTeamDoctor.setDel("1");
//                wlyyDoctorTeamDoctor.setType(1);
//                wlyyDoctorTeamDoctor.setCode(getCode());
//                wlyyDoctorTeamDoctor.setCzrq(new Date());
//                doctorTeamDoctor.save(wlyyDoctorTeamDoctor);
//            }
        } else {
            // 医生拒绝
            sf.setStatus(-2);
@ -963,10 +1030,10 @@ public class FamilyContractService extends BaseService {
            // 拒绝签约
            JSONObject json = new JSONObject();
            json.put("first", "签约失败通知");
            json.put("doctor", sf.getDoctor());
            json.put("doctorName", sf.getDoctorName());
            json.put("doctor", StringUtils.isEmpty(sf.getDoctor()) ? sf.getDoctorHealth() : sf.getDoctor());
            json.put("doctorName", StringUtils.isEmpty(sf.getDoctor()) ? sf.getDoctorHealthName() : sf.getDoctorHealth());
            json.put("date", DateUtil.dateToStrShort(new Date()));
            json.put("content", "您与 " + sf.getDoctorName() + " 医生建立家庭医生签约关系失败,请查看!");
            json.put("content", "您与 " + (StringUtils.isEmpty(sf.getDoctor()) ? sf.getDoctorHealthName() : sf.getDoctorHealth()) + " 医生建立家庭医生签约关系失败,请查看!");
            json.put("remark", "您好,签约家庭医生失败通知");
            // 添加到发送队列
            PushMsgTask.getInstance().putWxMsg(access_token, 2, sf.getOpenid(), sf.getName(), json);
@ -981,35 +1048,23 @@ public class FamilyContractService extends BaseService {
        // 推送消息消息给微信端
        if (type == 1) {
            Doctor doc = doctorDao.findByCode(sf.getDoctor());
            Doctor doc = doctorDao.findByCode(StringUtils.isNotEmpty(doctor) ? sf.getDoctorHealth() : sf.getDoctor());
            Hospital hos = hospitalDao.findByCode(doc.getHospital());
            String content = "祝贺您,成功签约" + sf.getDoctorName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
            String content = "祝贺您,成功签约" + doc.getName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
                    "为了给您提供更好的服务,请尽快到" + (hos != null ? hos.getName() : "") + "社区(地址:" +
                    (hos != null ? hos.getAddress() : "") + ")缴费。";
            // 同意签约
            JSONObject json = new JSONObject();
            json.put("first", "签约成功通知");
            json.put("doctor", sf.getDoctor());
            json.put("doctorName", sf.getDoctorName());
            json.put("doctor", doc.getCode());
            json.put("doctorName", doc.getName());
            json.put("date", DateUtil.dateToStrShort(sf.getBegin()));
            json.put("content", content);
            json.put("remark", ""); //您好,您成功签约家庭医生
            // 添加到发送队列
            PushMsgTask.getInstance().putWxMsg(access_token, 1, sf.getOpenid(), sf.getName(), json);
            new Thread(new SignUploadTask(sf.getCode())).start();
        } else if (type == 2) {
            System.out.println(" ---------- fail send weixin-------------");
            // 拒绝签约
            JSONObject json = new JSONObject();
            json.put("first", "签约失败通知");
            json.put("doctor", sf.getDoctor());
            json.put("doctorName", sf.getDoctorName());
            json.put("date", DateUtil.dateToStrShort(sf.getBegin()));
            json.put("content", "您与 " + sf.getDoctorName() + " 医生建立家庭医生签约关系失败,请查看!");
            json.put("remark", "您好,签约家庭医生失败通知");
            // 添加到发送队列
            PushMsgTask.getInstance().putWxMsg(access_token, 2, sf.getOpenid(), sf.getName(), json);
        }
        return 1;
    }
@ -1434,7 +1489,7 @@ public class FamilyContractService extends BaseService {
        // 判断患者有没有家庭签约
        SignFamily sf = signFamilyDao.findByPatientStatus(patientCard, 0);
        if (sf != null) {
            sf.setStatus(-5);
            sf.setStatus(-1);
        }
        return true;
    }
@ -1546,6 +1601,7 @@ public class FamilyContractService extends BaseService {
        return signFamilyDao.findNoHealthSignFamilyHealth(doctor, pageRequest);
    }
    /**
     * 查询居民的所有签约
     *

+ 1 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/team/AdminTeamService.java

@ -11,6 +11,7 @@ import com.yihu.wlyy.repository.doctor.DoctorTeamMemberDao;
import com.yihu.wlyy.service.BaseService;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;

+ 18 - 20
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorFamilyContractController.java

@ -158,7 +158,6 @@ public class DoctorFamilyContractController extends WeixinBaseController {
     * @param idcard     身份证号
     * @param ssc        社保卡号
     * @param mobile     手机号
     * @param group      患者组 1是健康人群组 2是慢病  3是65岁以上人群
     * @param emerMobile 应急人手机号
     * @param images     图片URL,多图以逗号分隔
     * @param expenses   签约费用
@ -175,8 +174,6 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            @RequestParam(required = false, defaultValue = "") String customLabel,
            @RequestParam(required = false, defaultValue = "") String disease,
            @RequestParam(required = false) String emerMobile,
            @RequestParam(required = false) String majorDoctor,
            @RequestParam(required = false) String majorDoctorName,
            String healthDoctor,
            String healthDoctorName,
            String images,
@ -186,15 +183,9 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            String signDoctorCode,//簽約人code
            String signDoctorName,//簽約人銘
            String signDoctorLevel,//簽約人等级
            @RequestParam(required = false) String group //分组
            long adminTeamCode //行政团队
    ) {
        try {
            //选择病种时需指定专科医生
//            if (StringUtils.isNotEmpty(disease)) {
//                if (!disease.equals("0") && (StringUtils.isEmpty(majorDoctor) || StringUtils.isEmpty(majorDoctorName))) {
//                    return error(-1, "请输入专科医生!");
//                }
//            }
            if (StringUtils.isEmpty(idcard)) {
                return error(-1, "请输入身份证号!");
            }
@ -230,6 +221,9 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            if (StringUtils.isEmpty(healthLabel)) {
                return error(-1, "健康情况标签不能为空!");
            }
            if (adminTeamCode < 1) {
                return error(-1, "行政团队不能为空!");
            }
            int amount = familyContractService.hasSingStatus(idcard);
            if (amount > 0) {
                return error(-1, "该居民已签约了家庭医生!");
@ -245,8 +239,8 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            }
            Doctor cDoctor = doctorService.findDoctorByCode(getUID());
            SignFamily sf = familyContractService.agent(getAccessToken(), name, doctor, doctorName,
                    healthDoctor, healthDoctorName, majorDoctor, majorDoctorName, cDoctor.getHospital(), cDoctor.getHosptialName(),
                    idcard, ssc, mobile, emerMobile, images, healthLabel, customLabel, disease, expenses, signDoctorCode, signDoctorName, signDoctorLevel, group);
                    healthDoctor, healthDoctorName,cDoctor.getHospital(), cDoctor.getHosptialName(),
                    idcard, ssc, mobile, emerMobile, images, healthLabel, customLabel, disease, expenses, signDoctorCode, signDoctorName, signDoctorLevel,adminTeamCode);
            if (sf == null) {
                return error(-1, "代理签约失败!");
@ -265,28 +259,28 @@ public class DoctorFamilyContractController extends WeixinBaseController {
     * @param signType         是否有三师签约 1 否 2是
     * @param healthDoctor     健康管理师标识
     * @param healthDoctorName 健康管理师姓名
     * @param majorDoctor      专科医生标识
     * @param disease          疾病code
     * @param msgid            消息id
     * @param patientIDcard    患者身份证
     * @param type             处理类型:1同意,2拒绝
     * @param group
     * @param adminTeamCode     行政团队code
     * @return
     */
    @RequestMapping(value = "sign")
    @ResponseBody
    public String sign(
            @RequestParam(required = true, defaultValue = "1") String signType,
            String healthDoctor,
            @RequestParam(required = false, defaultValue = "")String healthDoctor,
            @RequestParam(required = false, defaultValue = "")String healthDoctorName,
            @RequestParam(required = false, defaultValue = "") String doctor,
            @RequestParam(required = false, defaultValue = "")String doctorName,
            String healthLabel,
            @RequestParam(required = false, defaultValue = "") String customLabel,
            @RequestParam(required = false, defaultValue = "") String disease,
            String healthDoctorName,
            @RequestParam(required = false) String majorDoctor,
            @RequestParam(required = false) String majorDoctorName,
            long msgid,
            String patientIDcard,
            int type, String group,
            int type,
            long adminTeamCode,
            @RequestParam(required = false, defaultValue = "0") String expenses) {
        try {
            if (type != 2) {
@ -312,11 +306,15 @@ public class DoctorFamilyContractController extends WeixinBaseController {
                }
            }
            if(StringUtils.isEmpty(doctor) && StringUtils.isEmpty(healthDoctor)){
                return error(-1, "全科医生或健管师不能为空!");
            }
            if (StringUtils.isEmpty(healthLabel) && type != 2) {
                return error(-1, "健康情况标签不能为空!");
            }
            int res = familyContractService.handleSign(signType, getAccessToken(), healthDoctor, healthDoctorName, msgid, patientIDcard, type, healthLabel, customLabel, disease, majorDoctor, majorDoctorName, group, expenses);
            int res = familyContractService.handleSign(signType, getAccessToken(),doctor,doctorName, healthDoctor, healthDoctorName, msgid, patientIDcard, type, healthLabel, customLabel, disease, expenses,adminTeamCode);
            if (res == -1) {
                return error(-1, "未知的处理类型!");
            } else if (res == 0) {

+ 517 - 468
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/sign/FamilyContractController.java

@ -34,498 +34,547 @@ import java.util.List;
/**
 * 患者端:家庭签约控制类
 * @author George
 *
 * @author George
 */
@Controller
@RequestMapping(value = "/patient/family_contract", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "患者端-家庭签约")
public class FamilyContractController extends BaseController {
	@Autowired
	private FamilyContractService familyContractService;
	@Autowired
	private PatientService patientService;
	@Autowired
	private DoctorService doctorService;
	@Autowired
	private FamilyService familyService;
	@Autowired
	private DoctorPatientGroupInfoDao doctorPatientGroupInfoDao;
    @Autowired
    private FamilyContractService familyContractService;
    @Autowired
    private PatientService patientService;
    @Autowired
    private DoctorService doctorService;
    @Autowired
    private FamilyService familyService;
    @Autowired
    private DoctorPatientGroupInfoDao doctorPatientGroupInfoDao;
    /**
     * 得到患者的签约的医生的信息
     *
     * @param patientCode 患者标识
     * @return
     */
    @RequestMapping(value = "getSignMessage")
    @ResponseBody
    public String getSignDoctorMessage(String patientCode) {
        try {
            JSONArray array = familyContractService.getSignDoctorMessage(patientCode);
            return write(200, "获取列表成功!", "list", array);
        } catch (Exception e) {
            error(e);
            return error(-1, "获取列表失败!");
        }
    }
    /**
     * 社区医院列表查询接口
     *
     * @param type     医院类型:0全部,1大医院,2社区医院
     * @param province 患标识
     * @param city     城市标识
     * @param key      搜索关键字,用于搜索医院名称
     * @return
     */
    @RequestMapping(value = "hospitals")
    @ResponseBody
    public String hospitals(
            int type,
            @RequestParam(required = false) String province,
            @RequestParam(required = false) String city,
            @RequestParam(required = false) String town,
            @RequestParam(required = false) String key,
            long id,
            int pagesize) {
        try {
            JSONArray array = new JSONArray();
            Page<Hospital> list = familyContractService.findHospitals(type, province, city, town, key, id, pagesize);
            if (list != null) {
                for (Hospital hospital : list) {
                    if (hospital == null) {
                        continue;
                    }
                    JSONObject json = new JSONObject();
                    json.put("id", hospital.getId());
                    // 医院标识
                    json.put("code", hospital.getCode());
                    // 医院名称
                    json.put("name", hospital.getName());
                    // 省名
                    json.put("province_name", hospital.getProvinceName());
                    // 城市名
                    json.put("city_name", hospital.getCityName());
                    // 区县名
                    json.put("town_name", hospital.getTownName());
                    // 详细地址
                    json.put("address", hospital.getAddress());
                    // 简介
                    json.put("intro", hospital.getIntro());
                    // 医院图片
                    json.put("photo", hospital.getPhoto());
                    array.put(json);
                }
            }
            return write(200, "获取医院列表成功!", "list", array);
        } catch (Exception e) {
            error(e);
            return error(-1, "获取医院列表失败!");
        }
    }
	/**
	 * 得到患者的签约的医生的信息
	 * @param patientCode 患者标识
	 * @return
    /**
     * 社区医院下医生列表查询接口
     *
     * @param hospital 医院标识
     * @return
     */
	@RequestMapping(value = "getSignMessage")
	@ResponseBody
	public String getSignDoctorMessage(String patientCode){
		try {
    @RequestMapping(value = "doctors")
    @ResponseBody
    public String hospitalList(String hospital, long id, int pagesize) {
        try {
            JSONArray array = new JSONArray();
            Page<Doctor> list = familyContractService.findDoctors(hospital, 2, id, pagesize);
            if (list != null) {
                for (Doctor doctor : list) {
                    if (doctor == null) {
                        continue;
                    }
                    JSONObject json = new JSONObject();
                    json.put("id", doctor.getId());
                    // 医生标识
                    json.put("code", doctor.getCode());
                    // 医生姓名
                    json.put("name", doctor.getName());
                    // 所在医院名称
                    json.put("hospital_name", doctor.getHosptialName());
                    // 科室名称
                    json.put("dept_name", doctor.getDeptName());
                    // 职称名称
                    json.put("job_name", doctor.getJobName());
                    // 头像
                    json.put("photo", doctor.getPhoto());
                    // 简介
                    json.put("introduce", doctor.getIntroduce());
                    // 专长
                    json.put("expertise", doctor.getExpertise());
                    array.put(json);
                }
            }
            return write(200, "获取医院医生列表成功!", "list", array);
        } catch (Exception e) {
            error(e);
            return error(-1, "获取医院医生列表失败!");
        }
    }
			JSONArray array =familyContractService.getSignDoctorMessage(patientCode);
    /**
     * 医生主页信息查询接口
     *
     * @param doctor 医生标识
     * @return
     */
    @RequestMapping(value = "homepage")
    @ResponseBody
    public String homepage(String doctor) {
        try {
            JSONObject json = familyContractService.findDoctorMainPage(getUID(), doctor);
			return write(200, "获取列表成功!", "list", array);
		} catch (Exception e) {
			error(e);
			return error(-1, "获取列表失败!");
		}
	}
            if (json == null) {
                return error(-1, "医生主页查询失败!");
            }
            return write(200, "医生主页查询成功!", "data", json);
        } catch (Exception e) {
            error(e);
            return error(-1, "医生主页查询失败!");
        }
    }
    /**
     * 与指定医生的签约状态查询接口
     *
     * @param doctor
     * @return
     */
    @RequestMapping(value = "status")
    @ResponseBody
    public String signStatus(String doctor) {
        try {
            // -1未签约,0待签约,1已签约,2患者申请取消签约,3医生申请取消签约
            int status = familyContractService.findSignStatus(getUID(), doctor);
            return write(200, "数据加载成功!", "data", status);
        } catch (Exception e) {
            error(e);
            return error(-1, "数据加载失败!");
        }
    }
	/**
	 * 社区医院列表查询接口
	 * @param type 医院类型:0全部,1大医院,2社区医院
	 * @param province 患标识
	 * @param city 城市标识
	 * @param key 搜索关键字,用于搜索医院名称
	 * @return
	 */
	@RequestMapping(value = "hospitals")
	@ResponseBody
	public String hospitals(
			int type,
			@RequestParam(required = false) String province,
			@RequestParam(required = false) String city,
			@RequestParam(required = false) String town,
			@RequestParam(required = false) String key,
			long id,
			int pagesize) {
		try {
			JSONArray array = new JSONArray();
			Page<Hospital> list = familyContractService.findHospitals(type, province, city, town, key, id, pagesize);
			if (list != null) {
				for (Hospital hospital : list) {
					if (hospital == null) {
						continue;
					}
					JSONObject json = new JSONObject();
					json.put("id", hospital.getId());
					// 医院标识
					json.put("code", hospital.getCode());
					// 医院名称
					json.put("name", hospital.getName());
					// 省名
					json.put("province_name", hospital.getProvinceName());
					// 城市名
					json.put("city_name", hospital.getCityName());
					// 区县名
					json.put("town_name", hospital.getTownName());
					// 详细地址
					json.put("address", hospital.getAddress());
					// 简介
					json.put("intro", hospital.getIntro());
					// 医院图片
					json.put("photo", hospital.getPhoto());
					array.put(json);
				}
			}
			return write(200, "获取医院列表成功!", "list", array);
		} catch (Exception e) {
			error(e);
			return error(-1, "获取医院列表失败!");
		}
	}
    /**
     * 得到患者的签约信息
     * homePageDoctor,//主页医生code
     * invitePatientCode //邀请患者
     *
     * @return
     */
    @RequestMapping(value = "getPatientSign")
    @ResponseBody
    public String getPatientSign(
            String homePageDoctorCode,//主页医生code
            String invitePatientCode //邀请患者
    ) {
        try {
            JSONObject json = new JSONObject();
            //得到主页医生
            Doctor homePageDoctor = doctorService.findDoctorByCode(homePageDoctorCode);
            //得到邀请患者
            PatientInvitationLog w = familyService.getPatientInviteLog(invitePatientCode);
            //得到被邀请的患者的家庭签约
            SignFamily signFamily = familyContractService.getPatientSign(w.getInvitePatientCode());
            SignFamily ssSignFamily = familyContractService.getssPatientSign(w.getInvitePatientCode());
            json.put("homepage_doctor", homePageDoctor.getCode());
            json.put("homepage_doctorName", homePageDoctor.getName());
            json.put("homepage_photo", homePageDoctor.getPhoto());
            json.put("homepage_sex", homePageDoctor.getSex());
            json.put("homepage_job", homePageDoctor.getJob());
            json.put("homepage_jobName", homePageDoctor.getJobName());
            json.put("homepage_hospital", homePageDoctor.getHosptialName());
            json.put("homepage_dept", homePageDoctor.getDeptName());
            json.put("homepage_intro", homePageDoctor.getIntroduce());
            json.put("homepage_expertise", homePageDoctor.getExpertise());
            json.put("patient_code", w.getInvitePatientCode());//被邀请code
            json.put("patient_name", w.getInvitePatientName());//被邀请人名
            //设置查看病人所在分组
            List<DoctorPatientGroupInfo> dctorPatientGroupInfo = doctorPatientGroupInfoDao.findByMorenPatient(w.getInvitePatientCode());
            if (dctorPatientGroupInfo != null && dctorPatientGroupInfo.size() > 0) {
                json.put("group", dctorPatientGroupInfo.get(0).getGroup());
            } else {
                json.put("group", "0");
            }
            if (signFamily != null) {
                json.put("type", "1");//签约类型 家庭
                json.put("sign_code", signFamily.getCode());// 消息code
                json.put("sign_type", signFamily.getStatus());// -1未签约,0待签约,1已签约,2患者申请取消签约,3医生申请取消签约
                json.put("sign_doctor", signFamily.getDoctor());// 全科医生
                json.put("sign_doctorName", signFamily.getDoctorName());// 全科医生
                json.put("sign_code", signFamily.getCode());// 签约code
            } else if (ssSignFamily != null) {
                json.put("type", "2");//签约类型 三师
                json.put("sign_code", ssSignFamily.getCode());// 消息code
                json.put("sign_type", ssSignFamily.getStatus());// -1未签约,0待签约,1已签约,2患者申请取消签约,3医生申请取消签约
                json.put("sign_doctor", ssSignFamily.getDoctor());// 全科医生
                json.put("sign_doctorName", ssSignFamily.getDoctorName());// 全科医生
                json.put("sign_code", ssSignFamily.getCode());// 签约code
            } else {
                json.put("sign_type", -1);//-1未签约
            }
	/**
	 * 社区医院下医生列表查询接口
	 * @param hospital 医院标识
	 * @return
	 */
	@RequestMapping(value = "doctors")
	@ResponseBody
	public String hospitalList(String hospital, long id, int pagesize) {
		try {
			JSONArray array = new JSONArray();
			Page<Doctor> list = familyContractService.findDoctors(hospital, 2, id, pagesize);
			if (list != null) {
				for (Doctor doctor : list) {
					if (doctor == null) {
						continue;
					}
					JSONObject json = new JSONObject();
					json.put("id", doctor.getId());
					// 医生标识
					json.put("code", doctor.getCode());
					// 医生姓名
					json.put("name", doctor.getName());
					// 所在医院名称
					json.put("hospital_name", doctor.getHosptialName());
					// 科室名称
					json.put("dept_name", doctor.getDeptName());
					// 职称名称
					json.put("job_name", doctor.getJobName());
					// 头像
					json.put("photo", doctor.getPhoto());
					// 简介
					json.put("introduce", doctor.getIntroduce());
					// 专长
					json.put("expertise", doctor.getExpertise());
					array.put(json);
				}
			}
			return write(200, "获取医院医生列表成功!", "list", array);
		} catch (Exception e) {
			error(e);
			return error(-1, "获取医院医生列表失败!");
		}
	}
	/**
	 * 医生主页信息查询接口
	 * @param doctor 医生标识
	 * @return
	 */
	@RequestMapping(value = "homepage")
	@ResponseBody
	public String homepage(String doctor) {
		try {
			JSONObject json = familyContractService.findDoctorMainPage(getUID(), doctor);
            return write(200, "数据加载成功!", "data", json);
        } catch (Exception e) {
            error(e);
            return error(-1, "数据加载失败!");
        }
    }
			if (json == null) {
				return error(-1, "医生主页查询失败!");
			}
			return write(200, "医生主页查询成功!", "data", json);
		} catch (Exception e) {
			error(e);
			return error(-1, "医生主页查询失败!");
		}
	}
    /**
     * 校验openid是否有签约信息
     *
     * @return
     */
    @RequestMapping(value = "checkOpenid")
    @ResponseBody
    public String checkOpenid() {
        try {
            if (StringUtils.isEmpty(getOpenid())) {
                return error(-1, "无效的Openid!");
            }
            String doctor = familyContractService.checkPatient(getUID());
            return write(200, "签约验证成功!", "data", doctor);
        } catch (Exception e) {
            error(e);
            return error(-1, "签约验证异常!");
        }
    }
	/**
	 * 与指定医生的签约状态查询接口
	 * @param doctor
	 * @return
	 */
	@RequestMapping(value = "status")
	@ResponseBody
	public String signStatus(String doctor) {
		try {
			// -1未签约,0待签约,1已签约,2患者申请取消签约,3医生申请取消签约
			int status = familyContractService.findSignStatus(getUID(), doctor);
			return write(200, "数据加载成功!", "data", status);
		} catch (Exception e) {
			error(e);
			return error(-1, "数据加载失败!");
		}
	}
	/**
	 * 得到患者的签约信息
	 *   homePageDoctor,//主页医生code
	    invitePatientCode //邀请患者
	 * @return
	 */
	@RequestMapping(value = "getPatientSign")
	@ResponseBody
	public String getPatientSign(
			String homePageDoctorCode,//主页医生code
			String invitePatientCode //邀请患者
	) {
		try {
			JSONObject json = new JSONObject();
			//得到主页医生
			Doctor homePageDoctor=doctorService.findDoctorByCode(homePageDoctorCode);
			//得到邀请患者
			PatientInvitationLog w= familyService.getPatientInviteLog(invitePatientCode);
			//得到被邀请的患者的家庭签约
			SignFamily signFamily=familyContractService.getPatientSign(w.getInvitePatientCode());
			SignFamily ssSignFamily=familyContractService.getssPatientSign(w.getInvitePatientCode());
			json.put("homepage_doctor",homePageDoctor.getCode());
			json.put("homepage_doctorName",homePageDoctor.getName());
			json.put("homepage_photo", homePageDoctor.getPhoto());
			json.put("homepage_sex", homePageDoctor.getSex());
			json.put("homepage_job", homePageDoctor.getJob());
			json.put("homepage_jobName", homePageDoctor.getJobName());
			json.put("homepage_hospital", homePageDoctor.getHosptialName());
			json.put("homepage_dept", homePageDoctor.getDeptName());
			json.put("homepage_intro", homePageDoctor.getIntroduce());
			json.put("homepage_expertise", homePageDoctor.getExpertise());
			json.put("patient_code", w.getInvitePatientCode());//被邀请code
			json.put("patient_name", w.getInvitePatientName());//被邀请人名
			//设置查看病人所在分组
			List<DoctorPatientGroupInfo> dctorPatientGroupInfo = doctorPatientGroupInfoDao.findByMorenPatient(w.getInvitePatientCode());
			if (dctorPatientGroupInfo != null && dctorPatientGroupInfo.size() > 0) {
				json.put("group", dctorPatientGroupInfo.get(0).getGroup());
			} else {
				json.put("group", "0");
			}
			if(signFamily!=null){
				json.put("type","1");//签约类型 家庭
				json.put("sign_code", signFamily.getCode());// 消息code
				json.put("sign_type", signFamily.getStatus());// -1未签约,0待签约,1已签约,2患者申请取消签约,3医生申请取消签约
				json.put("sign_doctor",signFamily.getDoctor());// 全科医生
				json.put("sign_doctorName",signFamily.getDoctorName());// 全科医生
				json.put("sign_code", signFamily.getCode());// 签约code
			}else if(ssSignFamily!=null){
				json.put("type","2");//签约类型 三师
				json.put("sign_code", ssSignFamily.getCode());// 消息code
				json.put("sign_type", ssSignFamily.getStatus());// -1未签约,0待签约,1已签约,2患者申请取消签约,3医生申请取消签约
				json.put("sign_doctor",ssSignFamily.getDoctor());// 全科医生
				json.put("sign_doctorName",ssSignFamily.getDoctorName());// 全科医生
				json.put("sign_code", ssSignFamily.getCode());// 签约code
			}else{
				json.put("sign_type", -1);//-1未签约
			}
    /**
     * 校验是否有签约信息
     *
     * @param idcard
     * @return
     */
    @RequestMapping(value = "check")
    @ResponseBody
    public String checkSign(String idcard) {
        try {
            if (StringUtils.isEmpty(idcard)) {
                return error(-1, "请输入身份证号!");
            }
            // 解密身份证号
            idcard = RSAUtils.getInstance(familyContractService).decryptString(idcard);
            idcard = URLDecoder.decode(idcard, "UTF-8");
            idcard = StringUtils.reverse(idcard);
            // 校验身份证号
            IdcardValidator validator = new IdcardValidator();
            if (validator.isValidatedAllIdcard(idcard)) {
                if (idcard.length() == 15) {
                    idcard = validator.convertIdcarBy15bit(idcard);
                    if (StringUtils.isEmpty(idcard)) {
                        return error(-1, "请输入正确的身份证号!");
                    }
                }
            } else {
                return error(-1, "请输入正确的身份证号!");
            }
            Patient patient = patientService.findByCode(getUID());
            if (!StringUtils.equals(patient.getIdcard(), idcard)) {
                return error(-1, "身份证号错误,请输入注册的身份证号!");
            }
            JSONObject json = familyContractService.checkSign(patient);
            if (json == null) {
                return error(-1, "签约验证异常!");
            }
            return write(200, "签约验证成功!", "data", json);
        } catch (Exception e) {
            error(e);
            return error(-1, "签约验证异常!");
        }
    }
			return write(200, "数据加载成功!", "data", json);
		} catch (Exception e) {
			error(e);
			return error(-1, "数据加载失败!");
		}
	}
	/**
	 * 校验openid是否有签约信息
	 * @return
	 */
	@RequestMapping(value = "checkOpenid")
	@ResponseBody
	public String checkOpenid() {
		try {
			if (StringUtils.isEmpty(getOpenid())) {
				return error(-1, "无效的Openid!");
			}
			String doctor = familyContractService.checkPatient(getUID());
			return write(200, "签约验证成功!", "data", doctor);
		} catch (Exception e) {
			error(e);
			return error(-1, "签约验证异常!");
		}
	}
//    /**
//     * 发送签约申请
//     *
//     * @param province     省代码
//     * @param provinceName 省名称
//     * @param city         城市代码
//     * @param cityName     城市名称
//     * @param town         区县代码
//     * @param townName     区县名称
//     * @param address      详细地址
//     * @param name         患者姓名
//     * @param doctor       医生标识
//     * @param idcard       患者身份证号
//     * @param ssc          患者社保卡号
//     * @param mobile       患者手机号
//     * @param emerMobile   患者紧急联系人
//     */
//    @RequestMapping(value = "sign")
//    @ResponseBody
//    public String sign(
//            @RequestParam(required = false) String province,
//            @RequestParam(required = false) String provinceName,
//            @RequestParam(required = false) String city,
//            @RequestParam(required = false) String cityName,
//            @RequestParam(required = false) String town,
//            @RequestParam(required = false) String townName,
//            @RequestParam(required = false) String address,
//            String name,
//            String doctor,
//            String doctorName,
//            @RequestParam(required = false) String patientCode,
//            @RequestParam(required = false) String idcard,
//            String ssc,
//            @RequestParam(required = false) String mobile,
//            @RequestParam(required = false) String emerMobile) {
//        try {
//            // String openid = getOpenid();
//            // String uid = getUID();
//            // if (StringUtils.isEmpty(openid) && StringUtils.isEmpty(uid)) {
//            // return error(-1, "无效的用户请求!");
//            // }
//            // if (StringUtils.isEmpty(idcard)) {
//            // return error(-1, "身份证号不允许为空!");
//            // }
//            // // 解密身份证号
////			 idcard = RSAUtils.getInstance(familyContractService).decryptString(idcard);
////			 idcard = URLDecoder.decode(idcard, "UTF-8");
////			 idcard = StringUtils.reverse(idcard);
//            if (StringUtils.isEmpty(patientCode)) {
//                patientCode = getUID();
//            }
//            Patient patient = patientService.findByCode(patientCode);
//            int amount = familyContractService.hasSingStatus(patient.getIdcard());
//            if (amount > 0) {
//                return error(-1, "只可以签约一个家庭医生!");
//            }
//            JSONObject json = familyContractService.sign(patient.getProvince(), patient.getProvinceName(),
//                    patient.getCity(), patient.getCityName(), patient.getTown(), patient.getTownName(), patient.getAddress(),
//                    patient.getName(), doctor, patient.getOpenid(), patient.getCode(), patient.getIdcard(), patient.getSsc(), patient.getMobile(), emerMobile);
//            int res = json.getInt("res");
//            if (res == -2) {
//                return error(-1, "身份证号与当前登录用户的身份证号不匹配!");
//            } else if (res == -3) {
//                return error(-1, "身份证号已经注册!");
//            }
//            //更新患者信息
////			if (StringUtils.isEmpty(name) ) {
////				patient.setName(name);
////			}
////			if (StringUtils.isEmpty(idcard) ) {
////				patient.setIdcard(idcard);
////			}
//            if (StringUtils.isEmpty(ssc)) {
//                patient.setSsc(ssc);
//            }
////			if (StringUtils.isEmpty(mobile) ) {
////				patient.setMobile(mobile);
////			}
//            patientService.updatePatientInfo(patient);
//            return write(200, "签约申请已发送!", "data", json);
//        } catch (Exception e) {
//            error(e);
//            return error(-1, "签约申请发送失败!");
//        }
//    }
	/**
	 * 校验是否有签约信息
	 * @param idcard
	 * @return
	 */
	@RequestMapping(value = "check")
	@ResponseBody
	public String checkSign(String idcard) {
		try {
			if (StringUtils.isEmpty(idcard)) {
				return error(-1, "请输入身份证号!");
			}
			// 解密身份证号
			idcard = RSAUtils.getInstance(familyContractService).decryptString(idcard);
			idcard = URLDecoder.decode(idcard, "UTF-8");
			idcard = StringUtils.reverse(idcard);
			// 校验身份证号
			IdcardValidator validator = new IdcardValidator();
			if (validator.isValidatedAllIdcard(idcard)) {
				if (idcard.length() == 15) {
					idcard = validator.convertIdcarBy15bit(idcard);
					if (StringUtils.isEmpty(idcard)) {
						return error(-1, "请输入正确的身份证号!");
					}
				}
			}else{
				return error(-1, "请输入正确的身份证号!");
			}
    /**
     * 签约申请
     *
     * @param doctor     医生code
     * @param doctorType 医生类型  2:全科 3:健管
     * @return
     */
    @RequestMapping(value = "sign")
    @ResponseBody
    public String sign(String doctor, int doctorType) {
        try {
            if (StringUtils.isEmpty(doctor)) {
                return error(-1, "签约医生不能为空");
            }
            if (doctorType != 2 && doctorType != 3) {
                return error(-1, "医生类型参数错误");
            }
			Patient patient = patientService.findByCode(getUID());
			if (!StringUtils.equals(patient.getIdcard(), idcard)) {
				return error(-1, "身份证号错误,请输入注册的身份证号!");
			}
			JSONObject json = familyContractService.checkSign(patient);
			if (json == null) {
				return error(-1, "签约验证异常!");
			}
			return write(200, "签约验证成功!", "data", json);
		} catch (Exception e) {
			error(e);
			return error(-1, "签约验证异常!");
		}
	}
            int result = familyContractService.sign(doctor, getUID(), doctorType);
	/**
	 * 发送签约申请
	 * @param province 省代码
	 * @param provinceName 省名称
	 * @param city 城市代码
	 * @param cityName 城市名称
	 * @param town 区县代码
	 * @param townName 区县名称
	 * @param address 详细地址
	 * @param name 患者姓名
	 * @param doctor 医生标识
	 * @param idcard 患者身份证号
	 * @param ssc 患者社保卡号
	 * @param mobile 患者手机号
	 * @param emerMobile 患者紧急联系人
	 */
	@RequestMapping(value = "sign")
	@ResponseBody
	public String sign(
			@RequestParam(required = false) String province,
			@RequestParam(required = false) String provinceName,
			@RequestParam(required = false) String city,
			@RequestParam(required = false) String cityName,
			@RequestParam(required = false) String town,
			@RequestParam(required = false) String townName,
			@RequestParam(required = false) String address,
			String name,
			String doctor,
			String doctorName,
			@RequestParam(required = false) String patientCode,
			@RequestParam(required = false)String idcard,
			String ssc,
			@RequestParam(required = false) String mobile,
			@RequestParam(required = false) String emerMobile) {
		try {
			// String openid = getOpenid();
			// String uid = getUID();
			// if (StringUtils.isEmpty(openid) && StringUtils.isEmpty(uid)) {
			// return error(-1, "无效的用户请求!");
			// }
			// if (StringUtils.isEmpty(idcard)) {
			// return error(-1, "身份证号不允许为空!");
			// }
			// // 解密身份证号
//			 idcard = RSAUtils.getInstance(familyContractService).decryptString(idcard);
//			 idcard = URLDecoder.decode(idcard, "UTF-8");
//			 idcard = StringUtils.reverse(idcard);
			if(StringUtils.isEmpty(patientCode)){
				patientCode=getUID();
			}
			Patient patient = patientService.findByCode(patientCode);
			int amount = familyContractService.hasSingStatus(patient.getIdcard());
			if (amount > 0) {
				return error(-1, "只可以签约一个家庭医生!");
			}
			JSONObject json = familyContractService.sign(patient.getProvince(), patient.getProvinceName(),
					patient.getCity(), patient.getCityName(), patient.getTown(), patient.getTownName(), patient.getAddress(),
					patient.getName(), doctor, patient.getOpenid(), patient.getCode(), patient.getIdcard(), patient.getSsc(), patient.getMobile(), emerMobile);
			int res = json.getInt("res");
			if (res == -2) {
				return error(-1, "身份证号与当前登录用户的身份证号不匹配!");
			}else if (res == -3) {
				return error(-1, "身份证号已经注册!");
			}
			//更新患者信息
//			if (StringUtils.isEmpty(name) ) {
//				patient.setName(name);
//			}
//			if (StringUtils.isEmpty(idcard) ) {
//				patient.setIdcard(idcard);
//			}
			if (StringUtils.isEmpty(ssc) ) {
				patient.setSsc(ssc);
			}
//			if (StringUtils.isEmpty(mobile) ) {
//				patient.setMobile(mobile);
//			}
			patientService.updatePatientInfo(patient);
			return write(200, "签约申请已发送!", "data", json);
		} catch (Exception e) {
			error(e);
			return error(-1, "签约申请发送失败!");
		}
	}
            if (result == -1) {
                return error(-1, "用户信息查询失败");
            } else if (result == -2) {
                return error(-1, "用户已存在签约");
            } else if (result == -3) {
                return error(-1, "医生信息查询失败");
            } else {
                return write(200, "签约申请成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "签约申请失败");
        }
    }
	/**
	 * 取消签约申请
	 * @param doctor
	 * @return
	 */
	@RequestMapping(value = "unsign")
	@ResponseBody
	public String unsign(
			String doctor,
			@RequestParam(required = false) String patientCode
	) {
		try {
			// String openid = getOpenid();
			// String uid = getUID();
			// if (StringUtils.isEmpty(openid) && StringUtils.isEmpty(uid)) {
			// return error(-1, "无效的用户请求!");
			// }
			// -1申请失败, 200申请成功,其他为状态已变化无法取消申请
			patientCode=StringUtils.isNoneBlank(patientCode)?patientCode:getUID();
			int res = familyContractService.unsign(patientCode, doctor);
			if (res == -1) {
				return error(-1, "取消签约失败!");
			} else if (res == 200) {
				return success("签约申请已取消!");
			} else {
				return error(-1, "签约状态已变化,无法申请取消签约!");
			}
		} catch (Exception e) {
			error(e);
			return error(-1, "取消签约失败!");
		}
	}
    /**
     * 取消签约申请
     *
     * @param doctor
     * @return
     */
    @RequestMapping(value = "unsign")
    @ResponseBody
    public String unsign(
            String doctor,
            @RequestParam(required = false) String patientCode
    ) {
        try {
            // String openid = getOpenid();
            // String uid = getUID();
            // if (StringUtils.isEmpty(openid) && StringUtils.isEmpty(uid)) {
            // return error(-1, "无效的用户请求!");
            // }
            // -1申请失败, 200申请成功,其他为状态已变化无法取消申请
            patientCode = StringUtils.isNoneBlank(patientCode) ? patientCode : getUID();
            int res = familyContractService.unsign(patientCode, doctor);
            if (res == -1) {
                return error(-1, "取消签约失败!");
            } else if (res == 200) {
                return success("签约申请已取消!");
            } else {
                return error(-1, "签约状态已变化,无法申请取消签约!");
            }
        } catch (Exception e) {
            error(e);
            return error(-1, "取消签约失败!");
        }
    }
	/**
	 * 申请解约
	 * @param doctor 医生标识
	 * @param doctorName 医生姓名
	 * @return
	 */
	@RequestMapping(value = "surrender")
	@ResponseBody
	public String surrender(String doctor, String doctorName, String reason,
							@RequestParam(required = false) String patientCode) {
		try {
			patientCode=StringUtils.isNoneBlank(patientCode)?patientCode:getUID();
			Patient patient = patientService.findByCode(patientCode);
			int res = familyContractService.surrender(patient.getCode(), patient.getName(), patient.getPhoto(), doctor, doctorName, patient.getOpenid(), reason,patient.getSex());
			if (res == 0) {
				return error(-1, "解约申请发送失败!");
			} else {
				return success("解约申请已发送!");
			}
		} catch (Exception e) {
			error(e);
			return error(-1, "解约申请发送失败!");
		}
	}
    /**
     * 申请解约
     *
     * @param doctor     医生标识
     * @param doctorName 医生姓名
     * @return
     */
    @RequestMapping(value = "surrender")
    @ResponseBody
    public String surrender(String doctor, String doctorName, String reason,
                            @RequestParam(required = false) String patientCode) {
        try {
            patientCode = StringUtils.isNoneBlank(patientCode) ? patientCode : getUID();
            Patient patient = patientService.findByCode(patientCode);
            int res = familyContractService.surrender(patient.getCode(), patient.getName(), patient.getPhoto(), doctor, doctorName, patient.getOpenid(), reason, patient.getSex());
            if (res == 0) {
                return error(-1, "解约申请发送失败!");
            } else {
                return success("解约申请已发送!");
            }
        } catch (Exception e) {
            error(e);
            return error(-1, "解约申请发送失败!");
        }
    }
	/**
	 * 查询患者相关的签约消息
	 * @return
	 */
	@RequestMapping(value = "messages")
	@ResponseBody
	public String messages(long id, int pagesize) {
		try {
			JSONArray array = new JSONArray();
			Page<Message> list = familyContractService.findMessageByPatient(getUID(), id, pagesize);
			if (list != null) {
				for (Message msg : list) {
					if (msg == null) {
						continue;
					}
					JSONObject json = new JSONObject();
					// 消息ID
					json.put("id", msg.getId());
					// 消息标题
					json.put("title", msg.getTitle());
					// 消息内容
					json.put("message", msg.getContent());
					// 消息类型
					json.put("type", msg.getType());
					// 发送人标识
					json.put("sender", msg.getSender());
					// 发送人姓名
					json.put("senderName", msg.getSenderName());
					// 发送人头像
					json.put("senderPhoto", msg.getSenderPhoto());
					// 是否已读:1未读,0已读
					json.put("read", msg.getRead());
					// 是否已处理,1为未处理,0为已处理
					json.put("status", msg.getOver());
					// 性别
					json.put("sex", msg.getSex());
					// 发送时间
					json.put("czrq", DateUtil.dateToStrLong(msg.getCzrq()));
					array.put(json);
				}
			}
			return write(200, "获取消息列表成功!", "list", array);
		} catch (Exception e) {
			error(e);
			return error(-1, "获取消息列表失败!");
		}
	}
    /**
     * 查询患者相关的签约消息
     *
     * @return
     */
    @RequestMapping(value = "messages")
    @ResponseBody
    public String messages(long id, int pagesize) {
        try {
            JSONArray array = new JSONArray();
            Page<Message> list = familyContractService.findMessageByPatient(getUID(), id, pagesize);
            if (list != null) {
                for (Message msg : list) {
                    if (msg == null) {
                        continue;
                    }
                    JSONObject json = new JSONObject();
                    // 消息ID
                    json.put("id", msg.getId());
                    // 消息标题
                    json.put("title", msg.getTitle());
                    // 消息内容
                    json.put("message", msg.getContent());
                    // 消息类型
                    json.put("type", msg.getType());
                    // 发送人标识
                    json.put("sender", msg.getSender());
                    // 发送人姓名
                    json.put("senderName", msg.getSenderName());
                    // 发送人头像
                    json.put("senderPhoto", msg.getSenderPhoto());
                    // 是否已读:1未读,0已读
                    json.put("read", msg.getRead());
                    // 是否已处理,1为未处理,0为已处理
                    json.put("status", msg.getOver());
                    // 性别
                    json.put("sex", msg.getSex());
                    // 发送时间
                    json.put("czrq", DateUtil.dateToStrLong(msg.getCzrq()));
                    array.put(json);
                }
            }
            return write(200, "获取消息列表成功!", "list", array);
        } catch (Exception e) {
            error(e);
            return error(-1, "获取消息列表失败!");
        }
    }
}