Forráskód Böngészése

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

yeshijie 7 éve
szülő
commit
82c9e94e90

+ 30 - 30
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientHealthGuidanceDao.java

@ -1,6 +1,6 @@
/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.yihu.wlyy.repository.patient;
@ -18,43 +18,43 @@ import com.yihu.wlyy.entity.patient.PatientHealthGuidance;
public interface PatientHealthGuidanceDao extends PagingAndSortingRepository<PatientHealthGuidance, Long>, JpaSpecificationExecutor<PatientHealthGuidance> {
	@Query("select b.name, b.photo, a.id, a.content, a.createTime,b.level,a.readStatus from PatientHealthGuidance a, Doctor b where a.patient = ?1 and a.doctor = b.code and a.del = '1' order by a.id desc")
	Page<Object> findByPatient(String patient, Pageable pageRequest);
    @Query("select b.name, b.photo, a.id, a.content, a.createTime,b.level,a.readStatus from PatientHealthGuidance a, Doctor b where a.patient = ?1 and a.doctor = b.code and a.del = '1' order by a.id desc")
    Page<Object> findByPatient(String patient, Pageable pageRequest);
	@Query("select b.name, b.photo, a.id, a.content, a.createTime,b.level,a.readStatus from PatientHealthGuidance a, Doctor b where a.patient = ?1 and a.doctor = b.code and a.id < ?2 and a.del = '1' order by a.id desc")
	Page<Object> findByPatient(String patient, long id, Pageable pageRequest);
	
	@Query("select b.name, b.photo, a.id, a.content, a.czrq from PatientHealthGuidance a, Patient b where a.doctor = ?1 and a.patient = b.code and a.del = '1' order by a.id desc")
	Page<Object> findByDoctor(String doctor, Pageable pageRequest);
	
