package thyyxxk.webserver.utils;

import thyyxxk.webserver.constants.sidicts.Gend;
import thyyxxk.webserver.constants.sidicts.Insutype;
import thyyxxk.webserver.constants.sidicts.MedType;
import thyyxxk.webserver.constants.sidicts.PsnType;
import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetlinfo;

/**
 * @author dj
 */
public class FilterUtil {
    @SuppressWarnings("unchecked")
    public static <T> T cast(Object x) {
        return (T) x;
    }

    public static String filterDismissWay(String code) {
        if (StringUtil.isBlank(code)) {
            return "";
        }
        switch (code) {
            case "0":
                return "1";
            case "1":
                return "2";
            case "2":
                return "3";
            case "3":
                return "4";
            case "4":
                return "5";
            case "5":
                return "9";
        }
        return "";
    }

    public static String filterHnsybBizType(String bizType) {
        switch (bizType) {
            case "10":
                return "药店购药";
            case "11":
                return "普通门诊";
            case "12":
                return "普通住院";
            case "13":
                return "门诊特殊病";
            case "14":
                return "家庭病床";
            case "16":
                return "特治特查";
            case "17":
                return "急诊留观";
            case "18":
                return "特殊药品";
            case "41":
                return "工伤门诊";
            case "42":
                return "工伤住院";
            case "44":
                return "工伤家庭病床";
            case "45":
                return "工伤辅助器具";
            case "51":
                return "生育门诊";
            case "52":
                return "生育住院";
            default:
                return "未知";
        }
    }

    public static String filterPersonType(String personType) {
        switch (personType) {
            case "11":
                return "在职待遇";
            case "21":
                return "退休待遇";
            case "31":
                return "离休待遇";
            case "33":
                return "伤残军人待遇";
            case "41":
                return "非从业居民";
            case "42":
                return "老年";
            case "43":
                return "未成年";
            case "44":
                return "婴幼儿";
            case "45":
                return "中小学生";
            case "46":
                return "大学生";
            case "47":
                return "新农合";
            case "48":
                return "扶贫对象";
            default:
                return "未知";
        }
    }

    public static String filterCssybBizType(String bizType) {
        switch (bizType) {
            case "11":
                return "普通门诊";
            case "12":
                return "定点药店购药";
            case "13":
                return "门诊慢性病";
            case "14":
                return "门诊特病";
            case "15":
                return "门诊特检特治";
            case "16":
                return "急诊抢救";
            case "21":
                return "普通住院";
            case "22":
                return "市内转院";
            case "24":
                return "转市外就医";
            case "25":
                return "家庭病床";
            case "26":
                return "异地就医";
            case "27":
                return "非定点医疗机构就医";
            case "28":
                return "院内相关疾病转科";
            case "29":
                return "院内无关疾病转科";
            case "30":
                return "特殊费用二次报销";
            case "99":
                return "所有类别";
            case "71":
                return "动物咬伤";
            case "23":
                return "单病种住院";
            case "51":
                return "生育门诊";
            case "52":
                return "节育门诊";
            case "53":
                return "生育住院";
            case "54":
                return "节育住院";
            case "61":
                return "城居普通住院";
            case "62":
                return "城居普通门诊";
            case "63":
                return "城居单病种住院";
            case "64":
                return "城居门诊特病";
            case "65":
                return "城居家庭病床";
            case "66":
                return "青少年意外伤害门诊";
            case "69":
                return "城居门诊统筹";
            case "72":
                return "城居生育门诊";
            case "73":
                return "城居生育住院";
            case "20":
                return "单病种门诊";
            case "68":
                return "城居大学生门诊统筹";
            case "31":
                return "灵活就业生育";
            case "41":
                return "工伤普门";
            case "42":
                return "待定工伤住院";
            case "43":
                return "工伤特门";
            case "44":
                return "工伤住院";
            case "45":
                return "康复门诊";
            case "46":
                return "康复住院";
            case "47":
                return "特门检查";
            case "48":
                return "劳动能力鉴定";
            case "50":
                return "工伤家庭病床";
            case "60":
                return "城居急诊抢救";
            default:
                return "未知";
        }
    }

    public static String filterOrderType(Integer orderType) {
        // 订单类型，1：挂号费 2：门诊缴费 3：住院预交金
        if (null == orderType) {
            return "";
        }
        switch (orderType) {
            case 1:
                return "挂号费";
            case 2:
                return "门诊缴费";
            case 3:
                return "住院预交金";
            default:
                return "未知类型";
        }
    }

