Browse Source

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

lyr 8 years ago
parent
commit
db6ac0fe1d
18 changed files with 1780 additions and 1452 deletions
  1. 19 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/education/HealthEduArticlePatient.java
  2. 31 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/followup/Followup.java
  3. 19 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/patient/PatientHealthGuidance.java
  4. 18 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/patient/PatientReservation.java
  5. 3 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/consult/ConsultDao.java
  6. 2 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/followup/FollowUpDao.java
  7. 3 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientHealthGuidanceDao.java
  8. 1 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientReservationDao.java
  9. 578 563
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/followup/FollowUpService.java
  10. 127 89
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/HealthEduArticleService.java
  11. 44 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthGuidanceService.java
  12. 3 3
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/reservation/PatientReservationService.java
  13. 102 122
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/guahao/GuahaoXMService.java
  14. 24 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultController.java
  15. 325 305
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/followup/DoctorFollowUpController.java
  16. 443 364
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthEduArticleController.java
  17. 34 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthGuidanceController.java
  18. 4 4
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/BookingController.java

+ 19 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/education/HealthEduArticlePatient.java

@ -41,6 +41,10 @@ public class HealthEduArticlePatient extends IdEntity {
	private Integer read;
	// 发布时间
	private Date czrq;
	// 签约类型 1三师 2家庭
	private Integer signType;
	// 行政团队
	private Long adminTeamCode;
	public String getPatient() {
		return patient;
@ -116,4 +120,19 @@ public class HealthEduArticlePatient extends IdEntity {
		this.czrq = czrq;
	}
	public Integer getSignType() {
		return signType;
	}
	public void setSignType(Integer signType) {
		this.signType = signType;
	}
	public Long getAdminTeamCode() {
		return adminTeamCode;
	}
	public void setAdminTeamCode(Long adminTeamCode) {
		this.adminTeamCode = adminTeamCode;
	}
}

+ 31 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/followup/Followup.java

@ -53,8 +53,14 @@ public class Followup extends IdEntity {
	private String followupContentPhone;
	//创建时间
	private Date createTime;
	//更新时间
	private Date updateTime;
	//创建者
	private String creater;
	// 签约类型 1三师 2家庭
	private Integer signType;
	// 行政团队
	private Long adminTeamCode;
	public Date getFollowupPlanDate() {
		return followupPlanDate;
@ -187,6 +193,15 @@ public class Followup extends IdEntity {
		this.createTime = createTime;
	}
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getUpdateTime() {
		return updateTime;
	}
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	public String getStatus() {
		return status;
	}
@ -210,4 +225,20 @@ public class Followup extends IdEntity {
	public void setCreater(String creater) {
		this.creater = creater;
	}
	public Integer getSignType() {
		return signType;
	}
	public void setSignType(Integer signType) {
		this.signType = signType;
	}
	public Long getAdminTeamCode() {
		return adminTeamCode;
	}
	public void setAdminTeamCode(Long adminTeamCode) {
		this.adminTeamCode = adminTeamCode;
	}
}

+ 19 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/patient/PatientHealthGuidance.java

@ -36,6 +36,10 @@ public class PatientHealthGuidance extends IdEntity {
	private String del;
	// 添加时间
	private Date czrq;
	// 签约类型 1三师 2家庭
	private Integer signType;
	// 行政团队
	private Long adminTeamCode;
	public String getPatient() {
		return patient;
@ -94,4 +98,19 @@ public class PatientHealthGuidance extends IdEntity {
		this.voice = voice;
	}
	public Integer getSignType() {
		return signType;
	}
	public void setSignType(Integer signType) {
		this.signType = signType;
	}
	public Long getAdminTeamCode() {
		return adminTeamCode;
	}
	public void setAdminTeamCode(Long adminTeamCode) {
		this.adminTeamCode = adminTeamCode;
	}
}

+ 18 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/patient/PatientReservation.java

@ -68,6 +68,10 @@ public class PatientReservation extends IdEntity {
	private Date czrq;
	// 0 健康之路 1智业
	private String type;
	// 签约类型 1三师 2家庭
	private Integer signType;
	// 行政团队
	private Long adminTeamCode;
	public String getCode() {
		return code;
@ -257,4 +261,18 @@ public class PatientReservation extends IdEntity {
		this.type = type;
	}
	public Integer getSignType() {
		return signType;
	}
	public void setSignType(Integer signType) {
		this.signType = signType;
	}
	public Long getAdminTeamCode() {
		return adminTeamCode;
	}
	public void setAdminTeamCode(Long adminTeamCode) {
		this.adminTeamCode = adminTeamCode;
	}
}

+ 3 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/consult/ConsultDao.java

@ -30,4 +30,7 @@ public interface ConsultDao extends PagingAndSortingRepository<Consult, Long>, J
	@Query("select count(a) from Consult a,ConsultTeamDoctor b  where a.code = b.consult and a.patient=?1 and b.to=?2 and b.from is null")
	Integer findByPatient(String patientCode,String doctorCode);
	@Query("select a.id,a.type,a.code,a.title,a.symptoms,a.czrq,b.status,b.adminTeamId from Consult a,ConsultTeam b where a.code = b.consult and a.patient = ?1 and b.adminTeamId = ?2 and a.del = '1' order by a.czrq desc")
	Page<Object> findByPatientAndTeam(String patient,Long team, Pageable pageRequest);
}

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

@ -28,4 +28,6 @@ public interface FollowUpDao extends PagingAndSortingRepository<Followup, Long>,
    @Query(value = "select a.* from wlyy_followup a where a.doctor_code in ?1 and a.patient_code = ?2 and a.followup_class=?3 and a.status ='1' order by a.followup_date DESC limit 1",nativeQuery = true)
    Followup findLastFollowup(String[] doctors,String patientCode,String followClass) throws Exception;
    @Query("select d.code,d.name,d.photo,a.followupType,a.followupClass,a.status,a.createTime,a.updateTime from Followup a, Doctor d where a.doctorCode = d.code and a.patientCode = ?1 and a.adminTeamCode = ?2 ")
    Page<Object> findByPatientAndTeam(String patient, Long teamCode, Pageable pageable);
}

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

@ -54,4 +54,7 @@ public interface PatientHealthGuidanceDao extends PagingAndSortingRepository<Pat
	@Query("SELECT count(a) from PatientHealthGuidance a WHERE  a.patient=?2 and a.doctor=?1 ")
	Integer findbydoctorAndPatient(String doctor, String patientCode);
	@Query("select b.name, b.photo, a.id, a.content, a.czrq,b.level,b.code,a.adminTeamCode from PatientHealthGuidance a, Doctor b where a.doctor = b.code and a.patient = ?1 and a.adminTeamCode = ?2 and a.del = '1'")
	Page<Object> findByPatientAndTeamCode(String patient, Long teamCode, Pageable pageable);
}

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

@ -23,7 +23,7 @@ public interface PatientReservationDao extends PagingAndSortingRepository<Patien
	List<PatientReservation> findByPatient(String patient, Pageable page);
	List<PatientReservation> findByPatientAndDoctor(String patient,String doctor,Pageable page);
	List<PatientReservation> findByPatientAndAdminTeamCode(String patient,Long teamCode,Pageable page);
	List<PatientReservation> findByDoctor(String doctor,Pageable page);

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

@ -21,8 +21,12 @@ import com.yihu.wlyy.service.system.SystemDictService;
import com.yihu.wlyy.task.FollowupUploadTask;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
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;
@ -36,589 +40,600 @@ import java.util.*;
/**
 * 随访服务
 * @author hzp add 2016-12-07
 *
 * @author hzp add 2016-12-07
 */
@Component
@Transactional(rollbackOn = Exception.class)
public class FollowUpService extends BaseService {
	@Autowired
	private DoctorDao doctorDao;
    @Autowired
    private DoctorDao doctorDao;
    @Autowired
    private PatientDao patientDao;
	@Autowired
	private PatientDao patientDao;
    @Autowired
    private FollowUpDao followupDao;
	@Autowired
	private FollowUpDao followupDao;
    @Autowired
    private FollowupContentDao followupContentDao;
	@Autowired
	private FollowupContentDao followupContentDao;
    @Autowired
    private SystemDictService systemDictService;
	@Autowired
	private SystemDictService systemDictService;
    @Autowired
    private ObjectMapper objectMapper;
	@Autowired
	private ObjectMapper objectMapper;
    @Autowired
    private SignFamilyDao signFamilyDao;
	@Autowired
	private SignFamilyDao signFamilyDao;
    @Autowired
    private DrHealthTeamService drHealthTeamService;
	@Autowired
	private DrHealthTeamService drHealthTeamService;
    @Autowired
    private MessageDao messageDao;
	@Autowired
	private MessageDao messageDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
	@Autowired
	private JdbcTemplate jdbcTemplate;
    @Autowired
    SystemDictService dictService;
	/**
	 * 转译随访信息
    /**
     * 转译随访信息
     */
    private Map<String, String> getFollowupDetail(Followup followup) throws Exception {
        Map<String, String> re = new HashMap<>();
        //患者信息
        String patientCode = followup.getPatientCode();
        Patient patient = patientDao.findByCode(patientCode);
        if (patient != null) {
            re.put("patientCode", patientCode);
            re.put("patientName", patient.getName());
            re.put("idcard", patient.getIdcard());
            String mobile = patient.getMobile();
            if (StringUtils.isEmpty(mobile)) {
                mobile = patient.getMobileRemarks();
            }
            re.put("mobile", mobile);
            re.put("sex", String.valueOf(patient.getSex()));
            re.put("birthday", DateUtil.dateToStrLong(patient.getBirthday()));
            re.put("photo", patient.getPhoto());
        } else {
            throw new Exception("not exit patient:" + patientCode);
        }
        re.put("id", String.valueOf(followup.getId()));
        re.put("followupNo", followup.getFollowupNo());
        re.put("followupDate", DateUtil.dateToStrLong(followup.getFollowupDate()));
        re.put("followupNextDate", DateUtil.dateToStrLong(followup.getFollowupNextDate()));
        //随访方式转译
        re.put("followupType", followup.getFollowupType());
        String followupTypeName = systemDictService.getDictValue("FOLLOWUP_WAY_DICT", followup.getFollowupType());
        re.put("followupTypeName", followupTypeName);
        //随访类别转译
        re.put("followupClass", followup.getFollowupClass());
        String followupClassName = systemDictService.getDictValue("FOLLOWUP_CLASS_DICT", followup.getFollowupClass());
        re.put("followupClassName", followupClassName);
        //随访管理状态转译
        re.put("followupManagerStatus", followup.getFollowupManagerStatus());
        String followupManagerStatusName = systemDictService.getDictValue("FOLLOWUP_MANAGER_STATUS", followup.getFollowupManagerStatus());
        re.put("followupManagerStatusName", followupManagerStatusName);
        re.put("doctorCode", followup.getDoctorCode());
        re.put("doctorName", followup.getDoctorName());
        re.put("orgCode", followup.getOrgCode());
        re.put("orgName", followup.getOrgName());
        re.put("dataFrom", followup.getDataFrom());
        re.put("status", followup.getStatus());
        re.put("followupContentPhone", followup.getFollowupContentPhone());
        re.put("createTime", DateUtil.dateToStrLong(followup.getCreateTime()));
        re.put("creater", followup.getCreater());
        return re;
    }
    /**
     * 获取医生随访列表
     */
    public List<Map<String, String>> getListByDoctor(String doctorCode, String startTime, String endTime, String page, String pageSize) throws Exception {
        List<Map<String, String>> re = new ArrayList<>();
        // 排序
        Sort sort = new Sort(Sort.Direction.ASC, "followupDate");
        // 分页信息
        int pageInt = Integer.valueOf(page) - 1;
        int pageSizeInt = Integer.valueOf(pageSize);
        Pageable pageRequest = new PageRequest(pageInt, pageSizeInt, sort);
        List<Followup> list = followupDao.findByDoctor(doctorCode, DateUtil.strToDate(startTime), DateUtil.strToDate(endTime), pageRequest);
        if (list != null && list.size() > 0) {
            for (Followup followup : list) {
                Map<String, String> map = getFollowupDetail(followup);
                re.add(map);
            }
        }
        return re;
    }
    /**
     * 查询居民随访列表
     *
     * @param patient
     * @param teamCode
     * @param page
     * @param pageSize
     * @return
     */
    public JSONArray getListByPatientAndTeam(String patient, Long teamCode, int page, int pageSize) {
        PageRequest pageRequest = new PageRequest(page, pageSize);
        Page<Object> result = followupDao.findByPatientAndTeam(patient, teamCode, pageRequest);
        JSONArray array = new JSONArray();
        if (result != null && result.getContent().size() > 0) {
            Map<String, String> dictMap = new HashMap<>();
            Map<String, String> statusMap = new HashMap<>();
            List<SystemDict> dicts = dictService.getDictByDictName("FOLLOWUP_WAY_DICT");
            if (dicts != null) {
                for(SystemDict dict : dicts){
                    dictMap.put(dict.getCode(),dict.getValue());
                }
            }
            statusMap.put("0","取消");
            statusMap.put("1","已完成");
            statusMap.put("2","未开始");
            statusMap.put("3","进行中");
            for (Object obj : result) {
                JSONObject followup = new JSONObject();
                Object[] objArr = (Object[]) obj;
                followup.put("doctorCode", objArr[0]);
                followup.put("doctorName", objArr[1]);
                followup.put("doctorPhoto", objArr[2]);
                followup.put("followupType", objArr[3]);
                followup.put("followupTypeName", dictMap.get(objArr[3].toString()) != null ? dictMap.get(objArr[3].toString()) : "");
                followup.put("followupClass", objArr[4]);
                followup.put("followupClassName", objArr[4].toString().equals("1") ? "高血压" : "糖尿病");
                followup.put("status", objArr[5]);
                followup.put("statusName", statusMap.get(objArr[5].toString()) != null ? statusMap.get(objArr[5].toString()) : "");
                followup.put("createTime", objArr[6]);
                followup.put("updateTime", objArr[7]);
                array.put(followup);
            }
        }
        return array;
    }
    /**
     * 获取医生随访列表(创建者)
     */
    public List<Map<String, String>> getListByCreater(String doctorCode, String startTime, String endTime, String page, String pageSize) throws Exception {
        List<Map<String, String>> re = new ArrayList<>();
        // 排序
        Sort sort = new Sort(Sort.Direction.ASC, "followupDate");
        // 分页信息
        int pageInt = Integer.valueOf(page) - 1;
        int pageSizeInt = Integer.valueOf(pageSize);
        Pageable pageRequest = new PageRequest(pageInt, pageSizeInt, sort);
        List<Followup> list = followupDao.findByCreater(doctorCode, DateUtil.strToDate(startTime), DateUtil.strToDate(endTime), pageRequest);
        if (list != null && list.size() > 0) {
            for (Followup followup : list) {
                Map<String, String> map = getFollowupDetail(followup);
                re.add(map);
            }
        }
        return re;
    }
    /**
     * 新增随访计划(批量)
     */
    @Transactional
    public void addFollowupPlan(String doctorCode, String patientCode, String data) throws Exception {
        //批量随访计划
        JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, Map.class);
        List<Map<String, String>> list = objectMapper.readValue(data, javaType);
        if (list != null && list.size() > 0) {
            //获取患者信息
            Patient patient = patientDao.findByCode(patientCode);
            if (patient == null) {
                throw new Exception("not exit patient:" + patientCode + ".\r\n");
            }
            SignFamily signFamily = signFamilyDao.findByjiatingPatient(patientCode);
            if(signFamily == null){
                throw new Exception("can not find patient's family sign info");
            }
            List<Followup> followupPlan = new ArrayList<>();
            for (Map<String, String> map : list) {
                //获取医生信息
                Doctor doctor = doctorDao.findByCode(map.get("doctor"));
                if (doctor == null) {
                    throw new Exception("not exit doctor:" + doctorCode + ".\r\n");
                }
                Followup followup = new Followup();
                followup.setFollowupType(map.get("type"));
                Date date = DateUtil.strToDate(map.get("date"));
                followup.setFollowupDate(date);
                followup.setFollowupPlanDate(date);
                followup.setDoctorCode(doctor.getCode());
                followup.setDoctorName(doctor.getName());
                followup.setOrgCode(doctor.getHospital());
                followup.setOrgName(doctor.getHospitalName());
                followup.setPatientCode(patientCode);
                followup.setPatientName(patient.getName());
                followup.setIdcard(patient.getIdcard());
                followup.setDataFrom("2");//数据来源 1基卫 2APP
                followup.setStatus("2");     //状态 0取消 1已完成 2未开始 3进行中
                followup.setCreateTime(new Date());
                followup.setCreater(doctorCode);
                followup.setAdminTeamCode(signFamily.getAdminTeamId());
                followup.setSignType(2);
                followupPlan.add(followup);
            }
            followupDao.save(followupPlan);
        }
    }
    /**
     * 编辑随访计划
     */
    public void editFollowupPlan(String doctorCode, String id, String date, String followupType) throws Exception {
        Followup followup = followupDao.findOne(Long.valueOf(id));
        if (followup != null) {
            Date followupDate = DateUtil.strToDate(date);
            followup.setFollowupDate(followupDate);
            followup.setFollowupPlanDate(followupDate);
            followup.setFollowupType(followupType);
            followup.setCreater(doctorCode);
            followupDao.save(followup);
        } else {
            throw new Exception("not exit follow:" + id + ".\r\n");
        }
    }
    /**
     * 开始随访记录
     */
    public void startFollowup(String id, String date, String followupType, String followupClass, String followupManagerStatus) throws Exception {
        Followup followup = followupDao.findOne(Long.valueOf(id));
        if (followup != null) {
            followup.setFollowupDate(DateUtil.strToDate(date));
            followup.setFollowupType(followupType);
            followup.setFollowupClass(followupClass);
            followup.setFollowupManagerStatus(followupManagerStatus);
            followup.setStatus("3");  //状态 0取消 1已完成 2未开始 3进行中
            followupDao.save(followup);
        } else {
            throw new Exception("not exit follow:" + id + ".\r\n");
        }
    }
    /**
     * 新增临时随访记录(返回ID)
     */
    public String addFollowup(String doctorCode, String patientCode, String date, String followupType, String followupClass, String followupManagerStatus) throws Exception {
        String re = "";
        //获取医生信息
        Doctor doctor = doctorDao.findByCode(doctorCode);
        if (doctor == null) {
            throw new Exception("not exit doctor:" + doctorCode + ".\r\n");
        }
        //获取患者信息
        Patient patient = patientDao.findByCode(patientCode);
        if (patient == null) {
            throw new Exception("not exit patient:" + patientCode + ".\r\n");
        }
        SignFamily signFamily = signFamilyDao.findByjiatingPatient(patientCode);
        if(signFamily == null){
            throw new Exception("can not find patient's family sign info");
        }
        Followup followup = new Followup();
        Date followDate = DateUtil.strToDate(date);
        followup.setFollowupDate(followDate);
        followup.setFollowupPlanDate(followDate);
        followup.setDoctorCode(doctorCode);
        followup.setDoctorName(doctor.getName());
        followup.setOrgCode(doctor.getHospital());
        followup.setOrgName(doctor.getHospitalName());
        followup.setPatientCode(patientCode);
        followup.setPatientName(patient.getName());
        followup.setIdcard(patient.getIdcard());
        followup.setFollowupType(followupType);
        followup.setFollowupClass(followupClass);
        followup.setFollowupManagerStatus(followupManagerStatus);
        followup.setDataFrom("2");//数据来源 1基卫 2APP
        followup.setStatus("3");     //状态 0取消 1已完成 2未开始 3进行中
        followup.setCreateTime(new Date());
        followup.setCreater(doctorCode);
        followup.setAdminTeamCode(signFamily.getAdminTeamId());
        followup.setSignType(2);
        followupDao.save(followup);
        re = String.valueOf(followup.getId());
        return re;
    }
    /**
     * 取消随访计划
     */
	private Map<String,String> getFollowupDetail(Followup followup) throws Exception
	{
		Map<String,String> re = new HashMap<>();
		//患者信息
		String patientCode = followup.getPatientCode();
		Patient patient = patientDao.findByCode(patientCode);
		if(patient!=null) {
			re.put("patientCode",patientCode);
			re.put("patientName",patient.getName());
			re.put("idcard",patient.getIdcard());
			String mobile = patient.getMobile();
			if(StringUtils.isEmpty(mobile))
			{
				mobile = patient.getMobileRemarks();
			}
			re.put("mobile", mobile);
			re.put("sex",String.valueOf(patient.getSex()));
			re.put("birthday",DateUtil.dateToStrLong(patient.getBirthday()));
			re.put("photo",patient.getPhoto());
		}
		else{
			throw new Exception("not exit patient:"+patientCode);
		}
		re.put("id",String.valueOf(followup.getId()));
		re.put("followupNo",followup.getFollowupNo());
		re.put("followupDate",DateUtil.dateToStrLong(followup.getFollowupDate()));
		re.put("followupNextDate",DateUtil.dateToStrLong(followup.getFollowupNextDate()));
		//随访方式转译
		re.put("followupType",followup.getFollowupType());
		String followupTypeName = systemDictService.getDictValue("FOLLOWUP_WAY_DICT",followup.getFollowupType());
		re.put("followupTypeName",followupTypeName);
		//随访类别转译
		re.put("followupClass",followup.getFollowupClass());
		String followupClassName = systemDictService.getDictValue("FOLLOWUP_CLASS_DICT",followup.getFollowupClass());
		re.put("followupClassName",followupClassName);
		//随访管理状态转译
		re.put("followupManagerStatus",followup.getFollowupManagerStatus());
		String followupManagerStatusName = systemDictService.getDictValue("FOLLOWUP_MANAGER_STATUS",followup.getFollowupManagerStatus());
		re.put("followupManagerStatusName",followupManagerStatusName);
		re.put("doctorCode",followup.getDoctorCode());
		re.put("doctorName",followup.getDoctorName());
		re.put("orgCode",followup.getOrgCode());
		re.put("orgName",followup.getOrgName());
		re.put("dataFrom",followup.getDataFrom());
		re.put("status",followup.getStatus());
		re.put("followupContentPhone",followup.getFollowupContentPhone());
		re.put("createTime",DateUtil.dateToStrLong(followup.getCreateTime()));
		re.put("creater",followup.getCreater());
		return re;
	}
	/**
	 * 获取医生随访列表
    public void cancelFollowupPlan(String id) throws Exception {
        Followup followup = followupDao.findOne(Long.valueOf(id));
        if (followup != null) {
            followup.setStatus("0");  //状态 0取消 1已完成 2未开始 3进行中
            followupDao.save(followup);
        } else {
            throw new Exception("not exit follow:" + id + ".\r\n");
        }
    }
    /**
     * 完成随访记录,并上传随访记录
     */
    public void finishFollowup(String id) throws Exception {
        Followup followup = followupDao.findOne(Long.valueOf(id));
        if (followup != null) {
            followup.setStatus("1");  //状态 0取消 1已完成 2未开始 3进行中
            followupDao.save(followup);
            //上传随访计划
            new Thread(new FollowupUploadTask(String.valueOf(followup.getId()))).start();
        } else {
            throw new Exception("not exit follow:" + id + ".\r\n");
        }
    }
    /*********************************** 随访详情 *******************************************************************/
    /**
     * 获取面访项目列表
     */
    public Map<String, String> getFollowup(String id) throws Exception {
        Map<String, String> re = new HashMap<>();
        Followup followup = followupDao.findOne(Long.valueOf(id));
        if (followup != null) {
            re = getFollowupDetail(followup);
        } else {
            throw new Exception("not exit follow:" + id + ".\r\n");
        }
        return re;
    }
    /**
     * 获取面访项目列表
     */
    public List<Map<String, String>> getFollowupProject(String id) throws Exception {
        List<Map<String, String>> re = new ArrayList<>();
        //获取已填写的面访项目
        List<String> project = followupContentDao.findProjectByFollowupId(Long.valueOf(id));
        //获取所有面访项目
        List<SystemDict> dictList = systemDictService.getDictByDictName("FOLLOWUP_PROJECT");
        if (dictList != null && dictList.size() > 0) {
            for (SystemDict dict : dictList) {
                Map<String, String> map = new HashMap<>();
                String code = dict.getCode();
                map.put("projectCode", code);
                map.put("projectName", dict.getValue());
                if (project != null && project.contains(code)) {
                    map.put("status", "1"); //已填写
                } else {
                    map.put("status", "0");//未填写
                }
                re.add(map);
            }
        }
        return re;
    }
    /**
     * 获取面访项目数据
     */
    public Map<String, String> getFollowupProjectData(String id, String followupProject) throws Exception {
        Map<String, String> re = new HashMap<>();
        List<FollowupContent> dataList = followupContentDao.findByFollowupIdAndFollowupProject(Long.valueOf(id), followupProject);
        for (FollowupContent item : dataList) {
            re.put(item.getFollowupKey(), item.getFollowupValue());
        }
        return re;
    }
    /**
     * 保存面访项目数据
     */
    @Transactional
    public void saveFollowupProjectData(String id, String followupProject, String followupProjectData) throws Exception {
        List<FollowupContent> dataList = followupContentDao.findByFollowupIdAndFollowupProject(Long.valueOf(id), followupProject);
        //删除原有记录
        followupContentDao.delete(dataList);
        Map<String, String> data = objectMapper.readValue(followupProjectData, Map.class);
        if (data != null && data.keySet().size() > 0) {
            List<FollowupContent> newList = new ArrayList<>();
            for (String key : data.keySet()) {
                FollowupContent item = new FollowupContent();
                item.setFollowupId(Long.valueOf(id));
                item.setFollowupProject(followupProject);
                item.setFollowupKey(key);
                item.setFollowupValue(data.get(key));
                item.setCreateTime(new Date());
                newList.add(item);
            }
            followupContentDao.save(newList);
        }
    }
    /*********************************** 电话随访 *****************************************************************/
    /**
     * 获取电话随访内容
     */
    public String getFollowupPhone(String id) throws Exception {
        String re = "";
        Followup followup = followupDao.findOne(Long.valueOf(id));
        if (followup != null) {
            re = followup.getFollowupContentPhone();
        } else {
            throw new Exception("not exit followup:" + id + ".\r\n");
        }
        return re;
    }
    /**
     * 记录电话随访内容
     */
    public void saveFollowupPhone(String id, String content) throws Exception {
        Followup followup = followupDao.findOne(Long.valueOf(id));
        if (followup != null) {
            followup.setFollowupContentPhone(content);
            followupDao.save(followup);
        } else {
            throw new Exception("not exit followup:" + id + ".\r\n");
        }
    }
    /*************************************** 上次随访 ********************************************/
    /**
     * 获取团队医生
     */
	public List<Map<String,String>> getListByDoctor(String doctorCode,String startTime,String endTime,String page,String pageSize) throws Exception
	{
		List<Map<String,String>> re = new ArrayList<>();
		// 排序
		Sort sort = new Sort(Sort.Direction.ASC, "followupDate");
		// 分页信息
		int pageInt = Integer.valueOf(page)-1;
		int pageSizeInt =  Integer.valueOf(pageSize);
		Pageable pageRequest = new PageRequest(pageInt, pageSizeInt, sort);
		List<Followup> list = followupDao.findByDoctor(doctorCode,DateUtil.strToDate(startTime),DateUtil.strToDate(endTime),pageRequest);
		if(list!=null && list.size()>0)
		{
		    for(Followup followup : list)
			{
				Map<String,String> map = getFollowupDetail(followup);
				re.add(map);
			}
		}
		return re;
	}
	/**
	 * 获取医生随访列表(创建者)
	 */
	public List<Map<String,String>> getListByCreater(String doctorCode,String startTime,String endTime,String page,String pageSize) throws Exception
	{
		List<Map<String,String>> re = new ArrayList<>();
		// 排序
		Sort sort = new Sort(Sort.Direction.ASC, "followupDate");
		// 分页信息
		int pageInt = Integer.valueOf(page)-1;
		int pageSizeInt =  Integer.valueOf(pageSize);
		Pageable pageRequest = new PageRequest(pageInt, pageSizeInt, sort);
		List<Followup> list = followupDao.findByCreater(doctorCode,DateUtil.strToDate(startTime),DateUtil.strToDate(endTime),pageRequest);
		if(list!=null && list.size()>0)
		{
			for(Followup followup : list)
			{
				Map<String,String> map = getFollowupDetail(followup);
				re.add(map);
			}
		}
		return re;
	}
	/**
	 *新增随访计划(批量)
	 */
	@Transactional
	public void addFollowupPlan(String doctorCode,String patientCode,String data) throws Exception {
		//批量随访计划
		JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, Map.class);
		List<Map<String,String>> list = objectMapper.readValue(data,javaType);
		if(list!=null && list.size()>0)
		{
			//获取患者信息
			Patient patient = patientDao.findByCode(patientCode);
			if(patient==null)
			{
				throw new Exception("not exit patient:"+patientCode+".\r\n");
			}
			List<Followup> followupPlan = new ArrayList<>();
			for(Map<String,String> map : list)
			{
				//获取医生信息
				Doctor doctor = doctorDao.findByCode(map.get("doctor"));
				if(doctor==null)
				{
					throw new Exception("not exit doctor:"+doctorCode+".\r\n");
				}
				Followup followup = new Followup();
				followup.setFollowupType(map.get("type"));
				Date date =  DateUtil.strToDate(map.get("date"));
				followup.setFollowupDate(date);
				followup.setFollowupPlanDate(date);
				followup.setDoctorCode(doctor.getCode());
				followup.setDoctorName(doctor.getName());
				followup.setOrgCode(doctor.getHospital());
				followup.setOrgName(doctor.getHospitalName());
				followup.setPatientCode(patientCode);
				followup.setPatientName(patient.getName());
				followup.setIdcard(patient.getIdcard());
				followup.setDataFrom("2");//数据来源 1基卫 2APP
				followup.setStatus("2");     //状态 0取消 1已完成 2未开始 3进行中
				followup.setCreateTime(new Date());
				followup.setCreater(doctorCode);
				followupPlan.add(followup);
			}
			followupDao.save(followupPlan);
		}
	}
	/**
	 *编辑随访计划
	 */
	public void editFollowupPlan(String doctorCode,String id,String date,String followupType) throws Exception {
		Followup followup = followupDao.findOne(Long.valueOf(id));
		if(followup!=null)
		{
			Date followupDate = DateUtil.strToDate(date);
			followup.setFollowupDate(followupDate);
			followup.setFollowupPlanDate(followupDate);
			followup.setFollowupType(followupType);
			followup.setCreater(doctorCode);
			followupDao.save(followup);
		}
		else{
			throw new Exception("not exit follow:"+id+".\r\n");
		}
	}
	/**
	 *开始随访记录
	 */
	public void startFollowup(String id,String date,String followupType,String followupClass,String followupManagerStatus) throws Exception {
		 Followup followup = followupDao.findOne(Long.valueOf(id));
		 if(followup!=null)
		 {
			 followup.setFollowupDate(DateUtil.strToDate(date));
			 followup.setFollowupType(followupType);
			 followup.setFollowupClass(followupClass);
			 followup.setFollowupManagerStatus(followupManagerStatus);
			 followup.setStatus("3");  //状态 0取消 1已完成 2未开始 3进行中
			 followupDao.save(followup);
		 }
		else{
			 throw new Exception("not exit follow:"+id+".\r\n");
		 }
	}
	/**
	 *新增临时随访记录(返回ID)
	 */
	public String addFollowup(String doctorCode,String patientCode,String date,String followupType,String followupClass,String followupManagerStatus) throws Exception {
		String re ="";
		//获取医生信息
		Doctor doctor = doctorDao.findByCode(doctorCode);
		if(doctor==null)
		{
			throw new Exception("not exit doctor:"+doctorCode+".\r\n");
		}
		//获取患者信息
		Patient patient = patientDao.findByCode(patientCode);
		if(patient==null)
		{
			throw new Exception("not exit patient:"+patientCode+".\r\n");
		}
		Followup followup = new Followup();
		Date followDate = DateUtil.strToDate(date);
		followup.setFollowupDate(followDate);
		followup.setFollowupPlanDate(followDate);
		followup.setDoctorCode(doctorCode);
		followup.setDoctorName(doctor.getName());
		followup.setOrgCode(doctor.getHospital());
		followup.setOrgName(doctor.getHospitalName());
		followup.setPatientCode(patientCode);
		followup.setPatientName(patient.getName());
		followup.setIdcard(patient.getIdcard());
		followup.setFollowupType(followupType);
		followup.setFollowupClass(followupClass);
		followup.setFollowupManagerStatus(followupManagerStatus);
		followup.setDataFrom("2");//数据来源 1基卫 2APP
		followup.setStatus("3");     //状态 0取消 1已完成 2未开始 3进行中
		followup.setCreateTime(new Date());
		followup.setCreater(doctorCode);
		followupDao.save(followup);
		re = String.valueOf(followup.getId());
		return re;
	}
	/**
	 *取消随访计划
	 */
	public void cancelFollowupPlan(String id) throws Exception {
		Followup followup = followupDao.findOne(Long.valueOf(id));
		if(followup!=null)
		{
			followup.setStatus("0");  //状态 0取消 1已完成 2未开始 3进行中
			followupDao.save(followup);
		}
		else{
			throw new Exception("not exit follow:"+id+".\r\n");
		}
	}
	/**
	 * 完成随访记录,并上传随访记录
    private List<Doctor> getTeamDoctors(String doctor, String patient) throws Exception {
        List<Doctor> doctors = new ArrayList<>();
        //获取医生团队成员
        SignFamily signFamily = signFamilyDao.findByFamilyDoctorAndPatient(doctor, patient);
        // 查询家庭医生团队
        if (signFamily != null) {
            doctors = drHealthTeamService.findTeamDoctors(signFamily.getTeamCode());
        }
        // 查询三师团队医生
        if (doctors == null || doctors.size() == 0) {
            SignFamily sanshiSign = signFamilyDao.findBySanshiDoctorAndPatient(doctor, patient);
            if (sanshiSign != null) {
                doctors = drHealthTeamService.findTeamDoctors(patient, 1);
            } else {
                doctors = new ArrayList<>();
            }
        }
        return doctors;
    }
    /**
     * 获取上次随访
     */
	public void finishFollowup(String id) throws Exception {
		Followup followup = followupDao.findOne(Long.valueOf(id));
		if(followup!=null)
		{
			followup.setStatus("1");  //状态 0取消 1已完成 2未开始 3进行中
			followupDao.save(followup);
			//上传随访计划
			new Thread(new FollowupUploadTask(String.valueOf(followup.getId()))).start();
		}
		else{
			throw new Exception("not exit follow:"+id+".\r\n");
		}
	}
	/*********************************** 随访详情 *******************************************************************/
	/**
	 * 获取面访项目列表
	 */
	public Map<String,String> getFollowup(String id) throws Exception
	{
		Map<String,String> re = new HashMap<>();
		Followup followup = followupDao.findOne(Long.valueOf(id));
		if(followup!=null)
		{
			re = getFollowupDetail(followup);
		}
		else{
			throw new Exception("not exit follow:"+id+".\r\n");
		}
		return re;
	}
	/**
	 * 获取面访项目列表
	 */
	public List<Map<String,String>> getFollowupProject(String id) throws Exception
	{
		List<Map<String,String>> re = new ArrayList<>();
		//获取已填写的面访项目
		List<String> project = followupContentDao.findProjectByFollowupId(Long.valueOf(id));
		//获取所有面访项目
		List<SystemDict> dictList = systemDictService.getDictByDictName("FOLLOWUP_PROJECT");
		if (dictList!=null && dictList.size()>0)
		{
			for(SystemDict dict:dictList)
			{
				Map<String,String> map = new HashMap<>();
				String code = dict.getCode();
				map.put("projectCode",code);
				map.put("projectName",dict.getValue());
				if(project!=null && project.contains(code))
				{
					map.put("status","1"); //已填写
				}
				else{
					map.put("status","0");//未填写
				}
				re.add(map);
			}
		}
		return re;
	}
	/**
	 * 获取面访项目数据
	 */
	public Map<String,String> getFollowupProjectData(String id,String followupProject) throws Exception
	{
		Map<String,String> re = new HashMap<>();
		List<FollowupContent> dataList =  followupContentDao.findByFollowupIdAndFollowupProject(Long.valueOf(id),followupProject);
		for(FollowupContent item:dataList)
		{
			re.put(item.getFollowupKey(),item.getFollowupValue());
		}
		return re;
	}
	/**
	 *保存面访项目数据
	 */
	@Transactional
	public void saveFollowupProjectData(String id,String followupProject,String followupProjectData) throws Exception {
		List<FollowupContent> dataList = followupContentDao.findByFollowupIdAndFollowupProject(Long.valueOf(id),followupProject);
		//删除原有记录
		followupContentDao.delete(dataList);
		Map<String,String> data =  objectMapper.readValue(followupProjectData,Map.class);
		if(data!=null && data.keySet().size()>0)
		{
			List<FollowupContent> newList = new ArrayList<>();
			for (String key : data.keySet()) {
				FollowupContent item = new FollowupContent();
				item.setFollowupId(Long.valueOf(id));
				item.setFollowupProject(followupProject);
				item.setFollowupKey(key);
				item.setFollowupValue(data.get(key));
				item.setCreateTime(new Date());
				newList.add(item);
			}
			followupContentDao.save(newList);
		}
	}
	/*********************************** 电话随访 *****************************************************************/
	/**
	 *获取电话随访内容
	 */
	public String getFollowupPhone(String id) throws Exception {
		String re = "";
		Followup followup = followupDao.findOne(Long.valueOf(id));
		if(followup!=null)
		{
			re = followup.getFollowupContentPhone();
		}
		else {
			throw new Exception("not exit followup:"+id+".\r\n");
		}
		return re;
	}
	/**
	 *记录电话随访内容
	 */
	public void saveFollowupPhone(String id,String content) throws Exception {
		Followup followup = followupDao.findOne(Long.valueOf(id));
		if(followup!=null)
		{
			followup.setFollowupContentPhone(content);
			followupDao.save(followup);
		}
		else {
			throw new Exception("not exit followup:"+id+".\r\n");
		}
	}
	/*************************************** 上次随访 ********************************************/
	/**
	 * 获取团队医生
    public Map<String, String> getLastFollowup(String doctor, String patient, String followClass) throws Exception {
        Map<String, String> re = new HashMap<>();
        //获取医生团队成员
        String[] doctors = new String[]{doctor};
        List<Doctor> doctorList = getTeamDoctors(doctor, patient);
        if (doctorList != null && doctorList.size() > 1) {
            doctors = new String[doctorList.size()];
            for (int i = 0; i < doctorList.size(); i++) {
                doctors[i] = doctorList.get(i).getCode();
            }
        }
        //获取最新的随访记录
        Followup followup = followupDao.findLastFollowup(doctors, patient, followClass);
        if (followup != null) {
            re.put("id", String.valueOf(followup.getId()));
            re.put("followupDate", DateUtil.dateToStrShort(followup.getFollowupDate()));
        } else {
            re = null;
        }
        return re;
    }
    /**
     * 获取上次随访
     */
	private List<Doctor>  getTeamDoctors(String doctor,String patient) throws Exception
	{
		List<Doctor> doctors = new ArrayList<>();
		//获取医生团队成员
		SignFamily signFamily = signFamilyDao.findByFamilyDoctorAndPatient(doctor, patient);
		// 查询家庭医生团队
		if (signFamily != null) {
			doctors = drHealthTeamService.findTeamDoctors(signFamily.getTeamCode());
		}
		// 查询三师团队医生
		if (doctors == null || doctors.size() == 0) {
			SignFamily sanshiSign = signFamilyDao.findBySanshiDoctorAndPatient(doctor, patient);
			if (sanshiSign != null) {
				doctors = drHealthTeamService.findTeamDoctors(patient, 1);
			} else {
				doctors = new ArrayList<>();
			}
		}
		return doctors;
	}
	/**
	 * 获取上次随访
	 */
	public Map<String,String> getLastFollowup(String doctor,String patient,String followClass) throws Exception
	{
		Map<String,String> re = new HashMap<>();
		//获取医生团队成员
		String[] doctors = new String[]{doctor};
		List<Doctor> doctorList = getTeamDoctors(doctor,patient);
		if(doctorList!=null&& doctorList.size()>1)
		{
			doctors = new String[doctorList.size()];
			for(int i=0;i<doctorList.size();i++)
			{
				doctors[i] = doctorList.get(i).getCode();
			}
		}
		//获取最新的随访记录
		Followup followup = followupDao.findLastFollowup(doctors,patient,followClass);
		if(followup!=null)
		{
			re.put("id",String.valueOf(followup.getId()));
			re.put("followupDate",DateUtil.dateToStrShort(followup.getFollowupDate()));
		}
		else{
			re = null;
		}
		return re;
	}
	/**
	 * 获取上次随访
	 */
	public void copyFollowup(Long id,Long fromId) throws Exception
	{
		List<FollowupContent> list = followupContentDao.findByFollowupId(fromId);
		if(list!=null && list.size()>0)
		{
			List<FollowupContent> copyList = new ArrayList<>();
			for (FollowupContent item :list)
			{
				FollowupContent copyItem = new FollowupContent();
				copyItem.setFollowupId(id);
				copyItem.setFollowupKey(item.getFollowupKey());
				copyItem.setFollowupValue(item.getFollowupValue());
				copyItem.setFollowupProject(item.getFollowupProject());
				copyItem.setCreateTime(new Date());
				copyList.add(copyItem);
			}
			followupContentDao.save(copyList);
		}
	}
	/**************************************** 随访计划消息 ******************************************/
	/**
	 * 每日发送随访计划提醒消息
    public void copyFollowup(Long id, Long fromId) throws Exception {
        List<FollowupContent> list = followupContentDao.findByFollowupId(fromId);
        if (list != null && list.size() > 0) {
            List<FollowupContent> copyList = new ArrayList<>();
            for (FollowupContent item : list) {
                FollowupContent copyItem = new FollowupContent();
                copyItem.setFollowupId(id);
                copyItem.setFollowupKey(item.getFollowupKey());
                copyItem.setFollowupValue(item.getFollowupValue());
                copyItem.setFollowupProject(item.getFollowupProject());
                copyItem.setCreateTime(new Date());
                copyList.add(copyItem);
            }
            followupContentDao.save(copyList);
        }
    }
    /**************************************** 随访计划消息 ******************************************/
    /**
     * 每日发送随访计划提醒消息
     */
	@Transactional
	public void sendMessage(String date)
	{
	    try{
			String start = date +" 00:00:00";
			String end = date +" 23:59:59";
			String sql = "select doctor_code,count(1) count from wlyy_followup where status not in ('0','1') and followup_plan_date>='"+start+"' and followup_plan_date<='"+end+"' group by doctor_code";
			//获取所有未执行随访计划
			List<Map<String,Object>> followupToday = jdbcTemplate.queryForList(sql);
			if(followupToday!=null)
			{
				List<Message> list = new ArrayList<>();
				for(Map<String,Object> map:followupToday)
				{
					String doctor = String.valueOf(map.get("doctor_code"));
					String count = String.valueOf(map.get("count"));
					// 添加签约消息
					String title = "随访计划提醒";
					String content = "您今日有" +count+"个随访计划待处理";
					Message message = new Message();
					message.setCode(getCode());
					message.setCzrq(new Date());
					message.setContent(content);
					message.setRead(1);//设置未读
					message.setReceiver(doctor);//设置接受医生的code
					message.setSender("system");//设置发送的用户
					message.setTitle(title);
					message.setType(4);//随访计划提醒
					message.setReadonly(1);//是否只读消息
					list.add(message);
					// 推送消息给医生
					PushMsgTask.getInstance().put(doctor,"4",title,content,"");
				}
				messageDao.save(list);
			}
		}
		catch (Exception e)
		{
		   e.printStackTrace();
		}
	}
    @Transactional
    public void sendMessage(String date) {
        try {
            String start = date + " 00:00:00";
            String end = date + " 23:59:59";
            String sql = "select doctor_code,count(1) count from wlyy_followup where status not in ('0','1') and followup_plan_date>='" + start + "' and followup_plan_date<='" + end + "' group by doctor_code";
            //获取所有未执行随访计划
            List<Map<String, Object>> followupToday = jdbcTemplate.queryForList(sql);
            if (followupToday != null) {
                List<Message> list = new ArrayList<>();
                for (Map<String, Object> map : followupToday) {
                    String doctor = String.valueOf(map.get("doctor_code"));
                    String count = String.valueOf(map.get("count"));
                    // 添加签约消息
                    String title = "随访计划提醒";
                    String content = "您今日有" + count + "个随访计划待处理";
                    Message message = new Message();
                    message.setCode(getCode());
                    message.setCzrq(new Date());
                    message.setContent(content);
                    message.setRead(1);//设置未读
                    message.setReceiver(doctor);//设置接受医生的code
                    message.setSender("system");//设置发送的用户
                    message.setTitle(title);
                    message.setType(4);//随访计划提醒
                    message.setReadonly(1);//是否只读消息
                    list.add(message);
                    // 推送消息给医生
                    PushMsgTask.getInstance().put(doctor, "4", title, content, "");
                }
                messageDao.save(list);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

+ 127 - 89
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/HealthEduArticleService.java

@ -27,107 +27,145 @@ import com.yihu.wlyy.service.BaseService;
/**
 * 健康教育业务控制类
 * @author George
 *
 * @author George
 */
@Component
@Transactional(rollbackFor = Exception.class)
public class HealthEduArticleService extends BaseService {
	@Autowired
	private HealthEduArticleDao healthEduArticleDao;
	@Autowired
	private HealthEduArticlePatientDao healthEduArticlePatientDao;
	@Autowired
	private HealthEduArticleOpHistoryService healthEduArticleOpHistoryService;
	@Autowired
	private HealthEduArticleLabelService healthEduArticleLabelService;
	@Autowired
	private JdbcTemplate jdbcTemplate;
    @Autowired
    private HealthEduArticleDao healthEduArticleDao;
    @Autowired
    private HealthEduArticlePatientDao healthEduArticlePatientDao;
    @Autowired
    private HealthEduArticleOpHistoryService healthEduArticleOpHistoryService;
    @Autowired
    private HealthEduArticleLabelService healthEduArticleLabelService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 查询文章信息
     *
     * @param code
     * @return
     */
    public HealthEduArticle findArticleByCode(String code) {
        return healthEduArticleDao.findByCode(code);
    }
    /**
     * 获取文章列表
     *
     * @param page     页码
     * @param pagesize 分页大小
     * @return 列表
     */
    public List<Map<String, Object>> findAll(int page, int pagesize, String filter, String doctor, String patient) {
        if (pagesize <= 0) {
            pagesize = 10;
        }
        if (page < 0) {
            page = 0;
        }
        List<Object> params = new ArrayList<Object>();
        StringBuffer sql = new StringBuffer();
        sql.append("select a.id,a.code,a.title,a.url,a.czrq,a.content,a.keyword");
        sql.append(",(select count(1) from wlyy_health_edu_article_op_history c where c.code = a.code and c.status = 1) as readAmount");
        sql.append(",(select count(1) from wlyy_health_edu_article_op_history c where c.code = a.code and c.status = 2) as collectionAmount");
        sql.append(",(select count(1) from wlyy_health_edu_article_op_history c where c.code = a.code and c.status = 3) as repeatAmount");
        sql.append(",(select count(1) from wlyy_health_edu_article_doctor c where c.article = a.code and c.doctor =?) as collection");
        params.add(doctor);
        if (StringUtils.isNotBlank(patient)) {
            sql.append(",(select count(1) from wlyy_health_edu_article_patient c where c.article = a.code and c.doctor = ? and c.patient= ? ) as send");
            params.add(doctor);
            params.add(patient);
        }
        sql.append(" from wlyy_health_edu_article a ");//内联取文章内容
        String where = " ";
        if (StringUtils.isNotBlank(filter)) {
            //记录搜索记录
            healthEduArticleLabelService.saveOrUpdateLabel(filter, doctor);
            filter = "%" + filter + "%";
            where += " where ( a.title like ? or a.keyword like ? )";
            params.add(filter);
            params.add(filter);
        }
        int start = page * pagesize;
	/**
	 * 查询文章信息
	 * @param code
	 * @return
	 */
	public HealthEduArticle findArticleByCode(String code) {
		return healthEduArticleDao.findByCode(code);
	}
        String pageInfo = " limit " + start + "," + pagesize;
	/**
	 * 获取文章列表
	 * @param page 页码
	 * @param pagesize 分页大小
	 * @return 列表
	 */
	public List<Map<String, Object>> findAll(int page, int pagesize,String filter,String doctor,String patient) {
		if (pagesize <= 0) {
			pagesize = 10;
		}
		if(page<0){
			page = 0;
		}
		List<Object> params = new ArrayList<Object>();
		StringBuffer sql = new StringBuffer();
		sql.append("select a.id,a.code,a.title,a.url,a.czrq,a.content,a.keyword");
		sql.append(",(select count(1) from wlyy_health_edu_article_op_history c where c.code = a.code and c.status = 1) as readAmount");
		sql.append(",(select count(1) from wlyy_health_edu_article_op_history c where c.code = a.code and c.status = 2) as collectionAmount");
		sql.append(",(select count(1) from wlyy_health_edu_article_op_history c where c.code = a.code and c.status = 3) as repeatAmount");
		sql.append(",(select count(1) from wlyy_health_edu_article_doctor c where c.article = a.code and c.doctor =?) as collection");
		params.add(doctor);
		if(StringUtils.isNotBlank(patient)) {
			sql.append(",(select count(1) from wlyy_health_edu_article_patient c where c.article = a.code and c.doctor = ? and c.patient= ? ) as send");
			params.add(doctor);
			params.add(patient);
		}
		sql.append(" from wlyy_health_edu_article a ");//内联取文章内容
		String where = " ";
		if(StringUtils.isNotBlank(filter)){
			//记录搜索记录
			healthEduArticleLabelService.saveOrUpdateLabel(filter,doctor);
			filter="%"+filter+"%";
			where+=" where ( a.title like ? or a.keyword like ? )";
			params.add(filter);
			params.add(filter);
		}
		int start = page * pagesize;
        String orderBy = " order by a.czrq,a.id desc";
		String pageInfo = " limit "+start+","+pagesize;
        sql.append(where).append(orderBy).append(pageInfo);
        List<Map<String, Object>> result = jdbcTemplate.queryForList(sql.toString(), params.toArray());
        return result;
    }
		String orderBy = " order by a.czrq,a.id desc";
    /**
     * 查询给患者发送的健康教育文章
     *
     * @param patient
     * @param teamCode
     * @param page
     * @param pageSize
     * @return
     */
    public List<Map<String, Object>> findByPatientAndTeam(String patient, long teamCode, int page, int pageSize) {
        List<Object> params = new ArrayList<Object>();
        String sql = "select " +
                "    a.article" +
                "    ,a.title" +
                "    ,a.url" +
                "    ,a.czrq" +
                "    ,a.content" +
                "    ,d.code" +
                "    ,d.name" +
                "    ,d.photo" +
                "    ,a.admin_team_code" +
                "  from" +
                "    wlyy_health_edu_article_patient a" +
                "    ,wlyy_doctor d" +
                "  where" +
                "    a.doctor = d.code " +
                "    and a.patient = ?" +
                "    and a.admin_team_code = ?" +
                "  order by a.czrq desc limit " + page*pageSize + "," + pageSize;
		sql.append(where).append(orderBy).append(pageInfo);
		List<Map<String, Object>> result = jdbcTemplate.queryForList(sql.toString(),params.toArray());
		return result;
	}
        List<Map<String,Object>> result = jdbcTemplate.queryForList(sql,new Object[]{patient,teamCode});
        return result;
    }
	/**
	 * 文章更新为已读
	 * @param patient
	 * @param article
	 * @return
	 */
	public int updateRead(String patient, String article) {
		return healthEduArticlePatientDao.updateRead(patient, article);
	}
    /**
     * 文章更新为已读
     *
     * @param patient
     * @param article
     * @return
     */
    public int updateRead(String patient, String article) {
        return healthEduArticlePatientDao.updateRead(patient, article);
    }
	/**
	 * 发送文章列表
	 * @param list
	 * @return
	 */
	public int send(List<HealthEduArticlePatient> list) {
		Iterable<HealthEduArticlePatient> iterable = healthEduArticlePatientDao.save(list);
		//记录转发量
		for(HealthEduArticlePatient healthEduArticlePatient:list){
			healthEduArticleOpHistoryService.saveByStatus(HealthEduArticleOpHistory.REPEAT_STATUS,healthEduArticlePatient.getArticle(),healthEduArticlePatient.getTitle(),healthEduArticlePatient.getDoctor());
		}
		Iterator<HealthEduArticlePatient> iterator = iterable.iterator();
		if (iterator.hasNext()) {
			return 1;
		} else {
			return 0;
		}
    /**
     * 发送文章列表
     *
     * @param list
     * @return
     */
    public int send(List<HealthEduArticlePatient> list) {
        Iterable<HealthEduArticlePatient> iterable = healthEduArticlePatientDao.save(list);
        //记录转发量
        for (HealthEduArticlePatient healthEduArticlePatient : list) {
            healthEduArticleOpHistoryService.saveByStatus(HealthEduArticleOpHistory.REPEAT_STATUS, healthEduArticlePatient.getArticle(), healthEduArticlePatient.getTitle(), healthEduArticlePatient.getDoctor());
        }
        Iterator<HealthEduArticlePatient> iterator = iterable.iterator();
        if (iterator.hasNext()) {
            return 1;
        } else {
            return 0;
        }
	}
    }
}

+ 44 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthGuidanceService.java

@ -2,6 +2,8 @@ package com.yihu.wlyy.service.app.health;
import java.util.Date;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
@ -9,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@ -37,6 +40,8 @@ public class PatientHealthGuidanceService extends BaseService {
	private PatientDao patientDao;
	@Autowired
	private PatientHealthGuidanceDao patientHealthGuidanceDao;
	@Autowired
	SignFamilyDao signFamilyDao;
	public JSONObject findById(Long id){
		PatientHealthGuidance guidance = patientHealthGuidanceDao.findOne(id);
@ -63,12 +68,19 @@ public class PatientHealthGuidanceService extends BaseService {
	 * @param guidance
	 * @return
	 */
	public PatientHealthGuidance add(PatientHealthGuidance guidance, String accessToken) {
	public PatientHealthGuidance add(PatientHealthGuidance guidance, String accessToken) throws Exception {
		Doctor doctor = doctorDao.findByCode(guidance.getDoctor());
		Patient patient = patientDao.findByCode(guidance.getPatient());
		SignFamily signFamily = signFamilyDao.findByjiatingPatient(guidance.getPatient());
		if(signFamily == null){
			throw new Exception("can not find patient's family sign info");
		}
		guidance.setCzrq(new Date());
		guidance.setDel("1");
		guidance.setAdminTeamCode(signFamily.getAdminTeamId());
		guidance.setSignType(2);
		guidance = patientHealthGuidanceDao.save(guidance);
		if (guidance != null && StringUtils.isNotEmpty(patient.getOpenid())) {
			// 推送消息到微信端
@ -147,6 +159,37 @@ public class PatientHealthGuidanceService extends BaseService {
		return array;
	}
	/**
	 * 健康指导查询
	 *
	 * @param patient
	 * @param teamCode
	 * @param page
	 * @param pageSize
	 * @return
	 */
	public JSONArray findByPatientAndGuidanceAndTeam(String patient,long teamCode,int page,int pageSize){
		Sort sort = new Sort(Sort.Direction.DESC,"czrq");
		PageRequest pageRequest = new PageRequest(0, pageSize, sort);
		Page<Object> result = patientHealthGuidanceDao.findByPatientAndTeamCode(patient,teamCode,pageRequest);
		JSONArray array = new JSONArray();
		if (result != null) {
			for (Object obj : result) {
				Object[] temp = (Object[]) obj;
				JSONObject json = new JSONObject();
				json.put("doctorCode", temp[6]);
				json.put("doctorName", temp[0]);
				json.put("doctorPhoto", temp[1]);
				json.put("id", temp[2]);
				json.put("content", temp[3]);
				json.put("czrq", DateUtil.dateToStrLong((Date) temp[4]));
				json.put("adminTeamCode", temp[7]);
				array.put(json);
			}
		}
		return array;
	}
	/**
	 * 查询患者的健康指导
	 * @param patient 患者标识

+ 3 - 3
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/reservation/PatientReservationService.java

@ -181,15 +181,15 @@ public class PatientReservationService extends BaseService {
	 * 分页获取患者预约记录,医生为空查患者所有
     */
	@Transactional
	public List<PatientReservation> getReservationByPatient(String patient,String doctor, int page, int pagesize) throws Exception
	public List<PatientReservation> getReservationByPatient(String patient,Long teamCode, int page, int pagesize) throws Exception
	{
		List<PatientReservation> list = new ArrayList<>();
		// 排序
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(page-1, pagesize, sort);
		if(StringUtils.isNotBlank(doctor)){//传入医生查询医生帮此患者的预约记录
			list = patientReservationDao.findByPatientAndDoctor(patient, doctor, pageRequest);
		if(teamCode == null || teamCode < 1){//传入医生查询医生帮此患者的预约记录
			list = patientReservationDao.findByPatientAndAdminTeamCode(patient, teamCode, pageRequest);
		}else{
			list = patientReservationDao.findByPatient(patient, pageRequest);
		}

+ 102 - 122
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/guahao/GuahaoXMService.java

@ -3,8 +3,10 @@ package com.yihu.wlyy.service.third.guahao;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientReservation;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
import com.yihu.wlyy.repository.patient.PatientReservationDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.third.jw.JwSmjkService;
import com.yihu.wlyy.util.DateUtil;
@ -38,7 +40,7 @@ public class GuahaoXMService implements IGuahaoService {
    private String ORDER_CREATE = "WebRegisterVerify";  //新建预约
    private String ORDER_CANCEL = "Unregister";   //取消预约
    private String ORDER_INFO = "GetReservationRecord";//预约信息
    private String REG_LIST ="GetRegList";//获取市民预约挂号信息
    private String REG_LIST = "GetRegList";//获取市民预约挂号信息
    @Autowired
    private PatientService patientService;
@ -49,31 +51,29 @@ public class GuahaoXMService implements IGuahaoService {
    @Autowired
    private PatientReservationDao patientReservationDao;
    @Autowired
    SignFamilyDao signFamilyDao;
    private ObjectMapper objectMapper = new ObjectMapper();
    /**
     * 解析挂号后
     */
    private String CreateOrderAfter(String response,String hospitalId,String hospitalName,String hosDeptId,String hosDeptName,String doctorId,String doctorName,String sectionType,String startTime,String endTime,String patient,String patientName,String cardNo,String clinicCard,String patientPhone,String dname,String dcode) throws Exception
    {
    private String CreateOrderAfter(String response, String hospitalId, String hospitalName, String hosDeptId, String hosDeptName, String doctorId, String doctorName, String sectionType, String startTime, String endTime, String patient, String patientName, String cardNo, String clinicCard, String patientPhone, String dname, String dcode) throws Exception {
        String code = "";
        if(response.startsWith("error")||response.startsWith("System-Error"))
        {
        if (response.startsWith("error") || response.startsWith("System-Error")) {
            throw new Exception(response);
        }
        else if (response.toLowerCase().startsWith("ok")) {      //预约成功
        } else if (response.toLowerCase().startsWith("ok")) {      //预约成功
            // 预约成功,获取预约号
            code = response.replace("OK:", "").replace("ok:", "");
        }
        else if(response.split("\\|").length==3){
        } else if (response.split("\\|").length == 3) {
            code = response.split("\\|")[0];
        }
        else{
        } else {
            throw new Exception(response);
        }
        // 查询医生职称和头像
        GuahaoDoctor doctor =  GetDoctorInfo(doctorId,hospitalId,hosDeptId);
        GuahaoDoctor doctor = GetDoctorInfo(doctorId, hospitalId, hosDeptId);
        // 保存预约记录
        PatientReservation reservation = new PatientReservation();
        reservation.setCode(code);
@ -96,12 +96,20 @@ public class GuahaoXMService implements IGuahaoService {
        reservation.setStartTime(startTime);
        reservation.setEndTime(endTime);
        reservation.setStatus(1);
        if(StringUtils.isNotBlank(dname)){
        if (StringUtils.isNotEmpty(dcode)) {
            SignFamily signFamily = signFamilyDao.findByjiatingPatient(patient);
            if (signFamily == null) {
                throw new Exception("can not find patient's family sign info");
            }
            reservation.setSignType(2);
            reservation.setAdminTeamCode(signFamily.getAdminTeamId());
        }
        if (StringUtils.isNotBlank(dname)) {
            reservation.setDname(dname);//代理签约维护待签约人名称
        }
        if(StringUtils.isNotBlank(dcode)){
        if (StringUtils.isNotBlank(dcode)) {
            reservation.setDoctor(dcode);//代理签约维护待签约人编码
            SendP2PUtil.sendP2Pmsg(dcode,patient,"1","我已成功为您预约:"+startTime+","+hospitalName+hosDeptName+doctorName+"医生的号源。您可直接前往医院就诊</br><a name='guahao' href='javascript:void(0)' data-id='"+code+"'>点击查看详情</a>");
            SendP2PUtil.sendP2Pmsg(dcode, patient, "1", "我已成功为您预约:" + startTime + "," + hospitalName + hosDeptName + doctorName + "医生的号源。您可直接前往医院就诊</br><a name='guahao' href='javascript:void(0)' data-id='" + code + "'>点击查看详情</a>");
        }
        // 保存预约记录
        patientReservationDao.save(reservation);
@ -112,22 +120,21 @@ public class GuahaoXMService implements IGuahaoService {
    /**
     * 预约排班xml转列表
     */
    private List<Map<String,Object>> xmlToList(String xml) throws Exception{
        List<Map<String,Object>> re = new ArrayList<>();
    private List<Map<String, Object>> xmlToList(String xml) throws Exception {
        List<Map<String, Object>> re = new ArrayList<>();
        if (StringUtils.isEmpty(xml)) {
            // 请求失败
            throw new Exception("获取医生排班表失败!");
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        else if (StringUtils.startsWith(xml, "Error")) {
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        Document document = DocumentHelper.parseText(xml);
        Element root = document.getRootElement();
        if(root.element("doctor")!=null)     //包含doctor节点
        if (root.element("doctor") != null)     //包含doctor节点
        {
            root = root.element("doctor");
        }
@ -145,7 +152,7 @@ public class GuahaoXMService implements IGuahaoService {
            String used = e.attributeValue("used");
            // 1正常、2满号、3已过期
            String status = e.attributeValue("status");
            Map<String,Object> map = new HashMap<>();
            Map<String, Object> map = new HashMap<>();
            map.put("date", date);
            map.put("time", time);
            map.put("max", max);
@ -153,7 +160,7 @@ public class GuahaoXMService implements IGuahaoService {
            map.put("status", status);
            // 排班信息
            List<?> sections = e.elements();
            List<Map<String,String>> arrangeList = new ArrayList<>();
            List<Map<String, String>> arrangeList = new ArrayList<>();
            for (Object s : sections) {
                Element section = (Element) s;
                // 限号
@ -165,7 +172,7 @@ public class GuahaoXMService implements IGuahaoService {
                // 结束时间
                String end_time = section.attributeValue("end_time");
                Map<String,String> item = new HashMap<>();
                Map<String, String> item = new HashMap<>();
                item.put("max", s_max);
                item.put("used", s_used);
                item.put("startTime", start_time);
@ -184,23 +191,20 @@ public class GuahaoXMService implements IGuahaoService {
    /**
     * 获取医院列表
     */
    public List<Map<String,String>> GetOrgList(String city,String filter,String type,Integer pageIndex,Integer pageSize) throws Exception{
        List<Map<String,String>> re = new ArrayList<>();
    public List<Map<String, String>> GetOrgList(String city, String filter, String type, Integer pageIndex, Integer pageSize) throws Exception {
        List<Map<String, String>> re = new ArrayList<>();
        String[] values = null;
        //医院列表
        if(type.equals("1"))
        {
        if (type.equals("1")) {
            values = SOAPUtil.getCredential("<?xml version=\"1.0\" encoding=\"utf-8\"?><root type=\"1\"></root>", true);
        }
        else if(type.equals("2")) //社区列表
        } else if (type.equals("2")) //社区列表
        {
            values = SOAPUtil.getCredential("<?xml version=\"1.0\" encoding=\"utf-8\"?><root type=\"2\"></root>", true);
        }
        if(values!=null && values.length==3)
        {
        if (values != null && values.length == 3) {
            JSONArray params = new JSONArray();
            JSONObject param1 = new JSONObject();
@ -225,8 +229,7 @@ public class GuahaoXMService implements IGuahaoService {
            } else if (StringUtils.startsWith(xml, "System-Error")) {
                // 调用失败
                throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
            }
            else if (StringUtils.startsWith(xml, "Error")) {
            } else if (StringUtils.startsWith(xml, "Error")) {
                // 调用失败
                throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
            }
@ -238,24 +241,24 @@ public class GuahaoXMService implements IGuahaoService {
                String shortName = e.attribute("short_name").getValue();
                String code = e.attribute("code").getValue();
                String name = e.getText();
                Map<String,String> map = new HashMap<>();
                Map<String, String> map = new HashMap<>();
                map.put("id", code);
                map.put("name", shortName);
                map.put("address", name);
                String photo = hospitalMappingDao.getPhotoByMappingCode(code,"1");
                String photo = hospitalMappingDao.getPhotoByMappingCode(code, "1");
                map.put("photo", photo);
                re.add(map);
            }
        }
        return  re;
        return re;
    }
    /**
     * 获取科室接口
     */
    public List<Map<String,String>> GetOrgDepList(String hospitalId,String filter,Integer pageIndex,Integer pageSize) throws Exception{
        List<Map<String,String>> re = new ArrayList<>();
    public List<Map<String, String>> GetOrgDepList(String hospitalId, String filter, Integer pageIndex, Integer pageSize) throws Exception {
        List<Map<String, String>> re = new ArrayList<>();
        JSONArray params = new JSONArray();
        JSONObject param1 = new JSONObject();
@ -270,8 +273,7 @@ public class GuahaoXMService implements IGuahaoService {
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        else if (StringUtils.startsWith(xml, "Error")) {
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
@ -280,24 +282,23 @@ public class GuahaoXMService implements IGuahaoService {
        List<?> child = root.elements();
        for (Object o : child) {
            Element e = (Element) o;
            if(e.getName().equals("dept"))
            {
            if (e.getName().equals("dept")) {
                String code = e.attribute("code").getValue();
                String name = e.attribute("name").getValue();
                Map<String,String> map = new HashMap<>();
                Map<String, String> map = new HashMap<>();
                map.put("id", code);
                map.put("name", name);
                map.put("hospitalId", hospitalId);
                re.add(map);
            }
        }
        return  re;
        return re;
    }
    /**
     * 获取医生列表接口
     */
    public List<GuahaoDoctor> GetDoctorList(String hospitalId,String hosDeptId,String filter,Integer pageIndex,Integer pageSize) throws Exception{
    public List<GuahaoDoctor> GetDoctorList(String hospitalId, String hosDeptId, String filter, Integer pageIndex, Integer pageSize) throws Exception {
        List<GuahaoDoctor> re = new ArrayList<>();
        JSONArray params = new JSONArray();
@ -319,7 +320,7 @@ public class GuahaoXMService implements IGuahaoService {
        JSONObject param4 = new JSONObject();
        param4.put("key", "?strEnd");
        param4.put("value", DateUtil.getNextDay(nowDate,nextDays));  //一周后时间
        param4.put("value", DateUtil.getNextDay(nowDate, nextDays));  //一周后时间
        params.put(param4);
        String xml = SOAPUtil.post(DOCTOR_LIST, params);
@ -329,8 +330,7 @@ public class GuahaoXMService implements IGuahaoService {
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        else if (StringUtils.startsWith(xml, "Error")) {
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
@ -353,8 +353,7 @@ public class GuahaoXMService implements IGuahaoService {
            String name = e.attributeValue("name");
            // 照片
            String photo = "";
            if(e.attribute("photo")!=null)
            {
            if (e.attribute("photo") != null) {
                photo = e.attributeValue("photo");
            }
            // 挂号费
@ -382,14 +381,14 @@ public class GuahaoXMService implements IGuahaoService {
            doctor.setHospitalName(orgname);
            re.add(doctor);
        }
        return  re;
        return re;
    }
    /**
     * 获取医生排班接口(包含排班详细)
     * status 0 停诊、1正常、2满号、3已过期
     */
    public List<Map<String,Object>> GetDoctorArrange(String hospitalId,String hosDeptId,String doctorId) throws Exception{
    public List<Map<String, Object>> GetDoctorArrange(String hospitalId, String hosDeptId, String doctorId) throws Exception {
        JSONArray params = new JSONArray();
        JSONObject param1 = new JSONObject();
@ -415,20 +414,20 @@ public class GuahaoXMService implements IGuahaoService {
        JSONObject param5 = new JSONObject();
        param5.put("key", "?strEnd");
        param5.put("value", DateUtil.getNextDay(nowDate,nextDays));  //一周后时间
        param5.put("value", DateUtil.getNextDay(nowDate, nextDays));  //一周后时间
        params.put(param5);
        String xml = SOAPUtil.post(DOCTOR_ARRANGE, params);
        return  xmlToList(xml);
        return xmlToList(xml);
    }
    /**
     * 获取医生排班接口(一级)
     * status 0 停诊、1正常、2满号、3已过期
     */
    public List<Map<String,String>> GetDoctorArrangeSimple(String hospitalId,String hosDeptId,String doctorId) throws Exception{
        List<Map<String,String>> re = new ArrayList<>();
    public List<Map<String, String>> GetDoctorArrangeSimple(String hospitalId, String hosDeptId, String doctorId) throws Exception {
        List<Map<String, String>> re = new ArrayList<>();
        JSONArray params = new JSONArray();
        JSONObject param1 = new JSONObject();
@ -454,7 +453,7 @@ public class GuahaoXMService implements IGuahaoService {
        JSONObject param5 = new JSONObject();
        param5.put("key", "?strEnd");
        param5.put("value", DateUtil.getNextDay(nowDate,nextDays));  //一周后时间
        param5.put("value", DateUtil.getNextDay(nowDate, nextDays));  //一周后时间
        params.put(param5);
        String xml = SOAPUtil.post(DOCTOR_ARRANGE_SIMPLE, params);
@ -464,8 +463,7 @@ public class GuahaoXMService implements IGuahaoService {
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        else if (StringUtils.startsWith(xml, "Error")) {
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
@ -484,7 +482,7 @@ public class GuahaoXMService implements IGuahaoService {
            String used = e.attributeValue("used");
            // 1正常、2满号、3已过期
            String status = e.attributeValue("status");
            Map<String,String> map = new HashMap<>();
            Map<String, String> map = new HashMap<>();
            map.put("date", date);
            map.put("time", time);
            map.put("max", max);
@ -493,13 +491,13 @@ public class GuahaoXMService implements IGuahaoService {
            re.add(map);
        }
        return  re;
        return re;
    }
    /**
     * 创建挂号单
     */
    public String CreateOrder(String hospitalId,String hospitalName,String hosDeptId,String hosDeptName,String doctorId,String doctorName,String arrangeDate,String patient,String patientName,String cardNo,String clinicCard,String patientPhone) throws Exception{
    public String CreateOrder(String hospitalId, String hospitalName, String hosDeptId, String hosDeptName, String doctorId, String doctorName, String arrangeDate, String patient, String patientName, String cardNo, String clinicCard, String patientPhone) throws Exception {
        String re = "";
        Patient p = patientService.findByCode(patient);
@ -507,8 +505,8 @@ public class GuahaoXMService implements IGuahaoService {
            throw new Exception("患者信息不存在!");
        }
        Map<String,String> map = objectMapper.readValue(arrangeDate,Map.class);
        if(map.containsKey("sectionType") && map.containsKey("startTime")) {
        Map<String, String> map = objectMapper.readValue(arrangeDate, Map.class);
        if (map.containsKey("sectionType") && map.containsKey("startTime")) {
            String sectionType = map.get("sectionType");
            String startTime = map.get("startTime");
            String endTime = map.get("endTime");
@ -555,14 +553,13 @@ public class GuahaoXMService implements IGuahaoService {
            } else if (StringUtils.startsWith(response, "System-Error")) {
                // 调用失败
                throw new Exception(response.substring(response.indexOf(":") + 1, response.length()));
            }  else if (StringUtils.startsWith(response, "Error")) {
            } else if (StringUtils.startsWith(response, "Error")) {
                // 调用失败
                throw new Exception(response.substring(response.indexOf(":") + 1, response.length()));
            }
            re = CreateOrderAfter(response,hospitalId,hospitalName,hosDeptId,hosDeptName,doctorId,doctorName,sectionType,startTime,endTime,patient,patientName,cardNo,clinicCard,patientPhone,null,null);
        }
        else{
            re = CreateOrderAfter(response, hospitalId, hospitalName, hosDeptId, hosDeptName, doctorId, doctorName, sectionType, startTime, endTime, patient, patientName, cardNo, clinicCard, patientPhone, null, null);
        } else {
            throw new Exception("该排班信息错误或者不存在!");
        }
@ -570,13 +567,10 @@ public class GuahaoXMService implements IGuahaoService {
    }
    /**
     * 取消挂号单
     */
    public boolean CancelOrder(String orderId,String clinicCard)   throws Exception
    {
    public boolean CancelOrder(String orderId, String clinicCard) throws Exception {
        JSONArray params = new JSONArray();
        JSONObject param1 = new JSONObject();
@ -608,8 +602,7 @@ public class GuahaoXMService implements IGuahaoService {
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        else if (StringUtils.startsWith(xml, "Error")) {
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
@ -624,8 +617,7 @@ public class GuahaoXMService implements IGuahaoService {
    /**
     * 获取医生信息
     */
    public GuahaoDoctor GetDoctorInfo(String doctorId,String hospitalId,String hosDeptId) throws Exception
    {
    public GuahaoDoctor GetDoctorInfo(String doctorId, String hospitalId, String hosDeptId) throws Exception {
        GuahaoDoctor doctor = new GuahaoDoctor();
        JSONArray params = new JSONArray();
@ -644,7 +636,7 @@ public class GuahaoXMService implements IGuahaoService {
        params.put(param3);
        JSONObject param4 = new JSONObject();
        param4.put("key", "?strEnd");
        param4.put("value", DateUtil.getNextDay(nowDate,nextDays));  //一周后时间
        param4.put("value", DateUtil.getNextDay(nowDate, nextDays));  //一周后时间
        params.put(param4);
        String xml = SOAPUtil.post(DOCTOR_LIST, params);
@ -654,8 +646,7 @@ public class GuahaoXMService implements IGuahaoService {
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        else if (StringUtils.startsWith(xml, "Error")) {
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
@ -667,8 +658,7 @@ public class GuahaoXMService implements IGuahaoService {
            // 医生编码
            String code = e.attributeValue("code");
            if(code.equals(doctorId))
            {
            if (code.equals(doctorId)) {
                // 性别
                String sex = e.attributeValue("sex");
                // 职称
@ -681,8 +671,7 @@ public class GuahaoXMService implements IGuahaoService {
                String name = e.attributeValue("name");
                // 照片
                String photo = "";
                if(e.attribute("photo")!=null)
                {
                if (e.attribute("photo") != null) {
                    photo = e.attributeValue("photo");
                }
                // 挂号费
@ -711,15 +700,14 @@ public class GuahaoXMService implements IGuahaoService {
                break;
            }
        }
        return  doctor;
        return doctor;
    }
    /**
     * 获取预约状态
     * 0 撤销 1 确认 2 已诊  3停诊
     */
    public Integer GetOrderStatus(String hospitalId,String orderId,String clinicCard) throws Exception
    {
    public Integer GetOrderStatus(String hospitalId, String orderId, String clinicCard) throws Exception {
        Integer re = null;
        try {
            StringBuffer sb = new StringBuffer();
@ -789,9 +777,7 @@ public class GuahaoXMService implements IGuahaoService {
            } else {
                throw new Exception("获取预约状态失败!");
            }
        }
        catch (Exception ex)
        {
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return re;
@ -800,10 +786,9 @@ public class GuahaoXMService implements IGuahaoService {
    /**
     * 根据患者医保卡获取近三个月的预约记录
     */
    public List<PatientReservation> GetRegList(String patientCode,String strStart,String strEnd) throws Exception
    {
    public List<PatientReservation> GetRegList(String patientCode, String strStart, String strEnd) throws Exception {
        Patient patient = patientService.findByCode(patientCode);
        if(patient==null){
        if (patient == null) {
            throw new Exception("不存在该用户!");
        }
@ -830,7 +815,7 @@ public class GuahaoXMService implements IGuahaoService {
        params.put(param4);
        JSONObject param5 = new JSONObject();
        param5.put("key", "?strKey");
        param5.put("value",values[2]);  //一周后时间
        param5.put("value", values[2]);  //一周后时间
        params.put(param5);
        String xml = SOAPUtil.post(REG_LIST, params);
        if (StringUtils.isEmpty(xml)) {
@ -839,8 +824,7 @@ public class GuahaoXMService implements IGuahaoService {
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        else if (StringUtils.startsWith(xml, "Error")) {
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
@ -849,7 +833,7 @@ public class GuahaoXMService implements IGuahaoService {
        List<?> child = root.elements();
        if(child.size()>0) {
        if (child.size() > 0) {
            for (Object o : child) {
                Element e = (Element) o;
                // 医生编码
@ -918,8 +902,7 @@ public class GuahaoXMService implements IGuahaoService {
    /**
     * 根据患者,预约编号,机构编号获取单条记录预约记录
     */
    public PatientReservation getRegDetail(String patientCode,String orgCode,String regCode) throws Exception
    {
    public PatientReservation getRegDetail(String patientCode, String orgCode, String regCode) throws Exception {
        //获取签名信息
        Patient patient = patientService.findByCode(patientCode);
        StringBuffer sb = new StringBuffer();
@ -953,8 +936,7 @@ public class GuahaoXMService implements IGuahaoService {
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        else if (StringUtils.startsWith(xml, "Error"))  {
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
@ -962,12 +944,11 @@ public class GuahaoXMService implements IGuahaoService {
        Element root = document.getRootElement();
        List<?> child = root.elements();
        if(patient==null){
        if (patient == null) {
            throw new Exception("获取挂号人员信息失败!");
        }
        if(child.size()>0)
        {
        if (child.size() > 0) {
            Element e = (Element) child.get(0);
            // 医生编码
            String regdate = e.attributeValue("regdate");//预约日期
@ -979,14 +960,14 @@ public class GuahaoXMService implements IGuahaoService {
            String OrgCode = e.attributeValue("org_code");//医疗机构编码
            String org = e.attributeValue("org_name");//医疗机构名称
            String DeptCode = e.attributeValue("dept_code");//科室代码
            String dept =e.attributeValue("dept_name");//科室
            String dept = e.attributeValue("dept_name");//科室
            String DoctorCode = e.attributeValue("doctor_code");//医生代码
            String doctor = e.attributeValue("doctor_name");//医生
            String Introduction = e.attributeValue("introduction");//医生简介
            String status = e.attributeValue("status");//状态:删除、新建、确认、已诊
            String enter_time = e.attributeValue("enter_time");//预约登记时间
            String notes = e.attributeValue("notes");//备注
            String code  = e.getText();//预约号
            String code = e.getText();//预约号
            PatientReservation patientReservation = new PatientReservation();
            patientReservation.setCode(code);
            patientReservation.setSectionType(time);
@ -1005,7 +986,7 @@ public class GuahaoXMService implements IGuahaoService {
            patientReservation.setName(patient.getName());
            patientReservation.setIdcard(patient.getIdcard());
            patientReservation.setPhone(patient.getMobile());
            switch (status){
            switch (status) {
                case "删除":
                    patientReservation.setStatus(0);
                    break;
@ -1018,30 +999,31 @@ public class GuahaoXMService implements IGuahaoService {
                case "已诊":
                    patientReservation.setStatus(3);
                    break;
                default:patientReservation.setStatus(4);
            };
                default:
                    patientReservation.setStatus(4);
            }
            ;
            patientReservation.setSsc(patient.getSsc());
            GuahaoDoctor guahaoDoctor = GetDoctorInfo(DoctorCode, OrgCode, DeptCode);
            patientReservation.setDoctorPhoto(guahaoDoctor.getPhoto());//照片
            patientReservation.setDoctorJob(guahaoDoctor.getTitle());//职称
            return patientReservation;
        }
        else{
        } else {
            return null;
        }
    }
    @Autowired
    JwSmjkService jwSmjkService;
    /******************************** 基卫内网服务 ************************************************/
    public List<Map<String,Object>> GetDoctorArrangeTenDay(String hospitalId,String hosDeptId,String doctorId) throws Exception {
    public List<Map<String, Object>> GetDoctorArrangeTenDay(String hospitalId, String hosDeptId, String doctorId) throws Exception {
        String strStart = DateUtil.getStringDateShort(); //当前时间;
        String strEnd = DateUtil.getNextDay(strStart,11);         //10天预约
        String strEnd = DateUtil.getNextDay(strStart, 11);         //10天预约
        String response = jwSmjkService.getRegDeptSpeDoctorSectionList(hospitalId,hosDeptId,strStart,strEnd,doctorId);
        String response = jwSmjkService.getRegDeptSpeDoctorSectionList(hospitalId, hosDeptId, strStart, strEnd, doctorId);
        return xmlToList(response);
    }
@ -1049,8 +1031,7 @@ public class GuahaoXMService implements IGuahaoService {
    /**
     * 转诊预约挂号
     */
    public String CreateOrderByDoctor(String hospitalId,String hospitalName,String hosDeptId,String hosDeptName,String doctorId,String doctorName,String arrangeDate,String patient,String patientName,String cardNo,String clinicCard,String patientPhone,String dname,String dcode) throws Exception
    {
    public String CreateOrderByDoctor(String hospitalId, String hospitalName, String hosDeptId, String hosDeptName, String doctorId, String doctorName, String arrangeDate, String patient, String patientName, String cardNo, String clinicCard, String patientPhone, String dname, String dcode) throws Exception {
        String re = "";
        Patient p = patientService.findByCode(patient);
@ -1058,17 +1039,16 @@ public class GuahaoXMService implements IGuahaoService {
            throw new Exception("患者信息不存在!");
        }
        Map<String,String> map = objectMapper.readValue(arrangeDate,Map.class);
        if(map.containsKey("sectionType") && map.containsKey("startTime")) {
        Map<String, String> map = objectMapper.readValue(arrangeDate, Map.class);
        if (map.containsKey("sectionType") && map.containsKey("startTime")) {
            String sectionType = map.get("sectionType");
            String startTime = map.get("startTime");
            String endTime = map.get("endTime");
            String response = jwSmjkService.webRegisterByFamily(cardNo,patientName,clinicCard,sectionType,startTime,hospitalId,hosDeptId,hosDeptName,doctorId,doctorName);
            String response = jwSmjkService.webRegisterByFamily(cardNo, patientName, clinicCard, sectionType, startTime, hospitalId, hosDeptId, hosDeptName, doctorId, doctorName);
            re = CreateOrderAfter(response,hospitalId,hospitalName,hosDeptId,hosDeptName,doctorId,doctorName,sectionType,startTime,endTime,patient,patientName,cardNo,clinicCard,patientPhone,dname,dcode);
        }
        else{
            re = CreateOrderAfter(response, hospitalId, hospitalName, hosDeptId, hosDeptName, doctorId, doctorName, sectionType, startTime, endTime, patient, patientName, cardNo, clinicCard, patientPhone, dname, dcode);
        } else {
            throw new Exception("该排班信息错误或者不存在!");
        }

+ 24 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultController.java

@ -15,6 +15,8 @@ import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.util.IdCardUtil;
import com.yihu.wlyy.util.MessageType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
@ -164,6 +166,28 @@ public class DoctorConsultController extends WeixinBaseController {
        }
    }
    @RequestMapping(value = "list_by_team", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    @ApiOperation(value = "居民咨询列表查询")
    public String listByTeam(@RequestParam @ApiParam(value = "居民Code") String patient,
                             @RequestParam @ApiParam(value = "团队Code") Long teamCode,
                             @RequestParam @ApiParam(value = "第几页") int page,
                             @RequestParam @ApiParam(value = "页大小") int pagesize) {
        try {
            if (StringUtils.isEmpty(patient)) {
                return error(-1, "请输入需查询的居民");
            }
            if (teamCode == null || teamCode < 1) {
                return error(-1, "请输入需查询的居民的团队");
            }
            page = page > 0 ? page - 1 : 0;
            JSONArray jsonArray = consultTeamService.findByPatientAndTeam(patient, teamCode, page, pagesize);
            return write(200, "查询成功", "data", jsonArray);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
        }
    }
    /**
     * 获取三师家庭咨询
     *

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

@ -13,10 +13,7 @@ import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
@ -26,313 +23,336 @@ import com.yihu.wlyy.web.BaseController;
/**
 * 医生端:随访接口
 * 
 * @author hzp add 2016-12-07
 *
 * @author hzp add 2016-12-07
 */
@Controller
@RequestMapping(value = "/doctor/followup", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "医生端-随访接口")
public class DoctorFollowUpController extends BaseController {
	@Autowired
	private FollowUpService followUpService;
	/*************************************** 随访计划 ****************************************************************************/
	@ApiOperation("获取随访列表")
	@RequestMapping(value = "/list", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	public String getList(@ApiParam(name="startTime",value="开始时间",defaultValue = "2016-12-07 00:00:00")
							  @RequestParam(value="startTime",required = true) String startTime,
							  @ApiParam(name="endTime",value="结束时间",defaultValue = "2016-12-14 00:00:00")
							  @RequestParam(value="endTime",required = true) String endTime,
						      @ApiParam(name="page",value="第几页",defaultValue = "1")
							  @RequestParam(value="page",required = true) String page,
							  @ApiParam(name="pageSize",value="每页几行",defaultValue = "10")
							  @RequestParam(value="pageSize",required = true) String pageSize) {
		try {
			List<Map<String,String>> result = followUpService.getListByDoctor(getUID(),startTime,endTime,page,pageSize);     //"64de9952-5b15-11e6-8344-fa163e8aee56"
			return write(200, "获取随访列表成功!", "data", result);
		} catch (Exception e) {
			return invalidUserException(e, -1, "获取随访列表失败!"+e.getMessage());
		}
	}
	@ApiOperation("获取随访列表(创建者)")
	@RequestMapping(value = "/createrList", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	public String getCreaterList(@ApiParam(name="startTime",value="开始时间",defaultValue = "2016-12-07 00:00:00")
						  @RequestParam(value="startTime",required = true) String startTime,
						  @ApiParam(name="endTime",value="结束时间",defaultValue = "2016-12-14 00:00:00")
						  @RequestParam(value="endTime",required = true) String endTime,
						  @ApiParam(name="page",value="第几页",defaultValue = "1")
						  @RequestParam(value="page",required = true) String page,
						  @ApiParam(name="pageSize",value="每页几行",defaultValue = "10")
						  @RequestParam(value="pageSize",required = true) String pageSize) {
		try {
			List<Map<String,String>> result = followUpService.getListByCreater(getUID(),startTime,endTime,page,pageSize);     //"64de9952-5b15-11e6-8344-fa163e8aee56"
			return write(200, "获取随访列表成功!", "data", result);
		} catch (Exception e) {
			return invalidUserException(e, -1, "获取随访列表失败!"+e.getMessage());
		}
	}
	@ApiOperation("新增随访计划(批量)")
	@RequestMapping(value = "/addFollowupPlan", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public String addFollowupPlan(@ApiParam(name="patient",value="患者代码",defaultValue = "443a196ef8744536a531260eb26c05d7")
						  @RequestParam(value="patient",required = true) String patient,
						  @ApiParam(name="data",value="随访计划列表json",defaultValue = "[{\"date\":\"2016-12-16 20:00:00\",\"type\":\"10\",\"doctor\":\"64de9952-5b15-11e6-8344-fa163e8aee56\"},{\"date\":\"2016-12-17 15:00:00\",\"type\":\"3\",\"doctor\":\"64de9952-5b15-11e6-8344-fa163e8aee56\"}]")
						  @RequestParam(value="data",required = true) String data) {
		try {
			followUpService.addFollowupPlan(getUID(),patient,data);
			return write(200, "新增随访计划成功!");
		} catch (Exception e) {
			return invalidUserException(e, -1, "新增随访计划失败!"+e.getMessage());
		}
	}
	@ApiOperation("编辑随访计划")
	@RequestMapping(value = "/editFollowupPlan", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public String editFollowupPlan(@ApiParam(name="id",value="随访记录ID",defaultValue = "")
								@RequestParam(value="id",required = true) String id,
								@ApiParam(name="planDate",value="随访计划时间",defaultValue = "2016-12-14 20:00:00")
								@RequestParam(value="planDate",required = true) String planDate,
								@ApiParam(name="followupType",value="随访方式【字典FOLLOWUP_WAY_DICT】",defaultValue = "12")
								@RequestParam(value="followupType",required = true) String followupType) {
		try {
			followUpService.editFollowupPlan(getUID(),id,planDate,followupType);
			return write(200, "编辑随访计划成功!");
		} catch (Exception e) {
			return invalidUserException(e, -1, "编辑随访计划失败!"+e.getMessage());
		}
	}
	@ApiOperation("开始随访记录")
	@RequestMapping(value = "/startFollowup", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public String startFollowup(@ApiParam(name="id",value="随访记录ID",defaultValue = "")
								 @RequestParam(value="id",required = true) String id,
								 @ApiParam(name="date",value="随访时间",defaultValue = "2016-12-14 20:00:00")
								 @RequestParam(value="date",required = true) String date,
								 @ApiParam(name="followupType",value="随访方式【字典FOLLOWUP_WAY_DICT】",defaultValue = "12")
								 @RequestParam(value="followupType",required = true) String followupType,
								 @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) {
		try {
			followUpService.startFollowup(id,date,followupType,followupClass,followupManagerStatus);
			return write(200, "开始随访记录成功!");
		} catch (Exception e) {
			return invalidUserException(e, -1, "开始随访记录失败!"+e.getMessage());
		}
	}
	@ApiOperation("新增临时随访记录(返回ID)")
	@RequestMapping(value = "/addFollowup", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public String addFollowup(@ApiParam(name="patient",value="患者代码",defaultValue = "443a196ef8744536a531260eb26c05d7")
								@RequestParam(value="patient",required = true) String patient,
								@ApiParam(name="date",value="下次随访时间",defaultValue = "2016-12-15 20:00:00")
								@RequestParam(value="date",required = true) String date,
								@ApiParam(name="followupType",value="随访方式【字典FOLLOWUP_WAY_DICT】",defaultValue = "12")
								@RequestParam(value="followupType",required = true) String followupType,
								@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) {
		try {
			String response = followUpService.addFollowup(getUID(),patient,date,followupType,followupClass,followupManagerStatus);
			return write(200, "新增临时随访记录成功!","data",response);
		} catch (Exception e) {
			return invalidUserException(e, -1, "新增临时随访记录失败!"+e.getMessage());
		}
	}
	@ApiOperation("取消随访计划")
	@RequestMapping(value = "/cancelFollowupPlan", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public String cancelFollowupPlan(@ApiParam(name="id",value="随访记录ID",defaultValue = "")
								      @RequestParam(value="id",required = true) String id)
	{
		try {
			followUpService.cancelFollowupPlan(id);
			return write(200, "取消随访计划成功!");
		} catch (Exception e) {
			return invalidUserException(e, -1, "取消随访计划失败!"+e.getMessage());
		}
	}
	@ApiOperation("完成随访记录")
	@RequestMapping(value = "/finishFollowup", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public String finishFollowup(@ApiParam(name="id",value="随访记录ID",defaultValue = "")
									 @RequestParam(value="id",required = true) String id)
	{
		try {
			followUpService.finishFollowup(id);
			return write(200, "完成随访记录成功!");
		} catch (Exception e) {
			return invalidUserException(e, -1, "完成随访记录失败!"+e.getMessage());
		}
	}
	/*********************************** 随访详情 *******************************************************************/
	@ApiOperation("获取随访信息")
	@RequestMapping(value = "/getFollowup", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	public String getFollowup(@ApiParam(name="id",value="随访记录ID",defaultValue = "4")
									 @RequestParam(value="id",required = true) String id)
	{
		try {
			Map<String,String> response = followUpService.getFollowup(id);
			return write(200, "获取随访信息成功!","data",response);
		} catch (Exception e) {
			return invalidUserException(e, -1, "获取随访信息失败!"+e.getMessage());
		}
	}
	@ApiOperation("获取随访项目列表")
	@RequestMapping(value = "/getFollowupProject", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	public String getFollowupProject(@ApiParam(name="id",value="随访记录ID",defaultValue = "4")
									 @RequestParam(value="id",required = true) String id)
	{
		try {
			List<Map<String,String>> list = followUpService.getFollowupProject(id);
			return write(200, "获取随访项目列表成功!","data",list);
		} catch (Exception e) {
			return invalidUserException(e, -1, "获取随访项目列表失败!"+e.getMessage());
		}
	}
	@ApiOperation("获取随访项目数据")
	@RequestMapping(value = "/getFollowupProjectData", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	public String getFollowupProjectData(@ApiParam(name="id",value="随访记录ID",defaultValue = "4")
									 @RequestParam(value="id",required = true) String id,
									 @ApiParam(name="followupProject",value="随访项目",defaultValue = "2")
									 @RequestParam(value="followupProject",required = true) String followupProject)
	{
		try {
			Map<String,String> response = followUpService.getFollowupProjectData(id,followupProject);
			return write(200, "获取随访项目数据成功!","data",response);
		} catch (Exception e) {
			return invalidUserException(e, -1, "获取随访项目数据失败!"+e.getMessage());
		}
	}
	@ApiOperation("保存随访项目数据")
	@RequestMapping(value = "/saveFollowupProjectData", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public String saveFollowupProjectData(@ApiParam(name="id",value="随访记录ID",defaultValue = "4")
								   @RequestParam(value="id",required = true) String id,
								   @ApiParam(name="followupProject",value="随访项目",defaultValue = "2")
								   @RequestParam(value="followupProject",required = true) String followupProject,
								   @ApiParam(name="followupProjectData",value="随访项目数据",defaultValue = "{\"WEIGHT\":\"76\",\"WEIGHT_EXP\":\"60\",\"BMI\":\"11\"}")
								   @RequestParam(value="followupProjectData",required = true) String followupProjectData)
	{
		try {
			followUpService.saveFollowupProjectData(id,followupProject,followupProjectData);
			return write(200, "保存随访项目数据成功!");
		} catch (Exception e) {
			return invalidUserException(e, -1, "保存随访项目数据失败!"+e.getMessage());
		}
	}
	/*********************************** 电话随访 *****************************************************************/
	@ApiOperation("获取电话随访内容")
	@RequestMapping(value = "/getFollowupPhone", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	public String getFollowupPhone(@ApiParam(name="id",value="随访记录ID",defaultValue = "")
									@RequestParam(value="id",required = true) String id) {
		try {
			String response = followUpService.getFollowupPhone(id);
			return write(200, "获取电话随访内容成功!","data",response);
		} catch (Exception e) {
			return invalidUserException(e, -1, "获取电话随访内容失败!"+e.getMessage());
		}
	}
	@ApiOperation("记录电话随访内容")
	@RequestMapping(value = "/saveFollowupPhone", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public String saveFollowupPhone(@ApiParam(name="id",value="随访记录ID",defaultValue = "")
								  @RequestParam(value="id",required = true) String id,
								  @ApiParam(name="content",value="电话随访内容",defaultValue = "")
								  @RequestParam(value="content",required = true) String content) {
		try {
			followUpService.saveFollowupPhone(id,content);
			return write(200, "记录电话随访内容成功!");
		} catch (Exception e) {
			return invalidUserException(e, -1, "记录电话随访内容失败!"+e.getMessage());
		}
	}
	/*************************************** 上次随访 ********************************************/
	@ApiOperation("获取上次随访")
	@RequestMapping(value = "/getLastFollowup", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	public String getLastFollowup(@ApiParam(name="patient",value="患者代码",defaultValue = "P20161008001")
								   @RequestParam(value="patient",required = true) String patient,
								   @ApiParam(name="followClass",value="随访类别",defaultValue = "1")
								   @RequestParam(value="followClass",required = true) String followClass)
	{
		try {
			Map<String,String> response = followUpService.getLastFollowup(getUID(),patient,followClass);
			return write(200, "获取上次随访成功!","data",response);
		} catch (Exception e) {
			return invalidUserException(e, -1, "获取上次随访失败!"+e.getMessage());
		}
	}
	@ApiOperation("复制上次随访数据")
	@RequestMapping(value = "/copyFollowup", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public String copyFollowup(@ApiParam(name="id",value="本地随访ID",defaultValue = "")
								  @RequestParam(value="id",required = true) Long id,
								  @ApiParam(name="fromId",value="拷贝随访记录ID",defaultValue = "")
								  @RequestParam(value="fromId",required = true) Long fromId)
	{
		try {
			followUpService.copyFollowup(id,fromId);
			return write(200, "复制上次随访成功!");
		} catch (Exception e) {
			return invalidUserException(e, -1, "复制上次随访失败!"+e.getMessage());
		}
	}
	/*************************************** 发送随访计划消息 ********************************************/
	@ApiOperation("发送随访计划消息")
	@RequestMapping(value = "/sendMessage", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	public String sendMessage(@ApiParam(name="date",value="日期",defaultValue = "2017-01-05")
								  @RequestParam(value="date",required = true) String date)
	{
		try {
			followUpService.sendMessage(date);
			return write(200, "发送随访计划消息成功!");
		} catch (Exception e) {
			return invalidUserException(e, -1, "发送随访计划消息失败!"+e.getMessage());
		}
	}
    @Autowired
    private FollowUpService followUpService;
    /*************************************** 随访计划 ****************************************************************************/
    @ApiOperation("获取随访列表")
    @RequestMapping(value = "/list", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public String getList(@ApiParam(name = "startTime", value = "开始时间", defaultValue = "2016-12-07 00:00:00")
                          @RequestParam(value = "startTime", required = true) String startTime,
                          @ApiParam(name = "endTime", value = "结束时间", defaultValue = "2016-12-14 00:00:00")
                          @RequestParam(value = "endTime", required = true) String endTime,
                          @ApiParam(name = "page", value = "第几页", defaultValue = "1")
                          @RequestParam(value = "page", required = true) String page,
                          @ApiParam(name = "pageSize", value = "每页几行", defaultValue = "10")
                          @RequestParam(value = "pageSize", required = true) String pageSize) {
        try {
            List<Map<String, String>> result = followUpService.getListByDoctor(getUID(), startTime, endTime, page, pageSize);     //"64de9952-5b15-11e6-8344-fa163e8aee56"
            return write(200, "获取随访列表成功!", "data", result);
        } catch (Exception e) {
            return invalidUserException(e, -1, "获取随访列表失败!" + e.getMessage());
        }
    }
    /**
     * 查询居民随访列表
     *
     * @param patient
     * @param teamCode
     * @param page
     * @param pagesize
     * @return
     */
    @RequestMapping(value = "/list_by_team")
    @ResponseBody
    @ApiOperation(value = "查询居民随访列表")
    public String getListByPatientAndTeam(@RequestParam @ApiParam(value = "居民Code") String patient,
                                          @RequestParam @ApiParam(value = "团队code") Long teamCode,
                                          @RequestParam @ApiParam(value = "第几页") int page,
                                          @RequestParam @ApiParam(value = "页大小") int pagesize) {
        try {
            if (StringUtils.isEmpty(patient)) {
                return error(-1, "请输入需查询的居民");
            }
            if (teamCode == null || teamCode < 1) {
                return error(-1, "请输入需查询的居民的团队");
            }
            JSONArray result = followUpService.getListByPatientAndTeam(patient, teamCode, page, pagesize);
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
    @ApiOperation("获取随访列表(创建者)")
    @RequestMapping(value = "/createrList", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public String getCreaterList(@ApiParam(name = "startTime", value = "开始时间", defaultValue = "2016-12-07 00:00:00")
                                 @RequestParam(value = "startTime", required = true) String startTime,
                                 @ApiParam(name = "endTime", value = "结束时间", defaultValue = "2016-12-14 00:00:00")
                                 @RequestParam(value = "endTime", required = true) String endTime,
                                 @ApiParam(name = "page", value = "第几页", defaultValue = "1")
                                 @RequestParam(value = "page", required = true) String page,
                                 @ApiParam(name = "pageSize", value = "每页几行", defaultValue = "10")
                                 @RequestParam(value = "pageSize", required = true) String pageSize) {
        try {
            List<Map<String, String>> result = followUpService.getListByCreater(getUID(), startTime, endTime, page, pageSize);     //"64de9952-5b15-11e6-8344-fa163e8aee56"
            return write(200, "获取随访列表成功!", "data", result);
        } catch (Exception e) {
            return invalidUserException(e, -1, "获取随访列表失败!" + e.getMessage());
        }
    }
    @ApiOperation("新增随访计划(批量)")
    @RequestMapping(value = "/addFollowupPlan", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public String addFollowupPlan(@ApiParam(name = "patient", value = "患者代码", defaultValue = "443a196ef8744536a531260eb26c05d7")
                                  @RequestParam(value = "patient", required = true) String patient,
                                  @ApiParam(name = "data", value = "随访计划列表json", defaultValue = "[{\"date\":\"2016-12-16 20:00:00\",\"type\":\"10\",\"doctor\":\"64de9952-5b15-11e6-8344-fa163e8aee56\"},{\"date\":\"2016-12-17 15:00:00\",\"type\":\"3\",\"doctor\":\"64de9952-5b15-11e6-8344-fa163e8aee56\"}]")
                                  @RequestParam(value = "data", required = true) String data) {
        try {
            followUpService.addFollowupPlan(getUID(), patient, data);
            return write(200, "新增随访计划成功!");
        } catch (Exception e) {
            return invalidUserException(e, -1, "新增随访计划失败!" + e.getMessage());
        }
    }
    @ApiOperation("编辑随访计划")
    @RequestMapping(value = "/editFollowupPlan", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public String editFollowupPlan(@ApiParam(name = "id", value = "随访记录ID", defaultValue = "")
                                   @RequestParam(value = "id", required = true) String id,
                                   @ApiParam(name = "planDate", value = "随访计划时间", defaultValue = "2016-12-14 20:00:00")
                                   @RequestParam(value = "planDate", required = true) String planDate,
                                   @ApiParam(name = "followupType", value = "随访方式【字典FOLLOWUP_WAY_DICT】", defaultValue = "12")
                                   @RequestParam(value = "followupType", required = true) String followupType) {
        try {
            followUpService.editFollowupPlan(getUID(), id, planDate, followupType);
            return write(200, "编辑随访计划成功!");
        } catch (Exception e) {
            return invalidUserException(e, -1, "编辑随访计划失败!" + e.getMessage());
        }
    }
    @ApiOperation("开始随访记录")
    @RequestMapping(value = "/startFollowup", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public String startFollowup(@ApiParam(name = "id", value = "随访记录ID", defaultValue = "")
                                @RequestParam(value = "id", required = true) String id,
                                @ApiParam(name = "date", value = "随访时间", defaultValue = "2016-12-14 20:00:00")
                                @RequestParam(value = "date", required = true) String date,
                                @ApiParam(name = "followupType", value = "随访方式【字典FOLLOWUP_WAY_DICT】", defaultValue = "12")
                                @RequestParam(value = "followupType", required = true) String followupType,
                                @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) {
        try {
            followUpService.startFollowup(id, date, followupType, followupClass, followupManagerStatus);
            return write(200, "开始随访记录成功!");
        } catch (Exception e) {
            return invalidUserException(e, -1, "开始随访记录失败!" + e.getMessage());
        }
    }
    @ApiOperation("新增临时随访记录(返回ID)")
    @RequestMapping(value = "/addFollowup", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public String addFollowup(@ApiParam(name = "patient", value = "患者代码", defaultValue = "443a196ef8744536a531260eb26c05d7")
                              @RequestParam(value = "patient", required = true) String patient,
                              @ApiParam(name = "date", value = "下次随访时间", defaultValue = "2016-12-15 20:00:00")
                              @RequestParam(value = "date", required = true) String date,
                              @ApiParam(name = "followupType", value = "随访方式【字典FOLLOWUP_WAY_DICT】", defaultValue = "12")
                              @RequestParam(value = "followupType", required = true) String followupType,
                              @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) {
        try {
            String response = followUpService.addFollowup(getUID(), patient, date, followupType, followupClass, followupManagerStatus);
            return write(200, "新增临时随访记录成功!", "data", response);
        } catch (Exception e) {
            return invalidUserException(e, -1, "新增临时随访记录失败!" + e.getMessage());
        }
    }
    @ApiOperation("取消随访计划")
    @RequestMapping(value = "/cancelFollowupPlan", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public String cancelFollowupPlan(@ApiParam(name = "id", value = "随访记录ID", defaultValue = "")
                                     @RequestParam(value = "id", required = true) String id) {
        try {
            followUpService.cancelFollowupPlan(id);
            return write(200, "取消随访计划成功!");
        } catch (Exception e) {
            return invalidUserException(e, -1, "取消随访计划失败!" + e.getMessage());
        }
    }
    @ApiOperation("完成随访记录")
    @RequestMapping(value = "/finishFollowup", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public String finishFollowup(@ApiParam(name = "id", value = "随访记录ID", defaultValue = "")
                                 @RequestParam(value = "id", required = true) String id) {
        try {
            followUpService.finishFollowup(id);
            return write(200, "完成随访记录成功!");
        } catch (Exception e) {
            return invalidUserException(e, -1, "完成随访记录失败!" + e.getMessage());
        }
    }
    /*********************************** 随访详情 *******************************************************************/
    @ApiOperation("获取随访信息")
    @RequestMapping(value = "/getFollowup", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public String getFollowup(@ApiParam(name = "id", value = "随访记录ID", defaultValue = "4")
                              @RequestParam(value = "id", required = true) String id) {
        try {
            Map<String, String> response = followUpService.getFollowup(id);
            return write(200, "获取随访信息成功!", "data", response);
        } catch (Exception e) {
            return invalidUserException(e, -1, "获取随访信息失败!" + e.getMessage());
        }
    }
    @ApiOperation("获取随访项目列表")
    @RequestMapping(value = "/getFollowupProject", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public String getFollowupProject(@ApiParam(name = "id", value = "随访记录ID", defaultValue = "4")
                                     @RequestParam(value = "id", required = true) String id) {
        try {
            List<Map<String, String>> list = followUpService.getFollowupProject(id);
            return write(200, "获取随访项目列表成功!", "data", list);
        } catch (Exception e) {
            return invalidUserException(e, -1, "获取随访项目列表失败!" + e.getMessage());
        }
    }
    @ApiOperation("获取随访项目数据")
    @RequestMapping(value = "/getFollowupProjectData", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public String getFollowupProjectData(@ApiParam(name = "id", value = "随访记录ID", defaultValue = "4")
                                         @RequestParam(value = "id", required = true) String id,
                                         @ApiParam(name = "followupProject", value = "随访项目", defaultValue = "2")
                                         @RequestParam(value = "followupProject", required = true) String followupProject) {
        try {
            Map<String, String> response = followUpService.getFollowupProjectData(id, followupProject);
            return write(200, "获取随访项目数据成功!", "data", response);
        } catch (Exception e) {
            return invalidUserException(e, -1, "获取随访项目数据失败!" + e.getMessage());
        }
    }
    @ApiOperation("保存随访项目数据")
    @RequestMapping(value = "/saveFollowupProjectData", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public String saveFollowupProjectData(@ApiParam(name = "id", value = "随访记录ID", defaultValue = "4")
                                          @RequestParam(value = "id", required = true) String id,
                                          @ApiParam(name = "followupProject", value = "随访项目", defaultValue = "2")
                                          @RequestParam(value = "followupProject", required = true) String followupProject,
                                          @ApiParam(name = "followupProjectData", value = "随访项目数据", defaultValue = "{\"WEIGHT\":\"76\",\"WEIGHT_EXP\":\"60\",\"BMI\":\"11\"}")
                                          @RequestParam(value = "followupProjectData", required = true) String followupProjectData) {
        try {
            followUpService.saveFollowupProjectData(id, followupProject, followupProjectData);
            return write(200, "保存随访项目数据成功!");
        } catch (Exception e) {
            return invalidUserException(e, -1, "保存随访项目数据失败!" + e.getMessage());
        }
    }
    /*********************************** 电话随访 *****************************************************************/
    @ApiOperation("获取电话随访内容")
    @RequestMapping(value = "/getFollowupPhone", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public String getFollowupPhone(@ApiParam(name = "id", value = "随访记录ID", defaultValue = "")
                                   @RequestParam(value = "id", required = true) String id) {
        try {
            String response = followUpService.getFollowupPhone(id);
            return write(200, "获取电话随访内容成功!", "data", response);
        } catch (Exception e) {
            return invalidUserException(e, -1, "获取电话随访内容失败!" + e.getMessage());
        }
    }
    @ApiOperation("记录电话随访内容")
    @RequestMapping(value = "/saveFollowupPhone", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public String saveFollowupPhone(@ApiParam(name = "id", value = "随访记录ID", defaultValue = "")
                                    @RequestParam(value = "id", required = true) String id,
                                    @ApiParam(name = "content", value = "电话随访内容", defaultValue = "")
                                    @RequestParam(value = "content", required = true) String content) {
        try {
            followUpService.saveFollowupPhone(id, content);
            return write(200, "记录电话随访内容成功!");
        } catch (Exception e) {
            return invalidUserException(e, -1, "记录电话随访内容失败!" + e.getMessage());
        }
    }
    /*************************************** 上次随访 ********************************************/
    @ApiOperation("获取上次随访")
    @RequestMapping(value = "/getLastFollowup", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public String getLastFollowup(@ApiParam(name = "patient", value = "患者代码", defaultValue = "P20161008001")
                                  @RequestParam(value = "patient", required = true) String patient,
                                  @ApiParam(name = "followClass", value = "随访类别", defaultValue = "1")
                                  @RequestParam(value = "followClass", required = true) String followClass) {
        try {
            Map<String, String> response = followUpService.getLastFollowup(getUID(), patient, followClass);
            return write(200, "获取上次随访成功!", "data", response);
        } catch (Exception e) {
            return invalidUserException(e, -1, "获取上次随访失败!" + e.getMessage());
        }
    }
    @ApiOperation("复制上次随访数据")
    @RequestMapping(value = "/copyFollowup", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public String copyFollowup(@ApiParam(name = "id", value = "本地随访ID", defaultValue = "")
                               @RequestParam(value = "id", required = true) Long id,
                               @ApiParam(name = "fromId", value = "拷贝随访记录ID", defaultValue = "")
                               @RequestParam(value = "fromId", required = true) Long fromId) {
        try {
            followUpService.copyFollowup(id, fromId);
            return write(200, "复制上次随访成功!");
        } catch (Exception e) {
            return invalidUserException(e, -1, "复制上次随访失败!" + e.getMessage());
        }
    }
    /*************************************** 发送随访计划消息 ********************************************/
    @ApiOperation("发送随访计划消息")
    @RequestMapping(value = "/sendMessage", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public String sendMessage(@ApiParam(name = "date", value = "日期", defaultValue = "2017-01-05")
                              @RequestParam(value = "date", required = true) String date) {
        try {
            followUpService.sendMessage(date);
            return write(200, "发送随访计划消息成功!");
        } catch (Exception e) {
            return invalidUserException(e, -1, "发送随访计划消息失败!" + e.getMessage());
        }
    }
}

+ 443 - 364
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthEduArticleController.java

@ -4,6 +4,8 @@ import java.util.*;
import com.yihu.wlyy.entity.education.*;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.app.health.*;
import com.yihu.wlyy.service.app.label.SignPatientLabelInfoService;
import com.yihu.wlyy.service.common.account.PatientService;
@ -11,6 +13,8 @@ import com.yihu.wlyy.util.SendP2PUtil;
import com.yihu.wlyy.web.WeixinBaseController;
import com.yihu.wlyy.web.doctor.message.DoctorMessageController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.htmlparser.Parser;
import org.htmlparser.beans.StringBean;
@ -36,375 +40,450 @@ import com.yihu.wlyy.web.BaseController;
/**
 * 医生端:健康教育控制类
 * @author George
 *
 * @author George
 */
@Controller
@RequestMapping(value = "/doctor/health/edu", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "健康教育")
public class DoctorHealthEduArticleController extends WeixinBaseController {
	@Autowired
	private HealthEduArticleService healthEduArticleService;
	@Autowired
	private DoctorService doctorService;
	@Autowired
	private HealthEduArticleOpHistoryService healthEduArticleOpHistoryService;
	@Autowired
	private SignPatientLabelInfoService signPatientLabelInfoService;
	@Autowired
	private HealthEduArticlePatientService healthEduArticlePatientService;
	@Autowired
	private HealthEduArticleDoctorService healthEduArticleDoctorService;
	@Autowired
	private HealthEduArticleLabelService healthEduArticleLabelService;
	@Autowired
	private PatientService patientService;
	/**
	 * 查询
	 * @param pagesize 分页大小
	 * @return 列表
	 */
	@RequestMapping(value = "list")
	@ResponseBody
	public String list(@RequestParam(value = "page",required = true)int page, @RequestParam(value = "pagesize",required = true)int pagesize,@RequestParam(value = "filter",required = false)String filter,@RequestParam(value = "patient",required = false)String patient) {
		try {
			List<Map<String, Object>> list = healthEduArticleService.findAll(page, pagesize,filter,getUID(),patient);
			JSONArray jsonArray = new JSONArray();
			if (list != null) {
				for (Map<String, Object> map : list) {
					JSONObject json = new JSONObject();
					json.put("id", map.get("id"));
					// 文章标识
					json.put("code", map.get("code"));
					// 文章标题
					json.put("title", map.get("title"));
					// 文章查看URL
					json.put("url", map.get("url"));
					// 文章简介
					json.put("content", parsrHtml(map.get("content").toString()));
					// 添加日期
					json.put("czrq", DateUtil.dateToStrLong((Date)map.get("czrq")));
					json.put("keyword", map.get("keyword")==null?"":map.get("keyword"));
					json.put("send", map.get("send"));
					//阅读量
					json.put("readAmount", map.get("readAmount"));
					//收藏量
					json.put("collectionAmount", map.get("collectionAmount"));
					//转发量
					json.put("repeatAmount", map.get("repeatAmount"));
					json.put("collection",map.get("collection"));
					jsonArray.put(json);
				}
			}
			return write(200, "查询成功", "list", jsonArray);
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "查询失败!");
		}
	}
	/**
	 * 查询医生收藏列表
	 * @param pagesize 分页大小
	 * @return 列表
	 */
	@RequestMapping(value = "listDoctor")
	@ResponseBody
	public String listDoctor(@RequestParam(value = "page",required = true)int page, @RequestParam(value = "pagesize",required = true)int pagesize,@RequestParam(value = "filter",required = false)String filter,@RequestParam(value = "patient",required = false)String patient) {
		try {
			List<Map<String, Object>> list = healthEduArticleDoctorService.list(page, pagesize,filter,getUID(),patient);
			JSONArray jsonArray = new JSONArray();
			for(Map<String, Object> map:list){
				JSONObject json = new JSONObject();
				json.put("id", map.get("id"));
				// 文章标识
				json.put("code", map.get("article"));
				// 文章标题
				json.put("title", map.get("title"));
				// 文章查看URL
				json.put("url", map.get("url"));
				// 文章简介
				json.put("content", parsrHtml(map.get("content").toString()));
				// 添加日期
				json.put("czrq", DateUtil.dateToStrLong((Date)map.get("czrq")));
				json.put("keyword", map.get("keyword"));
				json.put("send", map.get("send"));
				//阅读量
				json.put("readAmount", map.get("readAmount"));
				//收藏量
				json.put("collectionAmount", map.get("collectionAmount"));
				//转发量
				json.put("repeatAmount", map.get("repeatAmount"));
				//是否收藏(医生收藏的列表肯定是收藏的无需额外校验)
				json.put("collection",1);
				jsonArray.put(json);
			}
			return write(200, "查询成功", "list", jsonArray);
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "查询失败!");
		}
	}
	/**
	 * 查询标签列表
	 * @param pagesize 分页大小
	 * @return 列表
	 */
	@RequestMapping(value = "listLabel")
	@ResponseBody
	public String listLabel(@RequestParam(value = "page",required = true)int page, @RequestParam(value = "pagesize",required = true)int pagesize,@RequestParam(value = "type",required = false,defaultValue = "0")int type) {
		try {
			Page<HealthEduArticleLabel> list = healthEduArticleLabelService.findAll(page,pagesize,type,getUID());
			return write(200, "查询成功", "list", list);
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "查询失败!");
		}
	}
	/**
	 * 查询文章列表
	 * @param code 数据文章唯一标示code
	 * @return 列表
	 */
	@RequestMapping(value = "article")
	@ResponseBody
	public String article(@RequestParam(value = "code",required = true) String code) {
		try {
			//获取单条文章记录
			HealthEduArticle healthEduArticle = healthEduArticleService.findArticleByCode(code);
			int isRead  = healthEduArticleOpHistoryService.countByUserStatus(getUID(), HealthEduArticleOpHistory.READ_STATUS);
			//插入文章读取状态第一次阅读记录浏览数量
			if(isRead==0){
				//更新浏览量
				healthEduArticleOpHistoryService.saveByStatus(HealthEduArticleOpHistory.READ_STATUS,healthEduArticle.getCode(),healthEduArticle.getTitle(),getUID());
			}
			JSONObject json = new JSONObject();
			json.put("id", healthEduArticle.getId());
			// 文章标识
			json.put("code", healthEduArticle.getCode());
			// 文章标题
			json.put("title", healthEduArticle.getTitle());
			json.put("url", healthEduArticle.getUrl()==null?"":healthEduArticle.getUrl());
			// 文章内容
			json.put("content", healthEduArticle.getContent());
			// 添加日期
			json.put("czrq", DateUtil.dateToStrLong(healthEduArticle.getCzrq()));
			int readAmount = healthEduArticleOpHistoryService.countReadAmount(code);
			json.put("readAmount",readAmount);
			HealthEduArticleDoctor healthEduArticleDoctor = healthEduArticleDoctorService.findByArticle(healthEduArticle.getCode(), getUID());
			if(healthEduArticleDoctor==null){
				json.put("collection",0);
			}else{
				json.put("collection",1);
			}
			return write(200, "查询成功", "data", json);
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "查询失败!");
		}
	}
	/**
	 * 发送文章给患者
	 * @param code 文章标识,多个以逗号分隔
	 * @param patient 患者标识,多个以逗号分隔
	 * @param  group 所选群组,多个用逗号分隔
	 * @return
	 */
	@RequestMapping(value = "send")
	@ResponseBody
	public String send(@RequestParam(value = "code")String code,
					   @RequestParam(value = "patient",required = false)String patient,
					   @RequestParam(value = "group",required = false,defaultValue = "")String group,
					   @RequestParam(value = "labelType",required = false)String labelType,
					   @RequestParam(value = "teamCode",required = false)long teamCode) {
		try {
			List<HealthEduArticlePatient> list = new ArrayList<HealthEduArticlePatient>();
			if (StringUtils.isEmpty(code)) {
				return error(-1, "请至少选择一篇文章!");
			}
			if (StringUtils.isEmpty(patient)&&StringUtils.isEmpty(group)) {
				return error(-1, "请至少选择一个患者!");
			}
			String[] articles = code.split(",");
			String[] patients = patient.split(",");
			String[] groups = group.split(",");
			if (articles.length == 0) {
				return error(-1, "请至少选择一篇文章!");
			}
			if (patients.length == 0&&groups.length==0) {
				return error(-1, "请至少选择一个患者!");
			}
			Map<String, HealthEduArticle> maps = new HashMap<String, HealthEduArticle>();
			Set<String> patientSet = new HashSet<>();
			if(StringUtils.isNotBlank(group)&&groups.length>0){
				//递归患者数据
				for(String g :groups){
					getPatientByGroup(g,labelType,teamCode,patientSet,0,100);
				}
			}
			//去重操作
			for (String p : patients) {
				if(StringUtils.isNotBlank(p)){
					patientSet.add(p);
				}
			}
			if(patientSet.size()==0){
				return error(-1, "请至少选择一个患者!");
			}
			// 查询医生信息
			Doctor doctor = doctorService.findDoctorByCode(getUID());
			String msgHead =  doctor.getName()+"医生给您发来了一篇患教文章";
			String endMsg = "为了您的健康,"+doctor.getName()+"医生给您发送了一篇患教文章,请仔细查阅,如有问题,可随时咨询医生。";
			JSONArray messages = new JSONArray();
			for (String p : patientSet) {
				Patient patientTemp = patientService.findByCode(p);
				for (String a : articles) {
					// 查询文章信息
					HealthEduArticle temp = maps.get(a);
					if (temp == null) {
						temp = healthEduArticleService.findArticleByCode(a);
						// 添加到缓存
						maps.put(a, temp);
					}
					HealthEduArticlePatient heap = new HealthEduArticlePatient();
					// 设置文章标识
					heap.setArticle(a);
					// 设置文章简介
					heap.setContent(temp.getContent());
					// 设置文章标题
					heap.setTitle(temp.getTitle());
					// 设置文章查看URL
					heap.setUrl(temp.getUrl());
					// 设置发送时间
					heap.setCzrq(new Date());
					// 设置医生标识
					heap.setDoctor(doctor.getCode());
					// 设置医生姓名
					heap.setDoctorName(doctor.getName());
					// 设置患者标识
					heap.setPatient(p);
					// 设置为示读
					heap.setRead(1);
					list.add(heap);
					SendP2PUtil.sendP2Pmsg(doctor.getCode(), p, "4", "{\"title\":\"" + temp.getTitle() + "\",\"id\":\"" + temp.getCode() + "\",\"img\":\"" + temp.getUrl() + "\",\"content\":\"为了您的健康,我给您发送了一篇文章,请咨询查阅,如有问题,可随时与我沟通\"}");
					if (StringUtils.isNotEmpty(patientTemp.getOpenid())) {
						// 推送消息给微信端
						JSONObject json = new JSONObject();
						json.put("first", patientTemp.getName() + ",您好!\n" + msgHead);
						json.put("toUser",p);
						json.put("article",temp.getCode()+"");
						json.put("title",temp.getTitle());
						json.put("doctorName",doctor.getName());
						json.put("date", DateUtil.dateToStrLong(DateUtil.getNowDate()));
						json.put("remark", endMsg);
						PushMsgTask.getInstance().putWxMsg(getAccessToken(), 9, patientTemp.getOpenid(), patientTemp.getName(), json);
					}
				}
			}
			// 保存到数据库
			int row = healthEduArticleService.send(list);
			if (row <= 0) {
				return error(-1, "发送失败!");
			} else {
				// 推送消息给患者
				PushMsgTask.getInstance().put(messages);
				return success("发送成功!");
			}
		} catch (Exception e) {
			error(e);
			return error(-1, "发送失败!");
		}
	}
	private void getPatientByGroup(String labelCode, String labelType, Long teamCode,Set<String> patientSet,int page,int pagesize) throws Exception{
		JSONArray result = signPatientLabelInfoService.getPatientByLabel(getUID(), labelCode, labelType, teamCode, page, pagesize);
		for(Object o : result){
			JSONObject json  = (JSONObject)o;
			String patient  = (String)json.get("code");
			patientSet.add(patient);
		}
		if(result.length()==100){
			getPatientByGroup(labelCode,labelType,teamCode,patientSet,page+1,pagesize);
		}
	}
	/**
	 * 文章收藏
	 * @param article 文章CODE
	 * @return
	 */
	@RequestMapping(value = "collectionArticle")
	@ResponseBody
	public String collectionArticle(@RequestParam(value = "article",required = true)String article){
		HealthEduArticleDoctor healthEduArticleDoctor = healthEduArticleDoctorService.findByArticle(article,getUID());
		if(healthEduArticleDoctor!=null){
			return error(-1, "收藏失败,该文章已经收藏!");
		}
		HealthEduArticle healthEduArticle =	healthEduArticleService.findArticleByCode(article);
		healthEduArticleDoctor = new HealthEduArticleDoctor();
		try{
			BeanUtils.copyProperties(healthEduArticle,healthEduArticleDoctor);
			healthEduArticleDoctor.setDoctor(getUID());
			healthEduArticleDoctor.setArticle(healthEduArticle.getCode());
			healthEduArticleDoctorService.save(healthEduArticleDoctor);
			//更新收藏量
			healthEduArticleOpHistoryService.saveByStatus(HealthEduArticleOpHistory.COLLECTION_STATUS,healthEduArticle.getCode(),healthEduArticle.getTitle(),getUID());
			return success("收藏成功!");
		}catch (Exception e){
			error(e);
			return error(-1, "收藏失败!");
		}
	}
	/**
	 * 文章收藏
	 * @param article 文章CODE
	 * @return
	 */
	@RequestMapping(value = "uncollectionArticle")
	@ResponseBody
	public String uncollectionArticle(@RequestParam(value = "article",required = true)String article){
		try{
			healthEduArticleDoctorService.delete(article,getUID());
			return success("取消收藏成功!");
		}catch (Exception e){
			error(e);
			return error(-1, "取消收藏失败!");
		}
	}
	private String parsrHtml(String html) {
		html =("<span>"+html+"</span>");//拼接一个HTML标签,防止纯文字字符串转换在linux下面出现的异常。
		Parser parser = null;
		try{
			parser = new Parser(html);
			TextExtractingVisitor visitor = new TextExtractingVisitor();
			parser.visitAllNodesWith(visitor);
			return StringUtils.isNotBlank(visitor.getExtractedText())?visitor.getExtractedText():"内容为图集,请点击查看";
		}catch (ParserException e){
			return html;//纯文本内容会转换失败,直接返回文本内容
		}
	}
	public static void main(String arg[]){
		System.out.println(MessageType.MESSAGE_TYPE_PATIENT_HEALTH_EDU.P_HE_01.name());
	}
    @Autowired
    private HealthEduArticleService healthEduArticleService;
    @Autowired
    private DoctorService doctorService;
    @Autowired
    private HealthEduArticleOpHistoryService healthEduArticleOpHistoryService;
    @Autowired
    private SignPatientLabelInfoService signPatientLabelInfoService;
    @Autowired
    private HealthEduArticlePatientService healthEduArticlePatientService;
    @Autowired
    private HealthEduArticleDoctorService healthEduArticleDoctorService;
    @Autowired
    private HealthEduArticleLabelService healthEduArticleLabelService;
    @Autowired
    private PatientService patientService;
    @Autowired
    SignFamilyDao signFamilyDao;
    /**
     * 查询
     *
     * @param pagesize 分页大小
     * @return 列表
     */
    @RequestMapping(value = "list")
    @ResponseBody
    public String list(@RequestParam(value = "page", required = true) int page, @RequestParam(value = "pagesize", required = true) int pagesize, @RequestParam(value = "filter", required = false) String filter, @RequestParam(value = "patient", required = false) String patient) {
        try {
            List<Map<String, Object>> list = healthEduArticleService.findAll(page, pagesize, filter, getUID(), patient);
            JSONArray jsonArray = new JSONArray();
            if (list != null) {
                for (Map<String, Object> map : list) {
                    JSONObject json = new JSONObject();
                    json.put("id", map.get("id"));
                    // 文章标识
                    json.put("code", map.get("code"));
                    // 文章标题
                    json.put("title", map.get("title"));
                    // 文章查看URL
                    json.put("url", map.get("url"));
                    // 文章简介
                    json.put("content", parsrHtml(map.get("content").toString()));
                    // 添加日期
                    json.put("czrq", DateUtil.dateToStrLong((Date) map.get("czrq")));
                    json.put("keyword", map.get("keyword") == null ? "" : map.get("keyword"));
                    json.put("send", map.get("send"));
                    //阅读量
                    json.put("readAmount", map.get("readAmount"));
                    //收藏量
                    json.put("collectionAmount", map.get("collectionAmount"));
                    //转发量
                    json.put("repeatAmount", map.get("repeatAmount"));
                    json.put("collection", map.get("collection"));
                    jsonArray.put(json);
                }
            }
            return write(200, "查询成功", "list", jsonArray);
        } catch (Exception ex) {
            error(ex);
            return invalidUserException(ex, -1, "查询失败!");
        }
    }
    /**
     * 查询发送给居民的文章列表
     *
     * @param pagesize 分页大小
     * @return 列表
     */
    @RequestMapping(value = "list_by_team", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    @ApiOperation(value = "查询发送给居民的文章列表")
    public String listByTeam(@RequestParam @ApiParam(value = "第几页") int page,
                             @RequestParam @ApiParam(value = "页大小") int pagesize,
                             @RequestParam @ApiParam(value = "居民code") String patient,
                             @RequestParam @ApiParam(value = "团队code") Long teamCode) {
        try {
            if (StringUtils.isEmpty(patient)) {
                return error(-1, "请输入需查询的居民");
            }
            if (teamCode == null || teamCode < 1) {
                return error(-1, "请输入需查询的居民的团队");
            }
            List<Map<String, Object>> list = healthEduArticleService.findByPatientAndTeam(patient, teamCode, page, pagesize);
            JSONArray jsonArray = new JSONArray();
            if (list != null) {
                for (Map<String, Object> map : list) {
                    JSONObject json = new JSONObject();
                    // 文章标识
                    json.put("doctorCode", map.get("code"));
                    // 文章标识
                    json.put("doctorName", map.get("name"));
                    // 文章标识
                    json.put("doctorPhoto", map.get("photo"));
                    // 文章标识
                    json.put("code", map.get("article"));
                    // 文章标题
                    json.put("title", map.get("title"));
                    // 文章查看URL
                    json.put("url", map.get("url"));
                    // 文章简介
                    json.put("content", parsrHtml(map.get("content").toString()));
                    // 发送日期
                    json.put("czrq", DateUtil.dateToStrLong((Date) map.get("czrq")));
                    // 发送团队
                    json.put("adminTeamCode", map.get("admin_team_code"));
                    jsonArray.put(json);
                }
            }
            return write(200, "查询成功", "list", jsonArray);
        } catch (Exception ex) {
            error(ex);
            return invalidUserException(ex, -1, "查询失败!");
        }
    }
    /**
     * 查询医生收藏列表
     *
     * @param pagesize 分页大小
     * @return 列表
     */
    @RequestMapping(value = "listDoctor")
    @ResponseBody
    public String listDoctor(@RequestParam(value = "page", required = true) int page, @RequestParam(value = "pagesize", required = true) int pagesize, @RequestParam(value = "filter", required = false) String filter, @RequestParam(value = "patient", required = false) String patient) {
        try {
            List<Map<String, Object>> list = healthEduArticleDoctorService.list(page, pagesize, filter, getUID(), patient);
            JSONArray jsonArray = new JSONArray();
            for (Map<String, Object> map : list) {
                JSONObject json = new JSONObject();
                json.put("id", map.get("id"));
                // 文章标识
                json.put("code", map.get("article"));
                // 文章标题
                json.put("title", map.get("title"));
                // 文章查看URL
                json.put("url", map.get("url"));
                // 文章简介
                json.put("content", parsrHtml(map.get("content").toString()));
                // 添加日期
                json.put("czrq", DateUtil.dateToStrLong((Date) map.get("czrq")));
                json.put("keyword", map.get("keyword"));
                json.put("send", map.get("send"));
                //阅读量
                json.put("readAmount", map.get("readAmount"));
                //收藏量
                json.put("collectionAmount", map.get("collectionAmount"));
                //转发量
                json.put("repeatAmount", map.get("repeatAmount"));
                //是否收藏(医生收藏的列表肯定是收藏的无需额外校验)
                json.put("collection", 1);
                jsonArray.put(json);
            }
            return write(200, "查询成功", "list", jsonArray);
        } catch (Exception ex) {
            error(ex);
            return invalidUserException(ex, -1, "查询失败!");
        }
    }
    /**
     * 查询标签列表
     *
     * @param pagesize 分页大小
     * @return 列表
     */
    @RequestMapping(value = "listLabel")
    @ResponseBody
    public String listLabel(@RequestParam(value = "page", required = true) int page, @RequestParam(value = "pagesize", required = true) int pagesize, @RequestParam(value = "type", required = false, defaultValue = "0") int type) {
        try {
            Page<HealthEduArticleLabel> list = healthEduArticleLabelService.findAll(page, pagesize, type, getUID());
            return write(200, "查询成功", "list", list);
        } catch (Exception ex) {
            error(ex);
            return invalidUserException(ex, -1, "查询失败!");
        }
    }
    /**
     * 查询文章列表
     *
     * @param code 数据文章唯一标示code
     * @return 列表
     */
    @RequestMapping(value = "article")
    @ResponseBody
    public String article(@RequestParam(value = "code", required = true) String code) {
        try {
            //获取单条文章记录
            HealthEduArticle healthEduArticle = healthEduArticleService.findArticleByCode(code);
            int isRead = healthEduArticleOpHistoryService.countByUserStatus(getUID(), HealthEduArticleOpHistory.READ_STATUS);
            //插入文章读取状态第一次阅读记录浏览数量
            if (isRead == 0) {
                //更新浏览量
                healthEduArticleOpHistoryService.saveByStatus(HealthEduArticleOpHistory.READ_STATUS, healthEduArticle.getCode(), healthEduArticle.getTitle(), getUID());
            }
            JSONObject json = new JSONObject();
            json.put("id", healthEduArticle.getId());
            // 文章标识
            json.put("code", healthEduArticle.getCode());
            // 文章标题
            json.put("title", healthEduArticle.getTitle());
            json.put("url", healthEduArticle.getUrl() == null ? "" : healthEduArticle.getUrl());
            // 文章内容
            json.put("content", healthEduArticle.getContent());
            // 添加日期
            json.put("czrq", DateUtil.dateToStrLong(healthEduArticle.getCzrq()));
            int readAmount = healthEduArticleOpHistoryService.countReadAmount(code);
            json.put("readAmount", readAmount);
            HealthEduArticleDoctor healthEduArticleDoctor = healthEduArticleDoctorService.findByArticle(healthEduArticle.getCode(), getUID());
            if (healthEduArticleDoctor == null) {
                json.put("collection", 0);
            } else {
                json.put("collection", 1);
            }
            return write(200, "查询成功", "data", json);
        } catch (Exception ex) {
            error(ex);
            return invalidUserException(ex, -1, "查询失败!");
        }
    }
    /**
     * 发送文章给患者
     *
     * @param code    文章标识,多个以逗号分隔
     * @param patient 患者标识,多个以逗号分隔
     * @param group   所选群组,多个用逗号分隔
     * @return
     */
    @RequestMapping(value = "send")
    @ResponseBody
    public String send(@RequestParam(value = "code") String code,
                       @RequestParam(value = "patient", required = false) String patient,
                       @RequestParam(value = "group", required = false, defaultValue = "") String group,
                       @RequestParam(value = "labelType", required = false) String labelType,
                       @RequestParam(value = "teamCode", required = false) long teamCode) {
        try {
            List<HealthEduArticlePatient> list = new ArrayList<HealthEduArticlePatient>();
            if (StringUtils.isEmpty(code)) {
                return error(-1, "请至少选择一篇文章!");
            }
            if (StringUtils.isEmpty(patient) && StringUtils.isEmpty(group)) {
                return error(-1, "请至少选择一个患者!");
            }
            String[] articles = code.split(",");
            String[] patients = patient.split(",");
            String[] groups = group.split(",");
            if (articles.length == 0) {
                return error(-1, "请至少选择一篇文章!");
            }
            if (patients.length == 0 && groups.length == 0) {
                return error(-1, "请至少选择一个患者!");
            }
            Map<String, HealthEduArticle> maps = new HashMap<String, HealthEduArticle>();
            Set<String> patientSet = new HashSet<>();
            if (StringUtils.isNotBlank(group) && groups.length > 0) {
                //递归患者数据
                for (String g : groups) {
                    getPatientByGroup(g, labelType, teamCode, patientSet, 0, 100);
                }
            }
            //去重操作
            for (String p : patients) {
                if (StringUtils.isNotBlank(p)) {
                    patientSet.add(p);
                }
            }
            if (patientSet.size() == 0) {
                return error(-1, "请至少选择一个患者!");
            }
            // 查询医生信息
            Doctor doctor = doctorService.findDoctorByCode(getUID());
            String msgHead = doctor.getName() + "医生给您发来了一篇患教文章";
            String endMsg = "为了您的健康," + doctor.getName() + "医生给您发送了一篇患教文章,请仔细查阅,如有问题,可随时咨询医生。";
            JSONArray messages = new JSONArray();
            for (String p : patientSet) {
                Patient patientTemp = patientService.findByCode(p);
                SignFamily signFamily = signFamilyDao.findByjiatingPatient(p);
                if(signFamily == null){
                    throw new Exception("can not find patient's family sign info");
                }
                for (String a : articles) {
                    // 查询文章信息
                    HealthEduArticle temp = maps.get(a);
                    if (temp == null) {
                        temp = healthEduArticleService.findArticleByCode(a);
                        // 添加到缓存
                        maps.put(a, temp);
                    }
                    HealthEduArticlePatient heap = new HealthEduArticlePatient();
                    // 设置文章标识
                    heap.setArticle(a);
                    // 设置文章简介
                    heap.setContent(temp.getContent());
                    // 设置文章标题
                    heap.setTitle(temp.getTitle());
                    // 设置文章查看URL
                    heap.setUrl(temp.getUrl());
                    // 设置发送时间
                    heap.setCzrq(new Date());
                    // 设置医生标识
                    heap.setDoctor(doctor.getCode());
                    // 设置医生姓名
                    heap.setDoctorName(doctor.getName());
                    // 设置患者标识
                    heap.setPatient(p);
                    // 设置为示读
                    heap.setRead(1);
                    // 签约类型
                    heap.setSignType(2);
                    // 行政团队
                    heap.setAdminTeamCode(signFamily.getAdminTeamId());
                    list.add(heap);
                    SendP2PUtil.sendP2Pmsg(doctor.getCode(), p, "4", "{\"title\":\"" + temp.getTitle() + "\",\"id\":\"" + temp.getCode() + "\",\"img\":\"" + temp.getUrl() + "\",\"content\":\"为了您的健康,我给您发送了一篇文章,请咨询查阅,如有问题,可随时与我沟通\"}");
                    if (StringUtils.isNotEmpty(patientTemp.getOpenid())) {
                        // 推送消息给微信端
                        JSONObject json = new JSONObject();
                        json.put("first", patientTemp.getName() + ",您好!\n" + msgHead);
                        json.put("toUser", p);
                        json.put("article", temp.getCode() + "");
                        json.put("title", temp.getTitle());
                        json.put("doctorName", doctor.getName());
                        json.put("date", DateUtil.dateToStrLong(DateUtil.getNowDate()));
                        json.put("remark", endMsg);
                        PushMsgTask.getInstance().putWxMsg(getAccessToken(), 9, patientTemp.getOpenid(), patientTemp.getName(), json);
                    }
                }
            }
            // 保存到数据库
            int row = healthEduArticleService.send(list);
            if (row <= 0) {
                return error(-1, "发送失败!");
            } else {
                // 推送消息给患者
                PushMsgTask.getInstance().put(messages);
                return success("发送成功!");
            }
        } catch (Exception e) {
            error(e);
            return error(-1, "发送失败!");
        }
    }
    private void getPatientByGroup(String labelCode, String labelType, Long teamCode, Set<String> patientSet, int page, int pagesize) throws Exception {
        JSONArray result = signPatientLabelInfoService.getPatientByLabel(getUID(), labelCode, labelType, teamCode, page, pagesize);
        for (Object o : result) {
            JSONObject json = (JSONObject) o;
            String patient = (String) json.get("code");
            patientSet.add(patient);
        }
        if (result.length() == 100) {
            getPatientByGroup(labelCode, labelType, teamCode, patientSet, page + 1, pagesize);
        }
    }
    /**
     * 文章收藏
     *
     * @param article 文章CODE
     * @return
     */
    @RequestMapping(value = "collectionArticle")
    @ResponseBody
    public String collectionArticle(@RequestParam(value = "article", required = true) String article) {
        HealthEduArticleDoctor healthEduArticleDoctor = healthEduArticleDoctorService.findByArticle(article, getUID());
        if (healthEduArticleDoctor != null) {
            return error(-1, "收藏失败,该文章已经收藏!");
        }
        HealthEduArticle healthEduArticle = healthEduArticleService.findArticleByCode(article);
        healthEduArticleDoctor = new HealthEduArticleDoctor();
        try {
            BeanUtils.copyProperties(healthEduArticle, healthEduArticleDoctor);
            healthEduArticleDoctor.setDoctor(getUID());
            healthEduArticleDoctor.setArticle(healthEduArticle.getCode());
            healthEduArticleDoctorService.save(healthEduArticleDoctor);
            //更新收藏量
            healthEduArticleOpHistoryService.saveByStatus(HealthEduArticleOpHistory.COLLECTION_STATUS, healthEduArticle.getCode(), healthEduArticle.getTitle(), getUID());
            return success("收藏成功!");
        } catch (Exception e) {
            error(e);
            return error(-1, "收藏失败!");
        }
    }
    /**
     * 文章收藏
     *
     * @param article 文章CODE
     * @return
     */
    @RequestMapping(value = "uncollectionArticle")
    @ResponseBody
    public String uncollectionArticle(@RequestParam(value = "article", required = true) String article) {
        try {
            healthEduArticleDoctorService.delete(article, getUID());
            return success("取消收藏成功!");
        } catch (Exception e) {
            error(e);
            return error(-1, "取消收藏失败!");
        }
    }
    private String parsrHtml(String html) {
        html = ("<span>" + html + "</span>");//拼接一个HTML标签,防止纯文字字符串转换在linux下面出现的异常。
        Parser parser = null;
        try {
            parser = new Parser(html);
            TextExtractingVisitor visitor = new TextExtractingVisitor();
            parser.visitAllNodesWith(visitor);
            return StringUtils.isNotBlank(visitor.getExtractedText()) ? visitor.getExtractedText() : "内容为图集,请点击查看";
        } catch (ParserException e) {
            return html;//纯文本内容会转换失败,直接返回文本内容
        }
    }
    public static void main(String arg[]) {
        System.out.println(MessageType.MESSAGE_TYPE_PATIENT_HEALTH_EDU.P_HE_01.name());
    }
}

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

@ -2,6 +2,8 @@ package com.yihu.wlyy.web.doctor.health;
import com.yihu.wlyy.util.SendP2PUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
@ -116,4 +118,36 @@ public class DoctorHealthGuidanceController extends WeixinBaseController {
		}
	}
	/**
	 * 查询患者的健康指导
	 *
	 * @param patient
	 * @param teamCode
	 * @param page
	 * @param pagesize
	 * @return
	 */
	@RequestMapping(value = "list_by_team", method = {RequestMethod.GET, RequestMethod.POST})
	@ResponseBody
	@ApiOperation(value = "查询居民健康指导记录")
	public String list(@RequestParam @ApiParam(value = "居民code") String patient,
					   @RequestParam @ApiParam(value = "团队Code") Long teamCode,
					   @RequestParam @ApiParam(value = "第几页") int page,
					   @RequestParam @ApiParam(value = "页大小") int pagesize) {
		try {
			if (StringUtils.isEmpty(patient)) {
				return error(-1, "请输入需查询的居民");
			}
			if (teamCode == null || teamCode < 1) {
				return error(-1, "请输入需查询的居民的团队");
			}
			JSONArray result = patientHealthGuidanceService.findByPatientAndGuidanceAndTeam(patient,teamCode,page,pagesize);
			return write(200, "查询成功!", "list", result);
		} catch (Exception e) {
			error(e);
			return error(-1, "查询失败!");
		}
	}
}

+ 4 - 4
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/BookingController.java

@ -453,7 +453,7 @@ public class BookingController extends WeixinBaseController {
    }
    /********************************************* 医生端查询 **************************************************************************/
    @RequestMapping(value = "GetPatientReservationList", method = RequestMethod.POST)
    @RequestMapping(value = "GetPatientReservationList", method = {RequestMethod.POST,RequestMethod.GET})
    @ResponseBody
    @ApiOperation("获取患者预约信息列表接口-医生端")
    public String GetPatientReservation(@ApiParam(name = "pageIndex", value = "第几页", defaultValue = "1")
@ -462,10 +462,10 @@ public class BookingController extends WeixinBaseController {
                                        @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                        @ApiParam(name = "patient", value = "患者编号", defaultValue = "4afdbce6194e412fbc770eb4dfbe7b00")
                                        @RequestParam(value = "patient", required = false) String patient,
                                        @ApiParam(name = "doctor", value = "医生编号", defaultValue = "shiliuD20160926005")
                                        @RequestParam(value = "doctor", required = false) String doctor) {
                                        @ApiParam(name = "teamCode", value = "行政团队", defaultValue = "shiliuD20160926005")
                                        @RequestParam(value = "teamCode", required = false) Long teamCode) {
        try {
            List<PatientReservation> list = patientReservationService.getReservationByPatient(patient, doctor, pageIndex, pageSize);
            List<PatientReservation> list = patientReservationService.getReservationByPatient(patient, teamCode, pageIndex, pageSize);
            return write(200, "获取患者预约信息列表成功!", "data", list);
        } catch (Exception e) {