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

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.model.doc.FirstCourseRecordDoc;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

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

/**
 * @ClassName : FIRC02910
 * @Description : 首次病程创建时间早于患者入院时间
 * @Author : 胡敬
 * @Date: 2020-06-12 14:12
 */
@Component
public class FIRC02910 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        FirstCourseRecordDoc firstCourseRecordDoc = inputInfo.getFirstCourseRecordDoc();
        BeHospitalizedDoc beHospitalizedDoc = inputInfo.getBeHospitalizedDoc();
        if (firstCourseRecordDoc == null || beHospitalizedDoc == null) {
            return;
        }
        Map<String, String> firstRecordMap = firstCourseRecordDoc.getStructureMap();
        Map<String, String> beHospitalizedMap = beHospitalizedDoc.getStructureMap();
        String createDateStr = firstRecordMap.get("记录时间");
        String beHospitalDateStr = beHospitalizedMap.get("入院日期");
        if (StringUtil.isNotBlank(createDateStr) && StringUtil.isNotBlank(beHospitalDateStr)) {
            Date createDate = StringUtil.parseDateTime(createDateStr);
            Date beHospitalDate = StringUtil.parseDateTime(beHospitalDateStr);
            if (createDate != null && beHospitalDate != null) {
                if (createDate.before(beHospitalDate)) {
                    status.set("-1");
                }
            }
        }
    }
}