    public static String filterTradeState(String status) {
        // 订单支付状态，99：初值，0：未支付，1：支付成功，2：已关闭，3：支付失败，4：已退款，5：已接收，等待扣款，6：用户支付中，7：退款失败
        if (null == status) {
            return "";
        }
        switch (status) {
            case "NOTPAY":
                return "未支付";
            case "SUCCESS":
                return "支付成功";
            case "CLOSED":
                return "已关闭";
            case "PAYERROR":
                return "支付失败";
            case "REFUND":
                return "已退款";
            case "REVOKED":
                return "已撤销";
            default:
                return "未知状态";
        }
    }

    public static void filterCodeToName(SiSetlinfo item) {
        item.setGendName(Gend.get(item.getGend()).getName());
        Insutype insutype = Insutype.get(item.getInsutype());
        if (null != insutype) {
            item.setInsutypeName(insutype.getName());
        }
        PsnType psnType = PsnType.get(item.getPsnType());
        if (null != psnType) {
            item.setPsnTypeName(psnType.getName());
        }
        MedType medType = MedType.get(item.getMedType());
        if (null != medType) {
            item.setMedTypeName(medType.getName());
        }
    }

    public static String translateGender(String gender) {
        if (null == gender) {
            return "未知";
        }
        switch (gender) {
            case "1":
                return "男";
            case "2":
                return "女";
            default:
                return "未知";
        }
    }

    public static String translateAdmissWay(String code) {
        if (null == code) {
            return "其他";
        }
        switch (code) {
            case "1":
                return "急诊";
            case "2":
                return "门诊";
            case "3":
                return "其他医疗机构转入";
            case "4":
                return "GCP实验";
            default:
                return "其他";
        }
    }

    public static String translateQualityLevel(String code) {
        if (null == code) {
            return "";
        }
        switch (code) {
            case "1":
                return "I";
            case "2":
                return "II";
            case "3":
                return "III";
            case "4":
                return "IV";
            case "5":
                return "V";
            default:
                return "";
        }
    }

    public static String translateDismissWay(String code) {
        if (null == code) {
            return "其他";
        }
        switch (code) {
            case "0":
                return "医嘱离院";
            case "1":
                return "医嘱转院";
            case "2":
                return "医嘱转社区卫生服务机构/乡镇卫生院";
            case "3":
                return "非医嘱离院";
            case "4":
                return "死亡";
            default:
                return "其他";
        }
    }

    public static String translateYesOrNo(String code) {
        if (StringUtil.isBlank(code)) {
            return "";
        }
        switch (code) {
            case "1":
                return "是";
            case "2":
                return "否";
            default:
                return "";
        }
    }

    public static String translateClnclPthwyMngmnt(String code) {
        if (null == code) {
            return "";
        }
        switch (code) {
            case "1":
                return "完成";
            case "2":
                return "变异";
            case "3":
                return "退出";
            case "4":
                return "未入";
            default:
                return "";
        }
    }

    public static String translateDrgsManagement(String code) {
        if (null == code) {
            return "";
        }
        switch (code) {
            case "1":
                return "无";
            case "2":
                return "按病种";
            case "3":
                return "按费用";
            case "4":
                return "两者都有";
            default:
                return "";
        }
    }

    public static String translateStatutoryEpidemic(String val) {
        if (StringUtil.isBlank(val)) {
            return "";
        }
        switch (val) {
            case "1":
                return "甲类";
            case "2":
                return "乙类";
            case "3":
                return "丙类";
            default:
                return "";
        }
    }

    public static String translatePayMethod(String code) {
        if (StringUtil.isBlank(code)) {
            return "";
        }
        switch (code) {
            case "1":
                return "城镇职工基本医疗保险";
            case "2":
                return "城镇居民基本医疗保险";
            case "3":
                return "新型农村合作医疗";
            case "4":
                return "贫困救助";
            case "5":
                return "商业医疗保险";
            case "6":
                return "全公费";
            case "7":
                return "全自费";
            case "8":
                return "其他社会保险";
            default:
                return "其他";
        }
    }

