package com.lantone.qc.kernel.catalogue.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;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName : FIRP0275
 * @Description : 实际住院天数与出院小结不一致
 * @Author : 胡敬
 * @Date: 2020-03-14 17:10
 */
@Component
public class FIRP0275 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getFirstPageRecordDoc() != null && inputInfo.getFirstPageRecordDoc().getStructureMap() != null
                && inputInfo.getLeaveHospitalDoc() != null && inputInfo.getLeaveHospitalDoc().getStructureMap() != null) {
            Map<String, String> firstpageStructureMap = inputInfo.getFirstPageRecordDoc().getStructureMap();
            Map<String, String> leaveHospitalStructureMap = inputInfo.getLeaveHospitalDoc().getStructureMap();
            String firstDischargeTime = firstpageStructureMap.get(Content.actualStay);//病案首页出院时间
            String dischargeTime = leaveHospitalStructureMap.get(Content.stayLength);//出院小结出院时间
            if (StringUtil.isBlank(firstDischargeTime) || StringUtil.isBlank(dischargeTime)) {
                return;
            }
            String first = copileNum(firstDischargeTime);
            String disc = copileNum(dischargeTime);
            if (!first.equals(disc)) {
                status.set("-1");
            }
        }
    }

    private String copileNum(String firstDischargeTime) {
        String num = "";
        String compile = "([1-9]\\d*\\.?\\d*)|(0\\.\\d*[1-9])";
        Pattern compile1 = Pattern.compile(compile);
        Matcher matcher = compile1.matcher(firstDischargeTime);
        while (matcher.find()) {
            num = matcher.group(0);
        }
        return num;
    }
}