Browse Source

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

liuwenbin 7 years ago
parent
commit
a0b0715756
43 changed files with 2574 additions and 196 deletions
  1. 10 0
      common/common-entity/src/main/java/com/yihu/wlyy/entity/followup/Followup.java
  2. 74 0
      common/common-entity/src/main/java/com/yihu/wlyy/entity/followup/FollowupMapping.java
  3. 91 0
      common/common-entity/src/main/java/com/yihu/wlyy/entity/patient/PhysicalExaminationRecords.java
  4. 133 0
      common/common-entity/src/main/java/com/yihu/wlyy/entity/patient/prescription/PrescriptionAdress.java
  5. 3 0
      common/common-entity/src/main/java/com/yihu/wlyy/entity/patient/prescription/PrescriptionLog.java
  6. 54 1
      patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/controller/SignController.java
  7. 34 0
      patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/SignZYService.java
  8. 57 0
      patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/ZysoftService.java
  9. 0 1
      patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/common/thread/UploadRenewThread.java
  10. 18 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/event/ApplicationEvent.java
  11. 41 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/job/FollowUpSynJob.java
  12. 32 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/job/FollowUpUploadJob.java
  13. 35 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/job/PatientPhysicalExaminationJob.java
  14. 3 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/doctor/DoctorDao.java
  15. 28 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/doctor/DoctorMappingDao.java
  16. 6 1
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/followup/FollowUpDao.java
  17. 17 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/followup/FollowUpMappingDao.java
  18. 2 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/followup/FollowupContentDao.java
  19. 3 3
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/organization/HospitalMappingDao.java
  20. 7 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/patient/SignFamilyDao.java
  21. 14 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/physicalExamination/PatientPhysicalExaminationDao.java
  22. 120 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/app/physicalExamination/PatientPhysicalExaminationService.java
  23. 767 93
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/third/jw/JwPrescriptionService.java
  24. 53 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/web/quota/JobController.java
  25. 8 1
      patient-co/patient-co-wlyy-job/src/main/resources/system.properties
  26. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientDao.java
  27. 40 7
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/followup/FollowUpService.java
  28. 6 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthIndexService.java
  29. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/message/MessageService.java
  30. 1 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/physicalExamination/PhysicalExamTeamRemindService.java
  31. 44 13
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/physicalExamination/PhysicalExaminationRemindService.java
  32. 52 18
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionInfoService.java
  33. 3 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionService.java
  34. 2 11
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsAllService.java
  35. 565 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsService.java
  36. 120 9
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statisticsES/StatisticsESService.java
  37. 12 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/jw/ZyDictService.java
  38. 5 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/followup/DoctorFollowUpController.java
  39. 17 16
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthGuidanceController.java
  40. 13 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/PyhsicExamRemindController.java
  41. 31 4
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/prescription/PrescriptionInfoController.java
  42. 3 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/EsStatisticsController.java
  43. 48 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java

+ 10 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/followup/Followup.java

@ -35,6 +35,8 @@ public class Followup extends IdEntity {
	private String doctorCode;
	//医生姓名
	private String doctorName;
	//基卫医生CODE
	private String jwdoctorCode;
	//社区代码
	private String orgCode;
	//社区名称
@ -252,4 +254,12 @@ public class Followup extends IdEntity {
	public void setSignCode(String signCode) {
		this.signCode = signCode;
	}
	
	public String getJwdoctorCode() {
		return jwdoctorCode;
	}
	
	public void setJwdoctorCode(String jwdoctorCode) {
		this.jwdoctorCode = jwdoctorCode;
	}
}

+ 74 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/followup/FollowupMapping.java

@ -0,0 +1,74 @@
package com.yihu.wlyy.entity.followup;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.sql.Timestamp;
/**
 * 随访记录映射表
 * @author huangwenjie
 * @date 2017/10/23 14:02
 */
@Entity
@Table(name = "wlyy_followup_mapping")
public class FollowupMapping extends IdEntity {
	private String code;
	private Integer followupId;
	private Integer needUpload;
	private Timestamp createTime;
	private Timestamp updateTime;
	
	@Basic
	@Column(name = "code")
	public String getCode() {
		return code;
	}
	
	public void setCode(String code) {
		this.code = code;
	}
	
	@Basic
	@Column(name = "followup_id")
	public Integer getFollowupId() {
		return followupId;
	}
	
	public void setFollowupId(Integer followupId) {
		this.followupId = followupId;
	}
	
	@Basic
	@Column(name = "need_upload")
	public Integer getNeedUpload() {
		return needUpload;
	}
	
	public void setNeedUpload(Integer needUpload) {
		this.needUpload = needUpload;
	}
	
	@Basic
	@Column(name = "create_time")
	public Timestamp getCreateTime() {
		return createTime;
	}
	
	public void setCreateTime(Timestamp createTime) {
		this.createTime = createTime;
	}
	
	@Basic
	@Column(name = "update_time")
	public Timestamp getUpdateTime() {
		return updateTime;
	}
	
	public void setUpdateTime(Timestamp updateTime) {
		this.updateTime = updateTime;
	}
}

+ 91 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/patient/PhysicalExaminationRecords.java

@ -0,0 +1,91 @@
package com.yihu.wlyy.entity.patient;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
 * 系统体检提醒记录表
 * 老年人体检提醒&免疫计划提醒
 * @author Reece
 * @date 2017/10/18 17:15
 */
@Entity
@Table(name = "wlyy_physical_examination_records")
public class PhysicalExaminationRecords extends IdEntity implements Serializable {
	private String code;
	private Integer type;           //1老年人体检提醒,2免疫计划提醒
	private String patientCode;     //居民CODE
	private int status;     //状态0未发送,1已发送,2发送失败
	private Date remindTime;   //提醒时间
	private Date createTime;   //创建时间
	
	private static final long serialVersionUID = 8358924836164389434L;
	@Basic
	@Column(name = "status")
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	@Basic
	@Column(name = "code")
	public String getCode() {
		return code;
	}
	
	public void setCode(String code) {
		this.code = code;
	}
	
	@Basic
	@Column(name = "type")
	public Integer getType() {
		return type;
	}
	
	public void setType(Integer type) {
		this.type = type;
	}
	@Basic
	@Column(name = "patient_code")
	public String getPatientCode() {
		return patientCode;
	}
	
	public void setPatientCode(String patientCode) {
		this.patientCode = patientCode;
	}
	
	@Basic
	@Column(name = "remind_time")
	public Date getRemindTime() {
		return remindTime;
	}
	
	public void setRemindTime(Date remindTime) {
		this.remindTime = remindTime;
	}
	
	@Basic
	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}
	
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
}

+ 133 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/patient/prescription/PrescriptionAdress.java

@ -0,0 +1,133 @@
package com.yihu.wlyy.entity.patient.prescription;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by Trick on 2017/10/20.
 */
@Entity
@Table(name = "wlyy_prescription_adress")
public class PrescriptionAdress extends IdEntity {
    private String patient;//关联患者
    private String name;//名字
    private String phone;//手机
    private String province;//省编码
    private String city;//市编码
    private String town;//区编码
    private String provinceName;//省会
    private String cityName;//城市
    private String townName;//区
    private String adress; //地址
    private String defaultFlag;//0.非首选,1.首选
    private Date createTime;//创建时间
    private Date updateTime;//更新时间
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
    public String getProvince() {
        return province;
    }
    public void setProvince(String province) {
        this.province = province;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getTown() {
        return town;
    }
    public void setTown(String town) {
        this.town = town;
    }
    public String getProvinceName() {
        return provinceName;
    }
    public void setProvinceName(String provinceName) {
        this.provinceName = provinceName;
    }
    public String getCityName() {
        return cityName;
    }
    public void setCityName(String cityName) {
        this.cityName = cityName;
    }
    public String getTownName() {
        return townName;
    }
    public void setTownName(String townName) {
        this.townName = townName;
    }
    public String getAdress() {
        return adress;
    }
    public void setAdress(String adress) {
        this.adress = adress;
    }
    public String getDefaultFlag() {
        return defaultFlag;
    }
    public void setDefaultFlag(String defaultFlag) {
        this.defaultFlag = defaultFlag;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}

+ 3 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/patient/prescription/PrescriptionLog.java

@ -55,6 +55,9 @@ public class PrescriptionLog extends IdEntity {
    //状态枚举
    public enum PrescriptionLogStatus {
        pay_cancle("线下取消",-5),
        pay_refund("线下退费",-4),
        //续方取消
        pay_outtime("支付超时", -3),

+ 54 - 1
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/controller/SignController.java

@ -103,7 +103,7 @@ public class SignController {
    }
    
    @RequestMapping(value = "getSickMedicalSimpleListInfo",method = RequestMethod.POST)
    @ApiOperation("查询老年人体检记录接口")
    @ApiOperation("查询家签老年人体检记录接口")
    public Result getSickMedicalSimpleListInfo (
            @ApiParam(name="TIME_START",value="修改的开始时间",defaultValue = "2012-2-6 00:00:00")
            @RequestParam(value="TIME_START",required = false) String TIME_START,
@ -124,6 +124,59 @@ public class SignController {
            }
        }
    }
    
    @RequestMapping(value = "getEhrChroDaysFollowUpInfoRecord",method = RequestMethod.POST)
    @ApiOperation("查询家庭医生服务日常随访信息接口")
    public Result getEhrChroDaysFollowUpInfoRecord(
            @ApiParam(name="TIME_START",value="修改的开始时间",defaultValue = "2017-06-6 00:00:00")
            @RequestParam(value="TIME_START",required = false) String TIME_START,
            @ApiParam(name="TIME_END",value="修改的开始时间",defaultValue = "2017-06-7 23:59:59")
            @RequestParam(value="TIME_END",required = false) String TIME_END,
            @ApiParam(name="IDENTITY_CARD_NO",value="身份证号",defaultValue = "350221197506113526")
            @RequestParam(value="IDENTITY_CARD_NO",required = false) String IDENTITY_CARD_NO){
        try {
            String response = "";
            if(StringUtils.isBlank(IDENTITY_CARD_NO)){
                response = signZYService.getEhrChroDaysFollowUpInfoRecord(TIME_START,TIME_END);
            }else{
                response = signZYService.getEhrChroDaysFollowUpInfoRecordByIdcard(IDENTITY_CARD_NO);
            }
            return Result.success("查询成功!",response);
        } catch (Exception ex) {
            ex.printStackTrace();
            if(ex instanceof ApiException)
            {
                ApiException apiEx = (ApiException) ex;
                return Result.error(apiEx.errorCode(),ex.getMessage());
            }
            else{
                return Result.error(ex.getMessage());
            }
        }
    }
    
    @RequestMapping(value = "uploadEhrSickChroDaysFollowUpRecord",method = RequestMethod.POST)
    @ApiOperation("查询家庭医生服务日常随访信息接口")
    public Result uploadEhrSickChroDaysFollowUpRecord(
            @ApiParam(name="OPERATOR",value="操作员代码",defaultValue = "")
            @RequestParam(value="OPERATOR",required = true) String OPERATOR,
            @ApiParam(name="data",value="Json格式字符串",defaultValue = "")
            @RequestParam(value="data",required = true) String data){
        try {
            String response = signZYService.uploadEhrSickChroDaysFollowUpRecord(OPERATOR,data);
            return Result.success("上传成功!",response);
        } catch (Exception ex) {
            ex.printStackTrace();
            if(ex instanceof ApiException)
            {
                ApiException apiEx = (ApiException) ex;
                return Result.error(apiEx.errorCode(),ex.getMessage());
            }
            else{
                return Result.error(ex.getMessage());
            }
        }
    }

+ 34 - 0
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/SignZYService.java

@ -139,4 +139,38 @@ public class SignZYService {
        String response = zysoftService.getSickMedicalSimpleListInfo(time_start,time_end,hospitalMapping[0],hospitalMapping[1]);
        return response;
	}
    /**
     * 根据时间范围查询家庭医生服务日常随访信息
     * @param time_start
     * @param time_end
     * @return
     */
	public String getEhrChroDaysFollowUpInfoRecord(String time_start, String time_end)  throws Exception{
        String[] hospitalMapping = getHospitalMapping(null); //获取机构映射
        String response = zysoftService.getEhrChroDaysFollowUpInfoRecord(time_start,time_end,hospitalMapping[0],hospitalMapping[1]);
        return response;
	}
    
    /**
     * 根据身份证号查询家庭医生服务日常随访信息
     * @param identity_card_no
     * @return
     */
    public String getEhrChroDaysFollowUpInfoRecordByIdcard(String identity_card_no)  throws Exception{
        String[] hospitalMapping = getHospitalMapping(null); //获取机构映射
        String response = zysoftService.getEhrChroDaysFollowUpInfoRecordByIdcard(identity_card_no,hospitalMapping[0],hospitalMapping[1]);
        return response;
    }
    
    /**
     * 上传家庭医生服务日常随访信息
     * @param operator
     * @param data
     * @return
     */
	public String uploadEhrSickChroDaysFollowUpRecord(String operator, String data) throws Exception{
        String[] hospitalMapping = getHospitalMapping(null); //获取机构映射
        String response = zysoftService.uploadEhrSickChroDaysFollowUpRecord(operator,data,hospitalMapping[0],hospitalMapping[1]);
        return response;
	}
}

+ 57 - 0
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/ZysoftService.java

@ -813,6 +813,63 @@ public class ZysoftService {
        
        String response = postSecond("getSickMedicalSimpleListInfo","查询老年人体检记录接口",params,header,false);
        
        return response;
	}
    
    /**
     * 根据时间范围查询家庭医生服务日常随访信息
     * @param time_start
     * @param time_end
     * @return
     */
	public String getEhrChroDaysFollowUpInfoRecord(String time_start, String time_end,String hospital,String licence) throws Exception{
        Map<String,String> header = new HashMap<>();
        header.put("ORGCODE",hospital);
        header.put("LICENCE",licence);
        
        Map<String,String> params = new HashMap<>();
        params.put("TIME_START",time_start);
        params.put("TIME_END",time_end);
        
        String response = postSecond("getEhrChroDaysFollowUpInfoRecord","查询家庭医生服务日常随访信息接口",params,header,false);
        
        return response;
	}
    
    /**
     * 根据身份证号查询家庭医生服务日常随访信息
     * @param identity_card_no
     * @return
     */
    public String getEhrChroDaysFollowUpInfoRecordByIdcard(String identity_card_no,String hospital,String licence) throws Exception{
    
        Map<String,String> header = new HashMap<>();
        header.put("ORGCODE",hospital);
        header.put("LICENCE",licence);
    
        Map<String,String> params = new HashMap<>();
        params.put("IDENTITY_CARD_NO",identity_card_no);
    
        String response = postSecond("getEhrChroDaysFollowUpInfoRecord","查询家庭医生服务日常随访信息接口",params,header,false);
    
        return response;
    }
    /**
     * 上传家庭医生服务日常随访信息
     * @param operator
     * @param data
     * @return
     */
	public String uploadEhrSickChroDaysFollowUpRecord(String operator, String data, String hospital,String licence) throws Exception{
        Map<String,String> header = new HashMap<>();
        header.put("ORGCODE",hospital);
        header.put("LICENCE",licence);
        header.put("OPERATOR",operator);
        
        com.alibaba.fastjson.JSONObject json = JSON.parseObject(data);
        
        String response = postSecond("getEhrChroDaysFollowUpInfoRecord","查询家庭医生服务日常随访信息接口",json,header);
        
        return response;
	}
}

+ 0 - 1
patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/common/thread/UploadRenewThread.java

@ -1,7 +1,6 @@
package com.yihu.wlyy.sign.common.thread;
import com.yihu.wlyy.sign.common.util.DateUtil;
import com.yihu.wlyy.sign.common.util.SpringContextHolder;
import com.yihu.wlyy.sign.service.SignRenewZYService;
import com.yihu.wlyy.sign.service.SystemDictService;

+ 18 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/event/ApplicationEvent.java

@ -169,6 +169,24 @@ public class ApplicationEvent implements ApplicationListener<ContextRefreshedEve
            } else {
                logger.info("old_people_tijian_syb_job  job exist");
            }
    
            //居民随访信息同步,每天陵城3点执行一次
            if (!quartzHelper.isExistJob("patient_followup_syb_job")) {
                String trigger = SystemConf.getInstance().getSystemProperties().getProperty("patient_followup_syb_job");
                quartzHelper.addJob(FollowUpSynJob.class, trigger, "patient_followup_syb_job", new HashMap<String, Object>());
                logger.info("patient_followup_syb_job  job success");
            } else {
                logger.info("patient_followup_syb_job  job exist");
            }
            //老年人体检消息发送记录,每天凌晨1点执行一次
            if (!quartzHelper.isExistJob("patient_physical_examination_job")) {
                String trigger = SystemConf.getInstance().getSystemProperties().getProperty("patient_physical_examination_job");
                quartzHelper.addJob(OldPeoplePhysicalExaminationSynJob.class, trigger, "patient_physical_examination_job", new HashMap<String, Object>());
                logger.info("patient_physical_examination_job  job success");
            } else {
                logger.info("patient_physical_examination_job  job exist");
            }
            // 启动redis 消息队列线程
            logger.info("redis message start");

+ 41 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/job/FollowUpSynJob.java

@ -0,0 +1,41 @@
package com.yihu.wlyy.job;
import com.yihu.wlyy.service.third.jw.JwPrescriptionService;
import com.yihu.wlyy.util.DateUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
 * 居民随访记录同步JOB
 * @author huangwenjie
 * @date 2017/10/19 15:02
 */
public class FollowUpSynJob implements Job {
	private static final Logger logger = LoggerFactory.getLogger(FollowUpSynJob.class);
	
