浏览代码

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

chenweida 8 年之前
父节点
当前提交
09afae7d72

+ 96 - 0
src/main/java/com/yihu/wlyy/entity/doctor/team/sign/SignPatientLabel.java

@ -0,0 +1,96 @@
package com.yihu.wlyy.entity.doctor.team.sign;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by lyr on 2016/10/9.
 */
@Entity
@Table(name = "wlyy_sign_patient_label")
public class SignPatientLabel extends IdEntity {
    // 标签code
    private String labelCode;
    // 标签名称
    private String labelName;
    // 标签类型 1:卫计委三大分组 2:健康情况 3:疾病类型 4:自定义
    private String labelType;
    // 是否系统标签
    private Integer isSystem;
    // 创建者
    private String creator;
    // 所属团队code
    private Long teamCode;
    // 排序
    private Integer sort;
    // 状态 0:无效 1:有效
    private Integer status;
    // 操作日期
    private Date czrq;
    public String getLabelCode() {
        return labelCode;
    }
    public void setLabelCode(String labelCode) {
        this.labelCode = labelCode;
    }
    public String getLabelName() {
        return labelName;
    }
    public void setLabelName(String labelName) {
        this.labelName = labelName;
    }
    public String getLabelType() {
        return labelType;
    }
    public void setLabelType(String labelType) {
        this.labelType = labelType;
    }
    public Integer getIsSystem() {
        return isSystem;
    }
    public void setIsSystem(Integer isSystem) {
        this.isSystem = isSystem;
    }
    public String getCreator() {
        return creator;
    }
    public void setCreator(String creator) {
        this.creator = creator;
    }
    public Long getTeamCode() {
        return teamCode;
    }
    public void setTeamCode(Long teamCode) {
        this.teamCode = teamCode;
    }
    public Integer getSort() {
        return sort;
    }
    public void setSort(Integer sort) {
        this.sort = sort;
    }
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
    public Date getCzrq() {
        return czrq;
    }
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
}

+ 79 - 0
src/main/java/com/yihu/wlyy/entity/doctor/team/sign/SignPatientLabelInfo.java

@ -0,0 +1,79 @@
package com.yihu.wlyy.entity.doctor.team.sign;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by lyr on 2016/10/9.
 */
@Entity
@Table(name = "wlyy_sign_patient_label_info")
public class SignPatientLabelInfo extends IdEntity {
    // 患者code
    private String patient;
    // 患者姓名
    private String pname;
    // 标签code
    private String label;
    // 标签名称
    private String labelName;
    // 标签类型
    private String labelType;
    // 状态 0:无效 1:有效
    private Integer status;
    // 操作日期
    private Date czrq;
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    public String getPname() {
        return pname;
    }
    public void setPname(String pname) {
        this.pname = pname;
    }
    public String getLabel() {
        return label;
    }
    public void setLabel(String label) {
        this.label = label;
    }
    public String getLabelName() {
        return labelName;
    }
    public void setLabelName(String labelName) {
        this.labelName = labelName;
    }
    public String getLabelType() {
        return labelType;
    }
    public void setLabelType(String labelType) {
        this.labelType = labelType;
    }
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
    public Date getCzrq() {
        return czrq;
    }
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
}

+ 69 - 0
src/main/java/com/yihu/wlyy/entity/doctor/team/sign/SignPatientLabelLog.java

@ -0,0 +1,69 @@
package com.yihu.wlyy.entity.doctor.team.sign;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by lyr on 2016/10/9.
 */
@Entity
@Table(name = "wlyy_sign_patient_lable_log")
public class SignPatientLabelLog extends IdEntity {
    // 标签code
    private String labelCode;
    // 旧名称
    private String oldName;
    // 新名称
    private String newName;
    // 变更类型 1:修改名称  2:删除
    private Integer modifyType;
    // 修改人
    private String modifyBy;
    // 操作日期
    private Date czrq;
    public String getLabelCode() {
        return labelCode;
    }
    public void setLabelCode(String labelCode) {
        this.labelCode = labelCode;
    }
    public String getOldName() {
        return oldName;
    }
    public void setOldName(String oldName) {
        this.oldName = oldName;
    }
    public String getNewName() {
        return newName;
    }
    public void setNewName(String newName) {
        this.newName = newName;
    }
    public Integer getModifyType() {
        return modifyType;
    }
    public void setModifyType(Integer modifyType) {
        this.modifyType = modifyType;
    }
    public String getModifyBy() {
        return modifyBy;
    }
    public void setModifyBy(String modifyBy) {
        this.modifyBy = modifyBy;
    }
    public Date getCzrq() {
        return czrq;
    }
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
}

+ 2 - 0
src/main/java/com/yihu/wlyy/repository/doctor/DoctorPatientGroupInfoDao.java

@ -101,4 +101,6 @@ public interface DoctorPatientGroupInfoDao extends PagingAndSortingRepository<Do
	@Query("select a from DoctorPatientGroupInfo a where  a.status = 1 and a.doctor = ?2 and a.patient = ?1 and a.signType =2")
	List<DoctorPatientGroupInfo> findByPatientAndDoctor(String patient, String oldDoctorCode);
	List<DoctorPatientGroupInfo> findByGroupAndStatus(String group, Integer status);
}

+ 54 - 0
src/main/java/com/yihu/wlyy/repository/doctor/SignPatientLabelDao.java

@ -0,0 +1,54 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabel;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by lyr on 2016/10/9.
 */
public interface SignPatientLabelDao extends
        PagingAndSortingRepository<SignPatientLabel, Long>,
        JpaSpecificationExecutor<SignPatientLabel> {
    /**
     * 根据标签code、标签类型、状态查询标签
     *
     * @param labelCode 标签code
     * @param labelType 标签类型
     * @param status 状态
     * @return
     */
    SignPatientLabel findByLabelCodeAndLabelTypeAndStatus(String labelCode,String labelType,Integer status);
    /**
     * 查询某个类型系统标签
     *
     * @param labelType
     * @param status
     * @return
     */
    List<SignPatientLabel> findByLabelTypeAndStatus(String labelType,Integer status);
    /**
     * 查询非自定义系统标签
     *
     * @return
     */
    @Query("select a from SignPatientLabel a where a.status = 1 and a.isSystem = 1 and a.labelType < 4")
    List<SignPatientLabel> findSystemLabels();
    /**
     * 查询某个团队自定义标签
     *
     * @param teamCode
     * @return
     */
    @Query("select a from SignPatientLabel a where a.status = 1 and (a.isSystem = 1  or a.teamCode = ?1) and a.labelType = 4")
    List<SignPatientLabel> findCustomLabels(long teamCode);
}

+ 61 - 0
src/main/java/com/yihu/wlyy/repository/doctor/SignPatientLabelInfoDao.java

