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

import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.pub.Content;
import com.lantone.qc.pub.model.InputInfo;
import com.lantone.qc.pub.model.OutputInfo;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.Map;


/**
 * @ClassName : BEH0416
 * @Description :  入院记录职业填写错误
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class BEH0416 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getBeHospitalizedDoc() == null || inputInfo.getFirstPageRecordDoc() == null) {
            return;
        }
        Map<String, String> structureMap = inputInfo.getBeHospitalizedDoc().getStructureMap();
        Map<String, String> firstStructMap = inputInfo.getFirstPageRecordDoc().getStructureMap();
        if (structureMap != null && firstStructMap != null) {
            String contactAddress_bh = structureMap.get("职业");
            String contactAddress_first = firstStructMap.get(Content.job);
            if (StringUtil.isNotBlank(contactAddress_bh) && StringUtil.isNotBlank(contactAddress_first)) {
                contactAddress_first = removeBrackets(contactAddress_first);
                contactAddress_bh = removeBrackets(contactAddress_bh);
                if (!contactAddress_first.contains(contactAddress_bh) && !contactAddress_bh.contains(contactAddress_first)) {
                    status.set("-1");
                }
            }
        }
    }

    /*
    去除括号
     */
    private String removeBrackets(String str) {
        return str.replaceAll("[()（）]", "");
    }
}