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

import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.dbanaly.util.KernelConstants;
import com.lantone.qc.dbanaly.util.SpecialStorageUtil;
import com.lantone.qc.pub.model.InputInfo;
import com.lantone.qc.pub.model.OutputInfo;
import com.lantone.qc.pub.model.doc.FirstCourseRecordDoc;
import com.lantone.qc.pub.model.entity.Diag;
import com.lantone.qc.pub.model.label.DiagLabel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName : FIRC0096
 * @Description : 初步诊断不标准
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class FIRC0096 extends QCCatalogue {
    @Autowired
    private SpecialStorageUtil specialStorageUtil;
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        if(inputInfo.getFirstCourseRecordDoc() == null){
            status.set("0");
            return;
        }
        List<String> diags_out = new ArrayList<>();
        Map<String, String> hostpital_standDiag = specialStorageUtil.getJsonStringValue(KernelConstants.HOSPITAL_DIAG_MAP);
        if (hostpital_standDiag == null){
            status.set("0");
            return;
        }
        FirstCourseRecordDoc firstCourseRecordDoc = inputInfo.getFirstCourseRecordDoc();
        if(firstCourseRecordDoc != null){
            DiagLabel initialDiagLabel = firstCourseRecordDoc.getInitialDiagLabel();
            if(initialDiagLabel != null){
                List<Diag> diags = initialDiagLabel.getDiags();
                if(diags != null && diags.size()>0){
                    for (Diag diag:diags) {
                        String hospitalDiagName = diag.getHospitalDiagName().trim().replace("待查","").replace("?","").replace("？","");
                        if ("ACT".equals(hospitalDiagName)){
                            continue;
                        }
                        if (hospitalDiagName.contains("伴")){
                            hospitalDiagName = hospitalDiagName.substring(0,hospitalDiagName.indexOf("伴"));
                        }
                        if (hospitalDiagName.length() > 15){
                            continue;
                        }
                        if(!hostpital_standDiag.containsKey(hospitalDiagName)){
                            diags_out.add(hospitalDiagName);
                            break;
                        }
                    }
                    if(diags_out.size()>0){
                        info.set(diags_out.toString().replace("[","").replace("]",""));
                    }else {
                        status.set("0");
                    }
                }else {
                    status.set("0");
                }
            }
        }
    }
}