@ -0,0 +1,61 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabelInfo;
import com.yihu.wlyy.entity.patient.SignFamily;
import io.swagger.models.auth.In;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by lyr on 2016/10/9.
 */
public interface SignPatientLabelInfoDao extends
        PagingAndSortingRepository<SignPatientLabelInfo, Long>,
        JpaSpecificationExecutor<SignPatientLabelInfo> {
    /**
     * 查询某个患者的标签
     *
     * @param patient 患者
     * @param status  状态
     * @return
     */
    List<SignPatientLabelInfo> findByPatientAndStatus(String patient, Integer status);
    /**
     * 查询某个患者的某个类型标签
     *
     * @param patient   患者
     * @param labelType 标签类型
     * @param status    状态
     * @return
     */
    List<SignPatientLabelInfo> findByPatientAndLabelTypeAndStatus(String patient, String labelType, Integer status);
    /**
     * 查询某个患者的某个类型的某个标签
     *
     * @param patient   患者
     * @param labelCode  标签代码
     * @param labelType 标签类型
     * @param status    状态
     * @return
     */
    SignPatientLabelInfo findByPatientAndLabelAndLabelTypeAndStatus(String patient, String labelCode, String labelType, Integer status);
    /**
     * 删除患者的某个标签类型的所有指定状态标签
     *
     * @param patient
     * @param labelType
     * @param status
     * @return
     */
    int deleteByPatientAndLabelTypeAndStatus(String patient, String labelType, Integer status);
}

+ 14 - 0
src/main/java/com/yihu/wlyy/repository/doctor/SignPatientLabelLogDao.java

@ -0,0 +1,14 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabelLog;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by lyr on 2016/10/9.
 */
public interface SignPatientLabelLogDao extends
        PagingAndSortingRepository<SignPatientLabelLog, Long>,
        JpaSpecificationExecutor<SignPatientLabelLog> {
}

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

@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Iterator;
import java.util.List;
/**
@ -51,4 +52,6 @@ public interface PatientDiseaseDao extends PagingAndSortingRepository<PatientDis
    @Modifying
    @Query("update PatientDisease set del = '0' where patient = ?1 and del = '1' and signType = '2' ")
    int updateDiseaseDel(String patient);
    List<PatientDisease> findByDel(String del);
}

+ 667 - 0
src/main/java/com/yihu/wlyy/service/app/label/SignPatientLabelInfoService.java

@ -0,0 +1,667 @@
package com.yihu.wlyy.service.app.label;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.sign.DoctorPatientGroupInfo;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabel;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabelInfo;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientDisease;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.doctor.DoctorPatientGroupInfoDao;
import com.yihu.wlyy.repository.doctor.SignPatientLabelInfoDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientDiseaseDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.IdCardUtil;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
 * 患者标签信息服务
 * <p>
 * Created by lyr on 2016/10/9.
 */
