package thyyxxk.webserver.entity.inpatient.patient;

import lombok.Data;
import org.apache.commons.codec.binary.Base64;

import java.nio.ByteBuffer;

@Data
public class IdCard {
    private Integer itemNo;
    private String inpatientNo;
    private Integer admissTimes;
    private String agency;
    private String expirestart;
    private String fileSfz;

    public String getFileSfz() {
        return null == fileSfz ? "" : new String(Base64.encodeBase64(hexStr2Byte(fileSfz)));
    }

    private byte[] hexStr2Byte(String hex) {
        ByteBuffer bf = ByteBuffer.allocate(hex.length() / 2);
        for (int i = 0; i < hex.length(); i++) {
            String hexStr = hex.charAt(i) + "";
            i++;
            hexStr += hex.charAt(i);
            byte b = (byte) Integer.parseInt(hexStr, 16);
            bf.put(b);
        }
        return bf.array();
    }
}
