Ver código fonte

医生端--预约挂号接口修改

hzp 8 anos atrás
pai
commit
1947ac9fa3

+ 108 - 14
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/reservation/PatientReservationService.java

@ -1,12 +1,13 @@
package com.yihu.wlyy.service.app.reservation;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import javax.transaction.Transactional;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.service.third.guahao.GuahaoXMService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@ -39,21 +40,47 @@ public class PatientReservationService extends BaseService {
	private PatientReservationDao patientReservationDao;
	@Autowired
	private PatientReservationDoctorDao patientReservationDoctorDao;
	
	@Autowired
	private GuahaoXMService  guahaoXMService;
	@Autowired
	private ObjectMapper objectMapper;
	@Autowired
	private PatientDao patientDao;
	public PatientReservation findByCode(String code){
		return patientReservationDao.findByCode(code);
	}
	public PatientReservation findById(String id){
		return patientReservationDao.findById(Long.valueOf(id));
	public PatientReservation findById(Long id) throws Exception{
		PatientReservation re = patientReservationDao.findById(id);
		if(re==null)
		{
			throw new Exception("not exit result!id:"+id);
		}
		return re;
	}
	/**
	 * 实体转map
	 */
	private Map<String, String> entityToMap(PatientReservation obj) throws Exception {
		String mapString = objectMapper.writeValueAsString(obj);
		return objectMapper.readValue(mapString, Map.class);
	}
	/**
	 * 更新预约状态
     */
	public void updateStatus(String code,Integer status)
	@Transactional
	public void updateStatus(Long id,Integer status)
	{
		PatientReservation obj=  patientReservationDao.findByCode(code);
		PatientReservation obj=  patientReservationDao.findOne(id);
		if(!obj.getStatus().equals(status))
		{
			obj.setStatus(status);
@ -153,26 +180,93 @@ public class PatientReservationService extends BaseService {
	/**
	 * 分页获取患者预约记录,医生为空查患者所有
     */
	public List<PatientReservation> getReservationByPatient(String patient,String doctor, int page, int pagesize) {
	@Transactional
	public List<PatientReservation> getReservationByPatient(String patient,String doctor, int page, int pagesize) throws Exception
	{
		List<PatientReservation> list = new ArrayList<>();
		// 排序
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(page-1, pagesize, sort);
		if(StringUtils.isNotBlank(doctor)){//传入医生查询医生帮此患者的预约记录
			return patientReservationDao.findByPatientAndDoctor(patient, doctor, pageRequest);
			list = patientReservationDao.findByPatientAndDoctor(patient, doctor, pageRequest);
		}else{
			return patientReservationDao.findByPatient(patient, pageRequest);
			list = patientReservationDao.findByPatient(patient, pageRequest);
		}
		//更新当前状态
		if(list!=null)
		{
			//遍历更新预约状态
			for (PatientReservation item : list) {
				String type = item.getType();
				String code = item.getCode();
				if (type.equals("0")) {  //医护网接口
				}
				else if (type.equals("1"))   //厦门市民健康预约接口
				{
					Integer status = guahaoXMService.GetOrderStatus(item.getOrgCode(), code, item.getSsc());
					//更新状态
					if (status != null && !status.equals(item.getStatus())) {
						item.setStatus(status);
					}
				}
			}
			patientReservationDao.save(list);
		}
		return list;
	}
	/**
	 * 分页获取患者预约记录(医生端)
	 */
	public List<PatientReservation> getReservationByDoctor(String doctor, int page, int pagesize) {
	public List<Map<String,String>> getReservationByDoctor(String doctor, int page, int pagesize) throws Exception
	{
		List<Map<String,String>> re = new ArrayList<>();
		// 排序
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(page-1, pagesize, sort);
		return patientReservationDao.findByDoctor(doctor, pageRequest);
		List<PatientReservation> list = patientReservationDao.findByDoctor(doctor, pageRequest);
		//更新当前状态
		if(list!=null)
		{
			//遍历更新预约状态
			for (PatientReservation item : list) {
				String type = item.getType();
				String code = item.getCode();
				if (type.equals("0")) {  //医护网接口
				}
				else if (type.equals("1"))   //厦门市民健康预约接口
				{
					Integer status = guahaoXMService.GetOrderStatus(item.getOrgCode(), code, item.getSsc());
					//更新状态
					if (status != null && !status.equals(item.getStatus())) {
						item.setStatus(status);
					}
				}
			}
			patientReservationDao.save(list);
		}
		//返回患者头像
		for (PatientReservation item : list) {
			Map<String,String> map = entityToMap(item);
			Patient patient = patientDao.findByCode(item.getPatient());
			if(patient!=null){
				map.put("photo",patient.getPhoto());
			}
			re.add(map);
		}
		return re;
	}
	public Long countReservationByDoctorForPatient(String doctor,String patient){

+ 1 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/guahao/GuahaoXMService.java

@ -614,6 +614,7 @@ public class GuahaoXMService implements IGuahaoService {
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        if (xml.toLowerCase().startsWith("ok")) {
            return true;
        } else {
            return false;

+ 64 - 129
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/BookingController.java

@ -307,6 +307,54 @@ public class BookingController extends WeixinBaseController {
    @RequestMapping(value = "CancelOrder", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("取消挂号单")
    public String CancelOrder(@ApiParam(name = "orderId", value = "订单id", defaultValue = "9")
                              @RequestParam(value = "orderId", required = true) Long 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(orderId, 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 = "CreateOrderByDoctor", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("(内网)转诊预约挂号")
@ -390,12 +438,12 @@ public class BookingController extends WeixinBaseController {
    @ResponseBody
    @ApiOperation("(内网)获取医生排班接口")
    public String GetDoctorArrangeTenDay(
                                   @ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211A1001")
                                   @RequestParam(value = "hospitalId", required = true) String hospitalId,
                                   @ApiParam(name = "hosDeptId", value = "科室ID", defaultValue = "1011610")
                                   @RequestParam(value = "hosDeptId", required = true) String hosDeptId,
                                   @ApiParam(name = "doctorId", value = "医生ID", defaultValue = "50108")
                                   @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 = "1011610")
            @RequestParam(value = "hosDeptId", required = true) String hosDeptId,
            @ApiParam(name = "doctorId", value = "医生ID", defaultValue = "50108")
            @RequestParam(value = "doctorId", required = true) String doctorId) {
        try {
            List<Map<String, Object>> list = guahaoXM.GetDoctorArrangeTenDay(hospitalId, hosDeptId, doctorId);
            return write(200, "获取医生排班成功!", "data", list);
@ -404,54 +452,6 @@ public class BookingController extends WeixinBaseController {
        }
    }
    @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
@ -460,29 +460,13 @@ public class BookingController extends WeixinBaseController {
                                        @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")
                                        @ApiParam(name = "patient", value = "患者编号", defaultValue = "4afdbce6194e412fbc770eb4dfbe7b00")
                                        @RequestParam(value = "patient", required = false) String patient,
                                        @ApiParam(name = "doctor", value = "医生编号", defaultValue = "10")
                                        @ApiParam(name = "doctor", value = "医生编号", defaultValue = "shiliuD20160926005")
                                        @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());
@ -497,39 +481,12 @@ public class BookingController extends WeixinBaseController {
                                       @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")
                                       @ApiParam(name = "doctor", value = "医生编号", defaultValue = "shiliuD20160926005")
                                       @RequestParam(value = "doctor", required = false) String doctor) {
        try {
            List<PatientReservation> list = patientReservationService.getReservationByDoctor(doctor, pageIndex, pageSize);
            //遍历更新预约状态
            JSONArray array = new JSONArray();
            for (PatientReservation item : list) {
                String type = item.getType();
                String code = item.getCode();
                JSONObject object = new JSONObject();
                Class pClass = (Class) item.getClass();
                for(Field field  : pClass.getDeclaredFields()){
                    field.setAccessible(true);
                    object.put(field.getName(),field.get(item));
                }
                Patient patient = patientService.findByCode(item.getPatient());
                if(patient!=null){
                    object.put("photo",patient.getPhoto());
                }
                array.put(object);
                if (type.equals("0")) {  //医护网接口
            List<Map<String,String>> list = patientReservationService.getReservationByDoctor(doctor, pageIndex, pageSize);
                } 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", array);
            return write(200, "获取患者预约信息列表成功!", "data", list);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
@ -540,35 +497,13 @@ public class BookingController extends WeixinBaseController {
    @ResponseBody
    @ApiOperation("获取患者预约信息单条-医生端")
    public String GetPatientReservation(@ApiParam(name = "orderId", value = "订单id", defaultValue = "9")
                                        @RequestParam(value = "orderId", required = true) String orderId) {
                                        @RequestParam(value = "orderId", required = true) Long 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, "不存在该条预约信息!");
            }
            PatientReservation obj = patientReservationService.findById(orderId);
        } catch (Exception e) {
            return write(200, "获取患者预约信息成功!", "data", obj);
        }
        catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }