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.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;

/**
 * @ClassName : FIRP0161
 * @Description : 患者年龄与入院记录不一致
 * @Author : 胡敬
 * @Date: 2020-03-16 10:00
 */
@Component
public class FIRP0161 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getFirstPageRecordDoc() != null && inputInfo.getFirstPageRecordDoc().getStructureMap() != null
                && inputInfo.getBeHospitalizedDoc() != null && inputInfo.getBeHospitalizedDoc().getStructureMap() != null) {
            Map<String, String> firstpageStructureMap = inputInfo.getFirstPageRecordDoc().getStructureMap();
            Map<String, String> beHospitalStructureMap = inputInfo.getBeHospitalizedDoc().getStructureMap();
            String firstAdmissionAge = firstpageStructureMap.get(Content.age);
            String admissionAge = beHospitalStructureMap.get(Content.age);
            if (StringUtil.isBlank(firstAdmissionAge) || StringUtil.isBlank(admissionAge)){
                status.set("0");
                return;
            }
            firstAdmissionAge = removalUnit(firstAdmissionAge);
            admissionAge = removalUnit(admissionAge);
            if (!CatalogueUtil.compareToken(firstAdmissionAge, admissionAge)) {
                status.set("-1");
            }
        }
    }

    private String removalUnit(String admissionAge) {
        if (StringUtil.isNotBlank(admissionAge) && admissionAge.contains("岁")) {
            admissionAge = admissionAge.replace("岁", "");
        }
        return admissionAge;
    }
}