package com.lantone.qc.kernel.catalogue.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;
        }
        Date admissionDate = StringUtil.parseDateTime(admissionDateStr);
        Date recordDate = StringUtil.parseDateTime(recordDateStr);
        if (admissionDate == null || recordDate == null) {
            return;
        }
        if (admissionDate.after(recordDate)) {
            status.set("-1");
        }
    }
}