package thyyxxk.webserver.entity.inpatient.patient;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import thyyxxk.webserver.utils.DateUtil;
import thyyxxk.webserver.utils.StringUtil;

import java.math.BigDecimal;
import java.util.Date;

@Data
public class Patient {
    private String table;
    private String inpatientNo;
    private String inOutStatusFlag;
    private Integer admissTimes;

    /**
     * 出院日期
     */
    private Date disDate;
    private Integer ledgerSn;
    private String staffId;
    private String psnCertType;
    private String socialNo;
    private String mzNo;
    private String name;
    private Integer sex;
    private String birthDate;
    private String homeTel;
    private String icdCode;
    private String icdText;
    private String admissPhysician;
    private String admissPhysicianName;
    private String referPhysician;
    private String referPhysicianName;
    private String acctUsedFlag;
    private String dutyNurse;
    private String dutyNurseName;
    private String country;
    private String nation;
    private String contactName;
    private String contactRelation;
    private String contactAddrName;
    private String contactPhone;
    private String admissDiag;
    private String admissDiagStr;
    private String clinicDiagStr;
    private String admissWard;
    private String admissWardName;
    private String admissDept;
    private String smallDept;
    private String smallDeptName;
    private String deptCode;
    private Date admissDate;
    private Date ybRegisterDate;
    private String responceType;
    private String responceName;
    private Integer dismissOrder;
    private String zkWard;
    private String zkWardName;
    private String bedNo;
    private String statusFlag;
    private String totalCharge;
    private String indiId;
    private String zySerialNo;
    private String centerId;
    private String ward;
    private String sid;
    private String disDiagStatus;
    private String operation;
    private String chargeYb;
    private Boolean midSetl; // 中间断账标志
    private Date zjdzDatetime; // 中间断账时间
    private Date dismissOrderDate; // 口腔科生成出院医嘱的出院时间
    private String medType;
    private String medTypeName;
    private String insutype;
    private String insutypeName;
    private Integer admdvs;
    private Integer[] admdvsCascader;
    private String matnType; // 生育类别
    private String latechbFlag; // 是否晚育
    private String pretFlag; // 是否早产
    private String mdtrtId;
    private String injurySerialNo;
    private String actIptDays; // 入院时间
    private String revokeRemark;

    /**
     * 离院方式
     */
    private String zyDismissWay;
    /**
     * 患者居住地
     */
    private String homeStreet;
    private Integer age;

    /**
     * 纬度
     */
    private BigDecimal latitude;

    /**
     * 经度
     */
    private BigDecimal longitude;

    /**
     * 转化成功标志
     */
    private Integer addrTransedFlag;

    /**
     * 同区域的人数
     */
    private Integer numberOfPeopleInTheSameArea;

    /**
     * 是否有出纳
     */
    private Integer timesBilled;

    private String yp;
    private String jyjc;
    private String yb;
    // 余额
    private String balance;

    private Date begntime;
    private Date endtime;
    private String diseCode;
    private String diseName;
    private String expContent;
    private Boolean deathFlag;

    private JSONObject drgGrouping;


    /**
     * DRG权重
     */
    private String groupInfoWeight;

    /**
     * 分组结果名称
     */
    private String groupInfoName;

    /**
     * 倍率（DRG）
     */
    private String groupInfoBl;

    /**
     * 盈亏额
     */
    private String groupInfoProfit;

    /**
     * 标杆费用
     */
    private String groupInfoFeeStand;
    /**
     * 病危状态
     */
    private String criticallyIllStatus;
    /**
     * 护理级别
     */
    private String nursingLevel;
    /**
     * 手术状态
     */
    private String oprtStatus;

    /**
     * 是否已经审核了
     */
    private Integer emrAudit;

    /**
     * 质控医生 来源 batj_ba2 zkys
     */
    private String zkys;

    /**
     * 主治医生
     */
    private String consultPhysician;
    private String consultPhysicianName;

    /**
     * 主任医生
     */
    private String deptDirector;
    private String deptDirectorName;

    private Integer finalControl;

    private String crmName;

    private String disDeptName;
    private String disMainDiag;

    /**
     * 医保参保地行政区划
     */
    private String insuplcAdmdvs;
    private String canceAdmissCount;

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

    public Integer getTempAge() {
        if (birthDate != null && admissDate != null) {
            try {
                return DateUtil.calculateAge(DateUtil.parse(birthDate, "yyyy-MM-dd"), admissDate);
            } catch (Exception ignored) {
            }
        }
        return age;
    }

    public String getPatNo() {
        return StringUtil.isBlank(inpatientNo) ? inpatientNo : inpatientNo.trim();
    }

    public Boolean getMidSetl() {
        return null != midSetl && midSetl;
    }

    public String getTable() {
        return null == table ? "zy_actpatient" : (table).trim();
    }

    public String mainInfo() {
        return "姓名：" + name + "，住院号：" + inpatientNo + "，住院次数：" + admissTimes;
    }

    public String getPatId() {
        return inpatientNo + "_" + admissTimes;
    }
}
