package com.zhyc.module.biosafety.enums;


/**
 * 诊疗结果枚举
 */
public enum DiagnosisResult {

    ABANDONED(0, "放弃"),
    CURED(1, "已治愈"),
    IN_TREATMENT(2, "治疗中"),
    COMPLETED(3, "治疗完成");

    private final int code;
    private final String desc;

    DiagnosisResult(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据code获取描述
     */
    public static String getDescByCode(Integer code) {
        if (code == null) {
            return "";
        }
        for (DiagnosisResult result : values()) {
            if (result.code == code) {
                return result.desc;
            }
        }
        return "";
    }

    /**
     * 根据code获取枚举
     */
    public static DiagnosisResult getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (DiagnosisResult result : values()) {
            if (result.code == code) {
                return result;
            }
        }
        return null;
    }

    /**
     * 根据描述获取code
     */
    public static Integer getCodeByDesc(String desc) {
        if (desc == null || desc.trim().isEmpty()) {
            return null;
        }
        for (DiagnosisResult result : values()) {
            if (result.desc.equals(desc)) {
                return result.code;
            }
        }
        return null;
    }
}