package com.yihu.wlyy.web.third; 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.PatientService; import com.yihu.wlyy.service.third.guahao.GuahaoDoctor; import com.yihu.wlyy.service.third.guahao.GuahaoXMService; import com.yihu.wlyy.service.third.guahao.GuahaoYihuService; import com.yihu.wlyy.service.third.guahao.IGuahaoService; import com.yihu.wlyy.task.PushMsgTask; import com.yihu.wlyy.web.WeixinBaseController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.commons.lang3.StringUtils; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Map; /** * 预约挂号 * @author hzp at 2016-08-30 */ @Controller @RequestMapping(value = "/third/guahao") @Api(description = "预约挂号接口") public class BookingController extends WeixinBaseController { @Autowired private GuahaoXMService guahaoXM; @Autowired private GuahaoYihuService guahaoYihu; @Autowired private PatientReservationService patientReservationService; @Autowired private PatientService patientService; /** * 根据城市编码获取相应挂号服务 * @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> 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> 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 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> 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> 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); } return write(200, "创建挂号单成功!"); } else{ return error(-1,"创建挂号单失败!"); } } catch (Exception e) { return error(-1,e.getMessage()); } } /** * 创建挂号单 */ @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) { 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 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 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 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 = patientReservationService.findById(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()); } } }