package com.diagbot.web;
import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.RespDTO;
import com.diagbot.dto.data.*;
import com.diagbot.facade.OldDataFacade;
import com.diagbot.facade.data.*;
import com.diagbot.vo.data.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/qc/data")
@Api(value = "对接接口API", tags = { "对接接口API" })
public class DataController {
    @Autowired
    private ABasDoctorInfoFacade aBasDoctorInfoFacade;
    @Autowired
    private ABasDeptInfoFacade aBasDeptInfoFacade;
    @Autowired
    private AMedRecordTypeFacade aMedRecordTypeFacade;
    @Autowired
    private ABehospitalInfoFacade aBehospitalInfoFacade;
    @Autowired
    private ADoctorAdviceFacade aDoctorAdviceFacade;
    @Autowired
    private AHomePageFacade aHomePageFacade;
    @Autowired
    private AHomeDiagnoseInfoFacade aHomeDiagnoseInfoFacade;
    @Autowired
    private AHomeOperationInfoFacade aHomeOperationInfoFacade;
    @Autowired
    private AMedCrisisFacade aMedCrisisFacade;
    @Autowired
    private AMedicalRecordFacade aMedicalRecordFacade;
    @Autowired
    private AMedicalRecordContentFacade aMedicalRecordContentFacade;
    @Autowired
    private AMedLisResultFacade aMedLisResultFacade;
    @Autowired
    private AMedPacsResultFacade aMedPacsResultFacade;
    @Autowired
    private AMedPacsInfoFacade aMedPacsInfoFacade;
    @Autowired
    private AMedLisInfoFacade aMedLisInfoFacade;
    @Autowired
    private SendDataDealFacade sendDataDealFacade;
    @Autowired
    private OldDataFacade oldDataFacade;
    @Autowired
    private AMedAbnormalInfoFacade aMedAbnormalInfoFacade;



//    @ApiOperation(value = "数据引擎-获取医院所有在职医生的基本信息")
//    @PostMapping("/sendDoctorInfos")
//    @SysLogger("sendDoctorInfos")
//    public RespDTO sendDoctorInfos(@RequestBody List<ABasDoctorInfoVO> list){
//        return aBasDoctorInfoFacade.executeDoctor(list);
//    }
    @ApiOperation(value = "数据引擎-获取医院所有在职医生的基本信息")
    @PostMapping("/sendDoctorInfos")
    @SysLogger("sendDoctorInfos")
    public void sendDoctorInfos(){
         aBasDoctorInfoFacade.executeDoctorPast();
    }

    @ApiOperation(value = "数据引擎-获取医院所有有效科室的基本信息")
    @PostMapping("/sendDeptInfos")
    @SysLogger("sendDeptInfos")
    public RespDTO<List<ABasDeptInfoDTO>> sendDeptInfos(@RequestBody List<ABasDeptInfoVO> list){
        return aBasDeptInfoFacade.executeDept(list);
    }

    @ApiOperation(value = "数据引擎-获取医院所有文书模板基本信息")
    @PostMapping("/sendRecordTypes")
    @SysLogger("sendRecordTypes")
    public RespDTO<List<AMedicalRecordTypeDTO>> sendRecordTypes(@RequestBody List<AMedicalRecordTypeVO> list){
        return aMedRecordTypeFacade.executeMRType(list);
    }

    @ApiOperation(value = "运行质控-评分-文书信息")
    @PostMapping("/sendMrRecordIng")
    @SysLogger("sendMrRecordIng")
    public RespDTO<Map<String, Object>> sendMrRecordIng(@Valid @RequestBody AMrContentVO aMrContentVO){
        return aMedicalRecordFacade.executeMrRecordIng(aMrContentVO);
    }

    @ApiOperation(value = "终末质控-文书信息")
    @PostMapping("/sendMrRecord")
    @SysLogger("sendMrRecord")
    public RespDTO<List<AMedicalRecordDTO>> sendMrRecord(@RequestBody List<AMedicalRecordVO> list){
        return aMedicalRecordFacade.executeMrRecord(list);
    }