	@Autowired
	private JwPrescriptionService jwPrescriptionService;
	
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		logger.info("START=====居民随访记录同步JOB");
		try {
			
			//获取前一天的时间范围
			String startdate = DateUtil.getNextDay(DateUtil.getStringDateShort(),-1) + " 00:00:00";
			String enddate = DateUtil.getNextDay(DateUtil.getStringDateShort(),-1) + " 23:59:59";
			
			//根据起止时间查询家签居民随访记录,并同步到本地数据库
			jwPrescriptionService.getFollowUpByTime(startdate,enddate);
			
			logger.info("END========居民随访记录同步JOB");
		}catch (Exception e){
			e.printStackTrace();
			logger.info("END===ERROE===居民随访记录同步JOB,message:"+e.getMessage());
		}
	}
}

+ 32 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/job/FollowUpUploadJob.java

@ -0,0 +1,32 @@
package com.yihu.wlyy.job;
import com.yihu.wlyy.service.third.jw.JwPrescriptionService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
 * 居民随访记录上传(上传到基卫)JOB
 * @author huangwenjie
 * @date 2017/10/23 11:20
 */
public class FollowUpUploadJob implements Job {
	private static final Logger logger = LoggerFactory.getLogger(FollowUpUploadJob.class);
	@Autowired
	private JwPrescriptionService jwPrescriptionService;
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		logger.info("START=====上传居民随访记录JOB");
		try {
			//上传居民随访记录到基卫
			jwPrescriptionService.uploadFollowUpRecordToJW();
			logger.info("END========上传居民随访记录JOB");
		}catch (Exception e){
			e.printStackTrace();
			logger.info("END===ERROE===上传居民随访记录JOB,message:"+e.getMessage());
		}
	}
}

+ 35 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/job/PatientPhysicalExaminationJob.java

@ -0,0 +1,35 @@
package com.yihu.wlyy.job;
import com.yihu.wlyy.service.app.physicalExamination.PatientPhysicalExaminationService;
import com.yihu.wlyy.task.PushMsgTask;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
 * Created by Reece on 2017/10/18/018.
 *
 * 居民端定期体检模板提醒
 */
public class PatientPhysicalExaminationJob implements Job {
    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(PatientPhysicalExaminationJob.class);
    @Autowired
    private PatientPhysicalExaminationService examinationService;
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        logger.info("PatientPhysicalExaminationJob start ..........");
        try {
            examinationService.sendExaminationTemplate();
            logger.info("PatientPhysicalExaminationJob end ..........");
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("PatientPhysicalExaminationJob error ..........  error ,error message "+e.getMessage());
        }
    }
}

+ 3 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/doctor/DoctorDao.java

@ -158,4 +158,7 @@ public interface DoctorDao extends PagingAndSortingRepository<Doctor, Long>, Jpa
    @Modifying
    @Query("update Doctor set checkPassword = ?2 ,checkSalt = ?3  where code = ?1")
    int updateCheckPassword(String code, String checkPassword, String checkSalt);
    
    @Query("select a from Doctor a,DoctorMapping b where a.code = b.doctorCode and b.jwDoctor = ?1 and b.jwDoctorHospital = ?2")
    Doctor findMappingDoctor(String jwDoctor,String jwHospital);
}

+ 28 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/doctor/DoctorMappingDao.java

@ -0,0 +1,28 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.DoctorMapping;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * 医生映射接口
 **/
public interface DoctorMappingDao extends PagingAndSortingRepository<DoctorMapping, Long>,JpaSpecificationExecutor<DoctorMapping> {
	
	
	@Query("select a.jwDoctor from DoctorMapping a where a.doctorCode = ?1 and a.jwDoctorHospital = ?2")
	String findByDocotrCodeAndJwDoctorHospital(String docotrCode,String jwDoctorHospital);
	
	DoctorMapping findByJwDoctorHospitalAndJwDoctor(String jwDoctorHospital,String jwDoctor);
	
	@Query("select a from Doctor a,DoctorMapping b where a.code = b.doctorCode and b.jwDoctorHospital = ?1 and b.jwDoctor = ?2")
	Doctor getDoctorByJw(String jwDoctorHospital, String jwDoctor);
	
	@Query("select a from Doctor a,DoctorMapping b where a.code = b.doctorCode and a.code = ?1 and b.jwDoctorHospital = ?2")
	Doctor getDoctor(String docotrCode,String jwDoctorHospital);
	
	@Query("from DoctorMapping a where a.jwDoctorHospital = ?1 and a.doctorCode = ?2")
	DoctorMapping findByJwDoctorHospitalAndDoctorCode(String jwDoctorHospital,String doctorCode);
}

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

@ -15,7 +15,6 @@ import com.yihu.wlyy.entity.followup.Followup;
import java.util.Date;
import java.util.List;
import java.util.Map;
public interface FollowUpDao extends PagingAndSortingRepository<Followup, Long>, JpaSpecificationExecutor<Followup> {
@ -30,4 +29,10 @@ public interface FollowUpDao extends PagingAndSortingRepository<Followup, Long>,
    @Query("select d.code,d.name,d.photo,a.followupType,a.followupClass,a.status,a.createTime,a.updateTime,a.followupManagerStatus,c.code,c.name,c.photo" + ",a.followupDate,a.followupPlanDate,a.followupNextDate,a.id,a.followupNo from Followup a, Doctor d, Doctor c where a.doctorCode = d.code and a.creater = c.code and a.patientCode = ?1 and a.adminTeamCode = ?2 and a.status > 0")
    Page<Object> findByPatientAndTeam(String patient, Long teamCode, Pageable pageable);
    
    @Query(value = "select a.* from wlyy_followup a where a.followup_no = ?1",nativeQuery = true)
    Followup findByFollowupNo(String followupNo) throws Exception;
    
    @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);
}

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

@ -0,0 +1,17 @@
package com.yihu.wlyy.repository.followup;
import com.yihu.wlyy.entity.followup.FollowupMapping;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * 随访记录映射表
 * @author huangwenjie
 * @date 2017/10/23 14:05
 */
public interface FollowUpMappingDao extends PagingAndSortingRepository<FollowupMapping, Long>, JpaSpecificationExecutor<FollowupMapping> {
	
	List<FollowupMapping> findByNeedUpload(Integer needupload);
}

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

@ -20,4 +20,6 @@ public interface FollowupContentDao extends PagingAndSortingRepository<FollowupC
    List<FollowupContent> findByFollowupIdAndFollowupProject(Long followupId,String followupProject);
    List<FollowupContent> findByFollowupId(Long followupId);
    
    void deleteByFollowupId(Long followupId);
}

+ 3 - 3
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/organization/HospitalMappingDao.java

@ -20,9 +20,9 @@ public interface HospitalMappingDao extends PagingAndSortingRepository<HospitalM
	@Query("select a.mappingCode from HospitalMapping a where a.code=?1 and a.type=?2")
	String getMappingCode(String code,String type);
	@Query("select a.code from HospitalMapping a where a.mappingCode=?1 and a.type=?2")
	String getCodeByMapping(String mappingCode,String type);
	
	@Query("select a from HospitalMapping a where a.mappingCode=?1 and a.type=?2")
	HospitalMapping getCodeByMapping(String mappingCode, String type);
	@Query("select a from HospitalMapping a where a.appId=?1 ")
	HospitalMapping findByAppId(String appId);

+ 7 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/patient/SignFamilyDao.java

@ -415,4 +415,11 @@ public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Lo
    @Query( " select a from SignFamily a where a.patient = ?1 ")
    SignFamily findPatientExpensesStatus(String patient);
    //查询65岁以上一年内未体检且未系统提醒的签约居民
    @Query(value = "SELECT DISTINCT t1.* FROM wlyy_sign_family t1 LEFT JOIN wlyy_physical_examination_records r ON r.patient_code=t1.patient WHERE r.patient_code IS NULL " +
            " AND t1.STATUS>0 AND t1.hospital=?1 AND(YEAR(curdate())-IF(length(idcard)=18,substring(idcard,7,4),IF(length(idcard)=15,concat('19',substring(idcard,7,2)),NULL)))>65 " +
            " AND t1.idcard NOT IN(SELECT DISTINCT s.idcard FROM wlyy_sign_family s,wlyy_old_people_physical_examination o WHERE s.hospital=?1 AND s.`status`>0 AND s.idcard=o.id_card " +
            " AND o.medical_time>?2 )ORDER BY t1.openid DESC,CONVERT(t1.NAME USING gbk) ",nativeQuery = true)
    List<SignFamily> findExaminationByHospital(String hospital,Date examinationTime);
}

+ 14 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/physicalExamination/PatientPhysicalExaminationDao.java

@ -0,0 +1,14 @@
package com.yihu.wlyy.repository.physicalExamination;
import com.yihu.wlyy.entity.oldpeople.OldPeoplePhysicalExaminationEntity;
import com.yihu.wlyy.entity.patient.PhysicalExaminationRecords;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Reece on 2017/10/18/018.
 */
public interface PatientPhysicalExaminationDao extends PagingAndSortingRepository<PhysicalExaminationRecords, Long>,JpaSpecificationExecutor<PhysicalExaminationRecords> {
}

+ 120 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/app/physicalExamination/PatientPhysicalExaminationService.java

@ -0,0 +1,120 @@
package com.yihu.wlyy.service.app.physicalExamination;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientRemindRecords;
import com.yihu.wlyy.entity.patient.PhysicalExaminationRecords;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.organization.HospitalDao;
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.physicalExamination.PatientPhysicalExaminationDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.IdCardUtil;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
 * Created by Reece on 2017/10/18/018.
 * <p>
 * 居民近365天无体检记录时,系统自动发送一条体检提醒信息。使用“代办事项通知”模板
 * 代理机制还存在
 */
public class PatientPhysicalExaminationService extends BaseService {
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private WeiXinOpenIdUtils openIdUtils;
    @Autowired
    private HospitalDao hospitalDao;
    @Autowired
    private SignFamilyDao familyDao;
    @Autowired
    private WeiXinAccessTokenUtils accessTokenUtils;
    @Autowired
    private PatientPhysicalExaminationDao examinationDao;
    public void sendExaminationTemplate() throws Exception {
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.YEAR, -1);
        Date yesteryear = c.getTime();
        JSONObject json = new JSONObject();
        String first = "温馨提醒,您已经超过一年没有到社区进行健康体检啦,为了您和您的家庭医生了解您近期的健康状况,请及时到签约社区进行免费的健康体检哟~";
        json.put("remark", "");
        json.put("keyword1", "健康体检");
        json.put("keyword2", format.format(new Date()));
        String accessToken = accessTokenUtils.getAccessToken();
//        1.找出符合条件的居民信息
        List<Hospital> hospitals = hospitalDao.findAllHospital();
        for (Hospital hospital : hospitals) {
            Boolean flag = false;
            List<SignFamily> signFamilies = familyDao.findExaminationByHospital(hospital.getCode(), yesteryear);
            for (SignFamily signFamilie : signFamilies) {
                String patientCode = signFamilie.getPatient();
                Patient patient = patientDao.findByCode(patientCode);
                String url = "huanzhe/html/jiankangtijian.html?openid=" + patient.getOpenid() + "&toUser=" + patient.getCode() + "&toName=" + patient.getName();
                json.put("url", url);
                String mobile = patient.getMobile();
                if (StringUtils.isNotBlank(patient.getOpenid())) {
                    json.put("first", first);
                    pushMsgTask.putWxMsg(accessToken, 11, patient.getOpenid(), patient.getName(), json);
                    flag = true;
                }
                //发送代理人
                JSONArray jsonArray = openIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
                if (jsonArray != null && jsonArray.length() > 0) {
                    for (int i = 0; i < jsonArray.length(); i++) {
                        org.json.JSONObject j = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        int start = url.indexOf("&toUser=");
                        int end = url.indexOf("&", start + 1);
                        String touser = url.substring(start, end);
                        url = url.replace(touser, "&toUser=" + member.getCode());
                        json.remove("first");
                        try {
                            json.put("first", openIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName()) + first);
                            json.put("url", url);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        if (StringUtils.isNotBlank(member.getOpenid())) {
                            pushMsgTask.putWxMsg(accessToken, 11, member.getOpenid(), patient.getName(), json);
                            flag = true;
                        }
                    }
                }
                if (flag){
                    //发送成功保存发送记录
                    PhysicalExaminationRecords records = new PhysicalExaminationRecords();
                    records.setCode(getCode());
                    records.setType(1);
                    records.setPatientCode(patientCode);
                    records.setStatus(1);
                    records.setCreateTime(new Date());
                    records.setRemindTime(new Date());
                    examinationDao.save(records);
                }
            }
        }
    }
}

+ 767 - 93
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/third/jw/JwPrescriptionService.java

@ -3,9 +3,26 @@ package com.yihu.wlyy.service.third.jw;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.followup.Followup;
import com.yihu.wlyy.entity.followup.FollowupContent;
import com.yihu.wlyy.entity.followup.FollowupDrugs;
import com.yihu.wlyy.entity.followup.FollowupMapping;
import com.yihu.wlyy.entity.oldpeople.OldPeoplePhysicalExaminationEntity;
import com.yihu.wlyy.entity.organization.HospitalMapping;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.patient.prescription.Prescription;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.doctor.DoctorMappingDao;
import com.yihu.wlyy.repository.followup.FollowUpDao;
import com.yihu.wlyy.repository.followup.FollowUpMappingDao;
import com.yihu.wlyy.repository.followup.FollowupContentDao;
import com.yihu.wlyy.repository.followup.FollowupDrugsDao;
import com.yihu.wlyy.repository.oldpeople.OldPeoplePhysicalExaminationDao;
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.prescription.PrescriptionDao;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.util.DateUtil;
@ -18,17 +35,24 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import java.text.DecimalFormat;
import java.util.*;
import static org.bouncycastle.asn1.x509.X509ObjectIdentifiers.id;
/**
 * 基位长处方接口
 * Created by yeshijie on 2017/8/3.
 */
@Service
public class JwPrescriptionService {
    
