package com.lantone.structure.ai.process;


import com.alibaba.fastjson.JSONObject;
import com.lantone.structure.ai.model.EntityEnum;
import com.lantone.structure.ai.model.Lemma;
import com.lantone.structure.model.label.PreoperativeDiscussionLabel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;

/**
 * 术前小结处理
 */
public class EntityProcessOperation extends EntityProcess {
    private Logger logger = LoggerFactory.getLogger(EntityProcessOperation.class);

    public PreoperativeDiscussionLabel extractEntity(JSONObject aiOut) {
        PreoperativeDiscussionLabel preoperativeDiscussionLabel= new PreoperativeDiscussionLabel();
        try {

            //过敏史
            StringBuffer sbxx = new StringBuffer();
            int allergy = 0;
            List<Lemma> indicationAllergy = createEntityTree(aiOut, EntityEnum.ALLERGYRECORD.toString());
            for (Lemma lemma : indicationAllergy) {
                allergy++;
                if(indicationAllergy.size()>1){
                    sbxx.append(allergy+lemma.getText()+" ");
                }else{
                    sbxx.append(lemma.getText());
                }
            }
            preoperativeDiscussionLabel.setAllergyRecord(sbxx.toString());

            //手术禁忌症
            StringBuffer sbx = new StringBuffer();
            int opContrain = 0;
            List<Lemma> indicationOpContrain = createEntityTree(aiOut, EntityEnum.OPCONTRAINDICATION.toString());
            for (Lemma lemma : indicationOpContrain) {
                opContrain++;
                if(indicationOpContrain.size()>1){
                    sbx.append(opContrain+lemma.getText()+" ");
                }else{
                    sbx.append(lemma.getText());
                }
            }
            preoperativeDiscussionLabel.setOpContraindication(sbx.toString());

            //拟实施手术目标部位名称
          StringBuffer sb = new StringBuffer();
            int count = 0;
            List<Lemma> indicationOpBottom = createEntityTree(aiOut, EntityEnum.OPBOTTOMNAME.toString());
            for (Lemma lemma : indicationOpBottom) {
                count++;
                if(indicationOpBottom.size()>1){
                    sb.append(count+lemma.getText()+" ");
                }else{
                    sb.append(lemma.getText());
                }
            }
            preoperativeDiscussionLabel.setOpBottomName(sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage(), e);
        }
        return preoperativeDiscussionLabel;
    }
}
