package com.docus.server.archive.converter;

import com.docus.core.util.ObjectUtil;
import com.docus.server.archive.entity.TBasic;
import com.docus.server.archive.utils.PinYinUtil;
import com.docus.server.mzsy.entity.MzsyPatientInfoView;

public class MzsyPatientInfoConverter {
    public static TBasic convertPatientInfo(MzsyPatientInfoView view) {
        if (view == null) {
            return null;
        }

        TBasic tBasic = new TBasic();
        tBasic.setJzh(view.getJZH());
        tBasic.setInpatientNo(view.getZYH());
        tBasic.setAdmissTimes(view.getZYCS());
        tBasic.setName(view.getXM());
        tBasic.setNameSpell(getPinyinFirstSpell(view.getXM()));
        tBasic.setSex(getSexCodeBySex(view.getXB()));
        tBasic.setSexName(getSexNameBySex(view.getXB()));
        tBasic.setAdmissDate(view.getRYRQ());
        tBasic.setAdmissDept(view.getRYBQ());
        tBasic.setAdmissDeptName(view.getRYKS());
        tBasic.setBedNo(view.getCWDM());
        tBasic.setAttending(view.getDQYS());
        tBasic.setAge(view.getNL());
        tBasic.setAgeMonth(0);
        tBasic.setAgeDay(0);
        tBasic.setIdCard(view.getSFZH());
        tBasic.setTelphone(view.getLXDH());
        tBasic.setDisDate(view.getCYRQ());
        tBasic.setDisDept(view.getCYBQ());
        tBasic.setDisDeptName(view.getCYKS());
        tBasic.setAdmissDays(view.getZYTS());
        tBasic.setTotalCost(view.getZJINE());
        tBasic.setIsDead(0);
        if(ObjectUtil.isNotEmpty(view.getSFSW())){
            tBasic.setIsDead(view.getSFSW());
        }
        tBasic.setFileSource(1);
        tBasic.setLeaveMethod(view.getCYQK());
        return tBasic;
    }

    public static String getPinyinFirstSpell(String str) {
        try {
            return PinYinUtil.getFirstSpell(str);
        } catch (Exception ex) {
            return null;
        }
    }

    public static String getSexCodeBySex(String sexName) {
        if ("M".equals(sexName)) {
            return "1";
        }
        if ("F".equals(sexName)) {
            return "2";
        }
        return null;
    }

    public static String getSexNameBySex(String sexName) {
        if ("M".equals(sexName)) {
            return "男";
        }
        if ("F".equals(sexName)) {
            return "女";
        }
        return null;
    }
}