	@Query("select b.name, b.photo, a.id, a.content, a.czrq from PatientHealthGuidance a, Patient b where a.doctor = ?1 and a.id < ?2 and a.patient = b.code and a.del = '1' order by a.id desc")
	Page<Object> findByDoctor(String doctor, long id, Pageable pageRequest);
    @Query("select b.name, b.photo, a.id, a.content, a.createTime,b.level,a.readStatus from PatientHealthGuidance a, Doctor b where a.patient = ?1 and a.doctor = b.code and a.id < ?2 and a.del = '1' order by a.id desc")
    Page<Object> findByPatient(String patient, long id, Pageable pageRequest);
	@Query("select b.name, b.photo, a.id, a.content, a.czrq from PatientHealthGuidance a, Patient b where a.doctor = ?1 and a.patient = ?2 and a.patient = b.code and a.del = '1' order by a.id desc")
	Page<Object> findByDoctor(String doctor, String patient, Pageable pageRequest);
    @Query("select b.name, b.photo, a.id, a.content, a.czrq from PatientHealthGuidance a, Patient b where a.doctor = ?1 and a.patient = b.code and a.del = '1' order by a.id desc")
    Page<Object> findByDoctor(String doctor, Pageable pageRequest);
	@Query("select b.name, b.photo, a.id, a.content, a.czrq from PatientHealthGuidance a, Patient b where a.doctor = ?1 and a.patient = ?2 and a.patient = b.code and a.id < ?3 and a.del = '1' order by a.id desc")
	Page<Object> findByDoctor(String doctor, String patient, long id, Pageable pageRequest);
    @Query("select b.name, b.photo, a.id, a.content, a.czrq from PatientHealthGuidance a, Patient b where a.doctor = ?1 and a.id < ?2 and a.patient = b.code and a.del = '1' order by a.id desc")
    Page<Object> findByDoctor(String doctor, long id, Pageable pageRequest);
	@Query("select b.name, b.photo, a.id, a.content, a.czrq from PatientHealthGuidance a, Patient b where a.doctor = ?1 and a.czrq between ?2 and ?3 and a.patient = b.code and a.del = '1' order by a.id desc")
	Page<Object> findByDoctor(String doctor, Date begin, Date end, Pageable pageRequest);
    @Query("select b.name, b.photo, a.id, a.content, a.czrq from PatientHealthGuidance a, Patient b where a.doctor = ?1 and a.patient = ?2 and a.patient = b.code and a.del = '1' order by a.id desc")
    Page<Object> findByDoctor(String doctor, String patient, Pageable pageRequest);
	@Query("select b.name, b.photo, a.id, a.content, a.czrq from PatientHealthGuidance a, Patient b where a.doctor = ?1 and a.czrq between ?2 and ?3 and a.id < ?4 and a.patient = b.code and a.del = '1' order by a.id desc")
	Page<Object> findByDoctor(String doctor, Date begin, Date end, long id, Pageable pageRequest);
    @Query("select b.name, b.photo, a.id, a.content, a.czrq from PatientHealthGuidance a, Patient b where a.doctor = ?1 and a.patient = ?2 and a.patient = b.code and a.id < ?3 and a.del = '1' order by a.id desc")
    Page<Object> findByDoctor(String doctor, String patient, long id, Pageable pageRequest);
	@Query("select b.name, b.photo, a.id, a.content, a.czrq from PatientHealthGuidance a, Patient b where a.doctor = ?1 and a.patient = ?2 and a.czrq between ?3 and ?4 and a.patient = b.code and a.del = '1' order by a.id desc")
	Page<Object> findByDoctor(String doctor, String patient, Date begin, Date end, Pageable pageRequest);
    @Query("select b.name, b.photo, a.id, a.content, a.czrq from PatientHealthGuidance a, Patient b where a.doctor = ?1 and a.czrq between ?2 and ?3 and a.patient = b.code and a.del = '1' order by a.id desc")
    Page<Object> findByDoctor(String doctor, Date begin, Date end, Pageable pageRequest);
	@Query("select b.name, b.photo, a.id, a.content, a.czrq from PatientHealthGuidance a, Patient b where a.doctor = ?1 and a.patient = ?2 and a.czrq between ?3 and ?4 and a.id < ?5 and a.patient = b.code and a.del = '1' order by a.id desc")
	Page<Object> findByDoctor(String doctor, String patient, Date begin, Date end, long id, Pageable pageRequest);
    @Query("select b.name, b.photo, a.id, a.content, a.czrq from PatientHealthGuidance a, Patient b where a.doctor = ?1 and a.czrq between ?2 and ?3 and a.id < ?4 and a.patient = b.code and a.del = '1' order by a.id desc")
    Page<Object> findByDoctor(String doctor, Date begin, Date end, long id, Pageable pageRequest);
	//查找昨天的健康指导
	@Query("SELECT a FROM PatientHealthGuidance a WHERE unix_timestamp(a.czrq)>=unix_timestamp(?1) and unix_timestamp(a.czrq)<unix_timestamp(?2) ")
	List<PatientHealthGuidance> findByCzrqyYesterday(String yesterday,String now );
    @Query("select b.name, b.photo, a.id, a.content, a.czrq from PatientHealthGuidance a, Patient b where a.doctor = ?1 and a.patient = ?2 and a.czrq between ?3 and ?4 and a.patient = b.code and a.del = '1' order by a.id desc")
    Page<Object> findByDoctor(String doctor, String patient, Date begin, Date end, Pageable pageRequest);
	@Query("SELECT count(a) from PatientHealthGuidance a WHERE  a.patient=?2 and a.doctor=?1 ")
	Integer findbydoctorAndPatient(String doctor, String patientCode);
    @Query("select b.name, b.photo, a.id, a.content, a.czrq from PatientHealthGuidance a, Patient b where a.doctor = ?1 and a.patient = ?2 and a.czrq between ?3 and ?4 and a.id < ?5 and a.patient = b.code and a.del = '1' order by a.id desc")
    Page<Object> findByDoctor(String doctor, String patient, Date begin, Date end, long id, Pageable pageRequest);
	@Query("select b.name, b.photo, a.id, substring(a.content, 1, 50) as content, a.createTime,b.level,b.code,a.adminTeamCode from PatientHealthGuidance a, Doctor b where a.doctor = b.code and a.patient = ?1 and a.adminTeamCode = ?2 and a.del = '1'")
	Page<Object> findByPatientAndTeamCode(String patient, Long teamCode, Pageable pageable);
    //查找昨天的健康指导
    @Query("SELECT a FROM PatientHealthGuidance a WHERE unix_timestamp(a.czrq)>=unix_timestamp(?1) and unix_timestamp(a.czrq)<unix_timestamp(?2) ")
    List<PatientHealthGuidance> findByCzrqyYesterday(String yesterday, String now);
    @Query("SELECT count(a) from PatientHealthGuidance a WHERE  a.patient=?2 and a.doctor=?1 ")
    Integer findbydoctorAndPatient(String doctor, String patientCode);
    @Query("select b.name, b.photo, a.id, substring(a.content, 1, 50) as content, a.createTime,b.level,b.code,a.adminTeamCode from PatientHealthGuidance a, Doctor b where a.doctor = b.code and a.patient = ?1 and a.adminTeamCode = ?2 and a.del = '1'")
    Page<Object> findByPatientAndTeamCode(String patient, Long teamCode, Pageable pageable);
}

+ 88 - 84
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionService.java

