Kaynağa Gözat

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

zd_123 7 yıl önce
ebeveyn
işleme
039985b7e9
30 değiştirilmiş dosya ile 906 ekleme ve 381 silme
  1. 17 0
      patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/controller/PrescriptionController.java
  2. 8 0
      patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/dao/FollowupDao.java
  3. 12 2
      patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/entity/Followup.java
  4. 38 0
      patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/prescription/PrescriptionService.java
  5. 1 0
      patient-co-service/wlyy_service/src/main/resources/application.yml
  6. 2 2
      patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/common/thread/UploadChargeThread.java
  7. 5 5
      patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/common/thread/UploadThread.java
  8. 2 0
      patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/dao/SignFamilyRenewLogDao.java
  9. 50 1
      patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/service/ChargeZYService.java
  10. 1 7
      patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/AgeConvert.java
  11. 0 111
      patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/DiseaseConvert.java
  12. 1 2
      patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/PrescriptionAgeConvert.java
  13. 65 0
      patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/PrescriptionDiseaseConvert.java
  14. 65 0
      patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/PrescriptionPatientDiseaseConvert.java
  15. 16 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/job/PrescriptionPayOverdueJob.java
  16. 8 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/followup/FollowUpDao.java
  17. 20 12
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java
  18. 56 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/followup/FollowUpService.java
  19. 24 17
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthIndexService.java
  20. 59 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionInfoService.java
  21. 14 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionService.java
  22. 8 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/reply/DoctorQuickReplyService.java
  23. 188 189
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statisticsES/StatisticsESService.java
  24. 73 22
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ElasticsearchUtil.java
  25. 16 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/followup/DoctorFollowUpController.java
  26. 43 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/prescription/PrescriptionAdjustController.java
  27. 4 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/reply/DoctorQuickReplyController.java
  28. 13 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/team/AdminTeamController.java
  29. 96 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/consult/ConsultController.java
  30. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/ehc/PatientEHCController.java

+ 17 - 0
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/controller/PrescriptionController.java

@ -339,6 +339,23 @@ public class PrescriptionController extends BaseController{
			return Result.error(ex.getMessage());
		}
	}
	
	@RequestMapping(value = "getZyDataStatus",method = RequestMethod.POST)
	@ApiOperation("获取基卫处方的相关数据状态")
	public Result getZyDataStatus(@ApiParam(name="type",value="数据类型:1:挂号数据;2:处方数据;3:结算数据",defaultValue = "")
	                            @RequestParam(value = "type",required = true) String type,
	                            @ApiParam(name="jwid",value="基卫处方ID",defaultValue = "")
	                            @RequestParam(value = "jwid",required = true) String jwid,
	                            @ApiParam(name="hosipital",value="基卫机构编码",defaultValue = "")
	                            @RequestParam(value = "hosipital",required = true) String hosipital){
		try {
			String re = prescriptionService.getZyDataStatus(type,jwid,hosipital);
			return Result.success("查询成功!",re);
		} catch (Exception ex) {
			ex.printStackTrace();
			return Result.error(ex.getMessage());
		}
	}
	/************************************ CA认证 ************************************************************/
	@RequestMapping(value = "RequestRealNameSoftCertAndSign",method = RequestMethod.POST)

+ 8 - 0
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/dao/FollowupDao.java

@ -18,4 +18,12 @@ public interface FollowupDao extends PagingAndSortingRepository<Followup, Long>,
    @Query("select a from Followup a where a.doctorCode = ?1 and a.followupDate between ?2 and ?3 and a.status <> '0'")
    List<Followup> findByDoctor(String doctor, Date begin, Date end, Pageable pageRequest) throws Exception;
    
    /**
     * 根据续方CODE获取随访记录
     * @param prescriptionCode
     * @return
     */
    @Query("select a from Followup a where a.prescriptionCode = ?1 and a.status <> '0'")
    Followup getFollowupByPrescriptionCode(String prescriptionCode);
}

+ 12 - 2
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/entity/Followup.java