@Service
@Transactional
public class SignPatientLabelInfoService extends BaseService {
    @Autowired
    SignPatientLabelService labelService;
    @Autowired
    DoctorDao doctorDao;
    @Autowired
    PatientDao patientDao;
    @Autowired
    SignPatientLabelInfoDao labelInfoDao;
    @Autowired
    PatientDiseaseDao diseaseDao;
    @Autowired
    DoctorPatientGroupInfoDao groupInfoDao;
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    SignFamilyDao signFamilyDao;
    /**
     * 根据标签查询患者信息
     *
     * @param labelCode 标签code
     * @param labelType 标签类型
     * @param page      第几页
     * @param pagesize  页大小
     * @return
     */
    public JSONArray getPatientByLabel(String doctor, String labelCode, String labelType, Long teamCode, int page, int pagesize) throws Exception {
        Doctor doc = doctorDao.findByCode(doctor);
        if (doc == null) {
            throw new Exception("doctor info can not find");
        }
        Map<String, JSONObject> result = new HashMap<>();
        List<Map<String, Object>> signList = new ArrayList<>();
        int start = page * pagesize;
        String sql = "";
        Object[] args = null;
        if (labelCode.equals("0")) {
            sql = "select a.*" +
                    " from" +
                    "     (select * from wlyy_sign_family where " + (doc.getLevel() == 2 ? " doctor" : "doctor_health") + " = ? and status > 0 and admin_team_code = ?) a" +
                    " left join" +
                    "     (select * from wlyy_sign_patient_label_info where label_type = ? and status = 1) b" +
                    " on a.patient = b.patient where b.patient is null limit " + start + "," + pagesize;
            args = new Object[]{doctor, teamCode, labelType};
        } else {
            sql = "select a.*" +
                    " from" +
                    "     (select * from wlyy_sign_family where " + (doc.getLevel() == 2 ? " doctor" : "doctor_health") + " = ? and status > 0 and admin_team_code = ?) a" +
                    " join" +
                    "     (select * from wlyy_sign_patient_label_info where label = ? and label_type = ? and status = 1) b" +
                    " on a.patient = b.patient limit " + start + "," + pagesize;
            args = new Object[]{doctor, teamCode, labelCode, labelType};
        }
        signList = jdbcTemplate.queryForList(sql, args);
        if (signList != null && signList.size() > 0) {
            for (Map<String, Object> sign : signList) {
                Patient p = patientDao.findByCode(sign.get("patient") == null ? "" : sign.get("patient").toString());
                if (p == null) {
                    continue;
                }
                if (result.containsKey(p.getCode())) {
                    JSONObject jsonP = result.get(p.getCode());
                    if (!String.valueOf(jsonP.get("signType")).equals(String.valueOf(sign.get("type")))) {
                        jsonP.put("signType", 3);
                    }
                    continue;
                }
                List<SignPatientLabelInfo> labels = labelInfoDao.findByPatientAndStatus(sign.get("patient").toString(), 1);
                JSONObject json = new JSONObject();
                // 设置患者标识
                json.put("code", p.getCode());
                // 设置患者姓名
                json.put("name", p.getName());
                // 设置患者头像
                json.put("photo", p.getPhoto());
                // 设置患者年龄
                json.put("age", DateUtil.getAgeByBirthday(p.getBirthday()));
                // 设置患者性别
                json.put("sex", p.getSex());
                // 设置签约日期
                json.put("qyrq", sign.get("apply_date") != null ? DateUtil.dateToStr((Date) sign.get("apply_date"), DateUtil.YYYY_MM_DD) : "");
                // 设置签约类型
                json.put("signType", sign.get("type") == null ? "" : sign.get("type"));
                // 身份证号
                json.put("idcard", p.getIdcard());
                // 患者标签
                json.put("labels", labels == null ? "" : labels);
                result.put(p.getCode(), json);
            }
        }
        return result.size() > 0 ? new JSONArray(result.values()) : new JSONArray();
    }
    /**
     * 查询某个标签类型的所有标签居民数统计
     *
     * @param labelType 标签类型
     * @param teamCode  标签类型为4时,不能为空
     * @return
     */
    public JSONArray getPatientAmountByLabelType(String doctor, String labelType, Long teamCode) throws Exception {
        Doctor doc = doctorDao.findByCode(doctor);
        if (doc == null) {
            throw new Exception("doctor info can not find");
        }
        List<SignPatientLabel> labels = labelService.getLabelsByTypeAndTeam(labelType, teamCode);
        JSONArray result = new JSONArray();
        SignPatientLabel labelNo = new SignPatientLabel();
        labelNo.setLabelCode("0");
        labelNo.setLabelName("未分组");
        labelNo.setStatus(1);
        labelNo.setIsSystem(1);
        labelNo.setLabelType(labelType);
        labelNo.setSort(999999999);
        labels.add(labelNo);
        if (labels != null) {
            for (SignPatientLabel label : labels) {
                JSONObject json = new JSONObject();
                json.put("labelCode", label.getLabelCode());
                json.put("labelName", label.getLabelName());
                json.put("isSystem", label.getIsSystem());
                int amount = 0;
                String sql = "";
                Object[] args = null;
                if (label.getLabelCode().equals("0")) {
                    sql = "select count(DISTINCT a.patient) count" +
                            " from" +
                            "     (select * from wlyy_sign_family where " + (doc.getLevel() == 2 ? " doctor" : "doctor_health") + " = ? and status > 0 " +
                            (teamCode > 0 ? "and admin_team_code = ?" : "") + ") a " +
                            " left join" +
                            "     (select * from wlyy_sign_patient_label_info where label_type = ? and status = 1) b" +
                            " on a.patient = b.patient where b.patient is null ";
                    if (teamCode > 0) {
                        args = new Object[]{doctor, teamCode, labelType};
                    } else {
                        args = new Object[]{doctor, labelType};
                    }
                } else {
                    sql = "select count(DISTINCT a.patient) count" +
                            " from" +
                            "     (select * from wlyy_sign_family where " + (doc.getLevel() == 2 ? " doctor" : "doctor_health") + " = ? and status > 0 " +
                            (teamCode > 0 ? "and admin_team_code = ?" : "") + ") a " +
                            " join" +
                            "     (select * from wlyy_sign_patient_label_info where label = ? and label_type = ? and status = 1) b" +
                            " on a.patient = b.patient ";
                    if (teamCode > 0) {
                        args = new Object[]{doctor, teamCode, label.getLabelCode(), labelType};
                    } else {
                        args = new Object[]{doctor, label.getLabelCode(), labelType};
                    }
                }
                Map<String, Object> count = jdbcTemplate.queryForMap(sql, args);
                if (count != null && count.containsKey("count")) {
                    amount = Integer.valueOf(String.valueOf(count.get("count")));
                }
                json.put("amount", amount);
                result.put(json);
            }
        }
        return result;
    }
    /**
     * 设置患者标签
     *
     * @param patient     患者名称
     * @param idcard      身份证号
     * @param patientName 患者姓名
     * @param health      健康情况标签
     * @param disease     疾病类型标签
     * @param custom      自定义标签
     * @return
     */
    public int setPatientLabels(String patient, String idcard, String patientName, String health, String disease, String custom) {
        Patient p = patientDao.findByCode(patient);
        if (p == null && (StringUtils.isEmpty(idcard) || StringUtils.isEmpty(patientName))) {
            return 0;
        } else {
            idcard = p.getIdcard();
            patientName = p.getName();
        }
        String[] diseaseArr = disease.split(",");
        String[] customArr = custom.split(",");
        // 健康情况标签
        int healthAmount = labelInfoDao.deleteByPatientAndLabelTypeAndStatus(patient, "2", 1);
        if (StringUtils.isNotEmpty(health)) {
            SignPatientLabelInfo healthLabel = new SignPatientLabelInfo();
            SignPatientLabel label = labelService.getLabelByCodeAndType(health, "2");
            if (label == null) {
                return -1;
            }
            healthLabel.setPatient(patient);
            healthLabel.setPname(patientName);
            healthLabel.setLabelType("2");
            healthLabel.setLabel(health);
            healthLabel.setLabelName(label.getLabelName());
            healthLabel.setStatus(1);
            healthLabel.setCzrq(new Date());
            labelInfoDao.save(healthLabel);
        } else {
            return -2;
        }
        // 疾病类型标签
        int disAmount = labelInfoDao.deleteByPatientAndLabelTypeAndStatus(patient, "3", 1);
        if (diseaseArr != null && diseaseArr.length > 0) {
            for (String diseaseLabel : diseaseArr) {
                if (StringUtils.isEmpty(diseaseLabel)) {
                    continue;
                }
                SignPatientLabelInfo disLabel = new SignPatientLabelInfo();
                SignPatientLabel label = labelService.getLabelByCodeAndType(diseaseLabel, "3");
                if (label == null) {
                    return -1;
                }
                disLabel.setPatient(patient);
                disLabel.setPname(patientName);
                disLabel.setLabelType("3");
                disLabel.setLabel(diseaseLabel);
                disLabel.setLabelName(label.getLabelName());
                disLabel.setStatus(1);
                disLabel.setCzrq(new Date());
                labelInfoDao.save(disLabel);
            }
        }
        // 自定义标签
        int cusAmount = labelInfoDao.deleteByPatientAndLabelTypeAndStatus(patient, "4", 1);
        if (customArr != null && customArr.length > 0) {
            for (String customLabel : customArr) {
                if (StringUtils.isEmpty(customLabel)) {
                    continue;
                }
                SignPatientLabelInfo cusLabel = new SignPatientLabelInfo();
                SignPatientLabel label = labelService.getLabelByCodeAndType(customLabel, "4");
                if (label == null) {
                    return -1;
                }
                cusLabel.setPatient(patient);
                cusLabel.setPname(patientName);
                cusLabel.setLabelType("4");
                cusLabel.setLabel(customLabel);
                cusLabel.setLabelName(label.getLabelName());
                cusLabel.setStatus(1);
                cusLabel.setCzrq(new Date());
                labelInfoDao.save(cusLabel);
            }
        }
        // 卫计委三大分组
        int wjwAmount = labelInfoDao.deleteByPatientAndLabelTypeAndStatus(patient, "1", 1);
        if (diseaseArr != null && diseaseArr.length > 0 && (Arrays.asList(diseaseArr).contains("1")
                || Arrays.asList(diseaseArr).contains("2"))) {
            SignPatientLabelInfo disLabel = new SignPatientLabelInfo();
            disLabel.setPatient(patient);
            disLabel.setPname(patientName);
            disLabel.setLabelType("1");
            disLabel.setLabel("2");
            disLabel.setLabelName("慢病人群");
            disLabel.setStatus(1);
            disLabel.setCzrq(new Date());
            labelInfoDao.save(disLabel);
        } else {
            int age = IdCardUtil.getAgeForIdcard(idcard);
            SignPatientLabelInfo disLabel = new SignPatientLabelInfo();
            disLabel.setPatient(patient);
            disLabel.setPname(patientName);
            disLabel.setLabelType("1");
            disLabel.setStatus(1);
            disLabel.setCzrq(new Date());
            if (age >= 65) {
                disLabel.setLabel("3");
                disLabel.setLabelName("65岁以上人群");
            } else {
                disLabel.setLabel("1");
                disLabel.setLabelName("普通人群");
            }
            labelInfoDao.save(disLabel);
        }
        return 1;
    }
    /**
     * 查询某个患者的某个类型的标签
     *
     * @param patient   患者code
     * @param labelType 标签类型
     * @return
     */
    public List<SignPatientLabelInfo> getPatientLabelByLabelType(String patient, String labelType) {
        List<SignPatientLabelInfo> labels = new ArrayList<>();
        if (StringUtils.isEmpty(labelType)) {
            labels = labelInfoDao.findByPatientAndStatus(patient, 1);
        } else {
            labels = labelInfoDao.findByPatientAndLabelTypeAndStatus(patient, labelType, 1);
        }
        return labels;
    }
    /**
     * 根据患者姓名或标签名称查询
     *
     * @param doctor
     * @param filter
     * @return
     * @throws Exception
     */
    public JSONArray searchPatientByNameOrLabel(String doctor, String filter, String labelCode, String labelType) throws Exception {
        Doctor doc = doctorDao.findByCode(doctor);
        if (doc == null) {
            throw new Exception("doctor info can not find");
        }
        Map<String, JSONObject> result = new HashMap<>();
        List<Map<String, Object>> signList = new ArrayList<>();
        Object[] args = null;
        String sql = "select a.*" +
                " from" +
                "     (select * from wlyy_sign_family where " + (doc.getLevel() == 2 ? " doctor" : "doctor_health") + " = ? and status > 0) a" +
                " left join" +
                "     (select * from wlyy_sign_patient_label_info where status = 1 " +
                (StringUtils.isNotEmpty(labelCode) ? " and label = ? " : "") +
                (StringUtils.isNotEmpty(labelType) ? " and label_type = ? " : "") + ") b" +
                " on a.patient = b.patient where a.name like ? or b.label_name like ?";
        if (StringUtils.isNotEmpty(labelCode)) {
            args = new Object[]{doctor, labelCode, labelType, "%" + filter + "%", "%" + filter + "%"};
        } else if (StringUtils.isEmpty(labelCode) && StringUtils.isNotEmpty(labelType)) {
            args = new Object[]{doctor, labelType, "%" + filter + "%", "%" + filter + "%"};
        } else {
            args = new Object[]{doctor, "%" + filter + "%", "%" + filter + "%"};
        }
        signList = jdbcTemplate.queryForList(sql, args);
        if (signList != null && signList.size() > 0) {
            for (Map<String, Object> sign : signList) {
                Patient p = patientDao.findByCode(sign.get("patient") == null ? "" : sign.get("patient").toString());
                if (p == null) {
                    continue;
                }
                if (result.containsKey(p.getCode())) {
                    JSONObject jsonP = result.get(p.getCode());
                    if (!String.valueOf(jsonP.get("signType")).equals(String.valueOf(sign.get("type")))) {
                        jsonP.put("signType", 3);
                    }
                    continue;
                }
                List<SignPatientLabelInfo> labels = labelInfoDao.findByPatientAndStatus(sign.get("patient").toString(), 1);
                JSONObject json = new JSONObject();
                // 设置患者标识
                json.put("code", p.getCode());
                // 设置患者姓名
                json.put("name", p.getName());
                // 设置患者头像
                json.put("photo", p.getPhoto());
                // 设置患者年龄
                json.put("age", DateUtil.getAgeByBirthday(p.getBirthday()));
                // 设置患者性别
                json.put("sex", p.getSex());
                // 设置签约日期
                json.put("qyrq", sign.get("apply_date") != null ? DateUtil.dateToStr((Date) sign.get("apply_date"), DateUtil.YYYY_MM_DD) : "");
                // 设置签约类型
                json.put("signType", sign.get("type") == null ? "" : sign.get("type"));
                // 身份证号
                json.put("idcard", p.getIdcard());
                // 患者标签
                json.put("labels", labels == null ? "" : labels);
                result.put(p.getCode(), json);
            }
        }
        return result.size() > 0 ? new JSONArray(result.values()) : new JSONArray();
    }
    /**
     * 添加居民到某个标签
     *
     * @param patient 患者
     * @param labelCode 标签code
     * @param labelType 标签类型
     * @return
     */
    public int addPatientLabel(String patient, String labelCode, String labelType) {
        Patient p = patientDao.findByCode(patient);
        if (p == null) {
            return -1;
        }
        SignPatientLabelInfo labelInfo = labelInfoDao.findByPatientAndLabelAndLabelTypeAndStatus(patient, labelCode, labelType, 1);
        if (labelInfo != null) {
            return -2;
        }
        SignPatientLabel label = labelService.getLabelByCodeAndType(labelCode, labelType);
        if (label == null) {
            return -3;
        }
        labelInfo = new SignPatientLabelInfo();
        labelInfo.setPatient(patient);
        labelInfo.setPname(p.getName());
        labelInfo.setLabel(labelCode);
        labelInfo.setLabelType(labelType);
        labelInfo.setLabelName(label.getLabelName());
        labelInfo.setStatus(1);
        labelInfo.setCzrq(new Date());
        labelInfoDao.save(labelInfo);
        return 1;
    }
    /**
     * 删除居民的某个标签
     *
     * @param patient 患者
     * @param labelCode 标签code
     * @param labelType 标签类型
     * @return
     */
    public int deletePatientLabel(String patient, String labelCode, String labelType) {
        SignPatientLabelInfo labelInfo = labelInfoDao.findByPatientAndLabelAndLabelTypeAndStatus(patient, labelCode, labelType, 1);
        if (labelInfo == null) {
            return -1;
        }
        labelInfoDao.delete(labelInfo);
        return 1;
    }
    /**
     * 疾病转标签
     *
     * @return
     */
    public boolean diseaseToLabel() {
        List<PatientDisease> diseases = diseaseDao.findByDel("1");
        Iterator<Patient> patients = patientDao.findAll().iterator();
        Map<String, String> patientNames = new HashMap<>();
        while (patients.hasNext()) {
            Patient p = patients.next();
            patientNames.put(p.getCode(), p.getName());
        }
        for (PatientDisease disease : diseases) {
            SignPatientLabelInfo labelInfo = new SignPatientLabelInfo();
            labelInfo.setPatient(disease.getPatient());
            labelInfo.setPname(patientNames.get(disease.getPatient()));
            labelInfo.setLabel(disease.getDisease());
            labelInfo.setLabelName(disease.getDiseaseName());
            labelInfo.setLabelType("3");
            labelInfo.setStatus(1);
            labelInfo.setCzrq(new Date());
            labelInfoDao.save(labelInfo);
        }
        return true;
    }
    /**
     * 分组转标签
     *
     * @return
     */
    public boolean groupToLabel() throws Exception {
        Iterator<Patient> patients = patientDao.findAll().iterator();
        Map<String, Patient> patientNames = new HashMap<>();
        Map<String, SignPatientLabelInfo> normalLabel = new HashMap<>();
        Map<String, SignPatientLabelInfo> manbingLabel = new HashMap<>();
        Map<String, SignPatientLabelInfo> sixFiveLabel = new HashMap<>();
        while (patients.hasNext()) {
            Patient p = patients.next();
            patientNames.put(p.getCode(), p);
        }
        List<DoctorPatientGroupInfo> groupInfos = groupInfoDao.findByGroupAndStatus("1", 1);
        for (DoctorPatientGroupInfo groupInfo : groupInfos) {
            Patient p = patientNames.get(groupInfo.getPatient());
            if (p == null) {
                continue;
            }
            SignPatientLabelInfo labelInfo = new SignPatientLabelInfo();
            labelInfo.setPatient(p.getCode());
            labelInfo.setPname(p.getName());
            labelInfo.setLabel("1");
            labelInfo.setLabelName("普通人群");
            labelInfo.setLabelType("1");
            labelInfo.setStatus(1);
            labelInfo.setCzrq(new Date());
            normalLabel.put(p.getCode(), labelInfo);
        }
        List<DoctorPatientGroupInfo> groupInfos1 = groupInfoDao.findByGroupAndStatus("2", 1);
        for (DoctorPatientGroupInfo groupInfo : groupInfos1) {
            Patient p = patientNames.get(groupInfo.getPatient());
            if (p == null) {
                continue;
            }
            SignPatientLabelInfo labelInfo = new SignPatientLabelInfo();
            labelInfo.setPatient(p.getCode());
            labelInfo.setPname(p.getName());
            labelInfo.setLabel("2");
            labelInfo.setLabelName("慢病人群");
            labelInfo.setLabelType("1");
            labelInfo.setStatus(1);
            labelInfo.setCzrq(new Date());
            manbingLabel.put(p.getCode(), labelInfo);
        }
        List<DoctorPatientGroupInfo> groupInfos2 = groupInfoDao.findByGroupAndStatus("3", 1);
        for (DoctorPatientGroupInfo groupInfo : groupInfos2) {
            Patient p = patientNames.get(groupInfo.getPatient());
            if (p == null) {
                continue;
            }
            SignPatientLabelInfo labelInfo = new SignPatientLabelInfo();
            labelInfo.setPatient(p.getCode());
            labelInfo.setPname(p.getName());
            labelInfo.setLabel("3");
            labelInfo.setLabelName("65岁以上人群");
            labelInfo.setLabelType("1");
            labelInfo.setStatus(1);
            labelInfo.setCzrq(new Date());
            sixFiveLabel.put(p.getCode(), labelInfo);
        }
        if (normalLabel.size() > 0) {
            for (SignPatientLabelInfo labelInfo : normalLabel.values()) {
                labelInfoDao.save(labelInfo);
            }
        }
        if (manbingLabel.size() > 0) {
            for (SignPatientLabelInfo labelInfo : manbingLabel.values()) {
                labelInfoDao.save(labelInfo);
            }
        }
        if (sixFiveLabel.size() > 0) {
            for (SignPatientLabelInfo labelInfo : sixFiveLabel.values()) {
                labelInfoDao.save(labelInfo);
            }
        }
        return true;
    }
}

+ 178 - 0
src/main/java/com/yihu/wlyy/service/app/label/SignPatientLabelService.java

@ -0,0 +1,178 @@
package com.yihu.wlyy.service.app.label;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabel;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabelLog;
import com.yihu.wlyy.repository.doctor.SignPatientLabelDao;
import com.yihu.wlyy.repository.doctor.SignPatientLabelLogDao;
import com.yihu.wlyy.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * 标签服务类
 * <p>
 * Created by lyr on 2016/10/9.
 */
@Service
@Transactional
public class SignPatientLabelService extends BaseService {
    @Autowired
    SignPatientLabelDao labelDao;
    @Autowired
    SignPatientLabelLogDao labelLogDao;
    /**
     * 新增自定义标签
     *
     * @param lableName 标签名称
     * @param creator   创建人
     * @param teamCode  所属团队
     * @return
     */
    public SignPatientLabel addLabel(String lableName, String creator, long teamCode) {
        SignPatientLabel label = new SignPatientLabel();
        label.setLabelCode(getCode());
        label.setLabelName(lableName);
        label.setLabelType("4");
        label.setIsSystem(1);
        label.setCreator(creator);
        label.setTeamCode(teamCode);
        label.setStatus(1);
        label.setCzrq(new Date());
        return labelDao.save(label);
    }
    /**
     * 修改某个自定义标签
     *
     * @param labelCode 标签code
     * @param newName   新名称
     * @return
     */
    public int modifyLabel(String labelCode, String newName, String modifyBy) {
        SignPatientLabel label = labelDao.findByLabelCodeAndLabelTypeAndStatus(labelCode, "4", 1);
        if (label == null) {
            // 标签不存在
            return -1;
        }
        if (label.getIsSystem() == 1) {
            // 系统标签不能修改
            return -2;
        }
        SignPatientLabelLog log = new SignPatientLabelLog();
        log.setLabelCode(labelCode);
        log.setOldName(label.getLabelName());
        log.setNewName(newName);
        log.setModifyType(1);
        log.setModifyBy(modifyBy);
        log.setCzrq(new Date());
        label.setLabelName(newName);
        label.setCzrq(new Date());
        labelLogDao.save(log);
        return 1;
    }
    /**
     * 删除某个自定义标签
     *
     * @param labelCode 标签code
     * @return
     */
    public int deleteLabel(String labelCode, String modifyBy) {
        SignPatientLabel label = labelDao.findByLabelCodeAndLabelTypeAndStatus(labelCode, "4", 1);
        if (label == null) {
            // 标签不存在
            return -1;
        }
        if (label.getIsSystem() == 1) {
            // 系统标签不能删除
            return -2;
        }
        SignPatientLabelLog log = new SignPatientLabelLog();
        log.setLabelCode(labelCode);
        log.setModifyType(2);
        log.setModifyBy(modifyBy);
        log.setCzrq(new Date());
        label.setStatus(0);
        label.setCzrq(new Date());
        labelLogDao.save(log);
        return 1;
    }
    /**
     * 查询某个团队的标签
     *
     * @param teamCode 团队code
     * @return
     */
    public List<SignPatientLabel> getTeamAllLabels(long teamCode) {
        List<SignPatientLabel> labels = new ArrayList<>();
        // 非自定义系统标签
        List<SignPatientLabel> systemLabels = labelDao.findSystemLabels();
        if (systemLabels.size() > 0) {
            labels.addAll(systemLabels);
        }
        // 自定义标签
        List<SignPatientLabel> customLabels = labelDao.findCustomLabels(teamCode);
        if (customLabels.size() > 0) {
            labels.addAll(customLabels);
        }
        return labels;
    }
    /**
     * 查询某个团队的自定义标签
     *
     * @param teamCode 团队code
     * @return
     */
    public List<SignPatientLabel> getLabelsByTypeAndTeam(String labelType, long teamCode) {
        List<SignPatientLabel> labels = new ArrayList<>();
        if (labelType.equals("4")) {
            // 自定义标签
            labels = labelDao.findCustomLabels(teamCode);
        } else {
            labels = labelDao.findByLabelTypeAndStatus(labelType, 1);
        }
        return labels;
    }
    /**
     * 查询某个标签
     *
     * @param labelCode 标签code
     * @param labelType 标签类型
     * @return
     */
    public SignPatientLabel getLabelByCodeAndType(String labelCode, String labelType) {
        return labelDao.findByLabelCodeAndLabelTypeAndStatus(labelCode,labelType,1);
    }
}

