package com.heyu.api.controller.medical;


import com.heyu.api.baidu.handle.medical.BMedicalSummaryHandle;
import com.heyu.api.baidu.request.medical.BMedicalSummaryRequest;
import com.heyu.api.baidu.response.medical.BMedicalSummaryResp;
import com.heyu.api.controller.BaseController;
import com.heyu.api.data.annotation.CacheResult;
import com.heyu.api.data.annotation.NotIntercept;
import com.heyu.api.data.utils.ApiR;
import com.heyu.api.data.utils.R;
import com.heyu.api.resp.medical.MedicalSummaryResp;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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


/***
 *
 * https://console.bce.baidu.com/support/?_=1740575657628&timestamp=1740581767882#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E5%8C%BB%E7%96%97%E7%A5%A8%E6%8D%AEOCR&api=rest%2F2.0%2Focr%2Fv1%2Fmedical_summary&method=post
 *
 *
 *出院小结识别
 *接口描述
 * 支持识别全国各地各医院诊断证明的姓名、性别、年龄、科室、入院时间、出院时间、住院号、出院诊断、出院医嘱 9个关键字段。
 *
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/medical")
@NotIntercept
public class MedicalSummaryController extends BaseController {

    @Autowired
    private BMedicalSummaryHandle bMedicalSummaryHandle;


    @RequestMapping("/summary")
    @CacheResult
    public R statement(BMedicalSummaryRequest req) {
        List<MedicalSummaryResp> respList = new ArrayList<>();

        ApiR<BMedicalSummaryResp> bR = bMedicalSummaryHandle.handle(req);
        if (bR.isSuccess()) {
            BMedicalSummaryResp bMedicalSummaryResp = bR.getData();
            List<BMedicalSummaryResp.WordsResultDTO> wordsResultDTOS = bMedicalSummaryResp.getWordsResult();

            if(CollectionUtils.isNotEmpty(wordsResultDTOS)){
                for (BMedicalSummaryResp.WordsResultDTO wordsResultDTO : wordsResultDTOS) {

                    MedicalSummaryResp medicalSummaryResp = new MedicalSummaryResp();
                    medicalSummaryResp.setWordName(wordsResultDTO.getWordName());
                    medicalSummaryResp.setWord(wordsResultDTO.getWord());
                    respList.add(medicalSummaryResp);
                }

            }
            return R.ok().setData(respList);
        }
        return R.error(bR.getErrorMsg());

    }


}