    public static String translateMarriage(String code) {
        if (StringUtil.isBlank(code)) {
            return "";
        }
        switch (code) {
            case "1":
                return "未婚";
            case "2":
                return "已婚";
            case "3":
                return "丧偶";
            case "4":
                return "离婚";
            default:
                return "其他";
        }
    }

    public static String translateRelation(String code) {
        if (StringUtil.isBlank(code)) {
            return "";
        }
        switch (code) {
            case "0":
                return "本人或户主";
            case "1":
                return "配偶";
            case "2":
                return "子";
            case "3":
                return "女";
            case "4":
                return "孙子、孙女或外孙子、外孙女";
            case "5":
                return "父母";
            case "6":
                return "祖父母或外祖父母";
            case "7":
                return "兄弟姐妹";
            case "8":
                return "同事同学";
            default:
                return "其他";
        }
    }

    public static String translateHasSurgery(String code) {
        if (StringUtil.isBlank(code)) {
            return "";
        }
        switch (code) {
            case "0":
                return "非手术";
            case "1":
                return "传统手术";
            case "2":
                return "介入手术";
            case "3":
                return "微创手术";
            case "4":
                return "恶性肿瘤放射治疗";
            case "5":
                return "恶性肿瘤化学治疗";
            case "6":
                return "恶性肿瘤放疗加化疗";
            case "7":
                return "恶性肿瘤姑息治疗";
            default:
                return "";
        }
    }

    public static String translateHaveOrNot(String code) {
        if (StringUtil.isBlank(code)) {
            return "";
        }
        switch (code) {
            case "1":
                return "无";
            case "2":
                return "有";
            default:
                return "";
        }
    }

    public static String translateHbsAg(String code) {
        if (StringUtil.isBlank(code)) {
            return "";
        }
        switch (code) {
            case "0":
                return "未查";
            case "1":
                return "阴性";
            case "2":
                return "阳性";
            case "3":
                return "不详";
            default:
                return "";
        }
    }

    public static String translateBloodType(String code) {
        if (StringUtil.isBlank(code)) {
            return "";
        }
        switch (code) {
            case "1":
                return "A";
            case "2":
                return "B";
            case "3":
                return "O";
            case "4":
                return "AB";
            case "5":
                return "不详";
            case "6":
                return "未查";
            default:
                return "";
        }
    }

    public static String translateDiagConform(String code) {
        if (StringUtil.isBlank(code)) {
            return "";
        }
        switch (code) {
            case "0":
                return "未做";
            case "1":
                return "符合";
            case "2":
                return "不符合";
            case "3":
                return "不确定";
            default:
                return "";
        }
    }

    public static String translateCaseClass(String code) {
        if (StringUtil.isBlank(code)) {
            return "";
        }
        switch (code) {
            case "1":
                return "A";
            case "2":
                return "B";
            case "3":
                return "C";
            case "4":
                return "D";
            default:
                return "";
        }
    }

    public static String filterCut(String cutHeal) {
        if (StringUtil.isBlank(cutHeal)) {
            return null;
        }
        String[] arrs = cutHeal.split("/");
        switch (arrs[0]) {
            case "0":
                return "0";
            case "Ⅰ":
                return "1";
            case "Ⅱ":
                return "2";
            case "Ⅲ":
                return "3";
            default:
                return null;
        }
    }

    public static String filterHeal(String cutHeal) {
        if (StringUtil.isBlank(cutHeal)) {
            return null;
        }
        String[] arrs = cutHeal.split("/");
        switch (arrs[1]) {
            case "0":
                return "0";
            case "甲":
                return "1";
            case "乙":
                return "2";
            case "丙":
                return "3";
            default:
                return null;
        }
    }

    public static String filterCutHealFirstPart(String cut) {
        switch (cut) {
            case "0":
                return "0";
            case "1":
                return "Ⅰ";
            case "2":
                return "Ⅱ";
            case "3":
                return "Ⅲ";
            default:
                return null;
        }
    }

    public static String filterCutHealLastPart(String heal) {
        switch (heal) {
            case "0":
                return "0";
            case "1":
                return "甲";
            case "2":
                return "乙";
            case "3":
                return "丙";
            default:
                return null;
        }
    }

    public static String combineCutHeal(String cut, String heal) {
        if (cut != null && heal != null) {
            String first = FilterUtil.filterCutHealFirstPart(cut);
            String last = FilterUtil.filterCutHealLastPart(heal);
            return first + "/" + last;
        } else {
            return "";
        }
    }
}
