package com.docus.server.archive.converter;

import com.docus.server.archive.entity.TBasic;
import com.docus.server.archive.utils.PinYinUtil;
import com.docus.server.zqdyry.entity.ZqDyRyPatientInfoView;

/**
 * @author YongBin Wen
 * @date 2024/5/24 14:17
 */
public class ZqDyRyPatientInfoConverter {
    public static TBasic convertPatientInfo(ZqDyRyPatientInfoView 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(getSexCodeBySexName(view.getXB()));
        tBasic.setSexName(view.getXB());
        tBasic.setAdmissDate(view.getRYRQ());
        tBasic.setAdmissDept(view.getRYBQ());
        tBasic.setAdmissDeptName(view.getRYKS());
        tBasic.setBedNo(view.getCWDM());
        tBasic.setAttending(view.getDQYS());
        tBasic.setAttendingName(view.getDQXM());
        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.getDQBQ());
        tBasic.setDisDeptName(view.getDQKS());
        tBasic.setTotalCost(view.getZJINE());
        tBasic.setIsDead(view.getSFSW());
        tBasic.setFileSource(1);
        return tBasic;
    }

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

    public static String getSexCodeBySexName(String sexName) {
        if ("男".equals(sexName)) {
            return "1";
        }
        if ("女".equals(sexName)) {
            return "2";
        }
        return "3";
    }
}