@ -231,97 +231,101 @@ public class PrescriptionService extends BaseService {
            if(200 == status && 1 == code){
                JSONArray zyCfinfoListReturnData = zyCfinfo.getJSONArray("returnData");
                JSONArray zyCfinfoList = zyCfinfoListReturnData.getJSONArray(0);
                JSONArray cfInfo = new JSONArray();
                for (int i = 0; i < zyCfinfoList.size(); i++) {
                    JSONObject zyCfinfoObj = zyCfinfoList.getJSONObject(i);
                    //支付明细
                    JSONArray zySettleDetailList = zyCfinfoList.getJSONObject(i).getJSONArray("SETTLE_DETAIL");
                    //根据挂号号获取处方明细
                    Prescription prescription = prescriptionDao.findByVisitNoAndRecipeNo(zyCfinfoObj.getString("VISIT_NO"),recipeNo);
                    List<PrescriptionDiagnosis> pds = prescriptionDiagnosisDao.findByPrescriptionCode(prescription.getCode());
                    //诊断明细        {"zdms00":"诊断或症状描述","zdbh00":"诊断或症状编码"}
                    if (!pds.isEmpty()){
                        JSONArray zdInfo = new JSONArray();
                        for (PrescriptionDiagnosis pd : pds) {
                            JSONObject j1 = new JSONObject();
                            j1.put("zdms00",pd.getName());//诊断或症状描述"1型糖尿病性酮症"
                            j1.put("zdbh00",pd.getCode());//诊断或症状编码"E10.100"
                            zdInfo.add(j1);
                
                if(zyCfinfoListReturnData.size()!=0 && !zyCfinfoListReturnData.isEmpty()){
    
                    JSONArray zyCfinfoList = zyCfinfoListReturnData.getJSONArray(0);
                    JSONArray cfInfo = new JSONArray();
                    for (int i = 0; i < zyCfinfoList.size(); i++) {
        
                        JSONObject zyCfinfoObj = zyCfinfoList.getJSONObject(i);
                        //支付明细
                        JSONArray zySettleDetailList = zyCfinfoList.getJSONObject(i).getJSONArray("SETTLE_DETAIL");
                        //根据挂号号获取处方明细
                        Prescription prescription = prescriptionDao.findByVisitNoAndRecipeNo(zyCfinfoObj.getString("VISIT_NO"),recipeNo);
        
                        List<PrescriptionDiagnosis> pds = prescriptionDiagnosisDao.findByPrescriptionCode(prescription.getCode());
                        //诊断明细        {"zdms00":"诊断或症状描述","zdbh00":"诊断或症状编码"}
                        if (!pds.isEmpty()){
                            JSONArray zdInfo = new JSONArray();
                            for (PrescriptionDiagnosis pd : pds) {
                                JSONObject j1 = new JSONObject();
                                j1.put("zdms00",pd.getName());//诊断或症状描述"1型糖尿病性酮症"
                                j1.put("zdbh00",pd.getCode());//诊断或症状编码"E10.100"
                                zdInfo.add(j1);
                            }
                            json.put("zdlist",zdInfo);
                        }
                        json.put("zdlist",zdInfo);
                    }
                    //收费明细       {"xmgg00":"项目规格","cfhao0":"处方号","sfybxm":"是否医保项目","dcyydw":"单次用药单位","xmje00":"项目金额","xmbh00":"项目编号",
                    // "ysxm00":"医生姓名","yppl00":"药品频率","gytj00":"给药途径","ypts00":"药品天数","xmdj00":"项目单价","qyzl00":"取药总量","ylts00":"药量天数",
                    // "sptxbm":"商品条形编码","xmmc00":"项目名称","fpxmbh":"发票项目编号","xmsl00":"项目数量","ypyl00":"药品用量","qyzldw":"取药单位","xmdw00":"项目单位",
                    // "jx0000":"剂型"}
                    Integer cfxms0 = 0;
                    for (int j= 0; j < zySettleDetailList.size(); j++) {
                        JSONObject zySettleDetailObj = zySettleDetailList.getJSONObject(j);
        
        
                        //收费明细       {"xmgg00":"项目规格","cfhao0":"处方号","sfybxm":"是否医保项目","dcyydw":"单次用药单位","xmje00":"项目金额","xmbh00":"项目编号",
                        // "ysxm00":"医生姓名","yppl00":"药品频率","gytj00":"给药途径","ypts00":"药品天数","xmdj00":"项目单价","qyzl00":"取药总量","ylts00":"药量天数",
                        // "sptxbm":"商品条形编码","xmmc00":"项目名称","fpxmbh":"发票项目编号","xmsl00":"项目数量","ypyl00":"药品用量","qyzldw":"取药单位","xmdw00":"项目单位",
                        // "jx0000":"剂型"}
        
                        Integer cfxms0 = 0;
                        for (int j= 0; j < zySettleDetailList.size(); j++) {
                            JSONObject zySettleDetailObj = zySettleDetailList.getJSONObject(j);
//                        String RECIPE_NO = zySettleDetailObj.getString("RECIPE_NO");
//                        if(recipeNo.equals(RECIPE_NO)){//过滤其他处方号
                        cfxms0++;
                        JSONObject j2 = new JSONObject();
                        j2.put("xmbh00",zySettleDetailObj.getString("INSUR_ITEM_CODE"));//项目编号
                        j2.put("xmmc00",zySettleDetailObj.getString("INSUR_ITEM_NAME"));//项目名称
                        j2.put("fpxmbh",zySettleDetailObj.getString("INSUR_INVOICE_TYPE_CODE"));//发票项目编号
                        j2.put("sfybxm",zySettleDetailObj.getString("INSUR_FLAG"));//是否医保项目
                        Double _price = Double.parseDouble(zySettleDetailObj.getString("INSUR_ITEM_PRICE"));
                        DecimalFormat df = new DecimalFormat("######0.00");
                        _price = _price*100;
                        j2.put("xmdj00",df.format(_price));//项目单价
                        j2.put("xmdw00",zySettleDetailObj.getString("INSUR_ITEM_UNIT_NAME"));//项目单位
                        j2.put("xmgg00",zySettleDetailObj.getString("INSUR_ITEM_SPEC"));//项目规格(医保)
                        j2.put("xmsl00",zySettleDetailObj.getString("ITEM_QUANTITY"));//项目数量
                        Double _cost = Double.parseDouble(zySettleDetailObj.getString("COST"));
                        Integer infocost = CommonUtil.doubleToInt(_cost);
                        j2.put("xmje00",String.valueOf(infocost));//项目金额
                        j2.put("ysxm00",zySettleDetailObj.getString("APPLY_OPERATOR_NAME"));//医生姓名
                        j2.put("sptxbm","");//商品条形编码
                        j2.put("yppl00",zySettleDetailObj.getString("FREQUENCY"));//药品频率
                        j2.put("ypyl00",zySettleDetailObj.getString("PHYSIC_DOSE"));//药品用量
                        j2.put("cfhao0",zySettleDetailObj.getString("RECIPE_NO"));//处方号
                        j2.put("jx0000",zySettleDetailObj.getString("PHYSIC_FORM"));//剂型
                        j2.put("dcyydw",zySettleDetailObj.getString("PHYSIC_DOSE_UNIT"));//单次用药单位
                        j2.put("qyzl00",zySettleDetailObj.getString("PHYSIC_AMOUNT"));//取药总量
                        j2.put("qyzldw",zySettleDetailObj.getString("PHYSIC_AMOUNT_UNIT"));//取药单位
                        j2.put("gytj00",zySettleDetailObj.getString("PHYSIC_USAGE"));//给药途径
                        j2.put("ypts00",zySettleDetailObj.getString("DAY_COUNT"));//药品天数
                        cfInfo.add(j2);
                            cfxms0++;
                            JSONObject j2 = new JSONObject();
                            j2.put("xmbh00",zySettleDetailObj.getString("INSUR_ITEM_CODE"));//项目编号
                            j2.put("xmmc00",zySettleDetailObj.getString("INSUR_ITEM_NAME"));//项目名称
                            j2.put("fpxmbh",zySettleDetailObj.getString("INSUR_INVOICE_TYPE_CODE"));//发票项目编号
                            j2.put("sfybxm",zySettleDetailObj.getString("INSUR_FLAG"));//是否医保项目
            
                            Double _price = Double.parseDouble(zySettleDetailObj.getString("INSUR_ITEM_PRICE"));
                            DecimalFormat df = new DecimalFormat("######0.00");
                            _price = _price*100;
                            j2.put("xmdj00",df.format(_price));//项目单价
            
                            j2.put("xmdw00",zySettleDetailObj.getString("INSUR_ITEM_UNIT_NAME"));//项目单位
                            j2.put("xmgg00",zySettleDetailObj.getString("INSUR_ITEM_SPEC"));//项目规格(医保)
                            j2.put("xmsl00",zySettleDetailObj.getString("ITEM_QUANTITY"));//项目数量
            
                            Double _cost = Double.parseDouble(zySettleDetailObj.getString("COST"));
                            Integer infocost = CommonUtil.doubleToInt(_cost);
                            j2.put("xmje00",String.valueOf(infocost));//项目金额
            
                            j2.put("ysxm00",zySettleDetailObj.getString("APPLY_OPERATOR_NAME"));//医生姓名
                            j2.put("sptxbm","");//商品条形编码
                            j2.put("yppl00",zySettleDetailObj.getString("FREQUENCY"));//药品频率
                            j2.put("ypyl00",zySettleDetailObj.getString("PHYSIC_DOSE"));//药品用量
                            j2.put("cfhao0",zySettleDetailObj.getString("RECIPE_NO"));//处方号
                            j2.put("jx0000",zySettleDetailObj.getString("PHYSIC_FORM"));//剂型
                            j2.put("dcyydw",zySettleDetailObj.getString("PHYSIC_DOSE_UNIT"));//单次用药单位
                            j2.put("qyzl00",zySettleDetailObj.getString("PHYSIC_AMOUNT"));//取药总量
                            j2.put("qyzldw",zySettleDetailObj.getString("PHYSIC_AMOUNT_UNIT"));//取药单位
                            j2.put("gytj00",zySettleDetailObj.getString("PHYSIC_USAGE"));//给药途径
                            j2.put("ypts00",zySettleDetailObj.getString("DAY_COUNT"));//药品天数
                            cfInfo.add(j2);
//                        }
                        }
        
                        //处方主信息     {"yyksbm":"医生科室编号","bcsfcs":"本次收费次数","yszjhm":"医生证件号码","ysxm00":"医生姓名","mzlb00":"门诊类别","sfydgh":"是否药店挂号",
                        // "bcghcs":"本次挂号次数","ghksmc":"挂号科室名称","cfxms0":"明细上传数量","mzlsh0":"医保挂号流水号 如果为空,将自动医保挂号并收费","ghfy00":"挂号费用",
                        // "yszjdj":"医师诊金级别","bqbm00":"病情编码","sfygwd":"是否医改网点"}
                        JSONObject jsonObject = new JSONObject();
                        jsonObject.put("yyksbm",zyCfinfoObj.getString("VISIT_DEPT"));//医生科室编号
                        jsonObject.put("bcsfcs","1");//本次收费次数
                        jsonObject.put("yszjhm",zyCfinfoObj.getString("VISIT_IDENTITY_CARD_NO"));//医生证件号码
                        jsonObject.put("ysxm00",prescription.getDoctorName());//医生姓名
                        jsonObject.put("mzlb00",zyCfinfoObj.getString("INSUR_DISP_REGISTER_TYPE"));//门诊类别---普通门诊默认为101
                        jsonObject.put("sfydgh","N");//是否药店挂号,默认为N,不是药店挂号
                        jsonObject.put("bcghcs","1");//本次挂号次数
                        jsonObject.put("ghksmc",prescription.getDeptName());//挂号科室名称
                        jsonObject.put("mzlsh0","");//医保挂号流水号
                        jsonObject.put("ghfy00","0");//挂号费用
                        jsonObject.put("bqbm00","");//病情编码---可为空,不传递
                        jsonObject.put("sfygwd","N");//是否医改网点--默认为否
                        jsonObject.put("yszjdj",zyCfinfoObj.getString("INSUR_DOCTOR_RANK"));//医师诊金级别
                        jsonObject.put("cfxms0",""+cfxms0);//明细上传数量
                        json.put("recipeContent",jsonObject);
                    }
                    //处方主信息     {"yyksbm":"医生科室编号","bcsfcs":"本次收费次数","yszjhm":"医生证件号码","ysxm00":"医生姓名","mzlb00":"门诊类别","sfydgh":"是否药店挂号",
                    // "bcghcs":"本次挂号次数","ghksmc":"挂号科室名称","cfxms0":"明细上传数量","mzlsh0":"医保挂号流水号 如果为空,将自动医保挂号并收费","ghfy00":"挂号费用",
                    // "yszjdj":"医师诊金级别","bqbm00":"病情编码","sfygwd":"是否医改网点"}
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("yyksbm",zyCfinfoObj.getString("VISIT_DEPT"));//医生科室编号
                    jsonObject.put("bcsfcs","1");//本次收费次数
                    jsonObject.put("yszjhm",zyCfinfoObj.getString("VISIT_IDENTITY_CARD_NO"));//医生证件号码
                    jsonObject.put("ysxm00",prescription.getDoctorName());//医生姓名
                    jsonObject.put("mzlb00",zyCfinfoObj.getString("INSUR_DISP_REGISTER_TYPE"));//门诊类别---普通门诊默认为101
                    jsonObject.put("sfydgh","N");//是否药店挂号,默认为N,不是药店挂号
                    jsonObject.put("bcghcs","1");//本次挂号次数
                    jsonObject.put("ghksmc",prescription.getDeptName());//挂号科室名称
                    jsonObject.put("mzlsh0","");//医保挂号流水号
                    jsonObject.put("ghfy00","0");//挂号费用
                    jsonObject.put("bqbm00","");//病情编码---可为空,不传递
                    jsonObject.put("sfygwd","N");//是否医改网点--默认为否
                    jsonObject.put("yszjdj",zyCfinfoObj.getString("INSUR_DOCTOR_RANK"));//医师诊金级别
                    jsonObject.put("cfxms0",""+cfxms0);//明细上传数量
                    json.put("recipeContent",jsonObject);
                    json.put("mxlist",cfInfo);
                }
                json.put("mxlist",cfInfo);
            }else{
                String errormessage = jwobj.getString("MESSAGE");
                throw new Exception(errormessage);

+ 180 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statisticsES/StatisticsESService.java

@ -0,0 +1,180 @@
package com.yihu.wlyy.service.app.statisticsES;
import com.yihu.wlyy.config.es.ElasticFactory;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionDispensaryCode;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.ElasticsearchUtil;
import com.yihu.wlyy.web.quota.vo.SaveModel;
import io.searchbox.client.JestClient;
import io.searchbox.core.Bulk;
import io.searchbox.core.BulkResult;
import io.searchbox.core.Index;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
 * Created by ${liuwenbin} on 2017/9/14.
 */
@Service
public class StatisticsESService {
    @Autowired
    private ElasticsearchUtil elasticsearchUtil;
    @Autowired
    private ElasticFactory elasticFactory;
    /**
     * 获取上次统计时间
     *
     * @return
     */
    public String getStatisticsTime() {
        String date = DateUtil.dateToStrLong(new Date());
        try {
//            date = redisTemplate.opsForValue().get("quota:date");
//            JestClient jestClient = elasticFactory.getJestClient();
//
//            Bulk.Builder bulk = new Bulk.Builder().defaultIndex("health_edu_article_patient_test").defaultType("health_edu_article_patient_test");
//            PrescriptionDispensaryCode ap = new PrescriptionDispensaryCode();
//            ap.setCode("aaaa");
//            ap.setType(2);
//            Index index = new Index.Builder(ap).build();
//            bulk.addAction(index);
//            BulkResult br = jestClient.execute(bulk.build());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }
    /**
     * 获取时间戳
     *
     * @return
     */
    public String getQuotaTimeStamp() {
//        return redisTemplate.opsForValue().get("quota:timeKey");
        return "";
    }
    /**
     * 获取时间范围内按间隔统计指标增量
     *
     * @param startDate 起始时间
     * @param endDate   结束时间
     * @param interval  时间间隔
     * @param area      区域或机构代码
     * @param level     级别
     * @param index     指标
     * @return
     */
    public JSONArray getDateIncrementDetail(String startDate, String endDate, int interval, String area, String level, String index, String level2_type) throws Exception {
        if (interval == 1) {
            return dateStatistics(startDate, endDate, area, level, index, level2_type);
        } else if (interval == 2) {
//            return weekStatistics(startDate, endDate, area, level, index, level2_type);
        } else if (interval == 3) {
//            return monthStatistics(startDate, endDate, area, level, index, level2_type);
        }
        return new JSONArray();
    }
    /**
     * 按日统计
     *
     * @param startDate
     * @param endDate
     * @param area
     * @param level
     * @param index
     * @return
     */
    private JSONArray dateStatistics(String startDate, String endDate, String area, String level, String index, String level2_type) {
//        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
//        // 起始日期
//        Calendar start = Calendar.getInstance();
//        start.setTime(DateUtil.strToDate(startDate, DateUtil.YYYY_MM_DD));
//        //结束日期
//        Calendar end = Calendar.getInstance();
//        end.setTime(DateUtil.strToDate(endDate, DateUtil.YYYY_MM_DD));
//        // 日期集合
//        List<Calendar> days = new ArrayList<>();
//        days.add(start);
//        boolean flag = true;
//        if (startDate.compareTo(endDate) == 0) {
//            flag = false;
//        }
//         计算统计日期
//        while (flag) {
//            Calendar next = Calendar.getInstance();
//            next.setTime(days.get(days.size() - 1).getTime());
//            next.add(Calendar.DATE, 1);
//            if (df.format(next.getTime()).compareTo(endDate) < 0) {
//                days.add(next);
//            } else {
//                days.add(end);
//                flag = false;
//            }
//        }
        startDate = changeDate(startDate);
        endDate = changeDate(endDate);
        StringBuffer sql = new StringBuffer();
        StringBuffer groupBy = new StringBuffer();
        if (SaveModel.teamLevel.equals(level)) {
            sql.append("select team,teamName,slaveKey1,slaveKey1Name,result1,result2 from wlyy_quota_test where team='" + area + "'");
            groupBy.append("  group by team,teamName,slaveKey1,slaveKey1Name");
        } else if (SaveModel.OrgLevel.equals(level)) {
            sql.append("select hospital,hospitalName,slaveKey1,slaveKey1Name,sum(result1) result1,sum(result2) result2 from wlyy_quota_test where hospital='" + area + "'");
            groupBy.append("  group by hospital,hospitalName,slaveKey1,slaveKey1Name");
        } else if (SaveModel.townLevel.equals(level)) {
            sql.append("select town,townName,slaveKey1,slaveKey1Name,sum(result1) result1,sum(result2) result2 from wlyy_quota_test where town='" + area + "'");
            groupBy.append("  group by town,townName,slaveKey1,slaveKey1Name");
        } else if (SaveModel.cityLevel.equals(level)) {
            sql.append("select city,cityName,slaveKey1,slaveKey1Name,sum(result1) result1,sum(result2) result2 from wlyy_quota_test where city='" + area + "'");
            groupBy.append("  group by city,cityName,slaveKey1,slaveKey1Name");
        }
        sql.append(" and quotaCode='" + index + "'  ");
        sql.append(" and timeLevel='1'  ");
        sql.append(" and areaLevel='"+level+"'");
        sql.append(" and quotaDate>='" + startDate + "'");
        sql.append(" and quotaDate<='" + endDate + "'");
        if(StringUtils.isNotBlank(level2_type)){
            sql.append(" and slaveKey2='"+level2_type+"'");
            groupBy.append(",slaveKey2,slaveKey2Name");
        }
        sql.append(groupBy);
        List<SaveModel> list =elasticsearchUtil.excute(sql.toString(),SaveModel.class,"","");
        List<JSONObject> result = new ArrayList<>();
        for (SaveModel saveModel:list){
            JSONObject range = new JSONObject();
            range.put("range", saveModel.getQuotaDate());
            range.put("amount", saveModel.getResult1());
            result.add(range);
        }
        return new JSONArray(result);
    }
    /**
     * 时间格式转换  yyyy-MM-dd转成 2017-07-17T00:00:00+0800
     *
     * @param quotaDate
     */
    private String changeDate(String quotaDate) {
        return quotaDate + "T00:00:00+0800";
    }
}

+ 4 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ElasticsearchUtil.java

@ -59,7 +59,7 @@ public class ElasticsearchUtil {
                requestBuilder = queryAction.explain();
            }
            SearchResponse response = (SearchResponse) requestBuilder.get();
            ObjectResult temp = new ObjectResultsExtractor(true, true, true).extractResults(response.getAggregations(), true);
            ObjectResult temp = new ObjectResultsExtractor(true, true, true).extractResults(response.getHits(), true);
            List<String> heads = temp.getHeaders();
            temp.getLines().stream().forEach(one -> {
                Object saveModel = null;
@ -72,6 +72,9 @@ public class ElasticsearchUtil {
                    try {
                        String key = null;
                        Object value = one.get(i);
                        if(heads.get(i).startsWith("_")){
                            continue;
                        }
                        if (heads.get(i).contains("date_histogram")) {
                            key = "setQuotaDate";
                            value = DateUtil.strToDate(String.valueOf(value), "yyyy-MM-dd HH:mm:ss");

+ 312 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/quota/vo/SaveModel.java

@ -0,0 +1,312 @@
package com.yihu.wlyy.web.quota.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.searchbox.annotations.JestId;
import org.springframework.data.annotation.CreatedDate;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
 * Created by chenweida on 2017/6/1.
 */
public class SaveModel {
    private final static String teamKey = "team";
    private final static String OrgKey = "hospital";
    private final static String townKey = "town";
    private final static String cityKey = "city";
    public final static String interval_day="1";
    public final static String interval_week="2";
    public final static String interval_month="3";
    public final static String teamLevel = "5";
    public final static String OrgLevel = "4";
    public final static String townLevel = "3";
    public final static String cityLevel = "2";
    private static final Map<String, String> fieldsSithch = new HashMap<>();
    @JestId
    private String id;
    private String saasId;//saasId
    private String quotaCode;//指标code
    private Date quotaDate;//统计时间
    private String city;//城市代码 350200
    private String cityName;//
    private String town;//区代码 350206
    private String townName;//
    private String hospital;//机构code
    private String hospitalName;//
    private String team;//团队的code
    private String teamName;//
    private String slaveKey1;//从维度  1级维度
    private String slaveKey1Name;
    private String slaveKey2;//从维度  2级维度
    private String slaveKey2Name;
    private String slaveKey3;//从维度  3级维度
    private String slaveKey3Name;
    private String slaveKey4;//从维度  4级维度
    private String slaveKey4Name;
    private Integer result1 = 0;//统计结果
    private Integer result2 = 0;//统计结果
    private String areaLevel;// 1 省 2 市 3 区县 4 机构 5团队
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyyMMdd'T'HHmmss.SSS'Z'")
    @CreatedDate
    private Date createTime;//创建时间
    private String timeLevel;// 1日 2年
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy/MM/dd ")
    public Date getQuotaDate() {
        return quotaDate;
    }
    public void setQuotaDate(Date quotaDate) {
        this.quotaDate = quotaDate;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getTown() {
        return town;
    }
    public void setTown(String town) {
        this.town = town;
    }
    //@Field(type = FieldType.String, analyzer="ngram_analyzer")//使用ngram进行单字分词
    public String getHospital() {
        return hospital;
    }
    public void setHospital(String hospital) {
        this.hospital = hospital;
    }
    public String getTeam() {
        return team;
    }
    public void setTeam(String team) {
        this.team = team;
    }
    public String getSlaveKey1() {
        return slaveKey1;
    }
    public void setSlaveKey1(String slaveKey1) {
        this.slaveKey1 = slaveKey1;
    }
    public String getSlaveKey2() {
        return slaveKey2;
    }
    public void setSlaveKey2(String slaveKey2) {
        this.slaveKey2 = slaveKey2;
    }
    public String getSlaveKey3() {
        return slaveKey3;
    }
    public void setSlaveKey3(String slaveKey3) {
        this.slaveKey3 = slaveKey3;
    }
    public String getSlaveKey4() {
        return slaveKey4;
    }
    public void setSlaveKey4(String slaveKey4) {
        this.slaveKey4 = slaveKey4;
    }
    public Integer getResult1() {
        return result1;
    }
    public void setResult1(Integer result1) {
        this.result1 = result1;
    }
    public Integer getResult2() {
        return result2;
    }
    public void setResult2(Integer result2) {
        this.result2 = result2;
    }
    public String getSlaveKey1Name() {
        return slaveKey1Name;
    }
    public void setSlaveKey1Name(String slaveKey1Name) {
        this.slaveKey1Name = slaveKey1Name;
    }
    public String getSlaveKey2Name() {
        return slaveKey2Name;
    }
    public void setSlaveKey2Name(String slaveKey2Name) {
        this.slaveKey2Name = slaveKey2Name;
    }
    public String getSlaveKey3Name() {
        return slaveKey3Name;
    }
    public void setSlaveKey3Name(String slaveKey3Name) {
        this.slaveKey3Name = slaveKey3Name;
    }
    public String getSlaveKey4Name() {
        return slaveKey4Name;
    }
    public void setSlaveKey4Name(String slaveKey4Name) {
        this.slaveKey4Name = slaveKey4Name;
    }
    public String getCityName() {
        return cityName;
    }
    public void setCityName(String cityName) {
        this.cityName = cityName;
    }
    public String getTownName() {
        return townName;
    }
    public void setTownName(String townName) {
        this.townName = townName;
    }
    public String getHospitalName() {
        return hospitalName;
    }
    public void setHospitalName(String hospitalName) {
        this.hospitalName = hospitalName;
    }
    public String getTeamName() {
        return teamName;
    }
    public void setTeamName(String teamName) {
        this.teamName = teamName;
    }
    public String getQuotaCode() {
        return quotaCode;
    }
    public void setQuotaCode(String quotaCode) {
        this.quotaCode = quotaCode;
    }
    public String getAreaLevel() {
        return areaLevel;
    }
    public void setAreaLevel(String areaLevel) {
        this.areaLevel = areaLevel;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getTimeLevel() {
        return timeLevel;
    }
    public void setTimeLevel(String timeLevel) {
        this.timeLevel = timeLevel;
    }
    /**
     * 根据级别得到key
     * 1 省 2 市 3 区县 4 机构 5团队
     *
     * @param level
     * @return
     */
    public static String getAreaLevelKey(String level) {
        switch (level) {
            case teamLevel: {
                return teamKey;
            }
            case OrgLevel: {
                return OrgKey;
            }
            case townLevel: {
                return townKey;
            }
            case cityLevel: {
                return cityKey;
            }
            default: {
                return teamKey;
            }
        }
    }
}

+ 6 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java

@ -4,6 +4,7 @@ import com.yihu.wlyy.entity.statistics.PopulationBase;
import com.yihu.wlyy.entity.statistics.WlyyQuotaResult;
import com.yihu.wlyy.service.app.statistics.StatisticsAllService;
import com.yihu.wlyy.service.app.statistics.StatisticsService;
import com.yihu.wlyy.service.app.statisticsES.StatisticsESService;
import com.yihu.wlyy.util.Constant;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.ValueComparator;
@ -33,6 +34,8 @@ public class StatisticsController extends BaseController {
    @Autowired
    StatisticsService statisticsService;
    @Autowired
    StatisticsESService statisticsESService;
    @Autowired
    StatisticsAllService statisticsAllService;
    /**
@ -69,7 +72,7 @@ public class StatisticsController extends BaseController {
                                @RequestParam(required = true) String endDate,
                                @RequestParam(required = true) int interval,
                                @RequestParam(required = true) String area,
                                @RequestParam(required = true) int level,
                                @RequestParam(required = true) String level,
                                @RequestParam(required = true) String index,
                                @RequestParam(required = false) String level2_type) {
        String tag = "";
@ -79,7 +82,8 @@ public class StatisticsController extends BaseController {
            if (index != null) {
                for (String idx : indexes) {
                    result.put("index_" + idx, statisticsService.getDateIncrementDetail(startDate, endDate, interval, area, level, idx, level2_type));
//                    result.put("index_" + idx, statisticsESService.getDateIncrementDetail(startDate, endDate, interval, area, level, idx, level2_type));
                    result.put("index_" + idx, statisticsService.getDateIncrementDetail(startDate, endDate, interval, area, Integer.parseInt(level), idx, level2_type));
                }
            }

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/doctor/GcEduArticleController.java

@ -40,7 +40,7 @@ import javax.jms.TextMessage;
import java.util.*;
/**
 * Created by chenweida on 2017/8/30.
 * Created by chenweida on 2017/8/30...
 */
@Controller
@RequestMapping(value = "/wlyygc/doctor/edu/article", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)