浏览代码

代码修改

LAPTOP-KB9HII50\70708 2 年之前
父节点
当前提交
280625c6f1

+ 43 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/booking/dao/PatientReservationDao.java

@ -0,0 +1,43 @@
/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.yihu.jw.hospital.booking.dao;
import com.yihu.jw.entity.hospital.booking.PatientReservation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
import java.util.List;
public interface PatientReservationDao extends PagingAndSortingRepository<PatientReservation, Long>, JpaSpecificationExecutor<PatientReservation> {
	PatientReservation findByCode(String code);
//	List<PatientReservation> findByPatient(String patient, Pageable page);
//	List<PatientReservation> findByPatientAndAdminTeamCode(String patient,Long teamCode,Pageable page);
	Page<Object> findByPatient(String patient, Pageable page);
	Page<Object>  findByPatientAndAdminTeamCode(String patient,Long teamCode,Pageable page);
	List<PatientReservation> findByDoctor(String doctor,Pageable page);
	@Query("select count(1) from PatientReservation a where a.doctor = ?1 and a.patient=?2 ")
	Long  countReservationByDoctorForPatient(String doctor,String patient);
	@Query(value = "select a.* from wlyy_patient_reservation a where a.patient = ?1 and a.canceler=?2 and a.canceler_time>?3 and a.status ='0' order by a.canceler_time DESC limit 1",nativeQuery = true)
	PatientReservation findByPatientAndCancelerAndCancelTime(String patient,String canceler,String cancelerTime);
	//根据患者医获取近三个月的已取消的预约记录
	@Query("select a from PatientReservation a where a.patient = ?1 and a.startTime between ?2 and ?3 and a.status = 1 order by a.startTime desc")
	List<PatientReservation> findByPatientAndStartTime(String patientCode,Date startTime,Date endTime);
	@Query("select a from PatientReservation a where a.relationCode = ?1 and a.status = 1 order by a.czrq desc")
	List<PatientReservation> findByRelationCode(String relationCode);
}

+ 240 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/booking/service/PatientReservationService.java

@ -0,0 +1,240 @@
package com.yihu.jw.hospital.booking.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.hospital.booking.PatientReservation;
import com.yihu.jw.hospital.booking.dao.PatientReservationDao;
import com.yihu.jw.mysql.query.BaseJpaService;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.entity.ServiceException;
import org.apache.commons.lang3.StringUtils;
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.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.*;
/**
 * 预约挂号业务处理类
 *
 * @author George
 */
