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

import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.pub.model.InputInfo;
import com.lantone.qc.pub.model.OutputInfo;
import com.lantone.qc.pub.model.doc.BeHospitalizedDoc;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;


/**
 * @ClassName : BEH0422
 * @Description :  入院记录记录日期填写错误
 * @Date: 2020-03-06 17:28
 */
@Component
public class BEH0422 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        /**
         * 记录日期比入院日期早就报错
         */
        status.set("0");
        BeHospitalizedDoc beHospitalizedDoc = inputInfo.getBeHospitalizedDoc();
        if (beHospitalizedDoc == null) {
            return;
        }
        Map<String, String> docStructureMap = beHospitalizedDoc.getStructureMap();
        String admissionDateStr = docStructureMap.get("入院日期");
        String recordDateStr = docStructureMap.get("记录日期");
        if (StringUtil.isBlank(admissionDateStr) || StringUtil.isBlank(recordDateStr)) {
            return;
        }
        // 如果时间格式不一致，就不比较 “2020-05-06 14:06” 与 “2020-05-06”
        if (admissionDateStr.length() != recordDateStr.length()) {
            return ;
        }
        Date admissionDate = StringUtil.parseDateTime(admissionDateStr);
        Date recordDate = StringUtil.parseDateTime(recordDateStr);
        if (admissionDate == null || recordDate == null) {
            return;
        }
        if (admissionDate.after(recordDate)) {
            status.set("-1");
        }
    }
}