package com.diagbot.facade;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diagbot.dto.ConceptDTO;
import com.diagbot.entity.LibraryInfo;
import java.util.List;
import com.diagbot.service.impl.ConceptServiceImpl;
import com.diagbot.vo.MedicalVo;
import com.diagbot.vo.TermVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * @Description: 术语查询业务层
 * @author: Weixuan Huang
 * @time: 2019/1/14 16:17
 */
@Component
public class ConceptFacade extends ConceptServiceImpl {

    @Autowired
    private LibraryInfoFacade libraryinfoFacade;
    @Autowired
    private LibraryDetailFacade libraryDetailFacade;
    @Autowired
    private MedicalFacade medicalFacade;
    @Autowired
    private RelationFacade relationFacade;


    /**
     * 获取医学术语信息
     *
     * @param termvo
     * @return ConceptDTO
     */
    public ConceptDTO getConceptInfo(@RequestBody TermVo termvo) {

        ConceptDTO conceptDTO = getConcept(termvo);
        // 获取与医学术语的基本信息
        if (conceptDTO != null) {
            termvo.setId(conceptDTO.getLibId());
            termvo.setConcept_id(conceptDTO.getId());
            termvo.setTerm(conceptDTO.getName());
            LibraryInfo libraryInfo = libraryinfoFacade.getLibraryInfor(termvo);

            if (libraryInfo.getIsConcept() != null && libraryInfo.getIsConcept() == 1) {
                conceptDTO.setName(libraryInfo.getName());
            }
            conceptDTO.setLibraryInfo(libraryInfo);

            // 获取与术语相关的医学知识
            conceptDTO.setInformation(libraryDetailFacade.getLibraryDetails(termvo));
            // 获取与术语相关的临床医学信息
            MedicalVo medicalVo = new MedicalVo();
            medicalVo.setName(termvo.getTerm());
            medicalVo.setConcept_id(conceptDTO.getId());
            conceptDTO.setMedicalInfo(medicalFacade.getMedicalInfo(medicalVo));
            // 获取术语的所有上级信息
            conceptDTO.setRelations(relationFacade.getAllRelation(termvo));
        }

        return conceptDTO;
    }

}
