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.Allergy;
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 BEH0039 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<Allergy> allergies = pastLabel.getAllergies();
        if (ListUtil.isEmpty(allergies)) {
            return;
        }
        for (Allergy allergy : allergies) {
            if (allergy == null
                    || StringUtil.isBlank(allergy.getName())
                    || allergy.getAllergyFood() == null
                    || StringUtil.isBlank(allergy.getAllergyFood().getName())) {
                continue;
            }
            if ((allergy.getNegative() == null || StringUtil.isBlank(allergy.getNegative().getName()))
                    && (allergy.getAllergyFood().getPd() == null || StringUtil.isBlank(allergy.getAllergyFood().getPd().getName()))
                    && (allergy.getAllergyFood().getDegree() == null || StringUtil.isBlank(allergy.getAllergyFood().getDegree().getName()))
                    && (allergy.getAllergyFood().getAllergyDesc() == null || StringUtil.isBlank(allergy.getAllergyFood().getAllergyDesc().getName()))) {
                info.set(info.get() + allergy.getAllergyFood().getName() + " ");
            }
        }
        if (StringUtil.isNotBlank(info.get())) {
            status.set("-1");
        }
    }

}