package com.hx.phip.his.service.impl; import com.hx.phip.common.KoapUrl; import com.hx.phip.his.config.SystemConfig; import com.hx.phiappt.dao.mapper.SystemParameterMapper; import com.hx.phip.his.service.GetTokenService; import com.hx.phip.his.service.KoapSyncBillReportService; import com.hx.phip.uti.HisHttpUtil; import com.hx.resultTool.ResponseCode; import com.hx.resultTool.Result; import com.hx.util.StringUtils; import net.sf.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; /** * @Author */ @Transactional @Service public class KoapSyncBillReportServiceImpl implements KoapSyncBillReportService { private static Logger logger = LoggerFactory.getLogger(KoapSyncBillReportServiceImpl.class); @Resource private SystemParameterMapper systemParameterMapper; @Resource private SystemConfig systemConfig; @Resource private GetTokenService getTokenService; /** * 获取KOAP token * @return */ public String getToken(){ String at = getTokenService.getKbjToken(systemParameterMapper, systemConfig.getKoaClientId(), systemConfig.getKoaGrantType(), systemConfig.getKoaClientSecret(), systemConfig.getKoapUrl()); return at; } @Override public Result feeReceiptList(JSONObject jsonObject) { jsonObject= JSONObject.fromObject(jsonObject.toString().replace("page","current")); String at =getToken(); Map header=new HashMap<>(); header.put("Authorization",at); jsonObject.put("clinicCode", systemConfig.getKoaClinicCode()); StringBuffer url=new StringBuffer(systemConfig.getKoapUrl()+ KoapUrl.FEE_RECEIPT_LIST); logger.info("获取KBJ获取患者缴费账单信息入参参数:{}",jsonObject.toString()); String datas=""; try { datas = HisHttpUtil.HttpURLUtilJson(url.toString(), null, jsonObject, header, "GET"); }catch (Exception e){ e.printStackTrace(); } if(StringUtils.isEmpty(datas)){ return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,datas); } datas=datas.replaceAll("\\\n",""); if(datas!=null){ JSONObject obj = JSONObject.fromObject(datas); if("0".equals(obj.optString("code","1"))){ return Result.success(com.alibaba.fastjson.JSONObject.parseObject(obj.optString("data"))); }else { return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,datas); } }else { return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,datas); } } @Override public Result inspectionRecord(JSONObject jsonObject) { String at =getToken(); Map header=new HashMap<>(); header.put("Authorization",at); jsonObject.put("clinicCode", systemConfig.getKoaClinicCode()); if(StringUtils.isEmpty(jsonObject.optString("patientNo",null))) return Result.failure(ResponseCode.ERROR_PARAMS_VALIDATOR,"患者编码不能为空"); if(StringUtils.isEmpty(jsonObject.optString("visitDateFrom",null))) return Result.failure(ResponseCode.ERROR_PARAMS_VALIDATOR,"就诊开始日期不能为空(YYYY-MM-DD)"); StringBuffer url=new StringBuffer(systemConfig.getKoapUrl()+ KoapUrl.EXECUTION_LAB_RECORD_PATIENT_LIST); logger.info("获取患者检验记录信息入参参数:{}",jsonObject.toString()); String datas = HisHttpUtil.HttpURLUtilJson(url.toString(), null, jsonObject, header, "GET"); if(StringUtils.isEmpty(datas)){ return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,datas); } datas=datas.replaceAll("\\\n",""); if(datas!=null){ JSONObject obj = JSONObject.fromObject(datas); if("0".equals(obj.optString("code","1"))){ return Result.success(com.alibaba.fastjson.JSONObject.parseObject(obj.optString("data"))); }else { return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,datas); } }else { return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,datas); } } @Override public Result inspectionReport(JSONObject jsonObject) { String at =getToken(); Map header=new HashMap<>(); header.put("Authorization",at); jsonObject.put("clinicCode", systemConfig.getKoaClinicCode()); if(StringUtils.isEmpty(jsonObject.optString("requestNo",null))) return Result.failure(ResponseCode.ERROR_PARAMS_VALIDATOR,"检验申请单编号不能为空"); if(StringUtils.isEmpty(jsonObject.optString("itemCode",null))) return Result.failure(ResponseCode.ERROR_PARAMS_VALIDATOR,"检验项目编码不能为空"); StringBuffer url=new StringBuffer(systemConfig.getKoapUrl()+ KoapUrl.EXECUTION_LAB_REPORT_GET); logger.info("获取患者检验报告入参信息:{}",jsonObject.toString()); String datas = HisHttpUtil.HttpURLUtilJson(url.toString(), null, jsonObject, header, "GET"); if(StringUtils.isEmpty(datas)){ return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,datas); } datas=datas.replaceAll("\\\n",""); if(datas!=null){ JSONObject obj = JSONObject.fromObject(datas); if("0".equals(obj.optString("code","1"))){ return Result.success(com.alibaba.fastjson.JSONObject.parseObject(obj.optString("data"))); }else { return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,datas); } }else { return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,datas); } } @Override public Result examInspectionRecord(JSONObject jsonObject) { String at =getToken(); Map header=new HashMap<>(); header.put("Authorization",at); jsonObject.put("clinicCode", systemConfig.getKoaClinicCode()); if(StringUtils.isEmpty(jsonObject.optString("patientNo",null))) return Result.failure(ResponseCode.ERROR_PARAMS_VALIDATOR,"患者编码不能为空"); if(StringUtils.isEmpty(jsonObject.optString("visitDateFrom",null))) return Result.failure(ResponseCode.ERROR_PARAMS_VALIDATOR,"就诊开始日期不能为空(YYYY-MM-DD)"); StringBuffer url=new StringBuffer(systemConfig.getKoapUrl()+ KoapUrl.EXECUTION_EXAM_RECORD_PATIENT_LIST); logger.info("获取患者检查记录信息入参信息:{}",jsonObject.toString()); String datas = HisHttpUtil.HttpURLUtilJson(url.toString(), null, jsonObject, header, "GET"); if(StringUtils.isEmpty(datas)){ return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,datas); } datas=datas.replaceAll("\\\n",""); if(datas!=null){ JSONObject obj = JSONObject.fromObject(datas); if("0".equals(obj.optString("code","1"))){ return Result.success(com.alibaba.fastjson.JSONObject.parseObject(obj.optString("data"))); }else { return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,datas); } }else { return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,datas); } } @Override public Result examInspectionReport(JSONObject jsonObject) { String at =getToken(); Map header=new HashMap<>(); header.put("Authorization",at); jsonObject.put("clinicCode", systemConfig.getKoaClinicCode()); if(StringUtils.isEmpty(jsonObject.optString("requestNo",null))) return Result.failure(ResponseCode.ERROR_PARAMS_VALIDATOR,"检验申请单编号不能为空"); StringBuffer url=new StringBuffer(systemConfig.getKoapUrl()+ KoapUrl.EXECUTION_EXAM_REPORT_GET); logger.info("获取患者检查报告信息入参信息:{}",jsonObject.toString()); String datas = HisHttpUtil.HttpURLUtilJson(url.toString(), null, jsonObject, header, "GET"); if(StringUtils.isEmpty(datas)){ return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,datas); } datas=datas.replaceAll("\\\n",""); if(datas!=null){ JSONObject obj = JSONObject.fromObject(datas); if("0".equals(obj.optString("code","1"))){ return Result.success(com.alibaba.fastjson.JSONObject.parseObject(obj.optString("data"))); }else { return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,datas); } }else { return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,datas); } } }