Преглед изворни кода

慢阻肺综合查询相关修改

LAPTOP-KB9HII50\70708 пре 1 година
родитељ
комит
bfb95201e7

+ 2 - 1
svr/svr-basic/src/main/java/com/yihu/jw/basic/resource/dao/ResourceBrowseDao.java

@ -685,7 +685,8 @@ public class ResourceBrowseDao {
        if(list.size()>0){
            //字典翻译
            List<DtoResourceMetadata> resourceMetadataList = resourceBrowseMetadataDao.getResourceMetadataHasDict(resourcesCodes.get(0));
            String resourcesCode = StringUtils.join(resourcesCodes, "','");
            List<DtoResourceMetadata> resourceMetadataList = resourceBrowseMetadataDao.getResourceMetadatasHasDict(resourcesCode);
            if(resourceMetadataList.size()>0){
                Map<String,String> fieldDictMap = resourceMetadataList.stream().collect(Collectors.toMap(DtoResourceMetadata::getEhrId,DtoResourceMetadata::getDictCode));
                Map<String,Map<String,String>> dictMap = new HashMap<>();

+ 23 - 0
svr/svr-basic/src/main/java/com/yihu/jw/basic/resource/dao/ResourceBrowseMetadataDao.java

@ -2,6 +2,7 @@ package com.yihu.jw.basic.resource.dao;
import com.yihu.jw.entity.ehr.resource.DtoResourceMetadata;
import com.yihu.jw.entity.ehr.resource.RsResourceMetadata;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
@ -21,6 +22,15 @@ public class ResourceBrowseMetadataDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 获取某资源所有数据元
     */
    public List<RsResourceMetadata> findResourceMetadata(String resourcesCode) throws Exception {
        String sql = "SELECT m.* from rs_resource_metadata m,rs_resource r WHERE m.RESOURCES_ID=r.id and r.`code` = '"+resourcesCode+"'";
        RowMapper rowMapper = BeanPropertyRowMapper.newInstance(RsResourceMetadata.class);
        return jdbcTemplate.query(sql, rowMapper);
    }
    /**
     * 获取某资源所有数据元
     */
@ -34,6 +44,19 @@ public class ResourceBrowseMetadataDao {
        return jdbcTemplate.query(sql, rowMapper);
    }
    /**
     * 获取某资源有字典的数据元
     */
    public List<DtoResourceMetadata> getResourceMetadatasHasDict(String resourcesCodes) throws Exception {
        String sql = "SELECT m.id,m.ehr_id, m.domain, m.name, m.std_code, m.display_code, m.column_type, m.null_able, m.dict_code, m.description, m.valid, a.group_type, a.group_data " +
                "FROM rs_resource_metadata a, rs_resource b, rs_metadata m " +
                "WHERE a.resources_id = b.id " +
                "AND a.metadata_id = m.ehr_id " +
                "AND b.code in ('" + resourcesCodes + "') and m.DICT_CODE is not null ";
        RowMapper rowMapper = BeanPropertyRowMapper.newInstance(DtoResourceMetadata.class);
        return jdbcTemplate.query(sql, rowMapper);
    }
    /**
     * 获取某资源有字典的数据元
     */

+ 47 - 9
svr/svr-basic/src/main/java/com/yihu/jw/basic/resource/service/ResourceBrowseService.java

@ -3,10 +3,15 @@ package com.yihu.jw.basic.resource.service;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.basic.resource.dao.ResourceBrowseDao;
import com.yihu.jw.basic.resource.dao.ResourceBrowseMetadataDao;
import com.yihu.jw.basic.resource.dao.RsResourceDao;
import com.yihu.jw.basic.resource.dao.RsResourceDefaultParamDao;
import com.yihu.jw.constants.ErrorCode;
import com.yihu.jw.basic.resource.dao.ResourceBrowseDao;
import com.yihu.jw.entity.ehr.resource.DtoResourceMetadata;
import com.yihu.jw.entity.ehr.resource.RsResource;
import com.yihu.jw.entity.ehr.resource.RsResourceDefaultParam;
import com.yihu.jw.entity.ehr.resource.RsResourceMetadata;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.mysql.enums.Operation;
import com.yihu.jw.mysql.model.QueryCondition;
@ -14,10 +19,6 @@ import com.yihu.jw.mysql.query.BaseJpaService;
import com.yihu.jw.profile.ProfileType;
import com.yihu.jw.profile.family.ResourceCells;
import com.yihu.jw.restmodel.ehr.resource.MRsColumnsModel;
import com.yihu.jw.basic.resource.dao.ResourceBrowseMetadataDao;
import com.yihu.jw.basic.resource.dao.RsResourceDao;
import com.yihu.jw.entity.ehr.resource.DtoResourceMetadata;
import com.yihu.jw.entity.ehr.resource.RsResource;
import com.yihu.jw.restmodel.web.Envelop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@ -499,31 +500,64 @@ public class ResourceBrowseService extends BaseJpaService {
        //获取资源编码列表
        List<String> codeList = (List<String>) objectMapper.readValue(resourcesCodes, List.class);
        String tableName = "";
        String where = "";
        Map<String,Integer> relationMap = new HashMap<>();//多视图关联
        Map<String,String> filedMap = new HashMap<>();//参数加别名
        //资源判空检查
        for (String code : codeList) {
            RsResource rsResources = rsResourceService.getResourceByCategory(code,"standard");
            if (rsResources == null) {
                throw new ApiException( "无效的资源编码" + code,ErrorCode.BAD_REQUEST.value());
            }
            List<RsResourceMetadata> resourceMetadataList = resourceBrowseMetadataDao.findResourceMetadata(code);
            for (RsResourceMetadata metadata:resourceMetadataList){
                filedMap.put(metadata.getMetadataId(),code);
            }
            String sortOrder = "";
            List<RsResourceDefaultParam> paramsList = resourceDefaultParamDao.findByResourcesCode(code);
            for (RsResourceDefaultParam param : paramsList) {
                if (param.getParamKey().equals("sort")) {
                    Map<String, String> temp = objectMapper.readValue(param.getParamValue(), Map.class);
                String paramKey = param.getParamKey();
                String paramValue = param.getParamValue();
                if ("sort".equals(paramKey)) {
                    Map<String, String> temp = objectMapper.readValue(paramValue, Map.class);
                    for (Map.Entry<String, String> entry:temp.entrySet()){
                        String key = entry.getKey();
                        String value = entry.getValue();
                        sortOrder ="T."+key+" "+ value+",";
                    }
                }else if (param.getParamKey().equals("table")){
                    tableName += " ("+param.getParamValue()+") "+ code;
                }else if ("table".equals(paramKey)){
                    tableName += " ("+paramValue+") "+ code +",";
                }else if("relation".equals(paramKey)){
                    String relate[] = paramValue.split(",");
                    for (String re:relate){
                        if(relationMap.containsKey(re)){
                            relationMap.put(re,relationMap.get(re)+1);
                        }else {
                            relationMap.put(re,1);
                        }
                    }
                }
            }
        }
        String code1 = codeList.get(0);
        int codeLength = codeList.size();
        for (int i=1;i<codeLength ;i++) {
            String codeTmp = codeList.get(i);
            for (Map.Entry<String, Integer> entry : relationMap.entrySet()) {
                String key = entry.getKey();
                int value = entry.getValue();
                if(value == codeLength){
                    where += " and " + code1+"."+key+"="+codeTmp+"."+key;
                }
            }
        }
        tableName = tableName.substring(0,tableName.length()-1);
        StringBuffer stringBuffer = new StringBuffer();
        if (!StringUtils.isEmpty(queryCondition)) {
            stringBuffer = parseCondition1(queryCondition);
        }
        stringBuffer.append(where);
        //数据元信息字段
        if(!StringUtils.isEmpty(metaData)){
            metaData = metaData.replaceAll(",","\",\"");
@ -532,10 +566,14 @@ public class ResourceBrowseService extends BaseJpaService {
        //参数集合
        List<String> paramList = new ArrayList<>(customizeList.size() * 2);
        for (String id : customizeList) {
            String codeTmp = filedMap.get(id);
            if(id.contains("-")){
                String tmp = id.substring(id.lastIndexOf("-")+1);
                id = tmp + " as '" +id+"'";
            }
            if(codeTmp!=null){
                id = codeTmp+"."+id;
            }
            paramList.add(id);
        }
        String queryString = org.apache.commons.lang3.StringUtils.join(paramList, ",");