    @ApiOperation(value = "终末质控-文书详情")
    @PostMapping("/sendMrContent")
    @SysLogger("sendMrContent")
    public RespDTO<List<AMedicalRecordContentDTO>> sendMrContent(@RequestBody List<AMedicalRecordContentVO> list){
        return aMedicalRecordContentFacade.executeMrRecordContent(list);
    }

    @ApiOperation(value = "数据引擎-获取医院病人住院记录信息")
    @PostMapping("/sendPatientInfo")
    @SysLogger("sendPatientInfo")
    public RespDTO<List<ABehospitalInfoDTO>> sendPatientInfo(@RequestBody List<ABehospitalInfoVO> list){
        return aBehospitalInfoFacade.executeBehospital(list);
    }

    @ApiOperation(value = "数据引擎-获取医院医生医嘱信息")
    @PostMapping("/sendDoctorAdvice")
    @SysLogger("sendDoctorAdvice")
    public RespDTO<List<ADoctorAdviceDTO>> sendDoctorAdvice(@RequestBody List<ADoctorAdviceVO> list){
        return aDoctorAdviceFacade.executeDoctorAdvice(list);
    }

    @ApiOperation(value = "运行质控-获取病案首页")
    @PostMapping("/sendHomePageIng")
    @SysLogger("sendHomePageIng")
    public RespDTO<Map<String, Object>> sendHomePageIng(@Valid @RequestBody AHomePageIngVO aHomePageIngVO){
        return aHomePageFacade.executeHomePageIng(aHomePageIngVO);
    }

    @ApiOperation(value = "终末质控-获取病案首页")
    @PostMapping("/sendHomePage")
    @SysLogger("sendHomePage")
    public RespDTO<List<AHomePageDTO>> sendHomePage(@RequestBody List<AHomePageVO> list){
        return aHomePageFacade.executeHomePage(list);
    }

    @ApiOperation(value = "终末质控-获取病案首页诊断")
    @PostMapping("/sendHomeDiagnose")
    @SysLogger("sendHomeDiagnose")
    public RespDTO<List<AHomeDiagnoseDTO>> sendHomeDiagnose(@RequestBody List<AHomeDiagnoseVO> list){
        return aHomeDiagnoseInfoFacade.executeHomeDiagnose(list);
    }

    @ApiOperation(value = "终末质控-获取病案首页手术")
    @PostMapping("/sendHomeOperation")
    @SysLogger("sendHomeOperation")
    public RespDTO<List<AHomeOperationDTO>> sendHomeOperation(@RequestBody List<AHomeOperationVO> list){
        return RespDTO.onSuc(aHomeOperationInfoFacade.executeHomeOperation(list));
    }

    @ApiOperation(value = "数据引擎-获取危急值")
    @PostMapping("/sendCrisis")
    @SysLogger("sendCrisis")
    public RespDTO<List<AMedCrisisDTO>> sendCrisis(@RequestBody List<AMedCrisisVO> list){
        return aMedCrisisFacade.executeMedCrisis(list);
    }

    @ApiOperation(value = "数据引擎-删除标识")
    @PostMapping("/deleteFlag")
    @SysLogger("deleteFlag")
    public RespDTO deleteFlag(@RequestBody ADeleteFlagVO aDeleteFlagVO){
        if("brzyxx".equals(aDeleteFlagVO.getModeType())){
            return aBehospitalInfoFacade.deleteFlag(aDeleteFlagVO);
        }else if("bryz".equals(aDeleteFlagVO.getModeType())){
            return aDoctorAdviceFacade.deleteFlag(aDeleteFlagVO);
        }else if("basyxx".equals(aDeleteFlagVO.getModeType())){
            return aHomePageFacade.deleteFlag(aDeleteFlagVO);
        }else if("basyzd".equals(aDeleteFlagVO.getModeType())){
            return aHomeDiagnoseInfoFacade.deleteFlag(aDeleteFlagVO);
        }else if("basyss".equals(aDeleteFlagVO.getModeType())){
            return aHomeOperationInfoFacade.deleteFlag(aDeleteFlagVO);
        }else if("wsxx".equals(aDeleteFlagVO.getModeType())){
            return aMedicalRecordFacade.deleteFlag(aDeleteFlagVO);
        }else if("wsnr".equals(aDeleteFlagVO.getModeType())){
            return aMedicalRecordContentFacade.deleteFlag(aDeleteFlagVO);
        }else if("hyjg".equals(aDeleteFlagVO.getModeType())){
            return aMedLisResultFacade.deleteFlag(aDeleteFlagVO);
        }else if("jcjg".equals(aDeleteFlagVO.getModeType())){
            return aMedPacsResultFacade.deleteFlag(aDeleteFlagVO);
        }
        return RespDTO.onSuc(true);
    }

