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

import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.kernel.util.CatalogueUtil;
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.FirstPageRecordDoc;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

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

/**
 * @ClassName : FIRP0517
 * @Description : 出生日期与入院记录不一致
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class FIRP0517 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        BeHospitalizedDoc beHospitalizedDoc = inputInfo.getBeHospitalizedDoc();
        FirstPageRecordDoc firstPageRecordDoc = inputInfo.getFirstPageRecordDoc();
        if (beHospitalizedDoc != null && firstPageRecordDoc != null) {
            Map<String, String> structureMap_bh = beHospitalizedDoc.getStructureMap();
            Map<String, String> structureMap_fpr = firstPageRecordDoc.getStructureMap();
            String bhBirthDay = structureMap_bh.get("出生日期");
            String fprBirthDay = structureMap_fpr.get("出生日期");
            if (StringUtil.isBlank(bhBirthDay) || StringUtil.isBlank(fprBirthDay)) {
                return;
            }
            Date bhBirthDayDate = StringUtil.parseDateTime(bhBirthDay);
            Date fprBirthDayDate = StringUtil.parseDateTime(fprBirthDay);
            if (bhBirthDayDate == null || fprBirthDayDate == null) {
                return;
            }
            if (!CatalogueUtil.equalsDate(bhBirthDayDate, fprBirthDayDate, "yyyy-MM-dd")) {
                status.set("-1");
            }
        }
    }
}