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.entity.BloodTransfusion;
import com.lantone.qc.pub.model.label.PastLabel;
import com.lantone.qc.pub.util.ListUtil;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description: 输血史描述不完整
 * @author: rengb
 * @time: 2020/3/10 14:02
 */
@Component
public class BEH0038 extends QCCatalogue {

    @Override
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getBeHospitalizedDoc() == null) {
            return;
        }
        PastLabel pastLabel = inputInfo.getBeHospitalizedDoc().getPastLabel();
        if (pastLabel == null) {
            return;
        }
        String pastText = pastLabel.getText();
        if (StringUtil.isNotBlank(pastText) && pastText.contains("输血")) {
            return;
        }
        List<BloodTransfusion> bloodTransfusions = pastLabel.getBloodTransfusions();
        if (ListUtil.isEmpty(bloodTransfusions)) {
            return;
        }
        for (BloodTransfusion bloodTransfusion : bloodTransfusions) {
            if (bloodTransfusion == null || StringUtil.isBlank(bloodTransfusion.getName())) {
                continue;
            }
            if ((bloodTransfusion.getNegative() == null || StringUtil.isBlank(bloodTransfusion.getNegative().getName()))
                    && (bloodTransfusion.getPd() == null || StringUtil.isBlank(bloodTransfusion.getPd().getName()))
                    && (bloodTransfusion.getQuantity() == null || StringUtil.isBlank(bloodTransfusion.getQuantity().getName()))) {
                info.set(info.get() + bloodTransfusion.getName() + " ");
            }
        }
        if (StringUtil.isNotBlank(info.get())) {
            status.set("-1");
        }
    }

}