majian 6 năm trước cách đây
mục cha
commit
0b3603bd41

+ 9 - 3
pom.xml

@ -56,12 +56,10 @@
			<groupId>com.yihu.ehr</groupId>
			<artifactId>commons-web</artifactId>
		</dependency>
		<dependency>
			<groupId>com.yihu.ehr</groupId>
			<artifactId>commons-data-mysql</artifactId>
		</dependency>
		<dependency>
			<groupId>com.yihu.ehr</groupId>
			<artifactId>commons-util</artifactId>
@ -70,7 +68,15 @@
			<groupId>com.yihu.ehr</groupId>
			<artifactId>commons-rest-model</artifactId>
		</dependency>
		<dependency>
			<groupId>com.yihu.ehr</groupId>
			<artifactId>commons-data-solr</artifactId>
		</dependency>
		<dependency>
			<groupId>com.yihu.ehr</groupId>
			<artifactId>commons-data-query</artifactId>
			<scope>compile</scope>
		</dependency>
	</dependencies>
	<build>

+ 3 - 0
src/main/java/com/yihu/ehr/SvrInspectionApplication.java

@ -5,10 +5,13 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
@EnableEurekaClient
@EnableDiscoveryClient
@EnableFeignClients
@SpringBootApplication
public class SvrInspectionApplication extends SpringBootServletInitializer {

+ 28 - 0
src/main/java/com/yihu/ehr/svrinspection/commons/exception/ManageException.java

@ -0,0 +1,28 @@
package com.yihu.ehr.svrinspection.commons.exception;
/**
 *  公共异常类
 *
 * @author HZY
 * @created 2018/11/15 10:21
 */
public class ManageException extends Exception{
    public ManageException() {
    }
    public ManageException(String message) {
        super(message);
    }
    public ManageException(String message, Throwable cause) {
        super(message, cause);
    }
    public ManageException(Throwable cause) {
        super(cause);
    }
    public ManageException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }
}

+ 53 - 0
src/main/java/com/yihu/ehr/svrinspection/commons/model/IntegerIdentityEntity.java

@ -0,0 +1,53 @@
package com.yihu.ehr.svrinspection.commons.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
/**
 *  integer实体类-基类
 *
 * @author HZY
 * @created 2018/11/14 16:23
 */
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class IntegerIdentityEntity implements Serializable {
    protected Integer id;
    protected Date createTime;
    @Id
    @GeneratedValue(generator = "generator")
    @GenericGenerator(name = "generator", strategy = "identity")
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    @CreatedDate
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    @Column(name = "create_time", nullable = false, length = 0,updatable = false)
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}

+ 48 - 0
src/main/java/com/yihu/ehr/svrinspection/commons/service/BaseService.java

@ -0,0 +1,48 @@
package com.yihu.ehr.svrinspection.commons.service;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
/**
 *  公共业务类
 *
 * @author HZY
 * @created 2018/11/16 9:58
 */
