package com.docus.server.archive.converter;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.docus.server.archive.entity.TBasic;
import com.docus.server.archive.utils.PinYinUtil;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author YongBin Wen
 * @date 2024/8/23 11:03
 */
public class GzZxyJhPatientInfoConverter {
    public static List<TBasic> convertTbasic(String result) {
        List<JSONObject> parseArray = JSONArray.parseArray(result, JSONObject.class);
        List<TBasic> tBasicList = new ArrayList<>();
        for (JSONObject jsonObject : parseArray) {
            String jzh = jsonObject.getString("INPATIENT_NO");
            if (StrUtil.isBlank(jzh)) {
                continue;
            }
            String inpatientNo = jsonObject.getString("PATIENT_NO");
            String name = jsonObject.getString("NAME");
            Integer admissTimes = jsonObject.getInteger("IN_TIMES");
            String idCard = jsonObject.getString("IDENNO");
            Date admissDate = jsonObject.getDate("IN_DATE");
            String admissDept = jsonObject.getString("IN_DEPT_CODE");
            String admissDeptName = jsonObject.getString("IN_DEPT_NAME");
            Date disDate = jsonObject.getDate("OUT_DATE");
            String disDept = jsonObject.getString("OUT_DEPT_CODE");
            String disDeptName = jsonObject.getString("OUT_DEPT_NAME");
            String groundingNo = jsonObject.getString("CASE_LIST_NO");
            String attending = jsonObject.getString("HOUSE_DOC_CODE");
            String attendingName = jsonObject.getString("HOUSE_DOC_NAME");
            String sexName = jsonObject.getString("SEX_NAME");
            String bedNo = jsonObject.getString("BED_NO");
            String zgName = jsonObject.getString("ZG_NAME");
            String linkmanTel = jsonObject.getString("LINKMAN_TEL");

            TBasic tBasic = new TBasic();
            tBasic.setJzh(jzh);
            tBasic.setInpatientNo(inpatientNo);
            tBasic.setName(name);
            tBasic.setNameSpell(PinYinUtil.getFirstSpell(name));
            tBasic.setAdmissTimes(admissTimes);
            tBasic.setIdCard(idCard);
            tBasic.setAdmissDate(admissDate);
            tBasic.setAdmissDept(admissDept);
            tBasic.setAdmissDeptName(admissDeptName);
            tBasic.setDisDate(disDate);
            tBasic.setDisDept(disDept);
            tBasic.setDisDeptName(disDeptName);
            tBasic.setGroundingNo(groundingNo);
            tBasic.setAttending(attending);
            tBasic.setAttendingName(attendingName);
            tBasic.setSexName(sexName);
            tBasic.setSex("男".equals(sexName) ? "1" : "2");
            tBasic.setBedNo(bedNo);
            tBasic.setIsDead("死亡".equals(zgName) ? 1 : 0);
            tBasic.setTelphone(linkmanTel);
            tBasicList.add(tBasic);
        }
        return tBasicList;

    }


}
