package com.lantone.qc.kernel.catalogue.firstpagerecord;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lantone.qc.dbanaly.util.KernelConstants;
import com.lantone.qc.dbanaly.util.SpecialStorageUtil;
import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.pub.model.InputInfo;
import com.lantone.qc.pub.model.OutputInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @ClassName : FIRP03038
 * @Description : 出院诊断疾病编码填写错误
 * @Author : kwz
 * @Date: 2020-07-15 17:45
 */
@Component
public class FIRP03038 extends QCCatalogue {
    @Autowired
    private SpecialStorageUtil specialStorageUtil;
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getFirstPageRecordDoc() == null) {
            return;
        }
        Map<String, Map<String,String>> hostpital_standDiag = specialStorageUtil.getJsonStringValue(KernelConstants.HOSPITAL_DIAG_MAP);
        if (inputInfo.getFirstPageRecordDoc().getStructureMap() != null) {
            Map<String, Object> firstpageStructureMap = inputInfo.getFirstPageRecordDoc().getStructureExtMap();
            JSONArray out_diag = (JSONArray)firstpageStructureMap.get("出院诊断");
            if (out_diag.size() > 0) {
                for (int i=0;i<out_diag.size();i++) {
                    JSONObject jsonObject = out_diag.getJSONObject(i);
                    String diag_code = (String)jsonObject.get("诊断编码");
                    String diag_name = (String) jsonObject.get("诊断名称");
                    if(StringUtils.isNotBlank(diag_code) && hostpital_standDiag.containsKey(diag_name)){
                        Map<String,String> s = hostpital_standDiag.get(diag_name);
                        if(s != null){
                            String icd10 = s.get("icd10");
                            if(StringUtils.isNotBlank(icd10) && icd10.equals(diag_code)){
                                status.set("0");
                            }else {
                                status.set("-1");
                                return;
                            }
                        }
                    }

                }

            }
        }
    }
}