package com.heyu.api.controller.medical;


import com.heyu.api.baidu.handle.medical.BMedicalSurgeryHandle;
import com.heyu.api.baidu.request.medical.BMedicalSurgeryRequest;
import com.heyu.api.baidu.response.medical.BMedicalSurgeryResp;
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.MedicalSurgeryResp;
import lombok.extern.slf4j.Slf4j;
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=1740582692921#/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_surgery&method=post
 *手术记录识别
 *
 * 接口描述
 *
 * 支持识别全国各地各医院手术记录的姓名、性别、年龄、科室、麻醉方式、手术操作名称、手术步骤、手术结果、术中所见、术中诊断、术前诊断、术后诊断 12个关键字段。
 *
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/medical")
@NotIntercept
public class MedicalSurgeryController extends BaseController {

    @Autowired
    private BMedicalSurgeryHandle bMedicalSurgeryHandle;


    @RequestMapping("/surgery")
    @CacheResult
    public R surgery(BMedicalSurgeryRequest req) {

        List<MedicalSurgeryResp> respList = new ArrayList<>();


        ApiR<BMedicalSurgeryResp> bR = bMedicalSurgeryHandle.handle(req);
        if (bR.isSuccess()) {
            BMedicalSurgeryResp bMedicalSurgeryResp = bR.getData();
            List<BMedicalSurgeryResp.WordsResultDTO> wordsResult = bMedicalSurgeryResp.getWordsResult();
            for (BMedicalSurgeryResp.WordsResultDTO wordsResultDTO : wordsResult) {
                MedicalSurgeryResp medicalSurgeryResp = new MedicalSurgeryResp();
                medicalSurgeryResp.setWord(wordsResultDTO.getWord());
                medicalSurgeryResp.setWordName(wordsResultDTO.getWordName());
                respList.add(medicalSurgeryResp);
            }
            return R.ok().setData(respList);
        }
        return R.error();
    }
}
