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.model.doc.ClinicalBloodDoc;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @ClassName : FIRP0190
 * @Description :Rh填写错误
 * @Author : 胡敬
 * @Date: 2020-03-18 13:35
 */
@Component
public class FIRP0190 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getFirstPageRecordDoc() != null && inputInfo.getFirstPageRecordDoc().getStructureMap() != null
                && inputInfo.getClinicalBloodDocs().size() > 0) {
            Map<String, String> firstpageStructureMap = inputInfo.getFirstPageRecordDoc().getStructureMap();
            List<ClinicalBloodDoc> clinicalBloodDocList = inputInfo.getClinicalBloodDocs();
            String rhFactor = firstpageStructureMap.get(Content.rhFactor);
            if (CatalogueUtil.isEmpty(rhFactor)) {
                return;
            }
            status.set("-1");
            for (ClinicalBloodDoc clinicalBloodDoc : clinicalBloodDocList) {
                String bloodType = clinicalBloodDoc.getStructureMap().get("输注种类、血型、数量");
                if (StringUtils.isEmpty(bloodType)) {
                    continue;
                }
                bloodType = bloodType.toUpperCase();
                String rh = Content.rhFactor.toUpperCase();
                if (bloodType.contains(rh) &&
                        bloodType.contains(CatalogueUtil.removeSpecialChar(rhFactor))) {
                    status.set("0");
                    return;
                }
            }
        }
    }
}