Quellcode durchsuchen

Merge branch 'dev' of huangwenjie/patient-co-management into dev

huangwenjie vor 7 Jahren
Ursprung
Commit
54a04d45b7
30 geänderte Dateien mit 1500 neuen und 39 gelöschten Zeilen
  1. 139 0
      common/common-entity/src/main/java/com/yihu/es/entity/QuestionnaireWinningESDO.java
  2. 58 0
      common/common-entity/src/main/java/com/yihu/wlyy/entity/common/SystemProperties.java
  3. 183 0
      common/common-entity/src/main/java/com/yihu/wlyy/entity/imm/ChildImmuneRegisterRecord.java
  4. 2 0
      common/common-entity/src/main/java/com/yihu/wlyy/entity/questionnaire/QuestionnaireWinning.java
  5. 17 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/doctor/DoctorSwitchDao.java
  6. 13 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/doctor/PatientAimBloodPressureDao.java
  7. 14 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/doctor/PatientAimBloodSuggerDao.java
  8. 18 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/patient/TrackPatientDao.java
  9. 126 7
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/common/account/PatientService.java
  10. 17 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/third/jw/JwPrescriptionService.java
  11. 62 0
      patient-co/patient-co-wlyy/doc/技术文档/es/回访问卷新增索引.txt
  12. 14 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/config/SystemConfig.java
  13. 24 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/common/SystemPropertiesDao.java
  14. 15 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/imm/ChildImmuneRegisterRecordDao.java
  15. 22 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/questionnaire/QuestionnaireWinningDao.java
  16. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionInfoService.java
  17. 39 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/InitiSysProService.java
  18. 118 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/questionnaire/QuestionnaireService.java
  19. 6 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/guahao/ImmuneService.java
  20. 156 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/random/LotteryUtils.java
  21. 46 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/random/dto/Lottery.java
  22. 71 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/random/dto/LotteryItem.java
  23. 45 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/test/Prize.java
  24. 282 28
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/booking/PatientBookingController.java
  25. 2 0
      patient-co/patient-co-wlyy/src/main/resources/application-dev.yml
  26. 2 0
      patient-co/patient-co-wlyy/src/main/resources/application-devtest.yml
  27. 2 0
      patient-co/patient-co-wlyy/src/main/resources/application-local.yml
  28. 2 0
      patient-co/patient-co-wlyy/src/main/resources/application-localtest.yml
  29. 2 0
      patient-co/patient-co-wlyy/src/main/resources/application-prod.yml
  30. 2 0
      patient-co/patient-co-wlyy/src/main/resources/application-test.yml

+ 139 - 0
common/common-entity/src/main/java/com/yihu/es/entity/QuestionnaireWinningESDO.java

@ -0,0 +1,139 @@
package com.yihu.es.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.searchbox.annotations.JestId;
import org.springframework.data.annotation.CreatedDate;
import java.util.Date;
/**
 * 调查问卷中奖纪录
 * @author huangwenjie
 * @date 2018/1/28 19:51
 */
public class QuestionnaireWinningESDO {
	
	@JestId
	private String id;
	// 业务主键
	private String code;
	//用户CODE
	private String userCode;
	//用户身份证信息
	private String userIdcard;
	//中奖人姓名
	private String userName;
	//中奖人openid
	private String userOpenid;
	//奖品类型:1电影票
	private Integer prizeType;
	//奖品兑奖码
	private String prizeCode;
	//0为未删除,1为删除
	private Integer del;
	//0为未中奖,1为已中奖
	private Integer winning;
	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyyMMdd'T'HHmmss.SSS'Z'")
	@CreatedDate
	private Date create_time;
	
	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyyMMdd'T'HHmmss.SSS'Z'")
	private Date update_time;
	
	
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	public String getCode() {
		return code;
	}
	
	public void setCode(String code) {
		this.code = code;
	}
	
	public String getUserCode() {
		return userCode;
	}
	
	public void setUserCode(String userCode) {
		this.userCode = userCode;
	}
	
	public String getUserIdcard() {
		return userIdcard;
	}
	
	public void setUserIdcard(String userIdcard) {
		this.userIdcard = userIdcard;
	}
	
	public String getUserName() {
		return userName;
	}
	
	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	public String getUserOpenid() {
		return userOpenid;
	}
	
	public void setUserOpenid(String userOpenid) {
		this.userOpenid = userOpenid;
	}
	
	public Integer getPrizeType() {
		return prizeType;
	}
	
	public void setPrizeType(Integer prizeType) {
		this.prizeType = prizeType;
	}
	
	public String getPrizeCode() {
		return prizeCode;
	}
	
	public void setPrizeCode(String prizeCode) {
		this.prizeCode = prizeCode;
	}
	
	public Integer getDel() {
		return del;
	}
	
	public void setDel(Integer del) {
		this.del = del;
	}
	
	public Date getCreate_time() {
		return create_time;
	}
	
	public void setCreate_time(Date create_time) {
		this.create_time = create_time;
	}
	
	public Date getUpdate_time() {
		return update_time;
	}
	
	public void setUpdate_time(Date update_time) {
		this.update_time = update_time;
	}
	
	public Integer getWinning() {
		return winning;
	}
	
	public void setWinning(Integer winning) {
		this.winning = winning;
	}
}

+ 58 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/common/SystemProperties.java

@ -0,0 +1,58 @@
package com.yihu.wlyy.entity.common;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * @author huangwenjie
 * @date 2018/1/28 23:40
 */
@Entity
@Table(name = "system_properties")
public class SystemProperties extends IdEntity {
	//工程类型-0:wlyy,1:wlyy_service
	private Integer client;
	
	//参数key
	private String key;
	
	//参数值
	private String value;
	
	//0为有效,1为删除状态
	private Integer isdel;
	
	public Integer getClient() {
		return client;
	}
	
	public void setClient(Integer client) {
		this.client = client;
	}
	
	public String getKey() {
		return key;
	}
	
	public void setKey(String key) {
		this.key = key;
	}
	
	public String getValue() {
		return value;
	}
	
	public void setValue(String value) {
		this.value = value;
	}
	
	public Integer getIsdel() {
		return isdel;
	}
	
	public void setIsdel(Integer isdel) {
		this.isdel = isdel;
	}
}

+ 183 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/imm/ChildImmuneRegisterRecord.java

@ -0,0 +1,183 @@
package com.yihu.wlyy.entity.imm;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * 计划免疫预约记录表
 * @author huangwenjie
 * @date 2018/1/28 17:26
 */
@Entity
@Table(name = "wlyy_child_immune_register_record")
public class ChildImmuneRegisterRecord  extends IdEntity {
	private String code;
	private String barCode;         //新生儿条码
	private String jwOrgcode;       //基卫机构编码
	private String orgCode;         //机构编码
	private String orgName;         //机构名称
	private String sectionType;     //坐诊类型:AM PM
	private Date startTime;         //号源日期
	private String ssc;             //挂号人社保卡
	private String idcard;          //挂号人身份证号
	private String name;            //挂号人姓名
	private String mobile;          //挂号人手机
	private Integer type;           //0为预约,1为取消预约
	private String familyCode;      //代预约的家人CODE
	private String familyName;      //代预约家人名称
	private String doctorCode;      //代预约的医生CODE
	private String doctorName;      //代预约的医生姓名
	private Date createTime;
	private Date updateTime;
	
	
	public String getCode() {
		return code;
	}
	
	public void setCode(String code) {
		this.code = code;
	}
	
	public String getBarCode() {
		return barCode;
	}
	
	public void setBarCode(String barCode) {
		this.barCode = barCode;
	}
	
	public String getJwOrgcode() {
		return jwOrgcode;
	}
	
	public void setJwOrgcode(String jwOrgcode) {
		this.jwOrgcode = jwOrgcode;
	}
	
