Browse Source

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

8 years ago
parent
commit
c45fb44bf6

+ 27 - 0
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/etl/BusinessTypeEnum.java

@ -0,0 +1,27 @@
package com.yihu.wlyy.analysis.etl;
/**
 * 业务类型
 *
 * Created by lyr-pc on 2017/2/17.
 */
public enum  BusinessTypeEnum {
    // 咨询
    consult
    // 指导
    , guidance
    // 健康教育
    , article
    // 随访
    , followup
    // 预约
    , appointment
    // 标签
    , label
    // 注册
    , register
    // 健康档案
    , archive
    // 签约
    , sign
}

+ 34 - 0
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/etl/ILogTransform.java

@ -0,0 +1,34 @@
package com.yihu.wlyy.analysis.etl;
import com.yihu.wlyy.analysis.model.DataModel;
import com.yihu.wlyy.analysis.model.emun.BusinessType;
import org.json.JSONObject;
/**
 * 日志信息提取分析
 * <p>
 * Created by lyr-pc on 2017/2/17.
 */
public interface ILogTransform {
    /**
     * 日志信息提取分析
     *
     * @param log
     */
    void transform(DataModel log);
    /**
     * 获取日志类型
     *
     * @return
     */
    int getLogType();
    /**
     * 获取日志类型名称
     *
     * @return
     */
    String getLogTypeName();
}

+ 99 - 0
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/etl/LogDataTransform.java

@ -0,0 +1,99 @@
package com.yihu.wlyy.analysis.etl;
import com.yihu.wlyy.analysis.model.DataModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileFilter;
import java.util.HashMap;
import java.util.Map;
/**
 * 日志信息分析提取
 * <p>
 * Created by lyr-pc on 2017/2/17.
 */
public class LogDataTransform {
    private static Logger logger = LoggerFactory.getLogger(LogDataTransform.class);
    // 日志清洗类
    private Map<String, ILogTransform> transforms = new HashMap<>();
    private LogDataTransform instance;
    private static Object obj = new Object();
    /**
     * 初始化
     */
    private LogDataTransform() {
        init();
    }
    /**
     * 获取日志清洗实例
     *
     * @return
     */
    public LogDataTransform getLogTransform() {
        synchronized (obj) {
            if (this.instance == null) {
                this.instance = new LogDataTransform();
            }
        }
        return this.instance;
    }
    /**
     * 日志信息分析提取
     *
     * @param log
     */
    public void transform(DataModel log) {
        try {
            ILogTransform transform = transforms.get(log.getLogType());
            if (transform == null) {
                logger.error("logType:" + log.getLogType() + " transform can not find");
            } else {
                transform.transform(log);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
        }
    }
    /**
     * 初始化加载日志提取分析类
     */
    public void init() {
        try {
            logger.info("log transform begin init");
            transforms.clear();
            String path = LogDataTransform.class.getResource(".").getPath();
            String rootPath = LogDataTransform.class.getResource("/").getPath();
            File root = new File(rootPath);
            File fileEtl = new File(path, "transform");
            File[] files = fileEtl.listFiles((pathname) -> {
                return pathname.getName().endsWith("Transform.class");
            });
            ClassLoader classLoader = ClassLoader.getSystemClassLoader();
            for (File file : files) {
                String className = file.getAbsolutePath()
                        .replace(root.getAbsolutePath() + "\\", "")
                        .replace("\\", ".")
                        .replace(".class", "");
                Class logClass = classLoader.loadClass(className);
                ILogTransform logTransform = (ILogTransform) logClass.newInstance();
                transforms.put(String.valueOf(logTransform.getLogType()), logTransform);
            }
            logger.info("log transform init success");
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("log transform init failed");
        }
    }
}

+ 26 - 0
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/etl/transform/ConsultLogTransform.java

@ -0,0 +1,26 @@
package com.yihu.wlyy.analysis.etl.transform;
import com.yihu.wlyy.analysis.etl.BusinessTypeEnum;
import com.yihu.wlyy.analysis.etl.ILogTransform;
import com.yihu.wlyy.analysis.model.DataModel;
/**
 * Created by lyr-pc on 2017/2/17.
 */
public class ConsultLogTransform implements ILogTransform {
    @Override
    public void transform(DataModel log) {
    }
    @Override
    public int getLogType() {
        return BusinessTypeEnum.consult.ordinal();
    }
    @Override
    public String getLogTypeName() {
        return BusinessTypeEnum.consult.name();
    }
}

+ 30 - 0
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/etl/transform/RegisterLogTransform.java

@ -0,0 +1,30 @@
package com.yihu.wlyy.analysis.etl.transform;
import com.yihu.wlyy.analysis.etl.ILogTransform;
import com.yihu.wlyy.analysis.etl.BusinessTypeEnum;
import com.yihu.wlyy.analysis.model.DataModel;
/**
 * 注册日志信息提取分析
 * <p>
 * Created by lyr-pc on 2017/2/17.
 */
public class RegisterLogTransform implements ILogTransform {
    @Override
    public void transform(DataModel log) {
    }
    @Override
    public int getLogType() {
        return BusinessTypeEnum.register.ordinal();
    }
    @Override
    public String getLogTypeName() {
        return BusinessTypeEnum.register.name();
    }
}

+ 108 - 0
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/etl/util/IdcardUtil.java

@ -0,0 +1,108 @@
package com.yihu.wlyy.analysis.etl.util;
import org.apache.commons.lang3.StringUtils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
 * 身份证号工具类
 *
 * Created by lyr-pc on 2017/2/17.
 */
public class IdcardUtil {
    /**
     * 根据身份证的号码算出当前身份证持有者的年龄
     *
     * @param
     * @throws Exception
     */
    public static int getAgeForIdcard(String idcard) {
        try {
            int age = -1;
            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;
        } catch (Exception e) {
            return -1;
        }
    }
    /**
     * 根据身份证的号码算出当前身份证持有者的性别
     * 1 男 2 女 3未知
     *
     * @return
     * @throws Exception
     */
    public static String getSexForIdcard(String CardCode)
            throws Exception {
        String sex = "3";
        if (CardCode.length() == 18) {
            if (Integer.parseInt(CardCode.substring(16).substring(0, 1)) % 2 == 0) {// 判断性别
                sex = "2";
            } else {
                sex = "1";
            }
        } else if (CardCode.length() == 15) {
            String usex = CardCode.substring(14, 15);// 用户的性别
            if (Integer.parseInt(usex) % 2 == 0) {
                sex = "2";
            } else {
                sex = "1";
            }
        }
        return sex;
    }
    /**
     * 身份证提取出身日期
     *
     * @param card
     * @return
     * @throws Exception
     */
    public static Date getBirthdayForIdcard(String card)
            throws Exception {
        Date b = null;
        if (card.length() == 18) {
            String year = card.substring(6).substring(0, 4);// 得到年份
            String yue = card.substring(10).substring(0, 2);// 得到月份
            String ri = card.substring(12).substring(0, 2);// 得到日
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            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);
        }
        return b;
    }
}

