浏览代码

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

lyr 8 年之前
父节点
当前提交
e4cb01a93b

+ 5 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientDao.java

@ -6,6 +6,8 @@
 *******************************************************************************/
package com.yihu.wlyy.repository.patient;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
@ -55,4 +57,7 @@ public interface PatientDao extends PagingAndSortingRepository<Patient, Long> {
	@Query(" select p from Patient p where password is null ")
	List<Patient> findAllIdCardPatientAndNoPassword();
	@Query("select p from Patient p where p.status = 1 and p.openid = ?1 order by p.czrq desc")
	Page<Patient> findPatientByOpenid(String openid, Pageable pageable);
}

+ 2 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/PatientInfoService.java

@ -178,8 +178,8 @@ public class PatientInfoService extends BaseService {
        // 绑定用户手机号和openid
        if (!StringUtils.equals(fp.getOpenid(), openid)) {
            fp.setOpenid(openid);
            patientService.updatePatient(fp);
            //fp.setOpenid(openid);
            patientService.updatePatient(fp, openid);
        }
        if (StringUtils.isNoneEmpty(openid)) {

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/ExpensesRemindService.java

@ -192,7 +192,7 @@ public class ExpensesRemindService extends BaseService {
                json.put("doctor", doc.getCode());
                json.put("doctorName", doc.getName());
                json.put("date", DateUtil.dateToStrShort(new Date()));
                json.put("content", "为完成家庭医生签约,尽早为您提供家庭医生服务,请尽快到" + hos.getName() + "(地址:" + hos.getAddress() + ")缴费");
                json.put("content", p.getName() + ",您好!\n为完成家庭医生签约,尽早为您提供家庭医生服务,请尽快到" + hos.getName() + "(地址:" + hos.getAddress() + ")缴费");
                json.put("remark", "");
                // 添加到发送队列
                PushMsgTask.getInstance().putWxMsg(tokenUtils.getAccessToken(), 8, p.getOpenid(), p.getName(), json);

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

@ -929,7 +929,7 @@ public class FamilyContractService extends BaseService {
            Doctor doc = doctorDao.findByCode(sf.getDoctor());
            Hospital hos = hospitalDao.findByCode(doc.getHospital());
            String content = "祝贺您,成功签约" + sf.getDoctorName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
            String content = sf.getName() + ",您好!祝贺您,成功签约" + sf.getDoctorName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
                    "为了给您提供更好的服务,请尽快到" + (hos != null ? hos.getName() : "") + "社区(地址:" +
                    (hos != null ? hos.getAddress() : "") + ")缴费。";
            JSONObject json = new JSONObject();
@ -1112,7 +1112,7 @@ public class FamilyContractService extends BaseService {
            json.put("doctor", StringUtils.isEmpty(sf.getDoctor()) ? sf.getDoctorHealth() : sf.getDoctor());
            json.put("doctorName", StringUtils.isEmpty(sf.getDoctor()) ? sf.getDoctorHealthName() : sf.getDoctorName());
            json.put("date", DateUtil.dateToStrShort(new Date()));
            json.put("content", "您与 " + (StringUtils.isEmpty(sf.getDoctor()) ? sf.getDoctorHealthName() : sf.getDoctorName()) + " 医生建立家庭医生签约关系失败,请查看!");
            json.put("content", sf.getName() + ",您好!您与 " + (StringUtils.isEmpty(sf.getDoctor()) ? sf.getDoctorHealthName() : sf.getDoctorName()) + " 医生建立家庭医生签约关系失败,请查看!");
            json.put("remark", "您好,签约家庭医生失败通知");
            // 添加到发送队列
            PushMsgTask.getInstance().putWxMsg(access_token, 2, sf.getOpenid(), sf.getName(), json);
@ -1131,7 +1131,7 @@ public class FamilyContractService extends BaseService {
            Doctor doc = doctorDao.findByCode(StringUtils.isNotEmpty(doctor) ? sf.getDoctorHealth() : sf.getDoctor());
            Hospital hos = hospitalDao.findByCode(doc.getHospital());
            String content = "祝贺您,成功签约" + doc.getName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
            String content = sf.getName() + ",您好!祝贺您,成功签约" + doc.getName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
                    "为了给您提供更好的服务,请尽快到" + (hos != null ? hos.getName() : "") + "社区(地址:" +
                    (hos != null ? hos.getAddress() : "") + ")缴费。";
            // 同意签约
@ -1200,7 +1200,7 @@ public class FamilyContractService extends BaseService {
            json.put("doctor", sf.getDoctor());
            json.put("doctorName", sf.getDoctorName());
            json.put("orgName", sf.getHospitalName());
            json.put("remark", "您好,您的签约医生已同意您的解约申请,解约已生效。");
            json.put("remark", sf.getName() + ",您好!您的签约医生已同意您的解约申请,解约已生效。");
            // 添加到发送队列
            PushMsgTask.getInstance().putWxMsg(access_token, 5, sf.getOpenid(), sf.getName(), json);
        } else {
@ -1214,7 +1214,7 @@ public class FamilyContractService extends BaseService {
            json.put("doctor", sf.getDoctor());
            json.put("doctorName", sf.getDoctorName());
            json.put("orgName", sf.getHospitalName());
            json.put("remark", "您好,您的签约医生拒绝您的解约申请,解约失败。");
            json.put("remark", sf.getName() + ",您好!您的签约医生拒绝您的解约申请,解约失败。");
            // 添加到发送队列
            PushMsgTask.getInstance().putWxMsg(access_token, 5, sf.getOpenid(), sf.getName(), json);
        }

+ 16 - 5
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/account/PatientService.java

@ -20,11 +20,15 @@ import com.yihu.wlyy.util.IdcardInfoExtractor;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.utils.Clock;
import java.util.Date;
import java.util.List;
/**
 * 患者基本信息类.
@ -92,10 +96,16 @@ public class PatientService extends TokenService {
     *
     * @param patient
     */
    public void updatePatient(Patient patient) {
//		if (StringUtils.isNotEmpty(patient.getOpenid())) {
//			patientDao.clearOpenid(patient.getCode(), patient.getOpenid());
//		}
    public void updatePatient(Patient patient, String openid) {
        if (patientDao.countByOpenid(openid) >= 10) {
            Sort sort = new Sort(Sort.Direction.DESC, "czrq");
            PageRequest pageRequest = new PageRequest(0, 1, sort);
            Page<Patient> pPage = patientDao.findPatientByOpenid(openid, pageRequest);
            for (Patient p : pPage) {
                p.setOpenid("");
                patientDao.save(p);
            }
        }
        patientDao.save(patient);
        if (StringUtils.isNotEmpty(patient.getOpenid())) {
            signFamilyDao.updateOpenidByPatient(patient.getOpenid(), patient.getCode());
@ -128,10 +138,11 @@ public class PatientService extends TokenService {
        patient.setDiseaseCondition(0);
        patient.setRecordAmount(0);
        patient.setPoints(0);
        patient.setOpenid("");
        Patient temp = patientDao.save(patient);
        if (temp != null) {
            // 更新openid
            updatePatient(temp);
            updatePatient(temp, imei);
            // 生成登录tokey
            Token token = newToken(temp.getCode(), imei, platform);
            if (token != null) {

+ 4 - 10
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/account/WechatController.java

@ -387,11 +387,8 @@ public class WechatController extends WeixinBaseController {
                if (loginPassword.equals(patient.getPassword())) {
                    // 绑定用户手机号和openid
                    if (!StringUtils.equals(patient.getOpenid(), openid)) {
                        if (patientService.countByOpenid(openid) >= 11) {
                            return error(-1,"该微信号已绑定11人,无法再绑定");
                        }
                        patient.setOpenid(openid);
                        patientService.updatePatient(patient);
                        //patient.setOpenid(openid);
                        patientService.updatePatient(patient, openid);
                    }
                    // 用户校验通过,生成token
@ -475,11 +472,8 @@ public class WechatController extends WeixinBaseController {
                loginLog.setUserCode(patient.getCode());
                // 绑定用户手机号和openid
                if (!StringUtils.equals(patient.getOpenid(), openid)) {
                    if (patientService.countByOpenid(openid) >= 11) {
                        return error(-1,"该微信号已绑定11人,无法再绑定");
                    }
                    patient.setOpenid(openid);
                    patientService.updatePatient(patient);
                    //patient.setOpenid(openid);
                    patientService.updatePatient(patient, openid);
                }
                // 用户校验通过,生成token

+ 19 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/account/DoctorController.java

@ -3,6 +3,7 @@ package com.yihu.wlyy.web.doctor.account;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
@ -21,6 +22,7 @@ import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@ -73,6 +75,8 @@ public class DoctorController extends BaseController {
    private HospitalDeptService deptService;
    @Autowired
    private DoctorWorkTimeService workTimeService;
    @Autowired
    StringRedisTemplate redisTemplate;
    /**
     * 社区医院下医生列表查询接口 没分页
@ -1560,8 +1564,18 @@ public class DoctorController extends BaseController {
                                          @RequestParam(required = false) String isAll) {
        try {
            if (StringUtils.isNotEmpty(isAll) && isAll.equals("1")) {
                int result = doctorInfoService.updateTeamHealthDoctorsAll(newDoctorCode, getUID());
                String status = redisTemplate.opsForValue().get("jianguanshifenpei:" + getUID());
                status = StringUtils.isEmpty(status) ? "0" : status;
                if(!status.equals("1")){
                    redisTemplate.opsForValue().set("jianguanshifenpei:" + getUID(),"1");
                    redisTemplate.expire("jianguanshifenpei:" + getUID(), 20, TimeUnit.MINUTES);
                } else {
                    return error(-1,"正在分配,请勿重复分配");
                }
                int result = doctorInfoService.updateTeamHealthDoctorsAll(newDoctorCode, getUID());
                redisTemplate.opsForValue().set("jianguanshifenpei:" + getUID(),"0");
                redisTemplate.expire("jianguanshifenpei:" + getUID(), 20, TimeUnit.MINUTES);
                if (result == 1) {
                    return write(200, "分配健管师成功");
                } else if (result == 2) {
@ -1575,6 +1589,10 @@ public class DoctorController extends BaseController {
            }
            return write(200, "更新成功");
        } catch (Exception e) {
            if(isAll.equals("1")) {
                redisTemplate.opsForValue().set("jianguanshifenpei:" + getUID(), "0");
                redisTemplate.expire("jianguanshifenpei:" + getUID(), 20, TimeUnit.MINUTES);
            }
            e.printStackTrace();
            return error(-1, "更新失败");
        }

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultController.java

@ -503,7 +503,7 @@ public class DoctorConsultController extends WeixinBaseController {
                    Patient p = patientService.findByCode(patient);
                    if (ct != null && p != null && StringUtils.isNotEmpty(p.getOpenid())) {
                        JSONObject json = new JSONObject();
                        json.put("first", "问诊回复提醒");
                        json.put("first", p.getName() + ",您好!\n您的健康咨询有新的回复");
                        json.put("toUser", p.getCode());
                        String symp = ct.getSymptoms();
                        json.put("consultcontent", StringUtils.isNotEmpty(symp) && symp.length() > 50 ? (symp.substring(0, 50) + "...")  : content);

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultPublicController.java

@ -231,7 +231,7 @@ public class DoctorConsultPublicController extends BaseController {
				Patient p = patientService.findByCode(cp.getPatient());
				JSONObject json = new JSONObject();
				json.put("isPublic", 1);
				json.put("first", "您的公共咨询有新的回复");
				json.put("first", p.getName() + ",您好!\n您的公共咨询有新的回复");
				json.put("toUser", p.getCode());
				String symp = cp.getContent();
				json.put("consultcontent", StringUtils.isNotEmpty(symp) && symp.length() > 50 ? (symp.substring(0, 50) + "...")  : content);

+ 2 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthEduArticleController.java

@ -271,7 +271,7 @@ public class DoctorHealthEduArticleController extends WeixinBaseController {
			}
			// 查询医生信息
			Doctor doctor = doctorService.findDoctorByCode(getUID());
			String msgHead = doctor.getName()+"医生给您发来了一篇患教文章";
			String msgHead =  doctor.getName()+"医生给您发来了一篇患教文章";
			String endMsg = "为了您的健康,"+doctor.getName()+"医生给您发送了一篇患教文章,请仔细查阅,如有问题,可随时咨询医生。";
			JSONArray messages = new JSONArray();
			for (String p : patientSet) {
@ -309,7 +309,7 @@ public class DoctorHealthEduArticleController extends WeixinBaseController {
					if (StringUtils.isNotEmpty(patientTemp.getOpenid())) {
						// 推送消息给微信端
						JSONObject json = new JSONObject();
						json.put("first",msgHead);
						json.put("first", patientTemp.getName() + ",您好!\n" + msgHead);
						json.put("toUser",p);
						json.put("article",temp.getCode()+"");
						json.put("title",temp.getTitle());

+ 589 - 600
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/BookingController.java

@ -1,8 +1,10 @@
package com.yihu.wlyy.web.third;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientReservation;
import com.yihu.wlyy.service.app.reservation.PatientReservationService;
import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.third.guahao.GuahaoDoctor;
import com.yihu.wlyy.service.third.guahao.GuahaoXMService;
@ -32,6 +34,7 @@ import java.util.*;
/**
 * 预约挂号
 *
 * @author hzp at 2016-08-30
 */
@Controller
@ -39,246 +42,244 @@ import java.util.*;
@Api(description = "预约挂号接口")
public class BookingController extends WeixinBaseController {
	@Autowired
	private GuahaoXMService guahaoXM;
    @Autowired
    private GuahaoXMService guahaoXM;
	@Autowired
	private GuahaoYihuService guahaoYihu;
    @Autowired
    private GuahaoYihuService guahaoYihu;
	@Autowired
	private PatientReservationService patientReservationService;
    @Autowired
    private PatientReservationService patientReservationService;
	@Autowired
	private PatientService patientService;
    @Autowired
    private PatientService patientService;
	/**
	 * 根据城市编码获取相应挂号服务
	 * @return
    @Autowired
    private DoctorService doctorService;
    /**
     * 根据城市编码获取相应挂号服务
     *
     * @return
     */
    private IGuahaoService getService(String city) {
        IGuahaoService re = guahaoYihu;
        if (city != null && city.equals("350200")) {
            re = guahaoXM;
        }
        return re;
    }
    /**
     * 获取机构列表
     */
    @RequestMapping(value = "GetOrgList", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("获取机构列表")
    public String GetOrgList(@ApiParam(name = "city", value = "城市编码", defaultValue = "350200")
                             @RequestParam(value = "city", required = true) String city,
                             @ApiParam(name = "filter", value = "过滤条件", defaultValue = "")
                             @RequestParam(value = "filter", required = false) String filter,
                             @ApiParam(name = "type", value = "类型", defaultValue = "1")
                             @RequestParam(value = "type", required = false) String type,
                             @ApiParam(name = "pageIndex", value = "第几页", defaultValue = "")
                             @RequestParam(value = "pageIndex", required = false) Integer pageIndex,
                             @ApiParam(name = "pageSize", value = "每页记录数", defaultValue = "")
                             @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        try {
            List<Map<String, String>> list = getService(city).GetOrgList(city, filter, type, pageIndex, pageSize);
            return write(200, "获取机构列表成功!", "data", list);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 获取科室接口
     */
    @RequestMapping(value = "GetOrgDepList", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("获取科室接口")
    public String GetOrgDepList(@ApiParam(name = "city", value = "城市编码", defaultValue = "350200")
                                @RequestParam(value = "city", required = true) String city,
                                @ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211A1001")
                                @RequestParam(value = "hospitalId", required = true) String hospitalId,
                                @ApiParam(name = "filter", value = "过滤条件", defaultValue = "")
                                @RequestParam(value = "filter", required = false) String filter,
                                @ApiParam(name = "pageIndex", value = "第几页", defaultValue = "")
                                @RequestParam(value = "pageIndex", required = false) Integer pageIndex,
                                @ApiParam(name = "pageSize", value = "每页记录数", defaultValue = "")
                                @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        try {
            List<Map<String, String>> list = getService(city).GetOrgDepList(hospitalId, filter, pageIndex, pageSize);
            return write(200, "获取科室列表成功!", "data", list);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 获取医生列表接口
     */
    @RequestMapping(value = "GetDoctorList", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("获取医生接口")
    public String GetDoctorList(@ApiParam(name = "city", value = "城市编码", defaultValue = "350200")
                                @RequestParam(value = "city", required = true) String city,
                                @ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211A1001")
                                @RequestParam(value = "hospitalId", required = true) String hospitalId,
                                @ApiParam(name = "hosDeptId", value = "科室ID", defaultValue = "1040610")
                                @RequestParam(value = "hosDeptId", required = true) String hosDeptId,
                                @ApiParam(name = "filter", value = "过滤条件", defaultValue = "")
                                @RequestParam(value = "filter", required = false) String filter,
                                @ApiParam(name = "pageIndex", value = "第几页", defaultValue = "")
                                @RequestParam(value = "pageIndex", required = false) Integer pageIndex,
                                @ApiParam(name = "pageSize", value = "每页记录数", defaultValue = "")
                                @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        try {
            List<GuahaoDoctor> list = getService(city).GetDoctorList(hospitalId, hosDeptId, filter, pageIndex, pageSize);
            return write(200, "获取医生列表成功!", "data", list);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 获取医生排班接口
     */
    @RequestMapping(value = "GetDoctorArrange", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("获取医生排班接口(包含排班详细)")
    public String GetDoctorArrange(@ApiParam(name = "city", value = "城市编码", defaultValue = "350200")
                                   @RequestParam(value = "city", required = true) String city,
                                   @ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211G1102")
                                   @RequestParam(value = "hospitalId", required = true) String hospitalId,
                                   @ApiParam(name = "hosDeptId", value = "科室ID", defaultValue = "3020001")
                                   @RequestParam(value = "hosDeptId", required = true) String hosDeptId,
                                   @ApiParam(name = "doctorId", value = "医生ID", defaultValue = "AA2")
                                   @RequestParam(value = "doctorId", required = true) String doctorId) {
        try {
            List<Map<String, Object>> list = getService(city).GetDoctorArrange(hospitalId, hosDeptId, doctorId);
            return write(200, "获取医生排班成功!", "data", list);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 获取医生排班接口
     */
    @RequestMapping(value = "GetDoctorArrangeSimple", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("获取医生排班接口(一级)")
    public String GetDoctorArrangeSimple(@ApiParam(name = "city", value = "城市编码", defaultValue = "350200")
                                         @RequestParam(value = "city", required = true) String city,
                                         @ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211A1001")
                                         @RequestParam(value = "hospitalId", required = true) String hospitalId,
                                         @ApiParam(name = "hosDeptId", value = "科室ID", defaultValue = "1010210")
                                         @RequestParam(value = "hosDeptId", required = true) String hosDeptId,
                                         @ApiParam(name = "doctorId", value = "医生ID", defaultValue = "03101")
                                         @RequestParam(value = "doctorId", required = true) String doctorId) {
        try {
            List<Map<String, String>> list = getService(city).GetDoctorArrangeSimple(hospitalId, hosDeptId, doctorId);
            return write(200, "获取医生排班成功!", "data", list);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 根据医生编码获取医生详细信息
     */
    @RequestMapping(value = "GetDoctorInfo", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("根据医生编码获取医生详细信息")
    public String GetDoctorInfo(@ApiParam(name = "city", value = "城市编码", defaultValue = "350200")
                                @RequestParam(value = "city", required = true) String city,
                                @ApiParam(name = "doctorId", value = "医生id", defaultValue = "07101")
                                @RequestParam(value = "doctorId", required = true) String doctorId,
                                @ApiParam(name = "hospitalId", value = "医院id", defaultValue = "350211A1001")
                                @RequestParam(value = "hospitalId", required = true) String hospitalId,
                                @ApiParam(name = "hosDeptId", value = "科室id", defaultValue = "1040610")
                                @RequestParam(value = "hosDeptId", required = true) String hosDeptId) {
        try {
            GuahaoDoctor doctor = getService(city).GetDoctorInfo(doctorId, hospitalId, hosDeptId);
            return write(200, "获取医生信息成功!", "data", doctor);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 创建挂号单
     */
	private  IGuahaoService getService(String city)
	{
		IGuahaoService re = guahaoYihu;
		if(city!=null && city.equals("350200"))
		{
			re = guahaoXM;
		}
		return re;
	}
	/**
	 * 获取机构列表
	 */
	@RequestMapping(value = "GetOrgList",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("获取机构列表")
	public String GetOrgList(@ApiParam(name="city",value="城市编码",defaultValue = "350200")
							  @RequestParam(value="city",required = true) String city,
							  @ApiParam(name="filter",value="过滤条件",defaultValue = "")
							  @RequestParam(value="filter",required = false) String filter,
							  @ApiParam(name="type",value="类型",defaultValue = "1")
							  @RequestParam(value="type",required = false) String type,
							  @ApiParam(name="pageIndex",value="第几页",defaultValue = "")
							  @RequestParam(value="pageIndex",required = false) Integer pageIndex,
							  @ApiParam(name="pageSize",value="每页记录数",defaultValue = "")
							  @RequestParam(value="pageSize",required = false) Integer pageSize) {
		try {
			List<Map<String,String>> list =  getService(city).GetOrgList(city,filter,type,pageIndex,pageSize);
			return write(200, "获取机构列表成功!", "data", list);
		} catch (Exception e) {
			return error(-1,e.getMessage());
		}
	}
	/**
	 * 获取科室接口
	 */
	@RequestMapping(value = "GetOrgDepList",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("获取科室接口")
	public String GetOrgDepList(@ApiParam(name="city",value="城市编码",defaultValue = "350200")
							  @RequestParam(value="city",required = true) String city,
							  @ApiParam(name="hospitalId",value="医院ID",defaultValue = "350211A1001")
							  @RequestParam(value="hospitalId",required = true) String hospitalId,
							  @ApiParam(name="filter",value="过滤条件",defaultValue = "")
							  @RequestParam(value="filter",required = false) String filter,
							  @ApiParam(name="pageIndex",value="第几页",defaultValue = "")
							  @RequestParam(value="pageIndex",required = false) Integer pageIndex,
							  @ApiParam(name="pageSize",value="每页记录数",defaultValue = "")
							  @RequestParam(value="pageSize",required = false) Integer pageSize) {
		try {
			List<Map<String,String>> list =  getService(city).GetOrgDepList(hospitalId,filter,pageIndex,pageSize);
			return write(200, "获取科室列表成功!", "data", list);
		} catch (Exception e) {
			return error(-1,e.getMessage());
		}
	}
	/**
	 * 获取医生列表接口
	 */
	@RequestMapping(value = "GetDoctorList",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("获取医生接口")
	public String GetDoctorList(@ApiParam(name="city",value="城市编码",defaultValue = "350200")
								@RequestParam(value="city",required = true) String city,
								@ApiParam(name="hospitalId",value="医院ID",defaultValue = "350211A1001")
								@RequestParam(value="hospitalId",required = true) String hospitalId,
								@ApiParam(name="hosDeptId",value="科室ID",defaultValue = "1040610")
								@RequestParam(value="hosDeptId",required = true) String hosDeptId,
								@ApiParam(name="filter",value="过滤条件",defaultValue = "")
								@RequestParam(value="filter",required = false) String filter,
								@ApiParam(name="pageIndex",value="第几页",defaultValue = "")
								@RequestParam(value="pageIndex",required = false) Integer pageIndex,
								@ApiParam(name="pageSize",value="每页记录数",defaultValue = "")
								@RequestParam(value="pageSize",required = false) Integer pageSize) {
		try {
			List<GuahaoDoctor> list =  getService(city).GetDoctorList(hospitalId,hosDeptId,filter,pageIndex,pageSize);
			return write(200, "获取医生列表成功!", "data", list);
		}
		catch (Exception e)
		{
			return error(-1,e.getMessage());
		}
	}
	/**
	 * 获取医生排班接口
	 */
	@RequestMapping(value = "GetDoctorArrange",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("获取医生排班接口(包含排班详细)")
	public String GetDoctorArrange(@ApiParam(name="city",value="城市编码",defaultValue = "350200")
								@RequestParam(value="city",required = true) String city,
								@ApiParam(name="hospitalId",value="医院ID",defaultValue = "350211G1102")
								@RequestParam(value="hospitalId",required = true) String hospitalId,
								@ApiParam(name="hosDeptId",value="科室ID",defaultValue = "3020001")
								@RequestParam(value="hosDeptId",required = true) String hosDeptId,
								@ApiParam(name="doctorId",value="医生ID",defaultValue = "AA2")
								@RequestParam(value="doctorId",required = true) String doctorId) {
		try {
			List<Map<String,Object>> list =  getService(city).GetDoctorArrange(hospitalId,hosDeptId,doctorId);
			return write(200, "获取医生排班成功!", "data", list);
		} catch (Exception e) {
			return error(-1,e.getMessage());
		}
	}
	/**
	 * 获取医生排班接口
	*/
	@RequestMapping(value = "GetDoctorArrangeSimple",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("获取医生排班接口(一级)")
	public String GetDoctorArrangeSimple(@ApiParam(name="city",value="城市编码",defaultValue = "350200")
								   @RequestParam(value="city",required = true) String city,
								   @ApiParam(name="hospitalId",value="医院ID",defaultValue = "350211A1001")
								   @RequestParam(value="hospitalId",required = true) String hospitalId,
								   @ApiParam(name="hosDeptId",value="科室ID",defaultValue = "1010210")
								   @RequestParam(value="hosDeptId",required = true) String hosDeptId,
								   @ApiParam(name="doctorId",value="医生ID",defaultValue = "03101")
								   @RequestParam(value="doctorId",required = true) String doctorId) {
		try {
			List<Map<String,String>> list =  getService(city).GetDoctorArrangeSimple(hospitalId,hosDeptId,doctorId);
			return write(200, "获取医生排班成功!", "data", list);
		} catch (Exception e) {
			return error(-1,e.getMessage());
		}
	}
	/**
	 * 根据医生编码获取医生详细信息
	 */
	@RequestMapping(value = "GetDoctorInfo",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("根据医生编码获取医生详细信息")
	public String GetDoctorInfo(@ApiParam(name="city",value="城市编码",defaultValue = "350200")
								@RequestParam(value="city",required = true) String city,
								@ApiParam(name="doctorId",value="医生id",defaultValue = "07101")
								@RequestParam(value="doctorId",required = true) String doctorId,
								@ApiParam(name="hospitalId",value="医院id",defaultValue = "350211A1001")
								@RequestParam(value="hospitalId",required = true) String hospitalId,
								@ApiParam(name="hosDeptId",value="科室id",defaultValue = "1040610")
								@RequestParam(value="hosDeptId",required = true) String hosDeptId)
	{
		try {
			GuahaoDoctor doctor = getService(city).GetDoctorInfo(doctorId,hospitalId,hosDeptId);
			return write(200, "获取医生信息成功!","data",doctor);
		} catch (Exception e) {
			return error(-1,e.getMessage());
		}
	}
	/**
	 * 创建挂号单
	 */
	@RequestMapping(value = "CreateOrder",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("创建挂号单")
	public String CreateOrder(@ApiParam(name="city",value="城市编码",defaultValue = "350200")
								   @RequestParam(value="city",required = true) String city,
								   @ApiParam(name="hospitalId",value="医院ID",defaultValue = "350211A1001")
								   @RequestParam(value="hospitalId",required = true) String hospitalId,
							       @ApiParam(name="hospitalName",value="医院名称",defaultValue = "厦门大学附属第一医院")
								   @RequestParam(value="hospitalName",required = true) String hospitalName,
								   @ApiParam(name="hosDeptId",value="科室ID",defaultValue = "1040610")
								   @RequestParam(value="hosDeptId",required = true) String hosDeptId,
							       @ApiParam(name="hosDeptName",value="医院科室名称",defaultValue = "儿二科")
								   @RequestParam(value="hosDeptName",required = true) String hosDeptName,
								   @ApiParam(name="doctorId",value="医生ID",defaultValue = "07101")
								   @RequestParam(value="doctorId",required = true) String doctorId,
							       @ApiParam(name="doctorName",value="医生姓名",defaultValue = "林素莲")
								   @RequestParam(value="doctorName",required = true) String doctorName,
							       @ApiParam(name="arrangeDate",value="排班信息",defaultValue = "{\"sectionType\":\"a\",\"startTime\":\"2016-09-02 08:20:00\",\"endTime\":\"2016-09-02 08:30:00\"}")
								   @RequestParam(value="arrangeDate",required = true) String arrangeDate,
							       @ApiParam(name="patient",value="患者代码",defaultValue = "01954b2ebbb24a40a05da9d2f5c94795")
								   @RequestParam(value="patient",required = true) String patient,
							       @ApiParam(name="patientName",value="患者姓名",defaultValue = "张锦川")
								   @RequestParam(value="patientName",required = true) String patientName,
							       @ApiParam(name="cardNo",value="身份证号码",defaultValue = "35052419880511553X")
								   @RequestParam(value="cardNo",required = true) String cardNo,
							       @ApiParam(name="clinicCard",value="市民卡号",defaultValue = "D57117706")
								   @RequestParam(value="clinicCard",required = true) String clinicCard,
							       @ApiParam(name="patientPhone",value="患者手机",defaultValue = "13950116510")
								   @RequestParam(value="patientPhone",required = true) String patientPhone) {
		try {
			if (StringUtils.isEmpty(patientName)) {
				return error(-1, "未设置姓名!");
			}
			if (StringUtils.isEmpty(cardNo)) {
				return error(-1, "未设置身份证号!");
			}
			if (StringUtils.isEmpty(clinicCard)) {
				return error(-1, "未设置社保卡号!");
			}
			if (StringUtils.isEmpty(patientPhone)) {
				return error(-1, "未设置手机号码!");
			}
			String orderCode =  getService(city).CreateOrder(hospitalId,hospitalName,hosDeptId,hosDeptName,doctorId,doctorName,arrangeDate,patient,patientName,cardNo,clinicCard,patientPhone,null,null);
			//预约发送微信消息
			PatientReservation obj = patientReservationService.findByCode(orderCode);
			if(obj!=null)
			{
				Patient p = patientService.findByCode(obj.getPatient());
				String msg = "您成功预约了 " + obj.getOrgName() + " " + obj.getDoctorName() + " " + obj.getStartTime() + " 的号源!";
				if (StringUtils.isNotEmpty(p.getOpenid())) {
					// 推送消息给微信端
					JSONObject json = new JSONObject();
					json.put("first", "预约挂号提醒");
					json.put("toUser", p.getCode());
					json.put("id",obj.getId());
					json.put("date", obj.getStartTime());
					json.put("orgName", obj.getOrgName());
					json.put("doctorName", obj.getDoctorName());
					json.put("deptName", obj.getDeptName());
					json.put("remark", msg);
					PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, p.getOpenid(), p.getName(), json);
				}
				//发送短信小时
				// 调用总部发送信息的接口
				String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(msg, p.getMobile()), "GBK");
				JSONObject json = toJson(result);
    @RequestMapping(value = "CreateOrder", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("创建挂号单")
    public String CreateOrder(@ApiParam(name = "city", value = "城市编码", defaultValue = "350200")
                              @RequestParam(value = "city", required = true) String city,
                              @ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211A1001")
                              @RequestParam(value = "hospitalId", required = true) String hospitalId,
                              @ApiParam(name = "hospitalName", value = "医院名称", defaultValue = "厦门大学附属第一医院")
                              @RequestParam(value = "hospitalName", required = true) String hospitalName,
                              @ApiParam(name = "hosDeptId", value = "科室ID", defaultValue = "1040610")
                              @RequestParam(value = "hosDeptId", required = true) String hosDeptId,
                              @ApiParam(name = "hosDeptName", value = "医院科室名称", defaultValue = "儿二科")
                              @RequestParam(value = "hosDeptName", required = true) String hosDeptName,
                              @ApiParam(name = "doctorId", value = "医生ID", defaultValue = "07101")
                              @RequestParam(value = "doctorId", required = true) String doctorId,
                              @ApiParam(name = "doctorName", value = "医生姓名", defaultValue = "林素莲")
                              @RequestParam(value = "doctorName", required = true) String doctorName,
                              @ApiParam(name = "arrangeDate", value = "排班信息", defaultValue = "{\"sectionType\":\"a\",\"startTime\":\"2016-09-02 08:20:00\",\"endTime\":\"2016-09-02 08:30:00\"}")
                              @RequestParam(value = "arrangeDate", required = true) String arrangeDate,
                              @ApiParam(name = "patient", value = "患者代码", defaultValue = "01954b2ebbb24a40a05da9d2f5c94795")
                              @RequestParam(value = "patient", required = true) String patient,
                              @ApiParam(name = "patientName", value = "患者姓名", defaultValue = "张锦川")
                              @RequestParam(value = "patientName", required = true) String patientName,
                              @ApiParam(name = "cardNo", value = "身份证号码", defaultValue = "35052419880511553X")
                              @RequestParam(value = "cardNo", required = true) String cardNo,
                              @ApiParam(name = "clinicCard", value = "市民卡号", defaultValue = "D57117706")
                              @RequestParam(value = "clinicCard", required = true) String clinicCard,
                              @ApiParam(name = "patientPhone", value = "患者手机", defaultValue = "13950116510")
                              @RequestParam(value = "patientPhone", required = true) String patientPhone) {
        try {
            if (StringUtils.isEmpty(patientName)) {
                return error(-1, "未设置姓名!");
            }
            if (StringUtils.isEmpty(cardNo)) {
                return error(-1, "未设置身份证号!");
            }
            if (StringUtils.isEmpty(clinicCard)) {
                return error(-1, "未设置社保卡号!");
            }
            if (StringUtils.isEmpty(patientPhone)) {
                return error(-1, "未设置手机号码!");
            }
            String orderCode = getService(city).CreateOrder(hospitalId, hospitalName, hosDeptId, hosDeptName, doctorId, doctorName, arrangeDate, patient, patientName, cardNo, clinicCard, patientPhone, null, null);
            //预约发送微信消息
            PatientReservation obj = patientReservationService.findByCode(orderCode);
            if (obj != null) {
                Patient p = patientService.findByCode(obj.getPatient());
                String msg = "您成功预约了 " + obj.getOrgName() + " " + obj.getDoctorName() + " " + obj.getStartTime() + " 的号源!";
                if (StringUtils.isNotEmpty(p.getOpenid())) {
                    // 推送消息给微信端
                    JSONObject json = new JSONObject();
                    json.put("first", "");
                    json.put("toUser", p.getCode());
                    json.put("id", obj.getId());
                    json.put("date", obj.getStartTime());
                    json.put("orgName", obj.getOrgName());
                    json.put("doctorName", obj.getDoctorName());
                    json.put("deptName", obj.getDeptName());
                    json.put("remark", p.getName() + ",您好!" + msg);
                    PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, p.getOpenid(), p.getName(), json);
                }
                //发送短信小时
                // 调用总部发送信息的接口
                //String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(msg, p.getMobile()), "GBK");
                //JSONObject json = toJson(result);
//				if (json == null) {
//					// 发送失败
//					throw new Exception("短信发送失败!");
@ -287,370 +288,358 @@ public class BookingController extends WeixinBaseController {
//				} else {
//					//发送成功,保存到数据库
//				}
				return write(200, "创建挂号单成功!");
			}
			else{
				return error(-1,"创建挂号单失败!");
			}
		}
		catch (Exception e) {
			return error(-1,e.getMessage());
		}
	}
	public static List<NameValuePair> buildSmsParams(String content, String mobile) {
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("SpCode", SystemConf.getInstance().getSmsCode()));
		params.add(new BasicNameValuePair("LoginName", SystemConf.getInstance().getSmsName()));
		params.add(new BasicNameValuePair("Password", SystemConf.getInstance().getSmsPassword()));
		params.add(new BasicNameValuePair("MessageContent", content));
		params.add(new BasicNameValuePair("UserNumber", mobile));
		params.add(new BasicNameValuePair("SerialNumber", String.valueOf(System.currentTimeMillis())));
		params.add(new BasicNameValuePair("ScheduleTime", ""));
		params.add(new BasicNameValuePair("f", "1"));
		return params;
	}
	public static JSONObject toJson(String result) {
		JSONObject json = new JSONObject();
		try {
			String[] temps = result.split("&");
			for (String temp : temps) {
				if (temp.split("=").length != 2) {
					continue;
				}
				String key = temp.split("=")[0];
				String value = temp.split("=")[1];
				json.put(key, value);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return json;
	}
	/**
	 * 创建挂号单
	 */
	@RequestMapping(value = "CreateOrderByDoctor",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("创建挂号单")
	public String CreateOrderByDoctor(@ApiParam(name="city",value="城市编码",defaultValue = "350200")
							  @RequestParam(value="city",required = true) String city,
							  @ApiParam(name="hospitalId",value="医院ID",defaultValue = "350211A1001")
							  @RequestParam(value="hospitalId",required = true) String hospitalId,
							  @ApiParam(name="hospitalName",value="医院名称",defaultValue = "厦门大学附属第一医院")
							  @RequestParam(value="hospitalName",required = true) String hospitalName,
							  @ApiParam(name="hosDeptId",value="科室ID",defaultValue = "1040610")
							  @RequestParam(value="hosDeptId",required = true) String hosDeptId,
							  @ApiParam(name="hosDeptName",value="医院科室名称",defaultValue = "儿二科")
							  @RequestParam(value="hosDeptName",required = true) String hosDeptName,
							  @ApiParam(name="doctorId",value="医生ID",defaultValue = "07101")
							  @RequestParam(value="doctorId",required = true) String doctorId,
							  @ApiParam(name="doctorName",value="医生姓名",defaultValue = "林素莲")
							  @RequestParam(value="doctorName",required = true) String doctorName,
							  @ApiParam(name="arrangeDate",value="排班信息",defaultValue = "{\"sectionType\":\"a\",\"startTime\":\"2016-09-02 08:20:00\",\"endTime\":\"2016-09-02 08:30:00\"}")
							  @RequestParam(value="arrangeDate",required = true) String arrangeDate,
							  @ApiParam(name="patient",value="患者代码",defaultValue = "01954b2ebbb24a40a05da9d2f5c94795")
							  @RequestParam(value="patient",required = true) String patient,
							  @ApiParam(name="patientName",value="患者姓名",defaultValue = "张锦川")
							  @RequestParam(value="patientName",required = true) String patientName,
							  @ApiParam(name="cardNo",value="身份证号码",defaultValue = "35052419880511553X")
							  @RequestParam(value="cardNo",required = true) String cardNo,
							  @ApiParam(name="clinicCard",value="市民卡号",defaultValue = "D57117706")
							  @RequestParam(value="clinicCard",required = true) String clinicCard,
							  @ApiParam(name="patientPhone",value="患者手机",defaultValue = "13950116510")
							  @RequestParam(value="patientPhone",required = true) String patientPhone,
                              @ApiParam(name="dcode",value="代预约医生编号",defaultValue = "test00000000005")
							  @RequestParam(value="dcode",required = true) String dcode,
							  @ApiParam(name="dname",value="代预约医生名称",defaultValue = "组2全科医生")
					 		  @RequestParam(value="dname",required = true) String dname) {
		try {
			if (StringUtils.isEmpty(patientName)) {
				return error(-1, "未设置姓名!");
			}
			if (StringUtils.isEmpty(cardNo)) {
				return error(-1, "未设置身份证号!");
			}
			if (StringUtils.isEmpty(clinicCard)) {
				return error(-1, "未设置社保卡号!");
			}
			if (StringUtils.isEmpty(patientPhone)) {
				return error(-1, "未设置手机号码!");
			}
			String orderCode =  getService(city).CreateOrder(hospitalId,hospitalName,hosDeptId,hosDeptName,doctorId,doctorName,arrangeDate,patient,patientName,cardNo,clinicCard,patientPhone,dname,dcode);
			//获取预约信息查询是否挂号成功
			PatientReservation obj = patientReservationService.findByCode(orderCode);
			if(obj!=null)
			{
				Patient p = patientService.findByCode(obj.getPatient());
				String msg = "您成功预约了 " + obj.getOrgName() + " " + obj.getDoctorName() + " " + obj.getStartTime() + " 的号源!";
				if (StringUtils.isNotEmpty(p.getOpenid())) {
					// 推送消息给微信端
					JSONObject json = new JSONObject();
					json.put("first", "预约挂号提醒");
					json.put("toUser", p.getCode());
					json.put("id",obj.getId());
					json.put("date", obj.getStartTime());
					json.put("orgName", obj.getOrgName());
					json.put("doctorName", obj.getDoctorName());
					json.put("deptName", obj.getDeptName());
					json.put("remark", msg);
					PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, p.getOpenid(), p.getName(), json);
				}
				//发送短信小时
				// 调用总部发送信息的接口
				String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(msg, p.getMobile()), "GBK");
				return write(200, "创建挂号单成功!");
			}
			else{
				return error(-1,"创建挂号单失败!");
			}
		}
		catch (Exception e) {
			return error(-1,e.getMessage());
		}
	}
	/**
	 * 取消挂号单
	 */
	@RequestMapping(value = "CancelOrder",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("取消挂号单")
	public String CancelOrder(@ApiParam(name="orderId",value="订单id",defaultValue = "9")
							  @RequestParam(value="orderId",required = true) String orderId) {
		try {
			//获取订单信息
			PatientReservation obj = patientReservationService.findById(orderId);
			boolean re = false;
			if(obj!=null) {
				String type = obj.getType();
				String code = obj.getCode();
				if (type.equals("0")) {  //医护网接口
					re = guahaoYihu.CancelOrder(code);
				}
				else if (type.equals("1"))   //厦门市民健康预约接口
				{
					re = guahaoXM.CancelOrder(code,obj.getSsc());
				}
			}
			if(re)
			{
				//更新状态
				patientReservationService.updateStatus(obj.getCode(),0);
				//微信消息
				Patient p = patientService.findByCode(obj.getPatient());
				if (StringUtils.isNotEmpty(p.getOpenid())) {
					JSONObject json = new JSONObject();
					json.put("first", "取消预约挂号提醒");
					json.put("toUser", p.getCode());
					json.put("name", obj.getName());
					json.put("date", obj.getStartTime());
					json.put("doctorName", obj.getDoctorName());
					json.put("orgName", obj.getOrgName());
					json.put("remark", "您好,您已取消了" + obj.getStartTime() + "的挂号!");
					PushMsgTask.getInstance().putWxMsg(getAccessToken(), 7, p.getOpenid(), obj.getName(), json);
				}
				return write(200, "取消挂号单成功!");
			}
			else{
				return error(-1,"取消挂号单失败!");
			}
		} catch (Exception e) {
			return error(-1,e.getMessage());
		}
	}
	/**
	 * 获取患者预约信息列表接口
	 */
	@RequestMapping(value = "GetPatientReservationList",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("获取患者预约信息列表接口-医生端")
	public String GetPatientReservation(@ApiParam(name="pageIndex",value="第几页",defaultValue = "1")
										@RequestParam(value="pageIndex",required = false) Integer pageIndex,
										@ApiParam(name="pageSize",value="每页记录数",defaultValue = "10")
										@RequestParam(value="pageSize",required = false) Integer pageSize,
										@ApiParam(name="patient",value="患者编号",defaultValue = "10")
										@RequestParam(value="patient",required = false) String patient,
										@ApiParam(name="doctor",value="医生编号",defaultValue = "10")
										@RequestParam(value="doctor",required = false) String doctor) {
		try {
			List<PatientReservation> list =  patientReservationService.getReservationByPatient(patient,doctor,pageIndex,pageSize);
			//遍历更新预约状态
			for(PatientReservation item :list)
			{
				String type = item.getType();
				String code = item.getCode();
				if (type.equals("0")) {  //医护网接口
				}
				else if (type.equals("1"))   //厦门市民健康预约接口
				{
					Integer status = guahaoXM.GetOrderStatus(item.getOrgCode(),code,item.getSsc());
					//更新状态
					if(status!=null) {
						patientReservationService.updateStatus(item.getCode(), 0);
						item.setStatus(status);
					}
				}
			}
			return write(200, "获取患者预约信息列表成功!", "data", list);
		} catch (Exception e) {
			return error(-1,e.getMessage());
		}
	}
	/**
	 * 获取医生代预约信息列表接口
	 */
	@RequestMapping(value = "GetDoctorReservationList",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("获取医生代预约信息列表接口-医生端")
	public String GetDoctorReservation(@ApiParam(name="pageIndex",value="第几页",defaultValue = "1")
										@RequestParam(value="pageIndex",required = false) Integer pageIndex,
										@ApiParam(name="pageSize",value="每页记录数",defaultValue = "10")
										@RequestParam(value="pageSize",required = false) Integer pageSize,
										@ApiParam(name="doctor",value="医生编号",defaultValue = "10")
										@RequestParam(value="doctor",required = false) String doctor) {
		try {
			List<PatientReservation> list =  patientReservationService.getReservationByDoctor(doctor,pageIndex,pageSize);
			//遍历更新预约状态
			for(PatientReservation item :list)
			{
				String type = item.getType();
				String code = item.getCode();
				if (type.equals("0")) {  //医护网接口
				}
				else if (type.equals("1"))   //厦门市民健康预约接口
				{
					Integer status = guahaoXM.GetOrderStatus(item.getOrgCode(),code,item.getSsc());
					//更新状态
					if(status!=null) {
						patientReservationService.updateStatus(item.getCode(), 0);
						item.setStatus(status);
					}
				}
			}
			return write(200, "获取患者预约信息列表成功!", "data", list);
		} catch (Exception e) {
			return error(-1,e.getMessage());
		}
	}
	/**
	 * 获取患者预约信息列表接口
	 */
	@RequestMapping(value = "GetRegList",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("获取患者预约信息列表接口--患者端")
	public String GetRegList(@ApiParam(name="patient",value="患者编号",defaultValue = "1")
										@RequestParam(value="patient",required = false) String patient) {
		try {
			SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd");
			Date nowDate = new Date();
			Date threeMonthBefore = getMonthBefore(nowDate, 3);
			List<PatientReservation> list  = guahaoXM.GetRegList(patient,sm.format(threeMonthBefore),sm.format(nowDate));
			return write(200, "获取患者预约信息列表成功!", "data", list);
		} catch (Exception e) {
			return error(-1,e.getMessage());
		}
	}
	public static Date getMonthBefore(Date d, int month) {
		Calendar now = Calendar.getInstance();
		now.setTime(d);
		now.set(Calendar.MONTH, now.get(Calendar.MONTH) - month);
		return now.getTime();
	}
	/**
	 * 获取患者预约信息单条
	 */
	@RequestMapping(value = "GetPatientReservation",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("获取患者预约信息单条-医生端")
	public String GetPatientReservation(@ApiParam(name="orderId",value="订单id",defaultValue = "9")
										 @RequestParam(value="orderId",required = true) String orderId) {
		try {
			PatientReservation obj = null;
			try{
				obj =  patientReservationService.findById(orderId);
			}catch (Exception e){
				obj = patientReservationService.findByCode(orderId);
			}
			if(obj!=null) {
				String type = obj.getType();
				String code = obj.getCode();
				Integer status = null;
				if (type.equals("0")) {  //医护网接口
				}
				else if (type.equals("1"))   //厦门市民健康预约接口
				{
					status = guahaoXM.GetOrderStatus(obj.getOrgCode(), code, obj.getSsc());
				}
				//更新状态
				if (status != null) {
					patientReservationService.updateStatus(obj.getCode(), 0);
					obj.setStatus(status);
				}
				return write(200, "获取患者预约信息成功!", "data", obj);
			}
			else{
				return error(-1,"不存在该条预约信息!");
			}
		} catch (Exception e) {
			return error(-1,e.getMessage());
		}
	}
	/**
	 * 获取患者预约信息单条
	 */
	@RequestMapping(value = "GetPatientReservationXm",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("获取患者预约信息单条-患者端")
	public String GetPatientReservationXm(@ApiParam(name="patientCode",value="患者编号")
										@RequestParam(value="patientCode",required = true) String patientCode,
										@ApiParam(name="orgCode",value="机构编码")
										@RequestParam(value="orgCode",required = true) String orgCode,
										@ApiParam(name="regCode",value="挂号单号")
										@RequestParam(value="regCode",required = true) String regCode) {
		try {
			PatientReservation obj =  guahaoXM.getRegDetail(patientCode,orgCode,regCode);
			return write(200, "获取患者预约信息成功!", "data", obj);
		} catch (Exception e) {
			return error(-1,e.getMessage());
		}
	}
	/**
	 * 获取医生为患者预约的总数
	 */
	@RequestMapping(value = "CountReservationByDoctorForPatient",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("获取患者预约信息单条-患者端")
	public String CountReservationByDoctorForPatient(@ApiParam(name="doctor",value="医生编号")
										  @RequestParam(value="doctor",required = true) String doctor,
										  @ApiParam(name="patient",value="患者编号")
										  @RequestParam(value="patient",required = true) String patient) {
		try {
			Long obj =  patientReservationService.countReservationByDoctorForPatient(doctor, patient);
			return write(200, "获取患者预约信息成功!", "data", obj);
		} catch (Exception e) {
			return error(-1,e.getMessage());
		}
	}
                return write(200, "创建挂号单成功!");
            } else {
                return error(-1, "创建挂号单失败!");
            }
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    public static List<NameValuePair> buildSmsParams(String content, String mobile) {
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("SpCode", SystemConf.getInstance().getSmsCode()));
        params.add(new BasicNameValuePair("LoginName", SystemConf.getInstance().getSmsName()));
        params.add(new BasicNameValuePair("Password", SystemConf.getInstance().getSmsPassword()));
        params.add(new BasicNameValuePair("MessageContent", content));
        params.add(new BasicNameValuePair("UserNumber", mobile));
        params.add(new BasicNameValuePair("SerialNumber", String.valueOf(System.currentTimeMillis())));
        params.add(new BasicNameValuePair("ScheduleTime", ""));
        params.add(new BasicNameValuePair("f", "1"));
        return params;
    }
    public static JSONObject toJson(String result) {
        JSONObject json = new JSONObject();
        try {
            String[] temps = result.split("&");
            for (String temp : temps) {
                if (temp.split("=").length != 2) {
                    continue;
                }
                String key = temp.split("=")[0];
                String value = temp.split("=")[1];
                json.put(key, value);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }
    /**
     * 创建挂号单
     */
    @RequestMapping(value = "CreateOrderByDoctor", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("创建挂号单")
    public String CreateOrderByDoctor(@ApiParam(name = "city", value = "城市编码", defaultValue = "350200")
                                      @RequestParam(value = "city", required = true) String city,
                                      @ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211A1001")
                                      @RequestParam(value = "hospitalId", required = true) String hospitalId,
                                      @ApiParam(name = "hospitalName", value = "医院名称", defaultValue = "厦门大学附属第一医院")
                                      @RequestParam(value = "hospitalName", required = true) String hospitalName,
                                      @ApiParam(name = "hosDeptId", value = "科室ID", defaultValue = "1040610")
                                      @RequestParam(value = "hosDeptId", required = true) String hosDeptId,
                                      @ApiParam(name = "hosDeptName", value = "医院科室名称", defaultValue = "儿二科")
                                      @RequestParam(value = "hosDeptName", required = true) String hosDeptName,
                                      @ApiParam(name = "doctorId", value = "医生ID", defaultValue = "07101")
                                      @RequestParam(value = "doctorId", required = true) String doctorId,
                                      @ApiParam(name = "doctorName", value = "医生姓名", defaultValue = "林素莲")
                                      @RequestParam(value = "doctorName", required = true) String doctorName,
                                      @ApiParam(name = "arrangeDate", value = "排班信息", defaultValue = "{\"sectionType\":\"a\",\"startTime\":\"2016-09-02 08:20:00\",\"endTime\":\"2016-09-02 08:30:00\"}")
                                      @RequestParam(value = "arrangeDate", required = true) String arrangeDate,
                                      @ApiParam(name = "patient", value = "患者代码", defaultValue = "01954b2ebbb24a40a05da9d2f5c94795")
                                      @RequestParam(value = "patient", required = true) String patient,
                                      @ApiParam(name = "patientName", value = "患者姓名", defaultValue = "张锦川")
                                      @RequestParam(value = "patientName", required = true) String patientName,
                                      @ApiParam(name = "cardNo", value = "身份证号码", defaultValue = "35052419880511553X")
                                      @RequestParam(value = "cardNo", required = true) String cardNo,
                                      @ApiParam(name = "clinicCard", value = "市民卡号", defaultValue = "D57117706")
                                      @RequestParam(value = "clinicCard", required = true) String clinicCard,
                                      @ApiParam(name = "patientPhone", value = "患者手机", defaultValue = "13950116510")
                                      @RequestParam(value = "patientPhone", required = true) String patientPhone,
                                      @ApiParam(name = "dcode", value = "代预约医生编号", defaultValue = "test00000000005")
                                      @RequestParam(value = "dcode", required = true) String dcode,
                                      @ApiParam(name = "dname", value = "代预约医生名称", defaultValue = "组2全科医生")
                                      @RequestParam(value = "dname", required = true) String dname) {
        try {
            if (StringUtils.isEmpty(patientName)) {
                return error(-1, "未设置姓名!");
            }
            if (StringUtils.isEmpty(cardNo)) {
                return error(-1, "未设置身份证号!");
            }
            if (StringUtils.isEmpty(clinicCard)) {
                return error(-1, "未设置社保卡号!");
            }
            if (StringUtils.isEmpty(patientPhone)) {
                return error(-1, "未设置手机号码!");
            }
            String orderCode = getService(city).CreateOrder(hospitalId, hospitalName, hosDeptId, hosDeptName, doctorId, doctorName, arrangeDate, patient, patientName, cardNo, clinicCard, patientPhone, dname, dcode);
            //获取预约信息查询是否挂号成功
            PatientReservation obj = patientReservationService.findByCode(orderCode);
            if (obj != null) {
                Patient p = patientService.findByCode(obj.getPatient());
                Doctor d = doctorService.findDoctorByCode(getUID());
                String msg = d.getName() + "医生已成功为您预约:" + obj.getStartTime() + "," + obj.getOrgName() +
                        obj.getDeptName() + obj.getDeptName() + "医生的号源。您可直接前往医院就诊。";
                if (StringUtils.isNotEmpty(p.getOpenid())) {
                    // 推送消息给微信端
                    JSONObject json = new JSONObject();
                    json.put("first", "");
                    json.put("toUser", p.getCode());
                    json.put("id", obj.getId());
                    json.put("date", obj.getStartTime());
                    json.put("orgName", obj.getOrgName());
                    json.put("doctorName", obj.getDeptName());
                    json.put("deptName", obj.getDeptName());
                    json.put("remark", p.getName() + ",您好!\n" + msg);
                    PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, p.getOpenid(), p.getName(), json);
                }
                //发送短信小时
                // 调用总部发送信息的接口
                String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(msg, p.getMobile()), "GBK");
                return write(200, "创建挂号单成功!");
            } else {
                return error(-1, "创建挂号单失败!");
            }
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 取消挂号单
     */
    @RequestMapping(value = "CancelOrder", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("取消挂号单")
    public String CancelOrder(@ApiParam(name = "orderId", value = "订单id", defaultValue = "9")
                              @RequestParam(value = "orderId", required = true) String orderId) {
        try {
            //获取订单信息
            PatientReservation obj = patientReservationService.findById(orderId);
            boolean re = false;
            if (obj != null) {
                String type = obj.getType();
                String code = obj.getCode();
                if (type.equals("0")) {  //医护网接口
                    re = guahaoYihu.CancelOrder(code);
                } else if (type.equals("1"))   //厦门市民健康预约接口
                {
                    re = guahaoXM.CancelOrder(code, obj.getSsc());
                }
            }
            if (re) {
                //更新状态
                patientReservationService.updateStatus(obj.getCode(), 0);
                //微信消息
                Patient p = patientService.findByCode(obj.getPatient());
                if (StringUtils.isNotEmpty(p.getOpenid())) {
                    JSONObject json = new JSONObject();
                    json.put("first", "");
                    json.put("toUser", p.getCode());
                    json.put("name", obj.getName());
                    json.put("date", obj.getStartTime());
                    json.put("doctorName", obj.getDoctorName());
                    json.put("orgName", obj.getOrgName());
                    json.put("remark", obj.getName() + ",您好!\n您已取消了" + obj.getStartTime() + "的挂号!");
                    PushMsgTask.getInstance().putWxMsg(getAccessToken(), 7, p.getOpenid(), obj.getName(), json);
                }
                return write(200, "取消挂号单成功!");
            } else {
                return error(-1, "取消挂号单失败!");
            }
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 获取患者预约信息列表接口
     */
    @RequestMapping(value = "GetPatientReservationList", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("获取患者预约信息列表接口-医生端")
    public String GetPatientReservation(@ApiParam(name = "pageIndex", value = "第几页", defaultValue = "1")
                                        @RequestParam(value = "pageIndex", required = false) Integer pageIndex,
                                        @ApiParam(name = "pageSize", value = "每页记录数", defaultValue = "10")
                                        @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                        @ApiParam(name = "patient", value = "患者编号", defaultValue = "10")
                                        @RequestParam(value = "patient", required = false) String patient,
                                        @ApiParam(name = "doctor", value = "医生编号", defaultValue = "10")
                                        @RequestParam(value = "doctor", required = false) String doctor) {
        try {
            List<PatientReservation> list = patientReservationService.getReservationByPatient(patient, doctor, pageIndex, pageSize);
            //遍历更新预约状态
            for (PatientReservation item : list) {
                String type = item.getType();
                String code = item.getCode();
                if (type.equals("0")) {  //医护网接口
                } else if (type.equals("1"))   //厦门市民健康预约接口
                {
                    Integer status = guahaoXM.GetOrderStatus(item.getOrgCode(), code, item.getSsc());
                    //更新状态
                    if (status != null) {
                        patientReservationService.updateStatus(item.getCode(), 0);
                        item.setStatus(status);
                    }
                }
            }
            return write(200, "获取患者预约信息列表成功!", "data", list);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 获取医生代预约信息列表接口
     */
    @RequestMapping(value = "GetDoctorReservationList", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("获取医生代预约信息列表接口-医生端")
    public String GetDoctorReservation(@ApiParam(name = "pageIndex", value = "第几页", defaultValue = "1")
                                       @RequestParam(value = "pageIndex", required = false) Integer pageIndex,
                                       @ApiParam(name = "pageSize", value = "每页记录数", defaultValue = "10")
                                       @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                       @ApiParam(name = "doctor", value = "医生编号", defaultValue = "10")
                                       @RequestParam(value = "doctor", required = false) String doctor) {
        try {
            List<PatientReservation> list = patientReservationService.getReservationByDoctor(doctor, pageIndex, pageSize);
            //遍历更新预约状态
            for (PatientReservation item : list) {
                String type = item.getType();
                String code = item.getCode();
                if (type.equals("0")) {  //医护网接口
                } else if (type.equals("1"))   //厦门市民健康预约接口
                {
                    Integer status = guahaoXM.GetOrderStatus(item.getOrgCode(), code, item.getSsc());
                    //更新状态
                    if (status != null) {
                        patientReservationService.updateStatus(item.getCode(), 0);
                        item.setStatus(status);
                    }
                }
            }
            return write(200, "获取患者预约信息列表成功!", "data", list);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 获取患者预约信息列表接口
     */
    @RequestMapping(value = "GetRegList", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("获取患者预约信息列表接口--患者端")
    public String GetRegList(@ApiParam(name = "patient", value = "患者编号", defaultValue = "1")
                             @RequestParam(value = "patient", required = false) String patient) {
        try {
            SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd");
            Date nowDate = new Date();
            Date threeMonthBefore = getMonthBefore(nowDate, 3);
            List<PatientReservation> list = guahaoXM.GetRegList(patient, sm.format(threeMonthBefore), sm.format(nowDate));
            return write(200, "获取患者预约信息列表成功!", "data", list);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    public static Date getMonthBefore(Date d, int month) {
        Calendar now = Calendar.getInstance();
        now.setTime(d);
        now.set(Calendar.MONTH, now.get(Calendar.MONTH) - month);
        return now.getTime();
    }
    /**
     * 获取患者预约信息单条
     */
    @RequestMapping(value = "GetPatientReservation", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("获取患者预约信息单条-医生端")
    public String GetPatientReservation(@ApiParam(name = "orderId", value = "订单id", defaultValue = "9")
                                        @RequestParam(value = "orderId", required = true) String orderId) {
        try {
            PatientReservation obj = null;
            try {
                obj = patientReservationService.findById(orderId);
            } catch (Exception e) {
                obj = patientReservationService.findByCode(orderId);
            }
            if (obj != null) {
                String type = obj.getType();
                String code = obj.getCode();
                Integer status = null;
                if (type.equals("0")) {  //医护网接口
                } else if (type.equals("1"))   //厦门市民健康预约接口
                {
                    status = guahaoXM.GetOrderStatus(obj.getOrgCode(), code, obj.getSsc());
                }
                //更新状态
                if (status != null) {
                    patientReservationService.updateStatus(obj.getCode(), 0);
                    obj.setStatus(status);
                }
                return write(200, "获取患者预约信息成功!", "data", obj);
            } else {
                return error(-1, "不存在该条预约信息!");
            }
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 获取患者预约信息单条
     */
    @RequestMapping(value = "GetPatientReservationXm", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("获取患者预约信息单条-患者端")
    public String GetPatientReservationXm(@ApiParam(name = "patientCode", value = "患者编号")
                                          @RequestParam(value = "patientCode", required = true) String patientCode,
                                          @ApiParam(name = "orgCode", value = "机构编码")
                                          @RequestParam(value = "orgCode", required = true) String orgCode,
                                          @ApiParam(name = "regCode", value = "挂号单号")
                                          @RequestParam(value = "regCode", required = true) String regCode) {
        try {
            PatientReservation obj = guahaoXM.getRegDetail(patientCode, orgCode, regCode);
            return write(200, "获取患者预约信息成功!", "data", obj);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 获取医生为患者预约的总数
     */
    @RequestMapping(value = "CountReservationByDoctorForPatient", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("获取患者预约信息单条-患者端")
    public String CountReservationByDoctorForPatient(@ApiParam(name = "doctor", value = "医生编号")
                                                     @RequestParam(value = "doctor", required = true) String doctor,
                                                     @ApiParam(name = "patient", value = "患者编号")
                                                     @RequestParam(value = "patient", required = true) String patient) {
        try {
            Long obj = patientReservationService.countReservationByDoctorForPatient(doctor, patient);
            return write(200, "获取患者预约信息成功!", "data", obj);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
}