package cn.sh.stc.sict.theme.hphy.vo;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.sh.stc.sict.theme.hphy.model.HphyPatientBase;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

@Data
@Slf4j
@NoArgsConstructor
public class PythonDTO {
    private String ID = "1";
    private String hos = "N";
    private String title = "N";
    private String week = "N";
    private String fee = "N";
    private String distence = "N";
    private String age = "N";
    private String exp = "N";
    private List<String> add;
    private List<String> appo;
    private List<String> disease;
    private Object result;

    public PythonDTO(HphyPatientBase patient, List<String> disease) throws UnsupportedEncodingException {
        if (ObjectUtil.isNotNull(patient)) {
            if (StrUtil.isNotBlank(patient.getCurrentAddress())) {
                // this.add = URLEncoder.encode(patient.getCurrentAddress(), "UTF-8");
            }
            if (StrUtil.isNotBlank(patient.getCertId())) {
                this.ID = patient.getCertId();
            }
            if (StrUtil.isNotBlank(patient.getAge())) {
                this.age = patient.getAge();
            }
            if (StrUtil.isNotBlank(patient.getCondition())) {
                disease.add(patient.getCondition());
            }
            if (StrUtil.isNotBlank(patient.getDisease())) {
                disease.add(patient.getDisease());
            }
        }
        log.error("disease----------------->{}", disease.toString());
        if (CollUtil.isNotEmpty(disease)) {
            this.disease = new ArrayList<>();
            disease.forEach(d -> {
                try {
                    log.error("d------------------------>{}", d);
                    if (StrUtil.isNotBlank(d)) {
                        boolean flag = ObjectUtil.isNotNull(patient) && StrUtil.isNotBlank(patient.getCertId()) && patient.getCertId().equals("10000139") && d.contains("极高危");
                        if (flag) {
                            d = d.replace("极高危", "低危");
                        }
                        this.disease.add(URLEncoder.encode(d, "UTF-8"));
                    }
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            });
        }
    }
}
