package thyyxxk.webserver.entity.zygl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdcardUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;
import thyyxxk.webserver.entity.medicaladvice.medicamanage.MzZyReq;

import java.util.Date;

/**
 * @Description:
 * @Author:lihong
 * @Date: 2025/5/7
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class APatientMiVo {
    //住院号
    private String inpatientNo;
    //是否在院 1 是 0 否
    private Integer zyFlag;
    private String patientId;
    private String mzNo;
    //性别
    private String sex;
    //名字
    private String name;
    //
    private Integer age;
    //出生日期
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private Date birthDate;
    //婚姻状态
    private String marryCode;
    //民族
    private String nationCode;
    //职业
    private String occupationCode;
    //证件类型
    private String psnCertType;
    //身份证
    private String socialNo;
    //电话
    private String homeTel;
    private String country;
    //出生地 区县编码
    private String birthPlace;
    //户口地址
    private String accountStreet;
    //出生地省
    private String homeZipcode;
    //出生地市
    private String homeDistrict;
    //单位地址
    private String employerStreet;
    //住院号类型  0 自动  1 家床
    private Integer inpatientNoType;
    //联系人姓名
    private String relationName;
    //联系人关系
    private String relationCode;
    //联系人电话
    private String relationTel;
    //联系人地址
    private String relationStreet;
    //家庭住址 省
    private String provinceCode;
    //家庭住址 市
    private String cityCode;
    //家庭住址 区县
    private String districtCode;
    //住址详情
    private String homeStreet;
    //地址详情
    private String addressDetail;

    private MzZyReq mzZyReq;

    public Integer getAge(){
        if(birthDate != null){
            return this.age = DateUtil.ageOfNow(birthDate);
        }else {
            if(StringUtils.isNotBlank(socialNo)){
                try {
                    int age = IdcardUtil.getAgeByIdCard(socialNo);
                    return this.age = age;
                }catch (Exception e){

                }
            }
        }
        return null;
    }

}
