package com.heyu.api.controller.medical;


import com.heyu.api.baidu.handle.medical.BMedicalRecordHandle;
import com.heyu.api.baidu.request.medical.BMedicalRecordRequest;
import com.heyu.api.baidu.response.medical.BMedicalRecordResp;
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.MedicalRecordResp;
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=1740581634871#/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_record&method=post
 *
 * 病案首页识别
 *
 *接口描述
 * 支持识别全国各地病案首页的病案号、姓名、性别、出生日期、身份证号、出/入院科别、住院次数、药物过敏情况等 15 个关键字段，其中北京地区票据识别效果最佳
 *
 */
@Slf4j
@RestController
@RequestMapping("/medical")
@NotIntercept
public class MedicalRecordController extends BaseController {


    @Autowired
    private BMedicalRecordHandle bMedicalRecordHandle;


    @RequestMapping("/record")
    @CacheResult
    public R record(BMedicalRecordRequest req) {
        MedicalRecordResp resp = new MedicalRecordResp();
        ApiR<BMedicalRecordResp> bR = bMedicalRecordHandle.handle(req);
        if (bR.isSuccess()) {
            BMedicalRecordResp bMedicalRecordResp = bR.getData();
            BMedicalRecordResp.WordsResultDTO wordsResultDTO = bMedicalRecordResp.getWordsResult();
            resp.setNation(wordsResultDTO.getNation().getWord());                              //民族
            resp.setAllergy(wordsResultDTO.getAllergy().getWord());                     //药物过敏
            resp.setSex(wordsResultDTO.getSex().getWord());                 //	性别
            resp.setBirthday(wordsResultDTO.getBirthday().getWord());                        //出生日期
            resp.setNationality(wordsResultDTO.getNationality().getWord());             //国籍
            resp.setName(wordsResultDTO.getName().getWord());                            //姓名
            resp.setMaritalStatus(wordsResultDTO.getMaritalStatus().getWord());                   //婚姻
            resp.setHospitalDay(wordsResultDTO.getHospitalDay().getWord());             //住院次数
            resp.setAdmissionDepartment(wordsResultDTO.getAdmissionDepartment().getWord());     //	入院科别
            resp.setId(wordsResultDTO.getId().getWord());                      //身份证号
            resp.setDischargeDepartment(wordsResultDTO.getDischargeDepartment().getWord());     //出院科别
            resp.setCareer(wordsResultDTO.getCareer().getWord());              //	职业
            resp.setAge(wordsResultDTO.getAge().getWord());                     //年龄
            resp.setBloodType(wordsResultDTO.getAge().getWord());           //血型、Rh血型、ABO血型
            resp.setRecordNum(wordsResultDTO.getRecordNum().getWord());               //	病案号
            return R.ok().setData(resp);
        }
        return R.error(bR.getErrorMsg());
    }
}
