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

import java.util.List;

/**
 * @ClassName : BEH0072
 * @Description : 家属有死亡者,未记录死亡原因
 * @Author : 胡敬
 * @Date: 2020-03-11 16:44
 */
@Component
public class BEH0072 extends QCCatalogue {
    @Override
    protected void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getBeHospitalizedDoc() != null && inputInfo.getBeHospitalizedDoc().getFamilyLabel() != null) {
            FamilyLabel familyLabel = inputInfo.getBeHospitalizedDoc().getFamilyLabel();
            if (familyLabel == null) {
                return;
            }
            String familyText = familyLabel.getText();
            if (StringUtil.isNotBlank(familyText)) {
                familyText = familyText.substring(0, Math.min(10, familyText.length()));
                if (familyText.contains("死因") || familyText.contains("原因") || familyText.contains("详")
                || familyText.contains("因")) {
                    return;
                }
            }
            List<Family> families = familyLabel.getFamilies();
            if (ListUtil.isEmpty(families)) {
                return;
            }
            for (Family family : families) {
                if (family.getDead() != null) {
                    Dead dead = family.getDead();
                    if (family.getName().contains("年迈") || dead.getNegative() != null) {
                        continue;
                    }
                    if (dead.getDeadReason() != null || dead.getUnknow() != null) {
                        return;
                    } else {
                        status.set("-1");
                        return;
                    }
                }
            }
        }
    }
}