public class BaseService {
    /**
     *  降序排序
     * @param list          排序集合
     * @param orderField    排序字段
     */
    public void comparator(List<Map<String, Object>> list , String orderField){
        Collections.sort(list, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                return getIntegerValue(o2.get(orderField)).compareTo(getIntegerValue(o1.get(orderField)));
            }
        });
    }
    /**
     * 获取值
     * @param objValue
     * @return
     */
    public Integer getIntegerValue(Object objValue) {
        int value = 0;
        try {
            if (objValue != null) {
                value = Integer.parseInt(objValue.toString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return value;
    }
}

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 89 - 42
src/main/java/com/yihu/ehr/svrinspection/controller/AssistanceApplyController.java


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 118 - 0
src/main/java/com/yihu/ehr/svrinspection/controller/AssistanceApplyControllerDemo.java


+ 5 - 1
src/main/java/com/yihu/ehr/svrinspection/dao/AssistanceApplyDao.java

@ -2,6 +2,8 @@ package com.yihu.ehr.svrinspection.dao;
import com.yihu.ehr.svrinspection.model.AssistanceApplyModel;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
@ -11,5 +13,7 @@ import org.springframework.data.repository.PagingAndSortingRepository;
public interface AssistanceApplyDao extends PagingAndSortingRepository<AssistanceApplyModel,Integer> {
//    Page<AssistanceApplyModel> queryAllBy
    Page<AssistanceApplyModel> queryAllByApplyOrgAndExamTypeAndExamDeptAndPatientNameLike(String appOrg, String type,String dept,String patientName, Pageable pageable);
    long countAllBySolutionStatusAndCreateTimeBetween(int solutionStatus,String startDate,String endDate );
}

+ 43 - 0
src/main/java/com/yihu/ehr/svrinspection/feign/AddressClient.java

@ -0,0 +1,43 @@
package com.yihu.ehr.svrinspection.feign;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.model.common.ObjectResult;
import com.yihu.ehr.model.geography.MGeography;
import com.yihu.ehr.model.geography.MGeographyDict;
import com.yihu.ehr.model.org.MOrganization;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Collection;
import java.util.List;
/**
 * Created by AndyCai on 2016/1/20.
 */
@FeignClient(name=MicroServices.Geography)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface AddressClient {
    @RequestMapping(value = "/geography_entries/pid/{pid}", method = RequestMethod.GET)
    @ApiOperation(value = "根据上级编号查询行政区划地址")
    List<MGeographyDict> getAddressDictByPid(
            @ApiParam(name = "pid", value = "上级id", defaultValue = "")
            @PathVariable(value = "pid") Integer pid) ;
    @ApiOperation(value = "根据地区代码获取机构列表")
    @RequestMapping(value = "/organizations/areas/{area}", method = RequestMethod.GET)
    public List<MOrganization> getOrganizationByAreaCode(
            @ApiParam(name = "area", value = "地区代码", defaultValue = "")
            @PathVariable(value = "area") String area);
}

+ 13 - 17
src/main/java/com/yihu/ehr/svrinspection/model/AssistanceApplyModel.java

@ -1,7 +1,10 @@
package com.yihu.ehr.svrinspection.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.ehr.svrinspection.commons.model.IntegerIdentityEntity;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Date;
/**
 * @author HZY
@ -9,16 +12,16 @@ import java.sql.Timestamp;
 */
@Entity
@Table(name = "org_assistance_apply", schema = "", catalog = "healtharchive")
public class AssistanceApplyModel {
public class AssistanceApplyModel extends IntegerIdentityEntity {
    private String applyOrg;
    private String applyUserId;
    private Timestamp applyDate;
    private Date applyDate;
    private String remark;
    private String picture;
    private Integer isRead;
    private String solutionOrg;
    private Integer solutionStatus;
    private Timestamp solutionDate;
    private Date solutionDate;
    private String solutionReply;
    private String solutionUserId;
    private String solutionUserName;
@ -29,7 +32,6 @@ public class AssistanceApplyModel {
    private String patientName;
    private String patientAge;
    private String patientSex;
    private int id;
    @Basic
    @Column(name = "apply_org", nullable = true, length = 32)
@ -52,12 +54,13 @@ public class AssistanceApplyModel {
    }
    @Basic
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    @Column(name = "apply_date", nullable = true)
    public Timestamp getApplyDate() {
    public Date getApplyDate() {
        return applyDate;
    }
    public void setApplyDate(Timestamp applyDate) {
    public void setApplyDate(Date applyDate) {
        this.applyDate = applyDate;
    }
@ -112,12 +115,13 @@ public class AssistanceApplyModel {
    }
    @Basic
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    @Column(name = "solution_date", nullable = true)
    public Timestamp getSolutionDate() {
    public Date getSolutionDate() {
        return solutionDate;
    }
    public void setSolutionDate(Timestamp solutionDate) {
    public void setSolutionDate(Date solutionDate) {
        this.solutionDate = solutionDate;
    }
@ -221,14 +225,6 @@ public class AssistanceApplyModel {
        this.patientSex = patientSex;
    }
    @Id
    @Column(name = "id", nullable = false)
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
}

+ 42 - 1
src/main/java/com/yihu/ehr/svrinspection/service/AssistanceApplyService.java

@ -1,14 +1,55 @@
package com.yihu.ehr.svrinspection.service;
import com.yihu.ehr.query.BaseJpaService;
import com.yihu.ehr.svrinspection.commons.exception.ManageException;
import com.yihu.ehr.svrinspection.dao.AssistanceApplyDao;
import com.yihu.ehr.svrinspection.model.AssistanceApplyModel;
import com.yihu.ehr.util.datetime.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
/**
 *  检验申请 业务类
 * @author HZY
 * @created 2018/11/14 9:21
 */
@Transactional
@Service
public class AssistanceApplyService {
public class AssistanceApplyService  extends BaseJpaService<AssistanceApplyModel, AssistanceApplyDao> {
    @Autowired
    private AssistanceApplyDao assistanceApplyDao;
    public AssistanceApplyModel findById(int id){
        return assistanceApplyDao.findOne(id);
    }
    public AssistanceApplyModel solutionApply(int id,String replyUserId,String replyContent) throws ManageException {
        AssistanceApplyModel applyModel = findById(id);
        if (applyModel == null) {
            throw new ManageException("申请记录不存在!");
        }
        applyModel.setSolutionUserId(replyUserId);
        applyModel.setSolutionReply(replyContent);
        applyModel.setSolutionDate(new Date());
        applyModel.setSolutionStatus(0);
        assistanceApplyDao.save(applyModel);
        return applyModel;
    }
    /**
     * 根据申请状态-获取今日统计量
     * @param status
     * @return
     */
    public long toDayCount(int status) {
        String toDay = DateUtil.getNowDate(DateUtil.DEFAULT_DATE_YMD_FORMAT);
        long todayCount = assistanceApplyDao.countAllBySolutionStatusAndCreateTimeBetween(status, toDay + " 00:00:00", toDay + " 23:59:59");
        return todayCount;
    }
}

+ 253 - 0
src/main/java/com/yihu/ehr/svrinspection/service/ExamStatisticsService.java

@ -0,0 +1,253 @@
package com.yihu.ehr.svrinspection.service;
import com.yihu.ehr.model.geography.MGeographyDict;
import com.yihu.ehr.model.org.MOrganization;
import com.yihu.ehr.profile.core.ResourceCore;
import com.yihu.ehr.solr.SolrUtil;
import com.yihu.ehr.svrinspection.commons.exception.ManageException;
import com.yihu.ehr.svrinspection.commons.service.BaseService;
import com.yihu.ehr.svrinspection.feign.AddressClient;
import com.yihu.ehr.util.datetime.DateUtil;
import com.yihu.ehr.util.log.LogService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
/**
 *  检验数据统计-solr
 * @author HZY
 * @created 2018/11/15 14:01
 */
@Component
public class ExamStatisticsService extends BaseService {
    private static String core = ResourceCore.SubTable;
    @Autowired
    private AddressClient addressClient;
    @Autowired
    private SolrUtil solrUtil;
    @Autowired
    private AssistanceApplyService assistanceApplyService;
    /**
     *  区域检验统计分布
     *
     * @param pid           上级区域编码
     * @param field         分组字段
     * @param eventDate
     * @return
     * @throws Exception
     */
    public List<Map<String,Object>> areaGroupCount(Integer pid, String field, String eventDate) throws Exception {
       List<Map<String,Object>> resultList = new ArrayList<>();
        StringBuilder fq = new StringBuilder();
        Map<String, Long> result = new TreeMap<>();
        String q = "(rowkey:*HDSD00_79* OR rowkey:*HDSD00_77*)";//solr细表中的检查检验
        if (StringUtils.isBlank(eventDate)) {
            LogService.getLogger().error("eventDate is null,check your params");
            throw new Exception("eventDate is null,check your params");
        }
        //事件日期
        fq.append("event_date:[" + eventDate + "T00:00:00Z TO " + eventDate + "T23:59:59Z]");
        //统计查询
        Map<String, Long> facetField = solrUtil.groupCount(core,q, fq.toString(),field, 0, -1);
        //获取区县列表
        List<MGeographyDict> addressList = addressClient.getAddressDictByPid(pid);
        addressList.stream().forEach(address ->{
            Map<String,Object> areaData = areaData = new HashMap<>();
            areaData.put("areaCode",address.getPid());
            areaData.put("areaName",address.getName());
            if (facetField.get(String.valueOf(address.getId())) == null) {
                areaData.put("count",0);
            }else {
                areaData.put("count",facetField.get(String.valueOf(address.getId())));
            }
            resultList.add(areaData);
        });
        comparator(resultList,"count");
        return resultList;
    }
    /**
     * 医院检验统计分布
     *
     * @param areaCode      区域编码
     * @param field         分组字段
     * @param eventDate     事件时间
     * @return
     * @throws Exception
     */
    public List<Map<String,Object>> hospitalGroupCount(String areaCode, String field, String eventDate) throws Exception {
        List<Map<String,Object>> resultList = new ArrayList<>();
        StringBuilder fq = new StringBuilder();
        String q = "(rowkey:*HDSD00_79* OR rowkey:*HDSD00_77*)";//solr细表中的检查检验
        if (StringUtils.isBlank(areaCode)) {
            throw new ManageException("areaCode is null,check your params");
        }
        if (StringUtils.isBlank(eventDate)) {
            throw new ManageException("eventDate is null,check your params");
        }
        //区域编码
        fq.append("org_area:"+areaCode);
        //事件日期
        fq.append(" && event_date:[" + eventDate + "T00:00:00Z TO " + eventDate + "T23:59:59Z]");
        //统计查询
        Map<String, Long> facetField = solrUtil.groupCount(core,q, fq.toString(),field, 0, -1);
        //获取区县列表
        List<MOrganization> addressList = addressClient.getOrganizationByAreaCode(areaCode);
        addressList.stream().forEach(organization ->{
           //只显示有检验数的医院
            if (facetField.get(organization.getOrgCode()) != null) {
                Map<String,Object> areaData = areaData = new HashMap<>();
                areaData.put("orgCode",organization.getOrgCode());
                areaData.put("orgName",organization.getFullName());
                areaData.put("count",facetField.get(organization.getOrgCode()));
                resultList.add(areaData);
            }
        });
        comparator(resultList,"count");
        return resultList;
    }
    /**
     *  区域检验数统计
     *
     * TODO 累计数和新增数先从solr获取,后期考虑是否同步到mysql中
     * @param areaCode
     * @param eventDate
     * @return
     */
    public Map<String,Object> areaExamStatistics(String areaCode, String eventDate) throws Exception {
        Map<String,Object> result = new HashMap<>();
        //累计检验数
        long total = totalCount(areaCode, eventDate);
        //今日新增数
        long today = todayIncreaseCount(areaCode);
        //已申请数
        long apply = assistanceApplyService.toDayCount(0);
        //已处理数
        long solution = assistanceApplyService.toDayCount(1);
        //业务分布
        List<Map<String, Object>> list = examEventRanking(areaCode, eventDate);
        result.put("total",total);
        result.put("increase",today);
        result.put("applied",apply);
        result.put("solution",solution);
        result.put("eventPercentage",solution);
        return result;
    }
    /**
     *  solr 获取检验累计总数
     *
     * @param areaCode      区域编码
     * @param eventDate     时间
     * @return
     * @throws ManageException
     */
    public long totalCount(String areaCode, String eventDate) throws ManageException {
        long total = 0;
        StringBuilder fq = new StringBuilder();
        String q = "(rowkey:*HDSD00_79* OR rowkey:*HDSD00_77*)";//solr细表中的检查检验
        if (!StringUtils.isBlank(areaCode)) {
            //区域编码
            fq.append("org_area:"+areaCode);
        }
        if (StringUtils.isBlank(eventDate)) {
            throw new ManageException("eventDate is null,check your params");
        }
        //事件日期
        fq.append(" && event_date:[" + eventDate + "T00:00:00Z TO " + eventDate + "T23:59:59Z]");
        //统计查询
        try {
             total = solrUtil.count(core,q, fq.toString());
        } catch (Exception e) {
            throw new ManageException("获取累计统计数异常",e);
        }
        return total;
    }
    /**
     *  今日新增检验数
     *
     * @param areaCode  区域编码
     * @return
     * @throws ManageException
     */
    public long todayIncreaseCount(String areaCode) throws ManageException {
        long total = 0;
        StringBuilder fq = new StringBuilder();
        String q = "(rowkey:*HDSD00_79* OR rowkey:*HDSD00_77*)";//solr细表中的检查检验
        if (!StringUtils.isBlank(areaCode)) {
            //区域编码
            fq.append("org_area:"+areaCode);
        }
        String createDate = DateUtil.getNowDate(DateUtil.DEFAULT_DATE_YMD_FORMAT);
        //创建日期
        fq.append(" && create_date:[" + createDate + "T00:00:00Z TO " + createDate + "T23:59:59Z]");
        //统计查询
        try {
            total = solrUtil.count(core,q, fq.toString());
        } catch (Exception e) {
            throw new ManageException("获取今日新增档案数异常",e);
        }
        return total;
    }
    /**
     * 检验次数业务分布
     *
     * @param areaCode      区域编码
     * @param eventDate     时间
     * @return
     * @throws Exception
     */
    public List<Map<String,Object>> examEventRanking(String areaCode, String eventDate) throws Exception {
        List<Map<String,Object>> resultList = new ArrayList<>();
        StringBuilder fq = new StringBuilder();
        String q = "(rowkey:*HDSD00_79* OR rowkey:*HDSD00_77*)";//solr细表中的检查检验
        if (StringUtils.isBlank(areaCode)) {
            throw new ManageException("areaCode is null,check your params");
        }
        if (StringUtils.isBlank(eventDate)) {
            throw new ManageException("eventDate is null,check your params");
        }
        //区域编码
        fq.append("org_area:"+areaCode);
        //事件日期
        fq.append(" && event_date:[" + eventDate + "T00:00:00Z TO " + eventDate + "T23:59:59Z]");
        //统计查询
        Map<String, Long> facetField = solrUtil.groupCount(core,q, fq.toString(),"event_type", 0, -1);
        comparator(resultList,"count");
        return resultList;
    }
}

+ 33 - 0
src/main/resources/application.yml

@ -20,6 +20,39 @@ spring:
spring:
  profiles: dev
  datasource:
<<<<<<< HEAD
    url: jdbc:mysql://172.18.20.105:3312/healtharchive?useUnicode=true&characterEncoding=UTF-8&useSSL=false
    username: cloud
    password: o8t$P39ekYSZ
=======
    url: jdbc:mysql://172.19.103.50:3306/healtharchive?useUnicode=true&characterEncoding=UTF-8&useSSL=false
    username: chenweishan
    password: chenweishan
  data:
    solr:
      zk-host: node1.hde.h3c.com,node2.hde.h3c.com,node3.hde.h3c.com:2181/solr
---
spring:
  profiles: test
  datasource:
    url: jdbc:mysql://172.19.103.50:3306/healtharchive?useUnicode=true&characterEncoding=UTF-8&useSSL=false
    username: chenweishan
    password: chenweishan
  data:
    solr:
      zk-host: node1.hde.h3c.com,node2.hde.h3c.com,node3.hde.h3c.com:2181/solr
---
spring:
  profiles: prod
  datasource:
    url: jdbc:mysql://172.19.103.50:3306/healtharchive?useUnicode=true&characterEncoding=UTF-8&useSSL=false
    username: chenweishan
    password: chenweishan
  data:
    solr:
      zk-host: node1.hde.h3c.com,node2.hde.h3c.com,node3.hde.h3c.com:2181/solr
>>>>>>> master