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.kernel.util.KernelConstants;
import com.lantone.qc.kernel.util.RedisUtil;
import com.lantone.qc.pub.model.InputInfo;
import com.lantone.qc.pub.model.OutputInfo;
import com.lantone.qc.pub.model.entity.Diag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

/**
 * @ClassName : BEH0011
 * @Description : 入院诊断不完整
 * 初步诊断没有既往史里的慢性疾病
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class BEH0011 extends QCCatalogue {
    @Autowired
    private RedisUtil redisUtil;
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        if(inputInfo.getBeHospitalizedDoc() == null){
            status.set("0");
            return;
        }
        Map<String, Map<String, Object>> diagMap = redisUtil.getJsonStringValue(KernelConstants.CONCEPT_DIAG_PROPERTY_MAP);
        String initDiagText = CatalogueUtil.removeSpecialChar(inputInfo.getBeHospitalizedDoc().getInitialDiagLabel().getText());
        List<Diag> diags = inputInfo.getBeHospitalizedDoc().getPastLabel().getDiags();
        if(StringUtils.isNotEmpty(initDiagText)){
            List<String> initDiags = Arrays.asList(initDiagText.split(","));
            if(diags.size()>0){
                for (Diag diag:diags) {
                    Map<String, Object> map = (Map<String, Object>) diagMap.get(diag.getName());
                    if(map != null && map.size() >0){
                        String chronic = (String) map.get("chronic");//1是慢病
                        if("1".equals(chronic) && !initDiags.contains(diag.getName())){
                            if(StringUtils.isEmpty(info.get())){
                                info.set(diag.getName());
                            }else {
                                info.set(info.get() + "," + diag.getName());
                            }
                        }
                    }
                }
            }
        }
        if(StringUtils.isEmpty(info.get())){
            status.set("0");
        }


    }
}