Explorar o código

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

LAPTOP-KB9HII50\70708 %!s(int64=2) %!d(string=hai) anos
pai
achega
ac14585cc2

+ 2165 - 0
business/base-service/src/main/java/com/yihu/jw/healthCare/service/HealthCareNewService.java

@ -0,0 +1,2165 @@
package com.yihu.jw.healthCare.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.entity.hospital.healthCare.*;
import com.yihu.jw.entity.hospital.httplog.YlzHttpLogDO;
import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
import com.yihu.jw.entity.hospital.mapping.PatientMappingDO;
import com.yihu.jw.entity.hospital.prescription.*;
import com.yihu.jw.healthCare.utils.AES;
import com.yihu.jw.healthCare.utils.SafeUtil;
import com.yihu.jw.healthCare.utils.YibaoJiaMi;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.hospital.healthCare.*;
import com.yihu.jw.hospital.httplog.dao.YlzHttpLogDao;
import com.yihu.jw.hospital.mapping.dao.DoctorMappingDao;
import com.yihu.jw.hospital.mapping.dao.PatientMappingDao;
import com.yihu.jw.hospital.prescription.dao.*;
import com.yihu.jw.hospital.prescription.service.entrance.EntranceService;
import com.yihu.jw.hospital.prescription.service.entrance.XzzxEntranceService;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.util.common.LatitudeUtils;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import net.sf.json.util.JSONTokener;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import javax.transaction.Transactional;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * 医保对接
 * Created by wangzhinan 20211002
 */
@Service
@Transactional
public class HealthCareNewService {
    private Logger logger = LoggerFactory.getLogger(HealthCareNewService.class);
    @Autowired
    private WlyyHospitalSysDictDao hospitalSysDictDao;
    @Autowired
    private BaseDoctorHospitalDao doctorHospitalDao;
    @Autowired
    private BaseDoctorDao doctorDao;
    @Autowired
    private BasePatientDao patientDao;
    @Autowired
    private OutpatientDao outpatientDao;
    @Autowired
    private DoctorMappingDao doctorMappingDao;
    @Autowired
    private PrescriptionExpressageDao prescriptionExpressageDao;
    @Autowired
    private PrescriptionDao prescriptionDao;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private YlzHttpLogDao ylzHttpLogDao;
    @Autowired
    private PatientMappingDao patientMappingDao;
    @Autowired
    private YlzMedicalPrescriptionUploadDao ylzMedicalPrescriptionUploadDao;
    @Autowired
    private PrescriptionInfoDao prescriptionInfoDao;
    @Autowired
    private YlzMedicailRelationDao ylzMedicailRelationDao;
    @Autowired
    private YlzMedicailBillDao ylzMedicailBillDao;
    @Autowired
    private YlzMedicailIcdDao ylzMedicailIcdDao;
    @Autowired
    private YlzMedicailMxDao ylzMedicailMxDao;
    @Autowired
    private XzzxEntranceService xzzxEntranceService;
    @Autowired
    private EntranceService entranceService;
    @Autowired
    private PrescriptionDiagnosisDao prescriptionDiagnosisDao;
    private String ylzConfigUrl;
    private String ylzConfigAppid;
    private String ylzConfigAppSecret;
    private String ylzConfigEncryptKey;
    private String ylzConfigSignKey;
    private String ylzConfigOrgCode;
    public static String entranceHealthCareUrl = "http://127.0.0.1:10023/healthCare/";
    public void initConfig() throws Exception{
        logger.info("初始话参数!");
        List<WlyyHospitalSysDictDO> hospitalSysDictDOS = hospitalSysDictDao.findByDictName("ylzConfig");
        if (hospitalSysDictDOS==null||hospitalSysDictDOS.size()==0){
            throw new Exception("尚未添加配置参数");
        }else {
            for (WlyyHospitalSysDictDO hospitalSysDictDO:hospitalSysDictDOS){
                if (hospitalSysDictDO.getId().equalsIgnoreCase("ylzConfigUrl")){
                    ylzConfigUrl = hospitalSysDictDO.getDictValue();
                }
                if (hospitalSysDictDO.getId().equalsIgnoreCase("ylzConfigAppid")){
                    ylzConfigAppid = hospitalSysDictDO.getDictValue();
                }
                if (hospitalSysDictDO.getId().equalsIgnoreCase("ylzConfigAppSecret")){
                    ylzConfigAppSecret = hospitalSysDictDO.getDictValue();
                }
                if (hospitalSysDictDO.getId().equalsIgnoreCase("ylzConfigEncryptKey")){
                    ylzConfigEncryptKey = hospitalSysDictDO.getDictValue();
                }
                if (hospitalSysDictDO.getId().equalsIgnoreCase("ylzConfigSignKey")){
                    ylzConfigSignKey = hospitalSysDictDO.getDictValue();
                }
                if (hospitalSysDictDO.getId().equalsIgnoreCase("ylzConfigOrgCode")){
                    ylzConfigOrgCode = hospitalSysDictDO.getDictValue();
                }
            }
        }
    }
    /**
     * 医保统一调用接口
     * @param data
     * @param funid
     * @param name
     * @return
     * @throws Exception
     */
    @org.springframework.transaction.annotation.Transactional(propagation= Propagation.NOT_SUPPORTED)
    public String requestYlz(JSONObject data,String funid,String name) throws Exception {
        String obj="";
        try {
            YlzHttpLogDO ylzHttpLogDO = new YlzHttpLogDO();
            initConfig();
            WlyyHospitalSysDictDO systemDict =  hospitalSysDictDao.findOneByDictNameAndDictCode("ylzConfig","testFlag");
            if (null!=systemDict&&"1".equalsIgnoreCase(systemDict.getDictValue())){//测试环境
                //N00.00.00.01接口外其他的接口在服务号前加个T就是测试
                funid ="N00.00.00.01".equalsIgnoreCase(funid)?funid:"T"+funid;
                System.out.println("funid="+funid);
            }
            JSONObject object = new JSONObject();
            object.put("sign_type","md5");
            object.put("appid",ylzConfigAppid);
            String accessToken = getYlzToken();
            if (accessToken==null){
                throw new Exception("token无效");
            }
            object.put("access_token",accessToken);
            object.put("funid",funid);
            data.put("appid",ylzConfigAppid);
            data.put("org_code",ylzConfigOrgCode);
            object.put("data",data);
            String signResult = SafeUtil.sign(object.toJSONString(),ylzConfigSignKey);
            obj = SafeUtil.encrypt(signResult,ylzConfigEncryptKey);
            JSONObject jsonObject = JSONObject.parseObject(obj);
            logger.info("请求前funid=="+funid+"data="+data.toJSONString());
            String response = httpClientUtil.postBody(ylzConfigUrl,jsonObject);
            ylzHttpLogDO.setResponseEncrpty(response);
            if (response!=null&&response!=""){
                JSONObject result = JSONObject.parseObject(response);
                if (result.getString("flag").equalsIgnoreCase("1")){
                    String dataResult = result.getString("encrypt_data");
                    result.remove("encrypt_data");
                    if (dataResult!=null&&dataResult!=""){
                        String decryptResult = AES.aesDecrypt(dataResult,ylzConfigEncryptKey);
                        JSONObject dataObject = JSONObject.parseObject(decryptResult);
                        result.put("encrypt_data",dataObject);
                        response = result.toJSONString();
                    }
                }
            }
            ylzHttpLogDO.setCode(funid);
            ylzHttpLogDO.setName(name);
            ylzHttpLogDO.setRequest(data.toJSONString());
            ylzHttpLogDO.setRequestEncrpty(obj);
            ylzHttpLogDO.setResponse(response);
            ylzHttpLogDO.setCreateTime(new Date());
            ylzHttpLogDao.save(ylzHttpLogDO);
            return response;
        }catch (Exception e){
            e.printStackTrace();
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            String error = sw.toString();
            YlzHttpLogDO ylzHttpLogDO = new YlzHttpLogDO();
            ylzHttpLogDO.setCode(funid);
            ylzHttpLogDO.setName(name);
            ylzHttpLogDO.setRequest(data.toJSONString());
            ylzHttpLogDO.setRequestEncrpty(obj);
            ylzHttpLogDO.setResponse(error);
            ylzHttpLogDO.setCreateTime(new Date());
            ylzHttpLogDao.save(ylzHttpLogDO);
            return null;
        }
    }
    /**
     * 获取token
     * @return
     * @throws Exception
     */
    /**
     * 2.3.1	医师身份验证(处方权,多点执业等)
     */
    public String doctorAuthentication(String doctorId){
        try {
            BaseDoctorDO doctorDO = doctorDao.findOne(doctorId);
            if (doctorDO == null){
                throw new Exception("医生不存在");
            }
            List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDoctorCode(doctorId);
            if(doctorHospitalDOS.size()<=0){
                throw new Exception("未找到医生科室编码");
            }
            BaseDoctorHospitalDO doctorHospitalDO = doctorHospitalDOS.get(0);
            JSONObject data = new JSONObject();
            data.put("his_dept_code",doctorHospitalDO.getDeptCode());//his内部科室编码
            data.put("his_dept_name",doctorHospitalDO.getDeptName());//his内部科室名称
//        data.put("dept_code","");//医保科室编码	String	N
//        data.put("dept_name","");//医保科室名称	String	N
            data.put("medical_mode","10");//医疗就诊方式	10	门(急)诊
            data.put("name",doctorDO.getName());//医师姓名
            data.put("idcard",doctorDO.getIdcard());//医师证件号
            data.put("cert_type","01");//医师证件类型
            String result = requestYlz(data,"N20.17.02.01","医师身份验证");
            if(result == null){
                throw new Exception("医保请求失败");
            }
            logger.info("医师身份验证:"+result);
            JSONObject object = JSONObject.parseObject(result);
            if (object.getString("flag").equalsIgnoreCase("1")){
                JSONObject encryptData = object.getJSONObject("encrypt_data");
                return encryptData.getString("is_prescribe");
            }else {
                return "0";
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return "0";
    }
    /**
     * 2.3.2	医师人脸签到表单地址
     * @param doctorId
     * @throws Exception
     */
    public String doctorFaceCheckInAddress(String doctorId)throws Exception{
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findOne("ylzConfigFaceReturnUrl");
        if(hospitalSysDictDO == null){
            throw new Exception("未配置回调地址");
        }
        BaseDoctorDO doctorDO = doctorDao.findOne(doctorId);
        if (doctorDO == null){
            throw new Exception("医生不存在");
        }
        JSONObject data = new JSONObject();
        data.put("name",doctorDO.getName());//医师姓名
        data.put("idcard",doctorDO.getIdcard());//医师证件号
        data.put("cert_type","01");//医师证件类型
        data.put("redirect_url",hospitalSysDictDO.getDictValue());//回调地址
        String result = requestYlz(data,"N20.17.02.02","医师人脸签到表单地址");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("医师人脸签到表单地址:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            return encryptData.toJSONString();
        }
        return result;
    }
    /**
     * 2.3.3	获取医师人脸签到数据
     */
    public String doctorFaceCheckInData(String doctorId)throws Exception{
        BaseDoctorDO doctorDO = doctorDao.findOne(doctorId);
        if (doctorDO == null){
            throw new Exception("医生不存在");
        }
        JSONObject data = new JSONObject();
        data.put("name",doctorDO.getName());//医师姓名
        data.put("idcard",doctorDO.getIdcard());//医师证件号
        data.put("cert_type","01");//医师证件类型
        String result = requestYlz(data,"N20.17.02.05","获取医师人脸签到数据");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("获取医师人脸签到数据:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            return encryptData.toJSONString();
        }
        return result;
    }
    /**
     * 2.3.4	医师人脸签到微信小程序二维码(N20.17.02.06)
     * @param doctorId
     * @throws Exception
     */
    public String doctorFaceCheckInAddressBase64(String doctorId)throws Exception{
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findOne("ylzConfigFaceReturnUrl");
        if(hospitalSysDictDO == null){
            throw new Exception("未配置回调地址");
        }
        BaseDoctorDO doctorDO = doctorDao.findOne(doctorId);
        if (doctorDO == null){
            throw new Exception("医生不存在");
        }
        JSONObject data = new JSONObject();
        data.put("name",doctorDO.getName());//医师姓名
        data.put("idcard",doctorDO.getIdcard());//医师证件号
        data.put("cert_type","01");//医师证件类型
        data.put("redirect_url",hospitalSysDictDO.getDictValue());//回调地址
        String result = requestYlz(data,"N20.17.02.06","2.3.3\t获取医师人脸签到数据");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("医师人脸签到表单地址:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            return encryptData.toJSONString();
        }
        return result;
    }
    /**
     * 2.4.1 事前提醒
     */
    public String advanceWarning(String prescriptionId){
        try {
            WlyyPrescriptionDO wlyyPrescriptionDO = prescriptionDao.findOne(prescriptionId);
            if (wlyyPrescriptionDO == null){
                throw new Exception("续方信息不存在");
            }
            WlyyOutpatientDO outpatientDO = outpatientDao.findOne(wlyyPrescriptionDO.getOutpatientId());
            if (outpatientDO == null){
                throw new Exception("门诊信息不存在");
            }
            WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("ylzConfigOrgCode");
            if(hospitalSysDictDO == null){
                throw new Exception("未配置网点编号");
            }
            String icCardNo = outpatientDO.getCardNo();
            String his_serial = outpatientDO.getRegisterNo();
            String org_code = hospitalSysDictDO.getDictCode();
            JSONObject data;
            //获取his处方信息
            String infoResponse = xzzxEntranceService.presUpload(icCardNo,his_serial,org_code);
            JSONObject infoObject = JSONObject.parseObject(infoResponse);
            if("0".equals(infoObject.getString("ret_code"))){
                data = infoObject;
            }else {
                throw new Exception("获取his处方信息失败:"+infoObject.getString("ret_mess"));
            }
            data.remove("ret_code");
            data.remove("ret_mess");
            data.remove("log_no");
            data.put("ticket_no",outpatientDO.getXtgzh());//	单据流水号
            String result = requestYlz(data,"N20.17.03.03","事前提醒");
            if(result == null){
                throw new Exception("医保请求失败");
            }
            logger.info("事前提醒:"+result);
            JSONObject object = JSONObject.parseObject(result);
            if (object.getString("flag").equalsIgnoreCase("1")){
                JSONObject encryptData = object.getJSONObject("encrypt_data");
                return encryptData.toJSONString();
            }
            return result;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 2.4.2	医师开方上传
     */
    public String doctorPrescriptionUpload(String prescriptionId,String wxId) throws Exception{
        WlyyPrescriptionDO wlyyPrescriptionDO = prescriptionDao.findOne(prescriptionId);
        if (wlyyPrescriptionDO == null){
            throw new Exception("续方信息不存在");
        }
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(wlyyPrescriptionDO.getOutpatientId());
        if (outpatientDO == null){
            throw new Exception("门诊信息不存在");
        }
        BaseDoctorDO baseDoctorDO = doctorDao.findById(outpatientDO.getDoctor());
        DoctorMappingDO doctorMappingDO = doctorMappingDao.findByDoctor(outpatientDO.getDoctor());
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("ylzConfigOrgCode");
        if(hospitalSysDictDO == null){
            throw new Exception("未配置网点编号");
        }
        String icCardNo = outpatientDO.getCardNo();
        String his_serial = outpatientDO.getRegisterNo();
        String org_code = hospitalSysDictDO.getDictCode();
        JSONObject data = new JSONObject();
        if (StringUtils.isNoneBlank(wxId)){
            if (wxId.equalsIgnoreCase("xm_xzzx_wx")){
                //获取his处方信息
                JSONObject infoObject= xzzxEntranceService.presUploadToEntrance(icCardNo,his_serial,org_code);
                JSONObject info = infoObject.getJSONArray("data").getJSONObject(0);
                if("0".equals(info.getString("ret_code"))){
                    data = info;
                }else {
                    throw new Exception("获取his处方信息失败:"+infoObject.getString("ret_mess"));
                }
                data.remove("ret_code");
                data.remove("ret_mess");
                data.remove("log_no");
                data.put("order_id",prescriptionId);
            }else if(wxId.equalsIgnoreCase("xm_zsyy_wx")){
                net.sf.json.JSONArray result = entranceService.BS10108(outpatientDO.getCardNo(),outpatientDO.getIdcard(),null,null,null,null,his_serial,false);
                if (result!=null&&result.size()!=0){
                    net.sf.json.JSONObject object = result.getJSONObject(0);
                    net.sf.json.JSONObject jsonObject = object.getJSONObject("retInfo");
                    net.sf.json.JSONObject msgInfoJson = object.getJSONObject("msgInfo");
                    if (jsonObject.getString("retCode").equalsIgnoreCase("00")){
                        if (msgInfoJson!=null){
                            net.sf.json.JSONObject resultJSON = msgInfoJson.getJSONObject("receipt");
                            if (resultJSON!=null){
                                data.put("name",resultJSON.getString("xming0"));
                                data.put("cert_type","01");
                                data.put("region_code","3502");
                                data.put("order_id",resultJSON.getString("xtgzh0"));
                                data.put("medical_mode","10");
                                data.put("prescription_code",resultJSON.getString("xtgzh0"));
                                data.put("idcard",resultJSON.getString("id0000"));
                                data.put("cert_type","01");
                                data.put("sex",resultJSON.getString("brnl00"));
                                data.put("birth", com.yihu.jw.util.idcard.IdCardUtil.getBirthdayForIdcardStr(resultJSON.getString("id0000")));
                                data.put("phone",outpatientDO.getMobile());
                                data.put("medical_type","11");
                                data.put("medical_type_name","普通门诊");
                                data.put("medical_time",DateUtil.dateToStrLong(outpatientDO.getCreateTime()));
                                data.put("disease_code",outpatientDO.getIcd10());
                                data.put("dept_code",outpatientDO.getDept());
                                data.put("dept_name",outpatientDO.getDeptName());
                                data.put("doctor_idcard",baseDoctorDO.getIdcard());
                                data.put("doctor_code",doctorMappingDO.getMappingCode());
                                data.put("doctor_name",baseDoctorDO.getName());
                                data.put("prescription_date",DateUtil.dateToStrLong(wlyyPrescriptionDO.getCreateTime()));
                                data.put("prescription_counts",resultJSON.getString("cfxms0"));
                                data.put("prescription_source",0);
                                List<WlyyPrescriptionDiagnosisDO> diagnosisDOList = prescriptionDiagnosisDao.findByPrescriptionId(prescriptionId,1);
                                JSONArray diagnosisArray = new JSONArray();
                                for (WlyyPrescriptionDiagnosisDO diagnosisDO:diagnosisDOList){
                                    JSONObject diagnosisObj = new JSONObject();
                                    diagnosisObj.put("disease_code_icd10",diagnosisDO.getCode());
                                    diagnosisObj.put("disease_name_icd10",diagnosisDO.getName());
                                    diagnosisObj.put("disease_type","01");
                                    diagnosisObj.put("disease_order","01");
                                    diagnosisArray.add(diagnosisObj);
                                }
                                data.put("zdlist",diagnosisArray);
                                JSONArray infoList = new JSONArray();
                                Object json = new JSONTokener(resultJSON.getString("mxlists")).nextValue();
                                if(json instanceof JSONObject){
                                    JSONObject mxListJSON = (JSONObject)json;
                                    JSONObject mxlistObj = mxListJSON.getJSONObject("mxlist");
                                    JSONObject infoJson = new JSONObject();
                                    infoJson.put("his_item_name",mxlistObj.getString("xmmc00"));
                                    infoJson.put("his_item_code",mxlistObj.getString("xmbh00"));
                                    infoJson.put("item_name",mxlistObj.getString("xmmc00"));
                                    infoJson.put("item_code",mxlistObj.getString("xmbh00"));
                                    infoJson.put("his_drug_no",mxlistObj.getString("xmbh00"));
                                    infoJson.put("his_detail_sn",mxlistObj.getString("cfhao0"));
                                    infoJson.put("invoice_type","01");
                                    infoJson.put("specification_type",mxlistObj.getString("xmgg00"));
                                    infoJson.put("dosage_form",mxlistObj.getString("jx0000"));
                                    infoJson.put("charge_unit",mxlistObj.getString("xmdw00"));
                                    infoJson.put("price",mxlistObj.getString("xmdj00"));
                                    infoJson.put("amount",mxlistObj.getString("xmsl00"));
                                    infoJson.put("total_money",mxlistObj.getString("xmje00"));
                                    infoJson.put("single_dose",mxlistObj.getString("dcyydw"));
                                    infoJson.put("use_frequency",mxlistObj.getString("yppl00"));
                                    infoJson.put("medical_way",mxlistObj.getString("gytj00"));
                                    infoJson.put("prescription_date",mxlistObj.getString("jzrq"));
                                    infoJson.put("medication_days",mxlistObj.getString("ylts00"));
                                    infoJson.put("his_dept_code",outpatientDO.getDept());
                                    infoJson.put("his_dept_name",outpatientDO.getDeptName());
                                    infoJson.put("limit_type",mxlistObj.getString("sfybxm"));
                                    infoList.add(infoJson);
                                }else if (json instanceof JSONArray){
                                    JSONArray mxListArray = (JSONArray)json;
                                    for (int j=0;j<mxListArray.size();j++){
                                        JSONObject mxlistObj = mxListArray.getJSONObject(j);
                                        JSONObject infoJson = new JSONObject();
                                        infoJson.put("his_item_name",mxlistObj.getString("xmmc00"));
                                        infoJson.put("his_item_code",mxlistObj.getString("xmbh00"));
                                        infoJson.put("item_name",mxlistObj.getString("xmmc00"));
                                        infoJson.put("item_code",mxlistObj.getString("xmbh00"));
                                        infoJson.put("his_drug_no",mxlistObj.getString("xmbh00"));
                                        infoJson.put("his_detail_sn",mxlistObj.getString("cfhao0"));
                                        infoJson.put("invoice_type","01");
                                        infoJson.put("specification_type",mxlistObj.getString("xmgg00"));
                                        infoJson.put("dosage_form",mxlistObj.getString("jx0000"));
                                        infoJson.put("charge_unit",mxlistObj.getString("xmdw00"));
                                        infoJson.put("price",mxlistObj.getString("xmdj00"));
                                        infoJson.put("amount",mxlistObj.getString("xmsl00"));
                                        infoJson.put("total_money",mxlistObj.getString("xmje00"));
                                        infoJson.put("single_dose",mxlistObj.getString("dcyydw"));
                                        infoJson.put("use_frequency",mxlistObj.getString("yppl00"));
                                        infoJson.put("medical_way",mxlistObj.getString("gytj00"));
                                        infoJson.put("prescription_date",mxlistObj.getString("jzrq"));
                                        infoJson.put("medication_days",mxlistObj.getString("ylts00"));
                                        infoJson.put("his_dept_code",outpatientDO.getDept());
                                        infoJson.put("his_dept_name",outpatientDO.getDeptName());
                                        infoJson.put("limit_type",mxlistObj.getString("sfybxm"));
                                        infoList.add(infoJson);
                                    }
                                }
                                data.put("mxlist",infoList);
                            }
                        }
                    }
                }
            }
        }
        YlzMedicalPrescriptionUploadDO uploadDO = new YlzMedicalPrescriptionUploadDO();
        uploadDO.setOrgCode(org_code);
        uploadDO.setIcCardNo(icCardNo);
        uploadDO.setHisSerial(his_serial);
        uploadDO.setOutpatientId(wlyyPrescriptionDO.getOutpatientId());
        uploadDO.setPrescriptionId(prescriptionId);
        uploadDO.setRegionCode(data.getString("region_code"));
        uploadDO.setName(data.getString("name"));
        uploadDO.setIdcard(outpatientDO.getIdcard());
        uploadDO.setCertType(data.getString("cert_type"));
        uploadDO.setDataSource("53");//53移动支付
        uploadDO.setInsuranceSerial(data.getString("insurance_serial"));
        String result = requestYlz(data,"N20.17.03.01","医师开方上传");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("医师开方上传:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            uploadDO.setTransactionNo(encryptData.getString("transaction_no"));
            ylzMedicalPrescriptionUploadDao.save(uploadDO);
            return encryptData.toJSONString();
        }
        return result;
    }
    /**
     * 2.4.2	医师开方上传
     *
     * @param prescriptionId
     * @return
     * @throws Exception
     */
    public String doctorPrescriptionUploadEntrance(String prescriptionId) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"doctorPrescriptionUpload?prescriptionId="+prescriptionId;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.4.3	医师开方上传取消(N20.17.03.06)
     */
    public String doctorPrescriptionUploadCancle(String prescriptionId,String cancelReason)throws Exception{
        YlzMedicalPrescriptionUploadDO uploadDO = ylzMedicalPrescriptionUploadDao.findByPrescriptionId(prescriptionId);
        if(uploadDO == null){
            throw new Exception("未找到开发上传记录");
        }
        JSONObject data = new JSONObject();
        data.put("transaction_no",uploadDO.getTransactionNo());//处方上传流水号  	String	Y
        data.put("insurance_serial",uploadDO.getInsuranceSerial());//医保流水号
        data.put("cancel_reason",cancelReason);//作废原因
        data.put("region_code",uploadDO.getRegionCode());//参保地区划代码
        data.put("idcard",uploadDO.getIdcard());//证件号码
        data.put("name",uploadDO.getName());//姓名
        data.put("cert_type",uploadDO.getCertType());//证件类型
        data.put("data_source",uploadDO.getDataSource());//数据来源	String	Y	参见编码附件
        String result = requestYlz(data,"N20.17.03.06","医师开方上传取消");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("医师开方上传取消:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            return encryptData.toJSONString();
        }
        return result;
    }
    /**
     * 2.4.3	医师开方上传取消(N20.17.03.06)
     *
     * @param prescriptionId
     * @return
     * @throws Exception
     */
    public String doctorPrescriptionUploadCancleEntrance(String prescriptionId,String cancelReason) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"doctorPrescriptionUploadCancle?prescriptionId="+prescriptionId+"&cancelReason"+cancelReason;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.6.1	电子处方订单接收(N20.17.05.02)
     */
    public String electronicPrescriptionReceiving(String outpatientId)throws Exception{
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(outpatientId);
        if (outpatientDO == null){
            throw new Exception("门诊信息不存在");
        }
        List<WlyyPrescriptionExpressageDO> expressageDOList = prescriptionExpressageDao.findByOutpatientId(outpatientId);
        if(expressageDOList.size()==0){
            throw new Exception("收获信息不存在");
        }
        BasePatientDO patientDO = patientDao.findById(outpatientDO.getPatient());
        if(patientDO==null){
            throw new Exception("居民信息不存在");
        }
        WlyyPrescriptionExpressageDO expressageDO = expressageDOList.get(0);
        logger.info("电子处方订单接收:1");
        List<YlzMedicalRelationDO> ylzMedicalRelationDOList = ylzMedicailRelationDao.findByOutpatientStatus(outpatientId);
        for (YlzMedicalRelationDO ylzMedicalRelationDO:ylzMedicalRelationDOList){
            logger.info("电子处方订单接收:2");
            JSONObject data = new JSONObject();
            data.put("order_time",DateUtil.dateToStrLong(expressageDO.getCreateTime()));//订单时间
            List<WlyyPrescriptionDO> wlyyPrescriptionDOS = prescriptionDao.findByRealOrderList(ylzMedicalRelationDO.getLogNo());
            if(wlyyPrescriptionDOS.size()==0){
                throw new Exception("处方信息不存在");
            }
            data.put("order_code",ylzMedicalRelationDO.getLogNo());//订单号
            WlyyPrescriptionDO wlyyPrescriptionDO = wlyyPrescriptionDOS.get(0);
            data.put("prescription_code",wlyyPrescriptionDO.getRealOrder());//医院处方编号
            data.put("channel","1");//1、微信公众号,2、app,3、web
            data.put("insurance_ticket_no",ylzMedicalRelationDO.getBillSerial());//医保收费单据号	String	N	订单结算后的收费单据号
            String order_state = "";
            if (wlyyPrescriptionDO.getStatus()==30){
                order_state = "1";
            }else if (wlyyPrescriptionDO.getStatus()==31){
                order_state = "2";
            }else if (wlyyPrescriptionDO.getStatus()==100){
                order_state = "3";
            }
            logger.info("电子处方订单接收:3"+order_state);
            data.put("order_state",order_state);//订单状态    --1待发货、2配送中、3已签收、4已取消	String	Y
            data.put("order_addr_detail",expressageDO.getProvinceName()+expressageDO.getCityName()+expressageDO.getTownName()+expressageDO.getStreetName()+expressageDO.getAddress());//订单详细地址
            data.put("order_owner",expressageDO.getName());
            data.put("order_owner_idcard",patientDO.getIdcard());
            data.put("order_owner_phone",patientDO.getMobile());
            Map<String,String> map = LatitudeUtils.getGeocoderLatitude(expressageDO.getProvinceName()+expressageDO.getCityName()+expressageDO.getTownName()+expressageDO.getStreetName()+expressageDO.getAddress());
            data.put("addr_lat",map.get("lat"));//收货地址纬度
            data.put("addr_lng",map.get("lng"));//收货地址经度
            if(expressageDO.getOneselfPickupFlg()==1){
                //自取
                data.put("delivery_way","2");//1.网订配送,2.网订自取
                data.put("qrcode_check_time","");//扫码校验时间
                data.put("receiving_time","");//药品签收时间
            }else {
                //非自取
                data.put("delivery_way","1");//配送方式 1.网订配送,2.网订自取
                data.put("delivery_number",expressageDO.getMailno());//配送单号
                data.put("delivery_org","顺丰");//配送单位
                data.put("delivery_take_time",DateUtil.dateToStrLong(wlyyPrescriptionDO.getPayTime()));//配送接单时间
                data.put("delivery_name","顺丰");//配送人姓名
                data.put("delivery_id_card","顺丰");//配送人身份证
//            data.put("delivery_phone","");//配送人联系电话 N
                data.put("getmedical_time",DateUtil.dateToStrLong(wlyyPrescriptionDO.getPayTime()));//骑手取药记录
                data.put("delivery_money","");//配送费
            }
//        apothecary_name	药师姓名	String	N
//        apothecary_id_card	药师身份证	String	N
//        apothecary_audit	药师审核时间	String	N
            data.put("money",ylzMedicalRelationDO.getTotalAmount());//商品金额
            data.put("settlement_time",DateUtil.dateToStrLong(ylzMedicalRelationDO.getPayDate()));//结算时间
            data.put("data_source",ylzMedicalRelationDO.getDataSource());//数据来源
            data.put("delivery_time",DateUtil.dateToStrLong(wlyyPrescriptionDO.getPayTime()));//发单时间
            data.put("elec_prescription_code",wlyyPrescriptionDO.getId());//平台处方编号
            data.put("prescription_code",wlyyPrescriptionDO.getRealOrder());//医院处方编号
//        data.put("insurance_serial",outpatientDO.getInsuranceSerial());//医保门诊流水号
            data.put("his_serial",ylzMedicalRelationDO.getHisSerial());//门诊业务流水号
            JSONArray array = new JSONArray();
            List<YlzMedicalMxDO> ylzMedicalMxDOS = ylzMedicailMxDao.findByMedicalId(ylzMedicalRelationDO.getId());
            for (YlzMedicalMxDO ylzMedicalMxDO:ylzMedicalMxDOS){
                JSONObject object = new JSONObject();
                object.put("order_id",ylzMedicalRelationDO.getLogNo());
                object.put("settlement_no",ylzMedicalRelationDO.getHisBillSerial());
                object.put("item_name",ylzMedicalMxDO.getItemName());
                object.put("item_code",ylzMedicalMxDO.getItemCode());
                array.add(object);
            }
            data.put("MXLIST",array);
//        mxlist	药品明细	MXLIST	N
//        MXLIST
//        order_id	订单号	String	Y
//        settlement_no	医保结算单据号	String	Y
//        item_name	医保项目名称	String	Y
//        item_code	医保项目编码	String	Y
//        supervision_code	药品电子监管码	String	N	非必填
            String result = requestYlz(data,"N20.17.05.02","电子处方订单接收");
            if(result == null){
                throw new Exception("医保请求失败");
            }
            logger.info("电子处方订单接收:"+result);
            JSONObject object = JSONObject.parseObject(result);
            if (object.getString("flag").equalsIgnoreCase("1")){
                JSONObject encryptData = object.getJSONObject("encrypt_data");
                logger.info("encryptData=="+encryptData);
            }
        }
        return "上传成功";
    }
    /**
     *2.6.2	电子处方订单取消(N20.17.05.03)
     */
    public String electronicPrescriptionCancle(String outpatientId)throws Exception{
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(outpatientId);
        if (outpatientDO == null){
            throw new Exception("门诊信息不存在");
        }
        JSONObject data = new JSONObject();
        data.put("order_code","");//订单号
        data.put("order_time",DateUtil.dateToStrLong(outpatientDO.getCreateTime()));//订单时间
        List<WlyyPrescriptionDO> wlyyPrescriptionDOS = prescriptionDao.findByOutPatientIdList(outpatientId);
        if(wlyyPrescriptionDOS.size()==0){
            throw new Exception("处方信息不存在");
        }
        data.put("prescription_code",wlyyPrescriptionDOS.get(0).getRealOrder());//医院处方编号
        data.put("channel","1");//1、微信公众号,2、app,3、web
//        data.put("insurance_ticket_no","");//医保收费单据号	String	N	订单结算后的收费单据号
        data.put("order_state","");//订单状态    --1待发货、2配送中、3已签收、4已取消	String	Y
        data.put("cancel_time","");//订单取消时间  取消时必填
        data.put("cancel_reason","");//取消原因
        String result = requestYlz(data,"N20.17.05.03","电子处方订单取消");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("电子处方订单取消:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            return encryptData.toJSONString();
        }
        return result;
    }
    /**
     * 2.6.3 获取处方流转平台药师审方结果(N20.17.05.04)
     */
    public String pharmacistReviewResults(String outpatientId)throws Exception{
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(outpatientId);
        if (outpatientDO == null){
            throw new Exception("门诊信息不存在");
        }
        JSONObject data = new JSONObject();
//        data.put("order_code","");//订单号
        List<WlyyPrescriptionDO> wlyyPrescriptionDOS = prescriptionDao.findByOutPatientIdList(outpatientId);
        if(wlyyPrescriptionDOS.size()==0){
            throw new Exception("处方信息不存在");
        }
        data.put("prescription_code",wlyyPrescriptionDOS.get(0).getRealOrder());//医院处方编号
        String result = requestYlz(data,"N20.17.05.04","获取处方流转平台药师审方结果");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("获取处方流转平台药师审方结果:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            return encryptData.toJSONString();
        }
        return result;
    }
    /**
     * 2.2.1	门诊提醒(N21.08.09.01)
     */
    public String outpatientReminder(String outpatientId,String doctorCode)throws Exception{
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(outpatientId);
        if (outpatientDO == null){
            throw new Exception("门诊信息不存在");
        }
        JSONObject data = new JSONObject();
//        data.put("order_code","");//订单号
        List<WlyyPrescriptionDO> wlyyPrescriptionDOS = prescriptionDao.findByOutPatientIdList(outpatientId);
        if(wlyyPrescriptionDOS.size()==0){
            throw new Exception("处方信息不存在");
        }
        data.put("card_no",outpatientDO.getCardNo());//社保卡号
        List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDoctorCode(outpatientDO.getDoctor());
        if(doctorHospitalDOS.size()<=0){
            throw new Exception("未找到医生科室编码");
        }
        BaseDoctorHospitalDO doctorHospitalDO = doctorHospitalDOS.get(0);
        data.put("medical_dept_code",doctorHospitalDO.getDeptCode());//科室编码(使用医院科室编号)
        data.put("medical_dept_name",doctorHospitalDO.getDeptName());//科室名称
        data.put("doctor_code",doctorCode);//医师编号(使用医保医生编号)
        data.put("doctor_name",outpatientDO.getDoctorName());//医师姓名
        String result = requestYlz(data,"N21.08.09.01","门诊提醒");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("门诊提醒:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            return encryptData.toJSONString();
        }
        return result;
    }
    /**
     * 2.2.2	门诊事中提醒(N21.08.09.02)
     */
    public String outpatientEventReminder(String outpatientId,String doctorCode)throws Exception{
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(outpatientId);
        if (outpatientDO == null){
            throw new Exception("门诊信息不存在");
        }
        JSONObject data = new JSONObject();
//        data.put("order_code","");//订单号
        data.put("card_no",outpatientDO.getCardNo());//社保卡号
        data.put("visit_no",outpatientDO.getRegisterNo());//门诊挂号号
        data.put("visit_type","1");//就诊类型	String	Y	(1住院、2门诊)
        data.put("medicine_type","");//医疗类别	String	Y
        List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDoctorCode(outpatientDO.getDoctor());
        if(doctorHospitalDOS.size()<=0){
            throw new Exception("未找到医生科室编码");
        }
        BaseDoctorHospitalDO doctorHospitalDO = doctorHospitalDOS.get(0);
        data.put("medical_dept_code",doctorHospitalDO.getDeptCode());//科室编码(使用医院科室编号)
        data.put("medical_dept_name",doctorHospitalDO.getDeptName());//科室名称
        data.put("doctor_code",doctorCode);//医师编号(使用医保医生编号)
        data.put("doctor_name",outpatientDO.getDoctorName());//医师姓名
        data.put("doctor_advice_no","");// 	处方流水号(医院内部唯一号)	String	Y
        //医嘱
        JSONArray advice_details = new JSONArray();
        List<WlyyPrescriptionDO> wlyyPrescriptionDOS = prescriptionDao.findByOutPatientIdList(outpatientId);
        if(wlyyPrescriptionDOS.size()==0){
            throw new Exception("处方信息不存在");
        }
        for (WlyyPrescriptionDO wlyyPrescriptionDO:wlyyPrescriptionDOS){
            List<WlyyPrescriptionInfoDO> prescriptionInfoDOS = prescriptionInfoDao.findByPrescriptionId(wlyyPrescriptionDO.getId(),1);
            for (WlyyPrescriptionInfoDO wlyyPrescriptionInfoDO:prescriptionInfoDOS){
                JSONObject infoObj = new JSONObject();
                infoObj.put("project_code","");//项目编码	String	Y	(使用医保三目录项目编码),正常情况必填,特殊情况,如生化全套等没有医保编码,可放空。
                infoObj.put("hospital_code","");//院内项目编码
                infoObj.put("project_name","");//项目名称
                infoObj.put("recipe_no",wlyyPrescriptionDO.getRealOrder());//处方号
                infoObj.put("invoice_project","");//发票项目编码	String	Y	(使用医保发票项目编码)
                infoObj.put("medical_specification",wlyyPrescriptionInfoDO.getSpecification());//规格型号
                infoObj.put("dose_form",wlyyPrescriptionInfoDO.getDosage());//剂型
                infoObj.put("charge_unit","");//单位
                infoObj.put("price",wlyyPrescriptionInfoDO.getPackRetprice());//单价
                infoObj.put("dose_unit",wlyyPrescriptionInfoDO.getPackRetprice());//单价
                infoObj.put("medical_number",wlyyPrescriptionInfoDO.getQuantity());//数量
                infoObj.put("amount",wlyyPrescriptionInfoDO.getPackRetprice()*Integer.parseInt(wlyyPrescriptionInfoDO.getQuantity()));//金额
                infoObj.put("single_dose_number","");//每次用量
                infoObj.put("single_dose_unit","");//每次用量
                infoObj.put("use_frequency",wlyyPrescriptionInfoDO.getUsageName());//使用频次
                infoObj.put("deliver_way","");//具体给药途径详见附录三的编码
                infoObj.put("use_day",wlyyPrescriptionInfoDO.getDays());//用药天数
/*                dose_form	剂型, 	String	Y	具体可使用剂型详见附录五的编码
                medical_specification	规格	String	Y
                price	单价	String	Y	必须使用数值型,如”12.5”
                medical_number	数量	String	Y	必须使用数值型,如”10”
                dose_unit	单价 String	Y
                amount	金额	String	Y	必须使用数值型,如”50.5”
                use_day	用药天数	String	Y	(项目为药品时非空),医嘱服用该药品天数,必须使用数值型,如”15”
                single_dose_number	单次用药量	String	Y	(项目为药品时非空),配合下一个字段的单位,如 50 mg,必须使用数值型,如”50”
                single_dose_unit	单次用药量剂量单位	String	Y	(项目为药品时非空),具体可使用剂量单位详见附录四的编码
                take_medical_number	取药总量(	String	Y	项目为药品时非空),配合下一个字段的单位,如 500 mg,必须使用数值型,如”500”
                take_medical_unit	取药总量剂量单位	String	Y	(项目为药品时非空),具体可使用剂量单位附录四的编码
                dose_day	药量天数	String	Y	(项目为药品时非空),依据医嘱服药要求,所配药品患者可以服用的天数,必须使用数值型,如”5”
                deliver_way	给药途径	String	Y	具体给药途径详见附录三的编码
                take_frequence	服用频次	String	Y
                具体可用服用频次详见附录二的编码*/
                advice_details.add(infoObj);
            }
        }
        data.put("advice_details",advice_details);
        //诊断
        JSONArray diagnoses = new JSONArray();
        String icd10 = outpatientDO.getIcd10();
        String icd10Name = outpatientDO.getIcd10Name();
        String icd[] = icd10.split(",");
        String icdName[] = icd10Name.split(",");
        for (int i=0;i<icd.length;i++){
            JSONObject icdObj = new JSONObject();
            icdObj.put("disease_code_icd10",icd[i]);//诊断或症状编码
            icdObj.put("disease_name_icd10",icdName[i]);//诊断或症状名称
            diagnoses.add(icdObj);
        }
        data.put("diagnoses",diagnoses);
        String result = requestYlz(data,"N21.08.09.02","门诊事中提醒");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("门诊事中提醒:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            return encryptData.toJSONString();
        }
        return result;
    }
    public String getYlzToken() throws Exception {
        YlzHttpLogDO ylzHttpLogDO = new YlzHttpLogDO();
        String token = null;
        initConfig();
        String funid = "N00.00.00.01";
        JSONObject data = new JSONObject();
        data.put("appid",ylzConfigAppid);
        data.put("appsecret",ylzConfigAppSecret);
        data.put("grant_type","client_credentials");
        JSONObject object = new JSONObject();
        object.put("sign_type","md5");
        object.put("appid",ylzConfigAppid);
       /* String stringSignTemp ="appid="+ylzConfigAppid+"&appsecret="+ylzConfigAppSecret+"&data="+data+"&funid="+funid+"&sign_type=md5&key="+ylzConfigSignKey;
        String sign = MD5.md5(stringSignTemp).toUpperCase();*/
        object.put("data",data);
        object.put("funid",funid);
        String signResult = SafeUtil.sign(object.toJSONString(),ylzConfigSignKey);
        String obj = SafeUtil.encrypt(signResult,ylzConfigEncryptKey);
        JSONObject jsonObject = JSONObject.parseObject(obj);
        logger.info("请求前funid=="+funid+"data="+data);
        String response = httpClientUtil.postBody(ylzConfigUrl,jsonObject);
        ylzHttpLogDO.setResponseEncrpty(response);
        logger.info("请求后response=="+response);
        if (response!=null&&response!=""){
            JSONObject result = JSONObject.parseObject(response);
            if (result.getString("flag").equalsIgnoreCase("1")){
                String dataResult = result.getString("encrypt_data");
                result.remove("encrypt_data");
                if (dataResult!=null&&dataResult!=""){
                    String decryptResult = AES.aesDecrypt(dataResult,ylzConfigEncryptKey);
                    JSONObject dataObject = JSONObject.parseObject(decryptResult);
                    result.put("encrypt_data",dataObject);
                    response = result.toString();
                    token = dataObject.getString("access_token");
                }
            }
        }
        ylzHttpLogDO.setCode(funid);
        ylzHttpLogDO.setName("获取AccessToken");
        ylzHttpLogDO.setRequest(data.toJSONString());
        ylzHttpLogDO.setRequestEncrpty(obj);
        ylzHttpLogDO.setResponse(response);
        ylzHttpLogDO.setCreateTime(new Date());
        ylzHttpLogDao.save(ylzHttpLogDO);
        
        return token;
    }
    /**
     * 2.2.1渠道应用是否已授权(N20.17.01.01)
     *
     * @param patient
     * @return
     * @throws Exception
     */
    public String authorized(String patient) throws Exception{
        String funid = "N20.17.01.01";
        BasePatientDO patientDO = patientDao.findById(patient);
        if (patientDO==null){
            throw new Exception("患者信息不存在");
        }
        PatientMappingDO patientMappingDO = patientMappingDao.findByPatient(patient);
        if (patientMappingDO==null){
            throw new Exception("患者his信息不存在");
        }
        JSONObject data = new JSONObject();
        data.put("service_id","350203");
        data.put("name",patientDO.getName());
        data.put("idcard",patientDO.getIdcard());
        data.put("cert_type","01");//TODO
        data.put("phone",patientDO.getMobile());
        data.put("user_id",patientMappingDO.getMappingCode());
        String result = requestYlz(data,funid,"渠道应用是否已授权");
        return result;
    }
    /**
     * 2.2.1渠道应用是否已授权(N20.17.01.01)
     *
     * @param patient
     * @return
     * @throws Exception
     */
    public String authorizedToEntrace(String patient) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"authorized?patient="+patient;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.2.2医保在线服务授权表单(H5表单/小程序)(N20.17.01.02)
     *
     * @param patient
     * @return
     * @throws Exception
     */
    public String medicareOnline(String patient) throws Exception{
        String funid = "N20.17.01.02";
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("ylzConfigRedirectUrl");
        if (hospitalSysDictDO==null){
            throw new Exception("回调地址为空!");
        }
        BasePatientDO patientDO = patientDao.findById(patient);
        if (patientDO==null){
            throw new Exception("患者信息不存在");
        }
        PatientMappingDO patientMappingDO = patientMappingDao.findByPatient(patient);
        if (patientMappingDO==null){
            throw new Exception("患者his信息不存在");
        }
        JSONObject data = new JSONObject();
        data.put("service_id","350203");
        data.put("name",patientDO.getName());
        data.put("idcard",patientDO.getIdcard());
        data.put("cert_type","01");//TODO
        data.put("phone",patientDO.getMobile());
        data.put("user_id",patientMappingDO.getMappingCode());
        data.put("redirect_url",hospitalSysDictDO.getDictValue());
        String result = requestYlz(data,funid,"医保在线服务授权表单");
        return result;
    }
    /**
     * 2.2.2医保在线服务授权表单(H5表单/小程序)(N20.17.01.02)
     *
     * @param patient
     * @return
     * @throws Exception
     */
    public String medicareOnlineToEntrance(String patient) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"medicareOnline?patient="+patient;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.2.3医保在线服务授权表单(H5表单/小程序)(N20.17.01.03)
     *
     * @param patient
     * @return
     * @throws Exception
     */
    public String medicareOnlineBase64(String patient) throws Exception{
        String funid = "N20.17.01.03";
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("ylzConfigRedirectUrl");
        if (hospitalSysDictDO==null){
            throw new Exception("回调地址为空!");
        }
        BasePatientDO patientDO = patientDao.findById(patient);
        if (patientDO==null){
            throw new Exception("患者信息不存在");
        }
        PatientMappingDO patientMappingDO = patientMappingDao.findByPatient(patient);
        if (patientMappingDO==null){
            throw new Exception("患者his信息不存在");
        }
        JSONObject data = new JSONObject();
        data.put("service_id","350203");
        data.put("name",patientDO.getName());
        data.put("idcard",patientDO.getIdcard());
        data.put("cert_type","01");//TODO
        data.put("phone",patientDO.getMobile());
        data.put("user_id",patientMappingDO.getMappingCode());
        data.put("redirect_url",hospitalSysDictDO.getDictValue());
        String result = requestYlz(data,funid,"医保在线服务授权表单");
        return result;
    }
    /**
     * 2.2.3医保在线服务授权表单(H5表单/小程序)(N20.17.01.03)
     *
     * @param patient
     * @return
     * @throws Exception
     */
    public String medicareOnlineBase64ToEntrance(String patient) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"medicareOnline?patient="+patient;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.5.1医保挂号(N20.17.04.01)
     *
     * 返回值
     *
     * @param outpatientId 系统id
     * @return
     * @throws Exception
     */
    public String register(String outpatientId) throws Exception{
        String funid = "N20.17.04.01";
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(outpatientId);
        if (ylzMedicalRelationDO==null){
            throw new Exception("上传医保挂号失败:结算信息为空!");
        }
        JSONObject data = new JSONObject();
        data.put("region_code",ylzMedicalRelationDO.getRegionCode());//参保地区划代码
        data.put("idcard",ylzMedicalRelationDO.getIdcard());//证件号码
        data.put("name",ylzMedicalRelationDO.getName());//姓名
        data.put("cert_type",ylzMedicalRelationDO.getCertType());//证件类型
        data.put("medical_mode",ylzMedicalRelationDO.getMedicalMode());//医疗就诊方式
        data.put("medical_type",ylzMedicalRelationDO.getMedicalType());//医疗类别
        data.put("his_serial",ylzMedicalRelationDO.getHisSerial());//his流水号
        data.put("his_dept_code",ylzMedicalRelationDO.getHisDeptCode());//his内部科室编码
        data.put("his_dept_name",ylzMedicalRelationDO.getHisDeptName());//his内部科室名称
        data.put("emergency_sign",ylzMedicalRelationDO.getEmergencySign());//急诊标志0 否,1 是
        data.put("trauma_sign",ylzMedicalRelationDO.getTraumaSign());//外伤标志0 否,1 是
        data.put("date", DateUtil.dateToStrFormatLong(ylzMedicalRelationDO.getDate()));//实际门诊/入院日期 若为空,默认取系统时间
        data.put("data_source",ylzMedicalRelationDO.getDataSource());//数据来源
        WlyyOutpatientDO outpatientDO = outpatientDao.findById(outpatientId);
        if (outpatientDO!=null){
            BaseDoctorDO doctorDO = doctorDao.findById(outpatientDO.getDoctor());
            if (doctorDO!=null){
                data.put("atddr_no",doctorDO.getAtddrNo());
                data.put("dr_name",doctorDO.getName());
            }
        }
        String result = requestYlz(data,funid,"医保挂号");
        if (result==null){
            throw new Exception("上传医保挂号失败!");
        }
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            String insuranceSerial = encryptData.getString("insurance_serial");
            ylzMedicalRelationDO.setInsuranceSerial(insuranceSerial);
            ylzMedicalRelationDO.setInsuranceType(encryptData.getString("insurance_type"));
            ylzMedicalRelationDO.setInsuranceTypeName(encryptData.getString("insurance_type_name"));
            ylzMedicailRelationDao.save(ylzMedicalRelationDO);
            logger.info("医保挂号流水号保存成功");
        }
        return result;
    }
    /**
     * 2.5.1医保挂号(N20.17.04.01)
     *
     * 返回值
     *
     * @param outpatientId 门诊id
     * @return
     * @throws Exception
     */
    public String registerToEntrance(String outpatientId) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"register?outpatientId="+outpatientId;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.5.2医保挂号冲销(N20.17.04.02)
     *
     * 返回值
     *
     * @param outpatientId 挂号号
     * @return
     * @throws Exception
     */
    public String registerBack(String outpatientId) throws Exception{
        String funid = "N20.17.04.02";
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(outpatientId);
        if (ylzMedicalRelationDO==null){
            throw new Exception("医保挂号冲销失败:结算信息为空!");
        }
        JSONObject data = new JSONObject();
        data.put("region_code",ylzMedicalRelationDO.getRegionCode());//参保地区划代码
        data.put("idcard",ylzMedicalRelationDO.getIdcard());//证件号码
        data.put("name",ylzMedicalRelationDO.getName());//姓名
        data.put("cert_type",ylzMedicalRelationDO.getCertType());//证件类型
        data.put("medical_mode",ylzMedicalRelationDO.getMedicalMode());//医疗就诊方式
        data.put("medical_type",ylzMedicalRelationDO.getMedicalType());//医疗类别
        data.put("his_serial",ylzMedicalRelationDO.getHisSerial());//his流水号
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//医保流水号
        data.put("data_source",ylzMedicalRelationDO.getDataSource());//数据来源
        String result = requestYlz(data,funid,"医保挂号冲销");
        if (result==null){
            throw new Exception("上传医保挂号冲销失败!");
        }
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            String invalidSerial = encryptData.getString("refund_serial");
            logger.info("医保挂号冲销流水号保存成功");
        }
        return result;
    }
    /**
     * 2.5.2医保挂号冲销(N20.17.04.02)
     *
     * 返回值
     *
     * @param outpatientId 挂号号
     * @return
     * @throws Exception
     */
    public String registerBackToEntrance(String outpatientId) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"registerBack?outpatientId="+outpatientId;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.5.3医保费用明细上传(N20.17.04.03)
     *
     * @param outpatientId 挂号号
     * @return
     * @throws Exception
     */
    public String feeDetailUpload(String outpatientId) throws Exception{
        String funid = "N20.17.04.03";
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(outpatientId);
        if (ylzMedicalRelationDO==null){
            throw new Exception("医保费用明细上传:结算信息为空!");
        }
        JSONObject data = new JSONObject();
        data.put("region_code",ylzMedicalRelationDO.getRegionCode());//参保地区划代码
        data.put("name",ylzMedicalRelationDO.getName());//姓名
        data.put("idcard",ylzMedicalRelationDO.getIdcard());//证件号码
        data.put("cert_type",ylzMedicalRelationDO.getCertType());//证件类型 TODO
        data.put("medical_mode",ylzMedicalRelationDO.getMedicalMode());//医疗就诊方式
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//医保流水号
        data.put("his_serial",ylzMedicalRelationDO.getHisSerial());//his流水号
        data.put("item_count",ylzMedicalRelationDO.getItemCount());//明细项目数量
        data.put("total_amount",ylzMedicalRelationDO.getTotalAmount());//医疗费总金额
        data.put("data_source",ylzMedicalRelationDO.getDataSource());//数据来源
        List<YlzMedicalIcdDO> ylzMedicalIcdDOList = ylzMedicailIcdDao.findByMedicalId(ylzMedicalRelationDO.getId());
        if (ylzMedicalIcdDOList==null){
            throw new Exception("医保费用明细上传:诊断结算信息为空!");
        }
        JSONArray icdArray = new JSONArray();
        for (YlzMedicalIcdDO ylzMI:ylzMedicalIcdDOList){
            JSONObject icdObj = new JSONObject();
            icdObj.put("disease_code_icd10",ylzMI.getDiseaseCodeIcd10());//诊断或症状编码
            icdObj.put("disease_name_icd10",ylzMI.getDiseaseNameIcd10());//诊断或症状名称
            icdObj.put("disease_type",ylzMI.getDiseaseType());//诊断或症状类型
            icdObj.put("disease_order",ylzMI.getDiseaseOrder());//诊断或症状序号
            icdArray.add(icdObj);
        }
        data.put("zdlist",icdArray);
        List<YlzMedicalMxDO> ylzMedicalMxDOS = ylzMedicailMxDao.findByMedicalId(ylzMedicalRelationDO.getId());
        if (ylzMedicalIcdDOList==null){
            throw new Exception("医保费用明细上传:诊断结算信息为空!");
        }
        JSONArray infoArray = new JSONArray();
        for (YlzMedicalMxDO ylzMedicalMxDO:ylzMedicalMxDOS){
                JSONObject infoObj = new JSONObject();
                infoObj.put("prescription_code",ylzMedicalMxDO.getPrescriptionCode());//医院处方编号
                infoObj.put("his_detail_sn",ylzMedicalMxDO.getHisDetailSn());//his处方明细流水号
                infoObj.put("item_name",ylzMedicalMxDO.getItemName());//医保项目名称
                infoObj.put("item_code",ylzMedicalMxDO.getItemCode());//医保项目编码
                infoObj.put("specification_type",ylzMedicalMxDO.getSpecificationType());//规格型号
                infoObj.put("dosage_form",ylzMedicalMxDO.getDosageForm());//剂型
                infoObj.put("charge_unit",ylzMedicalMxDO.getChargeUnit());//单位
                infoObj.put("price",ylzMedicalMxDO.getPrice());//单价
                infoObj.put("amount",ylzMedicalMxDO.getAmount());//数量
                infoObj.put("total_money",ylzMedicalMxDO.getTotalMoney());//金额
                infoObj.put("prescription_date", DateUtil.dateToStrLong(ylzMedicalMxDO.getPrescriptionDate()));//处方日期
                infoObj.put("his_dept_code",ylzMedicalMxDO.getHisDeptCode());//his内部科室编码
                infoObj.put("his_dept_name",ylzMedicalMxDO.getHisDeptName());//his内部科室名称
                infoObj.put("medical_per_name",ylzMedicalMxDO.getMedicalPerName());//医疗服务人员姓名
                infoObj.put("medical_per_id",ylzMedicalMxDO.getMedicalPerId());//医疗服务人员证件号码
                infoObj.put("limit_type",ylzMedicalMxDO.getLimitType());//限制范围类别
                infoObj.put("actg_date",DateUtil.dateToStr(ylzMedicalMxDO.getActgDate(),DateUtil.YYYYMMDD));//记帐日期
                infoObj.put("his_item_name",ylzMedicalMxDO.getHisItemName());//HIS院内项目名称
                infoObj.put("his_item_code",ylzMedicalMxDO.getHisItemCode());//HIS院内项目编码
                infoObj.put("clerk_days",DateUtil.dateToStrLong(ylzMedicalMxDO.getClerkDays()));//记帐日期
                infoObj.put("people_type",ylzMedicalMxDO.getPeopleType());//医保服务人员类别
                infoArray.add(infoObj);
        }
        data.put("mxlist",infoArray);
        String result = requestYlz(data,funid,"医保费用明细上传");
        if (result==null){
            throw new Exception("医保费用明细上传失败!");
        }
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            String detailSerial = encryptData.getString("detail_serial");
            ylzMedicalRelationDO.setDetailSerial(detailSerial);
            ylzMedicailRelationDao.save(ylzMedicalRelationDO);
            logger.info("医保费用明细上传保存成功");
        }
        return result;
    }
    /**
     * 2.5.3医保费用明细上传(N20.17.04.03)
     *
     * @param outpatientId 挂号号
     * @return
     * @throws Exception
     */
    public String feeDetailUploadToEntrance(String outpatientId) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"feeDetailUpload?outpatientId="+outpatientId;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.5.4医保费用明细上传冲销(N20.17.04.04)
     *
     * 返回值
     *
     * @param outpatientId 挂号号
     * @return
     * @throws Exception
     */
    public String feeDetailRefund(String outpatientId,String remark) throws Exception{
        String funid = "N20.17.04.04";
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(outpatientId);
        if (ylzMedicalRelationDO==null){
            throw new Exception("医保费用明细上传:结算信息为空!");
        }
        JSONObject data = new JSONObject();
        data.put("region_code",ylzMedicalRelationDO.getRegionCode());//参保地区划代码
        data.put("idcard",ylzMedicalRelationDO.getIdcard());//证件号码
        data.put("name",ylzMedicalRelationDO.getName());//姓名
        data.put("medical_mode",ylzMedicalRelationDO.getMedicalMode());//医疗就诊方式
        data.put("medical_type",ylzMedicalRelationDO.getMedicalType());//医疗类别
        data.put("detail_serial",ylzMedicalRelationDO.getDetailSerial());//医保明细流水号
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//医保流水号
        data.put("invalidation_reason",remark);//作废原因
        data.put("data_source",ylzMedicalRelationDO.getDataSource());//数据来源
        String result = requestYlz(data,funid,"医保费用明细上传冲销");
        if (result==null){
            throw new Exception("医保费用明细上传冲销失败!");
        }
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            logger.info("医保费用明细上传冲销保存成功");
        }
        return result;
    }
    /**
     * 2.5.4医保费用明细上传冲销(N20.17.04.04)
     *
     * 返回值
     *
     * @param outpatientId 门诊id
     * @return
     * @throws Exception
     */
    public String feeDetailRefundToEntrance(String outpatientId,String remark) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"feeDetailRefund?outpatientId="+outpatientId+"&remark="+remark;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.5.5医保预结算服务(N20.17.04.05)
     *
     * 返回值
     *
     * @param outpatientId 挂号号
     * @return
     * @throws Exception
     */
    public YlzMedicalRelationDO preSettlement(String outpatientId) throws Exception{
        String funid = "N20.17.04.05";
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(outpatientId);
        if (ylzMedicalRelationDO==null){
            throw new Exception("医保费用明细上传:结算信息为空!");
        }
        JSONObject data = new JSONObject();
        data.put("region_code",ylzMedicalRelationDO.getRegionCode());//参保地区划代码
        data.put("idcard",ylzMedicalRelationDO.getIdcard());//证件号码
        data.put("name",ylzMedicalRelationDO.getName());//姓名
        data.put("cert_type",ylzMedicalRelationDO.getCertType());//证件类型
        data.put("medical_mode",ylzMedicalRelationDO.getMedicalMode());//医疗就诊方式
        data.put("medical_type",ylzMedicalRelationDO.getMedicalType());//医疗类别
        data.put("his_bill_serial",ylzMedicalRelationDO.getHisBillSerial());//his收费单据流水号
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//医保流水号
        data.put("settlement_sign",0);//结算标识
        data.put("date",DateUtil.dateToStrFormatShort(ylzMedicalRelationDO.getDate()));//实际就诊日期
        data.put("leave_method","09");//离院方式
        data.put("pre_count",ylzMedicalRelationDO.getPreCount());//处方项目数
        data.put("total_amount",ylzMedicalRelationDO.getTotalAmount());//医疗费总金额
        data.put("data_source",ylzMedicalRelationDO.getDataSource());//数据来源
        data.put("his_serial",ylzMedicalRelationDO.getHisSerial());//his流水号
        data.put("doctor_level",ylzMedicalRelationDO.getDoctorLevel());//医师诊查费等级
        data.put("trt_fee_level",ylzMedicalRelationDO.getDoctorLevel());//医师诊查费等级
        data.put("dept_code",ylzMedicalRelationDO.getDeptCode());//科室编码
        data.put("disease_code",ylzMedicalRelationDO.getDiseaseCode());//病种编码
        data.put("charge_qty",1);//本次收费次数
        JSONArray array = new JSONArray();
        JSONObject object = new JSONObject();
        object.put("detail_serial",ylzMedicalRelationDO.getDetailSerial());
        array.add(object);
        data.put("cflist",array);
        String result = requestYlz(data,funid,"医保预结算服务");
        if (result==null){
            throw new Exception("医保预结算服务失败!");
        }else {
            JSONObject resObj = JSONObject.parseObject(result);
            if (resObj.getString("flag").equalsIgnoreCase("1")){
                JSONObject jsonObject = resObj.getJSONObject("encrypt_data");
                ylzMedicalRelationDO.setAccountBalance(jsonObject.getString("account_balance"));
                ylzMedicalRelationDO.setBillSerial(jsonObject.getString("bill_serial"));
                ylzMedicalRelationDO.setPersonalCode(jsonObject.getString("personal_code"));
                ylzMedicalRelationDO.setSex(jsonObject.getString("sex"));
                ylzMedicalRelationDO.setSexMc(jsonObject.getString("sex_mc"));
                ylzMedicalRelationDO.setPersonCash(jsonObject.getString("person_cash"));
                ylzMedicalRelationDO.setPersonAccount(jsonObject.getString("person_account"));
                ylzMedicalRelationDO.setFundPrice(jsonObject.getString("fund_price"));
                ylzMedicalRelationDO.setJkzhPay(jsonObject.getString("own_jkzh_pay"));
                ylzMedicalRelationDO.setOwnPay(jsonObject.getString("own_pay"));
                ylzMedicalRelationDO.setHospitalizationQty(jsonObject.getString("hospitalization_times"));
                ylzMedicalRelationDO.setPayDate(DateUtil.strToDate(jsonObject.getString("pay_date")+jsonObject.getString("pay_time")));
                ylzMedicalRelationDO.setInvoiceJj(jsonObject.getString("invoice_jj"));
                ylzMedicalRelationDO.setInvoiceXj(jsonObject.getString("invoice_xj"));
                ylzMedicalRelationDO.setInvoiceZh(jsonObject.getString("invoice_zh"));
                ylzMedicalRelationDO.setDiseaseCode(jsonObject.getString("disease_code"));
                ylzMedicalRelationDO.setTreatmentType(jsonObject.getString("treatment_type"));
                ylzMedicalRelationDO.setTreatmentTypeName(jsonObject.getString("treatment_type_name"));
                ylzMedicalRelationDO.setAllopatryType(jsonObject.getString("allopatry_type"));
                ylzMedicalRelationDO.setAllopatryTypeName(jsonObject.getString("allopatry_type_name"));
                ylzMedicalRelationDO.setAdministrativeArea(jsonObject.getString("administrative_area"));
                ylzMedicalRelationDO.setPayStandard(jsonObject.getString("pay_standard"));
                ylzMedicalRelationDO.setTcjjPay(jsonObject.getString("tcjj_pay"));
                ylzMedicalRelationDO.setSbjjPay(jsonObject.getString("sbjj_pay"));
                ylzMedicalRelationDO.setGwyPay(jsonObject.getString("gwy_pay"));
                ylzMedicalRelationDO.setJzfpPay(jsonObject.getString("jzfp_pay"));
                ylzMedicalRelationDO.setYljzPay(jsonObject.getString("yljz_pay"));
                ylzMedicalRelationDO.setOtherPay(jsonObject.getString("other_pay"));
                ylzMedicalRelationDO.setEnterpriseSupplement(jsonObject.getString("enterprise_supplement"));
                ylzMedicalRelationDO.setJtgjPay(jsonObject.getString("jtgj_pay"));
                ylzMedicalRelationDO.setCollector(jsonObject.getString("collector"));
                BigDecimal b1 = new BigDecimal(ylzMedicalRelationDO.getTcjjPay());
                BigDecimal b2 = new BigDecimal(ylzMedicalRelationDO.getSbjjPay());
                BigDecimal b3 = new BigDecimal(ylzMedicalRelationDO.getGwyPay());
                BigDecimal b4 = new BigDecimal(ylzMedicalRelationDO.getJzfpPay());
                BigDecimal b5 = new BigDecimal(ylzMedicalRelationDO.getYljzPay());
                BigDecimal b6 = new BigDecimal(ylzMedicalRelationDO.getOtherPay());
                BigDecimal b7 = new BigDecimal(ylzMedicalRelationDO.getEnterpriseSupplement());
                Double price = b1.add(b2).add(b3).add(b4).add(b5).add(b6).add(b7).doubleValue();
                /*Double price= Double.parseDouble(ylzMedicalRelationDO.getTcjjPay())+Double.parseDouble(ylzMedicalRelationDO.getSbjjPay())+
                        Double.parseDouble(ylzMedicalRelationDO.getGwyPay())+
                        Double.parseDouble(ylzMedicalRelationDO.getJzfpPay())+Double.parseDouble(ylzMedicalRelationDO.getYljzPay())+
                        Double.parseDouble(ylzMedicalRelationDO.getOtherPay())+Double.parseDouble(ylzMedicalRelationDO.getEnterpriseSupplement());*/
                ylzMedicalRelationDO.setMedicalPrice(price+"");
                logger.info("meidicalPrice====="+price);
                ylzMedicalRelationDO = ylzMedicailRelationDao.save(ylzMedicalRelationDO);
                JSONArray jsonArray = jsonObject.getJSONArray("fplist");
                for (int i=0;i<jsonArray.size();i++){
                    JSONObject jsonObject1 = jsonArray.getJSONObject(i);
                    YlzMedicalBillDO ylzMb = new YlzMedicalBillDO();
                    ylzMb.setMedicalId(ylzMedicalRelationDO.getId());
                    ylzMb.setInvoicePay(jsonObject1.getString("invoice_pay"));
                    ylzMb.setInvoiceType(jsonObject1.getString("invoice_type"));
                    ylzMb.setInvoiceTypeName(jsonObject1.getString("invoice_type_name"));
                    ylzMb.setProjectPay(jsonObject1.getString("project_pay"));
                    ylzMb.setOwnPay(jsonObject1.getString("own_pay"));
                    ylzMb.setSpecialPay(jsonObject1.getString("special_pay"));
                    ylzMb.setUninsurancePay(jsonObject1.getString("uninsurance_pay"));
                    ylzMb.setCreateTime(new Date());
                    ylzMedicailBillDao.save(ylzMb);
                }
            }
        }
        List<YlzMedicalIcdDO> icdDOList = ylzMedicailIcdDao.findByMedicalId(ylzMedicalRelationDO.getId());
        List<YlzMedicalMxDO> mxDOList = ylzMedicailMxDao.findByMedicalId(ylzMedicalRelationDO.getId());
        ylzMedicalRelationDO.setYlzMedicalIcdDOList(icdDOList);
        ylzMedicalRelationDO.setYlzMedicalMxDOList(mxDOList);
        return ylzMedicalRelationDO;
    }
    /**
     * 2.5.5医保预结算服务(N20.17.04.05)
     *
     * 返回值
     *
     * @param outpatientId 门诊id
     * @return
     * @throws Exception
     */
    public YlzMedicalRelationDO preSettlementToEntrance(String outpatientId) throws Exception{
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(outpatientId);
        if (ylzMedicalRelationDO==null){
            throw new Exception("医保费用明细上传:结算信息为空!");
        }
        List<YlzMedicalIcdDO> icdDOList = ylzMedicailIcdDao.findByMedicalId(ylzMedicalRelationDO.getId());;
        if (icdDOList!=null){
            ylzMedicalRelationDO.setYlzMedicalIcdDOList(icdDOList);
        }
        List<YlzMedicalMxDO> mxDOList = ylzMedicailMxDao.findByMedicalId(ylzMedicalRelationDO.getId());;
        if (mxDOList!=null){
            ylzMedicalRelationDO.setYlzMedicalMxDOList(mxDOList);
        }
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"preSettlement?outpatientId="+outpatientId;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
            JSONObject jsonObject1 = JSONObject.parseObject(result);
            if (jsonObject1.getString("flag").equalsIgnoreCase("1")){
                JSONObject encryptData = jsonObject1.getJSONObject("encrypt_data");
                String billSerial = encryptData.getString("bill_serial");
                ylzMedicalRelationDO.setInsuranceSerial(encryptData.getString("insurance_serial"));
                ylzMedicalRelationDO.setBillSerial(encryptData.getString("bill_serial"));
                ylzMedicalRelationDO.setHisBillSerial(encryptData.getString("his_bill_serial"));
                ylzMedicalRelationDO.setSexMc(encryptData.getString("sex_mc"));
                ylzMedicalRelationDO.setPersonCash(encryptData.getString("person_cash"));
                ylzMedicalRelationDO.setPersonAccount(encryptData.getString("person_account"));
                ylzMedicalRelationDO.setFundPrice(encryptData.getString("fund_price"));
                ylzMedicalRelationDO.setJkzhPay(encryptData.getString("jkzh_pay"));
                ylzMedicalRelationDO.setOwnPay(encryptData.getString("own_pay"));
                ylzMedicalRelationDO.setAccountBalance(encryptData.getString("account_balance"));
                ylzMedicalRelationDO.setHospitalizationQty(encryptData.getString("hospitalization_qty"));
                ylzMedicalRelationDO.setPayDate(DateUtil.strToDateLong(encryptData.getString("pay_date")));
                ylzMedicalRelationDO.setInvoiceJj(encryptData.getString("invoice_jj"));
                ylzMedicalRelationDO.setInvoiceXj(encryptData.getString("invoice_xj"));
                ylzMedicalRelationDO.setInvoiceZh(encryptData.getString("invoice_zh"));
                ylzMedicalRelationDO.setCreateTime(new Date());
                ylzMedicalRelationDO = ylzMedicailRelationDao.save(ylzMedicalRelationDO);
                JSONArray jsonArray = encryptData.getJSONArray("fplist");
                for (int i=0;i<jsonArray.size();i++){
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    YlzMedicalBillDO ylzMb = new YlzMedicalBillDO();
                    ylzMb.setMedicalId(ylzMedicalRelationDO.getId());
                    ylzMb.setInvoicePay(jsonObject.getString("invoice_pay"));
                    ylzMb.setInvoiceType(jsonObject.getString("invoice_type"));
                    ylzMb.setInvoiceTypeName(jsonObject.getString("invoice_type_name"));
                    ylzMb.setProjectPay(jsonObject.getString("project_pay"));
                    ylzMb.setOwnPay(jsonObject.getString("own_pay"));
                    ylzMb.setSpecialPay(jsonObject.getString("special_pay"));
                    ylzMb.setUninsurancePay(jsonObject.getString("uninsurance_pay"));
                    ylzMb.setCreateTime(new Date());
                    ylzMedicailBillDao.save(ylzMb);
                }
                logger.info("医保预结算服务保存成功");
            }
        }else {
            return null;
        }
        return ylzMedicalRelationDO;
    }
    /**
     * 2.5.6医保结算冲销服务(N20.17.04.06)
     *
     * 返回值
     *
     * @param outpatientId
     * @return
     * @throws Exception
     */
    public String preSettlementRefundToEntrance(String outpatientId) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"feeDetailRefund?outpatientId="+outpatientId;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.5.6医保结算冲销服务(N20.17.04.06)
     *
     * 返回值
     *
     * @param outpatientId
     * @return
     * @throws Exception
     */
    public String preSettlementRefund(String outpatientId) throws Exception{
        String funid = "N20.17.04.06";
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(outpatientId);
        if (ylzMedicalRelationDO==null){
            throw new Exception("医保结算冲销上传:结算信息为空!");
        }
        JSONObject data = new JSONObject();
        data.put("region_code",ylzMedicalRelationDO.getRegionCode());//参保地区划代码
        data.put("idcard",ylzMedicalRelationDO.getIdcard());//证件号码
        data.put("name",ylzMedicalRelationDO.getName());//姓名
        data.put("cert_type",ylzMedicalRelationDO.getCertType());//证件类型
        data.put("medical_mode",ylzMedicalRelationDO.getMedicalMode());//医疗就诊方式
        data.put("bill_serial",ylzMedicalRelationDO.getBillSerial());//医保收费流水号
        data.put("his_bill_serial",ylzMedicalRelationDO.getHisSettleNo());//his收费单据流水号
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//医保流水号
        data.put("data_source",ylzMedicalRelationDO.getDataSource());//数据来源
        data.put("refund_serial",ylzMedicalRelationDO.getHisSerial());//医院退费操作流水号
        String result = requestYlz(data,funid,"医保结算冲销服务");
        if (result==null){
            throw new Exception("医保结算冲销服务失败!");
        }
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            logger.info("医保结算冲销服务保存成功");
        }
        return result;
    }
    /**
     * 2.5.7获取医保结算页面地址(N20.17.04.07)
     *
     * 返回值
     *
     * @param outpatientId 挂号号
     * @return
     * @throws Exception
     */
    public String getSettlementResultUrl(String outpatientId) throws Exception{
        String funid = "N20.17.04.07";
        JSONObject data = new JSONObject();
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(outpatientId);
        if (ylzMedicalRelationDO==null){
            throw new Exception("获取医保结算页面地址:结算信息为空!");
        }
        WlyyHospitalSysDictDO wlyyHospitalSysDictDO = hospitalSysDictDao.findById("ResultRedirectUrl");
        if (wlyyHospitalSysDictDO==null){
            throw new Exception("获取医保结算页面地址失败:回调地址为空");
        }
        data.put("region_code",ylzMedicalRelationDO.getRegionCode());//参保地区划代码
        data.put("name",ylzMedicalRelationDO.getName());//姓名
        data.put("idcard",ylzMedicalRelationDO.getIdcard());//证件号码
        data.put("cert_type",ylzMedicalRelationDO.getCertType());//证件类型
        data.put("medical_mode",ylzMedicalRelationDO.getMedicalMode());//医疗就诊方式
        data.put("medical_type",ylzMedicalRelationDO.getMedicalType());//医疗类别
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//
        data.put("his_bill_serial",ylzMedicalRelationDO.getHisBillSerial());//his收费单据流水号
        data.put("date",DateUtil.dateToStrFormatShort(ylzMedicalRelationDO.getDate()));//实际就诊日期
        data.put("leave_method","09");//离院方式
        data.put("pre_count",ylzMedicalRelationDO.getPreCount());//处方项目数
        data.put("total_amount",ylzMedicalRelationDO.getTotalAmount());//医疗费总金额
        data.put("person_cash",ylzMedicalRelationDO.getPersonCash());//个人现金支付金额(实付现金)
        data.put("person_account",ylzMedicalRelationDO.getPersonAccount());//个人账户支付金额
        data.put("fund_price",ylzMedicalRelationDO.getMedicalPrice());//基金支付总额
        data.put("data_source",ylzMedicalRelationDO.getDataSource());//数据来源
        data.put("his_serial",ylzMedicalRelationDO.getHisSerial());//his流水号
        data.put("doctor_level",ylzMedicalRelationDO.getDoctorLevel());//医师诊查费等级
        data.put("redirect_url",wlyyHospitalSysDictDO.getDictValue());//回调地址
        data.put("disease_code",ylzMedicalRelationDO.getDiseaseCode());//病种编码
        JSONArray array = new JSONArray();
        JSONObject object = new JSONObject();
        object.put("detail_serial",ylzMedicalRelationDO.getDetailSerial());
        array.add(object);
        data.put("cflist",array);
        String result = requestYlz(data,funid,"获取医保结算页面地址");
        if (result==null){
            throw new Exception("获取医保结算页面地址失败!");
        }else {
            JSONObject resObj = JSONObject.parseObject(result);
            if (resObj.getString("flag").equalsIgnoreCase("1")){
                JSONObject jsonObject = resObj.getJSONObject("encrypt_data");
                String link_url = jsonObject.getString("link_url");
                String str1=link_url.substring(0, link_url.indexOf("="));
                String str2=link_url.substring(str1.length()+1, link_url.length());
                ylzMedicalRelationDO.setPageCode(str2);
                ylzMedicailRelationDao.save(ylzMedicalRelationDO);
            }
        }
        return result;
    }
    /**
     * 2.5.7获取医保结算页面地址(N20.17.04.07)
     *
     * 返回值
     *
     * @param outpatientId 挂号号
     * @return
     * @throws Exception
     */
    public String getSettlementResultUrlToEntrance(String outpatientId) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"getSettlementResultUrl?outpatientId="+outpatientId;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.5.8获取医保结算页面地址(N20.17.04.08)
     *
     * 返回值
     *
     * @param outpatientId 挂号号
     * @return
     * @throws Exception
     */
    public String getSettlementResultUrlBase64(String outpatientId) throws Exception{
        String funid = "N20.17.04.08";
        JSONObject data = new JSONObject();
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(outpatientId);
        if (ylzMedicalRelationDO==null){
            throw new Exception("获取医保结算页面地址:结算信息为空!");
        }
        WlyyHospitalSysDictDO wlyyHospitalSysDictDO = hospitalSysDictDao.findById("ResultRedirectUrl");
        if (wlyyHospitalSysDictDO==null){
            throw new Exception("获取医保结算页面地址失败:回调地址为空");
        }
        data.put("region_code",ylzMedicalRelationDO.getRegionCode());//参保地区划代码
        data.put("name",ylzMedicalRelationDO.getName());//姓名
        data.put("idcard",ylzMedicalRelationDO.getIdcard());//证件号码
        data.put("cert_type",ylzMedicalRelationDO.getCertType());//证件类型
        data.put("medical_mode",ylzMedicalRelationDO.getMedicalMode());//医疗就诊方式
        data.put("medical_type",ylzMedicalRelationDO.getMedicalType());//医疗类别
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//
        data.put("his_bill_serial",ylzMedicalRelationDO.getHisBillSerial());//his收费单据流水号
        data.put("date",DateUtil.dateToStrFormatShort(ylzMedicalRelationDO.getDate()));//实际就诊日期
        data.put("leave_method","09");//离院方式
        data.put("pre_count",ylzMedicalRelationDO.getPreCount());//处方项目数
        data.put("total_amount",ylzMedicalRelationDO.getTotalAmount());//医疗费总金额
        data.put("person_cash",ylzMedicalRelationDO.getPersonCash());//个人现金支付金额(实付现金)
        data.put("person_account",ylzMedicalRelationDO.getPersonAccount());//个人账户支付金额
        data.put("fund_price",ylzMedicalRelationDO.getMedicalPrice());//基金支付总额
        data.put("data_source",ylzMedicalRelationDO.getDataSource());//数据来源
        data.put("his_serial",ylzMedicalRelationDO.getHisSerial());//his流水号
        data.put("doctor_level",ylzMedicalRelationDO.getDoctorLevel());//医师诊查费等级
        data.put("redirect_url",wlyyHospitalSysDictDO.getDictValue());//回调地址
        String result = requestYlz(data,funid,"获取医保结算页面地址");
        if (result==null){
            throw new Exception("获取医保结算页面地址失败!");
        }
        return result;
    }
    /**
     * 2.5.8获取医保结算页面地址(N20.17.04.08)
     *
     * 返回值
     *
     * @param outpatientId 挂号号
     * @return
     * @throws Exception
     */
    public String getSettlementResultUrlBase64ToEntrance(String outpatientId) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"getSettlementResultUrlBase64?outpatientId="+outpatientId;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.5.8获取医保结算结果(N20.17.04.08)
     *
     * 返回值
     *
     * @param code
     * @return
     * @throws Exception
     */
    public String getSettlementResult(String code) throws Exception{
        String funid = "N20.17.04.08";
        JSONObject data = new JSONObject();
        data.put("code",code);//
        String result = requestYlz(data,funid,"获取医保结算结果");
        if (result==null){
            throw new Exception("获取医保结算结果失败!");
        }
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject jsonObject = object.getJSONObject("encrypt_data");
            String insuranceSerial = jsonObject.getString("insurance_serial");
            String billSerial = jsonObject.getString("bill_serial");
            String personCash = jsonObject.getString("person_cash");
            YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByInsuranceSerial(insuranceSerial);
            if (ylzMedicalRelationDO!=null){
                if (!ylzMedicalRelationDO.getPersonCash().equalsIgnoreCase(personCash)){
                    throw new Exception("医保结算金额不一致!");
                }else {
                    ylzMedicalRelationDO.setStatus(1);
                    ylzMedicalRelationDO.setBillSerial(billSerial);
                    ylzMedicalRelationDO.setPayDate(DateUtil.strToDate(jsonObject.getString("pay_date")+jsonObject.getString("pay_time")));
                    ylzMedicailRelationDao.save(ylzMedicalRelationDO);
                }
            }
        }
        return result;
    }
    /**
     * 2.5.8获取医保结算结果(N20.17.04.08)
     *
     * 返回值
     *
     * @param code
     * @return
     * @throws Exception
     */
    public String getSettlementResultToEntrance(String code) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"getSettlementResultUrl?code="+code;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.7.1上传用户病史病情及医学报告(N20.17.06.01)
     *
     * 返回值
     *
     * @param outpatientId
     * @return
     * @throws Exception
     */
    public String uploadMedicalHistory(String outpatientId) throws Exception{
        String funid = "N20.17.06.01";
        JSONObject data = new JSONObject();
        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(outpatientId);
        if (wlyyOutpatientDO==null){
            throw new Exception("医保上传户病史病情及医学报告失败!门诊为空");
        }
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(wlyyOutpatientDO.getRegisterNo());
        if (ylzMedicalRelationDO==null){
            throw new Exception("获取医保结算页面地址:结算信息为空!");
        }
        data.put("region_code","350200");//参保地区划代码
        data.put("idcard",wlyyOutpatientDO.getId());//身份证号
        data.put("name",wlyyOutpatientDO.getPatientName());//姓名
        data.put("cert_type","01");//证件类型
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//医保流水号
        data.put("blood_type",wlyyOutpatientDO.getBloodType());//血型
        data.put("allergy",wlyyOutpatientDO.getAllergy());//过敏史
        data.put("diagnosis",wlyyOutpatientDO.getIcd10Name());//病理诊断
        data.put("describe",wlyyOutpatientDO.getDescription());//病情描述
        data.put("difficult_cases","无");//疑难病例
        data.put("file_list_count",0);//医学报告附件数量
        data.put("data_source","53");//数据来源
        String result = requestYlz(data,funid,"上传用户病史病情及医学报告");
        if (result==null){
            throw new Exception("上传用户病史病情及医学报告失败!");
        }
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            wlyyOutpatientDO.setInsuranceMedHistserial(encryptData.getString("insurance_med_hist_serial"));
            logger.info("上传用户病史病情及医学报告保存成功");
        }
        return result;
    }
    /**
     * 2.7.1上传用户病史病情及医学报告(N20.17.06.01)
     *
     * 返回值
     *
     * @param outpatientId
     * @return
     * @throws Exception
     */
    public String uploadMedicalHistoryToEntrance(String outpatientId) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"uploadMedicalHistory?outpatientId="+outpatientId;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.7.2作废用户病史病情及医学报告(N20.17.06.06)
     *
     * 返回值
     *
     * @param outpatientId
     * @return
     * @throws Exception
     */
    public String refundMedicalHistory(String outpatientId,String remark) throws Exception{
        String funid = "N20.17.06.06";
        JSONObject data = new JSONObject();
        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(outpatientId);
        if (wlyyOutpatientDO==null){
            throw new Exception("医保上传户病史病情及医学报告失败!门诊为空");
        }
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(wlyyOutpatientDO.getRegisterNo());
        if (ylzMedicalRelationDO==null){
            throw new Exception("获取医保结算页面地址:结算信息为空!");
        }
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//医保流水号
        data.put("insurance_med_hist_serial",wlyyOutpatientDO.getInsuranceMedHistserial());//医保病史上传流水号
        data.put("invalid_reason",remark);//作废原因
        data.put("data_source","53");//数据来源
        String result = requestYlz(data,funid,"作废用户病史病情及医学报告");
        if (result==null){
            throw new Exception("作废用户病史病情及医学报告失败!");
        }
        return result;
    }
    /**
     * 2.7.2作废用户病史病情及医学报告(N20.17.06.06)
     *
     * 返回值
     *
     * @param outpatientId
     * @return
     * @throws Exception
     */
    public String refundMedicalHistoryToEntrance(String outpatientId,String remark) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"refundMedicalHistory?outpatientId="+outpatientId+"&remark="+remark;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.7.3获取问诊过程数据(N20.17.06.02)
     *
     * 返回值
     *
     * @param outpatientId
     * @return
     * @throws Exception
     */
    public String uploadIcdProcess(String outpatientId) throws Exception{
        String funid = "N20.17.06.02";
        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(outpatientId);
        if (wlyyOutpatientDO==null){
            throw new Exception("获取问诊过程数据失败!门诊为空");
        }
        BaseDoctorDO doctorDO = doctorDao.findById(wlyyOutpatientDO.getDoctor());
        if (doctorDO==null){
            throw new Exception("获取问诊过程数据失败!医生信息为空");
        }
        JSONObject data = new JSONObject();
        data.put("region_code","350200");//参保地区划代码
        data.put("idcard",wlyyOutpatientDO.getIdcard());//身份证号
        data.put("name",wlyyOutpatientDO.getPatientName());//姓名
        data.put("cert_type","01");//证件类型
        data.put("service_serial_id",wlyyOutpatientDO.getRegisterNo());//问诊流水号
        data.put("doctor_id_card",doctorDO.getIdcard());//医师身份证
        data.put("doctor_name",wlyyOutpatientDO.getDoctorName());//医师姓名
        /*data.put("file_list_count","");//附件总数
        data.put("filelist","");//附件列表
        data.put("file_bytes","");//二进制字节流
        data.put("file_name","");//文件名
        data.put("order_num",0);//顺序号*/
        String result = requestYlz(data,funid,"获取问诊过程数据");
        if (result==null){
            throw new Exception("获取问诊过程数据失败!");
        }
        return result;
    }
    /**
     * 2.7.3获取问诊过程数据(N20.17.06.02)
     *
     * 返回值
     *
     * @param outpatientId
     * @return
     * @throws Exception
     */
    public String uploadIcdProcessToEntrance(String outpatientId) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"uploadIcdProcess?outpatientId="+outpatientId;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    public Boolean isHospitalFlag(){
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("medicalFlag");
        if (hospitalSysDictDO!=null){
            if (hospitalSysDictDO.getDictValue().equalsIgnoreCase("1")){
                return true;
            }else {
                return false;
            }
        }else {
            return false;
        }
    }
}

+ 94 - 0
business/base-service/src/main/java/com/yihu/jw/healthCare/utils/Pkcs7Encoder.java

@ -0,0 +1,94 @@
package com.yihu.jw.healthCare.utils;//
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.Arrays;
import sun.misc.BASE64Encoder;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
public class Pkcs7Encoder {
    static final String KEY_ALGORITHM = "AES";
    static final String algorithmStr = "AES/CBC/PKCS7Padding";
    private static Key key;
    static byte[] iv = new byte[]{48, 49, 48, 50, 48, 51, 48, 52, 48, 53, 48, 54, 48, 55, 48, 56};
    public Pkcs7Encoder() {
    }
    private static Cipher init(byte[] keyBytes) {
        Cipher cipher = null;
        int base = 16;
        if (keyBytes.length % base != 0) {
            int groups = keyBytes.length / base + (keyBytes.length % base != 0 ? 1 : 0);
            byte[] temp = new byte[groups * base];
            Arrays.fill(temp, (byte)0);
            System.arraycopy(keyBytes, 0, temp, 0, keyBytes.length);
            keyBytes = temp;
        }
        Security.addProvider(new BouncyCastleProvider());
        key = new SecretKeySpec(keyBytes, "AES");
        try {
            cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
        } catch (NoSuchAlgorithmException var5) {
            var5.printStackTrace();
        } catch (NoSuchPaddingException var6) {
            var6.printStackTrace();
        } catch (NoSuchProviderException var7) {
            var7.printStackTrace();
        }
        return cipher;
    }
    public static byte[] encrypt(byte[] content, byte[] keyBytes) {
        byte[] encryptedText = encryptOfDiyIV(content, keyBytes, iv);
        return encryptedText;
    }
    public static byte[] decrypt(byte[] encryptedData, byte[] keyBytes) {
        byte[] encryptedText = decryptOfDiyIV(encryptedData, keyBytes, iv);
        return encryptedText;
    }
    public static byte[] encryptOfDiyIV(byte[] content, byte[] keyBytes, byte[] ivs) {
        byte[] encryptedText = null;
        Cipher cipher = init(keyBytes);
        System.out.println("IV:" + new String(ivs));
        try {
            cipher.init(1, key, new IvParameterSpec(ivs));
            encryptedText = cipher.doFinal(content);
        } catch (Exception var6) {
            var6.printStackTrace();
        }
        return encryptedText;
    }
    public static byte[] decryptOfDiyIV(byte[] encryptedData, byte[] keyBytes, byte[] ivs) {
        byte[] encryptedText = null;
        Cipher cipher = init(keyBytes);
        System.out.println("IV:" + new String(ivs));
        try {
            cipher.init(2, key, new IvParameterSpec(ivs));
            encryptedText = cipher.doFinal(encryptedData);
        } catch (Exception var6) {
            var6.printStackTrace();
        }
        return encryptedText;
    }
    public static String base64Encode(byte[] bytes) {
        return (new BASE64Encoder()).encode(bytes);
    }
}

