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.entity.AuxiliaryExamination;
import com.lantone.structure.model.entity.Drug;
import com.lantone.structure.model.entity.Laboratory;
import com.lantone.structure.model.entity.Surgery;
import com.lantone.structure.model.label.StagesSummaryLabel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

/**
 * 阶段小结处理
 */
public class EntityProcessStagesSummary extends EntityProcess {
    private Logger logger = LoggerFactory.getLogger(EntityProcessStagesSummary.class);

    public StagesSummaryLabel extractEntity(JSONObject aiOut) {
        StagesSummaryLabel stagesSummaryLabel = new StagesSummaryLabel();
        try {
            //药品
            List<Lemma> drugLemma = createEntityTree(aiOut, EntityEnum.DRUG_NAME.toString());
            List<Drug> drugList = new ArrayList<>();
            for (Lemma lemma : drugLemma) {
                Drug drug = new Drug();
                drug.setName(lemma.getText());
                drugList.add(drug);
            }
            stagesSummaryLabel.setDrugs(drugList);

            //手术名称
            List<Lemma> surgeryLemma = createEntityTree(aiOut, EntityEnum.OPERATION.toString());
            List<Surgery> surgeryList = new ArrayList<>();
            for (Lemma lemma : surgeryLemma) {
                Surgery surgery = new Surgery();
                surgery.setName(lemma.getText());
                surgeryList.add(surgery);
            }
            stagesSummaryLabel.setSurgerys(surgeryList);

            //实验室检查
            List<Lemma> examinationLemma = createEntityTree(aiOut, EntityEnum.LABORATORY.toString());
            List<Laboratory> laboratoryList = new ArrayList<>();
            for (Lemma lemma : examinationLemma) {
                Laboratory examination = new Laboratory();
                examination.setName(lemma.getText());
                laboratoryList.add(examination);
            }
            stagesSummaryLabel.setLaboratory(laboratoryList);

            //辅助检查
            List<Lemma> auxiliaryExaminationLemma = createEntityTree(aiOut, EntityEnum.AUXILIARY_EXAMINATION.toString());
            List<AuxiliaryExamination> auxiliaryExaminationList = new ArrayList<>();
            for (Lemma lemma : auxiliaryExaminationLemma) {
                AuxiliaryExamination auxiliaryExamination = new AuxiliaryExamination();
                auxiliaryExamination.setName(lemma.getText());
                auxiliaryExaminationList.add(auxiliaryExamination);
            }
            stagesSummaryLabel.setAuxiliaryExaminations(auxiliaryExaminationList);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage(), e);
        }
        return stagesSummaryLabel;
    }
}
