Browse Source

采集逻辑合并调试

lingfeng 9 years ago
parent
commit
708c6e4427
21 changed files with 713 additions and 826 deletions
  1. 53 0
      Hos-Framework/src/main/java/com/yihu/ehr/framework/util/encrypt/MD5.java
  2. 22 0
      Hos-Framework/src/main/java/com/yihu/ehr/framework/util/file/FileUtil.java
  3. 26 4
      Hos-Framework/src/main/java/com/yihu/ehr/framework/util/httpclient/HttpClientUtil.java
  4. 13 0
      Hos-Framework/src/main/java/com/yihu/ehr/framework/util/operator/NumberUtil.java
  5. 0 15
      Hos-resource/src/main/java/com/yihu/ehr/common/CommonPageController.java
  6. 11 302
      Hos-resource/src/main/java/com/yihu/ehr/crawler/controller/CrawlerController.java
  7. 1 1
      Hos-resource/src/main/java/com/yihu/ehr/crawler/model/adapter/AdapterDataSet.java
  8. 0 30
      Hos-resource/src/main/java/com/yihu/ehr/crawler/model/adapter/AdapterDict.java
  9. 2 2
      Hos-resource/src/main/java/com/yihu/ehr/crawler/model/adapter/AdapterMetaData.java
  10. 89 166
      Hos-resource/src/main/java/com/yihu/ehr/crawler/service/CrawlerManager.java
  11. 204 119
      Hos-resource/src/main/java/com/yihu/ehr/crawler/service/DataCollectDispatcher.java
  12. 14 37
      Hos-resource/src/main/java/com/yihu/ehr/crawler/service/DataSetTransformer.java
  13. 104 69
      Hos-resource/src/main/java/com/yihu/ehr/crawler/service/EsbHttp.java
  14. 2 3
      Hos-resource/src/main/java/com/yihu/ehr/crawler/service/PatientCDAIndex.java
  15. 110 0
      Hos-resource/src/main/java/com/yihu/ehr/crawler/service/PatientCDAUpload.java
  16. 0 16
      Hos-resource/src/main/java/com/yihu/ehr/datacollect/controller/DataPushController.java
  17. 2 2
      Hos-resource/src/main/java/com/yihu/ehr/resource/service/IStdService.java
  18. 10 10
      Hos-resource/src/main/java/com/yihu/ehr/resource/service/impl/StdService.java
  19. 14 14
      Hos-resource/src/main/java/com/yihu/ehr/standard/controller/SchemeDictEntryController.java
  20. 1 1
      Hos-resource/src/main/java/com/yihu/ehr/standard/model/adapter/AdapterDictentryModel.java
  21. 35 35
      Hos-resource/src/main/java/com/yihu/ehr/standard/service/adapter/AdapterDictentryService.java

+ 53 - 0
Hos-Framework/src/main/java/com/yihu/ehr/framework/util/encrypt/MD5.java

@ -2,7 +2,16 @@ package com.yihu.ehr.framework.util.encrypt;
import com.yihu.ehr.framework.util.encode.HexEncode;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.AccessController;
import java.security.MessageDigest;
import java.security.PrivilegedAction;
/**
 * @created  Air 2015/6/2.
@ -34,4 +43,48 @@ public class MD5 {
        String decryptStr = new String(a);
        return decryptStr;
    }
    public static String getMd5ByFile(File file) throws FileNotFoundException {
        String value = null;
        FileInputStream in = new FileInputStream(file);
        MappedByteBuffer byteBuffer =null;
        try {
            byteBuffer = in.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.length());
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(byteBuffer);
//            BigInteger bi = new BigInteger(1, md5.digest());
//            value = bi.toString(16);
            value= HexEncode.toHexString(md5.digest());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(null != in) {
                try {
                    in.close();
                    clean(byteBuffer);
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return value;
    }
    public static void clean(final Object buffer) throws Exception {
        AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                try {
                    Method getCleanerMethod = buffer.getClass().getMethod("cleaner", new Class[0]);
                    getCleanerMethod.setAccessible(true);
                    sun.misc.Cleaner cleaner = (sun.misc.Cleaner) getCleanerMethod.invoke(buffer, new Object[0]);
                    cleaner.clean();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        });
    }
}

+ 22 - 0
Hos-Framework/src/main/java/com/yihu/ehr/framework/util/file/FileUtil.java

@ -197,4 +197,26 @@ public class FileUtil {
            }
        }
    }
    /**
     * 删除整个目录
     *
     * @param dir 目录
     * @return boolean
     * @created Airhead
     */
    public static boolean deleteDirectory(File dir) {
        if (dir.isDirectory()) {
            String[] children = dir.list();
            //递归删除目录中的子目录下
            for (int i = 0; i < children.length; i++) {
                boolean success = deleteDirectory(new File(dir, children[i]));
                if (!success) {
                    return false;
                }
            }
        }
        // 目录此时为空,可以删除
        return dir.delete();
    }
}

+ 26 - 4
Hos-Framework/src/main/java/com/yihu/ehr/framework/util/httpclient/HttpClientUtil.java

@ -22,10 +22,7 @@ import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.springframework.util.StringUtils;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
@ -259,6 +256,31 @@ public class HttpClientUtil {
        return file;
    }
    public static HttpResponse postForm(String url, List<NameValuePair> formParams) {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        UrlEncodedFormEntity postEntity = new UrlEncodedFormEntity(formParams, Consts.UTF_8);
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(postEntity);
        CloseableHttpResponse response = null;
        HttpEntity entity = null;
        try {
            response = httpClient.execute(httpPost);
            entity = response.getEntity();
            HttpResponse res = new HttpResponse(response.getStatusLine().getStatusCode(), EntityUtils.toString(entity));
            return res;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            close(httpClient, (CloseableHttpResponse) entity);
        }
        return null;
    }
    /**
     * 下载文件
     */

+ 13 - 0
Hos-Framework/src/main/java/com/yihu/ehr/framework/util/operator/NumberUtil.java