+ 1 - 0
src/main/java/com/yihu/wlyy/task/SignUploadTask.java

@ -28,6 +28,7 @@ public class SignUploadTask implements Runnable {
    @Override
    public void run() {
        try {
            Thread.sleep(3000);
            String url = SystemConf.getInstance().getSystemProperties().getProperty("sign_check_upload");
            String resultStr = HttpUtil.sendPost(url + "/third/sign/UploadSignFamily?code=" + code, "");
            JSONObject json = new JSONObject(resultStr);

+ 75 - 36
src/main/java/com/yihu/wlyy/util/IdCardUtil.java

@ -1,11 +1,14 @@
package com.yihu.wlyy.util;
import com.yihu.wlyy.job.Constant;
import org.apache.commons.lang3.StringUtils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
/**
 * Created by Administrator on 2016.08.17.
@ -26,70 +29,105 @@ public class IdCardUtil {
        if (CardCode.length() == 18) {
            if (Integer.parseInt(CardCode.substring(16).substring(0, 1)) % 2 == 0) {// 判断性别
                // modifid by lyr 2016-09-29
               // sex =  Constant.level_sex_2;
                sex =  Constant.level_sex_1;
                // sex =  Constant.level_sex_2;
                sex = Constant.level_sex_1;
                // modifid by lyr 2016-09-29
            } else {
                // modifid by lyr 2016-09-29
               // sex =  Constant.level_sex_1;
                sex =  Constant.level_sex_2;
                // sex =  Constant.level_sex_1;
                sex = Constant.level_sex_2;
                // modifid by lyr 2016-09-29
            }
        } else if (CardCode.length() == 15) {
            String usex = CardCode.substring(14, 15);// 用户的性别
            if (Integer.parseInt(usex) % 2 == 0) {
                // sex =  Constant.level_sex_2;
                sex =  Constant.level_sex_1;
                sex = Constant.level_sex_1;
            } else {
                // sex =  Constant.level_sex_1;
                sex =  Constant.level_sex_2;
                sex = Constant.level_sex_2;
            }
        }
        return sex;
    }
//    /**
//     * 根据身份证的号码算出当前身份证持有者的年龄
//     *
//     * @param
//     * @throws Exception
//     */
//    public static int getAgeForIdcard(String card)
//            throws Exception {
//        int age = 0;
//        if (card.length() == 18) {
//            String year = card.substring(6).substring(0, 4);// 得到年份
//            String yue = card.substring(10).substring(0, 2);// 得到月份
//            // String day=CardCode.substring(12).substring(0,2);//得到日
//            Date date = new Date();// 得到当前的系统时间
//            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//            String fyear = format.format(date).substring(0, 4);// 当前年份
//            String fyue = format.format(date).substring(5, 7);// 月份
//            if (Integer.parseInt(yue) <= Integer.parseInt(fyue)) { // 当前月份大于用户出身的月份表示已过生
//                age = Integer.parseInt(fyear) - Integer.parseInt(year) + 1;
//            } else {// 当前用户还没过生
//                age = Integer.parseInt(fyear) - Integer.parseInt(year);
//            }
//        } else if (card.length() == 15) {
//            String uyear = "19" + card.substring(6, 8);// 年份
//            String uyue = card.substring(8, 10);// 月份
//            Date date = new Date();// 得到当前的系统时间
//            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//            String fyear = format.format(date).substring(0, 4);// 当前年份
//            String fyue = format.format(date).substring(5, 7);// 月份
//            // String fday=format.format(date).substring(8,10);
//            if (Integer.parseInt(uyue) <= Integer.parseInt(fyue)) { // 当前月份大于用户出身的月份表示已过生
//                age = Integer.parseInt(fyear) - Integer.parseInt(uyear) + 1;
//            } else {// 当前用户还没过生
//                age = Integer.parseInt(fyear) - Integer.parseInt(uyear);
//            }
//
//        }
//        return age;
//    }
    /**
     * 根据身份证的号码算出当前身份证持有者的年龄
     *
     * @param
     * @throws Exception
     */
    public static int getAgeForIdcard(String card)
            throws Exception {
    public static int getAgeForIdcard(String idcard) {
        int age = 0;
        if (card.length() == 18) {
            String year = card.substring(6).substring(0, 4);// 得到年份
            String yue = card.substring(10).substring(0, 2);// 得到月份
            // String day=CardCode.substring(12).substring(0,2);//得到日
            Date date = new Date();// 得到当前的系统时间
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            String fyear = format.format(date).substring(0, 4);// 当前年份
            String fyue = format.format(date).substring(5, 7);// 月份
            if (Integer.parseInt(yue) <= Integer.parseInt(fyue)) { // 当前月份大于用户出身的月份表示已过生
                age = Integer.parseInt(fyear) - Integer.parseInt(year) + 1;
            } else {// 当前用户还没过生
                age = Integer.parseInt(fyear) - Integer.parseInt(year);
            }
        } else if (card.length() == 15) {
            String uyear = "19" + card.substring(6, 8);// 年份
            String uyue = card.substring(8, 10);// 月份
            Date date = new Date();// 得到当前的系统时间
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            String fyear = format.format(date).substring(0, 4);// 当前年份
            String fyue = format.format(date).substring(5, 7);// 月份
            // String fday=format.format(date).substring(8,10);
            if (Integer.parseInt(uyue) <= Integer.parseInt(fyue)) { // 当前月份大于用户出身的月份表示已过生
                age = Integer.parseInt(fyear) - Integer.parseInt(uyear) + 1;
            } else {// 当前用户还没过生
                age = Integer.parseInt(fyear) - Integer.parseInt(uyear);
            }
        if (StringUtils.isEmpty(idcard)) {
            return age;
        }
        String birth = "";
        if (idcard.length() == 18) {
            birth = idcard.substring(6, 14);
        } else if (idcard.length() == 15) {
            birth = "19" + idcard.substring(6, 12);
        }
        int year = Integer.valueOf(birth.substring(0, 4));
        int month = Integer.valueOf(birth.substring(4, 6));
        int day = Integer.valueOf(birth.substring(6));
        Calendar cal = Calendar.getInstance();
        age = cal.get(Calendar.YEAR) - year;
        //周岁计算
        if (cal.get(Calendar.MONTH) > (month - 1) || (cal.get(Calendar.MONTH) == (month - 1) && cal.get(Calendar.DATE) > day)) {
            age--;
        }
        return age;
    }
    /**
     * 身份证提取出身日期
     *
     * @param card
     * @return
     * @throws Exception
@ -103,16 +141,17 @@ public class IdCardUtil {
            String ri = card.substring(12).substring(0, 2);// 得到日
            // String day=CardCode.substring(12).substring(0,2);//得到日
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            b=format.parse(year+"-"+yue+"-"+ri);
            b = format.parse(year + "-" + yue + "-" + ri);
        } else if (card.length() == 15) {
            String uyear = "19" + card.substring(6, 8);// 年份
            String uyue = card.substring(8, 10);// 月份
            String uri = card.substring(10, 12);// 得到日
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            b=format.parse(uyear+"-"+uyue+"-"+uri);
            b = format.parse(uyear + "-" + uyue + "-" + uri);
        }
        return b;
    }
    public static void main(String[] args) throws Exception {
        System.out.println(getSexForIdcard("350206199109092018"));
    }

+ 164 - 0
src/main/java/com/yihu/wlyy/web/doctor/patient/SignPatientLabelController.java

@ -0,0 +1,164 @@
package com.yihu.wlyy.web.doctor.patient;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabel;
import com.yihu.wlyy.service.app.label.SignPatientLabelService;
import com.yihu.wlyy.web.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
 * 标签控制类
 *
 * Created by lyr on 2016/10/9.
 */
@RestController
@RequestMapping(value = "/doctor/patient_label")
public class SignPatientLabelController extends BaseController {
    @Autowired
    SignPatientLabelService labelService;
    /**
     * 添加标签
     *
     * @param labelName 标签名称
     * @param teamCode  所属团队
     * @return
     */
    @RequestMapping(value = "/add")
    public String addPatientLabel(String labelName, Long teamCode) {
        try {
            if (StringUtils.isEmpty(labelName)) {
                return error(-1, "标签名称不能为空");
            }
            if (teamCode == null || teamCode <= 0) {
                return error(-1, "所属团队不能为空");
            }
            SignPatientLabel label = labelService.addLabel(labelName, getUID(), teamCode);
            if (label != null) {
                return write(200, "添加成功", "data", label);
            } else {
                return error(-1, "添加失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "添加失败");
        }
    }
    /**
     * 更新标签
     *
     * @param labelCode 标签code
     * @param newName   新名称
     * @return
     */
    @RequestMapping(value = "/modify")
    public String modifyPatientLabel(String labelCode, String newName) {
        try {
            if (StringUtils.isEmpty(labelCode)) {
                return error(-1, "标签code不能为空");
            }
            if (StringUtils.isEmpty(newName)) {
                return error(-1, "标签名称不能为空");
            }
            int result = labelService.modifyLabel(labelCode, newName, getUID());
            if (result == -1) {
                return error(-1, "标签不存在");
            } else if (result == -2) {
                return error(-1, "系统标签不能修改");
            }
            return write(200, "更新成功");
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "更新失败");
        }
    }
    /**
     * 更新标签
     *
     * @param labelCode 标签code
     * @return
     */
    @RequestMapping(value = "/delete")
    public String deletePatientLabel(String labelCode) {
        try {
            if (StringUtils.isEmpty(labelCode)) {
                return error(-1, "标签code不能为空");
            }
            int result = labelService.deleteLabel(labelCode, getUID());
            if (result == -1) {
                return error(-1, "标签不存在");
            } else if (result == -2) {
                return error(-1, "系统标签不能删除");
            }
            return write(200, "删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "删除失败");
        }
    }
    /**
     * 获取团队所有标签
     *
     * @param teamCode 团队代码
     * @return
     */
    @RequestMapping(value = "/all_labels")
    public String getTeamAllLabels(Long teamCode) {
        try {
            if (teamCode == null || teamCode <= 0) {
                return error(-1, "团队标识不能为空");
            }
            List<SignPatientLabel> labels = labelService.getTeamAllLabels(teamCode);
            return write(200, "查询成功", "data", labels);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
    /**
     * 获取某个标签类型所有标签
     *
     * @param labelType 标签类型
     * @param teamCode 团队代码
     * @return
     */
    @RequestMapping(value = "/labels_by_type")
    public String getLabelsByTypeAndTeam(String labelType, @RequestParam(required = false) Long teamCode) {
        try {
            if (StringUtils.isEmpty(labelType)) {
                return error(-1, "标签不能为空");
            }
            if (labelType.equals("4") && (teamCode == null || teamCode <= 0)) {
                return error(-1, "查询自定义标签团队code不能为空");
            }
            List<SignPatientLabel> labels = labelService.getLabelsByTypeAndTeam(labelType, teamCode);
            return write(200, "查询成功", "data", labels);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
}

+ 278 - 0
src/main/java/com/yihu/wlyy/web/doctor/patient/SignPatientLabelInfoController.java

@ -0,0 +1,278 @@
package com.yihu.wlyy.web.doctor.patient;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabelInfo;
import com.yihu.wlyy.service.app.label.SignPatientLabelInfoService;
import com.yihu.wlyy.web.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
 * 患者所属标签控制类
 * <p>
 * Created by lyr on 2016/10/9.
 */
@RestController
@RequestMapping(value = "/doctor/patient_label_info")
public class SignPatientLabelInfoController extends BaseController {
    @Autowired
    SignPatientLabelInfoService labelInfoService;
    /**
     * 查询某个团队的某个标签下的患者信息
     *
     * @param labelCode 标签code
     * @param labelType 标签类型
     * @param teamCode  团队code
     * @param page      第几页
     * @param pagesize  页大小
     * @return
     */
    @RequestMapping(value = "/patients_by_label")
    public String getPatientInfoByLabel(String labelCode, String labelType, Long teamCode, int page, int pagesize) {
        try {
            if (StringUtils.isEmpty(labelCode)) {
                return error(-1, "标签cdoe不能为空");
            }
            if (StringUtils.isEmpty(labelType)) {
                return error(-1, "标签类型不能为空");
            }
            if (StringUtils.isEmpty(String.valueOf(teamCode))) {
                return error(-1, "团队cdoe不能为空");
            }
            page = page - 1;
            JSONArray result = labelInfoService.getPatientByLabel("fa4dd8565f0f11e68344fa163e8aee56", labelCode, labelType, teamCode, page, pagesize);
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            return error(-1, "查询失败");
        }
    }
    /**
     * 查询某个团队的某个标签类型下各标签患者数
     *
     * @param labelType 标签类型
     * @param teamCode  团队code
     * @return
     */
    @RequestMapping(value = "/label_patient_amount")
    public String getPatientAmountByLabelType(String labelType, @RequestParam(required = false) Long teamCode) {
        try {
            if (StringUtils.isEmpty(labelType)) {
                return error(-1, "标签类型不能为空");
            }
            if (teamCode == null) {
                teamCode = 0L;
            }
            JSONArray result = labelInfoService.getPatientAmountByLabelType("fa4dd8565f0f11e68344fa163e8aee56", labelType, teamCode);
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            return error(-1, "查询失败");
        }
    }
    /**
     * 患者标签更新
     *
     * @param patient 患者
     * @param health  健康情况
     * @param disease 疾病情况
     * @param custom  自定义情况
     * @return
     */
    @RequestMapping(value = "/patient_label_update")
    public String setPatientLabels(String patient, String health, String disease, String custom) {
        try {
            if (StringUtils.isEmpty(patient)) {
                return error(-1, "患者不能为空");
            }
            if (StringUtils.isEmpty(health)) {
                return error(-1, "健康情况标签不能为空");
            }
            int result = labelInfoService.setPatientLabels(patient, "", "", health, disease, custom);
            if (result == 0) {
                return error(-1, "查不到患者信息");
            }
            if (result == -1) {
                return error(-1, "标签不存在");
            }
            if (result == -2) {
                return error(-1, "健康情况标签不能为空");
            }
            if (result == 1) {
                return write(200, "更新成功");
            } else {
                return error(-1, "更新失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "更新失败");
        }
    }
    /**
     * 查询某个患者的某类标签
     *
     * @param patient   患者
     * @param labelType 标签类型
     * @return
     */
    @RequestMapping(value = "/patient_label")
    public String getPatientLabelByLabelType(String patient, String labelType) {
        try {
            if (StringUtils.isEmpty(patient)) {
                return error(-1, "患者不能为空");
            }
            List<SignPatientLabelInfo> labels = labelInfoService.getPatientLabelByLabelType(patient, labelType);
            return write(200, "查询成功", "data", new JSONArray(labels));
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
    /**
     * 查询某个患者的某类标签
     *
     * @param filter 过滤字段
     * @return
     */
    @RequestMapping(value = "/patient_search")
    public String searchPatientByNameOrLabel(String filter, String labelCode, String labelType) {
        try {
            if (StringUtils.isEmpty(filter)) {
                return error(-1, "搜索字段不能为空");
            }
            if (!StringUtils.isEmpty(labelCode) || StringUtils.isEmpty(labelType)) {
                return error(-1, "标签参数不为空时标签类型不能为空");
            }
            JSONArray result = labelInfoService.searchPatientByNameOrLabel("fa4dd8565f0f11e68344fa163e8aee56", filter, labelCode, labelType);
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
    /**
     * 添加居民到某个标签
     *
     * @param patient   患者
     * @param labelCode 标签code
     * @param labelType 标签类型
     * @return
     */
    @RequestMapping(value = "/patient_label_add")
    public String addPatientLabel(String patient, String labelCode, String labelType) {
        try {
            if (StringUtils.isEmpty(String.valueOf(patient))) {
                return error(-1, "患者不能为空");
            }
            if (StringUtils.isEmpty(labelCode)) {
                return error(-1, "标签cdoe不能为空");
            }
            if (StringUtils.isEmpty(labelType)) {
                return error(-1, "标签类型不能为空");
            }
            int result = labelInfoService.addPatientLabel(patient, labelCode, labelType);
            if (result == -1) {
                return error(-1, "患者不存在");
            } else if (result == -2) {
                return error(-1, "患者已在此标签");
            } else if (result == -3) {
                return error(-1, "标签不存在");
            } else if (result == 1) {
                return error(200, "添加成功");
            } else {
                return error(-1, "添加失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "添加失败");
        }
    }
    /**
     * 删除居民某个标签
     *
     * @param patient   患者
     * @param labelCode 标签code
     * @param labelType 标签类型
     * @return
     */
    @RequestMapping(value = "/patient_label_delete")
    public String deletePatientLabel(String patient, String labelCode, String labelType) {
        try {
            if (StringUtils.isEmpty(String.valueOf(patient))) {
                return error(-1, "患者不能为空");
            }
            if (StringUtils.isEmpty(labelCode)) {
                return error(-1, "标签cdoe不能为空");
            }
            if (StringUtils.isEmpty(labelType)) {
                return error(-1, "标签类型不能为空");
            }
            int result = labelInfoService.deletePatientLabel(patient, labelCode, labelType);
            if (result == -1) {
                return error(-1, "患者没有此标签");
            } else if (result == 1) {
                return error(200, "添加成功");
            } else {
                return error(-1, "删除失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "删除失败");
        }
    }
    @RequestMapping(value = "/disease_to_label")
    public String diseaseToLabel() {
        try {
            if (labelInfoService.diseaseToLabel()) {
                return write(200, "转换成功");
            } else {
                return error(-1, "转换失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "转换失败");
        }
    }
    @RequestMapping(value = "/group_to_label")
    public String groupToLabel() {
        try {
            if (labelInfoService.groupToLabel()) {
                return write(200, "转换成功");
            } else {
                return error(-1, "转换失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "转换失败");
        }
    }
}