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

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.entity.Diag;
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;
import java.util.stream.Collectors;

/**
 * @Description: 疾病名未标引号
 * @author: rengb
 * @time: 2020/3/10 14:02
 */
@Component
public class BEH0032 extends QCCatalogue {

    @Override
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if(inputInfo.getBeHospitalizedDoc() == null){
            return;
        }
        PastLabel pastLabel = inputInfo.getBeHospitalizedDoc().getPastLabel();
        List<Diag> diags = pastLabel.getDiags();
        if (ListUtil.isEmpty(diags)) {
            return;
        }
        List<String> wtDiagNames = CatalogueUtil.noInQuotes(
                diags.stream().filter(diag -> diag.getNegative() == null).map(i -> i.getHospitalDiagName()).filter(i -> StringUtil.isNotEmpty(i)).distinct().collect(Collectors.toList()),
                pastLabel.getText().replace("“","\"").replace("”","\"")
        );
        if (ListUtil.isNotEmpty(wtDiagNames)) {
            status.set("-1");
            for (String wtDiagName : wtDiagNames) {
                info.set(info.get() + wtDiagName + " ");
            }
        }
    }

}