@Component
@Transactional(rollbackOn = Exception.class)
public class PatientReservationService extends BaseJpaService<PatientReservation,PatientReservationDao> {
    @Resource
    private PatientReservationDao patientReservationDao;
    @Autowired
    private ObjectMapper objectMapper;
    @Resource
    private BasePatientDao patientDao;
    @Resource
    private BaseDoctorDao doctorDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    public PatientReservation findByCode(String code) {
        return patientReservationDao.findByCode(code);
    }
    public PatientReservation findById(Long id) throws Exception {
        PatientReservation re = patientReservationDao.findById(id).orElse(null);
        if (re == null) {
            throw new ServiceException("获取预约详情失败!");
        }
        return re;
    }
    /**
     * 实体转map
     */
    private Map<String, String> entityToMap(PatientReservation obj) throws Exception {
        String mapString = objectMapper.writeValueAsString(obj);
        return objectMapper.readValue(mapString, Map.class);
    }
    /**
     * 更新预约状态
     */
    @Transactional
    public void updateStatus(Long id, Integer status) {
        PatientReservation obj = patientReservationDao.findById(id).orElse(null);
        if (!obj.getStatus().equals(status)) {
            obj.setStatus(status);
            patientReservationDao.save(obj);
        }
    }
    /**
     * 医生取消预约
     */
    @Transactional
    public void doctorCancelOrder(Long id,String doctor) {
        PatientReservation obj = patientReservationDao.findById(id).orElse(null);
        if (obj.getStatus()!=0) {
            obj.setStatus(0);
            String patient = obj.getPatient();
            obj.setCanceler(doctor);
            patientReservationDao.save(obj);
        }
    }
    /**
     * 居民取消预约
     */
    @Transactional
    public void patientCancelOrder(String code,String patient) {
        PatientReservation obj = patientReservationDao.findByCode(code);
        if (obj.getStatus()!=0) {
            obj.setStatus(0);
            obj.setCanceler(patient);
            obj.setCancelerName(obj.getName());
            obj.setCancelerType(5);
            obj.setCancelerTime(DateUtil.dateToStrLong(new Date()));
            patientReservationDao.save(obj);
        }
    }
    /**
     * 保存预约挂号记录
     *
     * @param code         预约号/流水号
     * @param doctor       医生标识
     * @param patient      患者标识
     * @param idcard       患者身份证号
     * @param name         患者姓名
     * @param phone        患者手机号
     * @param ssc          患者社保卡号
     * @param section_type 预约时间段:AM (上午)或者PM (下午)
     * @param start_time   一次预约段的开始时间
     * @param org_code     医生所在医疗机构编码
     * @param org_name     医疗机构名称
     * @param dept_code    科室编码
     * @param dept_name    科室名称
     * @param doctor_code  专家ID/编码
     * @param doctor_name  专家姓名
     * @param doctor_photo 专家头像
     * @return
     */
    public void save(String code, BaseDoctorDO doctor, String patient, String idcard, String name, String phone, String ssc, String section_type, String start_time, String org_code, String org_name, String dept_code, String dept_name, String doctor_code, String doctor_name, String doctor_job, String doctor_photo) {
        try {
            PatientReservation reservation = new PatientReservation();
            reservation.setCode(code);
            reservation.setCzrq(new Date());
            reservation.setType("1");
            reservation.setDeptCode(dept_code);
            reservation.setDeptName(dept_name);
            if (doctor != null) {
                reservation.setDname(doctor.getName());
                reservation.setDoctor(doctor.getId());
            }
            reservation.setDoctorCode(doctor_code);
            reservation.setDoctorName(doctor_name);
            reservation.setDoctorJob(doctor_job);
            reservation.setDoctorPhoto(doctor_photo);
            reservation.setIdcard(idcard);
            reservation.setName(doctor_name);
            reservation.setOrgCode(org_code);
            reservation.setOrgName(org_name);
            reservation.setPatient(patient);
            reservation.setPhone(phone);
            reservation.setSectionType(section_type);
            reservation.setSsc(ssc);
            reservation.setStartTime(DateUtil.strToDate(start_time,DateUtil.YYYY_M_D_HH_MM_SS));
            reservation.setStatus(1);
            // 保存记录
            PatientReservation temp = patientReservationDao.save(reservation);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 分页获取患者预约记录,根据团队
     */
    @Transactional
    public JSONArray getReservationByPatient(String patient, Long teamCode, int page, int pagesize) throws Exception {
        JSONArray array = new JSONArray();
        // 排序
        Sort sort = Sort.by(Direction.DESC, "id");
        // 分页信息
        PageRequest pageRequest = PageRequest.of(page - 1, pagesize, sort);
        Page<Object> result = null;
        if (teamCode != null && teamCode > 0) {//传入医生查询医生帮此患者的预约记录
            result = patientReservationDao.findByPatientAndAdminTeamCode(patient, teamCode, pageRequest);
        } else {
            result = patientReservationDao.findByPatient(patient, pageRequest);
        }
        List<Object> list = result.getContent();
        if (list != null) {
            Map<String, BaseDoctorDO> doctors = new HashMap<>();
            for (Object one : list) {
                PatientReservation item = (PatientReservation)one;
                JSONObject obj = new JSONObject(item);
                if (!StringUtils.isEmpty(item.getDoctor())) {
                    if (doctors.get(item.getDoctor()) != null) {
                        obj.put("photo", doctors.get(item.getDoctor()).getPhoto());
                    } else {
                        BaseDoctorDO doc = doctorDao.findById(item.getDoctor()).orElse(null);
                        if (doc != null) {
                            doctors.put(doc.getId(), doc);
                            obj.put("photo", doc.getPhoto());
                        }
                    }
                }
                obj.put("total",result.getTotalElements());
                array.put(obj);
            }
        }
        return array;
    }
    /**
     * 分页获取患者预约记录(医生端)
     */
    public List<Map<String, String>> getReservationByDoctor(String doctor, int page, int pagesize) throws Exception {
        List<Map<String, String>> re = new ArrayList<>();
        // 排序
        Sort sort = Sort.by(Direction.DESC, "id");
        // 分页信息
        PageRequest pageRequest = PageRequest.of(page - 1, pagesize, sort);
        List<PatientReservation> list = patientReservationDao.findByDoctor(doctor, pageRequest);
        //返回患者头像
        for (PatientReservation item : list) {
            Map<String, String> map = entityToMap(item);
            BasePatientDO patient = patientDao.findById(item.getPatient()).orElse(null);
            if (patient != null) {
                map.put("photo", patient.getPhoto());
            }
            re.add(map);
        }
        return re;
    }
    public Long countReservationByDoctorForPatient(String doctor, String patient) {
        return patientReservationDao.countReservationByDoctorForPatient(doctor, patient);
    }
}

+ 1453 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/entrance/JwSmjkEntranceService.java

@ -0,0 +1,1453 @@
package com.yihu.jw.hospital.prescription.service.entrance;
import com.yihu.jw.entity.hospital.booking.PatientReservation;
import com.yihu.jw.entity.hospital.booking.ReservationHospitalDept;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.hospital.booking.dao.PatientReservationDao;
import com.yihu.jw.hospital.prescription.vo.GuahaoDoctor;
import com.yihu.jw.sms.dao.HospitalSysDictDao;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.entity.ServiceException;
import com.yihu.jw.util.http.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
/**
 * Created by ysj on 2022/11/22.
 * 与统一接口平台对接
 */
@Service
public class JwSmjkEntranceService {
    //基卫服务地址
//    @Value("${sign.check_upload}")
    private String jwUrl="";
    @Autowired
    private HttpClientUtil HttpClientUtil;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Resource
    private HospitalSysDictDao hospitalSysDictDao;
    //未对接 模拟数据
    private boolean isdemo =true;
    /****************************************************************************************************************************/
    /**
     * 获取门/急诊记录 + 住院记录
     */
    public String getResidentEventListJson(String strSSID,String type,String page,String pageSize)  throws Exception
    {
        if(isdemo)     //演示环境
        {
            return "";
        }
        else {
            String re = "";
            String url = jwUrl + "/third/smjk/ResidentEventList";
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("strSSID", strSSID));
            if (!StringUtils.isEmpty(type)) {
                params.add(new BasicNameValuePair("type", type));
            }
            params.add(new BasicNameValuePair("page", page));
            params.add(new BasicNameValuePair("pageSize", pageSize));
            String response = HttpClientUtil.post(url, params, "UTF-8");
            if (!StringUtils.isEmpty(response)) {
                JSONObject responseObject = new JSONObject(response);
                int status = responseObject.getInt("status");
                if (status == 200) {
                    String data = responseObject.getString("data");
                    if (!StringUtils.isEmpty(data) && data.startsWith("error")) {
                        throw new ServiceException(data);
                    } else {
                        JSONObject jsonData = new JSONObject(data);
                        JSONArray jsonArray = jsonData.getJSONArray("EventList");
                        re = jsonArray.toString();
                    }
                } else {
                    throw new ServiceException(responseObject.getString("msg"));
                }
            } else {
                throw new ServiceException("null response.");
            }
            if(re.contains("[{}]"))
            {
                re = re.replace("[{}]","[]");
            }
            return re;
        }
    }
    /**
     * 通过event获取档案类型列表
     */
    public String getEventCatalog(String strSSID,String strEvent)  throws Exception
    {
        if(isdemo)     //演示环境
        {
            return "";
        }
        else {
            String url = jwUrl + "/third/smjk/EventCatalog";
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("strSSID", strSSID));
            params.add(new BasicNameValuePair("strEvent", strEvent));
            String response = HttpClientUtil.post(url, params, "UTF-8");
            String result = "";
            if (!StringUtils.isEmpty(response)) {
                JSONObject jsonObject = new JSONObject(response);
                int status = jsonObject.getInt("status");
                if (status == 200) {
                    result = jsonObject.getString("data");
                    if (result.startsWith("error")) {
                        throw new ServiceException(result);
                    }
                }
                else {
                    throw new ServiceException(jsonObject.getString("msg"));
                }
            }
            else {
                throw new ServiceException("null response.");
            }
            return result;
        }
    }
    /**
     * 获取健康档案信息详情
     */
    public String getHealthData(String strSSID, String strEvent, String strCatalog, String strSerial) throws Exception {
        if(isdemo)     //演示环境
        {
            return "";
//            return ehrService.getHealthData(strSSID,strEvent,strCatalog,strSerial);
        }
        else {
            String url = jwUrl + "/third/smjk/HealthData";
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("strSSID", strSSID));
            params.add(new BasicNameValuePair("strEvent", strEvent));
            params.add(new BasicNameValuePair("strCatalog", strCatalog));
            params.add(new BasicNameValuePair("strSerial", strSerial));
            String response = HttpClientUtil.post(url, params, "UTF-8");
            String result = "";
            if (!StringUtils.isEmpty(response)) {
                JSONObject jsonObject = new JSONObject(response);
                int status = jsonObject.getInt("status");
                if (status == 200) {
                    result = jsonObject.getString("data");
                    result = result.replaceAll("<\\?xml version=\"1.0\" encoding=\"utf-8\"\\?>", "");
                    if (result.startsWith("error")) {
                        throw new ServiceException(result);
                    }
                }
                else {
                    throw new ServiceException(jsonObject.getString("msg"));
                }
            }
            else {
                throw new ServiceException("null response.");
            }
            return result;
        }
    }
    /**
     * 获取检查检验列表
     */
    public String getExamAndLabReport(String strSSID,String page,String pageSize) throws Exception
    {
        if(isdemo)     //演示环境
        {
            return "";
        }
        else {
            String url = jwUrl + "/third/smjk/ExamAndLabReport";
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("strSSID", strSSID));
            params.add(new BasicNameValuePair("page", page));
            params.add(new BasicNameValuePair("pageSize", pageSize));
            String response = HttpClientUtil.post(url, params, "UTF-8");
            String re = "";
            if (!StringUtils.isEmpty(response)) {
                JSONObject jsonObject = new JSONObject(response);
                int status = jsonObject.getInt("status");
                if (status == 200) {
                    String data = jsonObject.getString("data");
                    if (!StringUtils.isEmpty(data) && data.startsWith("error")) {
                        throw new ServiceException(data);
                    } else {
                        JSONObject jsonData = new JSONObject(data);
                        JSONArray jsonArray = jsonData.getJSONArray("EhrList");
                        re = jsonArray.toString();
                    }
                } else {
                    throw new ServiceException(jsonObject.getString("msg"));
                }
            } else {
                throw new ServiceException("null response.");
            }
            if(re.contains("[{}]"))
            {
                re = re.replace("[{}]","[]");
            }
            return re;
        }
    }
    /**
     * 获取心电记录
     */
    public String EcGList(String strSSID,String strStart,String strEnd) throws Exception {
            String url = jwUrl + "/third/smjk/getEcGList";
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("strSSID", strSSID));
            params.add(new BasicNameValuePair("strStart", strStart));
            params.add(new BasicNameValuePair("strEnd", strEnd));
            String response = HttpClientUtil.post(url, params, "UTF-8");
            String re = "";
            if (!StringUtils.isEmpty(response)) {
                JSONObject jsonObject = new JSONObject(response);
                int status = jsonObject.getInt("status");
                if (status == 200) {
                    String data = jsonObject.getString("data");
                    if (!StringUtils.isEmpty(data) && data.startsWith("error")) {
                        return "暂无心电检查记录";
                    } else {
                        re = data;
                    }
                } else {
                    throw new ServiceException(jsonObject.getString("msg"));
                }
            } else {
                throw new ServiceException("null response.");
            }
            if(re.contains("[{}]"))
            {
                re = re.replace("[{}]","[]");
            }
            return re;
    }
    public List<Map<String, Object>> getEcGList(String strSSID,String strStart,String strEnd) throws Exception {
        String response = this.EcGList(strSSID, strStart, strEnd);
        if (response.equals("暂无心电检查记录")){
            List<Map<String, Object>> list = new ArrayList<>();
            Map<String,Object> map = new HashMap<>();
            map.put("fhsb","暂无心电检查记录");
            list.add(map);
            return list;
        }
        return  xmlToList(response);
    }
    private List<Map<String, Object>> xmlToList(String xml) throws Exception {
        List<Map<String, Object>> re = new ArrayList<>();
        if (StringUtils.isEmpty(xml)) {
            // 请求失败
            throw new ServiceException("获取心电失败!");
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            throw new ServiceException(xml.substring(xml.indexOf(":") + 1, xml.length()));
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            throw new ServiceException(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        Document document = DocumentHelper.parseText(xml);
        org.dom4j.Element root = document.getRootElement();
        if (root.element("\"item\"") != null)     //包含item节点
        {
            root = root.element("\"item\"");
        }
        List<?> child = root.elements();
        for (Object o : child) {
            org.dom4j.Element e = (org.dom4j.Element) o;
            String ssid = e.attributeValue("ssid");
            String url = e.attributeValue("url");
            String orgcode = e.attributeValue("orgcode");
            String orgname = e.attributeValue("orgname");
            String diagnosis = e.attributeValue("diagnosis");
            String reporttime = e.attributeValue("reporttime");
            Map<String, Object> map = new HashMap<>();
            map.put("ssid", ssid);
            map.put("url", url);
            map.put("orgcode", orgcode);
            map.put("orgname", orgname);
            map.put("diagnosis", diagnosis);
            map.put("reporttime", reporttime);
            re.add(map);
        }
        return re;
    }
    /**
     * 获取用药列表
     */
    public String getDrugsListPage(String strSSID,String page,String pageSize) throws Exception
    {
        if(isdemo)     //演示环境
        {
            return "";
        }
        else {
            String url = jwUrl + "/third/smjk/DrugsListPage";
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("strSSID", strSSID));
            params.add(new BasicNameValuePair("page", page));
            params.add(new BasicNameValuePair("pageSize", pageSize));
            String response = HttpClientUtil.post(url, params, "UTF-8");
            String result = "";
            if (!StringUtils.isEmpty(response)) {
                JSONObject jsonObject = new JSONObject(response);
                int status = jsonObject.getInt("status");
                if (status == 200) {
                    result = jsonObject.getString("data");
                }
                else {
                    throw new ServiceException(jsonObject.getString("msg"));
                }
            }
            else {
                throw new ServiceException("null response.");
            }
            if(result.contains("[{}]"))
            {
                result = result.replace("[{}]","[]");
            }
            return result;
        }
    }
    /****************************************************************************************************************************/
    /**
     * (内网)获取转诊预约医生号源信息
     */
    public String getRegDeptSpeDoctorSectionList(String OrgCode,String DeptCode,String strStart,String strEnd,String DocCode)  throws Exception
    {
        String re = "";
        String url = jwUrl + "/third/smjk/RegDeptSpeDoctorSectionList";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("OrgCode", OrgCode));
        params.add(new BasicNameValuePair("DeptCode", DeptCode));
        params.add(new BasicNameValuePair("strStart", strStart));
        params.add(new BasicNameValuePair("strEnd", strEnd));
        params.add(new BasicNameValuePair("DocCode", DocCode));
        String response =  HttpClientUtil.post(url, params, "UTF-8");
        if (!StringUtils.isEmpty(response)) {
            JSONObject jsonObject = new JSONObject(response);
            int status = jsonObject.getInt("status");
            if (status == 200) {
                String data = jsonObject.getString("data");
                if (!StringUtils.isEmpty(data) && (data.startsWith("error")||data.startsWith("System-Error"))) {
                    throw new ServiceException(data);
                } else {
                    re = data;
                }
            } else {
                throw new ServiceException(jsonObject.getString("msg"));
            }
        } else {
            throw new ServiceException("null response.");
        }
        return re;
    }
    /**
     * (内网)预约挂号接口
     */
    public String webRegisterByFamily(String idcard,String patientName,String ssid,String sectionType,String startTime,String orgCode,String deptCode,String deptName,String doctorCode,String doctorName,String patientPhone)  throws Exception
    {
        String re = "";
        String url = jwUrl + "/third/smjk/WebRegisterByFamily";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("idcard", idcard));
        params.add(new BasicNameValuePair("patientName", patientName));
        params.add(new BasicNameValuePair("ssid", ssid));
        params.add(new BasicNameValuePair("sectionType", sectionType));
        params.add(new BasicNameValuePair("startTime", startTime));
        params.add(new BasicNameValuePair("orgCode", orgCode));
        params.add(new BasicNameValuePair("deptCode", deptCode));
        params.add(new BasicNameValuePair("deptName", deptName));
        params.add(new BasicNameValuePair("doctorCode", doctorCode));
        params.add(new BasicNameValuePair("doctorName", doctorName));
        params.add(new BasicNameValuePair("patientPhone", patientPhone));
        String response = HttpClientUtil.post(url, params, "UTF-8");
        if (!StringUtils.isEmpty(response)) {
            JSONObject jsonObject = new JSONObject(response);
            int status = jsonObject.getInt("status");
            if (status == 200) {
                String data = jsonObject.getString("data");
                if (!StringUtils.isEmpty(data) && (data.startsWith("error")||data.startsWith("System-Error"))) {
                    throw new ServiceException(doMsg(data));
                } else {
                    re = data;
                }
            } else {
                throw new ServiceException(doMsg(jsonObject.getString("msg")));
            }
        } else {
            throw new ServiceException("预约失败,请稍后再试!");
        }
        //返回挂号单
        return re;
    }
    /**
     * 处理异常
     * @param msg
     * @return
     */
    public String doMsg(String msg){
        if(StringUtils.isNoneBlank(msg)&&msg.lastIndexOf(":")>0){
            String re = "市民健康系统提示" + msg.substring(msg.lastIndexOf(":"));
            return re;
        }
        return msg;
    }
    /**
     * 获取医院列表
     * @param type
     * @return
     * @throws Exception
     */
    public String GetOrgList(String type) throws Exception{
        String url = jwUrl + "/third/guahao/GetOrgList";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("type", type));
        String response = HttpClientUtil.post(url, params, "UTF-8");
        return response;
    }
    /**
     * 从数据中获取科室
     *
     * @param hospitalId
     * @param name
     * @return
     * @throws Exception
     */
    public List<ReservationHospitalDept> GetOrgDepListToMysql(String hospitalId, String name) throws Exception{
        StringBuffer buffer = new StringBuffer();
        if (StringUtils.isNoneBlank(name)){
            buffer.append(" and rh.name like '%"+name+"%'");
        }else {
            buffer.append("");
        }
        String sql = "select *  from wlyy_reservation_hospital_dept rh where 1=1 "+buffer;
        List<ReservationHospitalDept> reservationHospitals = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(ReservationHospitalDept.class));
        return reservationHospitals;
    }
    /**
     * 获取科室接口
     * @param hospitalId
     * @return
     * @throws Exception
     */
    public String GetOrgDepList(String hospitalId) throws Exception{
        String url = jwUrl + "/third/guahao/GetOrgDepList";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("hospitalId", hospitalId));
        String response = HttpClientUtil.post(url, params, "UTF-8");
        return response;
    }
    /**
     * 获取医生列表接口
     * @param hospitalId
     * @return
     * @throws Exception
     */
    public String GetDoctorList(String hospitalId,String hosDeptId) throws Exception{
        if(isdemo){
            return "{\n" +
                    "  \"status\": 200,\n" +
                    "  \"msg\": \"获取医生列表成功!\",\n" +
                    "  \"data\": [\n" +
                    "    {\n" +
                    "      \"id\": \"259724\",\n" +
                    "      \"name\": \"陈水龙\",\n" +
                    "      \"sex\": \"1\",\n" +
                    "      \"title\": \"主任医师\",\n" +
                    "      \"edu\": \"硕士\",\n" +
                    "      \"introduce\": \"主任医师、硕士,毕业于福建医科大学。现任科教部副主任,心内二科医疗组长。\\r\\n从事心血管内科临床及教学工作20余年,积累了丰富的临床工作经验。擅长高血压、冠心病、心力衰竭的临床诊治工作,在高血压的诊治方面有独到的造诣。\",\n" +
                    "      \"photo\": \"\",\n" +
                    "      \"fee\": null,\n" +
                    "      \"hosDeptId\": \"30100\",\n" +
                    "      \"hosDeptName\": \"心内科门诊\",\n" +
                    "      \"hospitalId\": \"350211A1002\",\n" +
                    "      \"hospitalName\": \"马銮湾医院\"\n" +
                    "    },\n" +
                    "    {\n" +
                    "      \"id\": \"259726\",\n" +
                    "      \"name\": \"王斌\",\n" +
                    "      \"sex\": \"1\",\n" +
                    "      \"title\": \"主任医师\",\n" +
                    "      \"edu\": \"博士\",\n" +
                    "      \"introduce\": \"主任医师、博士,毕业于四川大学华西临床医学院。现任急诊科主任。\\r\\n主要从事心血管内科临床、冠脉介入、瓣膜性心脏病微创介入及胸痛中心建设、维护及认证工作。\",\n" +
                    "      \"photo\": \"\",\n" +
                    "      \"fee\": null,\n" +
                    "      \"hosDeptId\": \"30100\",\n" +
                    "      \"hosDeptName\": \"心内科门诊\",\n" +
                    "      \"hospitalId\": \"350211A1002\",\n" +
                    "      \"hospitalName\": \"马銮湾医院\"\n" +
                    "    }\n" +
                    "  ]\n" +
                    "}";
        }
        String url = jwUrl + "/third/guahao/GetDoctorList";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("hospitalId", hospitalId));
        params.add(new BasicNameValuePair("hosDeptId", hosDeptId));
        String response = HttpClientUtil.post(url, params, "UTF-8");
        return response;
    }
    /**
     * 获取医生排班接口(包含排班详细)
     * @param hospitalId
     * @return
     * @throws Exception
     */
    public String GetDoctorArrange(String hospitalId,String hosDeptId,String doctorId) throws Exception{
        if(isdemo){
            return "{\n" +
                    "  \"status\": 200,\n" +
                    "  \"message\": \"获取医生排班成功!\",\n" +
                    "  \"data\": [\n" +
                    "    {\n" +
                    "      \"date\": \"2022/12/23 0:00:00\",\n" +
                    "      \"max\": \"28\",\n" +
                    "      \"fee\": \"50\",\n" +
                    "      \"time\": \"a\",\n" +
                    "      \"used\": \"14\",\n" +
                    "      \"regType\": \"主任号\",\n" +
                    "      \"sections\": [\n" +
                    "        {\n" +
                    "          \"max\": \"1\",\n" +
                    "          \"startTime\": \"2022/12/23 8:34:40\",\n" +
                    "          \"used\": \"0\",\n" +
                    "          \"endTime\": \"2022/12/23 8:42:00\"\n" +
                    "        },\n" +
                    "        {\n" +
                    "          \"max\": \"1\",\n" +
                    "          \"startTime\": \"2022/12/23 8:42:00\",\n" +
                    "          \"used\": \"0\",\n" +
                    "          \"endTime\": \"2022/12/23 8:49:20\"\n" +
                    "        },\n" +
                    "        {\n" +
                    "          \"max\": \"1\",\n" +
                    "          \"startTime\": \"2022/12/23 8:49:20\",\n" +
                    "          \"used\": \"0\",\n" +
                    "          \"endTime\": \"2022/12/23 8:56:40\"\n" +
                    "        },\n" +
                    "        {\n" +
                    "          \"max\": \"1\",\n" +
                    "          \"startTime\": \"2022/12/23 9:26:00\",\n" +
                    "          \"used\": \"0\",\n" +
                    "          \"endTime\": \"2022/12/23 9:33:20\"\n" +
                    "        },\n" +
                    "        {\n" +
                    "          \"max\": \"1\",\n" +
                    "          \"startTime\": \"2022/12/23 9:48:00\",\n" +
                    "          \"used\": \"0\",\n" +
                    "          \"endTime\": \"2022/12/23 9:55:20\"\n" +
                    "        },\n" +
                    "        {\n" +
                    "          \"max\": \"1\",\n" +
                    "          \"startTime\": \"2022/12/23 9:55:20\",\n" +
                    "          \"used\": \"0\",\n" +
                    "          \"endTime\": \"2022/12/23 10:02:40\"\n" +
                    "        },\n" +
                    "        {\n" +
                    "          \"max\": \"1\",\n" +
                    "          \"startTime\": \"2022/12/23 10:17:20\",\n" +
                    "          \"used\": \"0\",\n" +
                    "          \"endTime\": \"2022/12/23 10:24:40\"\n" +
                    "        },\n" +
                    "        {\n" +
                    "          \"max\": \"1\",\n" +
                    "          \"startTime\": \"2022/12/23 10:54:00\",\n" +
                    "          \"used\": \"0\",\n" +
                    "          \"endTime\": \"2022/12/23 11:01:20\"\n" +
                    "        },\n" +
                    "        {\n" +
                    "          \"max\": \"1\",\n" +
                    "          \"startTime\": \"2022/12/23 11:01:20\",\n" +
                    "          \"used\": \"0\",\n" +
                    "          \"endTime\": \"2022/12/23 11:08:40\"\n" +
                    "        },\n" +
                    "        {\n" +
                    "          \"max\": \"1\",\n" +
                    "          \"startTime\": \"2022/12/23 11:08:40\",\n" +
                    "          \"used\": \"0\",\n" +
                    "          \"endTime\": \"2022/12/23 11:16:00\"\n" +
                    "        },\n" +
                    "        {\n" +
                    "          \"max\": \"1\",\n" +
                    "          \"startTime\": \"2022/12/23 11:16:00\",\n" +
                    "          \"used\": \"0\",\n" +
                    "          \"endTime\": \"2022/12/23 11:23:20\"\n" +
                    "        },\n" +
                    "        {\n" +
                    "          \"max\": \"1\",\n" +
                    "          \"startTime\": \"2022/12/23 11:23:20\",\n" +
                    "          \"used\": \"0\",\n" +
                    "          \"endTime\": \"2022/12/23 11:30:40\"\n" +
                    "        },\n" +
                    "        {\n" +
                    "          \"max\": \"1\",\n" +
                    "          \"startTime\": \"2022/12/23 11:30:40\",\n" +
                    "          \"used\": \"0\",\n" +
                    "          \"endTime\": \"2022/12/23 11:38:00\"\n" +
                    "        },\n" +
                    "        {\n" +
                    "          \"max\": \"1\",\n" +
                    "          \"startTime\": \"2022/12/23 11:38:00\",\n" +
                    "          \"used\": \"0\",\n" +
                    "          \"endTime\": \"2022/12/23 11:45:20\"\n" +
                    "        }\n" +
                    "      ],\n" +
                    "      \"status\": \"1\"\n" +
                    "    }\n" +
                    "  ]\n" +
                    "}";
        }
        String url = jwUrl + "/third/guahao/GetDoctorArrange";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("hospitalId", hospitalId));
        params.add(new BasicNameValuePair("hosDeptId", hosDeptId));
        params.add(new BasicNameValuePair("doctorId", doctorId));
        String response = HttpClientUtil.post(url, params, "UTF-8");
        return response;
    }
    /**
     * 获取医生排班接口(一级)
     * @param hospitalId
     * @return
     * @throws Exception
     */
    public String GetDoctorArrangeSimple(String hospitalId,String hosDeptId,String doctorId) throws Exception{
        String url = jwUrl + "/third/guahao/GetDoctorArrangeSimple";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("hospitalId", hospitalId));
        params.add(new BasicNameValuePair("hosDeptId", hosDeptId));
        params.add(new BasicNameValuePair("doctorId", doctorId));
        String response = HttpClientUtil.post(url, params, "UTF-8");
        return response;
    }
    @Resource
    private PatientReservationDao patientReservationDao;
    /**
     * 创建挂号单
     * @param hospitalId
     * @return
     * @throws Exception
     */
    public String CreateOrder(String hospitalId,String hospitalName,String hosDeptId,String hosDeptName,
                               String doctorId,String doctorName,String arrangeDate,String patient,
                               String patientName,String cardNo,String clinicCard,String patientPhone) throws Exception{
        if(isdemo){
            String code = UUID.randomUUID().toString().replace("-","");
            PatientReservation reservation = new PatientReservation();
            reservation.setCode(code);
            reservation.setCzrq(new Date());
            reservation.setType("1");
            reservation.setOrgCode(hospitalId);
            reservation.setOrgName(hospitalName);
            reservation.setDeptCode(hosDeptId);
            reservation.setDeptName(hosDeptName);
            reservation.setDoctorCode(doctorId);
            reservation.setDoctorName(doctorName);
            reservation.setDoctorJob("主任医师");
            reservation.setDoctorPhoto("");
            reservation.setIdcard(cardNo);
            reservation.setName(patientName);
            reservation.setPatient(patient);
            reservation.setPhone(patientPhone);
            reservation.setSectionType("a");
            reservation.setSsc(clinicCard);
            reservation.setStartTime(DateUtil.strToDate("2022-12-23 10:00:00"));
            reservation.setEndTime(DateUtil.strToDate("2022-12-23 10:40:00"));
            reservation.setStatus(1);
            patientReservationDao.save(reservation);
            return code;
        }
        String re = "";
        String url = jwUrl + "/third/guahao/CreateOrder";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("hospitalName", hospitalName));
        params.add(new BasicNameValuePair("hospitalId", hospitalId));
        params.add(new BasicNameValuePair("hosDeptId", hosDeptId));
        params.add(new BasicNameValuePair("hosDeptName", hosDeptName));
        params.add(new BasicNameValuePair("doctorId", doctorId));
        params.add(new BasicNameValuePair("doctorName", doctorName));
        params.add(new BasicNameValuePair("arrangeDate", arrangeDate));
        params.add(new BasicNameValuePair("patient", patient));
        params.add(new BasicNameValuePair("patientName", patientName));
        params.add(new BasicNameValuePair("cardNo", cardNo));
        params.add(new BasicNameValuePair("clinicCard", clinicCard));
        params.add(new BasicNameValuePair("patientPhone", patientPhone));
        String response = HttpClientUtil.post(url, params, "UTF-8");
        if (!StringUtils.isEmpty(response)) {
            JSONObject jsonObject = new JSONObject(response);
            int status = jsonObject.getInt("status");
            if (status == 200) {
                re = jsonObject.getString("data");
            } else {
                String msg = "处理失败,请联系管理员";
                if(!jsonObject.isNull("msg")){
                    msg = jsonObject.getString("msg");
                }
                throw new ServiceException(doMsg(msg));
            }
        } else {
            throw new ServiceException("null response.");
        }
        return re;
    }
    /**
     * 取消挂号单
     * @param orderId
     * @return
     * @throws Exception
     */
    public Boolean CancelOrder(String orderId,String clinicCard) throws Exception{
        if(isdemo){
            return true;
        }
        boolean re = false;
        String url = jwUrl + "/third/guahao/CancelOrder";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("orderId", orderId));
        params.add(new BasicNameValuePair("clinicCard", clinicCard));
        String response = HttpClientUtil.post(url, params, "UTF-8");
        if (!StringUtils.isEmpty(response)) {
            JSONObject jsonObject = new JSONObject(response);
            int status = jsonObject.getInt("status");
            if (status == 200) {
                re = jsonObject.getBoolean("data");
            } else {
                String msg = "处理失败,请联系管理员";
                if(!jsonObject.isNull("msg")){
                    msg = jsonObject.getString("msg");
                }
                throw new ServiceException(msg);
            }
        } else {
            throw new ServiceException("取消挂号单失败!");
        }
        return re;
    }
    /**
     * 获取医生信息
     * @param hospitalId
     * @return
     * @throws Exception
     */
    public String GetDoctorInfo(String hospitalId,String hosDeptId,String doctorId) throws Exception{
        String re = "";
        String url = jwUrl + "/third/guahao/GetDoctorInfo";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("hospitalId", hospitalId));
        params.add(new BasicNameValuePair("hosDeptId", hosDeptId));
        params.add(new BasicNameValuePair("doctorId", doctorId));
        String response = HttpClientUtil.post(url, params, "UTF-8");
        return response;
    }
    /**
     * 获取医生信息
     * @param hospitalId
     * @param hosDeptId
     * @param doctorId
     * @return
     * @throws Exception
     */
    public GuahaoDoctor getGuahaoDoctor(String hospitalId, String hosDeptId, String doctorId) throws Exception{
        String response = GetDoctorInfo(hospitalId,hosDeptId,doctorId);
        if (!StringUtils.isEmpty(response)) {
            JSONObject jsonObject = new JSONObject(response);
            int status = jsonObject.getInt("status");
            if (status == 200) {
                GuahaoDoctor doctor = new GuahaoDoctor();
                JSONObject json = jsonObject.getJSONObject("data");
                doctor.setId(json.isNull("id")?"":json.getString("id"));//医生编码
                doctor.setName(json.isNull("name")?"":json.getString("name"));//医生姓名
                doctor.setSex(json.isNull("sex")?"":json.getString("sex"));//医生性别
                doctor.setTitle(json.isNull("title")?"":json.getString("title"));//医生职称
                doctor.setEdu(json.isNull("edu")?"":json.getString("edu"));//医生学历
                doctor.setIntroduce(json.isNull("introduce")?"":json.getString("introduce"));//医生简介
                doctor.setPhoto(json.isNull("photo")?"":json.getString("photo"));//医生头像
                doctor.setFee(json.isNull("fee")?"":json.getString("fee"));//医生挂号费
                doctor.setHosDeptId(json.isNull("hosDeptId")?"":json.getString("hosDeptId"));//医生科室编码
                doctor.setHosDeptName(json.isNull("hosDeptName")?"":json.getString("hosDeptName"));//医生科室名称
                doctor.setHospitalId(json.isNull("hospitalId")?"":json.getString("hospitalId"));//医生医院编码
                doctor.setHospitalName(json.isNull("hospitalName")?"":json.getString("hospitalName"));//医生医院名称
                return doctor;
            } else {
                String msg = "处理失败,请联系管理员";
                if(!jsonObject.isNull("msg")){
                    msg = jsonObject.getString("msg");
                }
                throw new ServiceException(msg);
            }
        } else {
            throw new ServiceException("获取挂号医生信息失败!");
        }
    }
    /**
     * 获取预约状态(0 撤销 1 确认 2 已诊  3停诊)
     * @param hospitalId
     * @return
     * @throws Exception
     */
    public Integer GetOrderStatus(String hospitalId,String hosDeptId,String doctorId) throws Exception{
        Integer re = null;
        String url = jwUrl + "/third/guahao/GetOrderStatus";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("hospitalId", hospitalId));
        params.add(new BasicNameValuePair("hosDeptId", hosDeptId));
        params.add(new BasicNameValuePair("doctorId", doctorId));
        String response = HttpClientUtil.post(url, params, "UTF-8");
        if (!StringUtils.isEmpty(response)) {
            JSONObject jsonObject = new JSONObject(response);
            int status = jsonObject.getInt("status");
            if (status == 200) {
                re = jsonObject.getInt("data");
            } else {
                throw new ServiceException(jsonObject.getString("msg"));
            }
        } else {
            throw new ServiceException("null response.");
        }
        return re;
    }
    /**
     * 根据患者医保卡获取近三个月的预约记录
     * @param patient
     * @return
     * @throws Exception
     */
    public String GetRegList(String patient) throws Exception{
        if(isdemo){
            List<PatientReservation> list = patientReservationDao.findByPatientAndStartTime(patient,DateUtil.getNextDay1(new Date(),-90),DateUtil.getNextDay1(new Date(),31));
            JSONObject json = new JSONObject();
            json.put("status",200);
            json.put("message","获取成功");
            json.put("data",new JSONArray(list));
            return json.toString();
        }
        String url = jwUrl + "/third/guahao/GetRegList";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("patient", patient));
        String response = HttpClientUtil.post(url, params, "UTF-8");
        return response;
    }
    /**
     * 根据患者,预约编号,机构编号获取单条记录预约记录
     * @param patient
     * @return
     * @throws Exception
     */
    public String GetRegDetail(String patient,String orgCode,String regCode) throws Exception{
        String re = "";
        String url = jwUrl + "/third/guahao/GetRegDetail";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("patient", patient));
        params.add(new BasicNameValuePair("orgCode", orgCode));
        params.add(new BasicNameValuePair("regCode", regCode));
        String response = HttpClientUtil.post(url, params, "UTF-8");
        return response;
    }
    /*************************************** 旧版本函数 *************************************************************************/
    /**
     * 获取住院记录(X)
     */
    public String getHospitalizationRecord(String strSSID, String startNum, String endNum) throws Exception {
        if(isdemo)     //演示环境
        {
            return "";
//            return ehrService.getHospitalizationRecord(strSSID);
        }
        else {
            String startDate = "1900-01-01";
            String endDate = DateUtil.dateToStr(DateUtil.getNowDate(), DateUtil.YYYY_MM_DD);
            String url = jwUrl + "/third/smjk/InpatientRecord";
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("strSSID", strSSID));
            params.add(new BasicNameValuePair("startDate", startDate));
            params.add(new BasicNameValuePair("endDate", endDate));
            params.add(new BasicNameValuePair("startNum", startNum));
            params.add(new BasicNameValuePair("endNum", endNum));
            String response = HttpClientUtil.post(url, params, "UTF-8");
            JSONArray resultArray = new JSONArray();
            List<WlyyHospitalSysDictDO> systemDictList = hospitalSysDictDao.findByDictName("EHR_CATALOG");
            Map<String, String> systemDictMap = new HashMap<>();
            for (WlyyHospitalSysDictDO systemDict : systemDictList) {
                systemDictMap.put(systemDict.getDictCode(), systemDict.getDictValue());
            }
            if (!StringUtils.isEmpty(response)) {
                JSONObject responseObject = new JSONObject(response);
                int status = responseObject.getInt("status");
                if (status == 200) {
                    String data = responseObject.getString("data");
                    if (!StringUtils.isEmpty(data)) {
                        if (data.startsWith("error")) {
                            return data;
                        }
                        JSONObject jsonData = new JSONObject(data);
                        JSONArray jsonArray = jsonData.getJSONArray("EhrList");
                        if (!jsonArray.isNull(0) && jsonArray.getJSONObject(0).length() != 0) {
                            Map<String, JSONObject> jsonObjectMap = new HashMap<>();
                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject jsonObject = jsonArray.getJSONObject(i);
                                String patientId = jsonObject.getString("XMAN_ID");
                                String eventNo = jsonObject.getString("EVENT");
                                Integer orgId = jsonObject.getInt("ORG_ID");
                                String key = patientId + eventNo + orgId;
                                JSONObject catalogObject = new JSONObject();
                                String catalogCode = jsonObject.get("CATALOG_CODE").toString();
                                String endTimeNew = jsonObject.get("END_TIME").toString();
                                String catalogValue = systemDictMap.get(catalogCode);
                                jsonObject.remove("CATALOG_CODE");
                                if (jsonObjectMap.containsKey(key)) {
                                    jsonObject = jsonObjectMap.get(key);
                                    String endTimeOld = jsonObject.get("END_TIME").toString();
                                    if (endTimeNew.compareTo(endTimeOld) < 0) {
                                        endTimeNew = endTimeOld;
                                    }
                                    catalogObject = jsonObject.getJSONObject("CATALOG");
                                }
                                catalogObject.put(catalogCode, catalogValue);
                                jsonObject.put("CATALOG", catalogObject);
                                jsonObject.put("END_TIME", endTimeNew);
                                jsonObjectMap.put(key, jsonObject);
                            }
                            for (String key : jsonObjectMap.keySet()) {
                                resultArray.put(jsonObjectMap.get(key));
                            }
                            JSONObject temp;
                            for (int i = 0; i < resultArray.length(); i++) {
                                for (int j = i + 1; j < resultArray.length(); j++) {
                                    String endTimeNew = resultArray.getJSONObject(j).get("END_TIME").toString();
                                    String endTimeOld = resultArray.getJSONObject(i).get("END_TIME").toString();
                                    if (endTimeNew.compareTo(endTimeOld) > 0) {
                                        temp = resultArray.getJSONObject(i);
                                        resultArray.put(i, resultArray.getJSONObject(j));
                                        resultArray.put(j, temp);  // 两个数交换位置
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return resultArray.toString();
        }
    }
    /**
     * 获取门/急诊记录(X)
     */
    public String getOutpatientRecord(String strSSID, String startNum, String endNum) throws Exception {
        if(isdemo)     //演示环境
        {
            return "";
//            return ehrService.getOutpatientRecord(strSSID);
        }
        else{
            String startDate = "1900-01-01";
            String endDate = DateUtil.dateToStr(DateUtil.getNowDate(), DateUtil.YYYY_MM_DD);
            String url = jwUrl + "/third/smjk/OutpatientRecord";
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("strSSID", strSSID));
            params.add(new BasicNameValuePair("startDate", startDate));
            params.add(new BasicNameValuePair("endDate", endDate));
            params.add(new BasicNameValuePair("startNum", startNum));
            params.add(new BasicNameValuePair("endNum", endNum));
            String response = HttpClientUtil.post(url, params, "UTF-8");
            JSONArray resultArray = new JSONArray();
            List<WlyyHospitalSysDictDO> systemDictList = hospitalSysDictDao.findByDictName("EHR_CATALOG");
            Map<String, String> systemDictMap = new HashMap<>();
            for (WlyyHospitalSysDictDO systemDict : systemDictList) {
                systemDictMap.put(systemDict.getDictCode(), systemDict.getDictValue());
            }
            if (!StringUtils.isEmpty(response)){
                JSONObject responseObject = new JSONObject(response);
                int status = responseObject.getInt("status");
                if (status == 200){
                    String data = responseObject.getString("data");
                    if (!StringUtils.isEmpty(data)){
                        if (data.startsWith("error")) {
                            return data;
                        }
                        JSONObject jsonData = new JSONObject(data);
                        JSONArray jsonArray = jsonData.getJSONArray("EhrList");
                        if (!jsonArray.isNull(0) && jsonArray.getJSONObject(0).length() != 0) {
                            Map<String, JSONObject> jsonObjectMap = new HashMap<>();
                            for (int i=0; i<jsonArray.length(); i++) {
                                JSONObject jsonObject = jsonArray.getJSONObject(i);
                                String patientId = jsonObject.getString("XMAN_ID");
                                String eventNo = jsonObject.getString("EVENT");
                                Integer orgId = jsonObject.getInt("ORG_ID");
                                String key = patientId + eventNo + orgId;
                                JSONObject catalogObject = new JSONObject();
                                String catalogCode = jsonObject.get("CATALOG_CODE").toString();
                                String endTimeNew = jsonObject.get("END_TIME").toString();
                                String catalogValue = systemDictMap.get(catalogCode);
                                jsonObject.remove("CATALOG_CODE");
                                if (jsonObjectMap.containsKey(key)) {
                                    jsonObject = jsonObjectMap.get(key);
                                    String endTimeOld = jsonObject.get("END_TIME").toString();
                                    if (endTimeNew.compareTo(endTimeOld) < 0) {
                                        endTimeNew = endTimeOld;
                                    }
                                    catalogObject = jsonObject.getJSONObject("CATALOG");
                                }
                                catalogObject.put(catalogCode, catalogValue);
                                jsonObject.put("CATALOG", catalogObject);
                                jsonObject.put("END_TIME", endTimeNew);
                                jsonObjectMap.put(key, jsonObject);
                            }
                            for (String key : jsonObjectMap.keySet()) {
                                resultArray.put(jsonObjectMap.get(key));
                            }
                            JSONObject temp;
                            for (int i = 0; i < resultArray.length(); i++) {
                                for (int j = i+1; j < resultArray.length(); j++) {
                                    String endTimeNew = resultArray.getJSONObject(j).get("END_TIME").toString();
                                    String endTimeOld = resultArray.getJSONObject(i).get("END_TIME").toString();
                                    if (endTimeNew.compareTo(endTimeOld) > 0) {
                                        temp = resultArray.getJSONObject(i);
                                        resultArray.put(i, resultArray.getJSONObject(j));
                                        resultArray.put(j, temp);  // 两个数交换位置
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return resultArray.toString();
        }
    }
    /**
     * 获取检查报告信息 (X)
     */
    private JSONArray getChecking(String strSSID, String startNum, String endNum) throws Exception {
        String api = "/third/smjk/ExamReport";
        return getResult(api, strSSID, startNum, endNum);
    }
    /**
     * 获取检验报告信息(X)
     */
    private JSONArray getInspection(String strSSID, String startNum, String endNum) throws Exception {
        String api = "/third/smjk/LabReport";
        return getResult(api, strSSID, startNum, endNum);
    }
    private JSONArray getResult(String api, String strSSID, String startNum, String endNum) {
        String startDate = "1900-01-01";
        String endDate = DateUtil.dateToStr(DateUtil.getNowDate(), DateUtil.YYYY_MM_DD);
        String url = jwUrl + api;
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("strSSID", strSSID));
        params.add(new BasicNameValuePair("startDate", startDate));
        params.add(new BasicNameValuePair("endDate", endDate));
        params.add(new BasicNameValuePair("startNum", startNum));
        params.add(new BasicNameValuePair("endNum", endNum));
        String response = HttpClientUtil.post(url, params, "UTF-8");
        JSONArray resultArray = new JSONArray();
        List<WlyyHospitalSysDictDO> systemDictList = hospitalSysDictDao.findByDictName("EHR_CATALOG");
        Map<String, String> systemDictMap = new HashMap<>();
        for (WlyyHospitalSysDictDO systemDict : systemDictList) {
            systemDictMap.put(systemDict.getDictCode(), systemDict.getDictValue());
        }
        if (!StringUtils.isEmpty(response)){
            JSONObject responseObject = new JSONObject(response);
            int status = responseObject.getInt("status");
            if (status == 200){
                String data = responseObject.getString("data");
                if (!StringUtils.isEmpty(data)){
                    if (data.startsWith("error")) {
                        JSONObject jsonObject = new JSONObject();
                        jsonObject.put("error", data);
                        resultArray.put(jsonObject);
                        return resultArray ;
                    }
                    JSONObject jsonData = new JSONObject(data);
                    JSONArray jsonArray = jsonData.getJSONArray("EhrList");
                    if (!jsonArray.isNull(0) && jsonArray.getJSONObject(0).length() != 0) {
                        Map<String, JSONObject> jsonObjectMap = new HashMap<>();
                        for (int i=0; i<jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            String patientId = jsonObject.getString("XMAN_ID");
                            String eventNo = jsonObject.getString("EVENT");
                            Integer orgId = jsonObject.getInt("ORG_ID");
                            String key = patientId + eventNo + orgId;
                            JSONObject catalogObject = new JSONObject();
                            String catalogCode = jsonObject.get("CATALOG_CODE").toString();
                            String endTimeNew = jsonObject.get("END_TIME").toString();
                            String catalogValue = systemDictMap.get(catalogCode);
                            jsonObject.remove("CATALOG_CODE");
                            if (jsonObjectMap.containsKey(key)) {
                                jsonObject = jsonObjectMap.get(key);
                                String endTimeOld = jsonObject.get("END_TIME").toString();
                                if (endTimeNew.compareTo(endTimeOld) < 0) {
                                    endTimeNew = endTimeOld;
                                }
                                catalogObject = jsonObject.getJSONObject("CATALOG");
                            }
                            catalogObject.put(catalogCode, catalogValue);
                            jsonObject.put("CATALOG", catalogObject);
                            jsonObject.put("END_TIME", endTimeNew);
                            jsonObjectMap.put(key, jsonObject);
                        }
                        for (String key : jsonObjectMap.keySet()) {
                            resultArray.put(jsonObjectMap.get(key));
                        }
                    }
                }
            }
        }
        return resultArray;
    }
    /**
     * 获取检查检验 信息(X)
     * @param strSSID
     * @param startNum
     * @param endNum
     * @return
     * @throws Exception
     */
    public String getInspectionAndChecking(String strSSID, String startNum, String endNum) throws Exception {
        if(isdemo)     //演示环境
        {
            return "";
//            return ehrService.getInspectionAndChecking(strSSID);
        }
        else {
            JSONArray total = new JSONArray();
            JSONArray check = getChecking(strSSID, startNum, endNum);
            if (!check.isNull(0)) {
                JSONObject jsonObject = check.getJSONObject(0);
                if (jsonObject.has("error")) {
                    return jsonObject.get("error").toString();
                }
            }
            JSONArray inspect = getInspection(strSSID, startNum, endNum);
            if (!inspect.isNull(0)) {
                JSONObject jsonObject = inspect.getJSONObject(0);
                if (jsonObject.has("error")) {
                    return jsonObject.get("error").toString();
                }
            }
            //TODO 检查检验数据合并
            for (int i = 0; i < check.length(); i++) {
                total.put(check.getJSONObject(i));
            }
            for (int i = 0; i < inspect.length(); i++) {
                total.put(inspect.getJSONObject(i));
            }
            JSONObject temp;
            for (int i = 0; i < total.length(); i++) {
                for (int j = i + 1; j < total.length(); j++) {
                    String endTimeNew = total.getJSONObject(j).get("END_TIME").toString();
                    String endTimeOld = total.getJSONObject(i).get("END_TIME").toString();
                    if (endTimeNew.compareTo(endTimeOld) > 0) {
                        temp = total.getJSONObject(i);
                        total.put(i, total.getJSONObject(j));
                        total.put(j, temp);  // 两个数交换位置
                    }
                }
            }
            return total.toString();
        }
    }
    /**
     * 获取用药记录(X)
     */
    public String getDrugsList(String strSSID, String startNum,String endNum) throws Exception {
        if(isdemo)     //演示环境
        {
            return "";
//            return ehrService.getDrugsList(strSSID);
        }
        else {
            String startDate = "1900-01-01";
            String endDate = DateUtil.dateToStr(DateUtil.getNowDate(), DateUtil.YYYY_MM_DD);
            String url = jwUrl + "/third/smjk/DrugsList";
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("strSSID", strSSID));
            params.add(new BasicNameValuePair("startDate", startDate));
            params.add(new BasicNameValuePair("endDate", endDate));
            params.add(new BasicNameValuePair("startNum", startNum));
            params.add(new BasicNameValuePair("endNum", endNum));
            String response = HttpClientUtil.post(url, params, "UTF-8");
            JSONArray resultArray = new JSONArray();
            List<WlyyHospitalSysDictDO> systemDictList = hospitalSysDictDao.findByDictName("EHR_CATALOG");
            Map<String, String> systemDictMap = new HashMap<>();
            for (WlyyHospitalSysDictDO systemDict : systemDictList) {
                systemDictMap.put(systemDict.getDictCode(), systemDict.getDictValue());
            }
            if (!StringUtils.isEmpty(response)) {
                JSONObject responseObject = new JSONObject(response);
                int status = responseObject.getInt("status");
                if (status == 200) {
                    String data = responseObject.getString("data");
                    if (!StringUtils.isEmpty(data)) {
                        if (data.startsWith("error")) {
                            return data;
                        }
                        JSONObject jsonData = new JSONObject(data);
                        JSONArray jsonArray = jsonData.getJSONArray("EhrList");
                        if (!jsonArray.isNull(0) && jsonArray.getJSONObject(0).length() != 0) {
                            Map<String, JSONObject> jsonObjectMap = new HashMap<>();
                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject jsonObject = jsonArray.getJSONObject(i);
                                String patientId = jsonObject.getString("XMAN_ID");
                                String eventNo = jsonObject.getString("EVENT");
                                Integer orgId = jsonObject.getInt("ORG_ID");
                                String key = patientId + eventNo + orgId;
                                JSONObject catalogObject = new JSONObject();
                                String catalogCode = jsonObject.get("CATALOG_CODE").toString();
                                String endTimeNew = jsonObject.get("END_TIME").toString();
                                String catalogValue = systemDictMap.get(catalogCode);
                                jsonObject.remove("CATALOG_CODE");
                                if (jsonObjectMap.containsKey(key)) {
                                    jsonObject = jsonObjectMap.get(key);
                                    String endTimeOld = jsonObject.get("END_TIME").toString();
                                    if (endTimeNew.compareTo(endTimeOld) < 0) {
                                        endTimeNew = endTimeOld;
                                    }
                                    catalogObject = jsonObject.getJSONObject("CATALOG");
                                }
                                catalogObject.put(catalogCode, catalogValue);
                                jsonObject.put("CATALOG", catalogObject);
                                jsonObject.put("END_TIME", endTimeNew);
                                jsonObjectMap.put(key, jsonObject);
                            }
                            for (String key : jsonObjectMap.keySet()) {
                                resultArray.put(jsonObjectMap.get(key));
                            }
                            JSONObject temp;
                            for (int i = 0; i < resultArray.length(); i++) {
                                for (int j = i + 1; j < resultArray.length(); j++) {
                                    String endTimeNew = resultArray.getJSONObject(j).get("END_TIME").toString();
                                    String endTimeOld = resultArray.getJSONObject(i).get("END_TIME").toString();
                                    if (endTimeNew.compareTo(endTimeOld) > 0) {
                                        temp = resultArray.getJSONObject(i);
                                        resultArray.put(i, resultArray.getJSONObject(j));
                                        resultArray.put(j, temp);  // 两个数交换位置
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return resultArray.toString();
        }
    }
    public JSONObject GetDoctorInfoTen(String hospitalId, String hosDeptId, String doctorId) {
        if(isdemo){
            String tmp = "{\n" +
                    "  \"message\": \"获取医生详细信息成功!\",\n" +
                    "  \"data\": {\n" +
                    "    \"hosDeptId\": \"30100\",\n" +
                    "    \"hospitalId\": \"350211A1002\",\n" +
                    "    \"introduce\": \"主任医师、硕士,毕业于福建医科大学。现任科教部副主任,心内二科医疗组长。\\r\\n从事心血管内科临床及教学工作20余年,积累了丰富的临床工作经验。擅长高血压、冠心病、心力衰竭的临床诊治工作,在高血压的诊治方面有独到的造诣。\",\n" +
                    "    \"hosDeptName\": \"心内科门诊\",\n" +
                    "    \"sex\": \"1\",\n" +
                    "    \"edu\": \"硕士\",\n" +
                    "    \"fee\": null,\n" +
                    "    \"name\": \"陈水龙\",\n" +
                    "    \"photo\": \"\",\n" +
                    "    \"id\": \"259724\",\n" +
                    "    \"hospitalName\": \"马銮湾医院\",\n" +
                    "    \"title\": \"主任医师\"\n" +
                    "  },\n" +
                    "  \"status\": 200\n" +
                    "}";
            return new JSONObject(tmp);
        }
        String url = jwUrl + "/third/smjk/RegDeptSpeDoctorList";
        List<NameValuePair> params = new ArrayList<>();
        //当前时间;
        String strStart = DateUtil.getStringDateShort();
        //10天预约
        String strEnd = DateUtil.getNextDay(strStart, 11);
        params.add(new BasicNameValuePair("orgCode", hospitalId));
        params.add(new BasicNameValuePair("deptCode", hosDeptId));
        params.add(new BasicNameValuePair("strStart", strStart));
        params.add(new BasicNameValuePair("strEnd", strEnd));
        String response = HttpClientUtil.post(url, params, "UTF-8");
        JSONObject jsonData = new JSONObject(response);
        JSONArray  jsonArray = jsonData.getJSONArray("data");
        for (int i=0; i<jsonArray.length(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            if(doctorId.equals(jsonObject.getString("id"))){
                return jsonObject;
            }
        }
        return null;
    }
    
    /**
     * 获取市民健康系统居民基本信息
     * @param ssc
     * @return
     * @throws Exception
     */
    public String getSmjkBaseInfo(String ssc)throws Exception{
        if(isdemo)     //演示环境
        {
            return "";
        }
        else {
            String re = "";
            String url = jwUrl + "/third/smjk/getXmanInfo";
        
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("strSSID", ssc));
        
            String response = HttpClientUtil.post(url, params, "UTF-8");
        
            if (!StringUtils.isEmpty(response)) {
                JSONObject responseObject = new JSONObject(response);
                int status = responseObject.getInt("status");
                if (status == 200) {
                    String data = responseObject.getString("data");
                    if (!StringUtils.isEmpty(data) && data.startsWith("error")) {
                        throw new ServiceException(data);
                    } else {
//                        JSONObject jsonData = new JSONObject(data);
//                        JSONArray jsonArray = jsonData.getJSONArray("EventList");
                        re = data;
                    }
                } else {
                    throw new ServiceException(responseObject.getString("msg"));
                }
            } else {
                throw new ServiceException("null response.");
            }
        
            if(re.contains("[{}]"))
            {
                re = re.replace("[{}]","[]");
            }
        
            return re;
        }
    }
}

+ 118 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/vo/GuahaoDoctor.java

@ -0,0 +1,118 @@
package com.yihu.jw.hospital.prescription.vo;
/**
 * Created by hzp on 2016/8/13.
 * 挂号服务医生信息
 */
public class GuahaoDoctor {
    private String id;//医生编码
    private String name;//医生姓名
    private String sex;//医生性别
    private String title;//医生职称
    private String edu;//医生学历
    private String introduce;//医生简介
    private String photo;//医生头像
    private String fee;//医生挂号费
    private String hosDeptId;//医生科室编码
    private String hosDeptName;//医生科室名称
    private String hospitalId;//医生医院编码
    private String hospitalName;//医生医院名称
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getEdu() {
        return edu;
    }
    public void setEdu(String edu) {
        this.edu = edu;
    }
    public String getIntroduce() {
        return introduce;
    }
    public void setIntroduce(String introduce) {
        this.introduce = introduce;
    }
    public String getPhoto() {
        return photo;
    }
    public void setPhoto(String photo) {
        this.photo = photo;
    }
    public String getFee() {
        return fee;
    }
    public void setFee(String fee) {
        this.fee = fee;
    }
    public String getHosDeptId() {
        return hosDeptId;
    }
    public void setHosDeptId(String hosDeptId) {
        this.hosDeptId = hosDeptId;
    }
    public String getHosDeptName() {
        return hosDeptName;
    }
    public void setHosDeptName(String hosDeptName) {
        this.hosDeptName = hosDeptName;
    }
    public String getHospitalId() {
        return hospitalId;
    }
    public void setHospitalId(String hospitalId) {
        this.hospitalId = hospitalId;
    }
    public String getHospitalName() {
        return hospitalName;
    }
    public void setHospitalName(String hospitalName) {
        this.hospitalName = hospitalName;
    }
}

+ 28 - 0
business/base-service/src/main/java/com/yihu/jw/wechat/service/WechatUtilService.java

@ -0,0 +1,28 @@
package com.yihu.jw.wechat.service;
import com.yihu.jw.entity.base.wx.WxAccessTokenDO;
import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
import com.yihu.jw.util.wechat.WeixinMessagePushUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
 * Created by yeshijie on 2022/11/22.
 */
@Component
public class WechatUtilService {
    @Value("${wechat.id}")
    private String wechatId;
    @Resource
    private WxAccessTokenService wxAccessTokenService;
    @Resource
    private WeixinMessagePushUtils weixinMessagePushUtils;
    public void putWxMsg(String openid, WxTemplateConfigDO newConfig){
        WxAccessTokenDO wxAccessTokenDO = wxAccessTokenService.getWxAccessTokenById(wechatId);
        weixinMessagePushUtils.putWxMsg(wxAccessTokenDO.getAccessToken(), openid, newConfig);
    }
}

+ 442 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/hospital/booking/PatientReservation.java

@ -0,0 +1,442 @@
package com.yihu.jw.entity.hospital.booking;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import java.util.Date;
/**
 * 预约挂号记录表
 * @author George
 *
 */
@Entity
@Table(name = "wlyy_patient_reservation")
@SequenceGenerator(name="id_generated", sequenceName="wlyy_patient_reservation")
public class PatientReservation extends IdEntity {
	/**
	 *
	 */
	private static final long serialVersionUID = 8452660447546825044L;
	// 预约号/预约流水号
	private String code;
	// 医生标识(医生帮患者预约时才会有值)
	private String doctor;
	// 医生姓名(医生帮患者预约时才会有值)
	private String dname;
	// 患者标识
	private String patient;
	// 患者身份证
	private String idcard;
	// 患者姓名
	private String name;
	// 患者手机号
	private String phone;
	// 患者社保卡号
	private String ssc;
	// 预约时间段:AM (上午)或者PM (下午)
	private String sectionType;
	// 一次预约段的开始时间
	private Date startTime;
	// 一次预约段的结束时间
	private Date endTime;
	// 医生所在医疗机构编码
	private String orgCode;
	// 医疗机构名称
	private String orgName;
	// 科室编码
	private String deptCode;
	// 科室名称
	private String deptName;
	// 专家ID/编码
	private String doctorCode;
	// 专家姓名
	private String doctorName;
	// 专家头像
	private String doctorPhoto;
	// 专家职称
	private String doctorJob;
	// 状态:1预约成功,0预约取消
	private Integer status;
	//取消预约者(状态为预约取消时才有值)
	private String canceler;
	//取消预约者姓名(状态为预约取消时才有值)
	private String cancelerName;
	//取消预约者角色(状态为预约取消时才有值)1专科医生,2全科医生,3健康管理师,4临时专科 5.患者 (与医生服务团队角色一直)6.客服
	private Integer cancelerType;
	//取消时间(状态为预约取消时才有值)
	private String cancelerTime;
	// 预约时间
	private Date czrq;
	// 0 健康之路 1智业
	private String type;
	// 签约类型 1三师 2家庭
	private Integer signType;
	// 行政团队
	private Long adminTeamCode;
	//关联电话记录Code(通过客服系统预约才有值)
	private String callCode;
	//客服系统客服code(通过客服系统预约才有值)
	private String userCode;
	//客服系统客服name(通过客服系统预约才有值)
	private String userName;
	//转诊类型 1普诊 2复诊
	private Integer reservationType;
	//附带消息类型(0:健康咨询  1:康复计划 2:门诊记录 3:住院记录 4:检查检验 5:用药记录 6:体检记录 7:血压情况  8
	//:血糖情况 9:产检记录 10:免疫记录  11:筛查报告)
	private String incidentalMsgType;
	//附带消息内容大概
	private String incidentalMsg;
	//转诊原因
	private String reservationReason;
	//参数json字符串
	private String paramJson;
	//业务关联code
	private String relationCode;
	private Integer source;//代预约来源(1体征预警 2疾病筛查 3康复复诊 4健康咨询)
	private Integer patientReadStatus;
	private Integer doctorReadStatus;
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getDoctor() {
		return doctor;
	}
	public void setDoctor(String doctor) {
		this.doctor = doctor;
	}
	public String getDname() {
		return dname;
	}
	public void setDname(String dname) {
		this.dname = dname;
	}
	public String getPatient() {
		return patient;
	}
	public void setPatient(String patient) {
		this.patient = patient;
	}
	public String getIdcard() {
		return idcard;
	}
	public void setIdcard(String idcard) {
		this.idcard = idcard;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getSsc() {
		return ssc;
	}
	public void setSsc(String ssc) {
		this.ssc = ssc;
	}
	@Column(name = "section_type")
	public String getSectionType() {
		return sectionType;
	}
	public void setSectionType(String sectionType) {
		this.sectionType = sectionType;
	}
	@Column(name = "start_time")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getStartTime() {
		return startTime;
	}
	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}
	@Column(name = "end_time")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getEndTime() {
		return endTime;
	}
	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
	@Column(name = "org_code")
	public String getOrgCode() {
		return orgCode;
	}
	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}
	@Column(name = "org_name")
	public String getOrgName() {
		return orgName;
	}
	public void setOrgName(String orgName) {
		this.orgName = orgName;
	}
	@Column(name = "dept_code")
	public String getDeptCode() {
		return deptCode;
	}
	public void setDeptCode(String deptCode) {
		this.deptCode = deptCode;
	}
	@Column(name = "dept_name")
	public String getDeptName() {
		return deptName;
	}
	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}
	@Column(name = "doctor_code")
	public String getDoctorCode() {
		return doctorCode;
	}
	public void setDoctorCode(String doctorCode) {
		this.doctorCode = doctorCode;
	}
	@Column(name = "doctor_name")
	public String getDoctorName() {
		return doctorName;
	}
	public void setDoctorName(String doctorName) {
		this.doctorName = doctorName;
	}
	@Column(name = "doctor_photo")
	public String getDoctorPhoto() {
		return doctorPhoto;
	}
	public void setDoctorPhoto(String doctorPhoto) {
		this.doctorPhoto = doctorPhoto;
	}
	@Column(name = "doctor_job")
	public String getDoctorJob() {
		return doctorJob;
	}
	public void setDoctorJob(String doctorJob) {
		this.doctorJob = doctorJob;
	}
	public Integer getStatus() {
		return status;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	public String getCanceler() {
		return canceler;
	}
	public void setCanceler(String canceler) {
		this.canceler = canceler;
	}
	@Column(name = "canceler_name")
	public String getCancelerName() {
		return cancelerName;
	}
	public void setCancelerName(String cancelerName) {
		this.cancelerName = cancelerName;
	}
	@Column(name = "canceler_type")
	public Integer getCancelerType() {
		return cancelerType;
	}
	public void setCancelerType(Integer cancelerType) {
		this.cancelerType = cancelerType;
	}
	@Column(name = "canceler_time")
	public String getCancelerTime() {
		return cancelerTime;
	}
	public void setCancelerTime(String cancelerTime) {
		this.cancelerTime = cancelerTime;
	}
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getCzrq() {
		return czrq;
	}
	public void setCzrq(Date czrq) {
		this.czrq = czrq;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public Integer getSignType() {
		return signType;
	}
	public void setSignType(Integer signType) {
		this.signType = signType;
	}
	public Long getAdminTeamCode() {
		return adminTeamCode;
	}
	public void setAdminTeamCode(Long adminTeamCode) {
		this.adminTeamCode = adminTeamCode;
	}
	public String getCallCode() {
		return callCode;
	}
	public void setCallCode(String callCode) {
		this.callCode = callCode;
	}
	public String getUserCode() {
		return userCode;
	}
	public void setUserCode(String userCode) {
		this.userCode = userCode;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public Integer getReservationType() {
		return reservationType;
	}
	public void setReservationType(Integer reservationType) {
		this.reservationType = reservationType;
	}
	public String getIncidentalMsgType() {
		return incidentalMsgType;
	}
	public void setIncidentalMsgType(String incidentalMsgType) {
		this.incidentalMsgType = incidentalMsgType;
	}
	public String getIncidentalMsg() {
		return incidentalMsg;
	}
	public void setIncidentalMsg(String incidentalMsg) {
		this.incidentalMsg = incidentalMsg;
	}
	public String getReservationReason() {
		return reservationReason;
	}
	public void setReservationReason(String reservationReason) {
		this.reservationReason = reservationReason;
	}
	public String getParamJson() {
		return paramJson;
	}
	public void setParamJson(String paramJson) {
		this.paramJson = paramJson;
	}
	public String getRelationCode() {
		return relationCode;
	}
	public void setRelationCode(String relationCode) {
		this.relationCode = relationCode;
	}
	public Integer getSource() {
		return source;
	}
	public void setSource(Integer source) {
		this.source = source;
	}
	public Integer getPatientReadStatus() {
		return patientReadStatus;
	}
	public void setPatientReadStatus(Integer patientReadStatus) {
		this.patientReadStatus = patientReadStatus;
	}
	public Integer getDoctorReadStatus() {
		return doctorReadStatus;
	}
	public void setDoctorReadStatus(Integer doctorReadStatus) {
		this.doctorReadStatus = doctorReadStatus;
	}
}

+ 49 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/hospital/booking/ReservationHospitalDept.java

@ -0,0 +1,49 @@
package com.yihu.jw.entity.hospital.booking;
import com.yihu.jw.entity.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
/**
 * Created by wangzhinan on 2019/9/11.
 * 预约科室
 */
@Entity
@Table(name = "wlyy_reservation_hospital_dept")
@SequenceGenerator(name="id_generated", sequenceName="wlyy_reservation_hospital_dept")
public class ReservationHospitalDept extends IdEntity {
    private String code;//科室编码
    private String hospitalCode;//医院或者社区编码
    private String name;//科室名称
    @Column(name = "code")
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    @Column(name ="hospital_code")
    public String getHospitalCode() {
        return hospitalCode;
    }
    public void setHospitalCode(String hospitalCode) {
        this.hospitalCode = hospitalCode;
    }
    @Column(name = "name")
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

+ 355 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/web/endpoint/BaseRestEndPoint.java

@ -5,8 +5,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.constants.PageArg;
import com.yihu.jw.util.date.DateTimeUtil;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import javax.servlet.http.HttpServletRequest;
@ -180,4 +183,356 @@ public class BaseRestEndPoint extends Exception {
        return links.toString();
    }
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @return
     */
    public String error(int code, String msg) {
        try {
            Map<Object, Object> map = new HashMap<Object, Object>();
            ObjectMapper mapper = new ObjectMapper();
            map.put("status", code);
            map.put("message", msg);
            return mapper.writeValueAsString(map);
        } catch (Exception e) {
            error(e);
            return null;
        }
    }
    public void error(Exception e) {
        e.printStackTrace();
    }
    public void errorResult(Exception e) {
        e.printStackTrace();
    }
    public String write(int code, String msg) {
        try {
            Map<Object, Object> map = new HashMap<Object, Object>();
            ObjectMapper mapper = new ObjectMapper();
            map.put("status", code);
            map.put("message", msg);
            return mapper.writeValueAsString(map);
        } catch (Exception e) {
            error(e);
            return null;
        }
    }
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @return
     */
    public String write(int code, String msg, String key, List<?> list) {
        try {
            Map<Object, Object> map = new HashMap<Object, Object>();
            ObjectMapper mapper = new ObjectMapper();
            mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
            map.put("status", code);
            map.put("message", msg);
            map.put(key, list);
            String s = mapper.writeValueAsString(map);
            return s;
        } catch (Exception e) {
            error(e);
            return error(-1, "服务器异常,请稍候再试!");
        }
    }
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @return
     */
    public String write(int code, String msg, String key, List<?> list,String key2,Object value) {
        try {
            Map<Object, Object> map = new HashMap<Object, Object>();
            ObjectMapper mapper = new ObjectMapper();
            mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
            map.put("status", code);
            map.put("message", msg);
            map.put(key, list);
            map.put(key2, value);
            String s = mapper.writeValueAsString(map);
            return s;
        } catch (Exception e) {
            error(e);
            return error(-1, "服务器异常,请稍候再试!");
        }
    }
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @param value 结果数据
     * @return
     */
    public String write(int code, String msg, String key, JSONObject value) {
        try {
            JSONObject json = new JSONObject();
            json.put("status", code);
            json.put("message", msg);
            json.put(key, value);
            return json.toString();
        } catch (Exception e) {
            error(e);
            return error(-1, "服务器异常,请稍候再试!");
        }
    }
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @param value 结果数据
     * @return
     */
    public String write(int code, String msg, String key, JSONArray value, String key2, JSONObject value2) {
        try {
            JSONObject json = new JSONObject();
            json.put("status", code);
            json.put("message", msg);
            json.put(key, value);
            json.put(key2, value2);
            return json.toString();
        } catch (Exception e) {
            error(e);
            return error(-1, "服务器异常,请稍候再试!");
        }
    }
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @param value 结果数据
     * @return
     */
    public String write(int code, String msg, String key, JSONArray value) {
        try {
            JSONObject json = new JSONObject();
            json.put("status", code);
            json.put("message", msg);
            json.put(key, value);
            return json.toString();
        } catch (Exception e) {
            error(e);
            return error(-1, "服务器异常,请稍候再试!");
        }
    }
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @param total 总数
     * @param value 结果数据
     * @return
     */
    public String write(int code, String msg, int total, String key, JSONArray value) {
        try {
            JSONObject json = new JSONObject();
            json.put("status", code);
            json.put("message", msg);
            json.put("total", total);
            json.put(key, value);
            return json.toString();
        } catch (Exception e) {
            error(e);
            return error(-1, "服务器异常,请稍候再试!");
        }
    }
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @return
     */
    public String write(int code, String msg, int total, String key, List<?> list) {
        try {
            Map<Object, Object> map = new HashMap<Object, Object>();
            ObjectMapper mapper = new ObjectMapper();
            mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
            map.put("status", code);
            map.put("message", msg);
            map.put("total", total);
            map.put(key, list);
            String s = mapper.writeValueAsString(map);
            return s;
        } catch (Exception e) {
            error(e);
            return error(-1, "服务器异常,请稍候再试!");
        }
    }
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @param value 结果数据
     * @return
     */
    public String write(int code, String msg, String key, Object value) {
        try {
            Map<Object, Object> map = new HashMap<Object, Object>();
            ObjectMapper mapper = new ObjectMapper();
            map.put("status", code);
            map.put("message", msg);
            map.put(key, value);
            return mapper.writeValueAsString(map);
        } catch (Exception e) {
            error(e);
            return error(-1, "服务器异常,请稍候再试!");
        }
    }
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @return
     */
    public String write(int code, String msg, String key, Page<?> list) {
        try {
            Map<Object, Object> map = new HashMap<Object, Object>();
            ObjectMapper mapper = new ObjectMapper();
            map.put("status", code);
            map.put("message", msg);
            // 是否为第一页
            map.put("isFirst", list.isFirst());
            // 是否为最后一页
            map.put("isLast", list.isLast());
            // 总条数
            map.put("total", list.getTotalElements());
            // 总页数
            map.put("totalPages", list.getTotalPages());
            map.put(key, list.getContent());
            return mapper.writeValueAsString(map);
        } catch (Exception e) {
            error(e);
            return error(-1, "服务器异常,请稍候再试!");
        }
    }
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @return
     */
    public String write(int code, String msg, String key, Page<?> page, JSONArray array) {
        try {
            JSONObject json = new JSONObject();
            json.put("status", code);
            json.put("message", msg);
            // 是否为第一页
            json.put("isFirst", page == null ? false : page.isFirst());
            // 是否为最后一页
            json.put("isLast", page == null ? true : page.isLast());
            // 总条数
            json.put("total", page == null ? 0 : page.getTotalElements());
            // 总页数
            json.put("totalPages", page == null ? 0 : page.getTotalPages());
            json.put(key, array);
            return json.toString();
        } catch (Exception e) {
            error(e);
            return error(-1, "服务器异常,请稍候再试!");
        }
    }
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @param value 结果数据
     * @return
     */
    public String write(int code, String msg, String key, Map<?, ?> value) {
        try {
            Map<Object, Object> map = new HashMap<Object, Object>();
            ObjectMapper mapper = new ObjectMapper();
            map.put("status", code);
            map.put("message", msg);
            map.put(key, value);
            return mapper.writeValueAsString(map);
        } catch (Exception e) {
            error(e);
            return error(-1, "服务器异常,请稍候再试!");
        }
    }
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @param value 结果数据
     * @return
     */
    public String write(int code, String msg, String key, String value) {
        try {
            Map<Object, Object> map = new HashMap<Object, Object>();
            ObjectMapper mapper = new ObjectMapper();
            map.put("status", code);
            map.put("message", msg);
            map.put(key, value);
            return mapper.writeValueAsString(map);
        } catch (Exception e) {
            error(e);
            return error(-1, "服务器异常,请稍候再试!");
        }
    }
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @return
     */
    public String write(int code, String msg, boolean isFirst, boolean isLast, long total, int totalPages, String key, Object values) {
        try {
            JSONObject json = new JSONObject();
            json.put("status", code);
            json.put("message", msg);
            // 是否为第一页
            json.put("isFirst", isFirst);
            // 是否为最后一页
            json.put("isLast", isLast);
            // 总条数
            json.put("total", total);
            // 总页数
            json.put("totalPages", totalPages);
            json.put(key, values);
            return json.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "服务器异常,请稍候再试!");
        }
    }
}

+ 363 - 0
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/booking/PatientBookingEndpoint.java

@ -0,0 +1,363 @@
package com.yihu.jw.hospital.endpoint.booking;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
import com.yihu.jw.entity.hospital.booking.PatientReservation;
import com.yihu.jw.hospital.booking.service.PatientReservationService;
import com.yihu.jw.hospital.prescription.service.entrance.JwSmjkEntranceService;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.entity.ServiceException;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.wechat.dao.WxTemplateConfigDao;
import com.yihu.jw.wechat.service.WechatUtilService;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
 * Created by yeshijie on 2022/11/22.
 */
@RestController
@RequestMapping("patient/booking" )
@Api(tags = "居民预约挂号管理")
public class PatientBookingEndpoint extends EnvelopRestEndpoint {
    private static final Logger logger = LoggerFactory.getLogger(PatientBookingEndpoint.class);
//    @Autowired
//    private GuahaoXMService guahaoXM;
    @Resource
    private PatientReservationService patientReservationService;
    @Resource
    private BasePatientDao patientDao;
    @Resource
    private WechatUtilService wechatUtilService;
    @Resource
    private JwSmjkEntranceService jwSmjkService;
    @Autowired
    private HttpClientUtil HttpClientUtil;
//    @Autowired
//    private SMSDao smsDao;
    @Autowired
    private WxTemplateConfigDao templateConfigDao;
    @Autowired
    private StringRedisTemplate redisTemplate;
//    @Autowired
//    private ConsultService consultService;
//    @Autowired
//    private SMSService smsService;
    @Autowired
    protected HttpServletRequest request;
    @Value("${wechat.id}")
    private String wechatId;
    @PostMapping(value = "CancelOrder")
    @ApiOperation("取消挂号单")
    public Envelop CancelOrder(@ApiParam(name = "orderId", value = "订单id", defaultValue = "48")
                              @RequestParam(value = "orderId", required = true) String orderId,
                               @ApiParam(name = "ssc", value = "社保卡号", defaultValue = "48")
                              @RequestParam(value = "ssc", required = true) String ssc) {
        try {
            //获取订单信息
            boolean re = jwSmjkService.CancelOrder(orderId,ssc);
            if (re) {
                PatientReservation obj = patientReservationService.findByCode(orderId);
                if(obj==null){//不是在i健康预约
                    return success("取消挂号单成功!");
                }
                //更新状态
                patientReservationService.patientCancelOrder(orderId,obj.getPatient());//"9aa5c557e06a4324911487a035195545"
                //微信消息
                BasePatientDO p = patientDao.findById(obj.getPatient()).orElse(null);
                WxTemplateConfigDO templateConfig = templateConfigDao.findByWechatIdAndTemplateNameAndScene(wechatId,"template_appoint_failed","qxgh");
                String remark = templateConfig.getRemark();
                remark = remark.replace("key1",(obj.getName()==null?"":obj.getName())).replace("key2",(obj.getStartTime()==null?"":obj.getStartTime()+""))
                        .replace("br","\n");
                if (StringUtils.isNotEmpty(p.getOpenid())) {
                    WxTemplateConfigDO newConfig = new WxTemplateConfigDO();
                    BeanUtils.copyProperties(templateConfig, newConfig);
                    newConfig.setRemark(remark);
                    //判断是否判定openId,有没有发则查找家人发送
                    if(StringUtils.isNotBlank(p.getOpenid())){
                        wechatUtilService.putWxMsg(p.getOpenid(),newConfig);
                    }
                }
                return success("取消挂号单成功!");
            } else {
                return Envelop.getError("取消挂号单失败!");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return failedException2(e);
        }
    }
    /**
     * ======================预约挂号 start=====================
     */
    private void recordRequestLog(String methodName){
        String uri = request.getRequestURI();//返回请求行中的资源名称
        String url = request.getRequestURL().toString();//获得客户端发送请求的完整url
        String ip = request.getRemoteAddr();//返回发出请求的IP地址
        String params = "";
        if("GET".equals(request.getMethod())){
            params = request.getQueryString();//返回请求行中的参数部分
        }else if("POST".equals(request.getMethod())){
            Map<String,String> map = new HashMap<>();
            Enumeration paraNames = request.getParameterNames();
            while (paraNames.hasMoreElements()){
                String paraName = (String) paraNames.nextElement();
                String[] paraValues = request.getParameterValues(paraName);
                if(paraValues.length ==1 ){
                    if(paraValues[0].length() !=0){
                        map.put(paraName,paraValues[0]);
                    }
                }
            }
            Set<Map.Entry<String,String>> set = map.entrySet();
            for (Map.Entry entry:set){
                params =  params +entry.getKey()+":"+entry.getValue()+"--";
            }
        }
        String host=request.getRemoteHost();//返回发出请求的客户机的主机名
        int port =request.getRemotePort();//返回发出请求的客户机的端口号。
        logger.info("ip:"+ip+",port:"+port+",host:"+host+",api:"+methodName+",uri:"+uri+",url:"+url+",params:"+params);
    }
    @PostMapping(value = "GetOrgDepListToMysql")
    @ApiOperation("从数据库获取科室接口")
    public Envelop GetOrgDepListToMysql(
            @ApiParam(name = "filter", value = "过滤条件", defaultValue = "")
            @RequestParam(value = "filter", required = false) String filter) {
        try {
            return ListEnvelop.getSuccess("获取科室列表成功",jwSmjkService.GetOrgDepListToMysql(null,filter));
        } catch (Exception e) {
            return failedException2(e);
        }
    }
    /**
     * 获取转诊预约医生列表
     */
    @RequestMapping(value = "/RegDeptSpeDoctorList",method = RequestMethod.POST)
    @ApiOperation("获取转诊预约医生列表")
    public String getRegDeptSpeDoctorList(
            @ApiParam(name="hospitalId",value="医院编码") @RequestParam(name="hospitalId",required = false) String hospitalId,
            @ApiParam(name="hosDeptId",value="科室编码",defaultValue = "1040610") @RequestParam(name="hosDeptId",required = true) String hosDeptId,
            @ApiParam(name = "filter", value = "过滤条件", defaultValue = "")
            @RequestParam(value = "filter", required = false) String filter,
            @ApiParam(name = "page", value = "第几页", defaultValue = "")
            @RequestParam(value = "page", required = false) Integer page,
            @ApiParam(name = "size", value = "每页记录数", defaultValue = "")
            @RequestParam(value = "size", required = false) Integer size){
        try {
            //7天排班的医生列表
            String list = jwSmjkService.GetDoctorList(hospitalId,hosDeptId);
            return list;
        } catch (Exception ex) {
            ex.printStackTrace();
            return error(-1,"获取转诊预约医生列表列表失败");
        }
    }
    @RequestMapping(value = "GetDoctorArrangeSimple", method = RequestMethod.POST)
    @ApiOperation("获取医生排班接口(一级)")
    public Envelop GetDoctorArrangeSimple(@ApiParam(name = "city", value = "城市编码", defaultValue = "350200")
                                         @RequestParam(value = "city", required = false) 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 {
            recordRequestLog("GetDoctorArrangeSimple");
            String list = jwSmjkService.GetDoctorArrangeSimple(hospitalId,hosDeptId,doctorId);
            return ObjEnvelop.getSuccess("",list);
        } catch (Exception e) {
            return failedException2(e);
        }
    }
    @RequestMapping(value = "GetDoctorInfo", method = RequestMethod.POST)
    @ApiOperation("根据医生编码获取医生详细信息")
    public String GetDoctorInfo(@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 = false) String hospitalId,
                                @ApiParam(name = "hosDeptId", value = "科室id", defaultValue = "1040610")
                                @RequestParam(value = "hosDeptId", required = true) String hosDeptId) {
        try {
            recordRequestLog("GetDoctorInfo10");
            JSONObject result  = jwSmjkService.GetDoctorInfoTen(hospitalId,hosDeptId,doctorId);
            return result.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"获取失败");
        }
    }
    @RequestMapping(value = "GetDoctorArrange", method = RequestMethod.POST)
    @ApiOperation("获取医生排班接口(包含排班详细)")
    public String GetDoctorArrange(@ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211G1102")
                                   @RequestParam(value = "hospitalId", required = false) 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 {
            recordRequestLog("GetDoctorArrange");
            String list = jwSmjkService.GetDoctorArrange(hospitalId,hosDeptId,doctorId);
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"获取失败");
        }
    }
    @RequestMapping(value = "CreateOrder", method = RequestMethod.POST)
    @ApiOperation("创建挂号单")
    public Envelop CreateOrder(@ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211A1002")
                              @RequestParam(value = "hospitalId", required = false) String hospitalId,
                              @ApiParam(name = "hospitalName", value = "医院名称", defaultValue = "马銮湾医院")
                              @RequestParam(value = "hospitalName", required = false) 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 = "00258f46c4fe11ec8771005056ab2351")
                              @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 = "key", value = "验证码key")
                              @RequestParam(value = "key", required = true) String key,
                              @ApiParam(name = "text", value = "text")
                              @RequestParam(value = "text", required = true) String text
    ) {
        try{
            boolean pass = false;
            key = key.replaceFirst(":",":"+patient+"_");
            String captcha = redisTemplate.opsForValue().get(key);
            if (captcha != null && captcha.equals(text.toLowerCase())){
                pass = true;
                redisTemplate.delete(key);
            }
            if(!pass){
                return Envelop.getError("验证码校验失败");
            }
        } catch (Exception e){
            return failedException2(e);
        }
        try {
            recordRequestLog("CreateOrder");
            if (StringUtils.isEmpty(patientName)) {
                return Envelop.getError("未设置姓名!");
            }
            if (StringUtils.isEmpty(cardNo)) {
                return Envelop.getError("未设置身份证号!");
            }
            if (StringUtils.isEmpty(clinicCard)) {
                return Envelop.getError("未设置社保卡号!");
            }
            if (StringUtils.isEmpty(patientPhone)) {
                return Envelop.getError("未设置手机号码!");
            }
            String orderCode = jwSmjkService.CreateOrder(hospitalId,hospitalName,hosDeptId,hosDeptName,doctorId,doctorName,arrangeDate,patient,patientName,cardNo,clinicCard,patientPhone);
            //预约发送微信消息
            PatientReservation obj = patientReservationService.findByCode(orderCode);
            if (obj != null) {
                BasePatientDO p = patientDao.findById(obj.getPatient()).orElse(null);
//                if(StringUtils.isNotBlank(obj.getDoctor())){
//                    consultService.sendMucMessageBySingnType(obj.getDoctor(),obj.getDoctorName(),patient,"我已成功为您预约:" + DateUtil.dateToStrLong(obj.getStartTime()) + "," + hospitalName + hosDeptName + doctorName + "医生的号源。您可直接前往医院就诊</br><a name='guahao' href='javascript:void(0)' data-id='" + obj.getId() + "'>点击查看详情</a>","1",p.getName());
//                }
                WxTemplateConfigDO templateConfig = templateConfigDao.findByWechatIdAndTemplateNameAndScene(wechatId,"template_appoint_success","yyghcg");
                String remark = templateConfig.getRemark();
                String first = templateConfig.getFirst();
                first = first.replace("key1",p.getName());
                // 推送消息给微信端
                if(StringUtils.isNotBlank(p.getOpenid())){
                    // 添加到发送队列
                    WxTemplateConfigDO newConfig = new WxTemplateConfigDO();
                    BeanUtils.copyProperties(templateConfig, newConfig);
                    newConfig.setRemark(remark);
                    newConfig.setFirst(first);
                    newConfig.setKeyword1(DateUtil.dateToStrLong(obj.getStartTime()));
                    newConfig.setKeyword2((obj.getOrgName() + " " + obj.getDeptName()+ " " + obj.getDoctorName()));
                    wechatUtilService.putWxMsg(p.getOpenid(),newConfig);
                }
                //发送短信消息
                return ObjEnvelop.getSuccess( "创建挂号单成功!",obj.getId());
            } else {
                return Envelop.getError( "创建挂号单失败!");
            }
        } catch (ServiceException se) {
            return Envelop.getError(se.getMessage());
        } catch (Exception e) {
            return failedException2(e);
        }
    }
    @RequestMapping(value = "GetRegList", method = RequestMethod.POST)
    @ApiOperation("获取患者预约信息列表接口--患者端")
    public String GetRegList(@ApiParam(name = "patient", value = "患者编号", defaultValue = "00258f46c4fe11ec8771005056ab2351")
                             @RequestParam(value = "patient", required = false) String patient) {
        try {
            recordRequestLog("GetRegList");
            String list = jwSmjkService.GetRegList(patient);
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"获取失败");
        }
    }
}