package com.heyu.api.controller.medical;


import com.heyu.api.baidu.handle.medical.BMedicalSummaryInHospitalHandle;
import com.heyu.api.baidu.request.medical.BMedicalSummaryInHospitalRequest;
import com.heyu.api.baidu.response.medical.BMedicalSummaryInHospitalResp;
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.MedicalSummaryInHospitalResp;
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=1740581925992#/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_in_hospital&method=post
 *
 *
 * 入院小结识别
 *
 *
 *
 * 接口描述
 * 支持识别全国各地各医院入院小结的姓名、性别、年龄、入院时间、主诉、身份证号、联系人电话、病史采集日期、既往史、现病史、个人史、月经婚育史、工作单位、可靠程度 14个关键字段。
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/medical")
@NotIntercept
public class MedicalSummaryInHospitalController extends BaseController {

    @Autowired
    private BMedicalSummaryInHospitalHandle bMedicalSummaryInHospitalHandle;


    @RequestMapping("/summaryInHospital")
    @CacheResult
    public R statement(BMedicalSummaryInHospitalRequest req) {
        List<MedicalSummaryInHospitalResp> respList = new ArrayList<>();
        ApiR<BMedicalSummaryInHospitalResp> bR = bMedicalSummaryInHospitalHandle.handle(req);
        if (bR.isSuccess()) {
            BMedicalSummaryInHospitalResp bMedicalSummaryInHospitalResp = bR.getData();
            List<BMedicalSummaryInHospitalResp.WordsResultDTO> wordsResultDTOS = bMedicalSummaryInHospitalResp.getWordsResult();


            for (BMedicalSummaryInHospitalResp.WordsResultDTO wordsResultDTO : wordsResultDTOS) {

                MedicalSummaryInHospitalResp resp = new MedicalSummaryInHospitalResp();
                resp.setWord(wordsResultDTO.getWord());
                resp.setWordName(wordsResultDTO.getWordName());
                respList.add(resp);
            }
            return R.ok().setData(respList);
        }
        return R.error();
    }


}