+ 14 - 0
business/base-service/src/main/java/com/yihu/jw/healthCare/utils/SM4Context.java

@ -0,0 +1,14 @@
package com.yihu.jw.healthCare.utils;//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
public class SM4Context {
    public int mode = 1;
    public long[] sk = new long[32];
    public boolean isPadding = true;
    public SM4Context() {
    }
}

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 354 - 0
business/base-service/src/main/java/com/yihu/jw/healthCare/utils/SM4New.java


+ 162 - 0
business/base-service/src/main/java/com/yihu/jw/healthCare/utils/SM4Util.java

@ -0,0 +1,162 @@
package com.yihu.jw.healthCare.utils;//
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SM4Util {
    public static final String BM = "UTF-8";
    private String secretKey = "";
    private String iv = "1234567890ABCDEF";
    private final static char[] hexArray = "0123456789ABCDEF".toCharArray();
    public SM4Util() {
    }
    public SM4Util(String secretKey) {
        this.secretKey = secretKey;
    }
    public SM4Util(String secretKey, String iv) {
        this.secretKey = secretKey;
        this.iv = iv;
    }
    public String encryptDataECB(String plainText) throws Exception {
        return this.encryptDataECB(plainText.getBytes("UTF-8"));
    }
    public String encryptDataECB(byte[] content) throws Exception {
        SM4Context ctx = new SM4Context();
        ctx.isPadding = true;
        ctx.mode = 1;
        SM4New sm4 = new SM4New();
        byte[] keyBytes = getKey(this.secretKey);
        sm4.sm4_setkey_enc(ctx, keyBytes);
        byte[] encrypted = sm4.sm4_crypt_ecb(ctx, content);
        String cipherText = byteArrToHex(encrypted);
        if (cipherText != null && cipherText.trim().length() > 0) {
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(cipherText);
            cipherText = m.replaceAll("");
        }
        return cipherText.toUpperCase();
    }
    public String decryptDataECB(String encData) throws Exception {
        return new String(this.decryptDataECB(hexToByte(encData)));
    }
    public byte[] decryptDataECB(byte[] content) throws Exception {
        SM4Context ctx = new SM4Context();
        ctx.isPadding = true;
        ctx.mode = 0;
        SM4New sm4 = new SM4New();
        byte[] keyBytes = getKey(this.secretKey);
        sm4.sm4_setkey_dec(ctx, keyBytes);
        byte[] decrypted = sm4.sm4_crypt_ecb(ctx, content);
        return decrypted;
    }
    private static byte[] getKey(String strKey) throws Exception {
        byte[] arrBTmp = strKey.getBytes("UTF-8");
        byte[] arrB = new byte[16];
        for(int i = 0; i < arrBTmp.length && i < arrB.length; ++i) {
            arrB[i] = arrBTmp[i];
        }
        return arrB;
    }
    public String encryptDataCBC(String content) throws Exception {
        String encData = this.encryptDataCBC(content.getBytes("UTF-8"));
        return encData;
    }
    public String encryptDataCBC(byte[] content) throws Exception {
        SM4Context ctx = new SM4Context();
        ctx.isPadding = true;
        ctx.mode = 1;
        byte[] ivBytes = this.iv.getBytes("UTF-8");
        byte[] keyBytes = getKey(this.secretKey);
        SM4New sm4 = new SM4New();
        sm4.sm4_setkey_enc(ctx, keyBytes);
        byte[] encrypted = sm4.sm4_crypt_cbc(ctx, ivBytes, content);
        String cipherText = byteArrToHex(encrypted);
        if (cipherText != null && cipherText.trim().length() > 0) {
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(cipherText);
            cipherText = m.replaceAll("");
        }
        return cipherText.toUpperCase();
    }
    public String decryptDataCBC(String content) throws Exception {
        String data = this.decryptDataCBC(hexToByte(content));
        return data;
    }
    public String decryptDataCBC(byte[] content) throws Exception {
        SM4Context ctx = new SM4Context();
        ctx.isPadding = true;
        ctx.mode = 0;
        byte[] ivBytes = this.iv.getBytes("UTF-8");
        byte[] keyBytes = getKey(this.secretKey);
        SM4New sm4 = new SM4New();
        sm4.sm4_setkey_dec(ctx, keyBytes);
        byte[] decrypted = sm4.sm4_crypt_cbc(ctx, ivBytes, content);
        return new String(decrypted, "UTF-8");
    }
    public static String byteToHex(byte[] b) {
        if (b == null) {
            throw new IllegalArgumentException("Argument b ( byte array ) is null! ");
        } else {
            String hs = "";
            String stmp = "";
            for(int n = 0; n < b.length; ++n) {
                stmp = Integer.toHexString(b[n] & 255);
                if (stmp.length() == 1) {
                    hs = hs + "0" + stmp;
                } else {
                    hs = hs + stmp;
                }
            }
            return hs.toUpperCase();
        }
    }
    public static byte[] hexToByte(String hex) throws IllegalArgumentException {
        if (hex.length() % 2 != 0) {
            throw new IllegalArgumentException();
        } else {
            char[] arr = hex.toCharArray();
            byte[] b = new byte[hex.length() / 2];
            int i = 0;
            int j = 0;
            for(int l = hex.length(); i < l; ++j) {
                String swap = "" + arr[i++] + arr[i];
                int byteint = Integer.parseInt(swap, 16) & 255;
                b[j] = (new Integer(byteint)).byteValue();
                ++i;
            }
            return b;
        }
    }
    public static String byteArrToHex(byte... bytes) {
        char[] hexChars = new char[bytes.length * 2];
        for (int j = 0; j < bytes.length; j++) {
            int v = bytes[j] & 0xFF;
            hexChars[j * 2] = hexArray[v >>> 4];
            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
        }
        return new String(hexChars);
    }
}