@ -50,8 +50,18 @@ public class Followup extends IdEntity {
	private String followupContentPhone;
	//创建时间
	private Date createTime;
	
	//关联的续方CODE
	private String prescriptionCode;
	
	public String getPrescriptionCode() {
		return prescriptionCode;
	}
	
	public void setPrescriptionCode(String prescriptionCode) {
		this.prescriptionCode = prescriptionCode;
	}
	
	public String getFollowupNo() {
		return followupNo;
	}

+ 38 - 0
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/prescription/PrescriptionService.java

@ -79,6 +79,8 @@ public class PrescriptionService extends ZysoftBaseService{
    private AmoutUtils amoutUtils;
    @Autowired
    private ZyIvPhysicDictDao zyIvPhysicDictDao;
    @Autowired
    private FollowupDao followupDao;
    /**
     * 新增续方日志
@ -1130,6 +1132,18 @@ public class PrescriptionService extends ZysoftBaseService{
                log.setUserCode(prescription.getDoctor());
                log.setStatus(PrescriptionLog.PrescriptionLogStatus.pay_refund.getValue());
                prescriptionLogDao.save(log);
                
                try {
                    //续方取消,随访记录也取消,这里如果抛错,则捕获记录日志,不往外抛异常,避免影响长处方的逻辑
                    Followup followup = followupDao.getFollowupByPrescriptionCode(prescription.getCode());
                    if(followup !=null){
                        followup.setStatus("0");
                        followupDao.save(followup);
                    }
                }catch (Exception e){
                    logger.info("取消随访记录失败,:"+e.getMessage());
                }
                
            }
        
        }catch (JSONException ex){
@ -1178,4 +1192,28 @@ public class PrescriptionService extends ZysoftBaseService{
    
        return response;
    }
    
    /**
     * 获取基卫处方的相关数据状态
     * @param type
     * @param jwid
     * @param hosipital
     * @return
     */
    public String getZyDataStatus(String type, String jwid, String hosipital)  throws Exception{
        String[] hospitalMapping = getHospitalMapping(hosipital); //获取机构映射
        String hospital = hospitalMapping[0];
        String licence = hospitalMapping[1];
        Map<String,String> header = new HashMap<>();
        header.put("ORGCODE",hospital);
        header.put("LICENCE",licence);
    
        Map<String,String> params = new HashMap<>();
        params.put("type",type);
        params.put("id",jwid);
    
        String response = postSecond("getDataStatus","获取基卫处方的相关数据状态",params,null,header,false,2,"2");
    
        return response;
    }
}

+ 1 - 0
patient-co-service/wlyy_service/src/main/resources/application.yml

@ -51,6 +51,7 @@ spring:
zysoftApi:
  internet: internet/CallEhrInterface
  base: base/CallEhrInterface
  imm: imm/Action
redisChannel:
    prescription: redisMessage

+ 2 - 2
patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/common/thread/UploadChargeThread.java

@ -29,7 +29,7 @@ public class UploadChargeThread implements Runnable{
                {
                    Boolean running = systemDictService.getUploadChargeRunning();
                    if(running) {
                        System.out.print(DateUtil.dateToStrLong(now) + " 上传缴费...\r\n");
//                        System.out.print(DateUtil.dateToStrLong(now) + " 上传缴费...\r\n");
                        try {
                            service.uploadCharge();
                        }
@ -38,7 +38,7 @@ public class UploadChargeThread implements Runnable{
                            e.printStackTrace();
                        }
                        System.out.print(DateUtil.dateToStrLong(new Date()) + " 上传缴费记录结束。\r\n");
//                        System.out.print(DateUtil.dateToStrLong(new Date()) + " 上传缴费记录结束。\r\n");
                    }
                    Thread.sleep(sleepTime);

+ 5 - 5
patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/common/thread/UploadThread.java

@ -30,8 +30,8 @@ public class UploadThread implements Runnable {
                Date now = new Date();
                //判断非空闲时候
                if(now.getHours()>=morningHours &&  now.getHours() < nightHours)
                {
//                if(now.getHours()>=morningHours &&  now.getHours() < nightHours)---2017.11.15修改为不判断空闲非空闲
//                {
                    //签约上传
                    SignZYService signZYService = (SignZYService) SpringContextHolder.getSpringBean("SignZYService");
                    SystemDictService systemDictService = (SystemDictService) SpringContextHolder.getSpringBean("SystemDictService");
@ -56,9 +56,9 @@ public class UploadThread implements Runnable {
                        Thread.sleep(retryTime);
                        continue;
                    }
                }
                Thread.sleep(1000*sleepTime);
//                }
//
//                Thread.sleep(1000*sleepTime);
            }
            catch (Exception ex)
            {

+ 2 - 0
patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/dao/SignFamilyRenewLogDao.java

@ -23,6 +23,8 @@ public interface SignFamilyRenewLogDao extends PagingAndSortingRepository<SignFa
    SignFamilyRenewLog findByProId(String proId);
    SignFamilyRenewLog findByRenewProId(String renewProId);
    
    SignFamilyRenewLog findBySignCode(String signCode);
    SignFamilyRenewLog findByRenewSignCode(String renewSignCode);

+ 50 - 1
patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/service/ChargeZYService.java

@ -6,11 +6,13 @@ import com.yihu.wlyy.sign.common.util.DateUtil;
import com.yihu.wlyy.sign.common.util.StringUtil;
import com.yihu.wlyy.sign.dao.*;
import com.yihu.wlyy.sign.entity.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -121,16 +123,62 @@ public class ChargeZYService {
                params.put("IDENTITY_CARD_NO", idcard);  //身份证
                params.put("SIGN_MANAGE_YEAR", year);  //签约年度
                params.put("SICK_NAME", patient.getName());  //姓名
                params.put("CHARGE_TIME", DateUtil.dateToStrLong(sign.getExpensesTime()));  //缴费时间
                
                if(sign.getExpensesTime() == null){
                    //如果签约表的支付时间为空,则从支付表获取支付时间
                    Date newdate = DateUtil.formatCharDateYMD(charge.getChargeTime(),"yyyyMMddHHmmss");
                    params.put("CHARGE_TIME", DateUtil.dateToStrLong(newdate));  //缴费时间
                    sign.setExpensesTime(newdate);
                    sign.setExpensesStatus("1");//已支付
                }else{
                    params.put("CHARGE_TIME", DateUtil.dateToStrLong(sign.getExpensesTime()));  //缴费时间
                }
                
               
                params.put("INSUR_PRO_ID", charge.getMiRegisterNo());  //医保签约号
                if("1".equals(sign.getRenewFlag())||"2".equals(sign.getRenewFlag())){
                    proId = signFamilyRenewLogDao.getProId(signCode);
                    if(StringUtils.isBlank(proId) || "0".equals(proId)){
                        
                        if("1".equals(sign.getSignSource())){
                            //如果是在基卫签约则需要更新同步
                            SignFamilyMapping signFamilyMapping = signFamilyMappingDao.findByCode(signCode);
                            signFamilyMapping.setNeedUpdate("1");
                            signFamilyMappingDao.save(signFamilyMapping);
                        }else{
                            //如果是网络签约则需要上传同步
                            SignFamilyRenewLog signFamilyRenewLog = signFamilyRenewLogDao.findBySignCode(signCode);
                            signFamilyRenewLog.setNeedUpload("1");
                            signFamilyRenewLogDao.save(signFamilyRenewLog);
                        }
    
                        //暂停30秒
                        Thread.sleep(30000);
                        return true;
                    }
                }else {
                    proId = signFamilyMappingDao.getProId(signCode);
                    if(StringUtils.isBlank(proId) || "0".equals(proId)){
    
                        SignFamilyMapping signFamilyMapping = signFamilyMappingDao.findByCode(signCode);
                        if("1".equals(sign.getSignSource())){
                            //如果是在基卫签约则需要更新同步
                            signFamilyMapping.setNeedUpdate("1");
                        }else{
                            //如果是网络签约则需要上传同步
                            signFamilyMapping.setNeedUpload("1");
                        }
                        signFamilyMappingDao.save(signFamilyMapping);
    
                        //暂停30秒
                        Thread.sleep(30000);
                        return true;
                    }
                }
                params.put("PRO_ID", proId);  //标志(智业签约主键)
                operator = doctorMappingDao.findByDocotrCodeAndJwDoctorHospital(operator,hm[0]);  //【医生映射】
@ -160,6 +208,7 @@ public class ChargeZYService {
                if(isSuccess)
                {
                    charge.setNeedUpload("0");
                    signFamilyDao.save(sign);
                }else {
                    charge.setNeedUpload("2");
                    content = objectMapper.writeValueAsString(charge);

+ 1 - 7
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/AgeConvert.java

@ -28,15 +28,9 @@ public class AgeConvert implements Convert {
        List<DataModel> result = new ArrayList<>();
        for(DataModel one:oneList) {
            try {
                Object value = DataModel.class.getMethod("get" + temp.getKey()).invoke(one);
                Object value = one.getIdcard();
                Integer age= IdCardUtil.getAgeForIdcard(String.valueOf(value));
                String key = getAgeCode(age);
//                if("63".equals(temp.getQuotaCode())){
//
//                    if(tempMap.containsKey(String.valueOf(value))){
//                        continue;
//                    }
//                }
                tempMap.put(String.valueOf(value),one);
                DataModel.class.getMethod("setSlaveKey" + slaveLevel, String.class).invoke(one, key);
//                result.add(one);

+ 0 - 111
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/DiseaseConvert.java

@ -1,111 +0,0 @@
package com.yihu.wlyy.statistics.etl.convert.wlyy;
import com.yihu.wlyy.entity.dimension.WlyyDimensionQuota;
import com.yihu.wlyy.statistics.etl.convert.Convert;
import com.yihu.wlyy.statistics.etl.convert.wlyy.model.HealthLable;
import com.yihu.wlyy.statistics.etl.convert.wlyy.model.PrescriptionDisease;
import com.yihu.wlyy.statistics.vo.DataModel;
import org.springframework.beans.BeanUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 长处方疾病
 * Created by zhangdan on 2017/10/26.
 */
public class DiseaseConvert implements Convert {
    @Override
    public List<DataModel> convert(JdbcTemplate jdbcTemplate, List<DataModel> oneList, String slaveLevel, WlyyDimensionQuota temp) {
        List<DataModel> returnList = new ArrayList<>();
        //初始化标签Map
//        Map<String, Object> map = initHealthLabesMap(jdbcTemplate, temp);
        Map<String,Object> tempMap = new HashMap<>();
        //把标签Map设置到对应的维度里面
        List<String> keyList = null;
        for(DataModel one:oneList){
            try {
                if("63".equals(temp.getQuotaCode())){
                    DataModel dataModelTemp = new DataModel();
                    BeanUtils.copyProperties(one, dataModelTemp);
                    DataModel.class.getMethod("setSlaveKey" + slaveLevel, String.class).invoke(dataModelTemp, one.getHealthProblem());
                    returnList.add(dataModelTemp);
                }else{
                    keyList = initHealthLabesMap(jdbcTemplate, temp, one);
                    for(String key:keyList){
                        DataModel dataModelTemp = new DataModel();
                        BeanUtils.copyProperties(one, dataModelTemp);
                        DataModel.class.getMethod("setSlaveKey" + slaveLevel, String.class).invoke(dataModelTemp, key);
                        returnList.add(dataModelTemp);
                    }
                }
            }catch (Exception e) {
                e.printStackTrace();
            }
//            List<String> healthProblems = prescriptionDiseaseMap.get(dataModel.getPrescriptionCode());
//            if (healthProblems != null && healthProblems.size() > 0) {
//                healthProblems.stream().forEach(str -> {
//                    try {
//                        DataModel dataModelTemp = new DataModel();
//                        BeanUtils.copyProperties(dataModel, dataModelTemp);
//                        DataModel.class.getMethod("setSlaveKey" + slaveLevel, String.class).invoke(dataModelTemp, str);
//                        returnList.add(dataModelTemp);
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    }
//                });
//            }
        }
        return returnList;
    }
    private List<String> initHealthLabesMap(JdbcTemplate jdbcTemplate, WlyyDimensionQuota temp,DataModel dataModel) {
//        //得到长处方的疾病标签(只要高血压 糖尿病)
//        String sql = "SELECT " +
//                "  health_problem ," +
//                "  prescription_code " +
//                "FROM " +
//                "  wlyy_prescription_diagnosis " +
//                "WHERE " +
//                "  health_problem = 'HP0047' " +
//                "OR health_problem = 'HP0093' ";
//        List<PrescriptionDisease> prescriptionDiseases = jdbcTemplate.query(sql, new BeanPropertyRowMapper(PrescriptionDisease.class));
//        prescriptionDiseases.stream().forEach(one -> {
//            List<String> labels = prescriptionDiseaseMap.get(one.getPrescriptionCode());
//            if (labels == null) {
//                labels = new ArrayList<String>();
//            }
//            labels.add(one.getHealthProblem());
//            prescriptionDiseaseMap.put(one.getPrescriptionCode(), labels);
//        });
        List<String> key = new ArrayList<>();
        String sql = "SELECT " +
                "  health_problem AS healthProblem ," +
                "  prescription_code AS prescriptionCode " +
                "  FROM " +
                "  wlyy_prescription_diagnosis " +
                "  WHERE " +
                "  prescription_code = '"+dataModel.getPrescriptionCode() +"'";
        List<Map<String, Object>>  diagnosisList =jdbcTemplate.queryForList(sql);
//        List<Map<String, Object>> dictList = jdbcTemplate.queryForList(temp.getDictSql());
        for (Map<String, Object> map:diagnosisList){
//            String diagnosis = map.get("healthProblem")+"";
//            for(Map<String, Object> dict:dictList){
//                if(diagnosis.equals(dict.get("code"))){
//                    key.add()
//                }
//            }
            key.add(map.get("healthProblem").toString());
        }
        return key;
    }
}

+ 1 - 2
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/PrescriptionAgeConvert.java

@ -27,11 +27,10 @@ public class PrescriptionAgeConvert implements Convert {
        List<DataModel> result = new ArrayList<>();
        for(DataModel one:oneList) {
            try {
                Object value = DataModel.class.getMethod("get" + temp.getKey()).invoke(one);
                Object value = one.getIdcard();
                Integer age= IdCardUtil.getAgeForIdcard(String.valueOf(value));
                String key = getAgeCode(age);
                if("63".equals(temp.getQuotaCode())){
                    if(tempMap.containsKey(String.valueOf(value))){
                        continue;
                    }

+ 65 - 0
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/PrescriptionDiseaseConvert.java

@ -0,0 +1,65 @@
package com.yihu.wlyy.statistics.etl.convert.wlyy;
import com.yihu.wlyy.entity.dimension.WlyyDimensionQuota;
import com.yihu.wlyy.statistics.etl.convert.Convert;
import com.yihu.wlyy.statistics.etl.convert.wlyy.model.HealthLable;
import com.yihu.wlyy.statistics.etl.convert.wlyy.model.PrescriptionDisease;
import com.yihu.wlyy.statistics.vo.DataModel;
import org.springframework.beans.BeanUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 长处方疾病
 * Created by zhangdan on 2017/10/26.
 */
public class PrescriptionDiseaseConvert implements Convert {
    @Override
    public List<DataModel> convert(JdbcTemplate jdbcTemplate, List<DataModel> oneList, String slaveLevel, WlyyDimensionQuota temp) {
        List<DataModel> returnList = new ArrayList<>();
        //初始化标签Map
        //把标签Map设置到对应的维度里面
        List<String> keyList = null;
        Map<String,List<String>>  returnMap=initHealthLabesMap(jdbcTemplate, temp);
        for (DataModel one : oneList) {
            try {
                keyList = returnMap.get(one.getPrescriptionCode());
                for (String key : keyList) {
                    DataModel dataModelTemp = new DataModel();
                    BeanUtils.copyProperties(one, dataModelTemp);
                    DataModel.class.getMethod("setSlaveKey" + slaveLevel, String.class).invoke(dataModelTemp, key);
                    returnList.add(dataModelTemp);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return returnList;
    }
    private  Map<String,List<String>> initHealthLabesMap(JdbcTemplate jdbcTemplate, WlyyDimensionQuota temp) {
//        //得到长处方的疾病标签(只要高血压 糖尿病)
       Map<String,List<String>>  returnMap = new HashMap<>();
        String sql = "SELECT " +
                "  health_problem AS healthProblem ," +
                "  prescription_code AS prescriptionCode " +
                "  FROM " +
                "  wlyy_prescription_diagnosis " ;
        List<Map<String, Object>> diagnosisList = jdbcTemplate.queryForList(sql);
        for (Map<String, Object> map : diagnosisList) {
            String key= (String) map.get("prescriptionCode");
            List<String> healthProblemList=returnMap.get(key);
            if(healthProblemList==null){
                healthProblemList=new ArrayList<>();
            }
            healthProblemList.add((String) map.get("healthProblem"));
            returnMap.put(key,healthProblemList);
        }
        return returnMap;
    }
}

+ 65 - 0
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/PrescriptionPatientDiseaseConvert.java

@ -0,0 +1,65 @@
package com.yihu.wlyy.statistics.etl.convert.wlyy;
import com.yihu.wlyy.entity.dimension.WlyyDimensionQuota;
import com.yihu.wlyy.statistics.etl.convert.Convert;
import com.yihu.wlyy.statistics.vo.DataModel;
import org.springframework.beans.BeanUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 长处方疾病
 * Created by zhangdan on 2017/10/26.
 */
public class PrescriptionPatientDiseaseConvert implements Convert {
    @Override
    public List<DataModel> convert(JdbcTemplate jdbcTemplate, List<DataModel> oneList, String slaveLevel, WlyyDimensionQuota temp) {
        List<DataModel> returnList = new ArrayList<>();
        //初始化标签Map
        //把标签Map设置到对应的维度里面
        List<String> keyList = null;
        Map<String,List<String>>  returnMap=initHealthLabesMap(jdbcTemplate, temp);
        for (DataModel one : oneList) {
            try {
                keyList = returnMap.get(one.getPatient());
                for (String key : keyList) {
                    DataModel dataModelTemp = new DataModel();
                    BeanUtils.copyProperties(one, dataModelTemp);
                    DataModel.class.getMethod("setSlaveKey" + slaveLevel, String.class).invoke(dataModelTemp, key);
                    returnList.add(dataModelTemp);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return returnList;
    }
    private  Map<String,List<String>> initHealthLabesMap(JdbcTemplate jdbcTemplate, WlyyDimensionQuota temp) {
//        //得到长处方的疾病标签(只要高血压 糖尿病)
        Map<String,List<String>>  returnMap = new HashMap<>();
        String sql = "SELECT distinct " +
                "  d.health_problem AS healthProblem, " +
                "  p.patient AS patient " +
                "FROM " +
                "  wlyy_prescription p, " +
                "  wlyy_prescription_diagnosis d " +
                "WHERE " +
                "p.`code`=d.prescription_code" ;
        List<Map<String, Object>> diagnosisList = jdbcTemplate.queryForList(sql);
        for (Map<String, Object> map : diagnosisList) {
            String key= (String) map.get("patient");
            List<String> healthProblemList=returnMap.get(key);
            if(healthProblemList==null){
                healthProblemList=new ArrayList<>();
            }
            healthProblemList.add((String) map.get("healthProblem"));
            returnMap.put(key,healthProblemList);
        }
        return returnMap;
    }
}

+ 16 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/job/PrescriptionPayOverdueJob.java

@ -2,8 +2,10 @@ package com.yihu.wlyy.job;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.followup.Followup;
import com.yihu.wlyy.entity.patient.prescription.Prescription;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionLog;
import com.yihu.wlyy.repository.followup.FollowUpDao;
import com.yihu.wlyy.repository.prescription.PrescriptionDao;
import com.yihu.wlyy.util.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;
@ -36,6 +38,8 @@ public class PrescriptionPayOverdueJob implements Job {
    private String jwUrl;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private FollowUpDao followUpDao;
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Override
@ -117,6 +121,18 @@ public class PrescriptionPayOverdueJob implements Job {
                }
                prescription.setZyCancelState(1);
                prescriptionDao.save(prescription);
    
                try {
                    //续方取消,随访记录也取消,这里如果出错则直接捕获,记录日志,不往外抛,避免影响长处方逻辑
                    Followup followup = followUpDao.getFollowupByPrescriptionCode(prescriptionCode);
                    if(followup !=null){
                        followup.setStatus("0");
                        followUpDao.save(followup);
                    }
                }catch (Exception e){
                    logger.info("续方取消,随访记录同步取消失败:"+e.getMessage());
                }
                
            }else{
                throw new Exception("基卫接口(挂号作废)请求失败,无数据返回!");
            }

+ 8 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/followup/FollowUpDao.java

@ -35,4 +35,12 @@ public interface FollowUpDao extends PagingAndSortingRepository<Followup, Long>,
    
    @Query(value = "select a.* from wlyy_followup a INNER JOIN  wlyy_followup_mapping b on b.followup_id = a.id AND b.need_upload=?1",nativeQuery = true)
	List<Followup> findByFollowMappingNeedUpload(Integer need_upload);
    
    /**
     * 根据续方CODE获取随访记录
     * @param prescriptionCode
     * @return
     */
    @Query("select a from Followup a where a.prescriptionCode = ?1 and a.status <> '0'")
    Followup getFollowupByPrescriptionCode(String prescriptionCode);
}

+ 20 - 12
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java

@ -240,6 +240,7 @@ public class ConsultTeamService extends ConsultService {
     */
    public boolean exist(String patient, Integer type) throws Exception {
        DoctorTeamMember member = null;
        String memberCode=null;
        // 咨询三师
        if (type == 1) {
            // 查询三师签约信息
@ -256,26 +257,33 @@ public class ConsultTeamService extends ConsultService {
            if (member == null) {
                member = doctorTeamDoctor.findDoctorSanshi2ByTeam(doctorTeam.getCode(), 2);
            }
            memberCode= member.getCode();
        } else if (type == 2) {
            // 咨询家庭医生
            SignFamily sf = signFamilyDao.findByjiatingPatient(patient);
            if (sf == null) {
                throw new Exception("不存在家庭签约");
            }
            if (StringUtils.isEmpty(sf.getDoctorHealth())){
                memberCode = sf.getDoctor();
            }else {
                memberCode = sf.getDoctorHealth();
            }
            // 设置健康管理师,家庭医生咨询默认给健康管理师处理
            //查找病人所在的团队
            DoctorTeam doctorTeam = doctorTeamDao.findByParientCode(patient);
            //得到团队的健康管理师
            member = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 3);
            if (member == null) {
                member = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 2);
            }
//            DoctorTeam doctorTeam = doctorTeamDao.findByParientCode(patient);
//            //得到团队的健康管理师
//            member = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 3);
//
//            if (member == null) {
//                member = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 2);
//            }
        }
        if (member == null) {
            throw new Exception("找不到签约服务团队医生");
        }
        int count = consultTeamDao.countByPatient(patient, member.getMemberCode());
        int count = consultTeamDao.countByPatient(patient, memberCode);
        return count > 0;
    }
@ -1143,15 +1151,15 @@ public class ConsultTeamService extends ConsultService {
            followup.setIdcard(patientObj.getIdcard());
            
            if(3 == type){
                followup.setFollowupType("1,2");
                followup.setFollowupClass("1,2");
            }else{
                followup.setFollowupType(String.valueOf(type));
                followup.setFollowupClass(String.valueOf(type));
            }
            
            if(2 == doctor.getLevel()){//全科
                followup.setFollowupClass("22");
                followup.setFollowupType("22");
            }else if(3 == doctor.getLevel()){//健管
                followup.setFollowupClass("10");
                followup.setFollowupType("10");
            }
            followup.setDataFrom("2");//数据来源 1基卫 2APP
            followup.setStatus("2");     //状态 0取消 1已完成 2未开始 3进行中

+ 56 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/followup/FollowUpService.java

@ -1047,7 +1047,23 @@ public class FollowUpService extends BaseService {
            followupContentESDOList = result.getSourceAsObjectList(FollowupContentESDO.class);
            if (!followupContentESDOList.isEmpty()) {
                for (FollowupContentESDO followupContentESDO : followupContentESDOList) {
                    resultList.add(followupContentESDO.getFollowup_project());
                   
                    if("2".equals(followupContentESDO.getFollowup_project())){
                        //判断血压必填
                        if(StringUtils.isNotBlank(followupContentESDO.getBP_D()) && StringUtils.isNotBlank(followupContentESDO.getBP_U())){
                            resultList.add(followupContentESDO.getFollowup_project());
                        }
                    }else if("3".equals(followupContentESDO.getFollowup_project())){
                        //判断血糖必填
                        if(StringUtils.isNotBlank(followupContentESDO.getBS_FPG()) ||
                                StringUtils.isNotBlank(followupContentESDO.getNO_BS_FPG())||
                                    StringUtils.isNotBlank(followupContentESDO.getRANDOM_BLOOD_SUGAR())){
                            resultList.add(followupContentESDO.getFollowup_project());
                        }
                    }else{
                        resultList.add(followupContentESDO.getFollowup_project());
                    }
                    
                }
            }
@ -1146,4 +1162,43 @@ public class FollowUpService extends BaseService {
        return count;
    }
    
    /**
     * 检查随访记录是否可完成
     * @param followupid
     * @return
     */
    public boolean checkfollowupcompleted(String followupid)  throws Exception {
        boolean result = true;
    
        List<FollowupContentESDO> eslist = this.esfindFollowUpContestsByFollowupId(followupid);
    
        if (!eslist.isEmpty()) {
            for (FollowupContentESDO followupContentESDO : eslist) {
            
                if("2".equals(followupContentESDO.getFollowup_project())){
                    //判断血压必填
                    if(StringUtils.isBlank(followupContentESDO.getBP_D()) || StringUtils.isBlank(followupContentESDO.getBP_U())){
                        return false;
                    }
                }else if("3".equals(followupContentESDO.getFollowup_project())){
                    //判断血糖必填
                    if(StringUtils.isBlank(followupContentESDO.getBS_FPG()) &&
                            StringUtils.isBlank(followupContentESDO.getNO_BS_FPG()) &&
                            StringUtils.isBlank(followupContentESDO.getRANDOM_BLOOD_SUGAR())){
                        return false;
                    }
                }else if("5".equals(followupContentESDO.getFollowup_project())){
                    //判断评价
                    if(StringUtils.isBlank(followupContentESDO.getDIA_FOLLOWUP_TYPE_CODE()) &&
                            StringUtils.isBlank(followupContentESDO.getHYP_FOLLOWUP_TYPE_CODE())){
                        return false;
                    }
                }else{}
            
            }
        }
        
        return result;
    }
}

+ 24 - 17
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthIndexService.java

@ -483,28 +483,35 @@ public class PatientHealthIndexService extends BaseService {
            json.put("msg", content);
            json.put("data", "");
            array.put(json);
        }
        // 批量保存消息
        messageDao.save(messages);
        for (String receiver : receivers) {
            if (StringUtils.isEmpty(receiver)) {
                continue;
            }
            //            新增发送医生助手模板消息 v1.4.0 by wujunjie
            if (StringUtils.isNotEmpty(doctorOpenID)) {
                List<Message> messagesList = messageDao.findUnreadHealthIndex(patientCode, receiver);
                String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
                List<NameValuePair> params = new ArrayList<>();
                params.add(new BasicNameValuePair("type", "3"));
                params.add(new BasicNameValuePair("openId", doctorOpenID));
                params.add(new BasicNameValuePair("url", targetUrl));
                params.add(new BasicNameValuePair("first", doctorName + "医生,您的签约居民" + patientName +
                        "有" + messagesList.size() + "条未读的体征异常消息"));
                params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
                SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
                String date = format.format(new Date());
                String keywords = date + "," + patientName;
                params.add(new BasicNameValuePair("keywords", keywords));
                httpClientUtil.post(url, params, "UTF-8");
                if (messagesList != null && messagesList.size()>0){
                    String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
                    List<NameValuePair> params = new ArrayList<>();
                    params.add(new BasicNameValuePair("type", "3"));
                    params.add(new BasicNameValuePair("openId", doctorOpenID));
                    params.add(new BasicNameValuePair("url", targetUrl));
                    params.add(new BasicNameValuePair("first", doctorName + "医生,您的签约居民" + patientName +
                            "有" + messagesList.size() + "条未读的体征异常消息"));
                    params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
                    SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
                    String date = format.format(new Date());
                    String keywords = date + "," + patientName;
                    params.add(new BasicNameValuePair("keywords", keywords));
                    httpClientUtil.post(url, params, "UTF-8");
                }
            }
        }
        // 批量保存消息
        messageDao.save(messages);
        // 推送消息给医生
        pushMsgTask.put(array);
    }

+ 59 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionInfoService.java

@ -4,6 +4,7 @@ import com.yihu.wlyy.adapter.PresModeAdapter;
import com.yihu.wlyy.entity.dict.SystemDict;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.followup.Followup;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.patient.prescription.*;
@ -19,20 +20,25 @@ import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.system.Icd10DictServcie;
import com.yihu.wlyy.service.third.jw.JwPrescriptionService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.util.HttpUtil;
import com.yihu.wlyy.util.ImUtill;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.*;
/**
@ -99,6 +105,12 @@ public class PrescriptionInfoService extends BaseService {
    private PrescriptionAdjustReasonDao prescriptionAdjustReasonDao;
    @Autowired
    private FollowUpDao followUpDao;
	@Value("${doctorAssistant.api}")
	private String doctorAssistant;
	@Value("${doctorAssistant.target_url}")
	private String targetUrl;
	@Autowired
	private HttpClientUtil httpClientUtil;
    private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
@ -495,6 +507,8 @@ public class PrescriptionInfoService extends BaseService {
        Patient p = patientDao.findByCode(patient);
        String rs = jwPrescriptionService.getRecipe(code, p.getSsc());
        com.alibaba.fastjson.JSONObject r = presModeAdapter.modelToSinglePrescription(rs);
    
        Followup followup = followUpDao.getFollowupByPrescriptionCode(code);
        String rState = presCheckStateObj(code);
        if ("1".equals(rState)) {
            r.put("reviewedState", 1);
@ -503,6 +517,7 @@ public class PrescriptionInfoService extends BaseService {
            r.put("reviewedState", 0);
            r.put("prescriptionCode", rState);
        }
        r.put("followup",followup);
        return r;
    }
@ -908,6 +923,32 @@ public class PrescriptionInfoService extends BaseService {
                //审核不通过模板消息
                sendRMess(p.getCode(), 0);
	
	            //取消长处方关联的随访记录
	            canclePrescriptionFollowup(code);
	
	            try {
		            //            新增发送医生助手模板消息 v1.4.0 by wujunjie
		            Doctor doctor = doctorDao.findByCode(p.getDoctor());
		            String doctorOpenID = doctor.getOpenid();
		            if (StringUtils.isNotEmpty(doctorOpenID)) {
			            String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
			            List<NameValuePair> params = new ArrayList<>();
			            params.add(new BasicNameValuePair("type", "1"));
			            params.add(new BasicNameValuePair("openId", doctorOpenID));
			            params.add(new BasicNameValuePair("url", targetUrl));
			            params.add(new BasicNameValuePair("first", doctor.getName() + "医生您好。您有一个您有1个续方申请处方开立失败。"));
			            params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
			            SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
			            String date = format.format(new Date());
			            String keywords = doctor.getName() +","+ p.getPatientName() +"," + date;
			            params.add(new BasicNameValuePair("keywords", keywords));
			
			            httpClientUtil.post(url, params, "UTF-8");
		            }
	            } catch (Exception e) {
		            e.printStackTrace();
	            }
            }
            prescriptionReviewedDao.save(reviewed);
            prescriptionDao.save(p);
@ -1850,4 +1891,22 @@ public class PrescriptionInfoService extends BaseService {
        }
        return jsonObject;
    }
	
	
	/**
	 * 根据长处方CODE,取消关联的随访记录
	 * @param prescriptionCode
	 */
	private void canclePrescriptionFollowup(String prescriptionCode){
		try {
			//续方取消,随访记录也取消,这里如果出错则直接捕获,记录日志,不往外抛,避免影响长处方逻辑
			Followup followup = followUpDao.getFollowupByPrescriptionCode(prescriptionCode);
			if(followup !=null){
				followup.setStatus("0");
				followUpDao.save(followup);
			}
		}catch (Exception e){
			logger.info("续方取消,随访记录同步取消失败:"+e.getMessage());
		}
	}
}

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

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeam;
import com.yihu.wlyy.entity.followup.Followup;
import com.yihu.wlyy.entity.message.Message;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.prescription.Prescription;
@ -11,6 +12,7 @@ import com.yihu.wlyy.entity.patient.prescription.PrescriptionDiagnosis;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionExpressage;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionLog;
import com.yihu.wlyy.repository.doctor.DoctorTeamDao;
import com.yihu.wlyy.repository.followup.FollowUpDao;
import com.yihu.wlyy.repository.message.MessageDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.prescription.PrescriptionDao;
@ -73,9 +75,8 @@ public class PrescriptionService extends BaseService {
    private PrescriptionInfoDao prescriptionInfoDao;
    @Autowired
    private JpaTransactionManager transactionManager;
    @Autowired
    private com.yihu.wlyy.util.CommonUtil commonUtil;
    private FollowUpDao followUpDao;
    /**
@ -431,6 +432,17 @@ public class PrescriptionService extends BaseService {
                        statusObj.put("status",200);
                        statusObj.put("code",9);
                        statusObj.put("message","基卫处方为作废,已修改本地数据库该处方为线下取消");
    
                        try {
                            //续方取消,随访记录也取消,这里如果出错则直接捕获,记录日志,不往外抛,避免影响长处方逻辑
                            Followup followup = followUpDao.getFollowupByPrescriptionCode(prescriptionCode);
                            if(followup !=null){
                                followup.setStatus("0");
                                followUpDao.save(followup);
                            }
                        }catch (Exception e){
                            logger.info("续方取消,随访记录同步取消失败:"+e.getMessage());
                        }
                    }else{
                        statusObj.put("status",200);
                        statusObj.put("code",data.getString("RECIPE_STATUS_CODE"));

+ 8 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/reply/DoctorQuickReplyService.java

@ -164,16 +164,22 @@ public class DoctorQuickReplyService extends BaseService {
     * 排序回复
     *
     * @param id
     * @param type
     * @return
     */
    public int sortReplyList(String id) {
    public int sortReplyList(String id,String type) {
        String[] ids = id.split(",");
        for (int i = 0; i < ids.length; i++) {
            DoctorQuickReply reply = quickReplyDao.findOne(Long.valueOf(ids[i]));
            if (reply == null) {
                return -1;
            }
            reply.setSort(ids.length - i);
            if("1".equals(type)){
                reply.setSort(i+1);
            }else{
                reply.setSort(ids.length - i);
            }
            
        }
        return 1;
    }

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

@ -93,69 +93,6 @@ public class StatisticsESService {
    }
//    /**
//     * 查询某一天父level下的子level 例如 查询市下面的团队,或者区下面的团队
//     *
//     * @param index      指标code
//     * @param area           机构code或者团队code或者town code或者city code
//     * @param timeLevel      1增量 2到达量
//     * @param level      父arealevel
//     * @param lowLevel 子arealevel
//     * @return
//     */
//    public List<SaveModel> findOneDateQuotaByChllevel(String startDate,
//                                                      String endDate,
//                                                      String index,
//                                                      String area,
//                                                      String timeLevel,
//                                                      String level,
//                                                      String lowLevel) {
//
//        //时间格式转换  yyyy-MM-dd转成 2017-07-17T00:00:00+0800
//        startDate = changeDate(startDate);
//        endDate = changeDate(endDate);
//
//        StringBuffer sql = new StringBuffer();
//        StringBuffer groupBy = new StringBuffer();
//        //根据 childAreaLevel   group by
//        if (SaveModel.teamLevel.equals(level)) {
//            sql.append("select team,teamName,result1,result2 from wlyy_quota_test where  ");
//            groupBy.append(" group by team,teamName");
//        } else if (SaveModel.OrgLevel.equals(level)) {
//            sql.append("select hospital,hospitalName,sum(result1) result1,sum(result2) result2 from wlyy_quota_test where  ");
//            groupBy.append(" group by hospital,hospitalName");
//        } else if (SaveModel.townLevel.equals(level)) {
//            sql.append("select town,townName,sum(result1) result1,sum(result2) result2 from wlyy_quota_test where ");
//            groupBy.append(" group by town,townName");
//        } else if (SaveModel.cityLevel.equals(level)) {
//            sql.append("select city,cityName,sum(result1) result1,sum(result2) result2 from wlyy_quota_test where  ");
//            groupBy.append(" group by city,cityName");
//        }
//
//        sql.append("  quotaCode='" + index + "'  ");
//        sql.append(" and timeLevel='" + timeLevel + "'  ");
//        sql.append(" and areaLevel='5'");
//        if(StringUtils.isNotEmpty(startDate)){
//            sql.append(" and quotaDate>='" + startDate + "'");
//        }
//        if(StringUtils.isNotEmpty(endDate)){
//            sql.append(" and quotaDate<='" + endDate + "'");
//        }
//        //查询code
//        if (SaveModel.teamLevel.equals(lowLevel)) {
//            sql.append(" and team='" + area + "'");
//        } else if (SaveModel.OrgLevel.equals(lowLevel)) {
//            sql.append(" and hospital='" + area + "'");
//        } else if (SaveModel.townLevel.equals(lowLevel)) {
//            sql.append(" and town='" + area + "'");
//        } else if (SaveModel.cityLevel.equals(lowLevel)) {
//            sql.append(" and city='" + area + "'");
//        }
//        sql.append(groupBy);
//        return elasticsearchUtil.excute(sql.toString(),SaveModel.class,"","");
//    }
    /**
     * 获取时间范围内按间隔统计指标增量
     *
@ -689,7 +626,7 @@ public class StatisticsESService {
     * @return
     */
    public JSONObject getGroupInfo(String endDate, String lowCode, String area, int level, String year) throws Exception {
        List<SaveModel> list = elasticsearchUtil.findDateQuotaLevel1(endDate, endDate, area, level, "17", "2",  lowCode, null, null);
        List<SaveModel> list = elasticsearchUtil.findDateQuotaLevel1(endDate, endDate, area, level, "17", "2", lowCode, null, null);
        long total = 0;
        if (list.size() > 0) {
            total = list.get(0).getResult2().longValue();
@ -844,7 +781,7 @@ public class StatisticsESService {
        }
        json.put("taskNum", taskNum);
        if (interval == 1){
        if (interval == 1) {
            JSONArray jsonArray = dateTotalStatistics(startDate, endDate, area, level, index, lowCode);
            json.put("data", jsonArray);
            return json;
@ -862,6 +799,7 @@ public class StatisticsESService {
    /**
     * 总体分析 折线图 绑定微信 按日
     *
     * @param startDate
     * @param endDate
     * @param area
@ -876,10 +814,10 @@ public class StatisticsESService {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        List<SaveModel> saveModels = new ArrayList<>();
        //startDate = DateUtil.getNextDay(startDate,-1);
        if (StringUtils.isNotBlank(lowCode)){
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel1(startDate,endDate,area,level,index,SaveModel.timeLevel_DDL,SaveModel.interval_day,lowCode);
        }else{
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate,endDate,area,level,index,SaveModel.timeLevel_DDL,SaveModel.interval_day);
        if (StringUtils.isNotBlank(lowCode)) {
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel1(startDate, endDate, area, level, index, SaveModel.timeLevel_DDL, SaveModel.interval_day, lowCode);
        } else {
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate, endDate, area, level, index, SaveModel.timeLevel_DDL, SaveModel.interval_day);
        }
        List<JSONObject> result = new ArrayList<>();
        if (saveModels != null) {
@ -893,19 +831,19 @@ public class StatisticsESService {
                result.add(json);
            }
        // 排序
        result.sort(new Comparator<JSONObject>() {
            @Override
            public int compare(JSONObject o1, JSONObject o2) {
                if (o1.getString("range").compareTo(o2.getString("range")) > 0) {
                    return 1;
                } else if (o1.getString("range").compareTo(o2.getString("range")) < 0) {
                    return -1;
                } else {
                    return 0;
            // 排序
            result.sort(new Comparator<JSONObject>() {
                @Override
                public int compare(JSONObject o1, JSONObject o2) {
                    if (o1.getString("range").compareTo(o2.getString("range")) > 0) {
                        return 1;
                    } else if (o1.getString("range").compareTo(o2.getString("range")) < 0) {
                        return -1;
                    } else {
                        return 0;
                    }
                }
            }
        });
            });
            return new JSONArray(result);
        } else {
@ -915,6 +853,7 @@ public class StatisticsESService {
    /**
     * 按周统计 折线图
     *
     * @param startDate
     * @param endDate
     * @param area
@ -1012,12 +951,11 @@ public class StatisticsESService {
        }
        List<SaveModel> saveModels = new ArrayList<>();
        if (StringUtils.isNotBlank(lowCode)){
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel1(startDate,endDate,area,level,index,SaveModel.timeLevel_DDL,SaveModel.interval_day,lowCode);
        }else{
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate,endDate,area,level,index,SaveModel.timeLevel_DDL,SaveModel.interval_day);
        if (StringUtils.isNotBlank(lowCode)) {
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel1(startDate, endDate, area, level, index, SaveModel.timeLevel_DDL, SaveModel.interval_day, lowCode);
        } else {
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate, endDate, area, level, index, SaveModel.timeLevel_DDL, SaveModel.interval_day);
        }
        if (saveModels != null) {
@ -1056,6 +994,7 @@ public class StatisticsESService {
    /**
     * 按月统计 折线图
     *
     * @param startDate
     * @param endDate
     * @param area
@ -1131,10 +1070,10 @@ public class StatisticsESService {
            startDate = df.format(preDate.getTime());
        }
        List<SaveModel> saveModels = new ArrayList<>();
        if (StringUtils.isNotBlank(lowCode)){
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel1(startDate,endDate,area,level,index,SaveModel.timeLevel_DDL,SaveModel.interval_day,lowCode);
        }else{
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate,endDate,area,level,index,SaveModel.timeLevel_DDL,SaveModel.interval_day);
        if (StringUtils.isNotBlank(lowCode)) {
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel1(startDate, endDate, area, level, index, SaveModel.timeLevel_DDL, SaveModel.interval_day, lowCode);
        } else {
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate, endDate, area, level, index, SaveModel.timeLevel_DDL, SaveModel.interval_day);
        }
        if (saveModels != null) {
@ -2642,7 +2581,7 @@ public class StatisticsESService {
            if (StringUtils.isBlank(lowCode)) {
                yearsList = elasticsearchUtil.findDateQuotaLevel0(lastDate, lastDate, area, level, "1", "2", "", low_level);
            } else {
                yearsList = elasticsearchUtil.findDateQuotaLevel1(lastDate, lastDate, area, level, "17", "2",lowCode, "", low_level);
                yearsList = elasticsearchUtil.findDateQuotaLevel1(lastDate, lastDate, area, level, "17", "2", lowCode, "", low_level);
            }
            Map<String, SaveModel> resultMap = new HashMap<>();
@ -3290,8 +3229,16 @@ public class StatisticsESService {
    public List<Map<String, Object>> getPrescriptionAgeLowLevel(String level, String lowlevel, String area, String disease) throws Exception {
        String index63 = "63";  //统计长处方总数疾病和状态维度(去重相同患者)
        String index68 = "68";  //统计长处方年龄人数(按照患者去重)
        String quotaDate = elasticsearchUtil.getQuotaTime();
        List<SaveModel> list = elasticsearchUtil.findListDateQuotaLevel1(quotaDate, area, Integer.parseInt(level), "63", "2", lowlevel, disease);
        List<SaveModel> list = null;
        if (org.springframework.util.StringUtils.isEmpty(disease)) {
            list = elasticsearchUtil.findListDateQuotaLevel1NoSlaveKey1(quotaDate, area, Integer.parseInt(level), index68, SaveModel.timeLevel_DDL, lowlevel);
        } else {
            list = elasticsearchUtil.findListDateQuotaLevel2NoSlaveKey1(quotaDate, area, Integer.parseInt(level), index63, SaveModel.timeLevel_DDL, lowlevel, disease);
        }
        Map<String, Object> map = null;
        List<Map<String, Object>> rs = new ArrayList<>();
        if (list.size() > 0) {
@ -3313,7 +3260,6 @@ public class StatisticsESService {
                map.put("val", one.getResult2().longValue());
            }
        } else {
            //统计数据为空时,自建结果集
            List<Town> townList = null;
            List<Hospital> hospitalList = null;
@ -3350,6 +3296,20 @@ public class StatisticsESService {
            }
        }
        rs.add(map);
        Collections.sort(rs, new Comparator<Map<String, Object>>() {
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Integer map1value = Integer.valueOf(String.valueOf(o1.get("val")));
                Integer map2value = Integer.valueOf(String.valueOf(o2.get("val")));
                if (map1value - map2value > 0) {
                    return -1;
                } else if (map1value - map2value < 0) {
                    return 1;
                } else {
                    return 0;
                }
            }
        });
        return rs;
    }
@ -3423,7 +3383,7 @@ public class StatisticsESService {
        //因为一个处方可能有多个疾病状态 所以分开2个指标
        String index58 = "58";//统计长处方总数疾病和状态维度
        String index64 = "64";//统计长处方总数状态维度
        Map<String,Map<String, Object>> rs = new LinkedHashMap<>();
        Map<String, Map<String, Object>> rs = new LinkedHashMap<>();
        Calendar dd = Calendar.getInstance();//定义日期实例
        Date endDate = new Date();
@ -3436,7 +3396,7 @@ public class StatisticsESService {
            mc.put("month", date);
            mc.put("count", 0);
            dd.add(Calendar.MONTH, -1);
            rs.put(date,mc);
            rs.put(date, mc);
        }
        String startTime = DateUtil.dateToStr(dd.getTime(), "YYYY-MM-dd HH:mm:ss");
        String endTime = DateUtil.dateToStr(new Date(), "YYYY-MM-dd HH:mm:ss");
@ -3458,14 +3418,14 @@ public class StatisticsESService {
            }
        }
        //把数据设置到初始化的Map里面去
        for(SaveModel saveModel:resultList){
        for (SaveModel saveModel : resultList) {
            String monthKeyEs = "";
            if (saveModel.getQuotaDate() != null) {
                monthKeyEs = DateUtil.changeQuotaDate(saveModel.getQuotaDate());
            }
            if (StringUtils.isNotBlank(monthKeyEs) && rs.containsKey(monthKeyEs)) {
                Map<String, Object> oneMc = rs.get(monthKeyEs);
                oneMc.put("count",saveModel.getResult2());
                oneMc.put("count", saveModel.getResult2());
            }
        }
@ -3573,6 +3533,20 @@ public class StatisticsESService {
            rs.add(map);
        }
        Collections.sort(rs, new Comparator<Map<String, Object>>() {
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Integer map1value = Integer.valueOf(String.valueOf(o1.get("val")));
                Integer map2value = Integer.valueOf(String.valueOf(o2.get("val")));
                if (map1value - map2value > 0) {
                    return -1;
                } else if (map1value - map2value < 0) {
                    return 1;
                } else {
                    return 0;
                }
            }
        });
        return rs;
    }
@ -3601,17 +3575,24 @@ public class StatisticsESService {
     * @return
     */
    public Map<String, Object> getPrescriptionAgeTotal(String level, String area, String disease) throws Exception {
        //统计长处方总数疾病和状态维度(去重相同患者)
        String index = "63";
        String index63 = "63";  //统计长处方总数疾病和状态维度(去重相同患者)
        String index68 = "68";  //统计长处方年龄人数(按照患者去重)
        Map<String, Object> map = new HashMap<>();
        String quotaDate = elasticsearchUtil.getQuotaTime();
        //统计年龄分布
        List<SaveModel> list = elasticsearchUtil.findOneDateQuotaLevel2(quotaDate, area, Integer.parseInt(level), index, "2", disease);
        //总数量
        SaveModel saveModel = elasticsearchUtil.findOneDateQuotaLevel0(quotaDate, area, Integer.parseInt(level), index, "2");
        List<SaveModel> list = null;
        SaveModel saveModel = null;
        if (org.springframework.util.StringUtils.isEmpty(disease)) {
            list = elasticsearchUtil.findListDateQuotaLevel1(quotaDate, area, Integer.parseInt(level), index68, SaveModel.timeLevel_DDL, null, null);
            //总数量
            saveModel = elasticsearchUtil.findOneDateQuotaLevel1NoSlaveKey1(quotaDate, area, Integer.parseInt(level), index68, SaveModel.timeLevel_DDL);
        } else {
            list = elasticsearchUtil.findListDateQuotaLevel2(quotaDate, area, Integer.parseInt(level), index63, SaveModel.timeLevel_DDL, null, null, disease);
            //总数量
            saveModel = elasticsearchUtil.findOneDateQuotaLevel2NoSlaveKey1(quotaDate, area, Integer.parseInt(level), index63, SaveModel.timeLevel_DDL, disease);
        }
        Double num = saveModel.getResult2();
        Map<String, Object> map = new HashMap<>();
        DecimalFormat decimalFormat = new DecimalFormat("0.00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
        Double ageRate = list.get(0).getResult2() / num;
        map.put("0ageRate", decimalFormat.format(ageRate));
@ -3638,7 +3619,9 @@ public class StatisticsESService {
    }
    public Map<String, Object> getPrescriptionDispatchingTotal(int level, String area, String disease) throws Exception {
        String index = "62";
        String index62 = "62";//统计长处方配送方式和疾病维度
        String index67 = "67";//统计长处方配送方式维度
        SaveModel selt = null;//自取集合
        SaveModel delivery = null;//物流配送集合
        SaveModel healthDoctor = null;//健管师配送集合
@ -3646,18 +3629,18 @@ public class StatisticsESService {
        //type二级指标,disease一级指标
        if (StringUtils.isNotBlank(disease)) {
            //自取
            selt = elasticsearchUtil.findOneDateQuotaLevel2(quotaTime, area, level, index, "2", disease, "1");
            selt = elasticsearchUtil.findOneDateQuotaLevel2(quotaTime, area, level, index62, SaveModel.timeLevel_DDL, disease, "1");
            //物流配送
            delivery = elasticsearchUtil.findOneDateQuotaLevel2(quotaTime, area, level, index, "2", disease, "2");
            delivery = elasticsearchUtil.findOneDateQuotaLevel2(quotaTime, area, level, index62, SaveModel.timeLevel_DDL, disease, "2");
            //健管师配送
            healthDoctor = elasticsearchUtil.findOneDateQuotaLevel2(quotaTime, area, level, index, "2", disease, "3");
            healthDoctor = elasticsearchUtil.findOneDateQuotaLevel2(quotaTime, area, level, index62, SaveModel.timeLevel_DDL, disease, "3");
        } else {
            //自取
            selt = elasticsearchUtil.findOneDateQuotaLevel2NoSlaveKey1(quotaTime, area, level, index, SaveModel.timeLevel_DDL, "1");
            selt = elasticsearchUtil.findOneDateQuotaLevel1(quotaTime, area, level, index67, SaveModel.timeLevel_DDL, "1");
            //物流配送
            delivery = elasticsearchUtil.findOneDateQuotaLevel2NoSlaveKey1(quotaTime, area, level, index, SaveModel.timeLevel_DDL, "2");
            delivery = elasticsearchUtil.findOneDateQuotaLevel1(quotaTime, area, level, index67, SaveModel.timeLevel_DDL, "2");
            //健管师配送
            healthDoctor = elasticsearchUtil.findOneDateQuotaLevel2NoSlaveKey1(quotaTime, area, level, index, SaveModel.timeLevel_DDL, "3");
            healthDoctor = elasticsearchUtil.findOneDateQuotaLevel1(quotaTime, area, level, index67, SaveModel.timeLevel_DDL, "3");
        }
@ -3693,6 +3676,8 @@ public class StatisticsESService {
     * @return
     */
    public List<Map<String, Object>> getPrescriptionDispatchingHistogram(int level, String area, String disease, String type) throws Exception {
        String index62 = "62";//统计长处方配送方式和疾病维度
        String index67 = "67";//统计长处方配送方式维度
        List<Map<String, Object>> rs = new ArrayList<>();
        Calendar dd = Calendar.getInstance();//定义日期实例
@ -3714,9 +3699,9 @@ public class StatisticsESService {
        List<SaveModel> resultList = new ArrayList<>();
        if (StringUtils.isNotBlank(disease)) {
            resultList = elasticsearchUtil.findLineChartDateQuotaLevel2(startTime, endTime, area, level, "62", "2", "3", disease, type);
            resultList = elasticsearchUtil.findLineChartDateQuotaLevel2(startTime, endTime, area, level, index62, SaveModel.timeLevel_DDL, SaveModel.interval_month, disease, type);
        } else {
            resultList = elasticsearchUtil.findLineChartDateQuotaLevel2NoSlaveKey1(startTime, endTime, area, level, "62", "2", "3", type);
            resultList = elasticsearchUtil.findLineChartDateQuotaLevel1(startTime, endTime, area, level, index67, SaveModel.timeLevel_DDL, SaveModel.interval_month, type);
        }
        for (Map<String, Object> m : rs) {
@ -3745,17 +3730,19 @@ public class StatisticsESService {
     */
    public List<Map<String, Object>> getPrescriptionDispatchingLowLevel(int level, String lowlevel, String area, String disease, String type) throws Exception {
        String index = "62";
        String index62 = "62";//统计长处方配送方式和疾病维度
        String index67 = "67";//统计长处方配送方式维度
        String quotaDate = elasticsearchUtil.getQuotaTime();
        List<SaveModel> saveModels = new ArrayList<>();
        List<Map<String, Object>> rs = new ArrayList<>();
        if (StringUtils.isNotBlank(disease)) {
            //类型 1.自取,2.快递配送,3.健管师配送
            saveModels = elasticsearchUtil.findListDateQuotaLevel2(quotaDate, area, level, index, SaveModel.timeLevel_DDL, lowlevel, disease, type);
            saveModels = elasticsearchUtil.findListDateQuotaLevel2(quotaDate, area, level, index62, SaveModel.timeLevel_DDL, lowlevel, disease, type);
        } else {
            saveModels = elasticsearchUtil.findListDateQuotaLevel2NoSlaveKey1(quotaDate, area, level, index, SaveModel.timeLevel_DDL, lowlevel, type);
            saveModels = elasticsearchUtil.findListDateQuotaLevel1(quotaDate, area, level, index67, SaveModel.timeLevel_DDL, lowlevel, type);
        }
        if ("5".equals(lowlevel)) {
        if (SaveModel.teamLevel.equals(lowlevel)) {
            translateTeamLeaderName2(saveModels);
        }
        Map<String, Object> map = null;
@ -3776,12 +3763,10 @@ public class StatisticsESService {
                    map.put("name", one.getTeamName());
                }
                map.put("val", one.getResult2().longValue());
                rs.add(map);
            }
        } else {
            //统计数据为空时,自建结果集
//            List<Map<String, Object>> resultList = new ArrayList<>();
//            resultList = getLowLevelMapKey(level, lowlevel, area);
            List<Town> townList = null;
            List<Hospital> hospitalList = null;
            List<AdminTeam> adminTeams = null;
@ -3797,25 +3782,30 @@ public class StatisticsESService {
            }
            if (SaveModel.townLevel.equals(lowlevel)) {
                for (Town one : townList) {
                    map = new HashMap<>();
                    map.put("code", one.getCode());
                    map.put("name", one.getName());
                    map.put("val", 0);
                    rs.add(map);
                }
            } else if (SaveModel.OrgLevel.equals(lowlevel)) {
                for (Hospital one : hospitalList) {
                    map = new HashMap<>();
                    map.put("code", one.getCode());
                    map.put("name", one.getName());
                    map.put("val", 0);
                    rs.add(map);
                }
            } else if (SaveModel.teamLevel.equals(lowlevel)) {
                for (AdminTeam one : adminTeams) {
                    map = new HashMap<>();
                    map.put("code", one.getLeaderCode());
                    map.put("name", one.getName());
                    map.put("val", 0);
                    rs.add(map);
                }
            }
        }
        rs.add(map);
        return rs;
    }
@ -3831,14 +3821,20 @@ public class StatisticsESService {
     * @return
     */
    public List<Map<String, Object>> getPrescriptionCostLowLevel(String level, String lowlevel, String area, String disease, String type) throws Exception {
        String index61 = "61";//统计长处方费用总数疾病维度
        String index66 = "66";//费用的指标code
        String quotaDate = elasticsearchUtil.getQuotaTime();
        //1.总量
        List<SaveModel> list = elasticsearchUtil.findListDateQuotaLevel1(quotaDate, area, Integer.parseInt(level), "61", "2", lowlevel, disease);
        List<SaveModel> costList = null;
        //获取费用
        if (org.springframework.util.StringUtils.isEmpty(disease)) {
            costList = elasticsearchUtil.findListDateQuotaLevel0(quotaDate, area, Integer.parseInt(level), index66, SaveModel.timeLevel_DDL, lowlevel);
        } else {
            costList = elasticsearchUtil.findListDateQuotaLevel1(quotaDate, area, Integer.parseInt(level), index61, SaveModel.timeLevel_DDL, lowlevel, disease);
        }
        Map<String, Object> map = null;
        List<Map<String, Object>> countList = new ArrayList<>();
        if ("1".equals(type)) {
            for (SaveModel one : list) {
            for (SaveModel one : costList) {
                map = new HashMap<>();
                if (SaveModel.townLevel.equals(lowlevel)) {
                    map.put("code", one.getTown());
@ -3855,33 +3851,50 @@ public class StatisticsESService {
            }
        } else {
            //2.平均值
            //去重获取总人数,计算人均费用
            String sql = "";
            for (SaveModel one : list) {
                sql = "  select count(DISTINCT(s.patient)) as num from wlyy_prescription_pay p left join wlyy_prescription s on p.prescription_code = s. CODE  ";
                sql += " and  p.trace_time <= " + one.getQuotaDate();
                Map<String, Object> count = jdbcTemplate.queryForMap(sql);
            //费用list转map
            for (SaveModel one : costList) {
                String avg = "0.0";
                map = new HashMap<>();
                if (SaveModel.townLevel.equals(lowlevel)) {
                    map.put("code", one.getTown());
                    map.put("name", one.getTownName());
                    if (one != null&&one.getResult2()>0) {
                        avg = decimalFormat.format(one.getResult1() / (one.getResult2()*100));
                    }
                    map.put("val", avg);
                } else if (SaveModel.OrgLevel.equals(lowlevel)) {
                    map.put("code", one.getHospital());
                    map.put("name", one.getHospitalName());
                    if (one != null&&one.getResult2()>0) {
                        avg = decimalFormat.format(one.getResult1() / (one.getResult2()*100));
                    }
                    map.put("val", avg);
                } else if (SaveModel.teamLevel.equals(lowlevel)) {
                    map.put("code", one.getTeam());
                    map.put("name", one.getTeamName());
                    if (one != null&&one.getResult2()>0) {
                        avg = decimalFormat.format(one.getResult1() / (one.getResult2()*100));
                    }
                    map.put("val", avg);
                }
                Long num = (Long) count.get("num");
                String avg = "0.0";
                if (num != 0) {
                    avg = decimalFormat.format(one.getResult1() / num);
                }
                map.put("val", avg);
                countList.add(map);
            }
        }
        Collections.sort(countList, new Comparator<Map<String, Object>>() {
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Double map1value = Double.valueOf(String.valueOf(o1.get("val")));
                Double map2value = Double.valueOf(String.valueOf(o2.get("val")));
                if (map1value - map2value > 0) {
                    return -1;
                } else if (map1value - map2value < 0) {
                    return 1;
                } else {
                    return 0;
                }
            }
        });
        return countList;
    }
@ -3896,80 +3909,66 @@ public class StatisticsESService {
     * @param type      1.按日,2.按周,3.按月
     */
    public List<Map<String, Object>> getPrescriptionCostAvgLine(String level, String area, String disease, String startDate, String endDate, String type) throws Exception {
        String index61 = "61";//统计长处方费用总数疾病维度
        String index66 = "66";//费用的指标code
        List<SaveModel> costList = null;
        startDate = elasticsearchUtil.changeTime(startDate += " 00:00:00");
        endDate = elasticsearchUtil.changeTime(endDate += " 23:59:59");
        List<SaveModel> list = elasticsearchUtil.findLineChartDateQuotaLevel1(startDate, endDate, area, Integer.parseInt(level), "61", "2", type, disease);
        String sql = "";
        Map<String, Object> map = null;
        List<Map<String, Object>> countList = new ArrayList<>();
        for (SaveModel one : list) {
            sql = "  select count(DISTINCT(s.patient)) as num from wlyy_prescription_pay p left join wlyy_prescription s on p.prescription_code = s. CODE  ";
            sql += " and  p.trace_time <= '" + dateFormat3.format(one.getQuotaDate())+"'";
            if ( SaveModel.cityLevel.equals(level)) {
                sql += " and LEFT(s.hospital,4) ='" + area.substring(0,4) + "' ";
            }else if (SaveModel.townLevel.equals(level) ) {
                sql += " and LEFT(s.hospital,6) ='" + area + "' ";
            } else if (SaveModel.OrgLevel.equals(level)) {
                sql += " and s.hospital ='" + area + "' ";
            } else if (SaveModel.teamLevel.equals(level)) {
                sql += " and s.admin_team_id ='" + area + "'";
        //获取费用
        if (org.springframework.util.StringUtils.isEmpty(disease)) {
            costList = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate, endDate, area, Integer.parseInt(level), index66, SaveModel.timeLevel_ZL, type);
        } else {
            costList = elasticsearchUtil.findLineChartDateQuotaLevel1(startDate, endDate, area, Integer.parseInt(level), index61, SaveModel.timeLevel_ZL, type, disease);
        }
        List<Map<String, Object>> countList = new ArrayList<>(); //map date avg
        for (SaveModel one : costList) {
            Map<String, Object> map = new HashMap<>();
            //获取key
            String key = null;
            if (SaveModel.interval_day.equals(type)) {
                key = dateFormat.format(one.getQuotaDate());
            } else if (SaveModel.interval_week.equals(type)) {
                key = dateFormat.format(one.getQuotaDate());
            } else {
                key = DateUtil.getMonth(dateFormat.format(one.getQuotaDate()));
            }
            Map<String, Object> count = jdbcTemplate.queryForMap(sql);
            Long num = (Long) count.get("num");
            String avg = "0.0";
            if (num != 0) {
                avg = decimalFormat.format(one.getResult1() / num);
            if (one.getResult2()!=0) {
                avg = decimalFormat.format(one.getResult1() / (one.getResult2()*100));
            }
            map = new HashMap<>();
            map.put("avg", avg);
            if ("1".equals(type)) {
                map.put("date", dateFormat.format(one.getQuotaDate()));
            map.put("val", avg);
            map.put("date", key);
            } else if ("2".equals(type)) {
                map.put("date", DateUtil.getWeekOfMonth(dateFormat.format(one.getQuotaDate())));
            } else {
                map.put("date", DateUtil.getMonth(dateFormat.format(one.getQuotaDate())));
            }
            countList.add(map);
        }
        return countList;
    }
    public Map<String, Object> getPrescriptionCost(String level, String area, String disease) throws Exception {
        SaveModel saveModel = null;
        String index = "61";//费用的指标code
        SaveModel costSaveModel = null;
        String index61 = "61";//统计长处方费用总数疾病维度
        String index66 = "66";//费用的指标code
        String quotaDate = elasticsearchUtil.getQuotaTime();
        if (StringUtils.isNotEmpty(disease)) {
            saveModel = elasticsearchUtil.findOneDateQuotaLevel1(quotaDate, area, Integer.parseInt(level), index, "2", disease);
            costSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(quotaDate, area, Integer.parseInt(level), index61, "2", disease);
        } else {
            saveModel = elasticsearchUtil.findOneDateQuotaLevel1NoSlaveKey1(quotaDate, area, Integer.parseInt(level), index, "2");
        }
        //获取人数
        String sql = "  select count(DISTINCT(s.patient)) as num from wlyy_prescription_pay p left join wlyy_prescription s on p.prescription_code = s. CODE  ";
        sql += " and  p.create_time <= '" + quotaDate+"'";
        if ( SaveModel.cityLevel.equals(level)) {
            sql += " and LEFT(s.hospital,4) ='" + area.substring(0,4) + "' ";
        }else if (SaveModel.townLevel.equals(level) ) {
            sql += " and LEFT(s.hospital,6) ='" + area + "' ";
        } else if (SaveModel.OrgLevel.equals(level)) {
            sql += " and s.hospital ='" + area + "' ";
        } else if (SaveModel.teamLevel.equals(level)) {
            sql += " and s.admin_team_id ='" + area + "' ";
            costSaveModel = elasticsearchUtil.findOneDateQuotaLevel0(quotaDate, area, Integer.parseInt(level), index66, "2");
        }
        Map<String, Object> count = jdbcTemplate.queryForMap(sql);
        Long num = (Long) count.get("num");
        Map<String, Object> rs = new HashedMap();
        BigDecimal s = BigDecimal.valueOf(saveModel.getResult1());
        BigDecimal s = BigDecimal.valueOf(costSaveModel.getResult1());
        BigDecimal a = null;
        if (num == 0) {
        if (costSaveModel.getResult2() == 0.0D) {
            a = BigDecimal.valueOf(0.0);
        } else {
            a = BigDecimal.valueOf(saveModel.getResult1().longValue() / num);
            a = BigDecimal.valueOf(costSaveModel.getResult1().longValue() / costSaveModel.getResult2().longValue());
        }
        rs.put("sum", s.divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP));//费用总计  单位是0 所以除以100四舍五入
        rs.put("avg", a.divide((new BigDecimal(100))).setScale(2, BigDecimal.ROUND_HALF_UP));//人均费用  单位是0 所以除以100四舍五入
        rs.put("sum", s.divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP));//费用总计  单位是分 所以除以100四舍五入
        rs.put("avg", a.divide((new BigDecimal(100))).setScale(2, BigDecimal.ROUND_HALF_UP));//人均费用  单位是分 所以除以100四舍五入
        return rs;
    }

+ 73 - 22
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ElasticsearchUtil.java

@ -39,6 +39,8 @@ public class ElasticsearchUtil {
    private Logger logger = LoggerFactory.getLogger(ElasticsearchUtil.class);
    private final String commonParams="xmijk_quota";
    @Autowired
    private ElasticFactory elasticFactory;
    @Autowired
@ -366,25 +368,25 @@ public class ElasticsearchUtil {
        if (SaveModel.teamLevel.equals(low_level)) {
            sql.append("select team,teamName,slaveKey1,slaveKey1Name,sum(result1) result1, sum(result2) result2 from " + esIndex + " where ");
            groupBy.append("  group by team,teamName");
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey1)) {
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey1)||commonParams.equals(slaveKey1)) {
                groupBy.append(",slaveKey1,slaveKey1Name");
            }
        } else if (SaveModel.OrgLevel.equals(low_level)) {
            sql.append("select hospital,hospitalName,slaveKey1,slaveKey1Name,sum(result1) result1,sum(result2) result2 from " + esIndex + " where ");
            groupBy.append("  group by hospital,hospitalName");
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey1)) {
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey1)||commonParams.equals(slaveKey1)) {
                groupBy.append(",slaveKey1,slaveKey1Name");
            }
        } else if (SaveModel.townLevel.equals(low_level)) {
            sql.append("select town,townName,slaveKey1,slaveKey1Name,sum(result1) result1,sum(result2) result2 from " + esIndex + " where ");
            groupBy.append("  group by town,townName" );
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey1)) {
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey1)||commonParams.equals(slaveKey1)) {
                groupBy.append(",slaveKey1,slaveKey1Name");
            }
        } else if (SaveModel.cityLevel.equals(low_level)) {
            sql.append("select city,cityName,slaveKey1,slaveKey1Name,sum(result1) result1,sum(result2) result2 from " + esIndex + " where ");
            groupBy.append("  group by city,cityName");
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey1)) {
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey1)||commonParams.equals(slaveKey1)) {
                groupBy.append(",slaveKey1,slaveKey1Name");
            }
        }
@ -411,7 +413,7 @@ public class ElasticsearchUtil {
        if (StringUtils.isNotEmpty(endDate)) {
            sql.append(" and quotaDate<='" + endDate + "'");
        }
        if (StringUtils.isNotEmpty(slaveKey1)) {
        if (StringUtils.isNotEmpty(slaveKey1)&&!commonParams.equals(slaveKey1)) {
            sql.append(" and slaveKey1='" + slaveKey1 + "'  ");
        }
@ -473,37 +475,37 @@ public class ElasticsearchUtil {
        if (SaveModel.teamLevel.equals(low_level)) {
            sql.append("select team,teamName,slaveKey1,slaveKey1Name,slaveKey2,slaveKey2Name,result1,result2 from " + esIndex + " where ");
            groupBy.append("  group by team,teamName");
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey1)) {
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey1)||commonParams.equals(slaveKey1)) {
                groupBy.append(",slaveKey1,slaveKey1Name");
            }
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey2)) {
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey2)||commonParams.equals(slaveKey2)) {
                groupBy.append(",slaveKey2,slaveKey2Name");
            }
        } else if (SaveModel.OrgLevel.equals(low_level)) {
            sql.append("select hospital,hospitalName,sum(result1) result1,sum(result2) result2 from " + esIndex + " where ");
            groupBy.append("  group by hospital,hospitalName");
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey1)) {
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey1)||commonParams.equals(slaveKey1)) {
                groupBy.append(",slaveKey1,slaveKey1Name");
            }
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey2)) {
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey2)||commonParams.equals(slaveKey2)) {
                groupBy.append(",slaveKey2,slaveKey2Name");
            }
        } else if (SaveModel.townLevel.equals(low_level)) {
            sql.append("select town,townName,slaveKey1,slaveKey1Name,slaveKey2,slaveKey2Name,sum(result1) result1,sum(result2) result2 from " + esIndex + " where ");
            groupBy.append("  group by town,townName");
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey1)) {
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey1)||commonParams.equals(slaveKey1)) {
                groupBy.append(",slaveKey1,slaveKey1Name");
            }
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey2)) {
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey2)||commonParams.equals(slaveKey2)) {
                groupBy.append(",slaveKey2,slaveKey2Name");
            }
        } else if (SaveModel.cityLevel.equals(low_level)) {
            sql.append("select city,cityName,slaveKey1,slaveKey1Name,slaveKey2,slaveKey2Name,sum(result1) result1,sum(result2) result2 from " + esIndex + " where ");
            groupBy.append("  group by city,cityName");
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey1)) {
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey1)||commonParams.equals(slaveKey1)) {
                groupBy.append(",slaveKey1,slaveKey1Name");
            }
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey2)) {
            if (!org.springframework.util.StringUtils.isEmpty(slaveKey2)||commonParams.equals(slaveKey2)) {
                groupBy.append(",slaveKey2,slaveKey2Name");
            }
        }
@ -529,10 +531,10 @@ public class ElasticsearchUtil {
        if (StringUtils.isNotEmpty(endDate)) {
            sql.append(" and quotaDate<='" + endDate + "'");
        }
        if (StringUtils.isNotBlank(slaveKey1)) {
        if (StringUtils.isNotBlank(slaveKey1)&&(!commonParams.equals(slaveKey1))) {
            sql.append(" and slaveKey1='" + slaveKey1 + "'");
        }
        if (StringUtils.isNotBlank(slaveKey2)) {
        if (StringUtils.isNotBlank(slaveKey2)&&(!commonParams.equals(slaveKey2))) {
            sql.append(" and slaveKey2='" + slaveKey2 + "'");
        }
@ -547,7 +549,8 @@ public class ElasticsearchUtil {
                groupBy.append(" ,date_histogram(field='quotaDate','interval'='1d','time_zone'='+08:00') ");
            }
        }
        sql.append(groupBy);
        String orderBy=" order by result1 desc " ;
        sql.append(groupBy).append(orderBy);
        return excute(sql.toString(), SaveModel.class, "", "");
    }
@ -724,6 +727,9 @@ public class ElasticsearchUtil {
     * @return
     */
    public SaveModel findOneDateQuotaLevel1(String quotaDate, String area, int level, String index, String timelevel, String slaveKey1) throws Exception {
        if(org.springframework.util.StringUtils.isEmpty(slaveKey1)){
            slaveKey1=commonParams;
        }
        List list = findDateQuotaLevel1(quotaDate, quotaDate, area, level, index, timelevel,  slaveKey1, null, null);
        return (SaveModel) list.get(0);
    }
@ -774,6 +780,9 @@ public class ElasticsearchUtil {
     * @return
     */
    public SaveModel findOneDateQuotaLevel1(String startDate, String endDate, String area, int level, String index, String timelevel, String slaveKey1) throws Exception {
        if(org.springframework.util.StringUtils.isEmpty(slaveKey1)){
            slaveKey1=commonParams;
        }
        List list = findDateQuotaLevel1(startDate, endDate, area, level, index, timelevel,  slaveKey1, null, null);
        return (SaveModel) list.get(0);
    }
@ -790,7 +799,7 @@ public class ElasticsearchUtil {
     * @return
     */
    public List<SaveModel> findOneDateQuotaLevel1(String quotaDate, String area, int level, String index, String timelevel) throws Exception {
        List list = findDateQuotaLevel1(quotaDate, quotaDate, area, level, index, timelevel, null, null, null);
        List list = findDateQuotaLevel1(quotaDate, quotaDate, area, level, index, timelevel, commonParams, null, null);
        return list;
    }
@ -805,7 +814,7 @@ public class ElasticsearchUtil {
     * @return
     */
    public List<SaveModel> findOneDateQuotaLevel1(String startDate, String endDate, String area, int level, String index, String timelevel) throws Exception {
        List list = findDateQuotaLevel1(startDate, endDate, area, level, index, timelevel,  null, null, null);
        List list = findDateQuotaLevel1(startDate, endDate, area, level, index, timelevel,  commonParams, null, null);
        return list;
    }
@ -823,6 +832,12 @@ public class ElasticsearchUtil {
     * @return
     */
    public SaveModel findOneDateQuotaLevel2(String quotaDate, String area, int level, String index, String timelevel, String slaveKey1, String slaveKey2) throws Exception {
        if(org.springframework.util.StringUtils.isEmpty(slaveKey1)){
            slaveKey1=commonParams;
        }
        if(org.springframework.util.StringUtils.isEmpty(slaveKey2)){
            slaveKey2=commonParams;
        }
        List list = findDateQuotaLevel2(quotaDate, quotaDate, area, level, index, timelevel, slaveKey1, slaveKey2, null, null);
        return (SaveModel) list.get(0);
    }
@ -856,7 +871,7 @@ public class ElasticsearchUtil {
     * @param slaveKey1 二级维度的key
     * @return
     */
    public SaveModel findOneDateQuotaLevel2NoSlave2(String quotaDate, String area, int level, String index, String timelevel, String slaveKey1) throws Exception {
    public SaveModel findOneDateQuotaLevel2NoSlaveKey2(String quotaDate, String area, int level, String index, String timelevel, String slaveKey1) throws Exception {
        List list = findDateQuotaLevel2(quotaDate, quotaDate, area, level, index, timelevel, slaveKey1, null, null, null);
        return (SaveModel) list.get(0);
    }
@ -876,6 +891,12 @@ public class ElasticsearchUtil {
     * @return
     */
    public SaveModel findOneDateQuotaLevel2(String startDate, String endDate, String area, int level, String index, String timelevel, String slaveKey1, String slaveKey2) throws Exception {
        if(org.springframework.util.StringUtils.isEmpty(slaveKey1)){
            slaveKey1=commonParams;
        }
        if(org.springframework.util.StringUtils.isEmpty(slaveKey2)){
            slaveKey2=commonParams;
        }
        List list = findDateQuotaLevel2(startDate, endDate, area, level, index, timelevel, slaveKey1, slaveKey2, null, null);
        return (SaveModel) list.get(0);
    }
@ -893,7 +914,10 @@ public class ElasticsearchUtil {
     * @return
     */
    public List<SaveModel> findOneDateQuotaLevel2(String quotaDate, String area, int level, String index, String timelevel, String slaveKey1) throws Exception {
        List list = findDateQuotaLevel2(quotaDate, quotaDate, area, level, index, timelevel, slaveKey1, null, null, null);
        if(org.springframework.util.StringUtils.isEmpty(slaveKey1)){
            slaveKey1=commonParams;
        }
        List list = findDateQuotaLevel2(quotaDate, quotaDate, area, level, index, timelevel, slaveKey1, commonParams, null, null);
        return list;
    }
@ -933,6 +957,9 @@ public class ElasticsearchUtil {
     * @return
     */
    public List<SaveModel> findLineChartDateQuotaLevel1(String startDate, String endDate, String area, int level, String index, String timelevel, String interval, String slaveKey1) throws Exception {
        if(org.springframework.util.StringUtils.isEmpty(slaveKey1)){
            slaveKey1=commonParams;
        }
        List list = findDateQuotaLevel1(startDate, endDate, area, level, index, timelevel,  slaveKey1, interval, null);
        return list;
    }
@ -971,6 +998,12 @@ public class ElasticsearchUtil {
     * @return
     */
    public List<SaveModel> findLineChartDateQuotaLevel2(String startDate, String endDate, String area, int level, String index, String timelevel, String interval, String slaveKey1, String slaveKey2) throws Exception {
        if(org.springframework.util.StringUtils.isEmpty(slaveKey1)){
            slaveKey1=commonParams;
        }
        if(org.springframework.util.StringUtils.isEmpty(slaveKey2)){
            slaveKey2=commonParams;
        }
        List list = findDateQuotaLevel2(startDate, endDate, area, level, index, timelevel, slaveKey1, slaveKey2, interval, null);
        return list;
    }
@ -1088,6 +1121,9 @@ public class ElasticsearchUtil {
     * @return
     */
    public List<SaveModel> findListDateQuotaLevel1(String quotaDate, String area, int level, String index, String timelevel, String lowLevel, String slaveKey1) throws Exception {
        if(org.springframework.util.StringUtils.isEmpty(slaveKey1)){
            slaveKey1=commonParams;
        }
        List list = findDateQuotaLevel1(quotaDate, quotaDate, area, level, index, timelevel, slaveKey1, null, lowLevel);
        return list;
    }
@ -1125,6 +1161,9 @@ public class ElasticsearchUtil {
     * @return
     */
    public List<SaveModel> findListDateQuotaLevel1(String startDate, String endDate, String area, int level, String index, String timelevel, String lowLevel, String slaveKey1) throws Exception {
        if(org.springframework.util.StringUtils.isEmpty(slaveKey1)){
            slaveKey1=commonParams;
        }
        List list = findDateQuotaLevel1(startDate, endDate, area, level, index, timelevel, slaveKey1, null, lowLevel);
        return list;
    }
@ -1145,17 +1184,23 @@ public class ElasticsearchUtil {
     * @return
     */
    public List<SaveModel> findListDateQuotaLevel2(String quotaDate, String area, int level, String index, String timelevel, String lowLevel, String slaveKey1, String slaveKey2) throws Exception {
        if(org.springframework.util.StringUtils.isEmpty(slaveKey1)){
            slaveKey1=commonParams;
        }
        if(org.springframework.util.StringUtils.isEmpty(slaveKey2)){
            slaveKey2=commonParams;
        }
        List list = findDateQuotaLevel2(quotaDate, quotaDate, area, level, index, timelevel, slaveKey1, slaveKey2, null, lowLevel);
        return list;
    }
    public List<SaveModel> findListDateQuotaLevel2NoSlaveKey1(String quotaDate, String area, int level, String index, String timelevel, String lowLevel, String slaveKey2) throws Exception {
        List list = findDateQuotaLevel2(quotaDate, quotaDate, area, level, index, timelevel, null, slaveKey2, null, lowLevel);
        List list = findDateQuotaLevel2(quotaDate, quotaDate, area, level, index, timelevel, null, slaveKey2, commonParams, lowLevel);
        return list;
    }
    public List<SaveModel> findListDateQuotaLevel2NoSlaveKey2(String quotaDate, String area, int level, String index, String timelevel, String lowLevel, String slaveKey1) throws Exception {
        List list = findDateQuotaLevel2(quotaDate, quotaDate, area, level, index, timelevel, slaveKey1, null, null, lowLevel);
        List list = findDateQuotaLevel2(quotaDate, quotaDate, area, level, index, timelevel, slaveKey1, commonParams, null, lowLevel);
        return list;
    }
@ -1181,6 +1226,12 @@ public class ElasticsearchUtil {
     * @return
     */
    public List<SaveModel> findListDateQuotaLevel2(String startDate, String endDate, String area, int level, String index, String timelevel, String lowLevel, String slaveKey1, String slaveKey2) throws Exception {
        if(org.springframework.util.StringUtils.isEmpty(slaveKey1)){
            slaveKey1=commonParams;
        }
        if(org.springframework.util.StringUtils.isEmpty(slaveKey2)){
            slaveKey2=commonParams;
        }
        List list = findDateQuotaLevel2(startDate, endDate, area, level, index, timelevel, slaveKey1, slaveKey2, null, lowLevel);
        return list;
    }

+ 16 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/followup/DoctorFollowUpController.java

@ -419,5 +419,21 @@ public class DoctorFollowUpController extends BaseController {
            return error(-1, "操作失败!");
        }
    }
    
    @RequestMapping(value = "/checkfollowupcompleted", method = RequestMethod.GET)
    @ApiOperation("检查续方关联的随访记录是否对应的详情记录")
    public String checkfollowupcompleted(
            @ApiParam(name = "followupid", value = "随访ID", defaultValue = "")
            @RequestParam(value = "followupid", required = true) String followupid){
        try {
            boolean completed = followUpService.checkfollowupcompleted(followupid);
            return write(200, "操作成功!","data",completed);
        }catch (Exception e){
            //日志文件中记录异常信息
            error(e);
            //返回接口异常信息处理结果
            return error(-1, "操作失败!");
        }
    }
}

+ 43 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/prescription/PrescriptionAdjustController.java

@ -2,17 +2,29 @@ package com.yihu.wlyy.web.doctor.prescription;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.aop.ObserverRequired;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.patient.prescription.Prescription;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.prescription.PrescriptionDao;
import com.yihu.wlyy.service.app.prescription.PrescriptionAdjustService;
import com.yihu.wlyy.service.third.jw.JwPrescriptionService;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * Created by yeshijie on 2017/8/17.
 */
@ -27,6 +39,14 @@ public class PrescriptionAdjustController extends BaseController {
    private PrescriptionDao prescriptionDao;
    @Autowired
    private PrescriptionAdjustService prescriptionAdjustService;
    @Autowired
    private DoctorDao doctorDao;
    @Value("${doctorAssistant.api}")
    private String doctorAssistant;
    @Value("${doctorAssistant.target_url}")
    private String targetUrl;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @RequestMapping(value = "adjustPrescription",method = RequestMethod.POST)
    @ObserverRequired
@ -44,6 +64,29 @@ public class PrescriptionAdjustController extends BaseController {
            if(json.getInteger("status")==-1){
                return error(-1,json.getString("msg"));
            }
            try {
                //            新增发送医生助手模板消息 v1.4.0 by wujunjie
                Prescription prescription = prescriptionDao.findByCode(code);
                Doctor doctor = doctorDao.findByCode(prescription.getDoctor());
                String doctorOpenID = doctor.getOpenid();
                if (StringUtils.isNotEmpty(doctorOpenID)) {
                    String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
                    List<NameValuePair> params = new ArrayList<>();
                    params.add(new BasicNameValuePair("type", "9"));
                    params.add(new BasicNameValuePair("openId", doctorOpenID));
                    params.add(new BasicNameValuePair("url", targetUrl));
                    params.add(new BasicNameValuePair("first", doctor.getName() + "医生您好。您有1个续方申请已在线下调整完成,请尽快进行CA认证."));
                    params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
                    SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
                    String date = format.format(new Date());
                    String keywords = "续方审核CA认证" +"," + date;
                    params.add(new BasicNameValuePair("keywords", keywords));
                    httpClientUtil.post(url, params, "UTF-8");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return write(200,"请求调整成功");
        }catch (Exception e){
            error(e);

+ 4 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/reply/DoctorQuickReplyController.java

@ -131,13 +131,15 @@ public class DoctorQuickReplyController extends BaseController {
    @RequestMapping(value = "/sortList", method = RequestMethod.POST)
    @ApiOperation(value = "快捷回复排序")
    public String sortReplyList(@RequestParam @ApiParam(value = "快捷回复ID")String id) {
    public String sortReplyList(@RequestParam @ApiParam(value = "快捷回复ID")String id,
                                @ApiParam(name = "type", value = "快捷回复类型(1为续方咨询)", defaultValue = "0")
                                @RequestParam(value = "type", required = false, defaultValue = "0") String type) {
        try {
            if (StringUtils.isEmpty(id)) {
                return error(-1, "请输入排序后的回复ID");
            }
            int result = quickReplyService.sortReplyList(id);
            int result = quickReplyService.sortReplyList(id,type);
            if (result == 1) {
                return write(200, "排序成功");

+ 13 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/team/AdminTeamController.java

@ -265,15 +265,25 @@ public class AdminTeamController extends BaseController {
    @ApiOperation(value = "获取医生团队列表")
    public String getDoctorTeams(@PathVariable("doctor_code") String doctorCode) {
        try {
//            List<AdminTeam> teamList = teamService.getDoctorTeams(doctorCode);
//            return write(200, "OK", "data", new JSONArray(teamList));
            return write(200, "OK", "data", teamService.getAdminTeams(doctorCode));
            List<AdminTeam> teamList = teamService.getDoctorTeams(doctorCode);
            return write(200, "OK", "data", new JSONArray(teamList));
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "/team/{doctor_code}/teamsLimit", method = RequestMethod.GET)
    @ApiOperation(value = "获取医生团队列表(获取基位签约上线)")
    public String getDoctorTeamLimit(@PathVariable("doctor_code") String doctorCode){
        try {
            return write(200, "OK", "data", teamService.getAdminTeams(doctorCode));
        }catch (Exception e){
            error(e);
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "/team/members/{patient_code}", method = RequestMethod.GET)
    @ApiOperation(value = "根据患者代码,获取医生团队信息")
    public String getTeam(@PathVariable("patient_code") String patientCode) {

+ 96 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/consult/ConsultController.java

@ -29,9 +29,12 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
@ -40,6 +43,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -88,6 +92,12 @@ public class ConsultController extends WeixinBaseController {
    private PrescriptionDao prescriptionDao;
    @Autowired
    private ConsultDao consultDao;
    @Value("${doctorAssistant.api}")
    private String doctorAssistant;
    @Value("${doctorAssistant.target_url}")
    private String targetUrl;
    @Autowired
    private HttpClientUtil httpClientUtil;
    /**
@ -382,10 +392,40 @@ public class ConsultController extends WeixinBaseController {
            // 推送消息给医生
            if(dts==null||dts.length()==0){
                pushMsgTask.put(consult.getDoctor(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.D_CT_01.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.指定咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.您有新的指定咨询.name(), consult.getConsult());
                Doctor doctor = doctorDao.findByCode(consult.getDoctor());
                if (doctor!=null && StringUtils.isNotEmpty(doctor.getOpenid())){
                    String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
                    List<NameValuePair> params = new ArrayList<>();
                    params.add(new BasicNameValuePair("type", "4"));
                    params.add(new BasicNameValuePair("openId", doctor.getOpenid()));
                    params.add(new BasicNameValuePair("url", targetUrl));
                    params.add(new BasicNameValuePair("first", doctor.getName() + "医生您好,有患者向您发起咨询"));
                    params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
                    String sex = consult.getSex()==1? "男" : "女";
                    String keywords = consult.getName() + "," + sex;
                    params.add(new BasicNameValuePair("keywords", keywords));
                    httpClientUtil.post(url, params, "UTF-8");
                }
            }else {
                for (int i=0;i<dts.length();i++){
                    String doctorCode = dts.getString(i);
                    pushMsgTask.put(doctorCode, MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.D_CT_01.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.指定咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.您有新的指定咨询.name(), consult.getConsult());
                    Doctor doctor = doctorDao.findByCode(doctorCode);
                    if (doctor!=null && StringUtils.isNotEmpty(doctor.getOpenid())){
                        String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
                        List<NameValuePair> params = new ArrayList<>();
                        params.add(new BasicNameValuePair("type", "4"));
                        params.add(new BasicNameValuePair("openId", doctor.getOpenid()));
                        params.add(new BasicNameValuePair("url", targetUrl));
                        params.add(new BasicNameValuePair("first", doctor.getName() + "医生您好,有患者向您发起咨询"));
                        params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
                        String sex = consult.getSex()==1? "男" : "女";
                        String keywords = consult.getName() + "," + sex;
                        params.add(new BasicNameValuePair("keywords", keywords));
                        httpClientUtil.post(url, params, "UTF-8");
                    }
                }
            }
@ -756,12 +796,45 @@ public class ConsultController extends WeixinBaseController {
            for (ConsultTeamLog log : logs) {
//                String response = ImUtill.sendTopicIM(getUID(), patient.getName(), consult, String.valueOf(log.getType()), log.getContent());
                String response = ImUtill.sendTopicIM(getRepUID(), patient.getName(), consult, String.valueOf(log.getType()), log.getContent(),agent);
                if (StringUtils.isNotEmpty(response)) {
                    JSONObject resObj = new JSONObject(response);
                    if (resObj.getInt("status") == -1) {
                        return invalidUserException(new RuntimeException(resObj.getString("message")), -1, "追问失败!" + resObj.getString("message"));
                    }
                    failed.add(String.valueOf(resObj.get("data")));
                    try {
                        //            新增发送医生助手模板消息 v1.4.0 by wujunjie
                        Doctor doctor = doctorDao.findByCode(log.getDoctor());
                        String doctorOpenID = doctor.getOpenid();
                        if (StringUtils.isNotEmpty(doctorOpenID)) {
                                String title = "";
                                Consult consultSingle = consultDao.findByCode(log.getConsult());
                                if (consultSingle!=null){
                                    Integer singleType = consultSingle .getType();
                                    if (singleType != null && singleType ==8 ){
                                        title = consultSingle.getTitle();
                                    }else if(singleType != null && singleType !=8 ){
                                        title = consultSingle.getSymptoms();
                                    }
                                    String first = "居民" +patient.getName()+"的健康咨询有新的回复。";
                                    String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
                                    List<NameValuePair> params = new ArrayList<>();
                                    params.add(new BasicNameValuePair("type", "8"));
                                    params.add(new BasicNameValuePair("openId", doctorOpenID));
                                    params.add(new BasicNameValuePair("url", targetUrl));
                                    params.add(new BasicNameValuePair("first",  first));
                                    params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
                                    String keywords = title + "," + content +","+ log.getDoctorName();
                                    params.add(new BasicNameValuePair("keywords", keywords));
                                    httpClientUtil.post(url, params, "UTF-8");
                                }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            return write(200, "追问成功!", "data", failed);
@ -1026,6 +1099,29 @@ public class ConsultController extends WeixinBaseController {
            // 推送消息给医生
            pushMsgTask.put(doctor, MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.D_CT_01.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM_PRESCRIPTION.续方咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM_PRESCRIPTION.您有新的续方咨询.name(), consult.getConsult());
            try {
                //            新增发送医生助手模板消息 v1.4.0 by wujunjie
                Doctor doctor1 = doctorDao.findByCode(doctor);
                Patient patient = patientDao.findByCode(getRepUID());
                String doctorOpenID = doctor1.getOpenid();
                if (StringUtils.isNotEmpty(doctorOpenID)) {
                        String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
                        List<NameValuePair> params = new ArrayList<>();
                        params.add(new BasicNameValuePair("type", "9"));
                        params.add(new BasicNameValuePair("openId", doctorOpenID));
                        params.add(new BasicNameValuePair("url", targetUrl));
                        params.add(new BasicNameValuePair("first", doctor1.getName() + "医生您好。您的签约居民"+patient.getName()+"申请线上续方,请尽快审核。"));
                        params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
                        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
                        String date = format.format(new Date());
                        String keywords = "续方审核" + "," + date;
                        params.add(new BasicNameValuePair("keywords", keywords));
                        httpClientUtil.post(url, params, "UTF-8");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            BusinessLogs.info(BusinessLogs.BusinessType.consult, getRepUID(), getUID(), new JSONObject(consult));
            return write(200, "提交成功", "data", consult);

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/ehc/PatientEHCController.java

@ -36,7 +36,7 @@ public class PatientEHCController extends WeixinBaseController {
        try {
            String msg = null;
            int code = 0;
            String patient = getUID();
            String patient = getRepUID();
            String result = ehcService.EHCRedirecturl(patient);
            switch (result) {
                case "0":