	public String getOrgCode() {
		return orgCode;
	}
	
	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}
	
	public String getOrgName() {
		return orgName;
	}
	
	public void setOrgName(String orgName) {
		this.orgName = orgName;
	}
	
	public String getSectionType() {
		return sectionType;
	}
	
	public void setSectionType(String sectionType) {
		this.sectionType = sectionType;
	}
	
	public Date getStartTime() {
		return startTime;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}
	
	public String getSsc() {
		return ssc;
	}
	
	public void setSsc(String ssc) {
		this.ssc = ssc;
	}
	
	public String getIdcard() {
		return idcard;
	}
	
	public void setIdcard(String idcard) {
		this.idcard = idcard;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getMobile() {
		return mobile;
	}
	
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	
	public Integer getType() {
		return type;
	}
	
	public void setType(Integer type) {
		this.type = type;
	}
	
	public String getFamilyCode() {
		return familyCode;
	}
	
	public void setFamilyCode(String familyCode) {
		this.familyCode = familyCode;
	}
	
	public String getFamilyName() {
		return familyName;
	}
	
	public void setFamilyName(String familyName) {
		this.familyName = familyName;
	}
	
	public String getDoctorCode() {
		return doctorCode;
	}
	
	public void setDoctorCode(String doctorCode) {
		this.doctorCode = doctorCode;
	}
	
	public String getDoctorName() {
		return doctorName;
	}
	
	public void setDoctorName(String doctorName) {
		this.doctorName = doctorName;
	}
	
	public Date getCreateTime() {
		return createTime;
	}
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	public Date getUpdateTime() {
		return updateTime;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
}

+ 2 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/questionnaire/QuestionnaireWinning.java

@ -31,6 +31,8 @@ public class QuestionnaireWinning extends IdEntity implements Serializable {
	private String userOpenid;
	//奖品类型:1电影票
	private Integer prizeType;
	//0未中奖,1已中奖
	private Integer winning;
	//奖品兑奖码
	private String prizeCode;
	//0为未删除,1为删除

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

@ -0,0 +1,17 @@
package com.yihu.wlyy.repository.doctor;
/**
 * @author huangwenjie
 * @date 2018/1/28 16:29
 */
import com.yihu.wlyy.entity.doctor.DoctorSwitch;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Trick on 2018/1/5.
 */
public interface DoctorSwitchDao extends PagingAndSortingRepository<DoctorSwitch, Long>, JpaSpecificationExecutor<DoctorSwitch> {
	public DoctorSwitch findByDoctor(String doctor);
}

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

@ -0,0 +1,13 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.patient.PatientAimBloodPressure;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author huangwenjie
 * @date 2018/1/28 16:34
 */
public interface PatientAimBloodPressureDao extends PagingAndSortingRepository<PatientAimBloodPressure, Integer>, JpaSpecificationExecutor<PatientAimBloodPressure> {
	public  PatientAimBloodPressure findByPatientcode(String patientcode);
}

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

@ -0,0 +1,14 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.patient.PatientAimBloodSugger;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author huangwenjie
 * @date 2018/1/28 16:32
 */
public interface PatientAimBloodSuggerDao extends PagingAndSortingRepository<PatientAimBloodSugger, Integer>, JpaSpecificationExecutor<PatientAimBloodSugger> {
	
	public PatientAimBloodSugger findByPatientcode(String patientcode);
}

+ 18 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/patient/TrackPatientDao.java

@ -0,0 +1,18 @@
package com.yihu.wlyy.repository.patient;
import com.yihu.wlyy.entity.patient.TrackPatient;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * @author huangwenjie
 * @date 2018/1/28 16:30
 */
public interface TrackPatientDao extends PagingAndSortingRepository<TrackPatient, String>, JpaSpecificationExecutor<TrackPatient> {
	
	public TrackPatient findByDoctorCodeAndPatientCode(String doctorCode,String patientCode);
	
	public List<TrackPatient> findByDoctorCodeAndTeamCodeAndDel(String doctorCode, Integer teamCode, String del);
}

+ 126 - 7
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/common/account/PatientService.java

@ -5,19 +5,16 @@
 *******************************************************************************/
package com.yihu.wlyy.service.common.account;
import com.yihu.wlyy.entity.doctor.DoctorSwitch;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.doctor.team.sign.DoctorPatient;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.ServerLabelTree;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.patient.SignFamilyRenew;
import com.yihu.wlyy.entity.patient.*;
import com.yihu.wlyy.entity.security.Token;
import com.yihu.wlyy.repository.doctor.DoctorAdminTeamDao;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.doctor.DoctorPatientDao;
import com.yihu.wlyy.repository.doctor.*;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.patient.TrackPatientDao;
import com.yihu.wlyy.repository.security.TokenDao;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.EncodesUtil;
@ -65,6 +62,14 @@ public class PatientService extends TokenService {
    @Autowired
    private DoctorAdminTeamDao doctorAdminTeamDao;
    @Autowired
    private DoctorSwitchDao doctorSwitchDao;
    @Autowired
    private TrackPatientDao trackPatientDao;
    @Autowired
    private PatientAimBloodSuggerDao patientAimBloodSuggerDao;
    @Autowired
    private PatientAimBloodPressureDao patientAimBloodPressureDao;
    @Autowired
    TokenDao tokenDao;
    @Autowired
    JdbcTemplate jdbcTemplate;
@ -1019,4 +1024,118 @@ public class PatientService extends TokenService {
        }
    }
    
    /**
     * //1.4.2加入重点关注逻辑
     * 红色定标居民加入重点关注
     * @param idcard_red_diseasecontion_map
     */
    public void setTrackPatientByDoctor(HashMap<String, Integer> idcard_red_diseasecontion_map) {
        
        Set<String> patient_idcards = idcard_red_diseasecontion_map.keySet();
    
        for (String idcard: patient_idcards) {
            Patient p = patientDao.findByIdcard(idcard);
            if(p==null){
                logger.info("居民idcard:"+idcard+";未找到该居民");
                continue;
            }
    
            SignFamily signFamily = signFamilyDao.findByjiatingPatientYes(p.getCode());
            if(signFamily==null){
                logger.info("居民idcard:"+idcard+";该居民未签约家庭医生");
                continue;
            }
    
            //医生是否自动追踪居民
            DoctorSwitch sw =  doctorSwitchDao.findByDoctor(signFamily.getDoctor());
            DoctorSwitch swh =  doctorSwitchDao.findByDoctor(signFamily.getDoctorHealth());
    
            if(sw!=null){
                if("1".equals(sw.getAlertPatientSwitch())){
                    //查询是否与医生建立重点跟踪关系,诺无关系则建立
                    TrackPatient trackPatient = trackPatientDao.findByDoctorCodeAndPatientCode(signFamily.getDoctor(),p.getCode());
            
                    if(trackPatient == null){
                        TrackPatient t = new TrackPatient();
                        t.setCreateTime(new Date());
                        t.setDoctorCode(signFamily.getDoctor());
                        t.setDoctorName(signFamily.getDoctorName());
                        t.setIdcard(signFamily.getIdcard());
                        t.setSsc(signFamily.getSsc());
                        t.setTeamCode(signFamily.getAdminTeamId().intValue());
                        t.setPatientCode(p.getCode());
                        t.setPatientName(p.getName());
                        t.setDel("1");
                        trackPatientDao.save(t);
                        //设置默认控制目标
                        setDefaultAim(p.getCode());
                    }else{
                        trackPatient.setDel("1");
                        trackPatientDao.save(trackPatient);
                    }
                }
            }
    
            if(swh!=null){
                if("1".equals(sw.getAlertPatientSwitch())){
                    //查询是否与医生建立重点跟踪关系,诺无关系则建立
                    TrackPatient trackPatient = trackPatientDao.findByDoctorCodeAndPatientCode(signFamily.getDoctorHealth(),p.getCode());
                    if(trackPatient == null){
                        TrackPatient t = new TrackPatient();
                        t.setCreateTime(new Date());
                        t.setDoctorCode(signFamily.getDoctorHealth());
                        t.setDoctorName(signFamily.getDoctorHealthName());
                        t.setIdcard(signFamily.getIdcard());
                        t.setSsc(signFamily.getSsc());
                        t.setTeamCode(signFamily.getAdminTeamId().intValue());
                        t.setPatientCode(p.getCode());
                        t.setPatientName(p.getName());
                        t.setDel("1");
                        trackPatientDao.save(t);
                        //设置默认控制目标
                        setDefaultAim(p.getCode());
                    }else{
                        trackPatient.setDel("1");
                        trackPatientDao.save(trackPatient);
                    }
                }
            }
        }
    }
    
    /**
     * 设置默认监控方案
     * @param patient
     * @return
     */
    public String setDefaultAim(String patient){
        PatientAimBloodSugger patientAimBloodSugger = patientAimBloodSuggerDao.findByPatientcode(patient);
        PatientAimBloodPressure patientAimBloodPressure =  patientAimBloodPressureDao.findByPatientcode(patient);
        if(patientAimBloodSugger==null){
            PatientAimBloodSugger pa = new PatientAimBloodSugger();
            pa.setPatientcode(patient);
            pa.setCode(getCode());
            pa.setCreateTime(new Date());
            pa.setUnit("mmol/L");
            pa.setFbg("7.0");
            pa.setHpg("11.1");
            pa.setFbgMin("4.0");
            pa.setHpgMin("4.0");
            patientAimBloodSuggerDao.save(pa);
        }
        if(patientAimBloodPressure==null){
            PatientAimBloodPressure pa = new PatientAimBloodPressure();
            pa.setPatientcode(patient);
            pa.setCode(getCode());
            pa.setCreateTime(new Date());
            pa.setSbp("140");
            pa.setSbpMin("90");
            pa.setDbp("90");
            pa.setDbpMin("60");
            pa.setUnit("mmHg");
            patientAimBloodPressureDao.save(pa);
        }
        return "1";
    }
}

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

@ -320,8 +320,12 @@ public class JwPrescriptionService {
        params.add(new BasicNameValuePair("TIME_END", enddate));//结束时间
        String response = httpClientUtil.post(url, params, "UTF-8");
    
        //全部定标的居民集合
        HashMap<String, Integer> idcard_diseasecontion_map = new HashMap<>();
    
        //红色定标的居民集合
        HashMap<String, Integer> idcard_red_diseasecontion_map = new HashMap<>();
    
        if (StringUtils.isNotBlank(response)) {
            JSONObject reobj = JSON.parseObject(response);
            Integer status = reobj.getInteger("status");
@ -336,11 +340,24 @@ public class JwPrescriptionService {
                        String idcard = json.getString("IDENTITY_CARD_NO");//身份证号码
                        Integer diseaseCondition = json.getInteger("SPECIALIST_CONTROL");//定标情况【 0 绿标 1 黄标 2 红标】
                        idcard_diseasecontion_map.put(idcard, diseaseCondition);
                        
                        //过滤出红色定标的居民集合
                        if(2 == diseaseCondition){
                            idcard_red_diseasecontion_map.put(idcard, diseaseCondition);
                        }
                    }
    
                    if (idcard_diseasecontion_map != null && !idcard_diseasecontion_map.keySet().isEmpty()) {
                        logger.info("从基卫接口获取需要更新定标情况的慢病患者个数为" + idcard_diseasecontion_map.keySet().size());
                        patientService.updatePatientDiseascontionByIdcard(idcard_diseasecontion_map);
                        
                        
                        //红色定标的居民单独处理
                        if(idcard_red_diseasecontion_map != null && !idcard_red_diseasecontion_map.isEmpty()){
                            //1.4.2加入重点关注逻辑
                            patientService.setTrackPatientByDoctor(idcard_red_diseasecontion_map);
                        }
                        
                    } else {
                        logger.info("从基卫接口获取需要更新定标情况的慢病患者个数为" + idcard_diseasecontion_map.keySet().size());
                    }

+ 62 - 0
patient-co/patient-co-wlyy/doc/技术文档/es/回访问卷新增索引.txt

@ -0,0 +1,62 @@
创建索引
POST  http://172.19.103.68:9200/wlyy_questionnaire_winning
查询索引
GET http://172.19.103.68:9200/wlyy_questionnaire_winning/
给索引加mapping
POST http://172.19.103.68:9200/wlyy_questionnaire_winning/wlyy_questionnaire_winning/_mapping
{
    "wlyy_questionnaire_winning": {
        "properties": {
            "code": {
                "type": "string",
                "index": "not_analyzed"
            },
            "userCode": {
                "type": "string",
                "index": "not_analyzed"
            },
            "userIdcard": {
                "type": "string",
                "index": "not_analyzed"
            },
            "userName": {
                "type": "string",
                "index": "not_analyzed"
            },
            "userOpenid": {
                "type": "string",
                "index": "not_analyzed"
            },
            "prizeCode": {
                "type": "string",
                "index": "not_analyzed"
            },
            "del": {
                "type": "string",
                "index": "not_analyzed"
            },
            "winning": {
                "type": "string",
                "index": "not_analyzed"
            },
            "create_time": {
                "type": "string",
                "index": "not_analyzed"
            },
            "update_time": {
                "type": "string",
                "index": "not_analyzed"
            }
        }
    }
}
增加索引搜索大小
PUT  http://172.19.103.68:9200/wlyy_questionnaire_winning/_settings
{
  "index": {
    "max_result_window": 500000
  }
}

+ 14 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/config/SystemConfig.java

@ -0,0 +1,14 @@
package com.yihu.wlyy.config;
import java.util.HashMap;
import java.util.Map;
/**
 * 缓存system_properties表的参数
 * @author huangwenjie
 * @date 2018/1/28 23:33
 */
public class SystemConfig {
	//从system_properties表中取到的系统参数集,key参数key,value参数值
	public static Map<String,String> sysPropertiesSets = new HashMap<>();
}

+ 24 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/common/SystemPropertiesDao.java

@ -0,0 +1,24 @@
package com.yihu.wlyy.repository.common;
import com.yihu.wlyy.entity.common.SystemProperties;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * 数据库系统参数表
 *@author huangwenjie
 *@date 2018/1/28 23:43
 */
public interface SystemPropertiesDao extends
        PagingAndSortingRepository<SystemProperties, Long>,
        JpaSpecificationExecutor<SystemProperties> {
    @Query("select a from SystemProperties a where a.client = ?1 and a.isdel = 0 ")
    List<SystemProperties> findSystemPropertiesByClientAndSpaValue(Integer client);
}

+ 15 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/imm/ChildImmuneRegisterRecordDao.java

@ -0,0 +1,15 @@
package com.yihu.wlyy.repository.imm;
import com.yihu.wlyy.entity.imm.ChildImmuneRegisterRecord;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * 计划免疫预约记录
 * @author huangwenjie
 * @date 2018/1/28 19:21
 */
public interface ChildImmuneRegisterRecordDao extends PagingAndSortingRepository<ChildImmuneRegisterRecord, Long>,
		JpaSpecificationExecutor<ChildImmuneRegisterRecord> {
}

+ 22 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/questionnaire/QuestionnaireWinningDao.java

@ -0,0 +1,22 @@
package com.yihu.wlyy.repository.questionnaire;
import com.yihu.wlyy.entity.questionnaire.QuestionnaireWinning;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * 调查问卷中奖纪录
 * @author huangwenjie
 * @date 2018/1/28 20:09
 */
public interface QuestionnaireWinningDao extends
		PagingAndSortingRepository<QuestionnaireWinning, Long>,
		JpaSpecificationExecutor<QuestionnaireWinning> {
	
	@Query("select p from QuestionnaireWinning p where (p.userIdcard=?1 or p.userOpenid=?2) and del = 0 ")
	List<QuestionnaireWinning> findByUserIdcardAndUserOpenid(String idcard,String openid);
}

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

@ -116,7 +116,7 @@ public class PrescriptionInfoService extends BaseService {
    @Autowired
    private MessageService messageService;
    private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
    private static final Logger logger = LoggerFactory.getLogger(PrescriptionInfoService.class);
    /**
     * 获取处方下的详细药品列表

+ 39 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/InitiSysProService.java

@ -0,0 +1,39 @@
package com.yihu.wlyy.service.common;
import com.yihu.wlyy.config.SystemConfig;
import com.yihu.wlyy.entity.common.SystemProperties;
import com.yihu.wlyy.repository.common.SystemPropertiesDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service("InitiSysProService")
public class InitiSysProService {
	
	@Autowired
	private SystemPropertiesDao systemPropertiesDao;
	
	
	/**
	 * 重新执行系统参数初始化
	 */
	public void startInitiSysProperties() throws Exception{
		if(!SystemConfig.sysPropertiesSets.isEmpty()){
			SystemConfig.sysPropertiesSets.clear();
		}
		Map<String,String> sysPropertiesSets = new HashMap<>();
		List<SystemProperties> sysvalueList = systemPropertiesDao.findSystemPropertiesByClientAndSpaValue(1);
		if(!sysvalueList.isEmpty()){
			for (SystemProperties systemProperties : sysvalueList) {
				System.out.println("key:"+systemProperties.getKey());
				System.out.println("value:"+systemProperties.getValue());
				sysPropertiesSets.put(systemProperties.getKey(),systemProperties.getValue());
			}
			SystemConfig.sysPropertiesSets = sysPropertiesSets;
		}
	}
}

+ 118 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/questionnaire/QuestionnaireService.java

@ -0,0 +1,118 @@
package com.yihu.wlyy.service.questionnaire;
import com.yihu.es.entity.HealthEduArticleES;
import com.yihu.es.entity.QuestionnaireWinningESDO;
import com.yihu.wlyy.config.SystemConfig;
import com.yihu.wlyy.config.es.ElasticFactory;
import com.yihu.wlyy.entity.questionnaire.QuestionnaireUsers;
import com.yihu.wlyy.entity.questionnaire.QuestionnaireWinning;
import com.yihu.wlyy.repository.questionnaire.QuestionnaireWinningDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.ElasticsearchUtil;
import com.yihu.wlyy.util.random.LotteryUtils;
import com.yihu.wlyy.util.random.dto.Lottery;
import com.yihu.wlyy.util.random.dto.LotteryItem;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
 * 回访问卷调查业务逻辑类
 * @author huangwenjie
 * @date 2018/1/28 20:20
 */
@Service
public class QuestionnaireService extends BaseService {
	
	private static final Logger logger = LoggerFactory.getLogger(QuestionnaireService.class);
	@Autowired
	private ElasticFactory elasticFactory;
	@Autowired
	private ElasticsearchUtil elasticsearchUtil;
	@Value("${es.type.QuestionnaireWinning}")
	private String esType;
	@Value("${es.index.QuestionnaireWinning}")
	private String esIndex;
	@Autowired
	private QuestionnaireWinningDao questionnaireWinningDao;
	
	/**
	 * 根据身份证和openid从ES查询中奖结果
	 * @param idcard
	 * @param openid
	 * @return
	 * @throws Exception
	 */
	public QuestionnaireWinningESDO getQuestionnaireWinningESDOByIdcardAndOpenid(String idcard,String openid) throws Exception{
		//中奖纪录
		String sql = "SELECT * FROM " + esType + "  where del = 0 and ( userIdcard= '" + idcard + "' or userOpenid = '"+openid+"' ) ";
		QuestionnaireWinningESDO result = (QuestionnaireWinningESDO)elasticsearchUtil.excuteOneObject(sql, HealthEduArticleES.class, esIndex, esType);
		return result;
	}
	
	/**
	 * 回访问卷抽奖
	 * @param questionnaireUsers
	 * @return
	 * @throws Exception
	 */
	public QuestionnaireWinningESDO questionnaireLottery(QuestionnaireUsers questionnaireUsers)throws Exception{
		
		if(StringUtils.isBlank(questionnaireUsers.getIdcard()) || !"undefined".equals(questionnaireUsers.getIdcard())){
			throw new Exception("身份证号为空或者异常:"+questionnaireUsers.getIdcard());
		}
		
		if(StringUtils.isBlank(questionnaireUsers.getOpenid()) || !"undefined".equals(questionnaireUsers.getOpenid())){
			throw new Exception("openid为空或者异常:"+questionnaireUsers.getIdcard());
		}
		
		//@todo 判断奖品池的奖品是否已经发完
		boolean canLottery = true;
		
		if(canLottery){
		//未发完,可继续抽奖
			
			//获取设置的中奖概率
			String awardProbability = SystemConfig.sysPropertiesSets.get("winning_pr");
			//抽奖
			LotteryItem lotteryItem = LotteryUtils.isWinning(new Double(awardProbability));
			QuestionnaireWinning questionnaireWinning = new QuestionnaireWinning();
			questionnaireWinning.setCode(UUID.randomUUID().toString());
			questionnaireWinning.setDel(0);
			questionnaireWinning.setPrizeType(1);
			questionnaireWinning.setUserCode(questionnaireUsers.getCode());
			questionnaireWinning.setUserIdcard(questionnaireUsers.getIdcard());
			questionnaireWinning.setUserName(questionnaireUsers.getName());
			questionnaireWinning.setUserOpenid(questionnaireUsers.getOpenid());
			questionnaireWinning.setCreate_time(new Date());
			questionnaireWinning.setUpdate_time(new Date());
			if("YES".equals(lotteryItem.getAwardName())){
				List<QuestionnaireWinning> winningList = questionnaireWinningDao.findByUserIdcardAndUserOpenid(questionnaireUsers.getIdcard(),questionnaireUsers.getOpenid());
				if(winningList.isEmpty()){
				
				}else{
					questionnaireWinning = winningList.get(0);
					
				}
				
			}else{
			}
		}
		
		
		
		
		return null;
	}
}

+ 6 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/guahao/ImmuneService.java

@ -3,10 +3,16 @@ package com.yihu.wlyy.service.third.guahao;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.security.AccessToken;
import com.yihu.wlyy.repository.organization.HospitalDao;
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
import com.yihu.wlyy.service.common.account.AccessTokenService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.util.HttpUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
@ -37,13 +43,10 @@ public class ImmuneService {
	@Autowired
	private HttpClientUtil httpClientUtil;
	@Autowired
	private JdbcTemplate jdbcTemplate;
	@Autowired
	private HospitalMappingDao hospitalMappingDao;
	@Autowired
	private HospitalDao hospitalDao;
	
	
	/**
	 * 计免:获取免疫接种儿童信息
	 * @param barcode 新生儿条码

+ 156 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/random/LotteryUtils.java

@ -0,0 +1,156 @@
package com.yihu.wlyy.util.random;
import com.yihu.wlyy.util.random.dto.Lottery;
import com.yihu.wlyy.util.random.dto.LotteryItem;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
 * 抽奖工具类
 * 算法原理:
 *          计算出抽奖活动一组数字,根据抽奖奖品的概率计算出每个奖品所在的数字区间。Random随机数落在了哪个奖品的数字区间,则用户中这个区间对应的奖品。
 * 中奖概率:
 *          奖品A[0,24]->中奖概率0.25的中奖数字区间
 *          奖品B[25,49]->中奖概率0.25的中奖数字区间
 *          奖品C[49,99]->中奖概率0.5的中奖数字区间
 *          可设置奖品C为未中奖,如果抽中奖品C,则未中奖
 * @author huangwenjie
 * @date 2018/1/28 21:34
 */
public class LotteryUtils {
	private static final Random random = new Random();
	private static final Integer MAXSOPE = 100000000;
	
	public static void calAwardProbability(Lottery lottery, List<LotteryItem> lotteryItemList) {
		Integer codeScope = 1;
		for (LotteryItem item : lotteryItemList) {
			Integer nowScope = 1;
			Double awardProbability = item.getAwardProbability();
			while (true) {
				Double test = awardProbability * nowScope;
				// 概率的精确度,调整到小数点后10位,概率太小等于不中奖,跳出
				if (test < 0.0000000001) {
					break;
				}
				if ((test >= 1L && (test - test.longValue()) < 0.0001D) || nowScope >= MAXSOPE) {
					if (nowScope > codeScope) {
						// 设置中奖范围
						codeScope = nowScope;
					}
					break;
				} else {
					// 中奖数字范围以10倍进行增长
					nowScope = nowScope * 10;
				}
			}
		}
		Integer winningStartCode = 0;
		Integer winningEndCode = winningStartCode;
		
		for (LotteryItem item : lotteryItemList) {
			Integer codeNum = (int) (item.getAwardProbability() * codeScope); // 获得其四舍五入的整数值
			// 无人中奖时,将中奖的起始范围设置在随机数的范围之外
			if (codeNum == 0) {
				item.setAwardStartCode(codeScope + 1);
				item.setAwardEndCode(codeScope + 1);
			} else {
				item.setAwardStartCode(winningEndCode);
				item.setAwardEndCode(winningEndCode + codeNum - 1);
				winningEndCode = winningEndCode + codeNum;
			}
		}
		// 设置用户的中奖随机码信息
		lottery.setWinningStartCode(winningStartCode);
		lottery.setWinningEndCode(winningEndCode);
		lottery.setCodeScope(codeScope);
	}
	
	public static LotteryItem beginLottery(Lottery lottery, List<LotteryItem> lotteryItemList) {
		// 确定活动是否有效,如果活动无效则,直接抽奖失败
		Integer randomCode = random.nextInt(lottery.getCodeScope());
		if (randomCode >= lottery.getWinningStartCode() && randomCode <= lottery.getWinningEndCode()) {
			for (LotteryItem item : lotteryItemList) {
				if (randomCode >= item.getAwardStartCode() && randomCode <= item.getAwardEndCode()) {
					item.setAwardCode(randomCode);
					return item;
				}
			}
		}
		return null;
	}
	
	
	/**
	 * demo
	 * @param args
	 */
	public static void main(String[] args) {
		List<LotteryItem> lotteryItemList = new ArrayList<LotteryItem>();
		LotteryItem awardItem1 = new LotteryItem();
		awardItem1.setAwardName("红包10元");
		awardItem1.setAwardProbability(0.25D);
		lotteryItemList.add(awardItem1);
		LotteryItem awardItem2 = new LotteryItem();
		awardItem2.setAwardName("红包20元");
		awardItem2.setAwardProbability(0.25D);
		lotteryItemList.add(awardItem2);
		LotteryItem awardItem3 = new LotteryItem();
		awardItem3.setAwardName("谢谢参与");
		awardItem3.setAwardProbability(0.5D);
		lotteryItemList.add(awardItem3);
		Lottery lottery = new Lottery();
		LotteryUtils.calAwardProbability(lottery, lotteryItemList);
		System.out.println("抽奖活动中奖数字范围:["+lottery.getWinningStartCode()+","+lottery.getWinningEndCode()+")");
		LotteryUtils.beginLottery(lottery, lotteryItemList);
		for (LotteryItem item : lotteryItemList) {
			System.out.println(item.getAwardName()+" 中奖数字范围:["+item.getAwardStartCode()+","+item.getAwardEndCode()+"]");
		}
		System.out.println("以下是模拟的抽奖中奖结果:");
		LotteryItem award1 = LotteryUtils.beginLottery(lottery, lotteryItemList);
		System.out.println("抽中的数字是:"+award1.getAwardCode()+",恭喜中奖:"+award1.getAwardName()+",数字落点["+award1.getAwardStartCode()+","+award1.getAwardEndCode()+"]");
		LotteryItem award2 = LotteryUtils.beginLottery(lottery, lotteryItemList);
		System.out.println("抽中的数字是:"+award2.getAwardCode()+",恭喜中奖:"+award2.getAwardName()+",数字落点["+award2.getAwardStartCode()+","+award2.getAwardEndCode()+"]");
		LotteryItem award3 = LotteryUtils.beginLottery(lottery, lotteryItemList);
		System.out.println("抽中的数字是:"+award3.getAwardCode()+",恭喜中奖:"+award3.getAwardName()+",数字落点["+award3.getAwardStartCode()+","+award3.getAwardEndCode()+"]");
		LotteryItem award4 = LotteryUtils.beginLottery(lottery, lotteryItemList);
		System.out.println("抽中的数字是:"+award4.getAwardCode()+",恭喜中奖:"+award4.getAwardName()+",数字落点["+award4.getAwardStartCode()+","+award4.getAwardEndCode()+"]");
		
	}
	
	/**
	 * 抽奖
	 * @param awardProbability 中奖概率
	 * @return
	 */
	public static LotteryItem isWinning(Double awardProbability){
		
		List<LotteryItem> lotteryItemList = new ArrayList<LotteryItem>();
		LotteryItem awardItem1 = new LotteryItem();
		awardItem1.setAwardName("YES");
		awardItem1.setAwardProbability(awardProbability);
		lotteryItemList.add(awardItem1);
		
		LotteryItem awardItem2 = new LotteryItem();
		awardItem2.setAwardName("NO");
		awardItem2.setAwardProbability(1-awardProbability);
		lotteryItemList.add(awardItem2);
		Lottery lottery = new Lottery();
		LotteryUtils.calAwardProbability(lottery, lotteryItemList);
		System.out.println("抽奖活动中奖数字范围:["+lottery.getWinningStartCode()+","+lottery.getWinningEndCode()+")");
		LotteryUtils.beginLottery(lottery, lotteryItemList);
		for (LotteryItem item : lotteryItemList) {
			System.out.println(item.getAwardName()+" 中奖数字范围:["+item.getAwardStartCode()+","+item.getAwardEndCode()+"]");
		}
		
		LotteryItem award = LotteryUtils.beginLottery(lottery, lotteryItemList);
		System.out.println("抽中的数字是:"+award.getAwardCode()+",是否中奖:"+award.getAwardName()+",数字落点["+award.getAwardStartCode()+","+award.getAwardEndCode()+"]");
		
		return award;
	}
}

+ 46 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/random/dto/Lottery.java

@ -0,0 +1,46 @@
package com.yihu.wlyy.util.random.dto;
/**
 * 抽奖信息对象
 * @author huangwenjie
 * @date 2018/1/28 21:33
 */
public class Lottery {
	/**
	 * 中奖数字范围起点(通常0作为起点)
	 */
	private Integer winningStartCode;
	/**
	 * 当前概率计算出的中奖数字范围终点
	 */
	private Integer winningEndCode;
	
	/**
	 * 中奖的数字范围
	 */
	private Integer codeScope;
	
	public Integer getWinningStartCode() {
		return winningStartCode;
	}
	
	public void setWinningStartCode(Integer winningStartCode) {
		this.winningStartCode = winningStartCode;
	}
	
	public Integer getWinningEndCode() {
		return winningEndCode;
	}
	
	public void setWinningEndCode(Integer winningEndCode) {
		this.winningEndCode = winningEndCode;
	}
	
	public Integer getCodeScope() {
		return codeScope;
	}
	
	public void setCodeScope(Integer codeScope) {
		this.codeScope = codeScope;
	}
}

+ 71 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/random/dto/LotteryItem.java

@ -0,0 +1,71 @@
package com.yihu.wlyy.util.random.dto;
/**
 * 抽奖奖品对象
 * @author huangwenjie
 * @date 2018/1/28 21:32
 */
public class LotteryItem {
	/**
	 * 奖品名称
	 */
	private String awardName;
	
	/**
	 * 中奖几率
	 */
	private Double awardProbability;
	/**
	 * 奖品中奖数字范围起点
	 */
	private Integer awardStartCode;
	/**
	 * 奖品中奖数字范围终点
	 */
	private Integer awardEndCode;
	
	/**
	 * 中奖数字,实际应用可不定义。
	 * 此处定义是为了理解
	 */
	private Integer awardCode;
	
	public String getAwardName() {
		return awardName;
	}
	
	public void setAwardName(String awardName) {
		this.awardName = awardName;
	}
	public Double getAwardProbability() {
		return awardProbability;
	}
	
	public void setAwardProbability(Double awardProbability) {
		this.awardProbability = awardProbability;
	}
	
	public Integer getAwardStartCode() {
		return awardStartCode;
	}
	
	public void setAwardStartCode(Integer awardStartCode) {
		this.awardStartCode = awardStartCode;
	}
	
	public Integer getAwardEndCode() {
		return awardEndCode;
	}
	
	public void setAwardEndCode(Integer awardEndCode) {
		this.awardEndCode = awardEndCode;
	}
	
	public Integer getAwardCode() {
		return awardCode;
	}
	
	public void setAwardCode(Integer awardCode) {
		this.awardCode = awardCode;
	}
}

+ 45 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/test/Prize.java

@ -0,0 +1,45 @@
package com.yihu.wlyy.util.test;
/**
 * @author huangwenjie
 * @date 2018/1/28 21:06
 */
public class Prize {
	
	private int id;//奖品id
	private String prize_name;//奖品名称
	private int prize_amount;//奖品(剩余)数量
	private int prize_weight;//奖品权重
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	public String getPrize_name() {
		return prize_name;
	}
	
	public void setPrize_name(String prize_name) {
		this.prize_name = prize_name;
	}
	
	public int getPrize_amount() {
		return prize_amount;
	}
	
	public void setPrize_amount(int prize_amount) {
		this.prize_amount = prize_amount;
	}
	
	public int getPrize_weight() {
		return prize_weight;
	}
	
	public void setPrize_weight(int prize_weight) {
		this.prize_weight = prize_weight;
	}
}

+ 282 - 28
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/booking/PatientBookingController.java

@ -1,9 +1,17 @@
package com.yihu.wlyy.web.patient.booking;
import com.yihu.wlyy.aop.ObserverRequired;
import com.yihu.wlyy.entity.imm.ChildImmuneRegisterRecord;
import com.yihu.wlyy.entity.imm.ChildInfo;
import com.yihu.wlyy.entity.message.SMS;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientReservation;
import com.yihu.wlyy.logs.BusinessLogs;
import com.yihu.wlyy.repository.imm.ChildImmuneRegisterRecordDao;
import com.yihu.wlyy.repository.message.SMSDao;
import com.yihu.wlyy.repository.organization.HospitalDao;
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
import com.yihu.wlyy.service.app.reservation.PatientReservationService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.imm.ChildInfoService;
@ -12,14 +20,23 @@ import com.yihu.wlyy.service.third.guahao.GuahaoYihuService;
import com.yihu.wlyy.service.third.guahao.ImmuneService;
import com.yihu.wlyy.service.third.jw.JwSmjkService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.util.NetworkUtil;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.web.WeixinBaseController;
import com.yihu.wlyy.web.third.zysoft.BookingController;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@ -27,8 +44,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * 预约挂号
@ -38,6 +55,9 @@ import java.util.Map;
@RequestMapping(value = "/patient/guahao")
@Api(description = "预约挂号接口-居民端")
public class PatientBookingController extends WeixinBaseController{
    
    private static final Logger logger = LoggerFactory.getLogger(PatientBookingController.class);
    
    @Autowired
    private GuahaoXMService guahaoXM;
    @Autowired
@ -56,6 +76,16 @@ public class PatientBookingController extends WeixinBaseController{
    private ChildInfoService childInfoService;
    @Autowired
    private ImmuneService immuneService;
    @Autowired
    private HospitalMappingDao hospitalMappingDao;
    @Autowired
    private HospitalDao hospitalDao;
    @Autowired
    private com.yihu.wlyy.util.HttpClientUtil HttpClientUtil;
    @Autowired
    private SMSDao smsDao;
    @Autowired
    private ChildImmuneRegisterRecordDao childImmuneRegisterRecordDao;
    @RequestMapping(value = "CancelOrder", method = RequestMethod.POST)
@ -212,11 +242,11 @@ public class PatientBookingController extends WeixinBaseController{
    @ObserverRequired
    @ApiOperation("计免:获取免疫接种号源")
    public String GetOrgNumberList (@ApiParam(name="orgId",value="机构编码-ZONECODE",defaultValue = "350206")
                                    @RequestParam String orgId,
                                    @RequestParam(value = "orgId", required = true) String orgId ,
                                    @ApiParam(name="ScheduleId",value="排班ID",defaultValue = "350211B10402017080901")
                                    @RequestParam String ScheduleId,
                                    @RequestParam(value = "ScheduleId", required = true) String ScheduleId,
                                    @ApiParam(name="amorpm",value="上午或者下午",defaultValue = "AM")
                                    @RequestParam String amorpm){
                                    @RequestParam(value = "amorpm", required = true) String amorpm){
        
        try{
            com.alibaba.fastjson.JSONArray result = immuneService.GetOrgNumberList(orgId,ScheduleId,amorpm);
@ -232,24 +262,120 @@ public class PatientBookingController extends WeixinBaseController{
    @ObserverRequired
    @ApiOperation("计免:免疫接种确认预约")
    public String RegisterImmune (@ApiParam(name="BarCode",value="新生儿条形编码",defaultValue = "")
                                      @RequestParam String BarCode,
                                      @RequestParam(value = "BarCode", required = true) String BarCode,
                                  @ApiParam(name="OrgCode",value="机构编码",defaultValue = "")
                                      @RequestParam String OrgCode,
                                      @RequestParam(value = "OrgCode", required = true) String OrgCode,
                                  @ApiParam(name="SectionType",value="坐诊类型:取号源的TIME",defaultValue = "")
                                      @RequestParam String SectionType,
                                      @RequestParam(value = "SectionType", required = true) String SectionType,
                                  @ApiParam(name="strStart",value="日期:取号源的START_TIME",defaultValue = "")
                                      @RequestParam String strStart,
                                      @RequestParam(value = "strStart", required = true) String strStart,
                                  @ApiParam(name="SSID",value="新生儿社保卡号",defaultValue = "")
                                      @RequestParam String SSID,
                                      @RequestParam(value = "SSID", required = true) String SSID,
                                  @ApiParam(name="PatientName",value="新生儿姓名",defaultValue = "")
                                      @RequestParam String PatientName,
                                      @RequestParam(value = "PatientName", required = true) String PatientName,
                                  @ApiParam(name="PatientID",value="新生儿身份证号",defaultValue = "")
                                      @RequestParam String PatientID,
                                      @RequestParam(value = "PatientID", required = true) String PatientID,
                                  @ApiParam(name="PatientPhone",value="市民手机号:代预约人的手机号",defaultValue = "")
                                      @RequestParam String PatientPhone){
                                      @RequestParam(value = "PatientPhone", required = true) String PatientPhone){
        
        try{
            immuneService.RegisterImmune(BarCode,OrgCode,SectionType,strStart,SSID,PatientName,PatientID,PatientPhone);
    
            //预约发送微信消息
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            Date START_TIME_VO = dateFormat.parse(strStart);
            String date = DateUtil.dateToStrLong(START_TIME_VO);//开始时间-前端展示用
    
            Patient p = patientService.findByCode(getRepUID());
            String hospitalcode = hospitalMappingDao.getCodeByMapping(OrgCode, "1");
            Hospital hospital = hospitalDao.findByCode(hospitalcode);
    
            String msg = "您成功为"+PatientName+"预约了" + hospital.getName() + "的计划免疫 "+date+" 的号源!";
            // 推送消息给微信端
            org.json.JSONObject json = new org.json.JSONObject();
            json.put("first", "");
            json.put("toUser", p.getCode());
            json.put("represented",p.getCode());//被代理人
            json.put("id", "");
            json.put("date", date);
            json.put("orgCode", hospitalcode);
            json.put("orgName", "-");
            json.put("doctorName", "-");
            json.put("deptName", "-");
            json.put("remark", p.getName() + ",您好!" + msg);
    
            //本地保存计划免疫预约记录
            ChildImmuneRegisterRecord childImmuneRegisterRecord = new ChildImmuneRegisterRecord();
            childImmuneRegisterRecord.setCode(UUID.randomUUID().toString());
            childImmuneRegisterRecord.setBarCode(BarCode);
            childImmuneRegisterRecord.setCreateTime(new Date());
            childImmuneRegisterRecord.setUpdateTime(new Date());
            childImmuneRegisterRecord.setFamilyCode(p.getCode());
            childImmuneRegisterRecord.setFamilyName(p.getName());
            childImmuneRegisterRecord.setMobile(PatientPhone);
            childImmuneRegisterRecord.setSsc(SSID);
            childImmuneRegisterRecord.setIdcard(PatientID);
            childImmuneRegisterRecord.setName(PatientName);
            childImmuneRegisterRecord.setOrgCode(hospitalcode);
            childImmuneRegisterRecord.setOrgName(hospital.getName());
            childImmuneRegisterRecord.setJwOrgcode(OrgCode);
            childImmuneRegisterRecord.setSectionType(SectionType);
            childImmuneRegisterRecord.setStartTime(START_TIME_VO);
            childImmuneRegisterRecord.setType(0);//0为预约,1为取消预约
            childImmuneRegisterRecord = childImmuneRegisterRecordDao.save(childImmuneRegisterRecord);
            
    
            //判断是否判定openId,有没有发则查找家人发送
            if(org.apache.commons.lang3.StringUtils.isNotBlank(p.getOpenid())){
                // 添加到发送队列
                pushMsgTask.putWxMsg(getAccessToken(), 6, p.getOpenid(), p.getName(), json);
            }
    
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
            if(jsonArray!=null&&jsonArray.length()>0){
                for (int i = 0;i<jsonArray.length();i++){
                    JSONObject j  = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    JSONObject data = json;
                    data.remove("toUser");
                    data.put("toUser",member.getCode());
                    //String first = (String) json.get("first");
                    data.remove("first");
                    data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),p.getName()));
                    pushMsgTask.putWxMsg(getAccessToken(), 6, member.getOpenid(), p.getName(), data);
                }
            }
    
            //发送短信消息
            //调用总部发送信息的接口
            String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(msg, p.getMobile()), "GBK");
            JSONObject r = toJson(result);
            SMS sms = new SMS();
            sms.setContent(msg);
            sms.setCaptcha(null);
            Date dateMsg = new Date();
            sms.setDeadline(dateMsg);
            sms.setCzrq(dateMsg);
            sms.setMobile(p.getMobile());
            sms.setIp(NetworkUtil.getIpAddress(request));
            sms.setType(6);
            if (r == null) {
                // 发送失败
                logger.error("短信发送失败!");
                sms.setStatus(0);
                //throw new Exception("短信发送失败!");
            } else if (r.getInt("result") != 0) {
                sms.setStatus(0);
                smsDao.save(sms);
                return r.getString("description");
            } else {
                //发送成功,保存到数据库
                sms.setStatus(1);
            }
            smsDao.save(sms);
            BusinessLogs.info(BusinessLogs.BusinessType.appointment, getUID(), p.getCode(), new JSONObject(childImmuneRegisterRecord));
            
            return write(200, "预约成功");
        }catch (Exception e){
            error(e);
@ -262,24 +388,117 @@ public class PatientBookingController extends WeixinBaseController{
    @ObserverRequired
    @ApiOperation("计免:免疫接种取消预约")
    public String UnResRegisterImmune (@ApiParam(name="BarCode",value="新生儿条形编码",defaultValue = "")
                                  @RequestParam String BarCode,
                                  @ApiParam(name="OrgCode",value="机构编码",defaultValue = "")
                                  @RequestParam String OrgCode,
                                  @ApiParam(name="SectionType",value="坐诊类型:取号源的TIME",defaultValue = "")
                                  @RequestParam String SectionType,
                                  @ApiParam(name="strStart",value="日期:取号源的START_TIME",defaultValue = "")
                                  @RequestParam String strStart,
                                  @ApiParam(name="SSID",value="新生儿社保卡号",defaultValue = "")
                                  @RequestParam String SSID,
                                  @ApiParam(name="PatientName",value="新生儿姓名",defaultValue = "")
                                  @RequestParam String PatientName,
                                  @ApiParam(name="PatientID",value="新生儿身份证号",defaultValue = "")
                                  @RequestParam String PatientID,
                                  @ApiParam(name="PatientPhone",value="市民手机号:代预约人的手机号",defaultValue = "")
                                  @RequestParam String PatientPhone){
                                           @RequestParam(value = "BarCode", required = true) String BarCode,
                                       @ApiParam(name="OrgCode",value="机构编码",defaultValue = "")
                                           @RequestParam(value = "OrgCode", required = true) String OrgCode,
                                       @ApiParam(name="SectionType",value="坐诊类型:取号源的TIME",defaultValue = "")
                                           @RequestParam(value = "SectionType", required = true) String SectionType,
                                       @ApiParam(name="strStart",value="日期:取号源的START_TIME",defaultValue = "")
                                           @RequestParam(value = "strStart", required = true) String strStart,
                                       @ApiParam(name="SSID",value="新生儿社保卡号",defaultValue = "")
                                           @RequestParam(value = "SSID", required = true) String SSID,
                                       @ApiParam(name="PatientName",value="新生儿姓名",defaultValue = "")
                                           @RequestParam(value = "PatientName", required = true) String PatientName,
                                       @ApiParam(name="PatientID",value="新生儿身份证号",defaultValue = "")
                                           @RequestParam(value = "PatientID", required = true) String PatientID,
                                       @ApiParam(name="PatientPhone",value="市民手机号:代预约人的手机号",defaultValue = "")
                                           @RequestParam(value = "PatientPhone", required = true) String PatientPhone){
        
        try{
            immuneService.UnResRegisterImmune(BarCode,OrgCode,SectionType,strStart,SSID,PatientName,PatientID,PatientPhone);
    
            //预约发送微信消息
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            Date START_TIME_VO = dateFormat.parse(strStart);
            String date = DateUtil.dateToStrLong(START_TIME_VO);//开始时间-前端展示用
    
            Patient p = patientService.findByCode(getRepUID());
            String hospitalcode = hospitalMappingDao.getCodeByMapping(OrgCode, "1");
            Hospital hospital = hospitalDao.findByCode(hospitalcode);
    
            String msg = "您已取消了为"+PatientName+"预约的" + hospital.getName() + "的计划免疫 "+date+" 的挂号!";
            // 推送消息给微信端
            org.json.JSONObject json = new org.json.JSONObject();
            json.put("first", "");
            json.put("toUser", p.getCode());
            json.put("represented",p.getCode());//被代理人
            json.put("name", p.getName());
            json.put("date", date);
            json.put("doctorName", "-");
            json.put("orgName", hospital.getName());
            json.put("remark", p.getName() + ",您好!" + msg);
    
            //本地保存计划免疫预约记录
            ChildImmuneRegisterRecord childImmuneRegisterRecord = new ChildImmuneRegisterRecord();
            childImmuneRegisterRecord.setCode(UUID.randomUUID().toString());
            childImmuneRegisterRecord.setBarCode(BarCode);
            childImmuneRegisterRecord.setCreateTime(new Date());
            childImmuneRegisterRecord.setUpdateTime(new Date());
            childImmuneRegisterRecord.setFamilyCode(p.getCode());
            childImmuneRegisterRecord.setFamilyName(p.getName());
            childImmuneRegisterRecord.setMobile(PatientPhone);
            childImmuneRegisterRecord.setSsc(SSID);
            childImmuneRegisterRecord.setIdcard(PatientID);
            childImmuneRegisterRecord.setName(PatientName);
            childImmuneRegisterRecord.setOrgCode(hospitalcode);
            childImmuneRegisterRecord.setOrgName(hospital.getName());
            childImmuneRegisterRecord.setJwOrgcode(OrgCode);
            childImmuneRegisterRecord.setSectionType(SectionType);
            childImmuneRegisterRecord.setStartTime(START_TIME_VO);
            childImmuneRegisterRecord.setType(1);//0为预约,1为取消预约
            childImmuneRegisterRecord = childImmuneRegisterRecordDao.save(childImmuneRegisterRecord);
    
    
            //判断是否判定openId,有没有发则查找家人发送
            if(org.apache.commons.lang3.StringUtils.isNotBlank(p.getOpenid())){
                // 添加到发送队列
                pushMsgTask.putWxMsg(getAccessToken(), 7, p.getOpenid(), p.getName(), json);
            }
    
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
            if(jsonArray!=null&&jsonArray.length()>0){
                for (int i = 0;i<jsonArray.length();i++){
                    JSONObject j  = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    JSONObject data = json;
                    data.remove("toUser");
                    data.put("toUser",member.getCode());
                    //String first = (String) json.get("first");
                    data.remove("first");
                    data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),p.getName()));
                    pushMsgTask.putWxMsg(getAccessToken(), 7, member.getOpenid(), p.getName(), data);
                }
            }
    
            //发送短信消息
            //调用总部发送信息的接口
//            String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(msg, p.getMobile()), "GBK");
//            JSONObject r = toJson(result);
//            SMS sms = new SMS();
//            sms.setContent(msg);
//            sms.setCaptcha(null);
//            Date dateMsg = new Date();
//            sms.setDeadline(dateMsg);
//            sms.setCzrq(dateMsg);
//            sms.setMobile(p.getMobile());
//            sms.setIp(NetworkUtil.getIpAddress(request));
//            sms.setType(6);
//            if (r == null) {
//                // 发送失败
//                logger.error("短信发送失败!");
//                sms.setStatus(0);
//                //throw new Exception("短信发送失败!");
//            } else if (r.getInt("result") != 0) {
//                sms.setStatus(0);
//                smsDao.save(sms);
//                return r.getString("description");
//            } else {
//                //发送成功,保存到数据库
//                sms.setStatus(1);
//            }
//            smsDao.save(sms);
//            BusinessLogs.info(BusinessLogs.BusinessType.appointment, getUID(), p.getCode(), new JSONObject(childImmuneRegisterRecord));
            return write(200, "取消预约成功");
        }catch (Exception e){
            error(e);
@ -303,6 +522,41 @@ public class PatientBookingController extends WeixinBaseController{
        }
    }
    
    
    /**
     * 发送短信参数
     */
    private List<NameValuePair> buildSmsParams(String content, String mobile) {
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("SpCode", SystemConf.getInstance().getSmsCode()));
        params.add(new BasicNameValuePair("LoginName", SystemConf.getInstance().getSmsName()));
        params.add(new BasicNameValuePair("Password", SystemConf.getInstance().getSmsPassword()));
        params.add(new BasicNameValuePair("MessageContent", content));
        params.add(new BasicNameValuePair("UserNumber", mobile));
        params.add(new BasicNameValuePair("SerialNumber", String.valueOf(System.currentTimeMillis())));
        params.add(new BasicNameValuePair("ScheduleTime", ""));
        params.add(new BasicNameValuePair("f", "1"));
        return params;
    }
    
    private JSONObject toJson(String result) {
        JSONObject json = new JSONObject();
        try {
            String[] temps = result.split("&");
            for (String temp : temps) {
                if (temp.split("=").length != 2) {
                    continue;
                }
                String key = temp.split("=")[0];
                String value = temp.split("=")[1];
                json.put(key, value);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }
    
    /**
     *-----------------计划免疫预约相关接口--------------END
     */

+ 2 - 0
patient-co/patient-co-wlyy/src/main/resources/application-dev.yml

@ -110,10 +110,12 @@ es:
    HealthEduArticlePatient: health_edu_article_patient_test2
    Statistics: wlyy_quota_test
    FollowUp: wlyy_followup
    QuestionnaireWinning: wlyy_questionnaire_winning
  type:
    HealthEduArticlePatient: health_edu_article_patient_test2
    Statistics: wlyy_quota_test
    FollowUpContent: wlyy_followup_content
    QuestionnaireWinning: wlyy_questionnaire_winning
  host:  http://172.19.103.68:9200
  tHost: 172.19.103.68:9300
  clusterName: jkzl

+ 2 - 0
patient-co/patient-co-wlyy/src/main/resources/application-devtest.yml

@ -108,10 +108,12 @@ es:
    HealthEduArticlePatient: health_edu_article_patient_test3
    FollowUp: wlyy_followup
    Statistics: wlyy_quota_test
    QuestionnaireWinning: wlyy_questionnaire_winning
  type:
    HealthEduArticlePatient: health_edu_article_patient_test3
    FollowUpContent: wlyy_followup_content
    Statistics: wlyy_quota_test
    QuestionnaireWinning: wlyy_questionnaire_winning
  host:  http://172.19.103.68:9200
  tHost: 172.19.103.68:9300
  clusterName: jkzl

+ 2 - 0
patient-co/patient-co-wlyy/src/main/resources/application-local.yml

@ -102,10 +102,12 @@ es:
    HealthEduArticlePatient: health_edu_article_patient_test
    Statistics: wlyy_quota_prod
    FollowUp: wlyy_followup
    QuestionnaireWinning: wlyy_questionnaire_winning
  type:
    HealthEduArticlePatient: health_edu_article_patient_test
    Statistics: wlyy_quota_prod
    FollowUpContent: wlyy_followup_content
    QuestionnaireWinning: wlyy_questionnaire_winning
  host:  http://10.95.22.155:9200,http://10.95.22.156:9200
  tHost: 10.95.22.155:9300,10.95.22.156:9300
  clusterName: jkzl

+ 2 - 0
patient-co/patient-co-wlyy/src/main/resources/application-localtest.yml

@ -103,10 +103,12 @@ es:
    HealthEduArticlePatient: health_edu_article_patient_test
    Statistics: wlyy_quota_test
    FollowUp: wlyy_followup
    QuestionnaireWinning: wlyy_questionnaire_winning
  type:
    HealthEduArticlePatient: health_edu_article_patient_test
    Statistics: wlyy_quota_test
    FollowUpContent: wlyy_followup_content
    QuestionnaireWinning: wlyy_questionnaire_winning
  host:  http://172.19.103.68:9200
  tHost: 172.19.103.68:9300
  clusterName: jkzl

+ 2 - 0
patient-co/patient-co-wlyy/src/main/resources/application-prod.yml

@ -108,10 +108,12 @@ es:
    HealthEduArticlePatient: health_edu_article_patient
    Statistics: wlyy_quota_prod
    FollowUp: wlyy_followup
    QuestionnaireWinning: wlyy_questionnaire_winning
  type:
    HealthEduArticlePatient: health_edu_article_patient
    Statistics: wlyy_quota_prod
    FollowUpContent: wlyy_followup_content
    QuestionnaireWinning: wlyy_questionnaire_winning
  host:  http://59.61.92.90:9065,http://59.61.92.90:9067
  tHost: 59.61.92.90:9066,59.61.92.90:9068
  clusterName: jkzl

+ 2 - 0
patient-co/patient-co-wlyy/src/main/resources/application-test.yml

@ -101,10 +101,12 @@ es:
    HealthEduArticlePatient: health_edu_article_patient_test3
    FollowUp: wlyy_followup
    Statistics: wlyy_quota_test
    QuestionnaireWinning: wlyy_questionnaire_winning
  type:
    HealthEduArticlePatient: health_edu_article_patient_test3
    FollowUpContent: wlyy_followup_content
    Statistics: wlyy_quota_test
    QuestionnaireWinning: wlyy_questionnaire_winning
  host:  http://172.19.103.68:9200
  tHost: 172.19.103.68:9300
  clusterName: jkzl