|  | @ -4,22 +4,21 @@ package com.yihu.jw.hospital.prescription.service;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | 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.ca.OauthCaConfigDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.httplog.WlyyHttpLogDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.mapping.PatientMappingDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.WlyyPatientRegisterDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionExpressageDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.httplog.dao.WlyyHttpLogDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.mapping.dao.DoctorMappingDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.mapping.dao.PatientMappingDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.OutpatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.PatientRegisterDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.PrescriptionDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.PrescriptionExpressageDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.service.entrance.XzzxEntranceService;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.IdCardUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.http.HttpClientUtil;
 | 
	
		
			
				|  |  | import com.yihu.mysql.query.BaseJpaService;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.slf4j.Logger;
 | 
	
	
		
			
				|  | @ -58,6 +57,21 @@ public class XzyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PrescriptionExpressageDao prescriptionExpressageDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private HttpClientUtil httpClientUtil;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private OauthCaConfigDao oauthCaConfigDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PrescriptionInfoDao infoDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PrescriptionDiagnosisDao diagnosisDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BasePatientDao patientDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoctorDao doctorDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PrescriptionEmrDao prescriptionEmrDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 挂号接口
 | 
	
	
		
			
				|  | @ -219,4 +233,164 @@ public class XzyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return  object;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 处方签名
 | 
	
		
			
				|  |  |      * @param prescriptionDO
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public void SOF_SignDataWithExtraInfo(WlyyPrescriptionDO prescriptionDO) throws Exception {
 | 
	
		
			
				|  |  |         WlyyOutpatientDO outpatientDO = outpatientDao.findById(prescriptionDO.getOutpatientId());
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionInfoDO> infoDOS = infoDao.findByPrescriptionId(prescriptionDO.getId(), 1);
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionDiagnosisDO> diagnosisDOS = diagnosisDao.findByPrescriptionId(prescriptionDO.getId(),1);
 | 
	
		
			
				|  |  |         JSONObject object = new JSONObject();
 | 
	
		
			
				|  |  |         object.put("infos",infoDOS);
 | 
	
		
			
				|  |  |         object.put("registerSn",outpatientDO.getRegisterNo());
 | 
	
		
			
				|  |  |         object.put("diagnosiss",diagnosisDOS);
 | 
	
		
			
				|  |  |         JSONObject jsonObject = computeDigestForAlg(object.toJSONString());
 | 
	
		
			
				|  |  |         String hashValue = null;
 | 
	
		
			
				|  |  |         String hashType = null;
 | 
	
		
			
				|  |  |         if (jsonObject.getString("status").equalsIgnoreCase("0")){
 | 
	
		
			
				|  |  |             JSONObject data = jsonObject.getJSONObject("data");
 | 
	
		
			
				|  |  |             hashValue= data.getString("hashValue");
 | 
	
		
			
				|  |  |             hashType = data.getString("hashType");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         BasePatientDO patientDO = patientDao.findById(outpatientDO.getPatient());
 | 
	
		
			
				|  |  |         BaseDoctorDO doctorDO = doctorDao.findById(outpatientDO.getDoctor());
 | 
	
		
			
				|  |  |         if (patientDO!=null&&doctorDO!=null){
 | 
	
		
			
				|  |  |             String patientName = patientDO.getName();
 | 
	
		
			
				|  |  |             Integer patientAge = IdCardUtil.getAgeForIdcard(patientDO.getIdcard());
 | 
	
		
			
				|  |  |             String patientSex = IdCardUtil.getSexForIdcard(patientDO.getIdcard());
 | 
	
		
			
				|  |  |             String recipeTime = DateUtil.dateToStrLong(prescriptionDO.getCreateTime());
 | 
	
		
			
				|  |  |             String openId = doctorDO.getOpenid();
 | 
	
		
			
				|  |  |             String idcard = patientDO.getIdcard();
 | 
	
		
			
				|  |  |             if (hashType!=null&&hashValue!=null){
 | 
	
		
			
				|  |  |                 JSONObject object1 = synRecipeInfo("2017070411003376","hash_004","2017070411003360",getCode(),patientName,patientAge.toString(),patientSex,"SF",recipeTime,hashValue,hashType,openId,idcard);
 | 
	
		
			
				|  |  |                 if (object1.getString("status").equalsIgnoreCase("0")){
 | 
	
		
			
				|  |  |                     logger.info("西药处方签名成功"+object1);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 处方签名
 | 
	
		
			
				|  |  |      * @param prescriptionDO
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public void SOF_SignDataWithExtraInfoEmr(WlyyPrescriptionDO prescriptionDO) throws Exception {
 | 
	
		
			
				|  |  |         WlyyOutpatientDO outpatientDO = outpatientDao.findById(prescriptionDO.getOutpatientId());
 | 
	
		
			
				|  |  |         WlyyPrescriptionEmrDO prescriptionEmrDO = prescriptionEmrDao.findEmrByPrescriptionId(prescriptionDO.getId());
 | 
	
		
			
				|  |  |         JSONObject object = new JSONObject();
 | 
	
		
			
				|  |  |         object.put("emr",prescriptionEmrDO);
 | 
	
		
			
				|  |  |         object.put("registerSn",outpatientDO.getRegisterNo());
 | 
	
		
			
				|  |  |         object.put("doctorName",outpatientDO.getDoctorName());
 | 
	
		
			
				|  |  |         object.put("patientName",outpatientDO.getPatientName());
 | 
	
		
			
				|  |  |         JSONObject jsonObject = computeDigestForAlg(object.toJSONString());
 | 
	
		
			
				|  |  |         String hashValue = null;
 | 
	
		
			
				|  |  |         String hashType = null;
 | 
	
		
			
				|  |  |         if (jsonObject.getString("status").equalsIgnoreCase("0")){
 | 
	
		
			
				|  |  |             JSONObject data = jsonObject.getJSONObject("data");
 | 
	
		
			
				|  |  |             hashValue= data.getString("hashValue");
 | 
	
		
			
				|  |  |             hashType = data.getString("hashType");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         BasePatientDO patientDO = patientDao.findById(outpatientDO.getPatient());
 | 
	
		
			
				|  |  |         BaseDoctorDO doctorDO = doctorDao.findById(outpatientDO.getDoctor());
 | 
	
		
			
				|  |  |         if (patientDO!=null&&doctorDO!=null){
 | 
	
		
			
				|  |  |             String patientName = patientDO.getName();
 | 
	
		
			
				|  |  |             Integer patientAge = IdCardUtil.getAgeForIdcard(patientDO.getIdcard());
 | 
	
		
			
				|  |  |             String patientSex = IdCardUtil.getSexForIdcard(patientDO.getIdcard());
 | 
	
		
			
				|  |  |             String recipeTime = DateUtil.dateToStrLong(prescriptionDO.getCreateTime());
 | 
	
		
			
				|  |  |             String openId = doctorDO.getOpenid();
 | 
	
		
			
				|  |  |             String idcard = patientDO.getIdcard();
 | 
	
		
			
				|  |  |             if (hashType!=null&&hashValue!=null){
 | 
	
		
			
				|  |  |                 JSONObject object1 = synRecipeInfo("2017070411003376","hash_002","2017070411003360",getCode(),patientName,patientAge.toString(),patientSex,"SF",recipeTime,hashValue,hashType,openId,idcard);
 | 
	
		
			
				|  |  |                 if (object1.getString("status").equalsIgnoreCase("0")){
 | 
	
		
			
				|  |  |                     logger.info("门诊病历签名成功"+object1);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 数据哈希计算接口
 | 
	
		
			
				|  |  |      * @param content
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject computeDigestForAlg(String content){
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             OauthCaConfigDO oauthCaConfigDO = oauthCaConfigDao.findOne("oauth_ca_config");
 | 
	
		
			
				|  |  |             String url = "";
 | 
	
		
			
				|  |  |             if (oauthCaConfigDO!=null){
 | 
	
		
			
				|  |  |                 url=oauthCaConfigDO.getUrl()+"/gateway/common/computeDigestForAlg";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             JSONObject object = new JSONObject();
 | 
	
		
			
				|  |  |             object.put("originData",content);
 | 
	
		
			
				|  |  |             String response = httpClientUtil.sendPost(url,object.toJSONString());
 | 
	
		
			
				|  |  |             logger.info("数据哈希计算接口 :"+response);
 | 
	
		
			
				|  |  |             return JSONObject.parseObject(response);
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return null;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /***
 | 
	
		
			
				|  |  |      * 数据签名接口
 | 
	
		
			
				|  |  |      * @param clientId 第三方厂商标识
 | 
	
		
			
				|  |  |      * @param templateId 模板ID签名数据摘要数据类型
 | 
	
		
			
				|  |  |      * @param clientSecret 第三方厂商秘钥
 | 
	
		
			
				|  |  |      * @param urId 签名流水ID
 | 
	
		
			
				|  |  |      * @param patientName 患者姓名
 | 
	
		
			
				|  |  |      * @param patientAge 患者年龄
 | 
	
		
			
				|  |  |      * @param patientSex 患者性别
 | 
	
		
			
				|  |  |      * @param patientCardType  证件类型
 | 
	
		
			
				|  |  |      * @param recipeTime 开具时间
 | 
	
		
			
				|  |  |      * @param hashValue Hash原文(从签名指纹接口结果中得到的)
 | 
	
		
			
				|  |  |      * @param hashType Hash算法(从签名指纹接口结果中得到的)
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject synRecipeInfo(String clientId,String templateId,String clientSecret,String urId,String patientName,String patientAge,String patientSex,String patientCardType,String recipeTime,String hashValue,String hashType,String openId,String patientCard){
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             OauthCaConfigDO oauthCaConfigDO = oauthCaConfigDao.findOne("oauth_ca_config");
 | 
	
		
			
				|  |  |             String url = "";
 | 
	
		
			
				|  |  |             if (oauthCaConfigDO!=null){
 | 
	
		
			
				|  |  |                 url=oauthCaConfigDO.getUrl()+"/gateway/recipe/synRecipeInfo";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             JSONObject object = new JSONObject();
 | 
	
		
			
				|  |  |             JSONObject msg = new JSONObject();
 | 
	
		
			
				|  |  |             JSONObject head = new JSONObject();
 | 
	
		
			
				|  |  |             head.put("clientId",clientId);
 | 
	
		
			
				|  |  |             head.put("templateId",templateId);
 | 
	
		
			
				|  |  |             head.put("clientSecret",clientSecret);
 | 
	
		
			
				|  |  |             head.put("selfSign",true);
 | 
	
		
			
				|  |  |             msg.put("head",head);
 | 
	
		
			
				|  |  |             JSONObject body = new JSONObject();
 | 
	
		
			
				|  |  |             body.put("urId",urId);
 | 
	
		
			
				|  |  |             body.put("patientName",patientName);
 | 
	
		
			
				|  |  |             body.put("patientAge",patientAge);
 | 
	
		
			
				|  |  |             body.put("patientSex",patientSex);
 | 
	
		
			
				|  |  |             body.put("patientCardType",patientCardType);
 | 
	
		
			
				|  |  |             body.put("recipeTime",recipeTime);
 | 
	
		
			
				|  |  |             body.put("hashValue",hashValue);
 | 
	
		
			
				|  |  |             body.put("hashType",hashType);
 | 
	
		
			
				|  |  |             body.put("patientCard",patientCard);
 | 
	
		
			
				|  |  |             body.put("openId",openId);
 | 
	
		
			
				|  |  |             msg.put("body",body);
 | 
	
		
			
				|  |  |             object.put("msg",msg);
 | 
	
		
			
				|  |  |             object.put("signType",4);
 | 
	
		
			
				|  |  |             logger.info("请求参数:"+object);
 | 
	
		
			
				|  |  |             String response = httpClientUtil.sendPost(url,object.toJSONString());
 | 
	
		
			
				|  |  |             logger.info("数据签名接口 :"+response);
 | 
	
		
			
				|  |  |             return JSONObject.parseObject(response);
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return null;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |