package com.heyu.api.controller.medical;

import com.heyu.api.baidu.handle.medical.BMedicalStatementHandle;
import com.heyu.api.baidu.request.medical.BMedicalStatementRequest;
import com.heyu.api.baidu.response.medical.BMedicalStatementResp;
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.MedicalStatementResp;
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;



/**
 * https://console.bce.baidu.com/support/?_=1740575657628&timestamp=1740581091562#/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_statement&method=post
 * <p>
 * 医疗费用结算单识别
 *
 *
 * 接口描述
 * 支持识别全国医疗费用结算单的姓名、出/入院时间、发票总金额、自费金额、医保支付金额等 6 个关键字段，其中北京地区票据识别效果最佳。
 */
@Slf4j
@RestController
@RequestMapping("/medical")
@NotIntercept
public class MedicalStatementController extends BaseController {


    @Autowired
    private BMedicalStatementHandle bMedicalStatementHandle;


    @RequestMapping("/statement")
    @CacheResult
    public R statement(BMedicalStatementRequest req) {

        MedicalStatementResp resp = new MedicalStatementResp();

        ApiR<BMedicalStatementResp> bR = bMedicalStatementHandle.handle(req);


        if (bR.isSuccess()) {

            BMedicalStatementResp bMedicalStatementResp = bR.getData();
            BMedicalStatementResp.WordResultDTO wordResultDTO = bMedicalStatementResp.getWordResult();


            resp.setAmountInFiguers(wordResultDTO.getAmountInFiguers().getWord());                     //发票总金额
            resp.setMedicalInsuranceAmount(wordResultDTO.getMedicalInsuranceAmount().getWord());                  //	医保支付
            resp.setSelfPaymentAmount(wordResultDTO.getSelfPaymentAmount().getWord());                   //	全自费
            resp.setAdmissionDate(wordResultDTO.getAdmissionDate().getWord());                   //入院时间
            resp.setDischargeDate(wordResultDTO.getDischargeDate().getWord());                   //出院时间
            resp.setName(wordResultDTO.getName().getWord());                    //姓名

            return R.ok().setData(resp);


        }

        return R.error(bR.getErrorMsg());
    }
}
