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

import com.google.common.collect.Lists;
import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.kernel.util.RegularUtil;
import com.lantone.qc.pub.model.InputInfo;
import com.lantone.qc.pub.model.OutputInfo;
import com.lantone.qc.pub.model.doc.DeathRecordDoc;
import com.lantone.qc.pub.model.doc.LeaveHospitalDoc;
import com.lantone.qc.pub.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

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

/**
 * @Description: 出院医嘱记录不规范
 * @author: 胡敬
 * @time: 2020/05/27 19:13
 */
@Component
public class LEA02901 extends QCCatalogue {

    @Override
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        LeaveHospitalDoc leaveHospitalDoc = inputInfo.getLeaveHospitalDoc();
        if (leaveHospitalDoc == null) {
            return;
        }
        DeathRecordDoc deathRecordDoc = inputInfo.getDeathRecordDoc();
        if (deathRecordDoc == null || deathRecordDoc.getText() == null) {
            Map<String, String> structureMap = leaveHospitalDoc.getStructureMap();
            String dischargeOrder = structureMap.get("出院医嘱");
            if(StringUtils.isNotEmpty(dischargeOrder)){
                //跟医学部任燕青确认过， 去除括号里的东西
                dischargeOrder = RegularUtil.ClearBracket(dischargeOrder);
                if (StringUtil.isNotBlank(dischargeOrder)) {
                    List<String> words = Lists.newArrayList("qd","bid","tid","qid","qh","q2h","q4h","q6h","q8h",
                            "qn","q3w","qod","biw","qw","prn","sos","ad","lib","st","stat","hs","am","po","ID","IH","IM",
                            "IV","OD","OL","OS","OU","ivgtt","Q12H","QN","ONCE");
                    for (String word : words) {
                        if (dischargeOrder.contains(word.toUpperCase()) || dischargeOrder.contains(word.toLowerCase())) {
                            status.set("-1");
                            info.set("出院医嘱用法用量不规范");
                            return;
                        }
                    }
                }
            }
        }
    }
}