package com.emr.controller;

import com.alibaba.fastjson.JSON;
import com.emr.dao.CommomMapper;
import com.emr.dao.Emr_DictionaryMapper;
import com.emr.dao.tTumour.TTumourChemotherapyMapper;
import com.emr.entity.Emr_Dictionary;
import com.emr.entity.ResultUtil;
import com.emr.entity.tTumour.TTumourChemotherapy;
import com.emr.service.tTumour.TTumourService;
import com.emr.util.ExceptionPrintUtil;
import com.emr.vo.commomSearch.CommomVo;
import com.emr.vo.tTumourVo.TTumourVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ProjectName:
 * @Description:
 * @Param 传输参数
 * @Return
 * @Author: 曾文和
 * @CreateDate: 2020/1/6 15:53
 * @UpdateUser: 曾文和
 * @UpdateDate: 2020/1/6 15:53
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Controller
@RequestMapping("tumour/")
public class TTumourController {
    @Autowired
    private Emr_DictionaryMapper dictionaryMapper;
    @Autowired
    private TTumourService tumourService;
    @Autowired
    private CommomMapper commomMapper;
    @Autowired
    private TTumourChemotherapyMapper tumourChemotherapyMapper;
    //加载放疗方式
    @RequestMapping("getRadiotherapyType")
    @ResponseBody
    public String getRadiotherapyType(){
        try {
            List<Emr_Dictionary> list = dictionaryMapper.selectDictionaryByTypeCode("radiotherapy_type_code");
            return JSON.toJSONString(list);
        }catch (Exception e){
            ExceptionPrintUtil.printException(e);
            e.printStackTrace();
            return null;
        }
    }

    //加载放疗程式
    @RequestMapping("getRadiotherapyProgram")
    @ResponseBody
    public String getRadiotherapyProgram(){
        try {
            List<Emr_Dictionary> list = dictionaryMapper.selectDictionaryByTypeCode("radiotherapy_program_code");
            return JSON.toJSONString(list);
        }catch (Exception e){
            ExceptionPrintUtil.printException(e);
            e.printStackTrace();
            return null;
        }
    }
    //加载放疗装置
    @RequestMapping("getRadiotherapyDevice")
    @ResponseBody
    public String getRadiotherapyDevice(){
        try {
            List<Emr_Dictionary> list = dictionaryMapper.selectDictionaryByTypeCode("radiotherapy_device_code");
            return JSON.toJSONString(list);
        }catch (Exception e){
            ExceptionPrintUtil.printException(e);
            e.printStackTrace();
            return null;
        }
    }
    //加载化疗方式
    @RequestMapping("getChemotherapyType")
    @ResponseBody
    public String getChemotherapyType(){
        try {
            List<Emr_Dictionary> list = dictionaryMapper.selectDictionaryByTypeCode("chemotherapy_type_code");
            return JSON.toJSONString(list);
        }catch (Exception e){
            ExceptionPrintUtil.printException(e);
            e.printStackTrace();
            return null;
        }
    }
    //加载化疗方法
    @RequestMapping("getChemotherapyMethod")
    @ResponseBody
    public String getChemotherapyMethod(){
        try {
            List<Emr_Dictionary> list = dictionaryMapper.selectDictionaryByTypeCode("chemotherapy_method_code");
            return JSON.toJSONString(list);
        }catch (Exception e){
            ExceptionPrintUtil.printException(e);
            e.printStackTrace();
            return null;
        }
    }
    //加载化疗疗效
    @RequestMapping("getCurativeEffects")
    @ResponseBody
    public String getCurativeEffects(){
        try {
            List<Emr_Dictionary> list = dictionaryMapper.selectDictionaryByTypeCode("curative_effect_code");
            return JSON.toJSONString(list);
        }catch (Exception e){
            ExceptionPrintUtil.printException(e);
            e.printStackTrace();
            return null;
        }
    }

    //加载肿瘤信息
    @RequestMapping("loadTumourInfo")
    @ResponseBody
    public ResultUtil loadTumourInfo(String patientId) throws Exception{
        CommomVo commomVos = commomMapper.selectTumourByPatientId(patientId);
        if(null != commomVos){
            return ResultUtil.ok(commomVos);
        }else{
            return ResultUtil.error();
        }
    }

    //加载肿瘤化疗信息
    @RequestMapping("loadChemotherapyInfo")
    @ResponseBody
    public ResultUtil loadChemotherapyInfo(String patientId) throws Exception{
        List<TTumourChemotherapy> tTumourChemotherapies = tumourChemotherapyMapper.selectByPatientId(patientId);
        if(null != tTumourChemotherapies && !tTumourChemotherapies.isEmpty()){
            return ResultUtil.ok(tTumourChemotherapies);
        }else{
            return ResultUtil.error();
        }
    }

    //保存肿瘤信息
    @RequestMapping("saveTumour")
    @ResponseBody
    public ResultUtil saveTumour(TTumourVo tumourVo, HttpServletRequest request) throws Exception{
        tumourService.saveTumour(tumourVo,request);
        return ResultUtil.ok();
    }
}