+ 292 - 0
business/base-service/src/main/java/com/yihu/jw/healthCare/utils/YibaoJiaMi.java

@ -0,0 +1,292 @@
package com.yihu.jw.healthCare.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
/**
 * Created by Bing on 2022/12/16.
 */
public class YibaoJiaMi {
    public static String signType = "MD5";//MD5,SM3
    public static String encryptType = "PKCS7";//AES,SM4ECB,PKCS7
    public static String encryptDataSign(JSONObject plainJson,String signKey,String encryptKey){
        plainJson.put("chs_fjs_encrypt_type", encryptType);
        plainJson.put("chs_fjs_sign_type", signType);
        //签名
        {
            plainJson.remove("chs_fjs_sign");
            String signTemp = getSortSignTemp(plainJson, signKey);
            String sign = sign(signTemp, signType);
            plainJson.put("chs_fjs_sign", sign);
        }
        //加密
        {
            String context = plainJson.toJSONString();
            if (isNotBlank(context)) {
                String encryptData = encrypt(context, encryptKey, encryptType);
                plainJson.remove("data");
                plainJson.put("chs_fjs_encdata", encryptData);
            }
        }
        System.out.println("最终请求报文:" + plainJson.toJSONString());
        return plainJson.toJSONString();
    }
    public static String encryptData(JSONObject plainJson,String signKey,String encryptKey){
        plainJson.put("encrypt_type", encryptType);
        plainJson.put("sign_type", signType);
        //签名
        {
            plainJson.remove("sign");
            String signTemp = getSortSignTemp(plainJson, signKey);
            String sign = sign(signTemp, signType);
            plainJson.put("sign", sign);
        }
        //加密
        {
            String context = plainJson.getString("data");
            if (isNotBlank(context)) {
                String encryptData = encrypt(context, encryptKey, encryptType);
                plainJson.remove("data");
                plainJson.put("encrypt_data", encryptData);
            }
        }
        System.out.println("最终请求报文:" + plainJson.toJSONString());
        return plainJson.toJSONString();
    }
    public static void main(String[] args) {
        String ylzConfigAppid = "cloudxmjw";
        String ylzConfigAppSecret = "f0ce9e957371bef58735de4abe1fa274";
        String ylzConfigSignKey = "2156B331D45F53B02BFF05C3942E60D8";
        String ylzConfigEncryptKey = "3716B331D45F53B02BFF05C3942E60D8";
        JSONObject object = new JSONObject();
        JSONObject data = new JSONObject();
        String funid = "N00.00.00.01";
        data.put("appid", ylzConfigAppid);
        data.put("appsecret", ylzConfigAppSecret);
        data.put("grant_type","client_credentials");
        object.put("sign_type","md5");
        object.put("chs_fjs_appid", ylzConfigAppid);
        object.put("data",data);
        object.put("chs_fjs_funid",funid);
        String ss = encryptData(object,ylzConfigSignKey,ylzConfigEncryptKey);
        System.out.println(ss);
        System.out.println();
    }
    /**
     * 获取待签名字符串
     *
     * @param json
     * @return
     */
    public static String getSortSignTemp(JSONObject json, String key) {
        System.out.println("需要签名的报文:" + json.toJSONString());
        String signTemp = "";
        String jsonStr = JSONObject.toJSONString(json, SerializerFeature.MapSortField);
        LinkedHashMap m = JSON.parseObject(jsonStr, LinkedHashMap.class);
        Iterator<Map.Entry> iterator = m.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = iterator.next();
            String strVal = "";
            if (entry.getValue() instanceof Map) {
                strVal = JSONObject.toJSONString(entry.getValue(), SerializerFeature.MapSortField);
            } else {
                if (null == entry.getValue()) {
                    strVal = "";
                } else {
                    strVal = String.valueOf(entry.getValue());
                }
            }
            signTemp += entry.getKey() + "=" + strVal + "&";
        }
        signTemp=signTemp.substring(0,signTemp.length()-1);
        signTemp = signTemp + "&key=" + key;
        System.out.println("待签名字符串:" + signTemp);
        return signTemp;
    }
    public static String sign(String signTemp, String signType) {
        switch (signType) {
            case "MD5":
                return signByMd5(signTemp);
            default:
                return null;
        }
    }
    public static String signByMd5(String signTemp) {
        System.out.println("签名类型:MD5");
        String sign = md5(signTemp, "utf-8").toUpperCase();//计算signStr的MD5值,并对结果转为大写
        System.out.println("签名结果:" + sign);
        return sign;
    }
    /**
     * MD5
     *
     * @param str
     * @param charset
     * @return
     */
    public static String md5(String str, String charset) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(str.getBytes(charset));
            byte[] b = md.digest();
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; ++offset) {
                int i = b[offset];
                if (i < 0) {
                    i += 256;
                }
                if (i < 16) {
                    buf.append("0");
                }
                buf.append(Integer.toHexString(i));
            }
            str = buf.toString();
        } catch (Exception var7) {
            var7.printStackTrace();
        }
        return str;
    }
    public static String encrypt(String context, String key, String encryptType) {
        try {
            switch (encryptType) {
                case "PKCS7":
                    return encryptByPKCS7(context, key);
                case "SM4ECB":
                    return encryptBySM4ECB(context, key);
                case "AES":
                    return AES.aesEncrypt(context, key);
                default:
                    return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public static String encryptByPKCS7(String context, String key) {
        System.out.println("加密模式:PKCS7");
        System.out.println("加密前:" + context);
        String encode = null;
        try {
            BASE64Encoder base64Encoder=new BASE64Encoder();
            encode=base64Encoder.encode(Pkcs7Encoder.encrypt(context.getBytes("UTF-8"), key.getBytes()));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        System.out.println("加密结果:" + encode);
        return encode;
    }
    /**
     * SM4ECB加密
     *
     * @param context
     * @param key
     * @return
     */
    public static String encryptBySM4ECB(String context, String key) {
        SM4Util sm4 = new SM4Util(key, "");
        System.out.println("加密模式:SM4ECB");
        System.out.println("加密前:" + context);
        String cipherText = null;
        try {
            cipherText = sm4.encryptDataECB(context);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("加密结果:" + cipherText);
        return cipherText;
    }
    public static String decrypt(String encryptData, String key) {
        try {
            switch (encryptType) {
                case "PKCS7":
                    return decryptByPKCS7(encryptData, key);
                case "SM4ECB":
                    return decryptBySM4ECB(encryptData, key);
                case "AES":
                    return  AES.aesDecrypt(encryptData, key);
                default:
                    return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public static String decryptBySM4ECB(String encryptData, String key) {
        SM4Util sm4 = new SM4Util(key, "");
        System.out.println("解密模式:SM4ECB");
        System.out.println("解密前:" + encryptData);
        String cipherText = null;
        try {
            cipherText = sm4.decryptDataECB(encryptData);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("解密结果:" + cipherText);
        return cipherText;
    }
    public static String decryptByPKCS7(String context, String key) {
        try {
            BASE64Decoder base64Decoder=new BASE64Decoder();
            String aes7Str = new String(Pkcs7Encoder.decrypt(base64Decoder.decodeBuffer(context), key.getBytes()), "UTF-8");
            return aes7Str;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static boolean isNotBlank(String str) {
        return !isBlank(str);
    }
    public static boolean isBlank(String str) {
        int strLen;
        if (str != null && (strLen = str.length()) != 0) {
            for(int i = 0; i < strLen; ++i) {
                if (!Character.isWhitespace(str.charAt(i))) {
                    return false;
                }
            }
            return true;
        } else {
            return true;
        }
    }
}

+ 13 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/HcyyPrescriptionService.java

@ -529,6 +529,11 @@ public class HcyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
        if (StringUtils.isNoneBlank(realOrder)){
            params +="&realOrder="+realOrder;
        }
        PatientMappingDO patientMappingDO = patientMappingDao.findByPatient(patNo);
        if (patientMappingDO==null){
            throw new Exception("his用户编码为空!");
        }
        patNo = patientMappingDO.getMappingCode();
        logger.info("处方request:"+registerSn+"=="+patNo+"==="+admNo+"===="+realOrder);
        String obj = hcyyEntranceService.getOriginPrescriptionList(registerSn,patNo,admNo,realOrder,null,null);
        if (StringUtils.isNoneBlank(obj)){
@ -1611,6 +1616,12 @@ public class HcyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
    public YlzMedicalRelationDO getSettlementInfo(String cardno,String outpatientId) throws Exception {
        YlzMedicalRelationDO ylzMedicalRelationDO =new YlzMedicalRelationDO();
        WlyyOutpatientDO outpatientDO = outpatientDao.findById(outpatientId);
        //查询余额
        String balance = "";
        JSONObject jsonObject = selectCardInfo(cardno);
        if (jsonObject!=null){
            balance = jsonObject.getString("ZHYE");
        }
        String resNo = outpatientDO.getRegisterNo();
        //请求his获取待结算存储
        Map<String,Object> params = new HashedMap();
@ -1649,6 +1660,7 @@ public class HcyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
                            ylzMedicalRelationDO.setHisDeptName(object.getString("DEPT_NAME"));
                            ylzMedicalRelationDO.setStatus(0);
                            ylzMedicalRelationDO.setState(0);
                            ylzMedicalRelationDO.setBalance(balance);
                            ylzMedicalRelationDO.setPersonAccount("0");
                            ylzMedicalRelationDO.setMedicalPrice("0");
                            ylzMedicalRelationDO.setHisSettleNo(object.getString("IPT_OTP_NO"));
@ -1669,6 +1681,7 @@ public class HcyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
                            ylzMedicalRelationDO.setHisDeptName(object.getString("DEPT_NAME"));
                            ylzMedicalRelationDO.setPersonAccount("0");
                            ylzMedicalRelationDO.setMedicalPrice("0");
                            ylzMedicalRelationDO.setBalance(balance);
                            ylzMedicalRelationDO.setHisSettleNo(object.getString("IPT_OTP_NO"));
                            ylzMedicalRelationDO.setCardNo(object.getString("CARD_NO"));
                            ylzMedicalRelationDO.setDate(DateUtil.strToDate(object.getString("BEGNTIME")));

+ 150 - 13
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java

@ -53,6 +53,7 @@ import com.yihu.jw.entity.hospital.prescription.*;
import com.yihu.jw.entity.order.BusinessOrderDO;
import com.yihu.jw.entity.ylzinfo.OauthYlzConfigDO;
import com.yihu.jw.file_upload.FileUploadService;
import com.yihu.jw.healthCare.service.HealthCareNewService;
import com.yihu.jw.healthCare.service.HealthCareService;
import com.yihu.jw.hospital.consult.dao.BaseAdviceTreatmentDao;
import com.yihu.jw.hospital.consult.dao.HospitalWaitingRoomDao;
@ -328,6 +329,8 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    @Autowired
    private HealthCareService healthCareService;
    @Autowired
    private HealthCareNewService healthCareNewService;
    @Autowired
    private HcyyPrescriptionService hcyyPrescriptionService;
    @Autowired
    private YlzMedicailRelationDao ylzMedicailRelationDao;
@ -4551,13 +4554,20 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                    }else {
                        rs.put("is_prescribe",0);
                    }
                }else {
                }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                    String isPrescribe =healthCareService.doctorAuthentication(doctorDO.getId());
                    if (StringUtils.isNoneBlank(isPrescribe)){
                        rs.put("is_prescribe", isPrescribe);//is_prescribe	是否具备处方权	1-有处方权,0无处方权
                    }else {
                        rs.put("is_prescribe",0);
                    }
                }else {
                    String isPrescribe =healthCareNewService.doctorAuthentication(doctorDO.getId());
                    if (StringUtils.isNoneBlank(isPrescribe)){
                        rs.put("is_prescribe", isPrescribe);//is_prescribe	是否具备处方权	1-有处方权,0无处方权
                    }else {
                        rs.put("is_prescribe",0);
                    }
                }
            }else{
@ -4885,8 +4895,10 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                    }else {
                        rs.put("is_prescribe",0);
                    }
                }else {
                }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")) {
                    rs.put("is_prescribe", healthCareService.doctorAuthentication(doctorDO.getId()));//is_prescribe	是否具备处方权	1-有处方权,0无处方权
                }else{
                    rs.put("is_prescribe", healthCareNewService.doctorAuthentication(doctorDO.getId()));//is_prescribe	是否具备处方权	1-有处方权,0无处方权
                }
            }else{
                rs.put("is_prescribe", 0);//is_prescribe	是否具备处方权	1-有处方权,0无处方权
@ -7616,7 +7628,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                        basePatientDO.setMedicalState(state);
                        basePatientDO = basePatientDao.save(basePatientDO);
                    }
                }else {
                }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                    String result = healthCareService.authorized(basePatientDO.getId());
                    com.alibaba.fastjson.JSONObject object = com.alibaba.fastjson.JSONObject.parseObject(result);
                    if (object.getString("flag").equalsIgnoreCase("1")){
@ -7626,6 +7638,16 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                        basePatientDO.setMedicalState(state);
                        basePatientDO = basePatientDao.save(basePatientDO);
                    }
                }else {
                    String result = healthCareNewService.authorized(basePatientDO.getId());
                    com.alibaba.fastjson.JSONObject object = com.alibaba.fastjson.JSONObject.parseObject(result);
                    if (object.getString("flag").equalsIgnoreCase("1")){
                        com.alibaba.fastjson.JSONObject encryptData = object.getJSONObject("encrypt_data");
                        String state = encryptData.getString("state");
                        String auth_date = encryptData.getString("auth_date");
                        basePatientDO.setMedicalState(state);
                        basePatientDO = basePatientDao.save(basePatientDO);
                    }
                }
            }catch (Exception e){
                e.printStackTrace();
@ -14431,17 +14453,71 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            object.put("cardNo",outpatientDO.getCardNo());
            object.put("deptName",outpatientDO.getPatientName());
            return object;
        } else if (wechatId.equalsIgnoreCase("xm_hcyy_wx")){
        } else if (wechatId.equalsIgnoreCase("xm_hcyy_wx")) {
            com.alibaba.fastjson.JSONObject object = new com.alibaba.fastjson.JSONObject();
            logger.info("获取患者待结算信息开始!");
            YlzMedicalRelationDO ylzMedicalRelationDO = new YlzMedicalRelationDO();
            ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(outpatientId);
            if (ylzMedicalRelationDO != null && StringUtils.isNoneBlank(ylzMedicalRelationDO.getPageCode())) {
                String result = confirmSettlementInfo(outpatientId, ylzMedicalRelationDO.getPageCode());
                com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(result);
                if (jsonObject.getString("flag").equalsIgnoreCase("1")) {
                    com.alibaba.fastjson.JSONObject object1 = jsonObject.getJSONObject("encrypt_data");
                    BigDecimal b1 = new BigDecimal(object1.getString("tcjj_pay"));
                    BigDecimal b2 = new BigDecimal(object1.getString("sbjj_pay"));
                    BigDecimal b3 = new BigDecimal(object1.getString("gwy_pay"));
                    BigDecimal b4 = new BigDecimal(object1.getString("jzfp_pay"));
                    BigDecimal b5 = new BigDecimal(object1.getString("yljz_pay"));
                    BigDecimal b6 = new BigDecimal(object1.getString("other_pay"));
                    String payDateStr = object1.getString("pay_date");
                    Date payDate = DateUtil.strToDate(payDateStr);
                    Date now = DateUtil.getDateShort(new Date());
                    if (payDate.compareTo(now) == 0) {
                        BigDecimal b7 = new BigDecimal(object1.getString("enterprise_supplement"));
                        Double price = b1.add(b2).add(b3).add(b4).add(b5).add(b6).add(b7).doubleValue();
                        if (Double.parseDouble(ylzMedicalRelationDO.getMedicalPrice()) == price) {
                            ylzMedicalRelationDO.setStatus(1);
                            ylzMedicailRelationDao.save(ylzMedicalRelationDO);
                        }
                    } else {
                        ylzMedicalRelationDO.setStatus(0);
                        ylzMedicailRelationDao.save(ylzMedicalRelationDO);
                    }
                }
            }
            if (ylzMedicalRelationDO != null && ylzMedicalRelationDO.getStatus() == 1) {
                com.alibaba.fastjson.JSONObject object2 = hcyyPrescriptionService.selectCardInfo(outpatientDO.getCardNo());
                Double cardFee = object2.getDouble("ZHYE");
                //医保已结算直接返回数据
                List<YlzMedicalMxDO> mxDOList = ylzMedicailMxDao.findByMedicalId(ylzMedicalRelationDO.getId());
                ylzMedicalRelationDO.setYlzMedicalMxDOList(mxDOList);
                BigDecimal b1 = new BigDecimal(ylzMedicalRelationDO.getPersonCash());//个人现金
                BigDecimal b2 = new BigDecimal(ylzMedicalRelationDO.getPersonAccount());//个人账户
                BigDecimal b3 = new BigDecimal(ylzMedicalRelationDO.getMedicalPrice());//医保总金额
                ylzMedicalRelationDO.setBalance(cardFee + "");
                ylzMedicalRelationDO = ylzMedicailRelationDao.save(ylzMedicalRelationDO);
                Double totalPirce = b1.add(b2).add(b3).doubleValue();
                logger.info("总费用:" + totalPirce);
                if (totalPirce != Double.parseDouble(ylzMedicalRelationDO.getTotalAmount())) {
                    object.put("code", "403");
                    object.put("message", "金额不对无法结算!");
                } else {
                    object.put("code", "200");
                    object.put("message", "核对金额无误!");
                }
                object.put("getSettleInfo", ylzMedicalRelationDO);
                return object;
            }
            try {
                ylzMedicalRelationDO = hcyyPrescriptionService.getSettlementInfo(outpatientDO.getCardNo(),outpatientDO.getId());
            }catch (Exception e){
                ylzMedicalRelationDO = hcyyPrescriptionService.getSettlementInfo(outpatientDO.getCardNo(), outpatientDO.getId());
            } catch (Exception e) {
                throw new Exception(e.getMessage());
            }
            BigDecimal b1 = new BigDecimal(ylzMedicalRelationDO.getPersonCash());//个人现金
            if (ylzMedicalRelationDO==null){
                throw new Exception("无待结算信息");
            }
            /*BigDecimal b1 = new BigDecimal(ylzMedicalRelationDO.getPersonCash());//个人现金
            BigDecimal b2 = new BigDecimal(ylzMedicalRelationDO.getPersonAccount());//个人账户
            BigDecimal b3 = new BigDecimal(ylzMedicalRelationDO.getMedicalPrice());//医保总金额
            Double totalPirce=b1.add(b2).add(b3).doubleValue();
@ -14452,9 +14528,62 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            }else {
                object.put("code","200");
                object.put("message","核对金额无误!");
            }*/
            if(outpatientDO!=null&&outpatientDO.getMedicalState().equalsIgnoreCase("1")){
                logger.info("医保挂号开始!");
                String register = healthCareNewService.register(outpatientId);
                logger.info("医保挂号结束!");
                logger.info("医保费用明细上传开始!");
                String feeDetailUpload= healthCareNewService.feeDetailUpload(outpatientId);
                logger.info("医保费用明细上传结束!");
                logger.info("医保预结算信息开始!");
                ylzMedicalRelationDO =  healthCareNewService.preSettlement(outpatientId);
                logger.info("医保预结算信息结束!");
                if (flag==1){
                    logger.info("获取医保结算页面地址开始!");
                    String getSettlementResultUrl = healthCareNewService.getSettlementResultUrl(outpatientId);
                    logger.info("获取医保结算页面地址结束!");
                    object.put("getSettlementResultUrl",getSettlementResultUrl);
                }else if (flag==2){
                    logger.info("获取医保结算页面地址开始!");
                    String getSettlementResultUrlBase64 = healthCareService.getSettlementResultUrlBase64(outpatientId);
                    logger.info("获取医保结算页面地址结束!");
                    object.put("getSettlementResultUrlBase64",getSettlementResultUrlBase64);
                }
                if (ylzMedicalRelationDO.getPersonCash()!=null){
                    BigDecimal b1 = new BigDecimal(ylzMedicalRelationDO.getPersonCash());//个人现金
                    BigDecimal b2 = new BigDecimal(ylzMedicalRelationDO.getPersonAccount());//个人账户
                    BigDecimal b3 = new BigDecimal(ylzMedicalRelationDO.getMedicalPrice());//医保总金额
                    Double totalPirce=b1.add(b2).add(b3).doubleValue();
                    logger.info("总费用:"+totalPirce);
                    if (totalPirce!=Double.parseDouble(ylzMedicalRelationDO.getTotalAmount())){
                        object.put("code","403");
                        object.put("message","金额不对无法结算!");
                    }else {
                        object.put("code","200");
                        object.put("message","核对金额无误!");
                    }
                }
                object.put("getSettleInfo",ylzMedicalRelationDO);
                return object;
            }else {
                BigDecimal b1 = new BigDecimal(ylzMedicalRelationDO.getPersonCash());//个人现金
                BigDecimal b2 = new BigDecimal(ylzMedicalRelationDO.getPersonAccount());//个人账户
                BigDecimal b3 = new BigDecimal(ylzMedicalRelationDO.getMedicalPrice());//医保总金额
                Double totalPirce=b1.add(b2).add(b3).doubleValue();
                logger.info("总费用:"+totalPirce);
                if (totalPirce!=Double.parseDouble(ylzMedicalRelationDO.getTotalAmount())){
                    object.put("code","403");
                    object.put("message","金额不对无法结算!");
                }else {
                    object.put("code","200");
                    object.put("message","核对金额无误!");
                }
                object.put("getSettleInfo",ylzMedicalRelationDO);
                return object;
            }
            object.put("getSettleInfo",ylzMedicalRelationDO);
            return object;
        } else {
            com.alibaba.fastjson.JSONObject object = new com.alibaba.fastjson.JSONObject();
            logger.info("获取患者待结算信息开始!");
@ -14612,10 +14741,18 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            throw new Exception("门诊信息为空");
        }
        if (StringUtils.isNoneBlank(code)){
            logger.info("医保结算结果获取start!");
            result = healthCareService.getSettlementResult(code);
            logger.info("医保结算结果获取end!");
            com.alibaba.fastjson.JSONObject object = com.alibaba.fastjson.JSONObject.parseObject(result);
            if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                logger.info("医保结算结果获取start!");
                result = healthCareService.getSettlementResult(code);
                logger.info("医保结算结果获取end!");
                com.alibaba.fastjson.JSONObject object = com.alibaba.fastjson.JSONObject.parseObject(result);
            }else {
                logger.info("医保结算结果获取start!");
                result = healthCareNewService.getSettlementResult(code);
                logger.info("医保结算结果获取end!");
                com.alibaba.fastjson.JSONObject object = com.alibaba.fastjson.JSONObject.parseObject(result);
            }
        }/*else{
            logger.info("医保结算页面start!");
            String registerNo = outpatientDO.getRegisterNo();

+ 14 - 1
business/base-service/src/main/java/com/yihu/jw/patient/service/BasePatientService.java

@ -11,6 +11,7 @@ import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.entity.hospital.prescription.WlyyInspectionDO;
import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionInfoDO;
import com.yihu.jw.healthCare.service.HealthCareNewService;
import com.yihu.jw.healthCare.service.HealthCareService;
import com.yihu.jw.hospital.mapping.dao.PatientMappingDao;
import com.yihu.jw.hospital.prescription.dao.OutpatientDao;
@ -108,6 +109,8 @@ public class BasePatientService<T, R extends CrudRepository> extends BaseJpaServ
    private HospitalSysDictDao hospitalSysDictDao;
    @Autowired
    private HealthCareService healthCareService;
    @Autowired
    private HealthCareNewService healthCareNewService;
    /**
     * 居民id
     * @param patientId
@ -419,7 +422,7 @@ public class BasePatientService<T, R extends CrudRepository> extends BaseJpaServ
                        basePatientDO.setMedicalState(state);
                        basePatientDO = basePatientDao.save(basePatientDO);
                    }
                }else {
                }else if (wxId.equalsIgnoreCase("xm_zsyy_wx")){
                    String result = healthCareService.authorized(basePatientDO.getId());
                    JSONObject object = JSONObject.parseObject(result);
                    if (object.getString("flag").equalsIgnoreCase("1")){
@ -429,6 +432,16 @@ public class BasePatientService<T, R extends CrudRepository> extends BaseJpaServ
                        basePatientDO.setMedicalState(state);
                        basePatientDO = basePatientDao.save(basePatientDO);
                    }
                }else {
                    String result = healthCareNewService.authorized(basePatientDO.getId());
                    JSONObject object = JSONObject.parseObject(result);
                    if (object.getString("flag").equalsIgnoreCase("1")){
                        JSONObject encryptData = object.getJSONObject("encrypt_data");
                        String state = encryptData.getString("state");
                        String auth_date = encryptData.getString("auth_date");
                        basePatientDO.setMedicalState(state);
                        basePatientDO = basePatientDao.save(basePatientDO);
                    }
                }
            }
        }catch (Exception e){

+ 85 - 27
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/healthCare/HealthCareEndPoint.java

@ -1,6 +1,7 @@
package com.yihu.jw.hospital.endpoint.healthCare;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.healthCare.service.HealthCareNewService;
import com.yihu.jw.healthCare.service.HealthCareService;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
@ -30,6 +31,8 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
    @Autowired
    private HealthCareService healthCareService;
    @Autowired
    private HealthCareNewService healthCareNewService;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Value("${wechat.id}")
    private String wechatId;
@ -49,8 +52,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.doctorAuthentication(doctorId));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.doctorAuthentication(doctorId));
            }
        }catch (Exception e){
@ -73,8 +78,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.doctorFaceCheckInAddress(doctorId));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.doctorFaceCheckInAddress(doctorId));
            }
        }catch (Exception e){
            e.printStackTrace();
@ -96,8 +103,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.doctorFaceCheckInAddressBase64(doctorId));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.doctorFaceCheckInAddressBase64(doctorId));
            }
        }catch (Exception e){
            e.printStackTrace();
@ -119,8 +128,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.doctorFaceCheckInData(doctorId));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.doctorFaceCheckInData(doctorId));
            }
        }catch (Exception e){
@ -143,8 +154,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.advanceWarning(outpatientId));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.advanceWarning(outpatientId));
            }
        }catch (Exception e){
            e.printStackTrace();
@ -166,8 +179,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.doctorPrescriptionUpload(prescriptionId,wechatId));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.doctorPrescriptionUpload(prescriptionId,wechatId));
            }
        }catch (Exception e){
            e.printStackTrace();
@ -191,8 +206,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.doctorPrescriptionUploadCancle(prescriptionId,cancelReason));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.doctorPrescriptionUploadCancle(prescriptionId,cancelReason));
            }
        }catch (Exception e){
            e.printStackTrace();
@ -213,8 +230,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
            }else {
                return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
            }
        }else {
        }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
            return ObjEnvelop.getSuccess("ok",healthCareService.electronicPrescriptionReceiving(outpatientId));
        }else {
            return ObjEnvelop.getSuccess("ok",healthCareNewService.electronicPrescriptionReceiving(outpatientId));
        }
    }
@ -232,8 +251,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.electronicPrescriptionCancle(outpatientId));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.electronicPrescriptionCancle(outpatientId));
            }
        }catch (Exception e){
@ -256,8 +277,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.pharmacistReviewResults(outpatientId));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.pharmacistReviewResults(outpatientId));
            }
        }catch (Exception e){
@ -282,8 +305,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.outpatientReminder(outpatientId,doctorCode));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.outpatientReminder(outpatientId,doctorCode));
            }
        }catch (Exception e){
@ -309,8 +334,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.outpatientEventReminder(outpatientId,doctorCode));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.outpatientEventReminder(outpatientId,doctorCode));
            }
        }catch (Exception e){
@ -332,8 +359,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.getYlzToken());
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.getYlzToken());
            }
        }catch (Exception e){
@ -357,10 +386,13 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.authorized(patient));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.authorized(patient));
            }
        }catch (Exception e){
            e.printStackTrace();
            return failedObjEnvelopException(e);
@ -381,8 +413,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.medicareOnline(patient));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.medicareOnline(patient));
            }
        }catch (Exception e){
@ -405,8 +439,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.medicareOnlineBase64(patient));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.medicareOnlineBase64(patient));
            }
        }catch (Exception e){
            e.printStackTrace();
@ -428,8 +464,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.register(outpatientId));
            }else{
                return ObjEnvelop.getSuccess("ok",healthCareNewService.register(outpatientId));
            }
        }catch (Exception e){
@ -452,8 +490,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.registerBack(outpatientId));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.registerBack(outpatientId));
            }
        }catch (Exception e){
            e.printStackTrace();
@ -475,8 +515,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.feeDetailUpload(outpatientId));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.feeDetailUpload(outpatientId));
            }
        }catch (Exception e){
@ -501,8 +543,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")) {
                return ObjEnvelop.getSuccess("ok",healthCareService.feeDetailRefund(outpatientId,remark));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.feeDetailRefund(outpatientId,remark));
            }
        }catch (Exception e){
@ -525,8 +569,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.preSettlement(outpatientId));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.preSettlement(outpatientId));
            }
        }catch (Exception e){
@ -549,8 +595,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")) {
                return ObjEnvelop.getSuccess("ok",healthCareService.preSettlementRefund(outpatientId));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.preSettlementRefund(outpatientId));
            }
        }catch (Exception e){
@ -573,8 +621,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")) {
                return ObjEnvelop.getSuccess("ok",healthCareService.getSettlementResultUrl(outpatientId));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.getSettlementResultUrl(outpatientId));
            }
        }catch (Exception e){
@ -597,8 +647,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.getSettlementResult(code));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.getSettlementResult(code));
            }
        }catch (Exception e){
@ -621,8 +673,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.uploadMedicalHistory(outpatientId));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.uploadMedicalHistory(outpatientId));
            }
        }catch (Exception e){
@ -647,8 +701,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")) {
                return ObjEnvelop.getSuccess("ok",healthCareService.refundMedicalHistory(outpatientId,remark));
            }else {
                return ObjEnvelop.getSuccess("ok",healthCareNewService.refundMedicalHistory(outpatientId,remark));
            }
        }catch (Exception e){
@ -671,8 +727,10 @@ public class HealthCareEndPoint extends EnvelopRestEndpoint {
                }else {
                    return ObjEnvelop.getError("调用内网接口失败:"+jsonObject.getString("message"));
                }
            }else {
            }else if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                return ObjEnvelop.getSuccess("ok",healthCareService.uploadIcdProcess(outpatientId));
            }else{
                return ObjEnvelop.getSuccess("ok",healthCareNewService.uploadIcdProcess(outpatientId));
            }
        }catch (Exception e){