@ -207,6 +207,19 @@ public class NumberUtil {
    }
    public static boolean isZero(Integer num) {
        if (num == null) {
            return true;
        }
        if (num == 0) {
            return true;
        }
        return false;
    }
    public static int toInt(String str) {
        Integer integer = toInteger(str);

+ 0 - 15
Hos-resource/src/main/java/com/yihu/ehr/common/CommonPageController.java

@ -1,28 +1,13 @@
package com.yihu.ehr.common;
import com.yihu.ehr.datacollect.model.RsJobConfig;
import com.yihu.ehr.datacollect.service.intf.IDatacollectManager;
import com.yihu.ehr.datacollect.service.intf.IDatacollectService;
import com.yihu.ehr.framework.constrant.DateConvert;
import com.yihu.ehr.framework.model.ActionResult;
import com.yihu.ehr.framework.model.Result;
import com.yihu.ehr.framework.util.controller.BaseController;
import com.yihu.ehr.std.service.intf.IStdService;
import com.yihu.ehr.system.model.SystemUser;
import com.yihu.ehr.system.service.intf.IDatasourceManager;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
/**
 * 数据采集配置页面

+ 11 - 302
Hos-resource/src/main/java/com/yihu/ehr/crawler/controller/CrawlerController.java

@ -1,325 +1,34 @@
package com.yihu.ehr.crawler.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.core.constant.LogAttribute;
import com.yihu.core.util.log.BusinessLogger;
import com.yihu.core.util.log.DebugLogger;
import com.yihu.core.util.log.LogUtil;
import com.yihu.core.util.operator.DateUtil;
import com.yihu.ehr.mqhelper.ActiveMQHelper;
import com.yihu.ehr.vanguard.common.constant.*;
import com.yihu.ehr.vanguard.common.controller.BaseController;
import com.yihu.ehr.vanguard.crawler.DataCollectDispatcher;
import com.yihu.ehr.vanguard.crawler.service.patient.Patient;
import com.yihu.ehr.crawler.model.patient.Patient;
import com.yihu.ehr.crawler.service.CrawlerManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
/**
 * 目前版本只需要采集,上传和注册病人档案就可了。
 * <p>
 * Created by Airhead on 2015/12/16.
 */
@RestController
@RequestMapping(ApiVersionPrefix.CommonVersion + "/crawler")
@Api(protocols = "https", value = "CrawlerController", description = "档案采集接口", tags = {"采集"})
public class CrawlerController extends BaseController {
@RequestMapping("/crawler")
@Api(protocols = "http", value = "CrawlerController", description = "档案采集接口", tags = {"采集"})
public class CrawlerController {
    @RequestMapping(value = "/patient/fetch", method = RequestMethod.POST)
    @RequestMapping(value = "/patient/crawler", method = RequestMethod.POST)
    @ApiOperation(value = "采集病人健康档案", produces = "application/json", notes = "采集病人健康档案")
    public RestEcho fetch(
            @ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
            @PathVariable(value = "apiVersion") String apiVersion,
            @ApiParam(name = "patient", value = "病人索引信息", required = true)
            @RequestParam(value = "patient", required = true) String patientInfo,
            @ApiParam(name = "userId", value = "用户ID", required = true)
            @RequestParam(value = "userId") Integer userId,
            @ApiParam(name = "accessToken", value = "数据令牌", required = true)
            @RequestParam(value = "accessToken") String accessToken,
            HttpServletRequest request ) {
        Map<String, String[]> parameterMap = request.getParameterMap();
        System.out.println(parameterMap);
        boolean result = false;
        RestEcho restEcho = new RestEcho();
        try {
            restEcho = tokenValid(userId, accessToken);
            if (restEcho.getCode().asText().equals(Constants.OK)) {
                Patient patient = DataCollectDispatcher.getInstance().parsePatient(patientInfo);
                if (patient != null) {
                    boolean patientStore = DataCollectDispatcher.getInstance().isPatientStore(patient.getOrgCode(), patient.getPatientId(), patient.getEventNo());
                    if (patientStore && !LogicValues.LOGIC_TRUE.equals(patient.getReUploadFlg())) {//是否已传并不是为补传的病人
                        restEcho.failed(Constants.NO);
                        return restEcho;
                    }else {
                        result = DataCollectDispatcher.getInstance().collectData(patient);
                    }
                }
                if (!result) {
                    restEcho.failed(Constants.NO);
                } else {
                    restEcho.success();
                }
            } else {
                // token验证失败处理
                sendFailPatient(patientInfo, FlowType.AUTH_FAIL_COLLECT);
            }
        } catch (IOException e) {
            restEcho.failed(Constants.NO);
            DebugLogger.error(LogAttribute.MARK_EXCEPTION,request,LogAttribute.FAIL,"CrawlerController采集异常", e);
        }catch (Exception e) {
            sendFailPatient(patientInfo, FlowType.AUTH_FAIL_COLLECT);
            restEcho.failed(Constants.NO);
            DebugLogger.error(LogAttribute.MARK_EXCEPTION,request,LogAttribute.FAIL,"CrawlerController采集异常", e);
        }
        return restEcho;
    }
    @RequestMapping(value = "/patient/query", method = RequestMethod.GET)
    @ApiOperation(value = "查询病人健康档案", produces = "application/json", notes = "查询病人健康档案")
    public RestEcho query(
            @ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
            @PathVariable(value = "apiVersion") String apiVersion,
            @ApiParam(name = "patient", value = "病人索引信息", required = true)
            @RequestParam(value = "patient") String patient,
            @ApiParam(name = "userId", value = "用户ID", required = true)
            @RequestParam(value = "userId") Integer userId,
            @ApiParam(name = "accessToken", value = "数据令牌", required = true)
            @RequestParam(value = "accessToken") String accessToken) {
        RestEcho restEcho = tokenValid(userId, accessToken);
        return restEcho;
    }
    @RequestMapping(value = "/patient/check/{orgCode}/{patientID}/{eventNo}", method = RequestMethod.POST)
    @ApiOperation(value = "检查病人是否已采集", produces = "application/json", notes = "检查病人是否已采集")
    public RestEcho check(
            @ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
            @PathVariable(value = "apiVersion") String apiVersion,
            @ApiParam(name = "orgCode", value = "机构编码", required = true)
            @PathVariable(value = "orgCode") String orgCode,
            @ApiParam(name = "patientID", value = "病人ID", required = true)
            @PathVariable(value = "patientID") String patientID,
            @ApiParam(name = "eventNo", value = "事件号", required = true)
            @PathVariable(value = "eventNo") String eventNo,
            @ApiParam(name = "userId", value = "用户ID", required = true)
            @RequestParam(value = "userId") Integer userId,
            @ApiParam(name = "accessToken", value = "数据令牌", required = true)
            @RequestParam(value = "accessToken") String accessToken) {
        RestEcho restEcho = tokenValid(userId, accessToken);
        boolean patientStore = DataCollectDispatcher.getInstance().isPatientStore(orgCode, patientID, eventNo);
        if (patientStore) {
            return restEcho.success();
        }
        return restEcho.failed(Constants.NO);
    }
    @RequestMapping(value = "/patient/transform/{orgCode}/{patientID}/{eventNo}", method = RequestMethod.POST)
    @ApiOperation(value = "转换档案到标准格式", produces = "application/json", notes = "采集病人健康档案")
    public String transform(
            @ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
            @PathVariable(value = "apiVersion") String apiVersion,
            @ApiParam(name = "orgCode", value = "机构编码", required = true)
            @PathVariable(value = "orgCode") String orgCode,
            @ApiParam(name = "patientID", value = "病人ID", required = true)
            @PathVariable(value = "patientID") String patientID,
            @ApiParam(name = "eventNo", value = "事件号", required = true)
            @PathVariable(value = "eventNo") String eventNo,
            @ApiParam(name = "content", value = "档案内容", required = true)
            @PathVariable(value = "content") String content,
            @ApiParam(name = "userId", value = "用户ID", required = true)
            @RequestParam(value = "userId") Integer userId,
            @ApiParam(name = "accessToken", value = "数据令牌", required = true)
            @RequestParam(value = "accessToken") String accessToken) {
        return content;
    }
    @RequestMapping(value = "/patient/storage/{orgCode}/{patientID}/{eventNo}", method = RequestMethod.POST)
    @ApiOperation(value = "采集病人健康档案", produces = "application/json", notes = "采集病人健康档案")
    public String storage(
            @ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
            @PathVariable(value = "apiVersion") String apiVersion,
            @ApiParam(name = "orgCode", value = "机构编码", required = true)
            @PathVariable(value = "orgCode") String orgCode,
            @ApiParam(name = "patientID", value = "病人ID", required = true)
            @PathVariable(value = "patientID") String patientID,
            @ApiParam(name = "eventNo", value = "事件号", required = true)
            @PathVariable(value = "eventNo") String eventNo,
            @ApiParam(name = "storageType", value = "保存类型", required = true)
            @PathVariable(value = "storageType") String storageType,
            @ApiParam(name = "content", value = "档案内容", required = true)
            @PathVariable(value = "content") String content) {
        return "";
    }
    @RequestMapping(value = "/patient/upload", method = RequestMethod.POST)
    @ApiOperation(value = "向总支撑平台上传病人档案", produces = "application/json", notes = "向总支撑平台上传病人档案")
    public RestEcho upload(
            @ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
            @PathVariable(value = "apiVersion") String apiVersion,
            @ApiParam(name = "patient", value = "病人索引信息", required = true)
            @RequestParam(value = "patient", required = true) String patientInfo,
            @ApiParam(name = "userId", value = "用户ID", required = true)
            @RequestParam(value = "userId") Integer userId,
            @ApiParam(name = "accessToken", value = "数据令牌", required = true)
            @RequestParam(value = "accessToken") String accessToken,
            HttpServletRequest request) {
        RestEcho restEcho = tokenValid(userId, accessToken);
        try {
            if (restEcho.getCode().asText().equals(Constants.OK)) {
                boolean result = false;
                Patient patient = DataCollectDispatcher.getInstance().parsePatient(patientInfo);
                if (patient != null) {
                    result = DataCollectDispatcher.getInstance().upload(patient);
                }
                if (!result) {
                    restEcho.failed(Constants.NO);
                } else {
                    restEcho.success();
                }
            } else {
                // token验证失败处理
                sendFailPatient(patientInfo, FlowType.AUTH_FAIL_UPLAOD);
            }
        } catch (IOException e) {
            restEcho.failed(Constants.NO);
            DebugLogger.error(LogAttribute.MARK_EXCEPTION,request,LogAttribute.FAIL,"CrawlerController上传异常", e);
        } catch (Exception e) {
            sendFailPatient(patientInfo, FlowType.AUTH_FAIL_UPLAOD);
            restEcho.failed(Constants.NO);
            DebugLogger.fatal(LogAttribute.MARK_EXCEPTION, request, LogAttribute.FAIL, "CrawlerController上传异常", e);
        }
        return restEcho;
    }
    @RequestMapping(value = "/patient/register", method = RequestMethod.POST)
    @ApiOperation(value = "向总支撑平台注册病人", produces = "application/json", notes = "向总支撑平台注册病人")
    public RestEcho register(
            @ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
            @PathVariable(value = "apiVersion") String apiVersion,
            @ApiParam(name = "patient", value = "病人索引信息", required = true)
            @RequestParam(value = "patient", required = true) String patientInfo,
            @ApiParam(name = "userId", value = "用户ID", required = true)
            @RequestParam(value = "userId") Integer userId,
            @ApiParam(name = "accessToken", value = "数据令牌", required = true)
            @RequestParam(value = "accessToken") String accessToken,
            HttpServletRequest request) {
        RestEcho restEcho = tokenValid(userId, accessToken);
        try {
            if (restEcho.getCode().asText().equals(Constants.OK)) {
                boolean result = false;
                Patient patient = DataCollectDispatcher.getInstance().parsePatient(patientInfo);
                if (patient != null) {
                    result = DataCollectDispatcher.getInstance().register(patient);
                }
                if (!result) {
                    restEcho.failed(Constants.NO);
                } else {
                    restEcho.success();
                }
            } else {
                // token验证失败处理
                sendFailPatient(patientInfo, FlowType.AUTH_FAIL_REGISTER);
            }
        } catch (IOException e) {
            restEcho.failed(Constants.NO);
            DebugLogger.error(LogAttribute.MARK_EXCEPTION, request, LogAttribute.FAIL, "CrawlerController注册异常", e);
        }  catch (Exception e) {
            sendFailPatient(patientInfo, FlowType.AUTH_FAIL_REGISTER);
            restEcho.failed(Constants.NO);
            DebugLogger.fatal(LogAttribute.MARK_EXCEPTION, request, LogAttribute.FAIL, "CrawlerController注册异常", e);
        }
        return restEcho;
    }
    @RequestMapping(value = "/security/saveFail", method = RequestMethod.POST)
    @ApiOperation(value = "安全认证失败病人保存", produces = "application/json", notes = "安全认证失败病人保存到队列")
    public RestEcho saveAuthFail(
    public Boolean crawler(
            @ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
            @PathVariable(value = "apiVersion") String apiVersion,
            @ApiParam(name = "patient", value = "病人索引信息", required = true)
            @RequestParam(value = "patient", required = true) String patientInfo) {
        RestEcho restEcho = new RestEcho();
        DebugLogger.debug("saveAuthFail");
        boolean succ= sendFailPatient(patientInfo, FlowType.AUTH_GEN_FAIL);
        if (succ){
            restEcho.success();
        }else {
            restEcho.failed(Constants.NO);
        Patient patient = CrawlerManager.getInstance().parsePatient(patientInfo);
        if (patient != null) {
            return CrawlerManager.getInstance().collectProcess(patient);
        }
        return restEcho;
        return false;
    }
    public boolean sendFailPatient(String patientInfo, String failType) {
        boolean result=false;
     try {
            ObjectMapper objectMapper = new ObjectMapper();
            ObjectNode rootNode = objectMapper.readValue(patientInfo, ObjectNode.class);
            rootNode.put(FlowType.AUTH_FAIL_TYPE, failType);
            String patient = rootNode.toString();
            ActiveMQHelper activeMQSender = new ActiveMQHelper();
            activeMQSender.sendJSONMessage(FlowType.AUTH_FAIL_PATIENT, patient);
            result=true;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
    @RequestMapping(value = "/patient/uploadLog", method = RequestMethod.POST)
    @ApiOperation(value = "向总支撑平台上传日志文件", produces = "application/json", notes = "向总支撑平台上传日志文件")
    public RestEcho uploadLog(
            @ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
            @PathVariable(value = "apiVersion") String apiVersion,
//            @ApiParam(name = "types", value = "日志类型", required = true)
//            @RequestParam(value = "types", required = true) String[] types,
            @ApiParam(name = "beginTime", value = "开始时间", required = true)
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime,
            @ApiParam(name = "userId", value = "用户ID", required = true)
            @RequestParam(value = "userId") Integer userId,
            @ApiParam(name = "accessToken", value = "数据令牌", required = true)
            @RequestParam(value = "accessToken") String accessToken,
            HttpServletRequest request) {
        RestEcho restEcho = tokenValid(userId, accessToken);
        SimpleDateFormat sdf=new SimpleDateFormat(DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        try {
            Date begin=sdf.parse(beginTime);
            Date end=sdf.parse(endTime);
            if (restEcho.getCode().asText().equals(Constants.OK)) {
                   boolean result = DataCollectDispatcher.getInstance().uploadLog(null,begin,end);
                if (!result) {
                    restEcho.failed(Constants.NO);
                } else {
                    restEcho.success();
                }
            } else {
                System.out.println("---------------");
                // TODO token验证失败处理
            }
        } catch (ParseException e) {
            restEcho.failed(Constants.NO);
            DebugLogger.fatal("CrawlerController日志上传异常", e);
        }
        return restEcho;
    }
}

+ 1 - 1
Hos-resource/src/main/java/com/yihu/ehr/crawler/model/adapter/AdapterDataSet.java

@ -1,6 +1,6 @@
package com.yihu.ehr.crawler.model.adapter;
import com.yihu.ehr.crawler.model.PatientIdentity;
import com.yihu.ehr.crawler.model.patient.PatientIdentity;
import com.yihu.ehr.framework.util.operator.CollectionUtil;
import com.yihu.ehr.framework.util.operator.StringUtil;
import com.yihu.ehr.standard.model.adapter.AdapterDatasetModel;

+ 0 - 30
Hos-resource/src/main/java/com/yihu/ehr/crawler/model/adapter/AdapterDict.java

@ -34,21 +34,6 @@ public class AdapterDict {
        return adapterDictModel != null;
    }
    public String getStdDictEntryValueByCode(String adapterEntryCode) {
        Map<String,String> condition = new HashMap<String,String>();
        condition.put("adapterDictId", StringUtil.toString(adapterDictModel.getId()));
        condition.put("adapterEntryCode", adapterEntryCode);
        JSONObject jsonpObject = JSONObject.fromObject(condition);
        List<AdapterDictEntryModel> adapterDictEntryModelList = adapterDictEntryService.getList(AdapterDictEntryModel.class, adapterVersion.getDictEntryTableName(), jsonpObject.toString(), null, null, null, null);
        if (!CollectionUtil.isEmpty(adapterDictEntryModelList)) {
            String stdDictEntryValue = adapterDictEntryModelList.get(0).getStdEntryValue();
            if (!StringUtil.isEmpty(stdDictEntryValue)) {
                return stdDictEntryValue;
            }
        }
        return new String(INVALID_ADAPTER_DICT);
    }
    public String getStdDictEntryCodeByValue(String adapterEntryValue) {
        Map<String,String> condition = new HashMap<String,String>();
        condition.put("adapterDictId", StringUtil.toString(adapterDictModel.getId()));
@ -78,19 +63,4 @@ public class AdapterDict {
        }
        return new String(INVALID_ADAPTER_DICT);
    }
    public String getStdDictEntryValueByValue(String adapterEntryValue) {
        Map<String,String> condition = new HashMap<String,String>();
        condition.put("adapterDictId", StringUtil.toString(adapterDictModel.getId()));
        condition.put("adapterEntryValue", adapterEntryValue);
        JSONObject jsonpObject = JSONObject.fromObject(condition);
        List<AdapterDictEntryModel> adapterDictEntryModelList = adapterDictEntryService.getList(AdapterDictEntryModel.class, adapterVersion.getDictEntryTableName(), jsonpObject.toString(), null, null, null, null);
        if (!CollectionUtil.isEmpty(adapterDictEntryModelList)) {
            String stdDictEntryValue = adapterDictEntryModelList.get(0).getStdEntryValue();
            if (!StringUtil.isEmpty(stdDictEntryValue)) {
                return stdDictEntryValue;
            }
        }
        return new String(INVALID_ADAPTER_DICT);
    }
}

+ 2 - 2
Hos-resource/src/main/java/com/yihu/ehr/crawler/model/adapter/AdapterMetaData.java

@ -1,7 +1,7 @@
package com.yihu.ehr.crawler.model.adapter;
import com.yihu.ehr.crawler.model.DictDataType;
import com.yihu.ehr.crawler.model.MetaDataType;
import com.yihu.ehr.crawler.model.transform.DictDataType;
import com.yihu.ehr.crawler.model.transform.MetaDataType;
import com.yihu.ehr.framework.constrant.ErrorCode;
import com.yihu.ehr.framework.util.operator.NumberUtil;
import com.yihu.ehr.standard.model.adapter.AdapterDictModel;

+ 89 - 166
Hos-resource/src/main/java/com/yihu/ehr/crawler/service/CrawlerManager.java

@ -1,19 +1,23 @@
package com.yihu.ehr.crawler.service;
import com.yihu.ehr.common.config.SysConfig;
import com.yihu.ehr.common.constants.Constants;
import com.yihu.ehr.dbhelper.jdbc.DBHelper;
import com.yihu.ehr.model.DataSource;
import com.yihu.ehr.model.Patient;
import com.yihu.ehr.model.entity.adapter.AdapterDataSet;
import com.yihu.ehr.model.entity.adapter.AdapterDataSetT;
import com.yihu.ehr.util.db.DBSessionFactory;
import com.yihu.ehr.util.httpclient.EsbHttp;
import com.yihu.ehr.util.log.LogUtil;
import org.json.JSONObject;
import java.sql.SQLException;
import java.util.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.crawler.model.adapter.AdapterDataSet;
import com.yihu.ehr.crawler.model.config.SysConfig;
import com.yihu.ehr.crawler.model.patient.Patient;
import com.yihu.ehr.framework.constrant.ErrorCode;
import com.yihu.ehr.framework.util.log.LogService;
import com.yihu.ehr.framework.util.operator.CollectionUtil;
import com.yihu.ehr.framework.util.operator.StringUtil;
import com.yihu.ehr.standard.model.adapter.AdapterDatasetModel;
import com.yihu.ehr.standard.service.adapter.AdapterDatasetService;
import com.yihu.ehr.standard.service.bo.AdapterVersion;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 标准管理,负责版本的升级,解包及相关安全
@ -21,14 +25,15 @@ import java.util.*;
 * @created Created by Air on 2015/6/3.
 */
public class CrawlerManager {
    private DBHelper db;
    @Resource(name = AdapterDatasetService.BEAN_ID)
    private AdapterDatasetService adapterDatasetService;
    private static volatile CrawlerManager instance;
    private static DataCollectDispatcher dispatch;
    private List<AdapterDataSet> adapterDataSetList;
    private List<DataSource> dataSourceList;
    private List<Patient> patientList;
    public CrawlerManager() {
        db = new DBHelper();
        dispatch = DataCollectDispatcher.getInstance();
    }
@ -53,174 +58,92 @@ public class CrawlerManager {
        return instance;
    }
    public void dataCrawlerFrequency() {
        List<JSONObject> versionList = db.query("select code from std_inner_version order by code desc");
        if(versionList==null)
        {
            LogUtil.info("标准数据还未初始化,请确认!");
            return;
        }
        String uuid = UUID.randomUUID().toString();
        Date lastCralwerTime = DateUtil.getSysDateTime();
        lastCralwerTime = DateUtil.formatYMDToYMDHMS(lastCralwerTime.toString());
        JSONObject json = db.load("select param_value from system_param where param_key = 'LAST_TIME'");
        if (!json.isNull("param_value") && !StringUtil.isEmpty(json.getString("param_value"))) {
            lastCralwerTime = DateUtil.formatYMDToYMDHMS(json.getString("param_value"));
        }
        Date current = DateUtil.fromatDateToTimestamp(DateUtil.getSysDateTime());
        db.execute("update system_param set param_value = '" + current.toString() + "'  where param_key = 'LAST_TIME'");
        LogUtil.info("采集任务开始!任务ID:" + uuid + ",采集时间:" + lastCralwerTime + "~" + current);
        if ((current.getTime() - lastCralwerTime.getTime()) <= 0) {
            LogUtil.info("采集不予执行,时间间隔小于或等于0!任务ID:" + uuid + ",采集时间:" + lastCralwerTime + "~" + current);
            return;
        }
        String message = dataCrawler(lastCralwerTime, current, uuid, 0);
        LogUtil.info("采集任务结束!任务ID:" + uuid + ",采集时间:" + lastCralwerTime + "~" + current + "\n" +message);
    }
    public void dataCrawlerSupply() {
        List<JSONObject> versionList = db.query("select code from std_inner_version order by code desc");
        if(versionList==null)
        {
            LogUtil.info("标准数据还未初始化,请确认!");
            return;
        }
        List<JSONObject> jsonList = db.query("select * from crawler_supply where status != 1");
        if (!CollectionUtil.isEmpty(jsonList)) {
            for (JSONObject json : jsonList) {
                String id = json.getString("id");
                db.execute("update crawler_supply set status = 2 where id = '"+id+"'");
                Date startTime = DateUtil.formatYMDToYMDHMS(json.getString("start_time"));
                Date endTime = DateUtil.formatYMDToYMDHMS(json.getString("end_time"));
                String message = "";
                if(startTime!=null && endTime!=null) {
                    LogUtil.info("补采任务开始!任务ID:" + id + ",采集时间:" + startTime + "~" + endTime);
                    if ((endTime.getTime() - startTime.getTime()) <= 0) {
                        LogUtil.info("补采任务提前结束,时间间隔小于或等于0!任务ID:" + id + ",采集时间:" + startTime + "~" + endTime);
                        changeFillMiningStatus(json, "补采任务提前结束,时间间隔小于或等于0!");
                        return;
                    }
                    message = dataCrawler(startTime, endTime, id, 1);
                    LogUtil.info("补采任务结束!任务ID:" + id + ",采集时间:" + startTime + "~" + endTime + "\n" + message);
                }
                else{
                    message = "采集时间范围:" + startTime + "~" + endTime + "无效!";
                    LogUtil.info(message);
                }
                if (!StringUtil.isEmpty(message)) {
                    changeFillMiningStatus(json, message);
                }
            }
        }
    }
    public void changeFillMiningStatus(JSONObject json, String message) {
        String id = json.getString("id");
        db.execute("update crawler_supply set status = 1 where id = '"+id+"'");
        if (!json.isNull("remote_id") && !StringUtil.isEmpty(json.getString("remote_id"))) {
            EsbHttp.changeFillMiningStatus(json.getString("remote_id"), message, "1");
        }
    }
    public synchronized String dataCrawler(Date begin, Date end, String taskId, int type) {
        if (SysConfig.getInstance().isEmptyOrgCode()) {
            return "本次任务执行失败,机构代码为空";
        }
    public String dataCrawler() {
        Integer count = 0;
        Integer totalCount = 0;
        getAdapterDataSetList();
        getDataSourceList();
        Map<String, Object> condition = new HashMap<>();
        condition.put("beginDate", begin);
        condition.put("endDate", end);
        condition.put("orgCode", SysConfig.getInstance().orgCode);
        Map<String, DBSessionFactory> dataSourceMap = new HashMap<>();
        patientList = dispatch.getPatientList(condition, adapterDataSetList);
        if (!CollectionUtil.isEmpty(patientList)) {
            totalCount = patientList.size();
            for (Patient patient : patientList) {
                collectProcess(patient);
            }
        }
        String message = "本次采集病人共" + totalCount + "条,成功采集信息"+ count + "条";
        LogService.getLogger().info(message);
        return message;
    }
    public Boolean collectProcess(Patient patient) {
        if (!dispatch.getToken()) {
            return false;
        }
        patient.setReUploadFlg(StringUtil.toString(false));
        LogService.getLogger().trace("采集->注册->打包上传,任务ID:,patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo());
        try {
            if (!CollectionUtil.isEmpty(dataSourceList)) {
                for (DataSource dataSource : dataSourceList) {
                    String name = dataSource.getName();
                    String config = dataSource.getConfig();
                    DBSessionFactory.addDataSource(name, config);
                    DBSessionFactory dbSessionFactory = new DBSessionFactory(name);
                    dataSourceMap.put(dataSource.getId(), dbSessionFactory);
            Map<String, AdapterDataSet> dataSetMap = new HashMap<>();
            List<JsonNode> dataList = new ArrayList<>();
            //采集、注册
            for (AdapterDataSet adapterDataSet : adapterDataSetList) {
                String data = dispatch.fecthData(patient, adapterDataSet);
                ObjectMapper objectMapper = new ObjectMapper();
                JsonNode jsonObject = objectMapper.readTree(data);
                if (!StringUtil.isEmpty(data)) {
                    dataSetMap.put(adapterDataSet.getAdapterDataSetT().getStdDatasetCode(), adapterDataSet);
                    dataList.add(jsonObject);
                }
                patientList = dispatch.getPatientQueue(condition, adapterDataSetList, dataSourceMap);
                if (!CollectionUtil.isEmpty(patientList)) {
                    totalCount = patientList.size();
                    for (Patient patient : patientList) {
                        String token;
                        try {
                            token = EsbHttp.getToken();
                        } catch (Exception e) {
                            LogUtil.error("本次任务执行失败,获取token失败!");
                            return "本次任务执行失败,获取token失败!";
                        }
                        if (type == 1) {
                            patient.setReUploadFlg(StringUtil.toString(true));
                        } else {
                            patient.setReUploadFlg(StringUtil.toString(false));
                        }
                        LogUtil.trace("采集->注册->打包上传,任务ID:"+taskId+",patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo());
                        // COLLECT->REGISTER->UPLOAD
                        Boolean result = dispatch.collectData(patient, adapterDataSetList, dataSourceMap, token);
                        SqlCreate sqlCreate = new SqlCreate();
                        sqlCreate.setTableName("task_track");
                        Map<String, String> keyValueMap = new HashMap<>();
                        UUID uuid = UUID.randomUUID();
                        keyValueMap.put("id", Constants.SINGLE_QUOTE_MARK + uuid.toString() + Constants.SINGLE_QUOTE_MARK);
                        keyValueMap.put("patient_id", Constants.SINGLE_QUOTE_MARK + patient.getPatientId() + Constants.SINGLE_QUOTE_MARK);
                        keyValueMap.put("event_no", Constants.SINGLE_QUOTE_MARK + patient.getEventNo() + Constants.SINGLE_QUOTE_MARK);
                        keyValueMap.put("crawler_time", Constants.SINGLE_QUOTE_MARK + DateUtil.getCurrentString(DateUtil.DEFAULT_YMDHMSDATE_FORMAT) + Constants.SINGLE_QUOTE_MARK);
                        if (result) {
                            keyValueMap.put("status", "1");
                            ++count;
                        } else {
                            keyValueMap.put("status", "0");
                if (SysConfig.getInstance().getRegisterDataSet().equals(adapterDataSet.getAdapterDataSetT().getStdDatasetCode())) {
                    if (!StringUtil.isEmpty(jsonObject.get("data")) && !StringUtil.isEmpty(jsonObject.get("data").get(0))) {
                        if (!StringUtil.isEmpty(jsonObject.get("data").get(0).get(SysConfig.getInstance().getRegisterIdCardNo()))) {
                            dispatch.register(patient, data);
                        }
                        sqlCreate.setKeyValueMap(keyValueMap);
                        db.execute(sqlCreate.insertDataByKeyValue());
                    }
                }
            }
        } catch (Exception e) {
            LogUtil.error(e);
            return null;
        } finally {
            for(String key : dataSourceMap.keySet()) {
                DBSessionFactory dbSessionFactory = dataSourceMap.get(key);
                try {
                    dbSessionFactory.close();
                } catch (SQLException e) {
                    LogUtil.error(e);
                    return null;
            LogService.getLogger().info("采集病人成功,patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo());
            //上传档案
            try {
                if (!CollectionUtil.isEmpty(dataList)) {
                    if (!dispatch.upload(dataList, patient, dataSetMap)) {
                        return false;
                    }
                }
            } catch (Exception e) {
                LogService.getLogger().error("档案上传失败,patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo());
                return false;
            }
        } catch (Exception e) {
            LogService.getLogger().error("采集病人失败,patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo(), e);
            return false;
        }
        String message = "本次采集病人共" + totalCount + "条,成功采集信息"+ count + "条";
        LogUtil.info(message);
        return message;
        return true;
    }
    public void getAdapterDataSetList() {
        adapterDataSetList = new ArrayList<>();
        List<JSONObject> dataSetList = db.query("select id, std_dataset_id, std_dataset_code, org_dataset_code from adapter_dataset");
        for (JSONObject json : dataSetList) {
            AdapterDataSetT datasetT = new AdapterDataSetT();
            datasetT.setId(json.getInt("id"));
            datasetT.setStdDatasetCode(json.getString("std_dataset_code"));
            datasetT.setStdDatasetId(json.getInt("std_dataset_id"));
            if (!json.isNull("org_dataset_code")) {
                datasetT.setOrgDatasetCode(json.getString("org_dataset_code"));
            }
            adapterDataSetList.add(new AdapterDataSet(datasetT, db));
        String version = "569f253c1cb3";
        AdapterVersion adapterVersion = new AdapterVersion(version);
        List<AdapterDatasetModel> adapterDataSetModelList = adapterDatasetService.getList(AdapterDatasetModel.class, adapterVersion.getDataSetTableName(), null, null, null, null, ErrorCode.GetDataSetFailed);
        for (AdapterDatasetModel adapterDatasetModel : adapterDataSetModelList) {
            adapterDataSetList.add(new AdapterDataSet(adapterDatasetModel, adapterVersion));
        }
    }
    public void getDataSourceList() {
        dataSourceList = db.query(DataSource.class, "select * from system_datasource");
    /**
     * 解析病人索引信息
     *
     * @param patientInfo 病人索引信息
     * @return
     */
    public Patient parsePatient(String patientInfo) {
        try {
            ObjectMapper mapper = new ObjectMapper();
            Patient patient = mapper.readValue(patientInfo, Patient.class);
            return patient;
        } catch (Exception e) {
            LogService.getLogger().error("patient参数错误:" + patientInfo, e);
            return null;
        }
    }
}

+ 204 - 119
Hos-resource/src/main/java/com/yihu/ehr/crawler/service/DataCollectDispatcher.java

@ -2,31 +2,34 @@ package com.yihu.ehr.crawler.service;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.ehr.common.config.SysConfig;
import com.yihu.ehr.common.constants.Constants;
import com.yihu.ehr.model.Patient;
import com.yihu.ehr.model.PatientIdentity;
import com.yihu.ehr.model.entity.adapter.AdapterDataSet;
import com.yihu.ehr.service.patient.PatientCDAIndex;
import com.yihu.ehr.service.patient.PatientCDAUpload;
import com.yihu.ehr.util.db.DBSessionFactory;
import com.yihu.ehr.util.file.FileUtil;
import com.yihu.ehr.util.httpclient.EsbHttp;
import com.yihu.ehr.util.log.LogUtil;
import com.yihu.ehr.util.operator.CollectionUtil;
import com.yihu.ehr.util.operator.StringUtil;
import com.yihu.ehr.crawler.model.adapter.AdapterDataSet;
import com.yihu.ehr.crawler.model.adapter.AdapterMetaData;
import com.yihu.ehr.crawler.model.config.SysConfig;
import com.yihu.ehr.crawler.model.patient.Patient;
import com.yihu.ehr.crawler.model.patient.PatientIdentity;
import com.yihu.ehr.crawler.model.transform.EhrCondition;
import com.yihu.ehr.crawler.model.transform.LogicValues;
import com.yihu.ehr.framework.constrant.Constants;
import com.yihu.ehr.framework.util.file.FileUtil;
import com.yihu.ehr.framework.util.httpclient.HttpClientUtil;
import com.yihu.ehr.framework.util.httpclient.HttpResponse;
import com.yihu.ehr.framework.util.log.LogService;
import com.yihu.ehr.framework.util.operator.DateUtil;
import com.yihu.ehr.framework.util.operator.StringUtil;
import com.yihu.ehr.standard.model.adapter.AdapterMetadataModel;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.*;
public class DataCollectDispatcher {
    public static String registerMethod;
    private static DataCollectDispatcher ourInstance = new DataCollectDispatcher();
    private String token;
    private DataCollectDispatcher() {
    }
@ -38,79 +41,214 @@ public class DataCollectDispatcher {
    }
    public Boolean getToken () {
        try {
            this.token = EsbHttp.getToken();
            return true;
        } catch (Exception e) {
            LogService.getLogger().error("本次任务执行失败,获取token失败!");
            return false;
        }
    }
    /**
     * @param patient 病人
     * @return true-采集成功,false-采集失败
     * 获取病人列表
     *
     * @param condition
     * @return List<PatientT>
     */
    public Boolean collectData(Patient patient, List<AdapterDataSet> adapterDataSetList, Map<String, DBSessionFactory> dataSourceMap, String token) {
        Boolean result = true;
        Map<String, AdapterDataSet> dataSetMap = new HashMap<>();
        List<ObjectNode> dataList = new ArrayList<>();
        try {
            for (String key : dataSourceMap.keySet()) {
                DBOrigin dataCollector = new DBOrigin();
                if (dataCollector == null) {
                    LogUtil.fatal("采集数据:无法获取采集数据源.");
                    continue;
    public List<Patient> getPatientList(Map<String, Object> condition, List<AdapterDataSet> adapterDataSetList) {
        ArrayList<Patient> patientList = new ArrayList<>();
        SimpleDateFormat df = new SimpleDateFormat(DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        for (AdapterDataSet adapterDataSet : adapterDataSetList) {
            PatientIdentity patientIdentity = SysConfig.getInstance().getPatientIdentity(adapterDataSet.getAdapterDataSetT().getStdDatasetCode());
            if (patientIdentity == null) {
                continue;
            }
            try {
                //获取病人列表字段检验
                Map<String, String> propertyMap = getItemList(adapterDataSet);
                if (propertyMap == null) {
                    return patientList;
                }
                for (AdapterDataSet adapterDataSet : adapterDataSetList) {
                    //采集病人信息
                    ObjectNode jsonObject = dataCollector.fecthData(patient, dataSourceMap.get(key), adapterDataSet);
                    if (jsonObject == null) {
                        continue;
                    }
                //请求参数
                Date beginDate = (Date) condition.get("beginDate");
                String beginTime = df.format(beginDate);
                Date endDate = (Date) condition.get("endDate");
                String endTime = df.format(endDate);
                List<EhrCondition> queryParams = new ArrayList<>();
                queryParams.add(new EhrCondition(" > ", patientIdentity.getRefTimeCode(), beginTime));
                queryParams.add(new EhrCondition(" < ", patientIdentity.getRefTimeCode(), endTime));
                    if (jsonObject != null && !StringUtil.isEmpty(jsonObject)) {
                        dataSetMap.put(adapterDataSet.getAdapterDataSetT().getStdDatasetCode(), adapterDataSet);
                        dataList.add(jsonObject);
                    }
                    //注册病人
                    if (SysConfig.getInstance().getRegisterDataSet().equals(adapterDataSet.getAdapterDataSetT().getStdDatasetCode())) {
                        if (!StringUtil.isEmpty(jsonObject.get("data")) && !StringUtil.isEmpty(jsonObject.get("data").get(0))) {
                            if (!StringUtil.isEmpty(jsonObject.get("data").get(0).get(SysConfig.getInstance().getRegisterIdCardNo()))) {
                                register(patient, StringUtil.toString(jsonObject), token);
                            }
                        }
                //Rest 接口请求
                String rootStr = EsbHttp.getPatientList(adapterDataSet, queryParams);
                if (StringUtil.isEmpty(rootStr)) {
                    return null;
                }
                ObjectMapper mapper = new ObjectMapper();
                JsonNode resultNode = mapper.readValue(rootStr, JsonNode.class);
                JsonNode patientNode = resultNode.path("detailModelList");
                boolean isArr = patientNode.isArray();
                if (isArr) {
                    Iterator<JsonNode> array = patientNode.iterator();
                    while (array.hasNext()) {
                        JsonNode node = array.next();
                        Patient patientT = new Patient();
                        String patientId = node.path(propertyMap.get("patient_id")).asText();
                        String eventNo = node.path(propertyMap.get("event_no")).asText();
                        String refTime = node.path(propertyMap.get("event_time")).asText();
                        patientT.setPatientId(patientId);
                        patientT.setEventNo(eventNo);
                        patientT.setReferenceTime(refTime);
                        patientList.add(patientT);
                    }
                }
            } catch (Exception e) {
                LogService.getLogger().error("采集病人失败", e);
            }
            LogUtil.info("采集病人成功,patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo());
        } catch (Exception e) {
            LogUtil.error("采集病人失败,patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo());
            LogUtil.error(e);
            result = false;
        }
        //上传档案
        return patientList;
    }
    public Map<String, String> getItemList(AdapterDataSet adapterDataSet) throws Exception {
        Map<String, String> propertyMap = new HashMap<>();
        PatientIdentity patientIdentity = SysConfig.getInstance().getPatientIdentity(adapterDataSet.getAdapterDataSetT().getStdDatasetCode());
        if (adapterDataSet.isHavePatientID()) {
            AdapterMetaData adapterMetaData = adapterDataSet.getAdapterMetaDataMap().get(PatientIdentity.getPatientIDCode());
            propertyMap.put("patient_id", adapterMetaData.getStdMetaDataModel().getCode().toUpperCase());
        } else {
            LogService.getLogger().error("", new Exception("采集病人列表数据集必须有patient_id."));
            return null;
        }
        if (adapterDataSet.isHaveEventNo()) {
            AdapterMetaData adapterMetaData = adapterDataSet.getAdapterMetaDataMap().get(patientIdentity.getEventNoCode());
            propertyMap.put("event_no",  adapterMetaData.getStdMetaDataModel().getCode().toUpperCase());
        } else {
            LogService.getLogger().error("采集病人列表数据集必须有event_no.");
            return null;
        }
        AdapterMetaData adapterRefMetaData = adapterDataSet.getAdapterMetaDataMap().get(patientIdentity.getRefTimeCode());
        if (adapterRefMetaData == null) {
            LogService.getLogger().error("采集病人列表数据集必须有采集时间.");
            return null;
        }
        propertyMap.put("event_time", adapterRefMetaData.getStdMetaDataModel().getCode().toUpperCase());
        return propertyMap;
    }
    public String fecthData(Patient patient, AdapterDataSet adapterDataSet) {
        try {
            if (!CollectionUtil.isEmpty(dataList)) {
                if (!upload(dataList, patient, dataSetMap, token)) {
                    result = false;
            ObjectMapper mapper = new ObjectMapper();
            List<EhrCondition> queryParams = new ArrayList<>();
            boolean patientId = true;
            if (adapterDataSet.isHavePatientID()) {
                AdapterMetaData adapterMetaData = adapterDataSet.getAdapterMetaDataMap().get(PatientIdentity.getPatientIDCode());
                queryParams.add(new EhrCondition(" = ", adapterMetaData.getStdMetaDataModel().getCode(), patient.getPatientId()));
            } else {
                patientId = false;
            }
            boolean eventNo = true;
            if (adapterDataSet.isHaveEventNo()) {
                AdapterMetaData adapterMetaData = adapterDataSet.getAdapterMetaDataMap().get(adapterDataSet.getEventNoCode());
                queryParams.add(new EhrCondition(" = ", adapterMetaData.getStdMetaDataModel().getCode(), patient.getEventNo()));
            } else {
                eventNo = false;
            }
            if (!patientId && !eventNo) {
                LogService.getLogger().error("采集病人数据集至少需要一项病人标识.数据集名:" + adapterDataSet.getAdapterDataSetT().getStdDatasetCode());
                throw new Exception("采集病人数据集至少需要一项病人标识.数据集名:" + adapterDataSet.getAdapterDataSetT().getStdDatasetCode());
            }
            ObjectNode paramsNode = mapper.createObjectNode();
            paramsNode.put("tableCode", adapterDataSet.getAdapterDataSetT().getStdDatasetCode());
            paramsNode.put("condition", mapper.writeValueAsString(queryParams));
            List<NameValuePair> formParams = new ArrayList<>();
//            formParams.add(new BasicNameValuePair("secret", secret));
            formParams.add(new BasicNameValuePair("api", "collectionData"));
            formParams.add(new BasicNameValuePair("param", mapper.writeValueAsString(paramsNode)));
            String rootStr = EsbHttp.getFecthData(formParams);
            JsonNode resultNode = mapper.readValue(rootStr, JsonNode.class);
            JsonNode result = resultNode.path("detailModelList");
            JsonNode data = matchAdapterData(result, adapterDataSet);
            ObjectNode jsonObject = mapper.createObjectNode();
            if (data != null && data.size() > 0) {
                jsonObject.set("data", data);
                jsonObject.put("code", adapterDataSet.getAdapterDataSetT().getStdDatasetCode());
                jsonObject.put("patient_id", patient.getPatientId());
                jsonObject.put("event_no", patient.getEventNo());
                String agencyCode = patient.getOrgCode();
                jsonObject.put("org_code", agencyCode);
                jsonObject.put("inner_version", "123456");
                jsonObject.put("create_date", DateUtil.toString(new Date(), DateUtil.DEFAULT_YMDHMSDATE_FORMAT));
                jsonObject.put("event_time", patient.getReferenceTime());//DateUtil.toString(patient.getReferenceTime(), DateUtil.DEFAULT_YMDHMSDATE_FORMAT)
                if (StringUtil.isEmpty(patient.getReUploadFlg())) {
                    jsonObject.put("reUploadFlg", LogicValues.LOGIC_FALSE);
                } else {
                    jsonObject.put("reUploadFlg", patient.getReUploadFlg());
                }
                return jsonObject.toString();
            } else {
                return null;
            }
        } catch (Exception e) {
            result = false;
            LogUtil.error("档案上传失败,patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo());
            LogService.getLogger().error("", e);
        }
        return null;
    }
    public JsonNode matchAdapterData(JsonNode data, AdapterDataSet adapterDataSet) {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode dataNode = null;
        ArrayNode result = mapper.createArrayNode();
        List<AdapterMetaData> metaDatas = adapterDataSet.getAdapterMetaDataList();
        Iterator<JsonNode> array = data.iterator();
        while (array.hasNext()) {
            dataNode = array.next();
            ObjectNode jsonNode = mapper.createObjectNode();
            for (AdapterMetaData adapterMetaData : metaDatas) {
                AdapterMetadataModel adapterMetadataModel = adapterMetaData.getAdapterMetadataModel();
                String orgMetaDataCode = adapterMetadataModel.getAdapterMetadataCode();
                String stdMetaDataCode = adapterMetadataModel.getStdMetadataCode();
                jsonNode.put(stdMetaDataCode, dataNode.path(orgMetaDataCode).asText());
            }
            result.add(jsonNode);
        }
        return result;
    }
    public Boolean upload(List<ObjectNode> dataList, Patient patient, Map<String, AdapterDataSet> dataSetMap, String token) {
    public Boolean register(Patient patient, String data) {
        return EsbHttp.register(patient, data, token);
    }
    public Boolean upload(List<JsonNode> dataList, Patient patient, Map<String, AdapterDataSet> dataSetMap) {
        Boolean result = true;
        try {
            DataSetTransformer dataTransformer = new DataSetTransformer();
            for (ObjectNode data : dataList) {
            for (JsonNode data : dataList) {
                dataTransformer.setData(data);
                if (!toFile(dataTransformer, patient, "origin")) {
                    LogUtil.fatal("存储原始文件失败:patient_id=" + patient.getPatientId()
                            +"event_no=" + patient.getEventNo());
                    LogService.getLogger().info("存储原始文件失败:patient_id=" + patient.getPatientId()
                            + "event_no=" + patient.getEventNo());
                    result = false;
                    break;
                }
                dataTransformer.transfer(dataSetMap);
                if (!toFile(dataTransformer, patient, "standard")) {
                    LogUtil.fatal("存储标准文件失败:patient_id=" + patient.getPatientId()
                    LogService.getLogger().info("存储标准文件失败:patient_id=" + patient.getPatientId()
                            + "event_no=" + patient.getEventNo());
                    result = false;
                    break;
@ -127,71 +265,18 @@ public class DataCollectDispatcher {
    }
    public boolean toFile(DataSetTransformer dataTransformer, Patient patient, String fileName) {
        ObjectNode jsonObject = dataTransformer.getJsonObject();
        JsonNode jsonObject = dataTransformer.getJsonObject();
        PatientCDAIndex patientCDAIndex = new PatientCDAIndex(patient);
        String filePath = patientCDAIndex.createDataIndex(fileName, PatientCDAIndex.FileType.JSON);
        boolean writeFile = false;
        try {
            writeFile = FileUtil.writeFile(filePath, jsonObject.toString(), "UTF-8");
        } catch (IOException e) {
            LogUtil.fatal("存储临时文件失败.");
            LogUtil.error(e);
            LogService.getLogger().info("存储临时文件失败.");
            LogService.getLogger().error("", e);
        }
        return writeFile;
    }
    /**
     * @param patient
     * @return boolean
     * 注册不是否成功 统一返回true
     */
    public Boolean register(Patient patient, String data, String token) {
        return EsbHttp.register(patient, data, token);
    }
    /**
     * @param condition 查询条件
     * @return 病人列表
     */
    public List<Patient> getPatientQueue(Map<String, Object> condition, List<AdapterDataSet> adapterDataSetList, Map<String, DBSessionFactory> dataSourceMap) {
        List<Patient> patientList = new ArrayList<>();
        DBOrigin dbOrigin = new DBOrigin();
        for(String key : dataSourceMap.keySet()) {
            DBSessionFactory dbSessionFactory = dataSourceMap.get(key);
            for (AdapterDataSet adapterDataSet : adapterDataSetList) {
                PatientIdentity patientIdentity = SysConfig.getInstance().getPatientIdentity(adapterDataSet.getAdapterDataSetT().getStdDatasetCode());
                if (patientIdentity == null) {
                    continue;
                }
                List<Patient> patients = dbOrigin.getPatientList(dbSessionFactory, key, adapterDataSet, condition);
                if (patients == null) {
                    return null;
                }
                if (patients.size() > 0) {
                    patientList.addAll(patients);
                }
            }
        }
        return patientList;
    }
    /**
     * 解析病人索引信息
     *
     * @param patientInfo 病人索引信息
     * @return
     */
    public Patient parsePatient(String patientInfo) throws IOException {
        Patient patient = null;
        ObjectMapper mapper = new ObjectMapper();
        JsonNode rootNode = null;
        patient = new Patient();
        patient = mapper.readValue(patientInfo, Patient.class);
        return patient;
    }
    /**
     * 解析token内容

+ 14 - 37
Hos-resource/src/main/java/com/yihu/ehr/crawler/service/DataSetTransformer.java

@ -3,14 +3,13 @@ package com.yihu.ehr.crawler.service;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.ehr.common.constants.DictDataType;
import com.yihu.ehr.common.constants.TransformType;
import com.yihu.ehr.crawler.model.adapter.AdapterDataSet;
import com.yihu.ehr.crawler.model.adapter.AdapterDict;
import com.yihu.ehr.crawler.model.adapter.AdapterMetaData;
import com.yihu.ehr.crawler.model.patient.Patient;
import com.yihu.ehr.crawler.model.transform.DictDataType;
import com.yihu.ehr.crawler.model.transform.TransformType;
import com.yihu.ehr.dbhelper.jdbc.DBHelper;
import com.yihu.ehr.model.Patient;
import com.yihu.ehr.model.entity.adapter.AdapterDataSet;
import com.yihu.ehr.model.entity.adapter.AdapterDict;
import com.yihu.ehr.model.entity.adapter.AdapterMetaData;
import com.yihu.ehr.service.standard.StandardManager;
import java.util.Iterator;
import java.util.Map;
@ -32,10 +31,10 @@ import java.util.Map;
 * Created by Air on 2015/6/4.
 */
public class DataSetTransformer {
    private ObjectNode jsonObject;
    private JsonNode jsonObject;
    private Patient patient;
    private static DBHelper db;
    public ObjectNode getJsonObject() {
    public JsonNode getJsonObject() {
        return jsonObject;
    }
@ -60,12 +59,10 @@ public class DataSetTransformer {
    public String getData() {
        //确保文档有版本信息
        StandardManager standardManager = StandardManager.getInstance();
        jsonObject.put("inner_version", standardManager.getCurrentVersion());
        return jsonObject.asText();
    }
    public void setData(ObjectNode data) {
    public void setData(JsonNode data) {
        jsonObject = data;
        setPatient();
    }
@ -126,36 +123,16 @@ public class DataSetTransformer {
        Map<String, AdapterMetaData> adapterMetaDataMap = adapterDataSet.getAdapterMetaDataMap();
        AdapterMetaData adapterMetaData = adapterMetaDataMap.get(code);
        AdapterDict adapterDict = adapterMetaData.getAdapterDict();
//        StdMetaDataT metaDataT = adapterMetaData.getStdMetaDataT();
//        if (adapterDict == null || !adapterDict.isValidAdapterDict()) {
//            MetaDataVerify metaDataVerify = new MetaDataVerify(metaDataT, data);
//            boolean check = metaDataVerify.check();
//            if (!check) {
//                LogUtil.fatal("保存:数据元校验错误." + metaDataVerify.getErrorInfo());
//                return null;    //未校验成功数据,清空
//            }
//
//            return data;
//        }
        if (adapterDict == null) {
            return data;
        }
        String stdData = null;
        DictDataType stdDictDataType = adapterMetaData.getStdDictDataType();
        DictDataType orgDictDataType = adapterMetaData.getOrgDictDataType();
        if (stdDictDataType == DictDataType.VALUE) {
            if (orgDictDataType == DictDataType.VALUE) {
                stdData = adapterDict.getStdDictItemValueByValue(data);
            } else if (orgDictDataType == DictDataType.CODE) {
                stdData = adapterDict.getStdDictItemValueByCode(data);
            }
        } else if (stdDictDataType == DictDataType.CODE) {
            if (orgDictDataType == DictDataType.VALUE) {
                stdData = adapterDict.getStdDictItemCodeByValue(data);
            } else if (orgDictDataType == DictDataType.CODE) {
                stdData = adapterDict.getStdDictItemCodeByCode(data);
            }
        DictDataType adapterDictDataType = adapterMetaData.getAdapterDictDataType();
        if (adapterDictDataType == DictDataType.VALUE) {
            stdData = adapterDict.getStdDictEntryCodeByValue(data);
        } else if (adapterDictDataType == DictDataType.CODE) {
            stdData = adapterDict.getStdDictEntryCodeByCode(data);
        }
        return stdData;
    }

+ 104 - 69
Hos-resource/src/main/java/com/yihu/ehr/crawler/service/EsbHttp.java

@ -1,18 +1,22 @@
package com.yihu.ehr.crawler.service;
import com.yihu.ehr.common.config.SysConfig;
import com.yihu.ehr.common.constants.Constants;
import com.yihu.ehr.model.Patient;
import com.yihu.ehr.service.intf.ISystemManager;
import com.yihu.ehr.util.encrypt.MD5;
import com.yihu.ehr.util.log.LogUtil;
import com.yihu.ehr.util.operator.ConfigureUtil;
import com.yihu.ehr.util.operator.StringUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.ehr.crawler.model.adapter.AdapterDataSet;
import com.yihu.ehr.crawler.model.config.SysConfig;
import com.yihu.ehr.crawler.model.patient.Patient;
import com.yihu.ehr.crawler.model.transform.EhrCondition;
import com.yihu.ehr.framework.util.encrypt.MD5;
import com.yihu.ehr.framework.util.httpclient.HttpClientUtil;
import com.yihu.ehr.framework.util.httpclient.HttpHelper;
import com.yihu.ehr.framework.util.httpclient.HttpResponse;
import com.yihu.ehr.framework.util.log.LogService;
import com.yihu.ehr.framework.util.operator.StringUtil;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import sun.misc.BASE64Encoder;
import java.io.File;
@ -26,14 +30,11 @@ import java.util.Map;
 */
public class EsbHttp {
    @Autowired
    private static ISystemManager system;
    /***************************** 用户接口 *********************************************/
    /**
     * 用户登录验证
     */
    public static Response loginAction(String user,String password) throws Exception{
    public static HttpResponse loginAction(String user, String password) throws Exception{
        String loginAction = HttpHelper.defaultHttpUrl+"/authorizations/users/" + user;
        Map<String,Object> header = new HashMap<>();
        String auth  = new BASE64Encoder().encode((user+":"+password).getBytes());
@ -44,7 +45,7 @@ public class EsbHttp {
    /*
    *   获取用户信息
    * */
    public static Response getUserInfo(String user,String token)
    public static HttpResponse getUserInfo(String user,String token)
    {
        String url = HttpHelper.defaultHttpUrl+"/users/" + user;
        Map<String,Object> params = new HashMap<>();
@ -61,7 +62,7 @@ public class EsbHttp {
     */
    private static String GetFingerprint(){
        try {
            return system.getSystemParam("FINGER_PRINT");
            return "";
        }
        catch (Exception e)
        {
@ -82,14 +83,14 @@ public class EsbHttp {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("info", "{\"fingerprint\": \"" + GetFingerprint() + "\"}");
            Response response = HttpHelper.put(loginAction, params, header);
            HttpResponse response = HttpHelper.put(loginAction, params, header);
            if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
                JSONObject obj = new JSONObject(response.getBody());
                //判断是否成功
                if (obj.has("token")) {
                    return obj.getString("token");
                } else {
                    LogUtil.info("返回未包含token。");
                    LogService.getLogger().info("返回未包含token。");
                    return null;
                }
            } else {
@ -98,52 +99,86 @@ public class EsbHttp {
                if (response != null) {
                    msg += "(错误代码:" + response.getStatusCode() + ",错误信息:" + response.getBody() + ")";
                }
                LogUtil.info(msg);
                LogService.getLogger().info(msg);
                return null;
            }
        }
        catch (Exception ex)
        {
            LogUtil.info("获取Token失败," + ex.getMessage());
            LogService.getLogger().info("获取Token失败," + ex.getMessage());
            return null;
        }
    }
    /**
     * 修改远程补传状态
     * 获取病人列表
     */
    public static void changeFillMiningStatus(String remoteId,String message, String status){
    public static String getPatientList(AdapterDataSet adapterDataSet, List<EhrCondition> queryParams){
        try {
            String token = getToken();
            Map<String, Object> paramMap = new HashMap<>();
            paramMap.put("id", remoteId);
            paramMap.put("status", status);
            paramMap.put("message", message);
            paramMap.put("token", token);
            String fillMiningMethod = HttpHelper.defaultHttpUrl + "/simplified-esb/changeFillMiningStatus";
            Response response = HttpHelper.post(fillMiningMethod, paramMap);
            if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
                LogUtil.info("修改远程补传状态成功。");
            ObjectMapper mapper = new ObjectMapper();
            ObjectNode paramsNode = mapper.createObjectNode();
            paramsNode.put("tableCode", adapterDataSet.getAdapterDataSetT().getStdDatasetCode());
            paramsNode.put("condition", mapper.writeValueAsString(queryParams));
            List<NameValuePair> formParams = new ArrayList<>();
            formParams.add(new BasicNameValuePair("api", "collectionData"));
            String params = mapper.writeValueAsString(paramsNode);
            formParams.add(new BasicNameValuePair("param", params));
            HttpResponse response = HttpClientUtil.postForm(HttpHelper.httpGateway, formParams);
            if (response == null || response.getStatusCode() != 200) {
                LogService.getLogger().error("获取病人列表错误,请求HTTP错误,请检查配置或HTTP是否可用.");
                return "";
            }
            else{
                String msg = "修改远程补传状态失败。";
                if (response != null)
                {
                    msg +="(错误代码:"+ response.getStatusCode() + ",错误信息:"+response.getBody()+")";
                }
                LogUtil.info(msg);
            JsonNode responseNode = mapper.readValue(response.getBody(), JsonNode.class);
            String code = responseNode.path("responseCode").asText();
            if (StringUtil.isEmpty(code) || !code.equals("10000")) {
                LogService.getLogger().error("获取病人列表错误,请求HTTP错误,请检查集成平台网关是否可用.");
                return "";
            }
        }
        catch (Exception ex)
        {
            LogUtil.info("修改远程补传状态失败." + ex.getMessage());
            String rootStr = responseNode.path("responseParams").asText();
            if ("".equals(rootStr)) {
                LogService.getLogger().error("获取病人列表错误,集成平台获取病人列表失败.");
                return "";
            }
            return rootStr;
        } catch (Exception e) {
            LogService.getLogger().error("获取病人列表失败!", e);
            return "";
        }
    }
    /**
     * 获取公钥
     */
    public static String getFecthData(List<NameValuePair> formParams) {
        try {
            HttpResponse response = HttpClientUtil.postForm(HttpHelper.httpGateway, formParams);
            if (response == null || response.getStatusCode() != 200) {
                LogService.getLogger().info("获取病人数据错误,请求HTTP错误,请检查配置或HTTP是否可用.");
                return "";
            }
            ObjectMapper mapper = new ObjectMapper();
            JsonNode responseNode = mapper.readValue(response.getBody(), JsonNode.class);
            String code = responseNode.path("responseCode").asText();
            if (StringUtil.isEmpty(code) || !code.equals("10000")) {
                LogService.getLogger().info("获取病人数据错误,请求HTTP错误,请检查集成平台网关是否可用.");
                return "";
            }
            String rootStr = responseNode.path("responseParams").asText();
            if ("".equals(rootStr)) {
                LogService.getLogger().info("获取病人数据错误,集成平台获取病人数据失败.");
                return "";
            }
            return rootStr;
        } catch (Exception e) {
            LogService.getLogger().error("获取病人数据失败.", e);
            return "";
        }
    }
        /**
         * 获取公钥
         */
    public static String getPublicKey(){
        try {
            String token = getToken();
@ -155,7 +190,7 @@ public class EsbHttp {
            paramMap.put("org_code", orgCode);
            paramMap.put("token", token);
            String publicKeyMethod = HttpHelper.defaultHttpUrl + "/organizations/"+orgCode+"/key";
            Response response = HttpHelper.get(publicKeyMethod, paramMap);
            HttpResponse response = HttpHelper.get(publicKeyMethod, paramMap);
            if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
                JSONObject json = new JSONObject(response.getBody());
                if(json.has("publicKey"))
@ -165,7 +200,7 @@ public class EsbHttp {
                    return key;
                }
                else{
                    LogUtil.info("获取公钥失败,返回未包含publicKey。");
                    LogService.getLogger().info("获取公钥失败,返回未包含publicKey。");
                    return null;
                }
            }
@ -176,11 +211,11 @@ public class EsbHttp {
                {
                    msg +="(错误代码:"+ response.getStatusCode() + ",错误信息:"+response.getBody()+")";
                }
                LogUtil.info(msg);
                LogService.getLogger().info(msg);
                return null;
            }
        } catch (Exception e) {
            LogUtil.info(e.getMessage());
            LogService.getLogger().info(e.getMessage());
            return null;
        }
    }
@ -195,7 +230,7 @@ public class EsbHttp {
            Map<String, Object> params = new HashMap<>();
            params.put("org_code", orgCode);
            params.put("token", token);
            Response response = HttpHelper.get(versionMethod, params);
            HttpResponse response = HttpHelper.get(versionMethod, params);
            if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
                return response.getBody();
            }
@ -206,13 +241,13 @@ public class EsbHttp {
                {
                    msg +="(错误代码:"+ response.getStatusCode() + ",错误信息:"+response.getBody()+")";
                }
                LogUtil.info(msg);
                LogService.getLogger().info(msg);
                return null;
            }
        } catch (Exception e) {
            LogUtil.fatal("获取远程版本号异常");
            LogUtil.error(e);
            LogService.getLogger().info("获取远程版本号异常");
            LogService.getLogger().error(e.getCause().toString());
            return null;
        }
    }
@ -230,24 +265,24 @@ public class EsbHttp {
                JSONObject p = (JSONObject)json.getJSONArray("data").get(0);
                if(!p.has(colName) || p.get(colName).equals(null) || p.getString(colName).length()==0)
                {
                    LogUtil.info("注册病人信息请求失败:身份证号码为空,patient_id=" + patient.getPatientId() + ", event_no=" + patient.getEventNo());
                    LogService.getLogger().info("注册病人信息请求失败:身份证号码为空,patient_id=" + patient.getPatientId() + ", event_no=" + patient.getEventNo());
                    return false;
                }
                else{
                    String idCord = p.getString(colName);
                    String registerMethod = HttpHelper.defaultHttpUrl + "/patients/"+idCord;
                    if (StringUtil.isEmpty(data)) {
                        LogUtil.info("注册病人信息请求失败:无具体病人信息,patient_id=" + patient.getPatientId() + ", event_no=" + patient.getEventNo());
                        LogService.getLogger().info("注册病人信息请求失败:无具体病人信息,patient_id=" + patient.getPatientId() + ", event_no=" + patient.getEventNo());
                        return false;
                    }
                    Map<String, Object> paramMap = new HashMap<>();
                    paramMap.put("demographic_id", idCord);
                    paramMap.put("json", data);
                    paramMap.put("token", token);
                    Response response = HttpHelper.post(registerMethod, paramMap);
                    HttpResponse response = HttpHelper.post(registerMethod, paramMap);
                    if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
                        LogUtil.info("注册病人信息成功。patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo());
                        LogService.getLogger().info("注册病人信息成功。patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo());
                        return true;
                    }
                    else{
@ -256,20 +291,20 @@ public class EsbHttp {
                        {
                            msg +="(错误代码:"+ response.getStatusCode() + ",错误信息:"+response.getBody()+")";
                        }
                        LogUtil.info(msg);
                        LogService.getLogger().info(msg);
                        return false;
                    }
                }
            }
            else{
                LogUtil.info("注册病人信息请求失败:传入数据无效,patient_id=" + patient.getPatientId() + ", event_no=" + patient.getEventNo());
                LogService.getLogger().info("注册病人信息请求失败:传入数据无效,patient_id=" + patient.getPatientId() + ", event_no=" + patient.getEventNo());
                return false;
            }
        }
        catch (Exception e)
        {
            LogUtil.info("注册病人信息请求失败."+e.getMessage());
            LogService.getLogger().info("注册病人信息请求失败." + e.getMessage());
            return false;
        }
    }
@ -287,10 +322,10 @@ public class EsbHttp {
            formParams.add(new BasicNameValuePair("package_crypto", encryptPwd));
            formParams.add(new BasicNameValuePair("org_code", SysConfig.getInstance().getOrgCode()));
            formParams.add(new BasicNameValuePair("token", token));
            Response response = HttpHelper.postFile(uploadMethod, formParams, file.getAbsolutePath());
            HttpResponse response = HttpHelper.postFile(uploadMethod, formParams, file.getAbsolutePath());
            if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
                LogUtil.info("上传病人档案成功,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
                LogService.getLogger().info("上传病人档案成功,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
                return true;
            }
            else {
@ -300,13 +335,13 @@ public class EsbHttp {
                {
                    msg +="(错误代码:"+ response.getStatusCode() + ",错误信息:"+response.getBody()+")";
                }
                LogUtil.info(msg);
                LogService.getLogger().info(msg);
                return false;
            }
        }
        catch (Exception e) {
            LogUtil.fatal("上传病人档案异常,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
            LogUtil.error(e);
            LogService.getLogger().info("上传病人档案异常,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
            LogService.getLogger().error(e.getCause().toString());
            return false;
        }
    }
@ -315,7 +350,7 @@ public class EsbHttp {
    /**
     * 下载标准包
     */
    public static Response download(String remoteVersion, String orgCode) {
    public static HttpResponse download(String remoteVersion, String orgCode) {
        try {
            String token = getToken();
            String downLoadMethod = HttpHelper.defaultHttpUrl + "/adaptions/"+orgCode+"/source";
@ -323,11 +358,11 @@ public class EsbHttp {
            params.put("version_code", remoteVersion);
            params.put("org_code", orgCode);
            params.put("token", token);
            Response response = HttpHelper.get(downLoadMethod, params);
            HttpResponse response = HttpHelper.get(downLoadMethod, params);
            return response;
        } catch (Exception e) {
            LogUtil.fatal("下载标准包异常:");
            LogUtil.error(e);
            LogService.getLogger().info("下载标准包异常:");
            LogService.getLogger().error(e.getCause().toString());
            return null;
        }
    }

+ 2 - 3
Hos-resource/src/main/java/com/yihu/ehr/crawler/service/PatientCDAIndex.java

@ -1,8 +1,7 @@
package com.yihu.ehr.crawler.service;
import com.yihu.ehr.common.config.SysConfig;
import com.yihu.ehr.crawler.model.Patient;
import com.yihu.ehr.model.Patient;
import com.yihu.ehr.crawler.model.config.SysConfig;
import com.yihu.ehr.crawler.model.patient.Patient;
import java.util.UUID;

+ 110 - 0
Hos-resource/src/main/java/com/yihu/ehr/crawler/service/PatientCDAUpload.java

@ -0,0 +1,110 @@
package com.yihu.ehr.crawler.service;
import com.yihu.ehr.crawler.model.config.SysConfig;
import com.yihu.ehr.crawler.model.patient.Patient;
import com.yihu.ehr.framework.util.compress.Zipper;
import com.yihu.ehr.framework.util.encrypt.RSA;
import com.yihu.ehr.framework.util.file.FileUtil;
import com.yihu.ehr.framework.util.log.LogService;
import java.io.File;
import java.security.Key;
import java.util.UUID;
/**
 * 档案上传
 *
 * @author Air
 * @version 1.0
 * @created 2015.07.06 15:58
 */
public class PatientCDAUpload {
    public static String uploadMethod;
    /**
     * @param patient
     * @return
     * @modify 2015.09.15 airhead 修订删除目录
     * @modify 2015.09.19 airhead 修复无文档问题及错误信息
     */
    public Boolean upload(Patient patient, String token) {
        ZipFile zipFile = zip(patient);
        try {
            if (zipFile == null || zipFile.file == null) {
                LogService.getLogger().info("压缩病人档案失败,病人文档未生成,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
                return false;
            }
            boolean result = upload(patient, zipFile, token);
            if (!result) {
                LogService.getLogger().info("上传病人档案失败,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
                return result;
            }
            LogService.getLogger().trace(zipFile.directory);
            result = FileUtil.deleteDirectory(new File(zipFile.directory));
            if (!result) {
                LogService.getLogger().info("删除临时文件失败,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
                return result;
            }
        } catch (Exception e) {
            FileUtil.deleteDirectory(new File(zipFile.directory));
            return false;
        }
        return true;
    }
    /**
     * @param patient
     * @return
     * @modify 从data目录生成zip数据
     */
    public ZipFile zip(Patient patient) {
        try {
            PatientCDAIndex patientCDAIndex = new PatientCDAIndex(patient);
            String dataDirectory = patientCDAIndex.getDataDirectory();
            String filePath = patientCDAIndex.createIndex(PatientCDAIndex.IndexType.ZIP, PatientCDAIndex.FileType.ZIP);
            UUID uuidPwd = UUID.randomUUID();
            String pwd = uuidPwd.toString();
            String PublicKey = SysConfig.getInstance().getPublicKey();
            if(PublicKey== null ||  PublicKey.length() == 0) {
                PublicKey = EsbHttp.getPublicKey();
                SysConfig.getInstance().setPublicKey(PublicKey);
            }
            Key key = RSA.genPublicKey(PublicKey);
            if (key == null) {
                LogService.getLogger().info("压缩文件错误,获取公钥错误.");
                return null;
            }
            ZipFile zipFile = new ZipFile();
            zipFile.encryptPwd = RSA.encrypt(pwd, key);
            Zipper zipper = new Zipper();
            zipFile.file = zipper.zipFile(new File(dataDirectory), filePath, pwd);
            zipFile.dataDirectory = dataDirectory;
            zipFile.directory = patientCDAIndex.getDirectory();
            return zipFile;
        } catch (Exception e) {
            LogService.getLogger().error("从data目录生成zip数据时,压缩文件异常");
            LogService.getLogger().error(e.getCause().toString());
        }
        return null;
    }
    private boolean upload(Patient patient, ZipFile zipFile, String token) {
        return EsbHttp.upload(patient, zipFile.file, zipFile.encryptPwd, token);
    }
    private class ZipFile {
        public File file;
        public String encryptPwd;
        public String directory;
        public String dataDirectory;
    }
}

+ 0 - 16
Hos-resource/src/main/java/com/yihu/ehr/datacollect/controller/DataPushController.java

@ -1,29 +1,13 @@
package com.yihu.ehr.datacollect.controller;
import com.yihu.ehr.common.Services;
import com.yihu.ehr.datacollect.model.RsJobConfig;
import com.yihu.ehr.datacollect.service.intf.IDatacollectManager;
import com.yihu.ehr.datacollect.service.intf.IDatacollectService;
import com.yihu.ehr.datacollect.service.intf.IDatapushService;
import com.yihu.ehr.framework.constrant.DateConvert;
import com.yihu.ehr.framework.model.ActionResult;
import com.yihu.ehr.framework.model.Result;
import com.yihu.ehr.framework.util.controller.BaseController;
import com.yihu.ehr.framework.util.operator.CollectionUtil;
import com.yihu.ehr.std.service.intf.IStdService;
import com.yihu.ehr.system.service.intf.IDatasourceManager;
import net.sf.json.JSONArray;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
/**
 * 数据采集配置页面
 * Created by hzp on 2015/8/12.

+ 2 - 2
Hos-resource/src/main/java/com/yihu/ehr/resource/service/IStdService.java

@ -3,7 +3,7 @@ package com.yihu.ehr.resource.service;
import com.yihu.ehr.framework.model.DictionaryResult;
import com.yihu.ehr.standard.model.adapter.AdapterDatasetModel;
import com.yihu.ehr.standard.model.adapter.AdapterDictentryModel;
import com.yihu.ehr.standard.model.adapter.AdapterDictEntryModel;
import com.yihu.ehr.standard.model.adapter.resultModel.AdapterMetadataResultDetailModel;
import com.yihu.ehr.standard.model.adapter.resultModel.SchemeVersionResultDetailModel;
import com.yihu.ehr.standard.model.standard.StdDataSetModel;
@ -46,7 +46,7 @@ public interface IStdService {
    /**
     * 通过适配方案获取字典列表
     */
    public List<AdapterDictentryModel> getDictByScheme(String schemeVersion, String dictId) throws Exception;
    public List<AdapterDictEntryModel> getDictByScheme(String schemeVersion, String dictId) throws Exception;
    /******************************** 标准版本 *****************************************************/
    /**

+ 10 - 10
Hos-resource/src/main/java/com/yihu/ehr/resource/service/impl/StdService.java

@ -7,13 +7,13 @@ import com.yihu.ehr.framework.model.DictionaryResult;
import com.yihu.ehr.framework.util.operator.CollectionUtil;
import com.yihu.ehr.resource.service.IStdService;
import com.yihu.ehr.standard.model.adapter.AdapterDatasetModel;
import com.yihu.ehr.standard.model.adapter.AdapterDictentryModel;
import com.yihu.ehr.standard.model.adapter.AdapterDictEntryModel;
import com.yihu.ehr.standard.model.adapter.resultModel.AdapterMetadataResultDetailModel;
import com.yihu.ehr.standard.model.adapter.resultModel.SchemeVersionResultDetailModel;
import com.yihu.ehr.standard.model.standard.StdDataSetModel;
import com.yihu.ehr.standard.model.standard.StdMetaDataModel;
import com.yihu.ehr.standard.service.adapter.AdapterDatasetService;
import com.yihu.ehr.standard.service.adapter.AdapterDictentryService;
import com.yihu.ehr.standard.service.adapter.AdapterDictEntryService;
import com.yihu.ehr.standard.service.adapter.AdapterMetadataService;
import com.yihu.ehr.standard.service.adapter.AdapterSchemeVersionService;
import com.yihu.ehr.standard.service.bo.AdapterVersion;
@ -37,8 +37,8 @@ public class StdService implements IStdService {
    private StdDatasetService stdDatasetService;
    @Resource(name = StdMetadataService.BEAN_ID)
    private StdMetadataService stdMetadataService;
    @Resource(name = AdapterDictentryService.BEAN_ID)
    private AdapterDictentryService dictentryService;
    @Resource(name = AdapterDictEntryService.BEAN_ID)
    private AdapterDictEntryService dictentryService;
    @Resource(name = AdapterMetadataService.BEAN_ID)
    private AdapterMetadataService metadataService;
    @Resource(name = AdapterDatasetService.BEAN_ID)
@ -87,11 +87,11 @@ public class StdService implements IStdService {
    /**
     * 通过适配方案获取字典列表
     */
    public List<AdapterDictentryModel> getDictByScheme(String schemeVersion, String dictId) {
    public List<AdapterDictEntryModel> getDictByScheme(String schemeVersion, String dictId) {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("adapterDictId", dictId);
        AdapterVersion version = new AdapterVersion(schemeVersion);
        return dictentryService.getList(AdapterDictentryModel.class, version.getDictEntryTableName(), net.sf.json.JSONObject.fromObject(map).toString(), null, null, null, ErrorCode.GetDictEntryListFailed);
        return dictentryService.getList(AdapterDictEntryModel.class, version.getDictEntryTableName(), net.sf.json.JSONObject.fromObject(map).toString(), null, null, null, ErrorCode.GetDictEntryListFailed);
    }
    /**
@ -102,16 +102,16 @@ public class StdService implements IStdService {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("adapterDictId", dictId);
        AdapterVersion version = new AdapterVersion(schemeVersion);
        List<AdapterDictentryModel> dictentryList =  dictentryService.getList(AdapterDictentryModel.class, version.getDictEntryTableName(), net.sf.json.JSONObject.fromObject(map).toString(), null, null, null, ErrorCode.GetDictEntryListFailed);
        List<AdapterDictEntryModel> dictentryList =  dictentryService.getList(AdapterDictEntryModel.class, version.getDictEntryTableName(), net.sf.json.JSONObject.fromObject(map).toString(), null, null, null, ErrorCode.GetDictEntryListFailed);
        List<DictItem> list = new ArrayList<>();
        if(!CollectionUtil.isEmpty(dictentryList)) {
            for(AdapterDictentryModel adapterDictentryModel : dictentryList)
            for(AdapterDictEntryModel adapterDictEntryModel : dictentryList)
            {
                DictItem dict = new  DictItem();
                dict.setCode(adapterDictentryModel.getAdapterEntryCode());
                dict.setValue(adapterDictentryModel.getAdapterEntryValue());
                dict.setCode(adapterDictEntryModel.getAdapterEntryCode());
                dict.setValue(adapterDictEntryModel.getAdapterEntryValue());
                list.add(dict);
            }
        }

+ 14 - 14
Hos-resource/src/main/java/com/yihu/ehr/standard/controller/SchemeDictEntryController.java

@ -3,9 +3,9 @@ package com.yihu.ehr.standard.controller;
import com.yihu.ehr.framework.constrant.ErrorCode;
import com.yihu.ehr.framework.constrant.Result;
import com.yihu.ehr.framework.util.controller.BaseController;
import com.yihu.ehr.standard.model.adapter.AdapterDictentryModel;
import com.yihu.ehr.standard.model.adapter.AdapterDictEntryModel;
import com.yihu.ehr.standard.model.adapter.resultModel.AdapterDictEntryResultDetailModel;
import com.yihu.ehr.standard.service.adapter.AdapterDictentryService;
import com.yihu.ehr.standard.service.adapter.AdapterDictEntryService;
import com.yihu.ehr.standard.service.bo.AdapterVersion;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -25,8 +25,8 @@ import java.util.List;
@Api(protocols = "https", value = "SchemeDictEntryController", description = "适配字典项管理", tags = {"适配字典项"})
public class SchemeDictEntryController extends BaseController {
    @Resource(name = AdapterDictentryService.BEAN_ID)
    private AdapterDictentryService dictentryService;
    @Resource(name = AdapterDictEntryService.BEAN_ID)
    private AdapterDictEntryService dictentryService;
    /**
     * 查询字典项列表信息(get)
     * @param adapterVersion
@ -50,8 +50,8 @@ public class SchemeDictEntryController extends BaseController {
            @RequestParam(value = "rows", required = false) Integer rows,
            @ApiParam(name = "page", value = "Start position of result set. Must be an integer")
            @RequestParam(value = "page", required = false) Integer page) {
        List<AdapterDictEntryResultDetailModel> detailModelList = dictentryService.getDictEntryList(AdapterDictentryModel.class, adapterVersion, condition, order, rows, page - 1);
        Integer count = dictentryService.getDictEntryInt(AdapterDictentryModel.class, adapterVersion, condition);
        List<AdapterDictEntryResultDetailModel> detailModelList = dictentryService.getDictEntryList(AdapterDictEntryModel.class, adapterVersion, condition, order, rows, page - 1);
        Integer count = dictentryService.getDictEntryInt(AdapterDictEntryModel.class, adapterVersion, condition);
        Result result = new Result();
        result.setDetailModelList(detailModelList);
        result.setTotalCount(count);
@ -59,19 +59,19 @@ public class SchemeDictEntryController extends BaseController {
    }
    @RequestMapping(value = "/getForDictEntryId")
    @ApiOperation(value = "获取字典项", response = AdapterDictentryModel.class, produces = "application/json", notes = "获取字典项")
    public AdapterDictentryModel get(
    @ApiOperation(value = "获取字典项", response = AdapterDictEntryModel.class, produces = "application/json", notes = "获取字典项")
    public AdapterDictEntryModel get(
            @ApiParam(name = "adapterVersion", value = "标准版本号")
            @RequestParam(value = "adapterVersion") String adapterVersion,
            @ApiParam(name = "dictEntryId", value = "字典项ID")
            @RequestParam(value = "dictEntryId") Integer dictentryId) {
        AdapterVersion version = new AdapterVersion(adapterVersion);
        return (AdapterDictentryModel) dictentryService.get(AdapterDictentryModel.class, version.getDictEntryTableName(), dictentryId, ErrorCode.GetDictEntryFailed);
        return (AdapterDictEntryModel) dictentryService.get(AdapterDictEntryModel.class, version.getDictEntryTableName(), dictentryId, ErrorCode.GetDictEntryFailed);
    }
    @RequestMapping(value = "/updateDictEntry")
    @ApiOperation(value = "修改字典项", response = AdapterDictentryModel.class, produces = "application/json", notes = "修改字典项")
    public AdapterDictentryModel updateDictEntry(
    @ApiOperation(value = "修改字典项", response = AdapterDictEntryModel.class, produces = "application/json", notes = "修改字典项")
    public AdapterDictEntryModel updateDictEntry(
            @ApiParam(name = "adapterVersion", value = "标准版本号")
            @RequestParam(value = "adapterVersion") String adapterVersion,
            @ApiParam(name = "dictEntry", value = "字典项")
@ -80,8 +80,8 @@ public class SchemeDictEntryController extends BaseController {
    }
    @RequestMapping(value = "/addDictEntry")
    @ApiOperation(value = "保存字典项", response = AdapterDictentryModel.class, produces = "application/json", notes = "保存字典项")
    public AdapterDictentryModel add(
    @ApiOperation(value = "保存字典项", response = AdapterDictEntryModel.class, produces = "application/json", notes = "保存字典项")
    public AdapterDictEntryModel add(
            @ApiParam(name = "adapterVersion", value = "标准版本号")
            @RequestParam(value = "adapterVersion") String adapterVersion,
            @ApiParam(name = "dictEntry", value = "字典项")
@ -100,7 +100,7 @@ public class SchemeDictEntryController extends BaseController {
    }
    @RequestMapping("/delDictEntry")
    @ApiOperation(value = "删除字典项", response = AdapterDictentryModel.class, produces = "application/json", notes = "删除字典项,若字典项表为空管理字典清掉")
    @ApiOperation(value = "删除字典项", response = AdapterDictEntryModel.class, produces = "application/json", notes = "删除字典项,若字典项表为空管理字典清掉")
    public void delete(
            @ApiParam(name = "adapterVersion", value = "标准版本号")
            @RequestParam(value = "adapterVersion") String adapterVersion,

+ 1 - 1
Hos-resource/src/main/java/com/yihu/ehr/standard/model/adapter/AdapterDictentryModel.java

@ -9,7 +9,7 @@ import javax.persistence.Id;
/**
 * Created by lingfeng on 2015/9/16.
 */
public class AdapterDictentryModel {
public class AdapterDictEntryModel {
    @Id
    @GeneratedValue(generator = "generator")
    @GenericGenerator(name = "generator", strategy = "increment")

+ 35 - 35
Hos-resource/src/main/java/com/yihu/ehr/standard/service/adapter/AdapterDictentryService.java

@ -10,7 +10,7 @@ import com.yihu.ehr.framework.util.operator.CollectionUtil;
import com.yihu.ehr.framework.util.operator.StringUtil;
import com.yihu.ehr.framework.util.sql.SqlCreator;
import com.yihu.ehr.standard.model.adapter.AdapterDictModel;
import com.yihu.ehr.standard.model.adapter.AdapterDictentryModel;
import com.yihu.ehr.standard.model.adapter.AdapterDictEntryModel;
import com.yihu.ehr.standard.model.adapter.AdapterSchemeModel;
import com.yihu.ehr.standard.model.adapter.resultModel.AdapterDictEntryResultDetailModel;
import com.yihu.ehr.standard.model.standard.StdDictionaryModel;
@ -24,35 +24,35 @@ import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.util.*;
@Transactional
@Service("AdapterDictentryService")
public class AdapterDictentryService extends SQLGeneralDAO {
@Service("AdapterDictEntryService")
public class AdapterDictEntryService extends SQLGeneralDAO {
    public static final String BEAN_ID = "AdapterDictentryService";
    public static final String BEAN_ID = "AdapterDictEntryService";
    public AdapterDictentryService() {
    public AdapterDictEntryService() {
    }
    public void finalize() throws Throwable {
        super.finalize();
    }
    public AdapterDictentryModel add(String adapterVersion, String dictentry) {
    public AdapterDictEntryModel add(String adapterVersion, String dictentry) {
        try {
            AdapterVersion version = new AdapterVersion(adapterVersion);
            ObjectMapper objectMapper = new ObjectMapper();
            AdapterDictentryModel adapterDictentryModel = objectMapper.readValue(dictentry, AdapterDictentryModel.class);
            AdapterDictEntryModel adapterDictEntryModel = objectMapper.readValue(dictentry, AdapterDictEntryModel.class);
            Session session = getCurrentSession();
            String sql = "select max(id) from " + version.getDictEntryTableName();
            Query query = session.createSQLQuery(sql);
            Object object = query.uniqueResult();
            adapterDictentryModel.setId(object == null ? 1 : Integer.parseInt(object.toString()) + 1);
            adapterDictEntryModel.setId(object == null ? 1 : Integer.parseInt(object.toString()) + 1);
            JsonNode jsonNode = objectMapper.readTree(objectMapper.writeValueAsString(adapterDictentryModel));
            SqlCreator sqlCreator = new SqlCreator(AdapterDictentryModel.class);
            JsonNode jsonNode = objectMapper.readTree(objectMapper.writeValueAsString(adapterDictEntryModel));
            SqlCreator sqlCreator = new SqlCreator(AdapterDictEntryModel.class);
            sql = sqlCreator.insertData(version.getDictEntryTableName(), jsonNode);
            query = getExeuteQuery(sqlCreator, sql);
            query.executeUpdate();
            return adapterDictentryModel;
            return adapterDictEntryModel;
        } catch (Exception e) {
            throw new ApiException(ErrorCode.saveDictEntryFailed);
        }
@ -72,17 +72,17 @@ public class AdapterDictentryService extends SQLGeneralDAO {
        }
    }
    public AdapterDictentryModel modify(String adapterVersion, String dictentry) {
    public AdapterDictEntryModel modify(String adapterVersion, String dictentry) {
        try {
            AdapterVersion version = new AdapterVersion(adapterVersion);
            ObjectMapper objectMapper = new ObjectMapper();
            AdapterDictentryModel adapterDictentryModel = objectMapper.readValue(dictentry, AdapterDictentryModel.class);
            JsonNode jsonNode = objectMapper.readTree(objectMapper.writeValueAsString(adapterDictentryModel));
            SqlCreator sqlCreator = new SqlCreator(AdapterDictentryModel.class);
            AdapterDictEntryModel adapterDictEntryModel = objectMapper.readValue(dictentry, AdapterDictEntryModel.class);
            JsonNode jsonNode = objectMapper.readTree(objectMapper.writeValueAsString(adapterDictEntryModel));
            SqlCreator sqlCreator = new SqlCreator(AdapterDictEntryModel.class);
            String sql = sqlCreator.updateDataByTableKey(version.getDictEntryTableName(), jsonNode);
            Query query = getExeuteQuery(sqlCreator, sql);
            query.executeUpdate();
            return adapterDictentryModel;
            return adapterDictEntryModel;
        } catch (Exception e) {
            throw new ApiException(ErrorCode.UpdateDictEntryFailed);
        }
@ -125,11 +125,11 @@ public class AdapterDictentryService extends SQLGeneralDAO {
                query.setFirstResult(offset * limit);
            }
        }
        List<AdapterDictentryModel> modelList = query.list();
        List<AdapterDictEntryModel> modelList = query.list();
        List<Integer> idList = new ArrayList<>();
        Map<Integer, StdDictionaryModel> stdDictModelMap = new HashMap<>();
        Integer schemeId = null;
        for (AdapterDictentryModel model : modelList) {
        for (AdapterDictEntryModel model : modelList) {
            if (model.getAdapterDictId() != null) {
                schemeId = model.getSchemeId();
                idList.add(model.getAdapterDictId());
@ -151,7 +151,7 @@ public class AdapterDictentryService extends SQLGeneralDAO {
        }
        List<AdapterDictEntryResultDetailModel> detailModelList = new ArrayList<>();
        for (AdapterDictentryModel model : modelList) {
        for (AdapterDictEntryModel model : modelList) {
            AdapterDictEntryResultDetailModel detailModel = new AdapterDictEntryResultDetailModel();
            detailModel.setId(model.getId());
            detailModel.setSchemeId(model.getSchemeId());
@ -205,20 +205,20 @@ public class AdapterDictentryService extends SQLGeneralDAO {
            Map<Integer, AdapterDictEntryResultDetailModel> dictEntryResultMap = new HashMap<>();
            Integer maxId = null;
            for (AdapterDictEntryResultDetailModel dictEntryModel : adapterDictEntryList) {
                AdapterDictentryModel adapterDictentryModel = new AdapterDictentryModel();
                adapterDictentryModel.setId(dictEntryModel.getId());
                adapterDictentryModel.setSchemeId(dictEntryModel.getSchemeId());
                adapterDictentryModel.setAdapterDictId(dictEntryModel.getAdapterDictId());
                adapterDictentryModel.setAdapterEntryId(dictEntryModel.getAdapterEntryId());
                adapterDictentryModel.setAdapterEntryCode(dictEntryModel.getAdapterEntryCode());
                adapterDictentryModel.setAdapterEntryValue(dictEntryModel.getAdapterEntryValue());
                adapterDictentryModel.setStdDictId(dictEntryModel.getStdDictId());
                adapterDictentryModel.setStdEntryId(dictEntryModel.getStdEntryId());
                adapterDictentryModel.setStdEntryCode(dictEntryModel.getStdEntryCode());
                adapterDictentryModel.setStdEntryValue(dictEntryModel.getStdEntryValue());
                AdapterDictEntryModel adapterDictEntryModel = new AdapterDictEntryModel();
                adapterDictEntryModel.setId(dictEntryModel.getId());
                adapterDictEntryModel.setSchemeId(dictEntryModel.getSchemeId());
                adapterDictEntryModel.setAdapterDictId(dictEntryModel.getAdapterDictId());
                adapterDictEntryModel.setAdapterEntryId(dictEntryModel.getAdapterEntryId());
                adapterDictEntryModel.setAdapterEntryCode(dictEntryModel.getAdapterEntryCode());
                adapterDictEntryModel.setAdapterEntryValue(dictEntryModel.getAdapterEntryValue());
                adapterDictEntryModel.setStdDictId(dictEntryModel.getStdDictId());
                adapterDictEntryModel.setStdEntryId(dictEntryModel.getStdEntryId());
                adapterDictEntryModel.setStdEntryCode(dictEntryModel.getStdEntryCode());
                adapterDictEntryModel.setStdEntryValue(dictEntryModel.getStdEntryValue());
                idList.add(dictEntryModel.getStdDictId());
                dictEntryResultMap.put(dictEntryModel.getStdDictId(), dictEntryModel);
                SqlCreator sqlCreator = new SqlCreator(AdapterDictentryModel.class);
                SqlCreator sqlCreator = new SqlCreator(AdapterDictEntryModel.class);
                String sql;
                if (dictEntryModel.getId() == null) {
                    if (maxId == null) {
@ -227,11 +227,11 @@ public class AdapterDictentryService extends SQLGeneralDAO {
                        Object object = query.uniqueResult();
                        maxId = object == null ? 1 : Integer.parseInt(object.toString()) + 1;
                    }
                    adapterDictentryModel.setId(maxId++);
                    JsonNode jsonNode = objectMapper.readTree(objectMapper.writeValueAsString(adapterDictentryModel));
                    adapterDictEntryModel.setId(maxId++);
                    JsonNode jsonNode = objectMapper.readTree(objectMapper.writeValueAsString(adapterDictEntryModel));
                    sql = sqlCreator.insertData(version.getDictEntryTableName(), jsonNode);
                } else {
                    JsonNode jsonNode = objectMapper.readTree(objectMapper.writeValueAsString(adapterDictentryModel));
                    JsonNode jsonNode = objectMapper.readTree(objectMapper.writeValueAsString(adapterDictEntryModel));
                    sql = sqlCreator.updateDataByTableKey(version.getDictEntryTableName(), jsonNode);
                }
@ -276,7 +276,7 @@ public class AdapterDictentryService extends SQLGeneralDAO {
            query.setInteger("id", dictEntryId);
            query.executeUpdate();
            SqlCreator sqlCreator = new SqlCreator(AdapterDictentryModel.class);
            SqlCreator sqlCreator = new SqlCreator(AdapterDictEntryModel.class);
            sqlCreator.equalCondition("stdDictId", stdDictId);
            sqlCreator.equalCondition("adapterDictId", adapterDictId);
            sql = sqlCreator.countData(version.getDictEntryTableName());