|  | @ -1,6 +1,7 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.hospital.prescription.service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONPObject;
 | 
	
		
			
				|  |  | import com.fasterxml.jackson.databind.ObjectMapper;
 | 
	
		
			
				|  |  | import com.yihu.jw.dict.dao.DictDeptDescDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.dict.dao.DictHospitalDeptDao;
 | 
	
	
		
			
				|  | @ -82,7 +83,6 @@ import com.yihu.jw.utils.CheckSumBuilder;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.GenerateUserSig;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.Pkis.PKIService_PortType;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.Pkis.PKIService_ServiceLocator;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.StringUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.WebserviceUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.hibernate.HibenateUtils;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.dao.BasePatientWechatDao;
 | 
	
	
		
			
				|  | @ -106,7 +106,6 @@ import org.apache.commons.collections.map.HashedMap;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.apache.http.NameValuePair;
 | 
	
		
			
				|  |  | import org.apache.http.message.BasicNameValuePair;
 | 
	
		
			
				|  |  | import org.checkerframework.checker.units.qual.A;
 | 
	
		
			
				|  |  | import org.slf4j.Logger;
 | 
	
		
			
				|  |  | import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | import org.springframework.beans.BeanUtils;
 | 
	
	
		
			
				|  | @ -272,6 +271,8 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
 | 
	
		
			
				|  |  |     private HttpClientUtil httpClientUtil;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private YxTokenMappingDao yxTokenMappingDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseNatAppointmentDao baseNatAppointmentDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -4682,6 +4683,55 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     //核算检测预约模板消息
 | 
	
		
			
				|  |  |     public void sendNatWxTemplat(String name,String idcard,String mobile,String time,String orderNo,String relationName){
 | 
	
		
			
				|  |  |         String first = "";
 | 
	
		
			
				|  |  |         String contentMsg = "";
 | 
	
		
			
				|  |  |         String msgUrl="";
 | 
	
		
			
				|  |  |         String remark="";
 | 
	
		
			
				|  |  |         String responseMsg="";
 | 
	
		
			
				|  |  |         if ("natAppointmentRemind".equalsIgnoreCase(relationName)){
 | 
	
		
			
				|  |  |             first = "尊敬的用户"+name+",您已完成线上自助核酸检测开单预约";
 | 
	
		
			
				|  |  |             contentMsg = "申请人:"+name+";预约时间:"+time+";发票流水号:"+orderNo;
 | 
	
		
			
				|  |  |             remark="请您持核酸开单预约信息和结算发票号、医保卡、就诊卡、电子健康卡,提前15分钟至我院五号楼北侧(急诊部后侧)核酸检测点2号窗口绑定检测。";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if ("xm_zsyy_wx".equalsIgnoreCase(wechatId)) {
 | 
	
		
			
				|  |  |             String prefix = "https://hlwyy.xmzsh.com";
 | 
	
		
			
				|  |  |             responseMsg = entranceService.ehospitalNotice(
 | 
	
		
			
				|  |  |                     name,
 | 
	
		
			
				|  |  |                    idcard,
 | 
	
		
			
				|  |  |                     mobile,
 | 
	
		
			
				|  |  |                     first,
 | 
	
		
			
				|  |  |                     prefix + msgUrl,
 | 
	
		
			
				|  |  |                     contentMsg,
 | 
	
		
			
				|  |  |                     remark);
 | 
	
		
			
				|  |  |                 logger.info("中山发送模板消息返回结果="+responseMsg);
 | 
	
		
			
				|  |  |                 System.out.println("结束发送模板消息");
 | 
	
		
			
				|  |  |         }else if ("xm_zsyy_wx".equalsIgnoreCase(wechatId)) {
 | 
	
		
			
				|  |  |             String prefix = "https://hlwyy.xmzsh.com";
 | 
	
		
			
				|  |  |                 responseMsg = entranceService.ehospitalNotice(
 | 
	
		
			
				|  |  |                         name,
 | 
	
		
			
				|  |  |                         idcard,
 | 
	
		
			
				|  |  |                         mobile,
 | 
	
		
			
				|  |  |                         first,
 | 
	
		
			
				|  |  |                         prefix + msgUrl,
 | 
	
		
			
				|  |  |                         contentMsg,
 | 
	
		
			
				|  |  |                         remark
 | 
	
		
			
				|  |  |                 );
 | 
	
		
			
				|  |  |                 logger.info("心脏发送模板消息返回结果="+responseMsg);
 | 
	
		
			
				|  |  |                 System.out.println("结束发送模板消息");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //保存发送模板记录,
 | 
	
		
			
				|  |  |         WxPushLogDO wxPushLogDO = new WxPushLogDO();
 | 
	
		
			
				|  |  |         wxPushLogDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         wxPushLogDO.setWechatId(wechatId);
 | 
	
		
			
				|  |  |         wxPushLogDO.setReceiverName(name);
 | 
	
		
			
				|  |  |         wxPushLogDO.setRequest(first+contentMsg+msgUrl);
 | 
	
		
			
				|  |  |         wxPushLogDO.setResponse(responseMsg);
 | 
	
		
			
				|  |  |         wxPushLogDO.setTempName("核算检测预约模板消息");
 | 
	
		
			
				|  |  |         wxPushLogDao.save(wxPushLogDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<WlyyHospitalSysDictDO> findCancelReasonList() {
 | 
	
	
		
			
				|  | @ -5970,6 +6020,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
 | 
	
		
			
				|  |  |         rs.put("mobile", basePatientDO.getMobile());
 | 
	
		
			
				|  |  |         rs.put("photo", basePatientDO.getPhoto());
 | 
	
		
			
				|  |  |         rs.put("address", basePatientDO.getAddress());
 | 
	
		
			
				|  |  |         rs.put("cardType",basePatientDO.getCardType());
 | 
	
		
			
				|  |  |         if (patientMedicareCardDO != null) {
 | 
	
		
			
				|  |  |             rs.put("ssc", patientMedicareCardDO.getCode());
 | 
	
		
			
				|  |  |         } else {
 | 
	
	
		
			
				|  | @ -9278,6 +9329,32 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
 | 
	
		
			
				|  |  |         return MixEnvelop.getSuccess(IotRequestMapping.Common.message_success_find, object);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public MixEnvelop selectByUrlHsjc(Integer id,String wxId) throws Exception {
 | 
	
		
			
				|  |  |         WxWechatDO wxWechatDO = wechatDao.findById(wxId);
 | 
	
		
			
				|  |  |         if (wxWechatDO == null) {
 | 
	
		
			
				|  |  |             throw new Exception("微信配置不存在!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         BaseNatAppointmentDO natAppointmentDO = baseNatAppointmentDao.findOne(id);
 | 
	
		
			
				|  |  |         List<BasePatientWechatDo> patientWechatDos = patientWechatDao.findByWechatIdAndPatientId(wxId, natAppointmentDO.getPatientId());
 | 
	
		
			
				|  |  |         if (patientWechatDos == null || patientWechatDos.size() == 0) {
 | 
	
		
			
				|  |  |             throw new Exception("openid不存在!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         BasePatientWechatDo patientWechatDo = patientWechatDos.get(0);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String idcard = null;
 | 
	
		
			
				|  |  |         if (natAppointmentDO != null) {
 | 
	
		
			
				|  |  |             idcard = natAppointmentDO.getMedicare();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (!StringUtils.isNoneBlank(idcard)) {
 | 
	
		
			
				|  |  |             throw new Exception("就诊卡不存在!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String url = ylzPayService.createSicardPayUrl(wxWechatDO.getAppOriginId(), patientWechatDo.getOpenid(), idcard, "WX");
 | 
	
		
			
				|  |  |         com.alibaba.fastjson.JSONObject object = com.alibaba.fastjson.JSONObject.parseObject(url);
 | 
	
		
			
				|  |  |         return MixEnvelop.getSuccess(IotRequestMapping.Common.message_success_find, object);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取居民openId
 | 
	
		
			
				|  |  |      *
 | 
	
	
		
			
				|  | @ -10337,5 +10414,376 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |        return doorServiceCount;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     public MixEnvelop findJobCategory(){
 | 
	
		
			
				|  |  |         String sqlPid = "select id as \"id\",name as \"name\",pid as \"pid\" from base_job_category  where pid = 0 and del = 1";
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sqlPid);
 | 
	
		
			
				|  |  |         if (list.size()>0){
 | 
	
		
			
				|  |  |             for (Map<String,Object> map:list){
 | 
	
		
			
				|  |  |                 String child = "select id as \"id\",name as \"name\",pid as \"pid\" from base_job_category  where del = 1";
 | 
	
		
			
				|  |  |                 String pid = map.get("id").toString();
 | 
	
		
			
				|  |  |                 child+=" and pid = "+pid;
 | 
	
		
			
				|  |  |                 List<Map<String,Object>> childList = hibenateUtils.createSQLQuery(child);
 | 
	
		
			
				|  |  |                 map.put("childList",childList);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         MixEnvelop envelop = new MixEnvelop();
 | 
	
		
			
				|  |  |         envelop.setDetailModelList(list);
 | 
	
		
			
				|  |  |         return  envelop;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     public Map<String,Object> findRandomDoctor(){
 | 
	
		
			
				|  |  |         String sql = "select t.id as \"id\"," +
 | 
	
		
			
				|  |  |                 "t.doctor_mapping_code as \"doctorMappingCode\"," +
 | 
	
		
			
				|  |  |                 "t.doctor_code as \"doctorCode\"," +
 | 
	
		
			
				|  |  |                 "t.dept_code as \"deptCode\"," +
 | 
	
		
			
				|  |  |                 "t.start_time as \"startTime\"," +
 | 
	
		
			
				|  |  |                 "t.end_time as \"endTime\"," +
 | 
	
		
			
				|  |  |                 "t.doctor_name as \"doctorName\"," +
 | 
	
		
			
				|  |  |                 "t.dept_name  as \"deptName\" from base_doctor_time_mapping t where 1=1 ";
 | 
	
		
			
				|  |  |         if ("xm_ykyy_wx".equalsIgnoreCase(wechatId)){
 | 
	
		
			
				|  |  |             sql+=" order by dbms_random.value";
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             sql+=" ORDER BY RAND() ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql);
 | 
	
		
			
				|  |  |         if (list!=null&&list.size()>0){
 | 
	
		
			
				|  |  |             return list.get(0);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return null;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     public Map saveNatAppointment(String mediaCard,String patientId,String name,String cardNo,String cardType,String mobile,
 | 
	
		
			
				|  |  |                                    String firstJobCode,String firstJobName,String secondJobCode,String secondJobName,String natTime,String address,String provinceName,String cityName,String townName,String streetName) throws Exception {
 | 
	
		
			
				|  |  |         BaseNatAppointmentDO baseNatAppointmentDO= new BaseNatAppointmentDO();
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setMedicare(mediaCard);
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setName(name);
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setCardNo(cardNo);
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setCardType(cardType);
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setAddress(address);
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setAppointmentTime(DateUtil.strToDate(natTime,"yyyy-MM-dd hh:mm:ss"));
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setCityName(cityName);
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setFirstJobCode(firstJobCode);
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setFirstJobName(firstJobName);
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setSecondJobCode(secondJobCode);
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setSecondJobName(secondJobName);
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setProvinceName(provinceName);
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setTownName(townName);
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setStreetName(streetName);
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setPatientId(patientId);
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setIsSuccess("0");
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setPayStatus("0");
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setMobile(mobile);
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setInspectionCode("鼻/咽拭子");
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setInspectionName("鼻/咽拭子");
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setIcdCode("Z00.000");
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setChargeCode("361322");
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setWinNo("6");
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setDept("3150000");
 | 
	
		
			
				|  |  |         baseNatAppointmentDO.setDeptName("感染疾病科");
 | 
	
		
			
				|  |  |         baseNatAppointmentDO= baseNatAppointmentDao.save(baseNatAppointmentDO);
 | 
	
		
			
				|  |  |         Map returnMap = new HashMap();
 | 
	
		
			
				|  |  |         net.sf.json.JSONObject jsondate = new JSONObject();
 | 
	
		
			
				|  |  |         jsondate.put("checkPart","鼻/咽拭子");
 | 
	
		
			
				|  |  |         jsondate.put("cardNo",mediaCard);
 | 
	
		
			
				|  |  |         jsondate.put("chargeFlag","2");
 | 
	
		
			
				|  |  |         jsondate.put("chargeCode","361322");
 | 
	
		
			
				|  |  |         jsondate.put("icdCode","Z00.000");
 | 
	
		
			
				|  |  |         jsondate.put("socialNo",cardNo);
 | 
	
		
			
				|  |  |         jsondate.put("tellPhone",mobile);
 | 
	
		
			
				|  |  |         jsondate.put("address1",provinceName);
 | 
	
		
			
				|  |  |         jsondate.put("address2",cityName);
 | 
	
		
			
				|  |  |         jsondate.put("address3",townName);
 | 
	
		
			
				|  |  |         jsondate.put("address4",streetName);
 | 
	
		
			
				|  |  |         jsondate.put("address5",2);
 | 
	
		
			
				|  |  |         jsondate.put("area",address);
 | 
	
		
			
				|  |  |         jsondate.put("winNo",6);
 | 
	
		
			
				|  |  |         jsondate.put("target",2);
 | 
	
		
			
				|  |  |         jsondate.put("quantity",1);
 | 
	
		
			
				|  |  |         Map<String,Object> map = findRandomDoctor();
 | 
	
		
			
				|  |  |         net.sf.json.JSONObject rs = new JSONObject();
 | 
	
		
			
				|  |  |         if (map!=null){
 | 
	
		
			
				|  |  |             //先进行核算检测预约
 | 
	
		
			
				|  |  |             String result = entranceService.BS10144("3150000","0001",natTime,mediaCard,name,cardNo,mobile,demoFlag);
 | 
	
		
			
				|  |  |             com.alibaba.fastjson.JSONObject object = com.alibaba.fastjson.JSONObject.parseObject(result);
 | 
	
		
			
				|  |  |             logger.info("核酸检测预约结束"+result);
 | 
	
		
			
				|  |  |             Boolean flag = false;
 | 
	
		
			
				|  |  |             if (object!=null){
 | 
	
		
			
				|  |  |                 com.alibaba.fastjson.JSONObject jsonObject = object.getJSONObject("MsgInfo");
 | 
	
		
			
				|  |  |                 String Msg = jsonObject.getString("Msg");
 | 
	
		
			
				|  |  |                 if (Msg.contains("Error")){
 | 
	
		
			
				|  |  |                     throw new Exception(Msg);
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     flag = true;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (flag){
 | 
	
		
			
				|  |  |                 try {
 | 
	
		
			
				|  |  |                     logger.info("挂号开始");
 | 
	
		
			
				|  |  |                     String date = DateUtil.dateToStr(new Date(), "yyyy-MM-dd");
 | 
	
		
			
				|  |  |                     List<WlyyPatientRegisterDO> patientRegisterDOs = patientRegisterDao.findByPatientAndDateAndDoctorAndDel(patientId, date,map.get("doctorCode").toString() ,1);
 | 
	
		
			
				|  |  |                     if (patientRegisterDOs != null && patientRegisterDOs.size() > 0) {
 | 
	
		
			
				|  |  |                         WlyyPatientRegisterDO registerDO = patientRegisterDOs.get(0);
 | 
	
		
			
				|  |  |                         //判断是否已经挂号,如果已经挂号
 | 
	
		
			
				|  |  |                         if (StringUtils.isNotBlank(registerDO.getConNo()) && StringUtils.isNotBlank(registerDO.getRegisterNo())) {
 | 
	
		
			
				|  |  |                             net.sf.json.JSONObject res = new JSONObject();
 | 
	
		
			
				|  |  |                             res.put("@RESULT", "0");
 | 
	
		
			
				|  |  |                             logger.info("已经挂号 res: " + res.toString());
 | 
	
		
			
				|  |  |                             jsondate.put("serialNo",registerDO.getRegisterNo());
 | 
	
		
			
				|  |  |                             jsondate.put("dept",map.get("deptCode").toString());
 | 
	
		
			
				|  |  |                             jsondate.put("doctor",map.get("doctorMappingCode").toString());
 | 
	
		
			
				|  |  |                             baseNatAppointmentDO.setDoctorId(map.get("doctorMappingCode").toString());
 | 
	
		
			
				|  |  |                             baseNatAppointmentDO.setDoctorName(map.get("doctorName").toString());
 | 
	
		
			
				|  |  |                         }else {
 | 
	
		
			
				|  |  |                             returnMap.put("msg","已经挂号的数据有误");
 | 
	
		
			
				|  |  |                             returnMap.put("status","-1");
 | 
	
		
			
				|  |  |                             returnMap.put("id",baseNatAppointmentDO.getId());
 | 
	
		
			
				|  |  |                             return returnMap;
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }else {
 | 
	
		
			
				|  |  |                         rs = entranceService.BS10111(mediaCard, map.get("doctorMappingCode").toString(), map.get("deptCode").toString(), "31", "6", demoFlag);
 | 
	
		
			
				|  |  |                         net.sf.json.JSONObject res = rs.getJSONObject("resquest");
 | 
	
		
			
				|  |  |                         logger.info("挂号结果 res: " + res.toString());
 | 
	
		
			
				|  |  |                         String rsCode = res.getString("@RESULT");
 | 
	
		
			
				|  |  |                         if ("0".equals(rsCode)) {
 | 
	
		
			
				|  |  |                             //存储挂号号
 | 
	
		
			
				|  |  |                             // {"resquest":{"@RESULT":"0","@MSG":"完成","@serial_no":"47770476","@times":"28"}}
 | 
	
		
			
				|  |  |                             String serialNo = (String) res.get("@serial_no");
 | 
	
		
			
				|  |  |                             String conNo = (String) res.get("@times");
 | 
	
		
			
				|  |  |                             String xtgzh = (String) res.get("@xtgzh");
 | 
	
		
			
				|  |  |                             String realOrder = (String) res.get("@real_order");
 | 
	
		
			
				|  |  |                             logger.info("挂号流水 @serial_no: " + serialNo + " @times: " + conNo);
 | 
	
		
			
				|  |  |                             jsondate.put("serialNo",serialNo);
 | 
	
		
			
				|  |  |                             jsondate.put("dept",map.get("deptCode").toString());
 | 
	
		
			
				|  |  |                             jsondate.put("doctor",map.get("doctorMappingCode").toString());
 | 
	
		
			
				|  |  |                             //存储就诊记录
 | 
	
		
			
				|  |  |                             WlyyPatientRegisterDO registerDO = new WlyyPatientRegisterDO();
 | 
	
		
			
				|  |  |                             // 存储挂号医生与挂号科室
 | 
	
		
			
				|  |  |                             registerDO.setDoctor(map.get("doctorCode").toString());
 | 
	
		
			
				|  |  |                             registerDO.setDoctorName(map.get("doctorName").toString());
 | 
	
		
			
				|  |  |                             registerDO.setDept(map.get("deptCode").toString());
 | 
	
		
			
				|  |  |                             registerDO.setDeptName(map.get("deptName").toString());
 | 
	
		
			
				|  |  |                             registerDO.setRealOrder(realOrder);
 | 
	
		
			
				|  |  |                             registerDO.setXtgzh(xtgzh);
 | 
	
		
			
				|  |  |                             registerDO.setPatient(patientId);
 | 
	
		
			
				|  |  |                             registerDO.setPatientName(name);
 | 
	
		
			
				|  |  |                             //挂号流水号与挂号次数
 | 
	
		
			
				|  |  |                             registerDO.setRegisterNo(serialNo);
 | 
	
		
			
				|  |  |                             registerDO.setConNo(conNo);
 | 
	
		
			
				|  |  |                             registerDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                             registerDO.setDel(1);
 | 
	
		
			
				|  |  |                             registerDO.setDate(DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
 | 
	
		
			
				|  |  |                             patientRegisterDao.save(registerDO);
 | 
	
		
			
				|  |  |                             //保存日志
 | 
	
		
			
				|  |  |                             WlyyHttpLogDO log = new WlyyHttpLogDO();
 | 
	
		
			
				|  |  |                             log.setCode("registerOutPatient");
 | 
	
		
			
				|  |  |                             log.setName("挂号");
 | 
	
		
			
				|  |  |                             log.setPatient(patientId);
 | 
	
		
			
				|  |  |                             log.setDoctor(map.get("doctorCode").toString());
 | 
	
		
			
				|  |  |                             log.setResponse(rs.toString());
 | 
	
		
			
				|  |  |                             log.setStatus(rsCode);
 | 
	
		
			
				|  |  |                             log.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                             wlyyHttpLogDao.save(log);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         } else if ("-2".equals(rsCode)) {
 | 
	
		
			
				|  |  |                             String serialNo = (String) res.get("@serial_no");
 | 
	
		
			
				|  |  |                             String xtgzh = (String) res.get("@xtgzh");
 | 
	
		
			
				|  |  |                             String realOrder = (String) res.get("@real_order");
 | 
	
		
			
				|  |  |                             String conNo = (String) res.get("@times");
 | 
	
		
			
				|  |  |                             jsondate.put("serialNo",serialNo);
 | 
	
		
			
				|  |  |                             jsondate.put("dept",map.get("deptCode").toString());
 | 
	
		
			
				|  |  |                             jsondate.put("doctor",map.get("doctorMappingCode").toString());
 | 
	
		
			
				|  |  |                             logger.info("挂号流水 @serial_no: " + serialNo + " @times: " + conNo);
 | 
	
		
			
				|  |  |                             //存储就诊记录
 | 
	
		
			
				|  |  |                             WlyyPatientRegisterDO registerDO = new WlyyPatientRegisterDO();
 | 
	
		
			
				|  |  |                             registerDO.setDoctor(map.get("doctorCode").toString());
 | 
	
		
			
				|  |  |                             registerDO.setDoctorName(map.get("doctorName").toString());
 | 
	
		
			
				|  |  |                             registerDO.setDept(map.get("deptCode").toString());
 | 
	
		
			
				|  |  |                             registerDO.setDeptName(map.get("deptName").toString());
 | 
	
		
			
				|  |  |                             registerDO.setRealOrder(realOrder);
 | 
	
		
			
				|  |  |                             registerDO.setXtgzh(xtgzh);
 | 
	
		
			
				|  |  |                             registerDO.setPatient(patientId);
 | 
	
		
			
				|  |  |                             registerDO.setPatientName(name);
 | 
	
		
			
				|  |  |                             registerDO.setRegisterNo(serialNo);
 | 
	
		
			
				|  |  |                             registerDO.setConNo(conNo);
 | 
	
		
			
				|  |  |                             registerDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                             registerDO.setDate(DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                             patientRegisterDao.save(registerDO);
 | 
	
		
			
				|  |  |                             //保存日志
 | 
	
		
			
				|  |  |                             WlyyHttpLogDO log = new WlyyHttpLogDO();
 | 
	
		
			
				|  |  |                             log.setCode("registerOutPatient");
 | 
	
		
			
				|  |  |                             log.setName("挂号");
 | 
	
		
			
				|  |  |                             log.setPatient(patientId);
 | 
	
		
			
				|  |  |                             log.setDoctor(map.get("doctorCode").toString());
 | 
	
		
			
				|  |  |                             log.setResponse(rs.toString());
 | 
	
		
			
				|  |  |                             log.setStatus(rsCode);
 | 
	
		
			
				|  |  |                             log.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                             wlyyHttpLogDao.save(log);
 | 
	
		
			
				|  |  |                         }else {
 | 
	
		
			
				|  |  |                             returnMap.put("msg","请求挂号失败");
 | 
	
		
			
				|  |  |                             returnMap.put("status","-1");
 | 
	
		
			
				|  |  |                             returnMap.put("id",baseNatAppointmentDO.getId());
 | 
	
		
			
				|  |  |                             return returnMap;
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         baseNatAppointmentDO.setDoctorId(map.get("doctorMappingCode").toString());
 | 
	
		
			
				|  |  |                         baseNatAppointmentDO.setDoctorName(map.get("doctorName").toString());
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 } catch (Exception e) {
 | 
	
		
			
				|  |  |                     e.printStackTrace();
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 logger.info("开单开始");
 | 
	
		
			
				|  |  |                 logger.info("saveNatAppointment params:"+jsondate.toString());
 | 
	
		
			
				|  |  |                 com.alibaba.fastjson.JSONArray array = new com.alibaba.fastjson.JSONArray();
 | 
	
		
			
				|  |  |                 array.add(jsondate);
 | 
	
		
			
				|  |  |                 try {
 | 
	
		
			
				|  |  |                     JSONObject jsonObject  = entranceService.BS10112(array.toString(),demoFlag);
 | 
	
		
			
				|  |  |                     //判断返回结果
 | 
	
		
			
				|  |  |                     String prers = jsonObject.getString("@RESULT");
 | 
	
		
			
				|  |  |                     //保存日志
 | 
	
		
			
				|  |  |                     WlyyHttpLogDO log = new WlyyHttpLogDO();
 | 
	
		
			
				|  |  |                     log.setCode("saveNatAppointment");
 | 
	
		
			
				|  |  |                     log.setName("核酸检测开方");
 | 
	
		
			
				|  |  |                     log.setPatient(patientId);
 | 
	
		
			
				|  |  |                     log.setDoctor(map.get("doctorCode").toString());
 | 
	
		
			
				|  |  |                     log.setResponse(jsonObject.toString());
 | 
	
		
			
				|  |  |                     log.setRequest(jsondate.toString());
 | 
	
		
			
				|  |  |                     log.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                     wlyyHttpLogDao.save(log);
 | 
	
		
			
				|  |  |                     if ("0".equals(prers)) {
 | 
	
		
			
				|  |  |                         String realOrder = jsonObject.getString("@real_order");
 | 
	
		
			
				|  |  |                         baseNatAppointmentDO.setRealOrder(realOrder);
 | 
	
		
			
				|  |  |                         baseNatAppointmentDO.setIsSuccess("1");
 | 
	
		
			
				|  |  |                         baseNatAppointmentDao.save(baseNatAppointmentDO);
 | 
	
		
			
				|  |  |                         String recipeTime = DateUtil.dateToStr(new Date(), "yyyyMMddHHmmss");
 | 
	
		
			
				|  |  |                         String applyDepaName = map.get("deptName").toString();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         String voucherNo = jsonObject.getString("@xtgzh0");
 | 
	
		
			
				|  |  |                         String applyDoctorName = map.get("doctorName").toString();
 | 
	
		
			
				|  |  |                         BasePatientDO patientDO = basePatientDao.findById(patientId);
 | 
	
		
			
				|  |  |                         String userName = null;
 | 
	
		
			
				|  |  |                         String idcard = null;
 | 
	
		
			
				|  |  |                         if (patientDO != null) {
 | 
	
		
			
				|  |  |                             userName = patientDO.getName();
 | 
	
		
			
				|  |  |                             idcard = patientDO.getIdcard();
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         PatientMappingDO patientMappingDO = patientMappingDao.findByPatient(patientId);
 | 
	
		
			
				|  |  |                         String userNo = null;
 | 
	
		
			
				|  |  |                         if (patientMappingDO != null) {
 | 
	
		
			
				|  |  |                             userNo = patientMappingDO.getMappingCode();
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         logger.info("cardNo:" + cardNo);
 | 
	
		
			
				|  |  |                         JSONObject jsonObject1 =entranceService.BS15054(patientMappingDO.getMappingCode(),realOrder,demoFlag);
 | 
	
		
			
				|  |  |                         net.sf.json.JSONObject res = jsonObject1.getJSONObject("resquest");
 | 
	
		
			
				|  |  |                         logger.info("获取待结算数据 res: " + res.toString());
 | 
	
		
			
				|  |  |                         String rsCode = res.getString("@RESULT");
 | 
	
		
			
				|  |  |                         String free= "";
 | 
	
		
			
				|  |  |                         if ("0".equals(rsCode)) {
 | 
	
		
			
				|  |  |                             free = res.getString("@total_charge");
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         ylzPayService.msgPush("01", mediaCard, "01", patientDO.getMobile(), "00", userNo, userName, idcard, voucherNo, applyDepaName, applyDoctorName, recipeTime, free, "1");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         /*//成功后发送模板消息
 | 
	
		
			
				|  |  |                         sendNatWxTemplat(name,cardNo,mobile,natTime,realOrder,"natAppointmentRemind");*/
 | 
	
		
			
				|  |  |                     }else{
 | 
	
		
			
				|  |  |                         returnMap.put("msg","核酸检测开方失败");
 | 
	
		
			
				|  |  |                         returnMap.put("status","-1");
 | 
	
		
			
				|  |  |                         returnMap.put("id",baseNatAppointmentDO.getId());
 | 
	
		
			
				|  |  |                         return returnMap;
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 } catch (Exception e) {
 | 
	
		
			
				|  |  |                     e.printStackTrace();
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             returnMap.put("msg","预约成功");
 | 
	
		
			
				|  |  |             returnMap.put("status","200");
 | 
	
		
			
				|  |  |             returnMap.put("id",baseNatAppointmentDO.getId());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return returnMap;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     public MixEnvelop getNatRecords(String patientId,Integer page ,Integer pageSize){
 | 
	
		
			
				|  |  |         String sql = "select t.name as \"name\"," +
 | 
	
		
			
				|  |  |                 "t.card_no as \"cardNo\"," +
 | 
	
		
			
				|  |  |                 "t.card_type as \"cardType\"," +
 | 
	
		
			
				|  |  |                 "t.mobile as \"mobile\"," +
 | 
	
		
			
				|  |  |                 "t.inspection_name as \"inspectionName\"," +
 | 
	
		
			
				|  |  |                 "t.real_order as \"realOrder\"," +
 | 
	
		
			
				|  |  |                 "t.is_success as \"isSuccess\"," +
 | 
	
		
			
				|  |  |                 "t.create_time as \"createTime\"," +
 | 
	
		
			
				|  |  |                 "t.pay_status as \"payStatus\"," +
 | 
	
		
			
				|  |  |                 "t.id as \"id\"," +
 | 
	
		
			
				|  |  |                 "t.appointment_time as \"appointmentTime\" " +
 | 
	
		
			
				|  |  |                 " from base_nat_appointment t where 1=1 ";
 | 
	
		
			
				|  |  |         if (StringUtils.isNoneBlank(patientId)){
 | 
	
		
			
				|  |  |             sql+=" and t.patient_id ='"+patientId+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         List<Map<String ,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
 | 
	
		
			
				|  |  |         List<Map<String ,Object>> listCount = hibenateUtils.createSQLQuery(sql);
 | 
	
		
			
				|  |  |         MixEnvelop mixnvelop = new MixEnvelop();
 | 
	
		
			
				|  |  |         if (listCount!=null&&listCount.size()>0){
 | 
	
		
			
				|  |  |             mixnvelop.setCurrPage(page);
 | 
	
		
			
				|  |  |             mixnvelop.setPageSize(pageSize);
 | 
	
		
			
				|  |  |             mixnvelop.setTotalCount(listCount.size());
 | 
	
		
			
				|  |  |             mixnvelop.setDetailModelList(list);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return mixnvelop;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> findBaseAddress(String addressFlag,String parentName){
 | 
	
		
			
				|  |  |         String sql="";
 | 
	
		
			
				|  |  |         if ("1".equalsIgnoreCase(addressFlag)){
 | 
	
		
			
				|  |  |             sql+="select  t.province_name as \"provinceName\" from base_address_mapping t group by t.province_name ";
 | 
	
		
			
				|  |  |         }else if("2".equalsIgnoreCase(addressFlag)){
 | 
	
		
			
				|  |  |             sql+="select  t.city_name as \"cityName\" from base_address_mapping t where t.province_name ='"+parentName+"' and city_name <> '' and city_name is not null group by t.city_name ";
 | 
	
		
			
				|  |  |         }else if("3".equalsIgnoreCase(addressFlag)){
 | 
	
		
			
				|  |  |             sql+="select  t.town_name as \"townName\" from base_address_mapping t  where t.city_name ='"+parentName+"' and town_name <> '' and town_name is not null group by t.town_name";
 | 
	
		
			
				|  |  |         }else if("4".equalsIgnoreCase(addressFlag)){
 | 
	
		
			
				|  |  |             sql+="select  t.street_name as \"streetName\" from base_address_mapping t  where t.town_name ='"+parentName+"' and street_name <> '' and street_name is not null";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql);
 | 
	
		
			
				|  |  |         return list;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     //患者取消预约
 | 
	
		
			
				|  |  |     public String cancelNatAppointment (Integer id,String patientId ){
 | 
	
		
			
				|  |  |         BasePatientDO patientDO = basePatientDao.findById(patientId);
 | 
	
		
			
				|  |  |         String res = "";
 | 
	
		
			
				|  |  |         if (patientDO!=null){
 | 
	
		
			
				|  |  |             String patientCode = null;
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  |                 patientCode = patientMappingService.findHisPatNoByIdCard(patientDO.getIdcard());
 | 
	
		
			
				|  |  |                 BaseNatAppointmentDO baseNatAppointmentDO = baseNatAppointmentDao.findOne(id);
 | 
	
		
			
				|  |  |                 if (null!=baseNatAppointmentDO){
 | 
	
		
			
				|  |  |                     res = entranceService.BS10145("3150000","0001",DateUtil.dateToStr(baseNatAppointmentDO.getAppointmentTime(),"yyyy-MM-dd hh:mm:ss"),baseNatAppointmentDO.getMedicare(),baseNatAppointmentDO.getName(),baseNatAppointmentDO.getCardNo(),baseNatAppointmentDO.getMobile(),demoFlag);
 | 
	
		
			
				|  |  |                     logger.info("核酸检测预约取消"+res);
 | 
	
		
			
				|  |  |                     com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(res);
 | 
	
		
			
				|  |  |                     Boolean flag = false;
 | 
	
		
			
				|  |  |                     if (jsonObject!=null){
 | 
	
		
			
				|  |  |                         com.alibaba.fastjson.JSONObject object = jsonObject.getJSONObject("MsgInfo");
 | 
	
		
			
				|  |  |                         String Msg = object.getString("Msg");
 | 
	
		
			
				|  |  |                         if (Msg.contains("Error")){
 | 
	
		
			
				|  |  |                             throw new Exception(Msg);
 | 
	
		
			
				|  |  |                         }else {
 | 
	
		
			
				|  |  |                             baseNatAppointmentDO.setIsSuccess("-1");
 | 
	
		
			
				|  |  |                             baseNatAppointmentDO.setCancelReson("患者本人取消");
 | 
	
		
			
				|  |  |                             baseNatAppointmentDO.setCancelTime(new Date());
 | 
	
		
			
				|  |  |                             baseNatAppointmentDO.setCancelBy(patientId);
 | 
	
		
			
				|  |  |                             baseNatAppointmentDao.save(baseNatAppointmentDO);
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             } catch (Exception e) {
 | 
	
		
			
				|  |  |                 e.printStackTrace();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return res;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |