package com.yihu.wlyy.analysis.etl.transform;

import com.yihu.wlyy.analysis.entity.UserPortrait;
import com.yihu.wlyy.analysis.etl.BusinessTypeEnum;
import com.yihu.wlyy.analysis.etl.ILogTransform;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 健康档案日志分析
 *
 * Created by lyr-pc on 2017/2/22.
 */
public class HealthArchiveLogTransform implements ILogTransform {

    private final BusinessTypeEnum logType = BusinessTypeEnum.archive;

    @Override
    public List<UserPortrait> transform(JSONObject log) throws Exception {
        JSONObject logData = log.getJSONObject("data");
        JSONObject businessData = logData.getJSONObject("data");
        List<UserPortrait> labelInfoList = new ArrayList<>();


        return labelInfoList;
    }

    @Override
    public int getLogType() {
        return logType.ordinal();
    }

    @Override
    public String getLogTypeName() {
        return logType.name();
    }

    /**
     * 获取诊断结果
     *
     * @param log
     * @return
     */
    public UserPortrait transformDiagnosis(JSONObject log) {
        String diagnosis = log.getString("diagnosis");

        if(StringUtils.isEmpty(diagnosis)) {
            return null;
        }

        UserPortrait userPortrait = new UserPortrait();

        userPortrait.setUserCode(log.getString("patient"));
        userPortrait.setCategory("1002");
        userPortrait.setSubCategory("1002001");
        userPortrait.setValue(diagnosis);
        userPortrait.setCzrq(new Date());

        return userPortrait;
    }

}
