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

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.model.doc.ThreeLevelWardDoc;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @ClassName : THR02967
 * @Description :  查房记录中查体与性别不匹配
 * @Author : 胡敬
 * @Date: 2020-06-13 16:13
 */
@Component
public class THR02967 extends QCCatalogue {
    @Override
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getBeHospitalizedDoc() == null || inputInfo.getThreeLevelWardDocs().size() == 0) {
            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("病情记录");
        for (ThreeLevelWardDoc threeLevelWardDoc : inputInfo.getThreeLevelWardDocs().get(0).getAllDoctorWradDocs()) {
            Map<String, String> structureMap = threeLevelWardDoc.getStructureMap();
            String text = CatalogueUtil.structureMapJoin(structureMap, keys);
            for (String noMatchWord : noMatchWords) {
                if (text.contains(noMatchWord)) {
                    status.set("-1");
                    info.set(noMatchWord);
                    return;
                }
            }
        }
    }
}