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

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 : FIRP0196
 * @Description :颅脑损伤患者昏迷时间未填写
 * @Author : 胡敬
 * @Date: 2020-03-17 16:28
 */
@Component
public class FIRP0196 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        /**
         * 如果入院前天数和入院后天数不为空，且不是数字，例如是“-”，就不报错
         * 如果天数是数字，那么小时和分都不能为空
         */
        status.set("0");
        if (inputInfo.getFirstPageRecordDoc() != null && inputInfo.getFirstPageRecordDoc().getStructureMap() != null) {
            Map<String, String> firstpageStructureMap = inputInfo.getFirstPageRecordDoc().getStructureMap();
            String brainInjuryComaBeforeDays = firstpageStructureMap.get(Content.brainInjuryComaBeforeDays);
            String brainInjuryComaBeforeHours = firstpageStructureMap.get(Content.brainInjuryComaBeforeHours);
            String brainInjuryComaBeforeMins = firstpageStructureMap.get(Content.brainInjuryComaBeforeMins);
            String brainInjuryComaAfterDays = firstpageStructureMap.get(Content.brainInjuryComaAfterDays);
            String brainInjuryComaAfterHours = firstpageStructureMap.get(Content.brainInjuryComaAfterHours);
            String brainInjuryComaAfterMins = firstpageStructureMap.get(Content.brainInjuryComaAfterMins);
            String regex = "([1-9]\\d*\\.?\\d*)|(0\\.\\d*[1-9])";
            if (StringUtil.isNotBlank(brainInjuryComaBeforeDays) && !brainInjuryComaBeforeDays.matches(regex)
                && StringUtil.isNotBlank(brainInjuryComaAfterDays) && !brainInjuryComaAfterDays.matches(regex)) {
                return ;
            }
            if (StringUtil.isBlank(brainInjuryComaBeforeDays)
                    && StringUtil.isBlank(brainInjuryComaBeforeHours)
                    && StringUtil.isBlank(brainInjuryComaBeforeMins)
                    && StringUtil.isBlank(brainInjuryComaAfterDays)
                    && StringUtil.isBlank(brainInjuryComaAfterHours)
                    && StringUtil.isBlank(brainInjuryComaAfterMins)
            ) {
                status.set("-1");
            }
        }
    }
}