+ 5 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/template/DoctorGuidanceTempDao.java

@ -1,6 +1,9 @@
package com.yihu.wlyy.repository.template;
import com.yihu.wlyy.entity.template.DoctorGuidanceTemp;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
@ -17,8 +20,8 @@ public interface DoctorGuidanceTempDao extends PagingAndSortingRepository<Doctor
    int deleteByCode(String code);
    @Query("select t from DoctorGuidanceTemp t where t.owner = ?1 order by t.sendTimes desc")
    List<DoctorGuidanceTemp> findByOwner(String owner);
    Page<List<DoctorGuidanceTemp>> findByOwner(String owner, Pageable pageRequest);
    @Query("select t from DoctorGuidanceTemp t where t.owner = ?1 or t.owner = 'system' order by t.sendTimes desc")
    List<DoctorGuidanceTemp> findByOwnerAndSystem(String owner);
    Page<List<DoctorGuidanceTemp>> findByOwnerAndSystem(String owner, Pageable pageRequest);
}

+ 46 - 25
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/template/DoctorGuidanceTempService.java

@ -6,6 +6,8 @@ import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.CommonUtil;
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.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -150,42 +152,61 @@ public class DoctorGuidanceTempService extends BaseService {
     * @param type   模板类型
     * @return
     */
    public List<Map<String,Object>> list(String doctor, String type) throws Exception {
        List<DoctorGuidanceTemp> temps = null;
    public List<Map<String,Object>> list(String doctor, String type,int pageSize) throws Exception {
//        List<DoctorGuidanceTemp> temps = null;
        Page<List<DoctorGuidanceTemp>> temps = null;
        PageRequest pageRequest = new PageRequest(0, pageSize);
        List<Map<String,Object>> listMap = new ArrayList<>();
        if (type.equals("1")) {
            temps = guidanceTempDao.findByOwner("system");
            for(DoctorGuidanceTemp temp : temps){
            temps = guidanceTempDao.findByOwner("system",pageRequest);
            /*for(List<DoctorGuidanceTemp> te : temps){
                for (DoctorGuidanceTemp temp : te){
                    Map<String,Object> tem = new HashMap<>();
                    tem.put("code",temp.getCode());
                    tem.put("owner",temp.getOwner());
                    tem.put("sendTimes",temp.getSendTimes());
                    tem.put("lastTime",temp.getLastTime());
                    tem.put("modelName",temp.getModelName());
                    listMap.add(tem);
                }
            }*/
            List<List<DoctorGuidanceTemp>> temd = temps.getContent();
            for (int i=0;i<temd.size();i++){
                DoctorGuidanceTemp doctorGuidanceTemp = (DoctorGuidanceTemp)temd.get(i);
                Map<String,Object> tem = new HashMap<>();
                tem.put("code",temp.getCode());
                tem.put("owner",temp.getOwner());
                tem.put("sendTimes",temp.getSendTimes());
                tem.put("lastTime",temp.getLastTime());
                tem.put("modelName",temp.getModelName());
                tem.put("code",doctorGuidanceTemp.getCode());
                tem.put("owner",doctorGuidanceTemp.getOwner());
                tem.put("sendTimes",doctorGuidanceTemp.getSendTimes());
                tem.put("lastTime",doctorGuidanceTemp.getLastTime());
                tem.put("modelName",doctorGuidanceTemp.getModelName());
                listMap.add(tem);
            }
        } else if (type.equals("2")) {
            temps = guidanceTempDao.findByOwner(doctor);
            for(DoctorGuidanceTemp temp : temps){
                Map<String,Object> tem = new HashMap<>();
                tem.put("code",temp.getCode());
                tem.put("owner",temp.getOwner());
                tem.put("sendTimes",temp.getSendTimes());
                tem.put("lastTime",temp.getLastTime());
                tem.put("modelName",temp.getModelName());
                listMap.add(tem);
            temps = guidanceTempDao.findByOwner(doctor,pageRequest);
            List<List<DoctorGuidanceTemp>> temd = temps.getContent();
            for (int i=0;i<temd.size();i++){
                DoctorGuidanceTemp doctorGuidanceTemp = (DoctorGuidanceTemp)temd.get(i);
                    Map<String,Object> tem = new HashMap<>();
                    tem.put("code",doctorGuidanceTemp.getCode());
                    tem.put("owner",doctorGuidanceTemp.getOwner());
                    tem.put("sendTimes",doctorGuidanceTemp.getSendTimes());
                    tem.put("lastTime",doctorGuidanceTemp.getLastTime());
                    tem.put("modelName",doctorGuidanceTemp.getModelName());
                    listMap.add(tem);
            }
        } else {
            temps = guidanceTempDao.findByOwnerAndSystem(doctor);
            for(DoctorGuidanceTemp temp : temps){
            temps = guidanceTempDao.findByOwnerAndSystem(doctor,pageRequest);
            List<List<DoctorGuidanceTemp>> temd = temps.getContent();
            for (int i=0;i<temd.size();i++){
                DoctorGuidanceTemp doctorGuidanceTemp = (DoctorGuidanceTemp)temd.get(i);
                Map<String,Object> tem = new HashMap<>();
                tem.put("code",temp.getCode());
                tem.put("owner",temp.getOwner());
                tem.put("sendTimes",temp.getSendTimes());
                tem.put("lastTime",temp.getLastTime());
                tem.put("modelName",temp.getModelName());
                tem.put("code",doctorGuidanceTemp.getCode());
                tem.put("owner",doctorGuidanceTemp.getOwner());
                tem.put("sendTimes",doctorGuidanceTemp.getSendTimes());
                tem.put("lastTime",doctorGuidanceTemp.getLastTime());
                tem.put("modelName",doctorGuidanceTemp.getModelName());
                listMap.add(tem);
            }
        }

+ 4 - 3
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/template/DoctorGuidanceTempController.java

@ -2,7 +2,6 @@ package com.yihu.wlyy.web.doctor.template;
import com.yihu.wlyy.entity.template.DoctorGuidanceTemp;
import com.yihu.wlyy.service.template.DoctorGuidanceTempService;
import com.yihu.wlyy.util.CommonUtil;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -178,9 +177,11 @@ public class DoctorGuidanceTempController extends BaseController {
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation(value = "查询指导模板")
    public String list(@RequestParam(required = false, defaultValue = "")
                       @ApiParam(value = "模板类型 1:系统 2:自定义 为空:所有") String type) {
                       @ApiParam(value = "模板类型 1:系统 2:自定义 为空:所有") String type,
                       @RequestParam(defaultValue = "10") String pageSize) {
        try {
            List<Map<String,Object>> temps = guidanceTempService.list(getUID(), type);
            int pagesize = Integer.parseInt(pageSize);
            List<Map<String,Object>> temps = guidanceTempService.list(getUID(), type,pagesize);
            if (temps == null || temps.size() < 1) {
                return write(200, "查询成功", "data", new JSONArray());