    @ApiOperation(value = "数据引擎-归档标识")
    @PostMapping("/placeFile")
    @SysLogger("placeFile")
    public RespDTO placeFileFlag(@RequestBody APlaceFileVO aPlaceFileVO){
        return aBehospitalInfoFacade.placeFileFlag(aPlaceFileVO);
    }

    @ApiOperation(value = "检查结果")
    @PostMapping("/sendPacsResults")
    @SysLogger("sendPacsResults")
    public RespDTO<List<AMedPacsResultVO>> sendPacsResults(@RequestBody List<AMedPacsResultVO> list){
        return aMedPacsResultFacade.executeMedPacsResult(list);
    }

    @ApiOperation(value = "化验结果")
    @PostMapping("/sendLisResults")
    @SysLogger("sendLisResults")
    public RespDTO<List<AMedLisResultVO>> sendLisResults(@RequestBody List<AMedLisResultVO> list){
        return aMedLisResultFacade.executeMedLisResult(list);
    }

    @ApiOperation(value = "检查信息")
    @PostMapping("/sendPacsInfos")
    @SysLogger("sendPacsInfos")
    public RespDTO sendPacsInfos(@RequestBody List<AMedPacsInfoVO> list){
        return aMedPacsInfoFacade.dealData(list);
    }

    @ApiOperation(value = "化验信息")
    @PostMapping("/sendLisInfos")
    @SysLogger("sendLisInfos")
    public RespDTO sendLisInfos(@RequestBody List<AMedLisInfoVO> list){
        return aMedLisInfoFacade.dealData(list);
    }

    @ApiOperation(value = "数据引擎-历史数据结构化处理")
    @PostMapping("/hisDataDeal")
    @SysLogger("hisDataDeal")
    public RespDTO<List<AMedCrisisDTO>> hisDataDeal(@RequestBody HisDataDealVO hisDataDealVO){
        boolean b = true;
        try {
             b = aMedicalRecordFacade.hisDataDeal(hisDataDealVO);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return RespDTO.onSuc(b);
    }

    @ApiOperation(value = "数据引擎-历史数据拉取<七院>")
    @PostMapping("/sendDataDeal")
    @SysLogger("sendDataDeal")
    public void sendDataDeal(String startDate,String stopDate){
        sendDataDealFacade.sendDataDeal(startDate,stopDate);
    }


    @ApiOperation(value = "数据引擎-单个病人历史数据拉取<七院>")
    @PostMapping("/sendDataDealOne")
    @SysLogger("sendDataDealOne")
    public void sendDataDealOne(String code){
        sendDataDealFacade.sendDateDealOne(code);
    }


    @ApiOperation(value = "文书加密")
    @PostMapping("/documentEncryption")
    @SysLogger("documentEncryption")
    public void sendDataDeal(){
        oldDataFacade.execute();
    }


    @ApiOperation(value = "测试")
    @PostMapping("/getColumnZhAndCh")
    @SysLogger("getColumnZhAndCh")
    public RespDTO getColumnZhAndCh(String name){
        aMedAbnormalInfoFacade.a(name);
        return RespDTO.onSuc(true);
    }

//    @Autowired
//    private ColumnFacade columnFacade;
//    @ApiOperation(value = "病历解析")
//    @PostMapping("/analyseRec")
//    @SysLogger("analyseRec")
//    public RespDTO analyseRec(@RequestBody AColumnVO aColumnVO){
//        columnFacade.analyseRec(aColumnVO.getHospitalId(),aColumnVO.getModeId(),aColumnVO.getContent());
//        return RespDTO.onSuc(true);
//    }
}
