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

import com.google.common.collect.Lists;
import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.kernel.util.CatalogueUtil;
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.List;
import java.util.Map;

/**
 * @ClassName : BEH02966
 * @Description :  患者病历书写与性别不符（入院记录）
 * @Author : 胡敬
 * @Date: 2020-06-13 15:51
 */
@Component
public class BEH02966 extends QCCatalogue {
    @Override
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getBeHospitalizedDoc() == null) {
            return;
        }

        Map<String, String> beHospitalStructureMap = inputInfo.getBeHospitalizedDoc().getStructureMap();
        String gender = beHospitalStructureMap.get("性别");
        if (StringUtil.isBlank(gender)) {
            return;
        }
        List<String> noMatchWords = null;
        if (gender.contains("男")) {
            /* 男性不合理词 */
            noMatchWords = Lists.newArrayList("阴道", "宫颈", "子宫", "宫底", "胎位", "胎数", "胎心",
                    "宫缩", "宫口", "输卵管", "卵巢", "输卵管", "阴唇", "阴蒂", "阴道前庭", "前庭大腺", "处女膜");
        } else if (gender.contains("女")) {
            /* 女性不合理词 */
            noMatchWords = Lists.newArrayList("睾丸", "阴茎", "精索", "包皮", "附睾", "输精管",
                    "射精管", "尿道海绵体", "冠状沟", "精阜", "精囊腺");
        }
        if (noMatchWords == null || noMatchWords.size() == 0) {
            return;
        }

        List<String> keys = Lists.newArrayList("主诉", "现病史", "既往史", "个人史", "体格检查", "一般情况"
                , "初步诊断", "专科体格检查", "神经系统检查", "实验室检查", "影像学检查");
        String text = CatalogueUtil.structureMapJoin(beHospitalStructureMap, keys);

        for (String noMatchWord : noMatchWords) {
            if (text.contains(noMatchWord)) {
                status.set("-1");
                info.set(noMatchWord);
                return;
            }
        }
    }
}