    private static final Logger logger = LoggerFactory.getLogger(JwPrescriptionService.class);
    //基卫服务地址
    @Value("${sign.check_upload}")
@ -43,50 +67,73 @@ public class JwPrescriptionService {
    private PatientService patientService;
    @Autowired
    private OldPeoplePhysicalExaminationDao oldPeoplePhysicalExaminationDao;
    @Autowired
    private DoctorMappingDao doctorMappingDao;
    @Autowired
    private HospitalMappingDao hospitalMappingDao;
    @Autowired
    private DoctorDao doctorDao;
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Autowired
    private FollowUpDao followUpDao;
    @Autowired
    private FollowupContentDao followupContentDao;
    @Autowired
    private JpaTransactionManager transactionManager;
    @Autowired
    private FollowupDrugsDao followupDrugsDao;
    @Autowired
    private FollowUpMappingDao followUpMappingDao;
    
    /**
     * 获取字典列表
     *
     * @param dictName 字典名称
     * @return
     * @throws Exception
     */
    public String getDictForI(String dictName) throws Exception{
    public String getDictForI(String dictName) throws Exception {
        String url = jwUrl + "/third/prescription/getDictForI";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("dictName", dictName));
    
        String response = httpClientUtil.post(url, params, "UTF-8");
    
        return response;
    }
    
    /**
     * 获取处方模板
     *
     * @param doctor 医生code
     * @return
     * @throws Exception
     */
    public String getRecipeTemplate(String doctor) throws Exception{
    public String getRecipeTemplate(String doctor) throws Exception {
        String url = jwUrl + "/third/prescription/getRecipeTemplate";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("doctor", doctor));
    
        String response = httpClientUtil.post(url, params, "UTF-8");
    
        return response;
    }
    
    
    /**
     * 获取历史处方记录
     * @param cardNo 社保卡号
     * @param recipeNo 医嘱号
     *
     * @param cardNo        社保卡号
     * @param recipeNo      医嘱号
     * @param applyTimeFrom 开始时间
     * @param applyTimeEnd 结束时间
     * @param applyTimeEnd  结束时间
     * @return
     * @throws Exception
     */
    public String getLastRecipe(String cardNo,String recipeNo,String applyTimeFrom,String applyTimeEnd) throws Exception{
    public String getLastRecipe(String cardNo, String recipeNo, String applyTimeFrom, String applyTimeEnd) throws Exception {
        String url = jwUrl + "/third/prescription/getLastRecipe";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("cardNo", cardNo));
@ -97,207 +144,215 @@ public class JwPrescriptionService {
//        String response = httpClientUtil.post(url, params, "UTF-8");
        String sql = "SELECT h.response from wlyy_http_log h WHERE h.id = 806287";
        List<Map<String ,Object>> list = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        String response = list.get(0).get("response").toString();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",200);
        jsonObject.put("data",response);
        jsonObject.put("status", 200);
        jsonObject.put("data", response);
        response = jsonObject.toString();
    
        return response;
    }
    
    /**
     * 获取单条历史处方
     *
     * @param recipeNo
     * @param cardNo
     * @return
     */
    public String getRecipe(String recipeNo,String cardNo){
    public String getRecipe(String recipeNo, String cardNo) {
        String url = jwUrl + "/third/prescription/getRecipe";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("recipeNo", recipeNo));
        params.add(new BasicNameValuePair("cardNo", cardNo));
    
        String response = httpClientUtil.post(url, params, "UTF-8");
    
        return response;
    }
    
    /**
     * 处方开方接口
     *
     * @param prescriptionCode 续方code
     * @return
     * @throws Exception
     */
    public String saveRecipe(String prescriptionCode){
    public String saveRecipe(String prescriptionCode) {
        String response = null;
        try {
            String url = jwUrl + "/third/prescription/saveRecipe";
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("prescriptionCode", prescriptionCode));
    
            response = httpClientUtil.post(url, params, "UTF-8");
            return response;
        }catch (Exception e){
            logger.info("处方开方接口saveRecipe:"+response);
        } catch (Exception e) {
            logger.info("处方开方接口saveRecipe:" + response);
            throw e;
        }
    }
    
    /**
     * 待结算费用列表接口
     *
     * @param cardNo
     * @param visitNo
     * @return
     * @throws Exception
     */
    public String getDispUnSettleFeeInfoList(String cardNo,String visitNo) throws Exception{
    public String getDispUnSettleFeeInfoList(String cardNo, String visitNo) throws Exception {
        String url = jwUrl + "/third/prescription/getDispUnSettleFeeInfoList";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("cardNo", cardNo));
        params.add(new BasicNameValuePair("visitNo", visitNo));
    
        String response = httpClientUtil.post(url, params, "UTF-8");
    
        return response;
    }
    
    
    /**
     * 院内结算确认接口
     *
     * @param prescriptionCode 处方CODE
     * @return
     * @throws Exception
     */
    public String executeSickSettle(String prescriptionCode) throws Exception{
    public String executeSickSettle(String prescriptionCode) throws Exception {
        String url = jwUrl + "/third/prescription/executeSickSettle";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("prescriptionCode", prescriptionCode));
        String response = httpClientUtil.post(url, params, "UTF-8");
        if(StringUtils.isNotBlank(response)){
            JSONObject reobj =  JSON.parseObject(response);
        if (StringUtils.isNotBlank(response)) {
            JSONObject reobj = JSON.parseObject(response);
            Integer status = reobj.getInteger("status");
            String errmsg = reobj.getString("msg");
            if(200 != status){
                throw new Exception("基卫接口(院内结算确认接口)请求失败,"+errmsg);
            if (200 != status) {
                throw new Exception("基卫接口(院内结算确认接口)请求失败," + errmsg);
            }
        }else{
        } else {
            throw new Exception("基卫接口(院内结算确认接口)请求失败,无数据返回!");
        }
        return response;
    }
    
    /**
     * 挂号作废处方接口
     *
     * @param prescriptionCode 续方号码
     * @return
     * @throws Exception
     */
    public String fadeRecipe(String prescriptionCode)throws Exception{
    public String fadeRecipe(String prescriptionCode) throws Exception {
    
        Prescription prescription = prescriptionDao.findByCode(prescriptionCode);
        if(StringUtils.isNotBlank(prescription.getVisitNo())){
    
        if (StringUtils.isNotBlank(prescription.getVisitNo())) {
            String url = jwUrl + "/third/prescription/fadeRecipe";
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("visitNo", prescription.getVisitNo()));//挂号号
            params.add(new BasicNameValuePair("fadeDept", prescription.getJwDeptCode()));//作废科室编码
            params.add(new BasicNameValuePair("fadeOperator", prescription.getJwDoctorCode()));//作废人员编码
            String response = httpClientUtil.post(url, params, "UTF-8");
            if(StringUtils.isNotBlank(response)){
                JSONObject reobj =  JSON.parseObject(response);
            if (StringUtils.isNotBlank(response)) {
                JSONObject reobj = JSON.parseObject(response);
                Integer status = reobj.getInteger("status");
                String errmsg = reobj.getString("msg");
                if(200 != status){
                    throw new Exception("基卫接口(挂号作废)请求失败,"+errmsg);
                if (200 != status) {
                    throw new Exception("基卫接口(挂号作废)请求失败," + errmsg);
                }
            }else{
            } else {
                throw new Exception("基卫接口(挂号作废)请求失败,无数据返回!");
            }
        
            return response;
        }
    
        return "";
    }
    
    /**
     * ca认证接口
     *
     * @param code 续方code
     * @return
     */
    public String affirmCARecipe(String code){
    public String affirmCARecipe(String code) {
        String url = jwUrl + "/third/prescription/affirmCARecipe";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("code", code));//续方code
        String response = httpClientUtil.post(url, params, "UTF-8");
        return response;
    }
    
    /**
     * 根据起止时间查询家签慢病患者定标情况,并同步到本地数据库
     *
     * @param startdate
     * @param enddate
     * @return
     */
    public void getPatientDiseaseContentMapByTime(String startdate, String enddate)throws Exception {
        logger.info("查询家签慢病患者定标情况,开始时间"+startdate+",结束时间:"+enddate);
    public void getPatientDiseaseContentMapByTime(String startdate, String enddate) throws Exception {
    
        logger.info("查询家签慢病患者定标情况,开始时间" + startdate + ",结束时间:" + enddate);
    
    
        String url = jwUrl + "/third/sign/getSickFamilyDoctorSpecialistControl";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("TIME_START", startdate));//开始时间
        params.add(new BasicNameValuePair("TIME_END", enddate));//结束时间
        String response = httpClientUtil.post(url, params, "UTF-8");
    
        HashMap<String, Integer> idcard_diseasecontion_map = new HashMap<>();
        if(StringUtils.isNotBlank(response)){
            JSONObject reobj =  JSON.parseObject(response);
    
        if (StringUtils.isNotBlank(response)) {
            JSONObject reobj = JSON.parseObject(response);
            Integer status = reobj.getInteger("status");
            String errmsg = reobj.getString("msg");
            if(200 == status){
            if (200 == status) {
                JSONObject jwData = reobj.getJSONObject("data");
                Integer jwCode = jwData.getInteger("CODE");
                if(1 == jwCode){
                if (1 == jwCode) {
                    JSONArray dataArray = jwData.getJSONArray("DATA");
                    for (int i = 0; i < dataArray.size(); i++) {
                        JSONObject json = dataArray.getJSONObject(i);
                        String idcard = json.getString("IDENTITY_CARD_NO");//身份证号码
                        Integer diseaseCondition = json.getInteger("SPECIALIST_CONTROL");//定标情况【 0 绿标 1 黄标 2 红标】
                        idcard_diseasecontion_map.put(idcard,diseaseCondition);
                        idcard_diseasecontion_map.put(idcard, diseaseCondition);
                    }
                    if(idcard_diseasecontion_map != null && !idcard_diseasecontion_map.keySet().isEmpty()){
                        logger.info("从基卫接口获取需要更新定标情况的慢病患者个数为"+idcard_diseasecontion_map.keySet().size());
    
                    if (idcard_diseasecontion_map != null && !idcard_diseasecontion_map.keySet().isEmpty()) {
                        logger.info("从基卫接口获取需要更新定标情况的慢病患者个数为" + idcard_diseasecontion_map.keySet().size());
                        patientService.updatePatientDiseascontionByIdcard(idcard_diseasecontion_map);
                    }else{
                        logger.info("从基卫接口获取需要更新定标情况的慢病患者个数为"+idcard_diseasecontion_map.keySet().size());
                    } else {
                        logger.info("从基卫接口获取需要更新定标情况的慢病患者个数为" + idcard_diseasecontion_map.keySet().size());
                    }
                }else{
                } else {
                    String jwMessage = jwData.getString("MESSAGE");
                    throw new Exception("获取慢病患者定标情况,请求基卫接口失败:"+jwMessage);
                    throw new Exception("获取慢病患者定标情况,请求基卫接口失败:" + jwMessage);
                }
            }else{
                throw new Exception("获取慢病患者定标情况请求失败,"+errmsg);
    
            } else {
                throw new Exception("获取慢病患者定标情况请求失败," + errmsg);
            }
        }else{
        } else {
            throw new Exception("获取慢病患者定标情况请求失败,无数据返回!");
        }
    }
    
    /**
     * 根据起止时间查询老年人体检记录,并同步到本地数据库
     *
     * @param startdate
     * @param enddate
     * @return
     */
    public void getOldPeoplePhysicalExaminationByTime(String startdate, String enddate)throws Exception {
    public void getOldPeoplePhysicalExaminationByTime(String startdate, String enddate) throws Exception {
        
        logger.info("查询老年人体检记录,开始时间"+startdate+",结束时间:"+enddate);
        logger.info("查询老年人体检记录,开始时间" + startdate + ",结束时间:" + enddate);
        
        
        String url = jwUrl + "/third/sign/getSickMedicalSimpleListInfo";
@ -309,14 +364,14 @@ public class JwPrescriptionService {
        //老年人体检记录列表
        List<OldPeoplePhysicalExaminationEntity> oldPeoplePhysicalExaminationEntities = new ArrayList<>();
        
        if(StringUtils.isNotBlank(response)){
            JSONObject reobj =  JSON.parseObject(response);
        if (StringUtils.isNotBlank(response)) {
            JSONObject reobj = JSON.parseObject(response);
            Integer status = reobj.getInteger("status");
            String errmsg = reobj.getString("msg");
            if(200 == status){
            if (200 == status) {
                JSONObject jwData = reobj.getJSONObject("data");
                Integer jwCode = jwData.getInteger("CODE");
                if(1 == jwCode){
                if (1 == jwCode) {
                    JSONArray dataArray = jwData.getJSONArray("DATA");
                    for (int i = 0; i < dataArray.size(); i++) {
    
@ -343,22 +398,641 @@ public class JwPrescriptionService {
                        oldPeoplePhysicalExaminationEntities.add(oldPeoplePhysicalExaminationEntity);
                    }
                    
                    if(!oldPeoplePhysicalExaminationEntities.isEmpty()){
                        logger.info("从基卫接口获取老年人体检记录数为"+oldPeoplePhysicalExaminationEntities.size());
                    if (!oldPeoplePhysicalExaminationEntities.isEmpty()) {
                        logger.info("从基卫接口获取老年人体检记录数为" + oldPeoplePhysicalExaminationEntities.size());
                        oldPeoplePhysicalExaminationDao.save(oldPeoplePhysicalExaminationEntities);
                    }else{
                        logger.info("从基卫接口获取老年人体检记录数个数为"+oldPeoplePhysicalExaminationEntities.size());
                    } else {
                        logger.info("从基卫接口获取老年人体检记录数个数为" + oldPeoplePhysicalExaminationEntities.size());
                    }
                }else{
                } else {
                    String jwMessage = jwData.getString("MESSAGE");
                    throw new Exception("从基卫接口获取老年人体检记,请求基卫接口失败:"+jwMessage);
                    throw new Exception("从基卫接口获取老年人体检记,请求基卫接口失败:" + jwMessage);
                }
                
            }else{
                throw new Exception("从基卫接口获取老年人体检记请求失败,"+errmsg);
            } else {
                throw new Exception("从基卫接口获取老年人体检记请求失败," + errmsg);
            }
        }else{
        } else {
            throw new Exception("从基卫接口获取老年人体检记请求失败,无数据返回!");
        }
    }
    
    /**
     * 根据起止时间查询居民随访记录,并同步到本地
     *
     * @param startdate
     * @param enddate
     * @return
     */
    public void getFollowUpByTime(String startdate, String enddate) throws Exception {
    
        logger.info("查询居民随访记录,开始时间" + startdate + ",结束时间:" + enddate);
    
        String url = jwUrl + "/third/sign/getEhrChroDaysFollowUpInfoRecord";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("TIME_START", startdate));//开始时间
        params.add(new BasicNameValuePair("TIME_END", enddate));//结束时间
        String response = httpClientUtil.post(url, params, "UTF-8");
    
        //居民随访记录
        List<Followup> followups = new ArrayList<>();
    
        if (StringUtils.isNotBlank(response)) {
            JSONObject reobj = JSON.parseObject(response);
            Integer status = reobj.getInteger("status");
            String errmsg = reobj.getString("msg");
            if (200 == status) {
                JSONObject jwData = reobj.getJSONObject("data");
                Integer jwCode = jwData.getInteger("CODE");
                if (1 == jwCode) {
                    JSONArray dataArray = jwData.getJSONArray("DATA");
                    for (int i = 0; i < dataArray.size(); i++) {
                        Followup followup = new Followup();
    
                        JSONObject json = dataArray.getJSONObject(i);
    
                        SignFamily sign = null;
    
                        //随访主表信息
                        String isNewCreate = json.getString("IS_NEW_CREATE");//是否新增
                        String followupNo = json.getString("FOLLOWUP_NO");//随访编号【基卫】:家庭医生服务随访主表ID
                        String dataFrom = json.getString("FOLLOWUP_SOURCE");//随访来源 1.平台端 2.移动端 3.第三方健康之路(移动端)"
                        
                        if ("0".equals(isNewCreate) || "3".equals(dataFrom)) {//修改
                            followup = followUpDao.findByFollowupNo(followupNo);
                            if (followup == null) {
                                followup.setFollowupNo(followupNo);
                            }
                        }
                        
                        if ("1".equals(dataFrom) || "2".equals(dataFrom)) {
                            followup.setDataFrom("1");
                        } else if ("3".equals(dataFrom)) {
                            followup.setDataFrom("2");
                        }
                        followup.setDataFrom(dataFrom);
                        
                        String followupDate = json.getString("THIS_FOLLOWUP_VISIT_DATE");//随访时间:此次随访时间
                        followup.setFollowupDate(DateUtil.strToDate(followupDate));
                        String followupPlanDate = "";//随访计划时间
                        String followupNextDate = json.getString("NEXT_FOLLOWUP_DATE");//计划下次随访时间:下次随访时间
                        followup.setFollowupNextDate(DateUtil.strToDate(followupNextDate));
    
                        /******************* 医生机构映射 ****************/
    
                        String orgCode = json.getString("ORG_CODE");//机构编码
                        followup.setOrgCode(orgCode);
                        String jwdoctorCode = json.getString("FOLLOWUP_VISIT_DOCTOR_NAME");//基卫医生CODE:随访医生 基卫系统的随访医生ID
                        followup.setJwdoctorCode(jwdoctorCode);
                        //医院映射
                        HospitalMapping hm = hospitalMappingDao.getCodeByMapping(orgCode, "1");
                        if (hm == null) {
                            logger.info("no mapping hospital:" + orgCode);
                            continue;
                        }
                        //医生映射
                        Doctor doctor = doctorDao.findMappingDoctor(jwdoctorCode, orgCode);
                        if (doctor == null) {
                            logger.info("no mapping hospital:" + orgCode + ",familyDoctor:" + jwdoctorCode);
                            continue;
                        }
                        
                        String doctorCode = doctor.getCode();//医生CODE
                        String doctorName = doctor.getName();//医生姓名 "FOLLOWUP_VISIT_DOCTOR_NAME_N":"随访医生 基卫系统的随访医生中文名"
                        String orgName = hm.getName();//机构名称
                        followup.setDoctorCode(doctorCode);
                        followup.setDoctorName(doctorName);
                        followup.setOrgName(orgName);
                        
                        String idcard = json.getString("IDENTITY_CARD_NO");//患者身份证
                        Patient patient = patientDao.findByIdcard(idcard);
                        String patientCode = patient.getCode();//患者CODE
                        String patientName = patient.getName();//患者姓名
                        followup.setIdcard(idcard);
                        followup.setPatientCode(patientCode);
                        followup.setPatientName(patientName);
    
                        String followupStatus = "1";//状态 0取消 1已完成 2未开始 3进行中 *基卫没有状态字段,传递过来的默认都是已完成的*
                        String followupContentPhone = "";//电话随访内容 -------
                        String followupManagerStatus = "";//随访管理状态【字典FOLLOWUP_MANAGER_STATUS】-------
                        String followupClass = json.getString("FAMILY_FOLLOWUP_CLASS_NAMES");//随访类别【1.高血压 2.糖尿病】
    
                        if (followupClass.contains("高血压") && followupClass.contains("糖尿病")) {
                            followupClass = "1,2";
                        }else if(followupClass.contains("高血压")){
                            followupClass= "1";
                        }else if(followupClass.contains("糖尿病")){
                            followupClass= "2";
                        }else{}
                        
                        String visitWayCode = json.getString("VISIT_WAY_CODE");//随访来源 1.门诊,2.家庭,3.电话,4.健康小屋
                        String creater = doctor.getCode();//创建者
                        followup.setStatus(followupStatus);
                        followup.setFollowupClass(followupClass);
                        followup.setFollowupType(visitWayCode);
                        followup.setCreater(creater);
    
                        //判断是否存在
                        sign = signFamilyDao.findByIdcard(idcard);
                        //判断是否存在签约修改身份证情况
                        if (sign == null) {
                            logger.info("no sign familyy patient idcard:" + idcard);
                            continue;
                        }
                        Integer signType = Integer.parseInt(sign.getSignSource());//签约类型 1三师 2家庭
                        Long adminTeamCode = new Long(sign.getAdminTeamId());//行政团队
                        String signCode = sign.getCode();//签约表Code
                        followup.setAdminTeamCode(adminTeamCode);
                        followup.setSignCode(signCode);
                        
                        //随访记录详
                        HashMap<String, String> followupContent1 = new HashMap<>();
                        HashMap<String, String> followupContent2 = new HashMap<>();
                        HashMap<String, String> followupContent3 = new HashMap<>();
                        HashMap<String, String> followupContent4 = new HashMap<>();
                        HashMap<String, String> followupContent5 = new HashMap<>();
                        HashMap<String, String> followupContent6 = new HashMap<>();
                        HashMap<String, String> followupContent7 = new HashMap<>();
                        HashMap<String, String> followupContent8 = new HashMap<>();
                        HashMap<String, String> followupContent9 = new HashMap<>();
                        HashMap<String, String> followupContent10 = new HashMap<>();
                        
                        //症状
                        followupContent1.put("NO_SYMPTOM", json.getString("NO_SYMPTOM"));//无症状【0.无 1.有】
                        followupContent1.put("HEADACHE", json.getString("HEADACHE"));//头痛头晕【0.无 1.有】
                        followupContent1.put("NAUSEA", json.getString("NAUSEA"));//恶心呕吐【0.无 1.有】
                        followupContent1.put("VERTIGO_TINNITUS", json.getString("VERTIGO_TINNITUS"));//眼花耳鸣【0.无 1.有】
                        followupContent1.put("DIFFICULTY_BREATHING", json.getString("DIFFICULTY_BREATHING"));//呼吸困难【0.无 1.有】
                        followupContent1.put("PALPITATIONS", json.getString("PALPITATIONS"));//心悸胸闷【0.无 1.有】
                        followupContent1.put("EPISTAXIS_BLEEDING", json.getString("EPISTAXIS_BLEEDING"));//鼻衄出血不止【0.无 1.有】
                        followupContent1.put("LIMBS_NUMB", json.getString("LIMBS_NUMB"));//四肢发麻【0.无 1.有】
                        followupContent1.put("EXTREMITY_EDEMA", json.getString("EXTREMITY_EDEMA"));//下肢水肿【0.无 1.有】
                        followupContent1.put("SYMPTOM_OTHER", json.getString("SYMPTOM_OTHER"));//"其他症状"
                        followupContent1.put("POLYDIPSIA", json.getString("POLYDIPSIA"));//多饮【0.无 1.有】
                        followupContent1.put("MORE_FOOD", json.getString("MORE_FOOD"));//多食【0.无 1.有】
                        followupContent1.put("MORE_URINE", json.getString("MORE_URINE"));//多尿【0.无 1.有】
                        followupContent1.put("BLURRED_VISION", json.getString("BLURRED_VISION"));//视力模糊【0.无 1.有】
                        followupContent1.put("INFECTION", json.getString("INFECTION"));//感染【0.无 1.有】
                        followupContent1.put("NUMB_HANDS", json.getString("NUMB_HANDS"));//手脚麻木【0.无 1.有】
                        followupContent1.put("WEIGHT_LOSS", json.getString("WEIGHT_LOSS"));//体重明显下降【0.无 1.有】
                        followupContent1.put("HYPOG_REACT_CODE", json.getString("HYPOG_REACT_CODE"));//低血糖反应【0.无;1.偶尔;2.频繁;】
                        
                        //体征信息
                        followupContent2.put("HEIGHT", json.getString("HEIGHT"));//身高
                        followupContent2.put("HEIGHT_EXP", json.getString("HEIGHT_EXP"));//期望身高
                        followupContent2.put("WEIGHT", json.getString("WEIGHT"));//体重
                        followupContent2.put("WEIGHT_EXP", json.getString("WEIGHT_EXP"));//期望体重
                        followupContent2.put("BP_D", json.getString("BP_D"));//舒张压
                        followupContent2.put("BP_U", json.getString("BP_U"));//收缩压
                        followupContent2.put("BS_FPG", json.getString("BS_FPG"));//空腹血糖
                        followupContent2.put("NO_BS_FPG", json.getString("NO_BS_FPG"));//餐后血糖
                        followupContent2.put("RANDOM_BLOOD_SUGAR", json.getString("RANDOM_BLOOD_SUGAR"));//随机血糖
                        followupContent2.put("BMI", json.getString("BMI"));//体质指数
                        followupContent2.put("BMI_EXP", json.getString("BMI_EXP"));//期望体质
                        followupContent2.put("OTHER_POSITIVE_SIGNS", json.getString("OTHER_POSITIVE_SIGNS"));//体征其他
                        followupContent2.put("POFDA_MARK", json.getString("POFDA_MARK"));//足背动脉搏动【TOUCH_DICT】
                        followupContent2.put("HEART_RATE", json.getString("HEART_RATE"));//心率
                        
                        //检查室检查
                        followupContent3.put("GHB", json.getString("GHB"));//糖化血红蛋白
                        followupContent3.put("RENAL_FUNCTION_CREATININE", json.getString("RENAL_FUNCTION_CREATININE"));//血清肌酐
                        followupContent3.put("RENAL_FUNCTION_BUN", json.getString("RENAL_FUNCTION_BUN"));//血尿素氮
                        followupContent3.put("MICROALBUMINURIA", json.getString("MICROALBUMINURIA"));//尿微量白蛋白
                        followupContent3.put("EXAM_DATE", json.getString("EXAM_DATE"));//检查日期
                        followupContent3.put("BLOOD_FAT_TRIGLYCERIDE", json.getString("BLOOD_FAT_TRIGLYCERIDE"));//甘油三酯 V01
                        followupContent3.put("BLOOD_FAT_TC", json.getString("BLOOD_FAT_TC"));//总胆固醇 V02
                        followupContent3.put("BLOOD_FAT_LDLC", json.getString("BLOOD_FAT_LDLC"));//血清低密度脂蛋白胆固醇 V03
    
                        //生活方式
                        followupContent4.put("DAILY_SMOKING", json.getString("DAILY_SMOKING"));//日吸烟量
                        followupContent4.put("SOMKING_EXP", json.getString("SOMKING_EXP"));//日吸烟期望
                        followupContent4.put("DAILY_DRINKING", json.getString("DAILY_DRINKING"));//日饮酒量
                        followupContent4.put("DRINK_EXP", json.getString("DRINK_EXP"));//日饮酒期望
                        followupContent4.put("EXERCISE_FREQ_CODE", json.getString("EXERCISE_FREQ_CODE"));//运动频率【HYGIENE_SPORT_FREQ_DICT】
                        followupContent4.put("EXERCISE_FREQ_CODE_EXP", json.getString("EXERCISE_FREQ_CODE_EXP"));//运动频率期望【HYGIENE_SPORT_FREQ_DICT】
                        followupContent4.put("EXERCISE_DURATION_MINS", json.getString("EXERCISE_DURATION_MINS"));//运动时长(min) 分钟/次
                        followupContent4.put("EXERCISE_DURATION_MINS_EXP", json.getString("EXERCISE_DURATION_MINS_EXP"));//运动时长期望(min) 分钟/次期望
                        followupContent4.put("SALT_TAKEN_LEVEL_CODE", json.getString("SALT_TAKEN_LEVEL_CODE"));//摄盐情况【LIGHT_WEIGHT_DICT】
                        followupContent4.put("SALT_TAKEN_LEVEL_EXP", json.getString("SALT_TAKEN_LEVEL_EXP"));//摄盐情况期望【LIGHT_WEIGHT_DICT】
                        followupContent4.put("PSY_ADJUST_RESULT_CODE", json.getString("PSY_ADJUST_RESULT_CODE"));//心里调整【GOOD_FAIR_POOR_DICT】
                        followupContent4.put("COMPLIANCE_RESULT_CODE", json.getString("COMPLIANCE_RESULT_CODE"));//遵医行为【GOOD_FAIR_POOR_DICT】
                        followupContent4.put("DAILY_STAPLE", json.getString("DAILY_STAPLE"));//主食(克/天)
                        
                        //随访评价
                        followupContent5.put("HYP_FOLLOWUP_TYPE_CODE", json.getString("HYP_FOLLOWUP_TYPE_CODE"));//高血压随访分类【FOLLOW_TYPE_DICT】
                        followupContent5.put("HYP_COMPLICATION_DETAIL", json.getString("HYP_COMPLICATION_DETAIL"));//高血压随访分类--详情
                        followupContent5.put("DIA_FOLLOWUP_TYPE_CODE", json.getString("DIA_FOLLOWUP_TYPE_CODE"));//糖尿病随访分类【FOLLOW_TYPE_DICT】
                        followupContent5.put("DIA_COMPLICATION_DETAIL", json.getString("DIA_COMPLICATION_DETAIL"));//糖尿病随访分类--详情
    
                        //用药情况
                        followupContent6.put("DRUG_COMPLIANCE_CODE", json.getString("DRUG_COMPLIANCE_CODE"));//服药依从性【DRUG_STATE_DICT】
                        
                        //控制目标
                        followupContent7.put("CONTROL_DATE", json.getString("CONTROL_DATE"));//控制日期 V04
                        followupContent7.put("CONTROL_CONSTITUTOR", json.getString("CONTROL_CONSTITUTOR"));//制定者 V05
                        followupContent7.put("CONTROL_BP_U", json.getString("CONTROL_BP_U"));//血压收缩压 V06
                        followupContent7.put("CONTROL_BP_D", json.getString("CONTROL_BP_D"));//血压舒张压 V07
                        followupContent7.put("CONTROL_BS_FPG", json.getString("CONTROL_BS_FPG"));//空腹血糖 V08
                        followupContent7.put("CONTROL_NO_BS_FPG", json.getString("CONTROL_NO_BS_FPG"));//餐后血糖 V09
                        followupContent7.put("CONTROL_GHB", json.getString("CONTROL_GHB"));//糖化血红蛋白 V10
                        followupContent7.put("CONTROL_TRIGLYCERIDE", json.getString("CONTROL_TRIGLYCERIDE"));//甘油三酯 V11
                        followupContent7.put("CONTROL_TOTAL_CHOLESTEROL", json.getString("CONTROL_TOTAL_CHOLESTEROL"));//总胆固醇 V12
                        followupContent7.put("CONTROL_LDL", json.getString("CONTROL_LDL"));//低密度脂蛋白 V13
                        followupContent7.put("CONTROL_WEIGHT", json.getString("CONTROL_WEIGHT"));//体重 V14
                        followupContent7.put("CONTROL_EXERCISE_FREQ_CODE", json.getString("CONTROL_EXERCISE_FREQ_CODE"));//运动频率 V15
                        followupContent7.put("CONTROL_EXERCISE_DURATION_MINS", json.getString("CONTROL_EXERCISE_DURATION_MINS"));//运动时长 V16
                        
                        //健康教育
                        followupContent8.put("ARCHIVE_TIME", json.getString("ARCHIVE_TIME"));//健康教育日期 V17
                        followupContent8.put("ARCHIVE_OPERATOR_NAME", json.getString("ARCHIVE_OPERATOR_NAME"));//健康教育记录者 基卫系统医生【传中文名称】 V18
                        followupContent8.put("HEALTH_EDUCATE", json.getString("HEALTH_EDUCATE"));//健康教育【CHRO_HEALTH_EDUCATE_DICT】 V19
                        followupContent8.put("EDUCATE_CONTENT", json.getString("EDUCATE_CONTENT"));//健康教育内容 V20
    
                        //转诊
                        followupContent9.put("DRUG_ADVERSE_MARK", json.getString("DRUG_ADVERSE_MARK"));//药物不良反应【0.无;1.有;】
                        followupContent9.put("ADR_REMARK", json.getString("ADR_REMARK"));//药物不良反应【内容】
                        followupContent9.put("TRANSFER_RESON", json.getString("TRANSFER_RESON"));//转诊原因
                        followupContent9.put("TRANSFER_ORG_DEPT", json.getString("TRANSFER_ORG_DEPT"));//转诊机构科室
                        followupContent9.put("REFUSE_REFERRAL", json.getString("REFUSE_REFERRAL"));//患者拒绝转诊【0 否 1 是】
                        followupContent9.put("REFUSE_REFERRAL_WHY", json.getString("REFUSE_REFERRAL_WHY"));//患者拒绝转诊内容
    
                        //多余字段
                        followupContent10.put("ARCHIVE_ID", json.getString("ARCHIVE_ID"));//档案ID
                        followupContent10.put("CHECK_FEE_TYPE", json.getString("CHECK_FEE_TYPE"));//检测费用类型
                        followupContent10.put("FAMILY_FOLLOWUP_ID", json.getString("FAMILY_FOLLOWUP_ID"));//随访细表外键随访ID
    
                        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
                        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别,开启新事务
                        TransactionStatus transactionStatus = transactionManager.getTransaction(def); // 获得事务状态
                        try {
                            followup = followUpDao.save(followup);
                            Long followupId = followup.getId();
                            //删除原有记录
                            followupContentDao.deleteByFollowupId(followup.getId());
                            //组装数据
                            List<FollowupContent> newList = new ArrayList<>();
    
                            followupContent1.forEach((k, v) -> {
                                FollowupContent item = new FollowupContent();
                                item.setFollowupId(followupId);
                                item.setFollowupProject("1");
                                item.setFollowupKey(k);
                                item.setFollowupValue(v);
                                item.setCreateTime(new Date());
                                newList.add(item);
                            });
    
                            followupContent2.forEach((k, v) -> {
                                FollowupContent item = new FollowupContent();
                                item.setFollowupId(followupId);
                                item.setFollowupProject("2");
                                item.setFollowupKey(k);
                                item.setFollowupValue(v);
                                item.setCreateTime(new Date());
                                newList.add(item);
                            });
    
                            followupContent3.forEach((k, v) -> {
                                FollowupContent item = new FollowupContent();
                                item.setFollowupId(followupId);
                                item.setFollowupProject("3");
                                item.setFollowupKey(k);
                                item.setFollowupValue(v);
                                item.setCreateTime(new Date());
                                newList.add(item);
                            });
    
                            followupContent4.forEach((k, v) -> {
                                FollowupContent item = new FollowupContent();
                                item.setFollowupId(followupId);
                                item.setFollowupProject("4");
                                item.setFollowupKey(k);
                                item.setFollowupValue(v);
                                item.setCreateTime(new Date());
                                newList.add(item);
                            });
    
                            followupContent5.forEach((k, v) -> {
                                FollowupContent item = new FollowupContent();
                                item.setFollowupId(followupId);
                                item.setFollowupProject("5");
                                item.setFollowupKey(k);
                                item.setFollowupValue(v);
                                item.setCreateTime(new Date());
                                newList.add(item);
                            });
    
                            followupContent6.forEach((k, v) -> {
                                FollowupContent item = new FollowupContent();
                                item.setFollowupId(followupId);
                                item.setFollowupProject("6");
                                item.setFollowupKey(k);
                                item.setFollowupValue(v);
                                item.setCreateTime(new Date());
                                newList.add(item);
                            });
    
                            followupContent7.forEach((k, v) -> {
                                FollowupContent item = new FollowupContent();
                                item.setFollowupId(followupId);
                                item.setFollowupProject("7");
                                item.setFollowupKey(k);
                                item.setFollowupValue(v);
                                item.setCreateTime(new Date());
                                newList.add(item);
                            });
    
                            followupContent8.forEach((k, v) -> {
                                FollowupContent item = new FollowupContent();
                                item.setFollowupId(followupId);
                                item.setFollowupProject("8");
                                item.setFollowupKey(k);
                                item.setFollowupValue(v);
                                item.setCreateTime(new Date());
                                newList.add(item);
                            });
    
                            followupContent9.forEach((k, v) -> {
                                FollowupContent item = new FollowupContent();
                                item.setFollowupId(followupId);
                                item.setFollowupProject("9");
                                item.setFollowupKey(k);
                                item.setFollowupValue(v);
                                item.setCreateTime(new Date());
                                newList.add(item);
                            });
    
                            followupContent10.forEach((k, v) -> {
                                FollowupContent item = new FollowupContent();
                                item.setFollowupId(followupId);
                                item.setFollowupProject("10");
                                item.setFollowupKey(k);
                                item.setFollowupValue(v);
                                item.setCreateTime(new Date());
                                newList.add(item);
                            });
    
                            followupContentDao.save(newList);
    
                            List<FollowupDrugs> DRUG_LIST = new ArrayList<>();//用药记录
    
                            for (int j = 1; j < 7; j++) {
                                if (json.containsKey("PHYSIC_NAME" + j)) {
                                    FollowupDrugs drug = new FollowupDrugs();
                                    drug.setFollowupId(followupId);
                                    drug.setDrugsGroup("normal");
                                    drug.setDrugsCode("");
                                    drug.setDrugsName(json.getString("PHYSIC_NAME" + j));//药物名称
                                    drug.setDose(Double.valueOf(json.getString("PHYSIC_DOSE" + j)));//剂量
                                    drug.setUnit(json.getString("PHYSIC_UNIT" + j));//单位【MEASURE_UNIT_DICT】
                                    drug.setFrequency(json.getString("FREQUENCY" + j));//频次【RECIPE_FREQUENCY_DICT】
                                    drug.setCreateTime(new Date());
                                    DRUG_LIST.add(drug);
                                }
                            }
    
                            for (int k = 1; k < 4; k++) {
                                if (json.containsKey("PHYSIC_NAME" + k)) {
                                    FollowupDrugs drug = new FollowupDrugs();
                                    drug.setFollowupId(followupId);
                                    drug.setDrugsGroup("insulin");
                                    drug.setDrugsCode("");
                                    drug.setDrugsName(json.getString("INSULIN_NAME" + k));//胰岛素药物名称
                                    drug.setDose(Double.valueOf(json.getString("INSULIN_DOSE" + k)));//胰岛素剂量
                                    drug.setUnit(json.getString("INSULIN_UNIT" + k));//v单位【MEASURE_UNIT_DICT】
                                    drug.setFrequency(json.getString("INSULIN_FREQUENCY" + k));//胰岛素频次【RECIPE_FREQUENCY_DICT】
                                    drug.setCreateTime(new Date());
                                    DRUG_LIST.add(drug);
                                }
                            }
                            //删除原有用药记录
                            followupDrugsDao.deleteByFollowupId(followupId);
                            followupDrugsDao.save(DRUG_LIST);
                            
                            transactionManager.commit(transactionStatus);
                        } catch (Exception ex) {
                            logger.info("同步随访信息报错,errmessage:" + ex.toString());
                            transactionManager.rollback(transactionStatus);
                            continue;
                        }
                    }
                } else {
                    String jwMessage = jwData.getString("MESSAGE");
                    throw new Exception("同步随访信息报错接口失败:" + jwMessage);
                }
    
            } else {
                throw new Exception("同步随访信息报错请求失败," + errmsg);
            }
        } else {
            throw new Exception("同步随访信息报错请求失败,无数据返回!");
        }
    }
    
    /**
     * 上传居民随访记录到基卫
     */
    public void uploadFollowUpRecordToJW() throws Exception {
        //查找出需要上传的随访映射记录
        List<Followup> followupMappings = followUpDao.findByFollowMappingNeedUpload(1);
        
        if (!followupMappings.isEmpty()) {
            logger.info("需要上传的的随访记录数:" + followupMappings.size());
            for (Followup followup : followupMappings) {
                try {
                    //随访信息详情
                    JSONObject jsonObject = new JSONObject();
                    //组装请求结果MAP
                    HashMap<String,String> followupResultMap = new HashMap<>();
                    
                    List<FollowupContent> followupContents = followupContentDao.findByFollowupId(followup.getId());
                    
                    for (FollowupContent followupContent : followupContents) {
                        followupResultMap.put(followupContent.getFollowupKey(), followupContent.getFollowupValue());
                    }
                    
                    String OPERATOR = followup.getJwdoctorCode();//操作员&录入医生
                    if (StringUtils.isBlank(OPERATOR)) {
                        OPERATOR = doctorMappingDao.findByDocotrCodeAndJwDoctorHospital(followup.getDoctorCode(), followup.getOrgCode());
                    }
                    followupResultMap.put("OPERATOR",OPERATOR);
                    
                    String FOLLOWUP_ID = followup.getFollowupNo();//家庭医生服务随访主表ID
                    if (StringUtils.isBlank(FOLLOWUP_ID)) {
                        FOLLOWUP_ID = "0";
                    }
                    followupResultMap.put("FOLLOWUP_ID",FOLLOWUP_ID);
                    
                    String FAMILY_FOLLOWUP_TYPE = "3";//随访类型,必传值3 【必填】
                    String ORG_CODE = followup.getOrgCode();//机构编码
                    String FOLLOWUP_SOURCE = "3";//健康之路移动端
                    String IDENTITY_CARD_NO = followup.getIdcard();
                    String FAMILY_FOLLOWUP_CLASS_NAMES = followup.getFollowupClass();
                    if ("1".equals(FAMILY_FOLLOWUP_CLASS_NAMES)) {
                        FAMILY_FOLLOWUP_CLASS_NAMES = "高血压";
                    } else if ("2".equals(FAMILY_FOLLOWUP_CLASS_NAMES)) {
                        FAMILY_FOLLOWUP_CLASS_NAMES = "糖尿病";
                    } else if ("1,2".equals(FAMILY_FOLLOWUP_CLASS_NAMES)) {
                        FAMILY_FOLLOWUP_CLASS_NAMES = "高血压,糖尿病";
                    } else {}
    
                    followupResultMap.put("FAMILY_FOLLOWUP_TYPE",FAMILY_FOLLOWUP_TYPE);
                    followupResultMap.put("ORG_CODE",ORG_CODE);
                    followupResultMap.put("FOLLOWUP_SOURCE",FOLLOWUP_SOURCE);
                    followupResultMap.put("IDENTITY_CARD_NO",IDENTITY_CARD_NO);
                    followupResultMap.put("FAMILY_FOLLOWUP_CLASS_NAMES",FAMILY_FOLLOWUP_CLASS_NAMES);
                    
                    
                    String THIS_FOLLOWUP_VISIT_DATE = DateUtil.dateToStr(followup.getFollowupDate(), DateUtil.YYYY_MM_DD_HH_MM_SS);
                    String NEXT_FOLLOWUP_DATE = DateUtil.dateToStr(followup.getFollowupPlanDate(), DateUtil.YYYY_MM_DD_HH_MM_SS);
                    String VISIT_WAY_CODE = followup.getFollowupType();//随访方式【FOLLOWUP_WAY_DICT】【必填】
    
                    followupResultMap.put("THIS_FOLLOWUP_VISIT_DATE",THIS_FOLLOWUP_VISIT_DATE);
                    followupResultMap.put("NEXT_FOLLOWUP_DATE",NEXT_FOLLOWUP_DATE);
                    followupResultMap.put("VISIT_WAY_CODE",VISIT_WAY_CODE);
                    
                    String ARCHIVE_ID = "";//档案ID
                    if (followupResultMap.containsKey("ARCHIVE_ID")) {
                        ARCHIVE_ID = followupResultMap.get("ARCHIVE_ID");
                    }
                    
                    if(StringUtils.isBlank(ARCHIVE_ID) || "0".equals(ARCHIVE_ID)){
                        //通过接口请求
                        ARCHIVE_ID = this.getSickArchiveFlag(IDENTITY_CARD_NO);
                        followupResultMap.put("ARCHIVE_ID",ARCHIVE_ID);
                    }
                    List<FollowupDrugs> followupDrugs = followupDrugsDao.findByFollowupId(followup.getId());
                    List<FollowupDrugs> followupDrugsNormal = new ArrayList<>();//其他药品
                    List<FollowupDrugs> followupDrugsInsulin = new ArrayList<>();//胰岛素
    
                    for (FollowupDrugs drugs : followupDrugs) {
                        if("insulin".equals(drugs.getDrugsGroup()) || "474A3255574347758ABE7BC00223F14A".equals(drugs.getDrugsGroup())){
                            followupDrugsInsulin.add(drugs);
                        }else{
                            followupDrugsNormal.add(drugs);
                        }
                    }
                    
                    if(followupDrugsNormal.size() >6 || followupDrugsInsulin.size() >3){
                        logger.info("随访记录上传失败,普通药品或者胰岛素类药瓶超过了上线,随访主表ID:" + followup.getId().toString());
                        continue;
                    }
    
                    DecimalFormat df = new DecimalFormat("######0.00");
    
                    //普通药品
                    if(!followupDrugsNormal.isEmpty()){
                        for (int i = 0; i < followupDrugsNormal.size(); i++) {
                            int tag = i+1;
                            followupResultMap.put("PHYSIC_NAME"+tag,followupDrugsNormal.get(i).getDrugsName());
                            followupResultMap.put("FREQUENCY"+tag,followupDrugsNormal.get(i).getFrequency());
                            followupResultMap.put("PHYSIC_UNIT"+tag,followupDrugsNormal.get(i).getUnit());
                            followupResultMap.put("PHYSIC_DOSE"+tag,df.format(followupDrugsNormal.get(i).getDose()));
                        }
                    }
    
                    //胰岛素类药品
                    if(!followupDrugsInsulin.isEmpty()){
                        for (int  j= 0; j < followupDrugsInsulin.size(); j++) {
                            int tag = j+1;
                            followupResultMap.put("PHYSIC_NAME"+tag,followupDrugsInsulin.get(j).getDrugsName());
                            followupResultMap.put("FREQUENCY"+tag,followupDrugsInsulin.get(j).getFrequency());
                            followupResultMap.put("PHYSIC_UNIT"+tag,followupDrugsInsulin.get(j).getUnit());
                            followupResultMap.put("PHYSIC_DOSE"+tag,df.format(followupDrugsInsulin.get(j).getDose()));
                        }
                    }
    
                    jsonObject = JSONObject.parseObject(JSON.toJSONString(followupResultMap));
                    
                    String url = jwUrl + "/third/archives/uploadEhrSickChroDaysFollowUpRecord";
    
                    List<NameValuePair> params = new ArrayList<>();
                    params.add(new BasicNameValuePair("OPERATOR", OPERATOR));
                    params.add(new BasicNameValuePair("data", jsonObject.toString()));
                    String response = httpClientUtil.post(url, params, "UTF-8");
    
                    if (StringUtils.isNotBlank(response)) {
                        JSONObject reobj = JSON.parseObject(response);
                        Integer status = reobj.getInteger("status");
                        String errmsg = reobj.getString("msg");
                        if (200 == status) {
                            JSONObject jwData = reobj.getJSONObject("data");
                            Integer jwCode = jwData.getInteger("CODE");
                            if (1 == jwCode) {
                                JSONArray dataArray = jwData.getJSONArray("DATA");
                                for (int i = 0; i < dataArray.size(); i++) {
                    
                                    OldPeoplePhysicalExaminationEntity oldPeoplePhysicalExaminationEntity = new OldPeoplePhysicalExaminationEntity();
                    
                                    JSONObject json = dataArray.getJSONObject(i);
                                    
                                    String jw_followup_no = json.getString("FOLLOWUP_NO");
    
                                    followup.setFollowupNo(jw_followup_no);
    
                                    followUpDao.save(followup);//获取的基卫随访主表ID,更新回数据库
                                }
                                
                            } else {
                                String jwMessage = jwData.getString("MESSAGE");
                                logger.info("随访记录上传失败,普通药品或者胰岛素类药瓶超过了上线,随访主表ID:" + followup.getId().toString()+",err:"+jwMessage);
                                continue;
                            }
            
                        } else {
                            logger.info("随访记录上传失败,普通药品或者胰岛素类药瓶超过了上线,随访主表ID:" + followup.getId().toString()+",err:请求失败");
                            continue;
                        }
                    } else {
                        logger.info("随访记录上传失败,普通药品或者胰岛素类药瓶超过了上线,随访主表ID:" + followup.getId().toString()+",无返回值");
                        continue;
                    }
                } catch (Exception e) {
                    logger.info("随访记录上传失败,普通药品或者胰岛素类药瓶超过了上线,随访主表ID:" + followup.getId().toString()+",err"+e.getMessage());
                    continue;
                }
            }
        }
    }
    
    /**
     *  查询居民是否有建立健康档案接口
     */
    public String getSickArchiveFlag(String idcard)  throws Exception {
        String re = "0";//0 未建档,非0为档案号
        String url = jwUrl + "/third/sign/uploadEhrSickChroDaysFollowUpRecord";
        
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("idcard", idcard));
        String response = httpClientUtil.post(url, params, "UTF-8");
        
        if(!StringUtils.isEmpty(response))
        {
            org.json.JSONObject json = new org.json.JSONObject(response);
            if (!"200".equals(json.optString("status"))) {
                throw new Exception(json.optString("msg"));
            }else{
                String dataStr = json.getString("data");
                if(!StringUtils.isEmpty(dataStr)){
                    org.json.JSONObject data = new org.json.JSONObject(dataStr);
                    if("1".equals(data.optString("CODE")))
                    {
                        org.json.JSONArray jsonArray = data.getJSONArray("DATA");
                        re = jsonArray.getJSONObject(0).getString("ARCHIVE_ID");
                    }
                    else{
                        throw new Exception(json.optString("MESSAGE"));
                    }
                }else{
                    throw new Exception("返回结果为空!");
                }
            }
        }
        else{
            throw new Exception("返回结果为空!");
        }
        
        return re;
    }
}

+ 53 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/web/quota/JobController.java

@ -606,4 +606,57 @@ public class JobController extends BaseController {
            return error(-1, e.getMessage());
        }
    }
    /**
     *根据时间范围同步居民随访记录
     *@author huangwenjie
     *@date 2017/10/23 08:45
     */
    @RequestMapping(value = "/executeFollowUpSynByTime", method = RequestMethod.POST)
    @ApiOperation("根据时间范围同步居民随访记录")
    public String executeFollowUpSynByTime(
            @ApiParam(name="startdate", value="开始时间:yyyy-mm-dd")
            @RequestParam(value = "startdate",required = true) String startdate,
            @ApiParam(name="enddate", value="结束时间:yyyy-mm-dd")
            @RequestParam(value = "enddate",required = true) String enddate) {
        try {
            String start = "";
            String end = "";
            do{
                start = startdate + " 00:00:00";
                end = startdate + " 23:59:59";
                //根据时间范围同步居民随访记录
                jwPrescriptionService.getFollowUpByTime(start,end);
                startdate = DateUtil.getNextDay(startdate,1);
            }while (!startdate.equals(enddate));
            return write(200, "执行成功");
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
    }
    /**
     *老年人体检系统发送提醒,每天早上8点执行一次
     *@author Reece
     *@date 2017/10/23 13:37
     */
    @RequestMapping(value = "/executePatientPhysicalExaminationJob", method = RequestMethod.POST)
    @ApiOperation("定期体检,系统定时提醒")
    public String executePatientPhysicalExaminationJob() {
        try {
            quartzHelper.startNow(PatientPhysicalExaminationJob.class, "PATIENT_PHYSICAL_EXAMINATION_JOB", null);
            return write(200, "启动成功");
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
    }
}

+ 8 - 1
patient-co/patient-co-wlyy-job/src/main/resources/system.properties

@ -96,7 +96,7 @@ zy_execute_sick_settle_job=0 0/3 * * * ?
prescription_pay_query_job=0 0/3 * * * ?
#居民24小时未回复的咨询自动关闭 每小时59分开始执行一次
finish_consult_job=* 59 * * * ?
finish_consult_job=0 59 * * * ?
#提醒有监测方案的居民上传数据,每29分钟执行一次
doctor_feldsher_template_job=0 0/29 * * * ?
@ -113,6 +113,13 @@ onepay_query_job=0 0/3 * * * ?
# 老年人体检记录同步,每天凌晨1点执行一次
old_people_tijian_syb_job=0 0 1 * * ?
# 老年人体检记录同步,每天凌晨1点执行一次
patient_followup_syb_job=0 0 3 * * ?
# 老年人体检系统发送提醒记录,每天8点执行一次
#patient_physical_examination_job=0 0 8 * * ?
patient_physical_examination_job=0 0/10 * * * ?
#统一支付平台支付成功后页面跳转地址
return_url={server}/wx/html/qygl/html/pay_result.html
#统一支付平台支付接口地址

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientDao.java

@ -69,7 +69,7 @@ public interface PatientDao extends PagingAndSortingRepository<Patient, Long> {
    @Query(value=" select p.* from wlyy_patient p LEFT JOIN wlyy_sign_family s on s.patient = p.code WHERE s.status > 0  and p.disease >0 and p.status>0 and s.admin_team_code = ?1 and (s.doctor = ?2 or s.doctor_health =?2)",nativeQuery = true)
    List<Patient> findAllSignPatientTeamcode(String teamcode, String  doctorcode);
    @Query(value="SELECT DISTINCT t.*FROM wlyy_sign_family t1,wlyy_patient t WHERE t.`code`=t1.patient AND t1.STATUS>0 AND " +
    @Query(value="SELECT DISTINCT t.* FROM wlyy_sign_family t1,wlyy_patient t WHERE t.`code`=t1.patient AND t1.STATUS>0 AND " +
            " t1.admin_team_code= ?1 AND(YEAR(curdate())-IF(length(t.idcard)=18,substring(t.idcard,7,4),IF(length(t.idcard)=15,concat('19',substring(t.idcard,7,2)),NULL)))>65 " +
            " AND t1.idcard NOT IN(SELECT DISTINCT s.idcard FROM wlyy_sign_family s,wlyy_old_people_physical_examination o WHERE s.admin_team_code=?1 AND s.`status`>0 AND s.idcard=o.id_card " +
            " AND o.medical_time>?2 )ORDER BY t1.openid DESC,CONVERT(t1.NAME USING gbk)",nativeQuery = true)

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

@ -119,8 +119,22 @@ public class FollowUpService extends BaseService {
        re.put("followupTypeName", followupTypeName);
        //随访类别转译
        re.put("followupClass", followup.getFollowupClass());
        
        String followupClass = followup.getFollowupClass();
        re.put("followupClass", followupClass);
    
        String followupClassName = systemDictService.getDictValue("FOLLOWUP_CLASS_DICT", followup.getFollowupClass());
        if(followupClass.contains(",")){
            String[] followupClassArray = followupClass.split(",");
            followupClassName = "";
            for (int i = 0; i < followupClassArray.length; i++) {
                followupClassName += systemDictService.getDictValue("FOLLOWUP_CLASS_DICT", followupClassArray[i]);
                if(i != followupClassArray.length -1){
                    followupClassName +=",";
                }
            }
        }
        
        re.put("followupClassName", followupClassName);
        //随访管理状态转译
@ -187,17 +201,17 @@ public class FollowUpService extends BaseService {
     * @param type 类型:0全部,1计划,2记录
     * @return
     */
    public JSONArray getListByPatientAndTeam(String patient, Long teamCode, int page, int pageSize, int type) {
    public JSONArray getListByPatientAndTeam(String patient, Long teamCode, int page, int pageSize, String type) {
        Sort sort = new Sort(Sort.Direction.DESC,"createTime");
        PageRequest pageRequest = new PageRequest(page, pageSize,sort);
        Page<Object> result = null;
        
        if(type == 0){
        if(StringUtils.isBlank(type)){
            result = followupDao.findByPatientAndTeam(patient, teamCode, pageRequest);
        }else if(type == 1){
        }else if("1".equals(type)){
            //已经开始的就是记录
            result = followupDao.findPlanByPatientAndTeam(patient, teamCode, pageRequest);
        }else if(type == 2){
        }else if("2".equals(type)){
            //未开始的就是计划
            result = followupDao.findRecordByPatientAndTeam(patient, teamCode, pageRequest);
        }else{}
@ -245,7 +259,22 @@ public class FollowUpService extends BaseService {
                followup.put("followupType", objArr[3] == null ? "" : objArr[3]);
                followup.put("followupTypeName", objArr[3] == null ? "" : (dictMap.get(objArr[3].toString()) != null ? dictMap.get(objArr[3].toString()) : ""));
                followup.put("followupClass", objArr[4] == null ? "" : objArr[4]);
                followup.put("followupClassName", objArr[4] == null ? "" : (objArr[4].toString().equals("1") ? "高血压" : "糖尿病"));
    
//                followup.put("followupClassName", objArr[4] == null ? "" : (objArr[4].toString().equals("1") ? "高血压" : "糖尿病"));
               
                if( objArr[4] == null){
                    followup.put("followupClassName", "");
                }else{
                    if(objArr[4].toString().equals("1")){
                        followup.put("followupClassName", "高血压");
                    }else if(objArr[4].toString().equals("1")){
                        followup.put("followupClassName", "糖尿病");
                    }else if(objArr[4].toString().equals("1,2")){
                        followup.put("followupClassName", "高血压,糖尿病");
                    }else{}
                }
                
                
                followup.put("status", objArr[5] == null ? "" : objArr[5]);
                followup.put("statusName", objArr[5] == null ? "" : (statusMap.get(objArr[5].toString()) != null ? statusMap.get(objArr[5].toString()) : ""));
                followup.put("createTime", objArr[6] != null ? DateUtil.dateToStrLong((Date)objArr[6]) : "");
@ -370,10 +399,14 @@ public class FollowUpService extends BaseService {
    /**
     * 开始随访记录
     */
    public void startFollowup(String id, String date, String followupType, String followupClass, String followupManagerStatus) throws Exception {
    public void startFollowup(String id, String date, String followupType, String followupClass, String followupManagerStatus,String plandate) throws Exception {
        Followup followup = followupDao.findOne(Long.valueOf(id));
        if (followup != null) {
            followup.setFollowupDate(DateUtil.strToDate(date));
            //计划下次随访时间--huangwenjie.2017.10.19
            if(StringUtils.isNoneBlank(plandate)){
                followup.setFollowupNextDate(DateUtil.strToDate(plandate));
            }
            followup.setFollowupType(followupType);
            followup.setFollowupClass(followupClass);
            followup.setFollowupManagerStatus(followupManagerStatus);

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

@ -29,7 +29,6 @@ import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
@ -664,14 +663,14 @@ public class PatientHealthIndexService extends BaseService {
            String value1 = data.getValue1();
            // 餐后
            if (index % 2 == 0) {
                if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueBefore, minValueBefore)) {
                if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueAfter, minValueAfter)) {
                    msgContent += patient.getName() + "血糖异常(" + value1 + "mmol/L)";
                    //体征异常,更新体征数据状态
                    data.setStatus(1);
                    patientHealthIndexDao.save(data);
                }
            } else { //餐前
                if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueAfter, minValueAfter)) {
                if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueBefore,minValueBefore)) {
                    msgContent += patient.getName() + "血糖异常(" + value1 + "mmol/L)";
                    data.setStatus(1);
                    patientHealthIndexDao.save(data);
@ -1463,8 +1462,12 @@ public class PatientHealthIndexService extends BaseService {
                } else if (type == 3) //体重
                {
                    String weight = item.getValue1();   //体重
                    String height = item.getValue2();   //身高
                    String bmi = item.getValue3();      //BMI
                    map.put("time", DateUtil.dateToStrShort(item.getRecordDate()));
                    map.put("weight", weight);
                    map.put("height", height);
                    map.put("bmi", bmi);
                    map.put("text", weight + " kg");
                    re.add(map);
                }

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/message/MessageService.java

@ -297,7 +297,7 @@ public class MessageService extends BaseService {
     */
    public List<Map<String, Object>> getHealthIndexMessage(String doctor) throws Exception {
        List<Map<String, Object>> re = new ArrayList<>();
        String sql = "select a.sender,a.tz_type,count(1) count,max(date_format(a.create_time,'%Y-%c-%d %H:%i:%s')) last_time,a.has_read from wlyy_Message a where a.receiver='" + doctor + "' and a.type='2' group by a.sender,a.tz_type,a.has_read order by last_time desc";
        String sql = "select a.sender,a.tz_type,count(1) count,max(date_format(a.create_time,'%Y-%m-%d %H:%i:%s')) last_time,a.has_read from wlyy_Message a where a.receiver='" + doctor + "' and a.type='2' group by a.sender,a.tz_type,a.has_read order by last_time desc";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        Map<String,Map<String, Object>> map = new HashMap<>();

+ 1 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/physicalExamination/PhysicalExamTeamRemindService.java

@ -48,6 +48,7 @@ public class PhysicalExamTeamRemindService extends BaseService{
        Doctor d = doctorDao.findByCode(doctor);
        try {
            //在方法上加@Async注解 这个方法就成异步方法了            异步方法不能和调用方法放在一个类里面
            remindService.sendBatchNotice(teamCode, d.getName(), record.getId());
        } catch (Exception e) {
            e.printStackTrace();

+ 44 - 13
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/physicalExamination/PhysicalExaminationRemindService.java

@ -84,6 +84,19 @@ public class PhysicalExaminationRemindService extends BaseService {
        return 0;
    }
    /**
     * 是否7天内提醒过居民
     * @param patient
     * @return
     */
    public Integer isRemind(String patient){
        List<PatientRemindRecords> records = patientRemindRecordsDao.findByPatientAndType(patient, 1);
        if (records != null && records.size() > 0) {
            return 1;
        }
        return 0;
    }
    /**
     * 健康体检 是否显示批量提醒按钮
     *
@ -322,11 +335,13 @@ public class PhysicalExaminationRemindService extends BaseService {
        String mobile = patient.getMobile();
        Boolean flag = true;
        // 推送消息给微信端
        String url = "huanzhe/html/jiankangtijian.html?openid=" + patient.getOpenid() +"&toUser="+patient.getCode()+"&toName=" + patient.getName();
        String first = "您的家庭医生" + doctName + "提醒,您可以到签约社区进行免费的健康体检啦~";
        JSONObject json = new org.json.JSONObject();
        json.put("first", "您的家庭医生" + doctName + "提醒,您可以到签约社区进行免费的健康体检啦~");
        json.put("first",first);
        json.put("url",url);
        json.put("keyword1", "健康体检");
        json.put("keyword2", format.format(new Date()));
        json.put("url", "");
        json.put("remark", "为了您和您的家庭医生了解您近期的健康状况,请及时到您签约的社区体检哟~");
        if (StringUtils.isNotBlank(patient.getOpenid())) {
            pushMsgTask.putWxMsg(accessToken, 11, patient.getOpenid(), patient.getName(), json);
@ -338,11 +353,14 @@ public class PhysicalExaminationRemindService extends BaseService {
            for (int i = 0; i < jsonArray.length(); i++) {
                org.json.JSONObject j = jsonArray.getJSONObject(i);
                Patient member = (Patient) j.get("member");
                json.remove("toUser");
                json.put("toUser", member.getCode());
                int start = url.indexOf("&toUser=");
                int end = url.indexOf("&", start + 1);
                String touser = url.substring(start, end);
                url = url.replace(touser, "&toUser=" + member.getCode());
                json.remove("first");
                try {
                    json.put("first", openIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName()));
                    json.put("first", openIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName())+first);
                    json.put("url", url);
                } catch (Exception e) {
                    e.printStackTrace();
                }
@ -354,7 +372,7 @@ public class PhysicalExaminationRemindService extends BaseService {
        }
//        微信发送失败发送短信
        if (flag && StringUtils.isNotEmpty(mobile)) {
            smsService.sendMsg(mobile, "您的家庭医生" + doctName + "提醒,您可以到签约社区进行免费的健康体检啦~");
            smsService.sendMsg(mobile, "厦门i健康家庭医生温馨提醒,您已经超过一年没有到社区进行健康体检啦,为了您和您的家庭医生了解您近期的健康状况,请及时到签约社区进行免费的健康体检");
        }
        //保存发送提醒
@ -381,15 +399,25 @@ public class PhysicalExaminationRemindService extends BaseService {
        Boolean flag = true;
        // 推送消息给微信端
        JSONObject json = new org.json.JSONObject();
        json.put("first", "您的家庭医生" + doctName + "提醒,您可以到签约社区进行免费的健康体检啦~");
        json.put("keyword1", "健康体检");
        json.put("keyword2", format.format(new Date()));
        json.put("url", "");
        json.put("remark", "为了您和您的家庭医生了解您近期的健康状况,请及时到您签约的社区体检哟~");
        List<Patient> patients = patientDao.findExaminationRemind(teamId, new Date());
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.YEAR, -1);
        Date yesteryear = c.getTime();
        List<Patient> patients = patientDao.findExaminationRemind(teamId, yesteryear);
        for (Patient patient : patients) {
            String url = "huanzhe/html/jiankangtijian.html?openid=" + patient.getOpenid() +"&toUser="+patient.getCode()+"&toName=" + patient.getName();
            String first = "您的家庭医生" + doctName + "提醒,您可以到签约社区进行免费的健康体检啦~";
            json.put("first",first);
            json.put("url",url);
            String mobile = patient.getMobile();
            List<PatientRemindRecords> records = patientRemindRecordsDao.findByPatientAndType(patient.getCode(), 1);
            if (records != null && records.size() > 0) {
                continue;
            }
            if (StringUtils.isNotBlank(patient.getOpenid())) {
                pushMsgTask.putWxMsg(accessToken, 11, patient.getOpenid(), patient.getName(), json);
                flag = false;
@ -400,11 +428,14 @@ public class PhysicalExaminationRemindService extends BaseService {
                for (int i = 0; i < jsonArray.length(); i++) {
                    org.json.JSONObject j = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    json.remove("toUser");
                    json.put("toUser", member.getCode());
                    int start = url.indexOf("&toUser=");
                    int end = url.indexOf("&", start + 1);
                    String touser = url.substring(start, end);
                    url = url.replace(touser, "&toUser=" + member.getCode());
                    json.remove("first");
                    try {
                        json.put("first", openIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName()));
                        json.put("first", openIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName())+first);
                        json.put("url", url);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
@ -416,7 +447,7 @@ public class PhysicalExaminationRemindService extends BaseService {
            }
            //        微信发送失败发送短信
            if (flag && StringUtils.isNotEmpty(mobile)) {
                smsService.sendMsg(mobile, "您的家庭医生" + doctName + "提醒,您可以到签约社区进行免费的健康体检啦~");
                smsService.sendMsg(mobile, "厦门i健康家庭医生温馨提醒,您已经超过一年没有到社区进行健康体检啦,为了您和您的家庭医生了解您近期的健康状况,请及时到签约社区进行免费的健康体检");
            }
            flag = true;
            //保存发送提醒

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

@ -361,25 +361,43 @@ public class PrescriptionInfoService extends BaseService {
                //过滤病症
                if(StringUtils.isNotBlank(diagnosisCode)&&!"0".equals(diagnosisCode)){
                    String dis = gxy;
                    if("1".equals(diagnosisCode)){
                        dis = gxy;
                    }else if("2".equals(diagnosisCode)){
                        dis = tnb;
                    }
                    boolean flag = false;
                    for (int j = 0; j < des.size(); j++) {
                        PrescriptionDiagnosis ds = des.getObject(j, PrescriptionDiagnosis.class);
                        //如果含有选择病症,标记为true
                        if (dis.equals(ds.getHealthProblem())) {
                            //含有选择的病症
                            flag = true;
                    //高血压或者糖尿病
                    if("3".equals(diagnosisCode)){
                        for (int j = 0; j < des.size(); j++) {
                            PrescriptionDiagnosis ds = des.getObject(j, PrescriptionDiagnosis.class);
                            //如果含有选择病症,标记为true
                            if (gxy.equals(ds.getHealthProblem()) || tnb.equals(ds.getHealthProblem())) {
                                //含有选择的病症
                                flag = true;
                            }
                        }
                        //如果未含有选择的病症,则删除
                        if (!flag){
                            continue;
                        }
                    }else{
                        String dis = gxy;
                        if("1".equals(diagnosisCode)){
                            //高血压
                            dis = gxy;
                        }else if("2".equals(diagnosisCode)){
                            //糖尿病
                            dis = tnb;
                        }
    
                        for (int j = 0; j < des.size(); j++) {
                            PrescriptionDiagnosis ds = des.getObject(j, PrescriptionDiagnosis.class);
                            //如果含有选择病症,标记为true
                            if (dis.equals(ds.getHealthProblem())) {
                                //含有选择的病症
                                flag = true;
                            }
                        }
                        //如果未含有选择的病症,则删除
                        if (!flag){
                            continue;
                        }
                    }
                    //如果未含有选择的病症,则删除
                    if (!flag){
                        continue;
                    }
                }
                newtotalCount++;
@ -468,7 +486,7 @@ public class PrescriptionInfoService extends BaseService {
        return r;
    }
    public com.alibaba.fastjson.JSONObject getPrescriptionProcess(String code) {
    public com.alibaba.fastjson.JSONObject getPrescriptionProcess(String code) throws Exception{
        Prescription prescription = prescriptionDao.findByCode(code);
        List<PrescriptionInfo> prescriptionInfos = prescriptionInfoDao.findByPrescriptionCode(code);
        PrescriptionReviewed reviewed = prescriptionReviewedDao.findByPrescriptionCode(code);
@ -512,6 +530,22 @@ public class PrescriptionInfoService extends BaseService {
        } else {
            //rs.put("time","");
        }
        if(prescription.getStatus()==PrescriptionLog.PrescriptionLogStatus.wait_pay.getValue()){
            com.alibaba.fastjson.JSONObject object = new com.alibaba.fastjson.JSONObject();
            object = prescriptionService.checkRecipeNoPay(2,code);
            String status = object.getString("status");
            if("200".equals(status)){
                //-1操作失败 0新开 1待执行 5已执行 9作废 404没有找到对应的数据.
                String jwCode = object.getString("code");
                if("9".equals(jwCode)){
                    prescription.setStatus(PrescriptionLog.PrescriptionLogStatus.pay_cancle.getValue());
                }
                rs.put("jwStatus",object.getString("code"));
            }else{
            }
        }
        if (prescriptionAdjusts != null && prescriptionAdjusts.size() > 0) {
            rs.put("isAdjust", true);
        } else {

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

@ -427,9 +427,9 @@ public class PrescriptionService extends BaseService {
                    //如果基卫返回回来的处方状态为“作废”,code为9的时候,修改本地数据库
                    //处方状态为“线下取消”
                    if("9".equals(code)){
                        prescriptionDao.updateStatus(prescriptionCode,-5);
                        prescriptionDao.updateStatus(prescriptionCode,PrescriptionLog.PrescriptionLogStatus.pay_cancle.getValue());
                        statusObj.put("status",200);
                        statusObj.put("code",200);
                        statusObj.put("code",9);
                        statusObj.put("message","基卫处方为作废,已修改本地数据库该处方为线下取消");
                    }else{
                        statusObj.put("status",200);
@ -441,7 +441,7 @@ public class PrescriptionService extends BaseService {
                statusObj.put("status",404);
                statusObj.put("message","没有找到相应的结果");
            }else{
                statusObj.put("status",0);
                statusObj.put("status",-1);
                statusObj.put("message","操作失败!");
            }
        }

+ 2 - 11
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsAllService.java

@ -2932,7 +2932,6 @@ public class StatisticsAllService extends BaseService {
        //自建结果集
        resultList = getLowLevelMapKey(level, low_level, area);
        if (resultList != null) {
            DecimalFormat df = new DecimalFormat("0.0000");
            //查询去年的签约转map
@ -2940,16 +2939,8 @@ public class StatisticsAllService extends BaseService {
            if(org.apache.commons.lang.StringUtils.isBlank(lowCode)){
                yearsYear = findQuotaResultList(lastDate, Integer.valueOf(low_level), "1");
            }else{
                if("3".equals(lowCode)){
                    //老年人
                    yearsYear = findQuotaResultsWithLevelType1AndLevelType2(lastDate,Integer.valueOf(low_level),"17","3");
                }else if("4".equals(lowCode)){
                    //高血压
                    yearsYear = findQuotaResultsWithLevelType1AndLevelType2(lastDate,Integer.valueOf(low_level),"17","1");
                }else if("5".equals(lowCode)){
                    //糖尿病
                    yearsYear = findQuotaResultsWithLevelType1AndLevelType2(lastDate,Integer.valueOf(low_level),"17","2");
                }else{}
                //老年人、高血压、糖尿病
                yearsYear = findQuotaResultsWithLevelType1AndLevelType2(lastDate,Integer.valueOf(low_level),"17",lowCode);
            }
            
            Map<String, WlyyQuotaResult> resultMap = new HashMap<>();

+ 565 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsService.java

@ -4196,7 +4196,7 @@ public class StatisticsService extends BaseService {
        
        String rediscode = code;
        
        //如果服务类型维度code(老年人3,高血压4,糖尿病5)不为空,则rediscode默认带上lowcode
        //如果服务类型维度code(老年人3,高血压1,糖尿病2)不为空,则rediscode默认带上lowcode
        if(StringUtils.isNoneBlank(lowCode)){
            rediscode = rediscode + ":"+lowCode;
        }
@ -5476,7 +5476,7 @@ public class StatisticsService extends BaseService {
    public String setLevelAndDisSql2(String sql,String disease,String level,String area){
        if(StringUtils.isNotBlank(disease)){
            sql += " JOIN wlyy_prescription_diagnosis d ON d.prescription_code = t.prescription_code ";
            sql += " JOIN wlyy_prescription_diagnosis d ON d.prescription_code = p.code ";
        }
        if("4".equals(level)){
            sql +=" WHERE 1=1  ";
@ -6100,5 +6100,568 @@ public class StatisticsService extends BaseService {
        }
        return rs;
    }
    public List<Map<String,Object>> getPrescriptionAgeTotal(String level,String area,String disease){
        String sql = "SELECT " +
                " ( " +
                "  SELECT " +
                "   count(1) 0age " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient ";
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   )>= 0 " +
                "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "   RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "  ) <= 6 " +
                " ) 0age, " +
                " ( " +
                "  SELECT " +
                "   count(1) 7age " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient ";
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   ) >= 7 " +
                "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "   RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "  ) <= 18 " +
                " ) 7age, " +
                " ( " +
                "  SELECT " +
                "   count(1) 19age " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient " ;
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  " AND  YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   ) >= 19 " +
                "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "   RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "  ) <= 30 " +
                " ) 19age, " +
                " ( " +
                "  SELECT " +
                "   count(1) 31age " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient " ;
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  " AND  YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   ) >= 31 " +
                "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "   RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "  ) <= 50 " +
                " ) 31age, " +
                " ( " +
                "  SELECT " +
                "   count(1) 51age " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient ";
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  " AND  YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   ) >= 51 " +
                "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "   RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "  ) <= 64 " +
                "  ) 51age, " +
                " ( " +
                "  SELECT " +
                "   count(1) 65age " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient " ;
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  " AND  YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   ) >= 65 " +
                "  ) 65age, " +
                "  ( " +
                "  SELECT " +
                "   count(1) total " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient " ;
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql += "  ) total";
        List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql);
        if(rs!=null&&rs.size()>0){
            Long age0 = (Long)rs.get(0).get("0age");
            Long age7 = (Long)rs.get(0).get("7age");
            Long age19 = (Long)rs.get(0).get("19age");
            Long age31 = (Long)rs.get(0).get("31age");
            Long age51 = (Long)rs.get(0).get("51age");
            Long age65 = (Long)rs.get(0).get("65age");
            Long total = (Long)rs.get(0).get("total");
            rs.get(0).put("0ageRate",getAgeRate(age0,total));
            rs.get(0).put("7ageRate",getAgeRate(age7,total));
            rs.get(0).put("19ageRate",getAgeRate(age19,total));
            rs.get(0).put("31ageRate",getAgeRate(age31,total));
            rs.get(0).put("51ageRate",getAgeRate(age51,total));
            rs.get(0).put("65ageRate",getAgeRate(age65,total));
        }
        return rs;
    }
    public String getAgeRate(Long age,Long total){
        if(total!=null&&total!=0){
            float ageRate0 = age.floatValue()/total.floatValue()*100;
            DecimalFormat decimalFormat=new DecimalFormat("0.00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
            String ageR0=decimalFormat.format(ageRate0)+"%";//format 返回的是字符串
            return ageR0;
        }
        return "0";
    }
    public String getAgeRateLine(Long age,Long total){
        if(total!=null&&total!=0){
            float ageRate0 = age.floatValue()/total.floatValue();
            DecimalFormat decimalFormat=new DecimalFormat("0.00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
            String ageR0=decimalFormat.format(ageRate0);//format 返回的是字符串
            return ageR0;
        }
        return "0";
    }
    public List<Map<String,Object>> getPrescriptionAgeHistogram(String level,String area,String disease,String startDate,String endDate){
        startDate += " 00:00:00";
        endDate += " 23:59:59";
        String sql ="SELECT " +
                " ( " +
                "  SELECT " +
                "   count(1) 0age " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient ";
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  " AND  YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   )>= 0 " +
                "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "   RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "  ) <= 6 " +
                "  AND p.create_time >='"+startDate+"'  " +
                "  AND p.create_time <='"+endDate+"' " +
                " ) 0age,( " +
                " SELECT " +
                " COUNT(c.patient)  " +
                " FROM " +
                " ( " +
                "  SELECT " +
                "    DISTINCT p.patient " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient ";
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  " AND  YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   )>= 0 " +
                "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "   RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "  ) <= 6 " +
                "  AND p.create_time >='"+startDate+"'  " +
                "  AND p.create_time <='"+endDate+"') c " +
                " ) 0people, " +
                " ( " +
                "  SELECT " +
                "   count(1) 7age " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient ";
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  " AND  YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   ) >= 7 " +
                "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "   RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "  ) <= 18 " +
                "  AND p.create_time >='"+startDate+"'  " +
                "  AND p.create_time <='"+endDate+"' " +
                " ) 7age,( " +
                " SELECT " +
                " COUNT(c.patient)  " +
                " FROM " +
                " ( " +
                "  SELECT " +
                "    DISTINCT p.patient " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient ";
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  " AND  YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   ) >= 7 " +
                "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "   RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "  ) <= 18 " +
                "  AND p.create_time >='"+startDate+"'  " +
                "  AND p.create_time <='"+endDate+"') c " +
                " ) 7people, " +
                " ( " +
                "  SELECT " +
                "   count(1) 19age " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient " ;
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  " AND  YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   ) >= 19 " +
                "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "   RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "  ) <= 30 " +
                "  AND p.create_time >='"+startDate+"'  " +
                "  AND p.create_time <='"+endDate+"' " +
                " ) 19age,( " +
                " SELECT " +
                " COUNT(c.patient)  " +
                " FROM " +
                " ( " +
                "  SELECT " +
                "    DISTINCT p.patient " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient " ;
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  " AND  YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   ) >= 19 " +
                "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "   RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "  ) <= 30 " +
                "  AND p.create_time >='"+startDate+"'  " +
                "  AND p.create_time <='"+endDate+"') c " +
                "  ) 19people, " +
                "  ( " +
                "  SELECT " +
                "   count(1) 31age " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient ";
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  " AND  YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   ) >= 31 " +
                "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "   RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "  ) <= 50 " +
                "  AND p.create_time >='"+startDate+"'  " +
                "  AND p.create_time <='"+endDate+"' " +
                " ) 31age,( " +
                " SELECT " +
                " COUNT(c.patient)  " +
                " FROM " +
                " ( " +
                "  SELECT " +
                "    DISTINCT p.patient " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient ";
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  " AND  YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   ) >= 31 " +
                "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "   RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "  ) <= 50 " +
                "  AND p.create_time >='"+startDate+"'  " +
                "  AND p.create_time <='"+endDate+"') c " +
                "  ) 31people, " +
                "  ( " +
                "  SELECT " +
                "   count(1) 51age " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient " ;
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  " AND  YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   ) >= 51 " +
                "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "   RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "  ) <= 64 " +
                "  AND p.create_time >='"+startDate+"'  " +
                "  AND p.create_time <='"+endDate+"' " +
                " ) 51age,( " +
                " SELECT " +
                " COUNT(c.patient)  " +
                " FROM " +
                " ( " +
                "  SELECT " +
                "    DISTINCT p.patient " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient ";
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  " AND  YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   ) >= 51 " +
                "  AND YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "   RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "  ) <= 64 " +
                "  AND p.create_time >='"+startDate+"'  " +
                "  AND p.create_time <='"+endDate+"') c " +
                " ) 51people, " +
                " ( " +
                "  SELECT " +
                "   count(1) 65age " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient ";
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  " AND  YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   ) >= 65 " +
                "  AND p.create_time >='"+startDate+"'  " +
                "  AND p.create_time <='"+endDate+"' " +
                " ) 65age,( " +
                " SELECT " +
                " COUNT(c.patient)  " +
                " FROM " +
                " ( " +
                "  SELECT " +
                "    DISTINCT p.patient " +
                "  FROM " +
                "   wlyy_prescription p " +
                "  JOIN wlyy_patient pt ON pt. CODE = p.patient ";
        sql = setLevelAndDisSql2(sql,disease,level,area);
        sql +=  " AND  YEAR (CURDATE()) - YEAR (birthday) - ( " +
                "    RIGHT (CURDATE(), 5) < RIGHT (birthday, 5) " +
                "   ) >= 65 " +
                "  AND p.create_time >='"+startDate+"'  " +
                "  AND p.create_time <='"+endDate+"') c " +
                " ) 65people";
        List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql);
        if(rs!=null&&rs.size()>0){
            Long age0 = (Long)rs.get(0).get("0age");
            Long age7 = (Long)rs.get(0).get("7age");
            Long age19 = (Long)rs.get(0).get("19age");
            Long age31 = (Long)rs.get(0).get("31age");
            Long age51 = (Long)rs.get(0).get("51age");
            Long age65 = (Long)rs.get(0).get("65age");
            Long people0 = (Long)rs.get(0).get("0people");
            Long people7 = (Long)rs.get(0).get("7people");
            Long people19 = (Long)rs.get(0).get("19people");
            Long people31 = (Long)rs.get(0).get("31people");
            Long people51 = (Long)rs.get(0).get("51people");
            Long people65= (Long)rs.get(0).get("65people");
            rs.get(0).put("0ageRate",getAgeRateLine(age0,people0));
            rs.get(0).put("7ageRate",getAgeRateLine(age7,people7));
            rs.get(0).put("19ageRate",getAgeRateLine(age19,people19));
            rs.get(0).put("31ageRate",getAgeRateLine(age31,people31));
            rs.get(0).put("51ageRate",getAgeRateLine(age51,people51));
            rs.get(0).put("65ageRate",getAgeRateLine(age65,people65));
        }
        return rs;
    }
    public List<Map<String,Object>> getPrescriptionAgeLowLevel(String level,String lowlevel,String area,String disease) {
        if("4".equals(level)){
            if("3".equals(lowlevel)){
                String sql = "SELECT " +
                        " tw.`code`, " +
                        " tw.`name`, " +
                        "  ifnull(c.total,0) num " +
                        " FROM " +
                        " dm_town tw LEFT JOIN ( " +
                        " SELECT " +
                        " count(1) total, " +
                        " LEFT(pp.hospital,6) code " +
                        " FROM " +
                        " ( " +
                        "  SELECT DISTINCT " +
                        "   p.patient, " +
                        "   p.admin_team_id, " +
                        "   p.hospital " +
                        "  FROM " +
                        "   wlyy_prescription p " ;
                sql = setDisSql( sql, disease);
                sql +=  " ) pp " +
                        " GROUP BY " +
                        " LEFT(pp.hospital,6) " +
                        " ) c ON c.code = tw.code " +
                        " WHERE " +
                        " tw.city = '350200' " +
                        "   ORDER BY num DESC ";
                List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql);
                return rs;
            }else if("2".equals(lowlevel)){
                String sql = "SELECT " +
                        " tw.`code`, " +
                        " tw.`name`, " +
                        "  ifnull(c.total,0) num " +
                        " FROM " +
                        " dm_hospital tw LEFT JOIN ( " +
                        " SELECT " +
                        " count(1) total, " +
                        " pp.hospital code " +
                        " FROM " +
                        " ( " +
                        "  SELECT DISTINCT " +
                        "   p.patient, " +
                        "   p.admin_team_id, " +
                        "   p.hospital " +
                        "  FROM " +
                        "   wlyy_prescription p ";
                sql = setDisSql(sql,disease);
                sql +=  " ) pp " +
                        " GROUP BY " +
                        " pp.hospital " +
                        " ) c ON c.code = tw.code " +
                        " WHERE " +
                        " tw.city = '350200' " +
                        " AND LENGTH(tw.code)=10 " +
                        " ORDER BY num DESC ";
                List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql);
                return rs;
            }else if("1".equals(lowlevel)){
                String sql ="SELECT " +
                        " tw.id code, " +
                        " tw.`name`, " +
                        "  ifnull(c.total,0) num " +
                        " FROM " +
                        " wlyy_admin_team tw LEFT JOIN ( " +
                        " SELECT " +
                        " count(1) total, " +
                        " pp.admin_team_id code " +
                        " FROM " +
                        " ( " +
                        "  SELECT DISTINCT " +
                        "   p.patient, " +
                        "   p.admin_team_id, " +
                        "   p.hospital " +
                        "  FROM " +
                        "   wlyy_prescription p ";
                sql = setDisSql(sql,disease);
                sql +=  " ) pp " +
                        " GROUP BY " +
                        " pp.admin_team_id " +
                        " ) c ON c.code = tw.id " +
                        " WHERE " +
                        " 1=1  " +
                        " ORDER BY num DESC ";
                List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql);
                statisticsAllService.translateTeamLeaderName2(rs);
                return rs;
            }
        }else if("3".equals(level)){
            if("2".equals(lowlevel)){
                String sql = "SELECT " +
                        " tw.`code`, " +
                        " tw.`name`, " +
                        "  ifnull(c.total,0) num " +
                        " FROM " +
                        " dm_hospital tw LEFT JOIN ( " +
                        " SELECT " +
                        " count(1) total, " +
                        " pp.hospital code " +
                        " FROM " +
                        " ( " +
                        "  SELECT DISTINCT " +
                        "   p.patient, " +
                        "   p.admin_team_id, " +
                        "   p.hospital " +
                        "  FROM " +
                        "   wlyy_prescription p ";
                sql = setDisSql(sql,disease);
                sql +=  " AND LEFT(p.hospital,6) ='"+area+"'" +
                        " ) pp " +
                        " GROUP BY " +
                        " pp.hospital " +
                        " ) c ON c.code = tw.code " +
                        " WHERE " +
                        " tw.city = '350200' " +
                        " AND tw.town ='"+area+"' " +
                        " AND LENGTH(tw.code)=10 " +
                        " ORDER BY num DESC ";
                List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql);
                return rs;
            }else if("1".equals(lowlevel)){
                String sql ="SELECT " +
                        " tw.id code, " +
                        " tw.`name`, " +
                        "  ifnull(c.total,0) num " +
                        " FROM " +
                        " wlyy_admin_team tw LEFT JOIN ( " +
                        " SELECT " +
                        " count(1) total, " +
                        " pp.admin_team_id code " +
                        " FROM " +
                        " ( " +
                        "  SELECT DISTINCT " +
                        "   p.patient, " +
                        "   p.admin_team_id, " +
                        "   p.hospital " +
                        "  FROM " +
                        "   wlyy_prescription p ";
                sql = setDisSql(sql,disease);
                sql +=  " AND LEFT(p.hospital,6) ='"+area+"'" +
                        ") pp " +
                        " GROUP BY " +
                        " pp.admin_team_id " +
                        " ) c ON c.code = tw.id " +
                        " WHERE " +
                        " 1=1  " +
                        " AND LEFT(tw.org_code,6) ='"+area+"' " +
                        " ORDER BY num DESC ";
                List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql);
                statisticsAllService.translateTeamLeaderName2(rs);
                return rs;
            }
        }else if("2".equals(level)){
            if("1".equals(lowlevel)){
                String sql ="SELECT " +
                        " tw.id code, " +
                        " tw.`name`, " +
                        "  ifnull(c.total,0) num " +
                        " FROM " +
                        " wlyy_admin_team tw LEFT JOIN ( " +
                        " SELECT " +
                        " count(1) total, " +
                        " pp.admin_team_id code " +
                        " FROM " +
                        " ( " +
                        "  SELECT DISTINCT " +
                        "   p.patient, " +
                        "   p.admin_team_id, " +
                        "   p.hospital " +
                        "  FROM " +
                        "   wlyy_prescription p ";
                sql = setDisSql(sql,disease);
                sql +=  " AND p.hospital ='"+area+"'" +
                        ") pp " +
                        " GROUP BY " +
                        " pp.admin_team_id " +
                        " ) c ON c.code = tw.id " +
                        " WHERE " +
                        " 1=1  " +
                        " AND tw.org_code ='"+area+"' " +
                        " ORDER BY num DESC ";
                List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql);
                statisticsAllService.translateTeamLeaderName2(rs);
                return rs;
            }
        }
        return null;
    }
}

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

@ -1923,11 +1923,11 @@ public class StatisticsESService {
        return resultMaps;
    }
    public JSONObject getRenewPercentAndChangePercent(Integer level, String area, String year, String lowCode) {
    public JSONObject getRenewPercentAndChangePercent(String index, Integer level, String area, String year, String lowCode) {
        JSONObject jo = new JSONObject();
        String switchIndex = "";//转签index
        String signIndex ="1";//签约index
        String renewIndex ="";//续签index
        String renewIndex =index;//续签index
        String date = year + "-06-30";
        try{
            if (level == 5) {
@ -1935,30 +1935,24 @@ public class StatisticsESService {
                if(StringUtils.isNoneBlank(lowCode)){
                    //服务类型维度
                    switchIndex = "55";
                    renewIndex = "52";
                }else{
                    switchIndex = "35";
                    renewIndex = "42";
                }
            } else if (level == 4) {
                //社区的转签
                if(StringUtils.isNoneBlank(lowCode)){
                    //服务类型维度
                    switchIndex = "56";
                    renewIndex = "53";
                }else{
                    switchIndex = "35";
                    renewIndex = "43";
                }
            } else {
                //区和市的转签
                if(StringUtils.isNoneBlank(lowCode)){
                    //服务类型维度
                    switchIndex = "57";
                    renewIndex = "54";
                }else{
                    switchIndex = "35";
                    renewIndex = "44";
                }
            }
            String timeKey = elasticsearchUtil.getQuotaTime();
@ -2184,8 +2178,125 @@ public class StatisticsESService {
            String preDate = new SimpleDateFormat("yyyy-MM-dd").format(today.getTime());
//            data = getTodayBeforeLowLevelTotalSingle(preDate, area, level, index);
        }
        return data;
    }
    /**
     * 去年的签约量,续签量和续签率 列表
     * @param area
     * @param level 等级 1(5):团队 2(4)社区机构 (3)3区级 4(2)市级
     * @param index
     * @param sort
     * @param lowLevel
     * @param year
     * @param lowCode
     * @return
     * @throws Exception
     */
    public JSONArray getLevelTwoLowLevelTotalSignAndRenew(String area, int level, String index, int sort, String lowLevel, String year, String lowCode) throws Exception {
        String lastDate = year + "-10-19";
        //String timeKey = elasticsearchUtil.getQuotaTime();
        String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level - 1) : lowLevel);
        List<Map<String, Object>> resultList = new ArrayList<>();//续签量
        Map<String, Integer> renewMap = new HashMap<>(); //续签的的列表转map
        List<SaveModel> renewSaveModels = new ArrayList<SaveModel>();
        List<SaveModel> signSaveModels = new ArrayList<SaveModel>();
        if (StringUtils.isEmpty(lowCode)) {
            //续签量
            renewSaveModels = elasticsearchUtil.findListDateQuotaLevel0(lastDate, area, level, index, "2", lowLevel);
        } else {
            //续签量
            renewSaveModels = elasticsearchUtil.findListDateQuotaLevel1(lastDate, area, level, index, "2", lowLevel, lowCode);
        }
        if (renewSaveModels != null && renewSaveModels.size() > 0) {
            for (SaveModel saveModel : renewSaveModels) {
                if ("3".equals(low_level)) {
                    renewMap.put(saveModel.getTown(), saveModel.getResult2());
                } else if ("4".equals(low_level)) {
                    renewMap.put(saveModel.getHospital(), saveModel.getResult2());
                } else if ("5".equals(low_level)) {
                    renewMap.put(saveModel.getTeam(), saveModel.getResult2());
                } else {
                    continue;
                }
            }
        }
        //自建结果集
        resultList = getLowLevelMapKey(level, low_level, area);
        return data;
        if (resultList != null) {
            DecimalFormat df = new DecimalFormat("0.0000");
            //查询去年的签约转map
            List<SaveModel> yearsList = new ArrayList();
            if (StringUtils.isBlank(lowCode)) {
                yearsList = elasticsearchUtil.findListDateQuotaLevel0(lastDate,"",Integer.valueOf(low_level),"1","2","");
            } else {
                if ("3".equals(lowCode)) {
                    //老年人
                    yearsList = elasticsearchUtil.findListDateQuotaLevel1(lastDate,"",Integer.valueOf(low_level),"17","2","","3");
                } else if ("4".equals(lowCode)) {
                    //高血压
                    yearsList = elasticsearchUtil.findListDateQuotaLevel1(lastDate,"",Integer.valueOf(low_level),"17","2","","1");
                } else if ("5".equals(lowCode)) {
                    //糖尿病
                    yearsList = elasticsearchUtil.findListDateQuotaLevel1(lastDate,"",Integer.valueOf(low_level),"17","2","","2");
                } else {
                }
            }
            Map<String, SaveModel> resultMap = new HashMap<>();
            yearsList.stream().forEach(one -> {
                if ("5".equals(low_level)) {
                    resultMap.put(one.getTeam(), one);
                } else if ("4".equals(low_level)) {
                    resultMap.put(one.getHospital(), one);
                } else if ("3".equals(low_level)) {
                    resultMap.put(one.getTown(), one);
                }
            });
            for (Map<String, Object> reMap : resultList) {
                reMap.put("amount", reMap.get("amount") != null ? Long.valueOf(reMap.get("amount").toString()) : 0L);
                //获取去年签约的人数 默认是上个年度的最后一天
                if((resultMap!=null && resultMap.size()>0)&&(renewMap!=null && renewMap.size()>0)){
                    SaveModel one = resultMap.get(reMap.get("code").toString());
                    int signNum = 0;
                    int renewNum = renewMap.get(reMap.get("code").toString());
                    if (one != null) {
                        signNum = Integer.valueOf(one.getResult2());
                    }
                    reMap.put("rate", getRange(renewNum, signNum, 2));//续签率是 续签量/去年的签约数
                    reMap.put("signNum", signNum);
                    reMap.put("renewNum", renewNum);
                }
            }
            if ((level == 4 && "1".equals(lowLevel)) || (level == 2) || (level == 3 && "1".equals(lowLevel))) {
                translateTeamLeaderName(resultList);
            }
            //对结果进行排序
            Collections.sort(resultList, new Comparator<Map<String, Object>>() {
                public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                    int map1value = (int) o1.get("renewNum");
                    int map2value = (int) o2.get("renewNum");
                    if (map1value - map2value > 0) {
                        return sort == 1 ? -1 : 1;
                    } else if (map1value - map2value < 0) {
                        return sort == 1 ? 1 : -1;
                    } else {
                        return 0;
                    }
                }
            });
            return new JSONArray(resultList);
        } else {
            return new JSONArray();
        }
    }
}

+ 12 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/jw/ZyDictService.java

@ -193,7 +193,7 @@ public class ZyDictService {
     * @param name
     * @return
     */
    public List<Map<String, Object>> findDictByDoctorAndName(String doctor,String name){
    public List<Map<String, Object>> findDictByDoctorAndName(String doctor,String name,String isinsulin){
        String sql = "SELECT  yp.physic_code drugCode, " +
                " yp.physic_name drugName, " +
                " yp.physic_spec drugFormat, " +
@ -255,6 +255,17 @@ public class ZyDictService {
                " AND com2.`code` = yp.quantity_unit " +
                " AND com3.`code` = yp.pack_unit " +
                " AND class.class_code = yp.subject_class";
        if(StringUtils.isNoneBlank(isinsulin)){
            
            String insulin = "胰岛素";
            
            if("1".equals(isinsulin)){
                sql+= " AND yp.physic_name not like '%"+insulin+"%' ";
            }
            if("2".equals(isinsulin)){
                sql+= " AND yp.physic_name like '%"+insulin+"%' and yp.subject_class like '%010%'";
            }
        }
//        subjectClass
//        drugNumUnit":"224","drugNumUnitName":"支",
//        physicDoseUnit":"224","physicDoseUnitName":"支",

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

@ -68,7 +68,7 @@ public class DoctorFollowUpController extends BaseController {
                                          @RequestParam @ApiParam(value = "团队code") Long teamCode,
                                          @RequestParam @ApiParam(value = "第几页") int page,
                                          @RequestParam @ApiParam(value = "页大小") int pagesize,
                                          @RequestParam(value = "type",required = false) @ApiParam(value = "类型:0全部,1计划,2记录",defaultValue = "0") int type) {
                                          @RequestParam(value = "type",required = false) @ApiParam(value = "类型:放空为全部,1计划,2记录",defaultValue = "0") String type) {
        try {
            if (StringUtils.isEmpty(patient)) {
                return error(-1, "请输入需查询的居民");
@ -162,9 +162,11 @@ public class DoctorFollowUpController extends BaseController {
                                @ApiParam(name = "followupClass", value = "随访类别【1.高血压 2.糖尿病】", defaultValue = "1")
                                @RequestParam(value = "followupClass", required = true) String followupClass,
                                @ApiParam(name = "followupManagerStatus", value = "随访管理状态【字典FOLLOWUP_MANAGER_STATUS】", defaultValue = "1")
                                @RequestParam(value = "followupManagerStatus", required = false) String followupManagerStatus) {
                                @RequestParam(value = "followupManagerStatus", required = false) String followupManagerStatus,
                                @ApiParam(name = "plandate", value = "下次随访时间", defaultValue = "2016-12-14 20:00:00")
                                @RequestParam(value = "plandate", required = false) String plandate) {
        try {
            followUpService.startFollowup(id, date, followupType, followupClass, followupManagerStatus);
            followUpService.startFollowup(id, date, followupType, followupClass, followupManagerStatus,plandate);
            return write(200, "开始随访记录成功!");
        } catch (Exception e) {

+ 17 - 16
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthGuidanceController.java

@ -197,23 +197,24 @@ public class DoctorHealthGuidanceController extends WeixinBaseController {
                Doctor doctor = doctorService.findDoctorByCode(getUID());
                if (images == null || "".equals(images)) {
                    images = null;
                } else {
                    String[] imgs = images.split(",");
                    for (String image : imgs) {
                        if (image.contains("http://")) {
                            imageUrls += image + ",";
                        } else {
                            try {
                                imageRow += CommonUtil.copyTempImage(image) + ",";
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                    images = imageUrls + imageRow;
                    images = images.substring(0, images.length() - 1);
                }
//                else {
//                    String[] imgs = images.split(",");
//                    for (String image : imgs) {
//                        if (image.contains("http://")) {
//                            imageUrls += image + ",";
//                        } else {
//                            try {
//                                imageRow += CommonUtil.copyTempImage(image) + ",";
//                            } catch (Exception e) {
//                                e.printStackTrace();
//                            }
//                        }
//                    }
//
//                    images = imageUrls + imageRow;
//                    images = images.substring(0, images.length() - 1);
//                }
                guidance.setImages(images);
                // 保存

+ 13 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/PyhsicExamRemindController.java

@ -92,4 +92,17 @@ public class PyhsicExamRemindController extends BaseController{
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value = "isRemind", method = RequestMethod.GET)
    @ApiOperation("7天内是否提醒过居民")
    public String isRemind(@ApiParam(name = "patient", value = "居民code", defaultValue = "644")
                                 @RequestParam(value = "patient", required = true) String patient){
        try {
            Integer re =  physicalExaminationRemindService.isRemind(patient);
            return write(200, "查询成功", "data", re);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
}

+ 31 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/prescription/PrescriptionInfoController.java

@ -56,7 +56,7 @@ public class PrescriptionInfoController extends BaseController {
                                      @RequestParam(required = false)@ApiParam(name="isRenewal",value="处方是否可续方:1.是;2.无过滤")String isRenewal,
                                      @RequestParam(required = false)@ApiParam(name="startDate",value="开始时间")String startDate,
                                      @RequestParam(required = false)@ApiParam(name="endDate",value="结束时间")String endDate,
                                      @RequestParam(required = false,defaultValue = "0")@ApiParam(name="diagnosisCode",value="所有诊断(0 全部 1高血压 2糖尿病)")String diagnosisCode,
                                      @RequestParam(required = false,defaultValue = "0")@ApiParam(name="diagnosisCode",value="所有诊断(0 全部 1高血压 2糖尿病 3高血压和糖尿病)")String diagnosisCode,
                                      @RequestParam(required = false)@ApiParam(name="page",value="起始页")Integer page,
                                      @RequestParam(required = false)@ApiParam(name="size",value="每页记录数")Integer size){
        try {
@ -67,6 +67,31 @@ public class PrescriptionInfoController extends BaseController {
            return error(-1, "查询失败!");
        }
    }
    
    /**
     * 获取长处方信息列表
     * @param type
     * @return
     */
    @RequestMapping(value = "/getPrescriptionInfos" , method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取长处方信息列表")
    public String getPrescriptionInfos(@RequestParam(required = true)@ApiParam(name="type",value="1:查询处方;2我的续方;3:续方记录")String type,
                                       @RequestParam(required = false)@ApiParam(name="isRenewal",value="处方是否可续方:1.是;2.无过滤")String isRenewal,
                                       @RequestParam(required = false)@ApiParam(name="recipeNo",value="医嘱号,第一次获取上一方时传入0,第二次获取上一方时传入第一次返回的医嘱号,以此类推")String recipeNo,
                                       @RequestParam(required = false)@ApiParam(name="startDate",value="开始时间")String startDate,
                                       @RequestParam(required = false)@ApiParam(name="endDate",value="结束时间")String endDate,
                                       @RequestParam(required = false,defaultValue = "0")@ApiParam(name="diagnosisCode",value="所有诊断(0 全部 1高血压 2糖尿病)")String diagnosisCode,
                                       @RequestParam(required = false)@ApiParam(name="page",value="起始页")Integer page,
                                       @RequestParam(required = false)@ApiParam(name="size",value="每页记录数")Integer size,
                                       @RequestParam(required = true)@ApiParam(name="patientCode",value="居民CODE")String patientCode){
        try {
            return write(200, "查询成功!", "data", prescriptionInfoService.getPrescriptionInfos(type,recipeNo,diagnosisCode,startDate,endDate,patientCode,isRenewal,page,size));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败!");
        }
    }
    @RequestMapping(value = "/getPrescriptionFilter", method = RequestMethod.GET)
    @ApiOperation(value = "获取过滤规则信息列表")
@ -170,10 +195,12 @@ public class PrescriptionInfoController extends BaseController {
    @RequestMapping(value = "/findDictByName", method = RequestMethod.GET)
    @ApiOperation(value = "药品列表")
    public String findDictByName(@ApiParam(name = "name", value = "药品名称(中文或拼音首字母查询)", defaultValue = "胰岛素")
                                 @RequestParam(value = "name", required = false) String name) {
                                 @RequestParam(value = "name", required = false) String name,
                                 @ApiParam(name = "isinsulin", value = "是否过滤胰岛素:1非胰岛素,2胰岛素", defaultValue = "")
                                 @RequestParam(value = "isinsulin", required = false) String isinsulin) {
        try {
//            return write(200, "操作成功!", "data",zyDictService.findDictByDoctorAndName("e3b3bfb3644011e69616fa163e424525",name));
            return write(200, "操作成功!", "data", zyDictService.findDictByDoctorAndName(getUID(), name));
//            return write(200, "操作成功!", "data",zyDictService.findDictByDoctorAndName("e3b3bfb3644011e69616fa163e424525",name,isinsulin));
            return write(200, "操作成功!", "data",zyDictService.findDictByDoctorAndName(getUID(), name,isinsulin));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败!");

+ 3 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/EsStatisticsController.java

@ -1458,7 +1458,7 @@ public class EsStatisticsController extends BaseController {
    @RequestMapping(value = "/getRenewPercentAndChangePercent", method = RequestMethod.GET)
    @ResponseBody
    public String getRenewPercentAndChangePercent(
            //@RequestParam(required = true) String index,//续签index
            @RequestParam(required = true) String index,//续签index
            @RequestParam(required = true) int level,
            @RequestParam(required = true) String area,
            @RequestParam(required = false) String year,
@ -1466,7 +1466,7 @@ public class EsStatisticsController extends BaseController {
        try {
            //return write(200, "查询成功", "data", statisticsService.getRenewPercentAndChangePercent(index,level, code, year,lowCode));
            return write(200,"查询成功!","data",statisticsESService.getRenewPercentAndChangePercent(elasticsearchUtil.changeLevel(level),area,year,lowCode));
            return write(200,"查询成功!","data",statisticsESService.getRenewPercentAndChangePercent(index,elasticsearchUtil.changeLevel(level),area,year,lowCode));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -1563,7 +1563,7 @@ public class EsStatisticsController extends BaseController {
                lowLevel = level - 1 + "";
            }
            result.put("index_" + index, statisticsESService.getLevelTwoLowLevelTotalSignAndRenew(area,elasticsearchUtil.changeLevel(level), index, sort, String.valueOf(elasticsearchUtil.changeLevel(Integer.valueOf(lowLevel))), year, lowCode));
//            result.put("index_" + index, statisticsAllService.getLevelTwoLowLevelTotalSignAndRenew(area, changeLevel(level), index, sort, String.valueOf(changeLevel(Integer.valueOf(lowLevel))), year, lowCode));
            return write(200, "查询成功", "data", result);

+ 48 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java

@ -1489,7 +1489,7 @@ public class StatisticsController extends BaseController {
     * @param level 等级  4 市  3区  2社区 1团队
     * @param code  市 默认是厦门市 350200  区 就是区的code  社区就是社区的code 团队就是团队的code.
     * @param year  年份 非比传
     * @param lowCode 服务类型维度code(老年人3,高血压4,糖尿病5)
     * @param lowCode 服务类型维度code(老年人3,高血压1,糖尿病2)
     * @return
     */
    @RequestMapping(value = "/getRenewPercentAndChangePercent", method = RequestMethod.GET)
@ -1594,6 +1594,7 @@ public class StatisticsController extends BaseController {
     */
    @RequestMapping("/lowlevel_all_sign_renew")
    @ResponseBody
    @Deprecated
    public String getIndexLowLevelTotalSignAndRenew(
            @RequestParam(required = true) String index,
            @RequestParam(required = true) String area,
@ -1803,4 +1804,50 @@ public class StatisticsController extends BaseController {
            return error(-1, "查询失败");
        }
    }
    @RequestMapping("/getPrescriptionAgeTotal")
    @ResponseBody
    @ApiOperation("年龄统计-上部总数图")
    public String  getPrescriptionAgeTotal(@ApiParam(name="level", value="级别") @RequestParam(required = true)String level,
                                           @ApiParam(name="area", value="级别编码") @RequestParam(required = true)String area,
                                           @ApiParam(name="disease", value="疾病") @RequestParam(required = false)String disease){
        try{
            return write(200, "查询成功", "data", statisticsService.getPrescriptionAgeTotal(level,area,disease));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
    @RequestMapping("/getPrescriptionAgeHistogram")
    @ResponseBody
    @ApiOperation("年龄统计-中部部条形图")
    public String getPrescriptionAgeHistogram(@ApiParam(name="level", value="级别") @RequestParam(required = true)String level,
                                              @ApiParam(name="area", value="级别编码") @RequestParam(required = true)String area,
                                              @ApiParam(name="disease", value="疾病") @RequestParam(required = false)String disease,
                                              @ApiParam(name="startDate", value="开始时间") @RequestParam(required = true)String startDate,
                                              @ApiParam(name="endDate", value="结束时间") @RequestParam(required = true)String endDate){
        try{
            return write(200, "查询成功", "data", statisticsService.getPrescriptionAgeHistogram(level,area,disease,startDate,endDate));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
    @RequestMapping("/getPrescriptionAgeLowLevel")
    @ResponseBody
    @ApiOperation("年龄统计-下部列表")
    public String getPrescriptionAgeLowLevel(@ApiParam(name="level", value="级别") @RequestParam(required = true)String level,
                                             @ApiParam(name="lowlevel", value="第二级别") @RequestParam(required = true)String lowlevel,
                                             @ApiParam(name="area", value="级别编码") @RequestParam(required = true)String area,
                                             @ApiParam(name="disease", value="疾病") @RequestParam(required = false)String disease){
        try{
            return write(200, "查询成功", "data", statisticsService.getPrescriptionAgeLowLevel(level,lowlevel,area,disease));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
}