package com.lantone.structure.ai.process;

import com.alibaba.fastjson.JSONObject;
import com.lantone.structure.ai.model.EntityEnum;
import com.lantone.structure.model.entity.*;
import org.apache.commons.lang3.StringUtils;

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

public class EntityProcessVital extends EntityProcess {
    public List<Vital> extractEntity(JSONObject outputs) {
        List<Vital> vitals = new ArrayList<>();
        Vital vital =null;
        List<Map<String, String>> vitalEntityList = processJson(outputs, EntityEnum.SIGN.toString());
        for (Map<String, String> vitalEntityMap : vitalEntityList) {
            if (StringUtils.isEmpty(vitalEntityMap.get(EntityEnum.SIGN.toString()))) {
                continue;
            }
            vital = new Vital();
            for (String key:vitalEntityMap.keySet()) {
                String entity = vitalEntityMap.get(key);
                switch (EntityEnum.parseOfValue(key)) {
                    case SIGN:
                        vital.setVitalName(entity);
                        break;
                    case NEGATIVE:
                        Negative negative = new Negative();
                        negative.setName(entity);
                        vital.setNegative(negative);
                        break;
                    case BODY:
                        BodyPart bodyPart = new BodyPart();
                        bodyPart.setName(entity);
                        vital.setBodyPart(bodyPart);
                        break;
                    case INDEX_VALUE:
                        vital.setValue(StringUtils.isEmpty(entity)?"":entity);
                        PD pd =new PD();
                        pd.setValue(StringUtils.isEmpty(entity)?"":entity);
                        vital.setPd(pd);
                        break;
                    case MODIFICATION:
                        if(entity.contains("度")){
                            Degree degree = new Degree();
                            degree.setName(entity);
                            vital.setDegree(degree);
                        }
                        break;
                }
            }
            vitals.add(vital);
        }
        return vitals;
    }
}
