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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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.doc.operation.OperationDoc;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

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

/**
 * @ClassName : FIRP02844
 * @Description : 手术及操作编码未填
 * @Author : kwz
 * @Date: 2020-07-15 17:45
 */
@Component
public class FIRP02844 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getFirstPageRecordDoc() == null) {
            return;
        }
        if (inputInfo.getFirstPageRecordDoc().getStructureMap() != null) {
            List<OperationDoc> operationDocs = inputInfo.getOperationDocs();
            long count = operationDocs.stream().filter(x -> x.getOperationRecordDoc() != null).count();
            Map<String, Object> firstpageStructureMap = inputInfo.getFirstPageRecordDoc().getStructureExtMap();
            JSONArray out_diag = (JSONArray)firstpageStructureMap.get("手术信息");
            if (out_diag != null && out_diag.size() > 0) {
                for (int i=0;i<out_diag.size();i++) {
                    JSONObject jsonObject = out_diag.getJSONObject(i);
                    String diag_code = (String)jsonObject.get("手术编码");
                    if(StringUtils.isBlank(diag_code)){
                        status.set("-1");
                        return;
                    }

                }

            }
        }
    }
}