package com.heyu.api.controller.medical;

import com.heyu.api.baidu.handle.medical.BHealthReportHandle;
import com.heyu.api.baidu.request.medical.BHealthReportRequest;
import com.heyu.api.baidu.response.medical.BHealthReportResp;
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.HealthReportResp;
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=1740581406549#/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%2Fhealth_report&method=post
 *医疗诊断报告单识别
 *
 *
 *
 接口描述
 支持识别全国各地各医院医疗诊断报告单，包括医院名称、报告名称、姓名、性别、年龄、科室、临床诊断、报告日期、检查部位、检查方法、检查所见、检查提示、建议、肉眼可见 14个字段。


 */
@Slf4j
@RestController
@RequestMapping("/health")
@NotIntercept
public class HealthReportController extends BaseController {


    @Autowired
    private BHealthReportHandle bHealthReportHandle;


    @RequestMapping("/report")
    @CacheResult
    public R report(BHealthReportRequest req) {
        List<HealthReportResp> respList = new ArrayList<>();
        ApiR<BHealthReportResp> bR = bHealthReportHandle.handle(req);
        if (bR.isSuccess()) {
            BHealthReportResp bMedicalReportDetectionResp = bR.getData();
            if (CollectionUtils.isNotEmpty(bMedicalReportDetectionResp.getWordsResult())) {
                for (BHealthReportResp.WordsResultDTO wordsResultDTO : bMedicalReportDetectionResp.getWordsResult()) {
                    HealthReportResp healthReportResp = new HealthReportResp();

                    healthReportResp.setWord(wordsResultDTO.getWord());
                    healthReportResp.setWordName(wordsResultDTO.getWordName());
                    respList.add(healthReportResp);
                }
            }
            return R.ok().setData(respList);
        }
        return R.error(bR.getErrorMsg());

    }


}
