package thyyxxk.webserver.controller.inpatient.casefrontsheet;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.casefrontsheet.*;
import thyyxxk.webserver.entity.casefrontsheet.request.*;
import thyyxxk.webserver.entity.casefrontsheet.response.DismissCount;
import thyyxxk.webserver.entity.casefrontsheet.response.SheetOverviewForBas;
import thyyxxk.webserver.entity.dictionary.CodeName;
import thyyxxk.webserver.service.inpatient.casefrontsheet.CaseFrontSheetAnalyzeService;
import thyyxxk.webserver.service.inpatient.casefrontsheet.CaseFrontSheetMainService;
import thyyxxk.webserver.utils.TokenUtil;

import java.util.List;
import java.util.Map;

/**
 * @author dj
 */
@RestController
@RequestMapping("/caseFrontSheet")
public class CaseFrontSheetController {
    private final CaseFrontSheetMainService service;
    private final CaseFrontSheetAnalyzeService analyzeService;

    @Autowired
    public CaseFrontSheetController(CaseFrontSheetMainService service, CaseFrontSheetAnalyzeService analyzeService) {
        this.service = service;
        this.analyzeService = analyzeService;
    }

    @GetMapping("/getAllDictionary")
    public ResultVo<Map<String, List<CodeName>>> getAllDictionary() {
        return service.getAllDictionary();
    }

    @GetMapping("/resetDictionary")
    public ResultVo<String> resetDictionary() {
        return service.resetDictionary();
    }

    @GetMapping("/getUserWards")
    public ResultVo<List<CodeName>> getUserWards() {
        return service.getUserWards();
    }

    @GetMapping("/getAllWards")
    public ResultVo<List<CodeName>> getWards() {
        return service.getAllWards();
    }

    @GetMapping("/getPatientOverview")
    public ResultVo<List<SheetOverview>> getPatientOverview(String ward) {
        return service.getPatientOverview(ward);
    }

    @PostMapping("/outPatients")
    public ResultVo<List<SheetOverview>> getOutPatients(@RequestBody DismissedSheetInquiry param) {
        return service.getOutPatient(param);
    }

    @PostMapping("/basOutPatients")
    public ResultVo<SheetOverviewForBas> getOutPatientsForBas(@RequestBody DismissedSheetInquiry param) {
        return service.getOutPatientForBas(param);
    }

    @PostMapping("/getSheetInfo")
    public ResultVo<CaseFrontsheetMain> getPatientInfo(@RequestBody SheetOverview overview) {
        return service.getPatientInfo(overview);
    }

    @GetMapping("/getYbDiags")
    public ResultVo<List<YiBaoDisdiag>> getYbDiags(@RequestParam("bah") String bah,
                                                   @RequestParam("times") Integer times) {
        return service.getYbDiags(bah, times);
    }

    @PostMapping("/saveYbDiags")
    public ResultVo<String> saveYbDiags(@RequestBody SaveYbDiag param) {
        return service.saveYbDiags(param);
    }

    @PostMapping("/unArchiveBa")
    public ResultVo<String> unArchiveBa(@RequestBody OpCaseFrontsheet param) {
        param.setStaffId(TokenUtil.getInstance().getTokenUserId());
        return service.unArchiveSheet(param);
    }

    @PostMapping("/printVerify")
    public ResultVo<Map<String, List<CodeName>>> printVerification(@RequestBody OpCaseFrontsheet param) {
        param.setStaffId(TokenUtil.getInstance().getTokenUserId());
        return service.printVerification(param);
    }

    @PostMapping("/saveVerify")
    public ResultVo<List<CodeName>> saveVerify(@RequestBody OpCaseFrontsheet param) {
        param.setStaffId(TokenUtil.getInstance().getTokenUserId());
        return service.saveVerify(param);
    }

    @PostMapping("/frontsheetQualityCheck")
    public ResultVo<String> frontsheetQualityCheck(@RequestBody CaseFrontsheetMain sheet) {
        return service.frontsheetQualityCheck(sheet);
    }

    @PostMapping("/advanceSearch")
    public ResultVo<List<SheetOverview>> advanceSearch(@RequestBody AdvanceSearch param) {
        return service.advanceSearch(param);
    }

    @GetMapping("/fetchSsfz")
    public ResultVo<String> fetchSsfz(@RequestParam("code") String code,
                                      @RequestParam("bah") String bah,
                                      @RequestParam("times") Integer times) {
        return service.fetchSsfz(code, bah, times);
    }

    @PostMapping("/analyzeDismissCount")
    public ResultVo<List<DismissCount>> analyzeDismissCount(@RequestBody SheetAnalyzeParams param) {
        return analyzeService.analyzeDismissCount(param);
    }

    @GetMapping("/increaseDiagWeight")
    public void increaseDiagWeight(@RequestParam("code") String code) {
        service.increaseDiagWeight(code);
    }

    @PostMapping("/analyzeQualityControl")
    public ResultVo<List<SheetQuality>> analyzeQualityControl(@RequestBody SheetAnalyzeParams params) {
        return analyzeService.analyzeQualityControl(params);
    }

    @GetMapping("/selectSiDiagByBaDiag")
    public ResultVo<CodeName> selectSiDiagByBaDiag(@RequestParam("code") String code) {
        return service.selectSiDiagByBaDiag(code);
    }

    @GetMapping("/isMedinsSetl")
    public ResultVo<String> isMedinsSetl(@RequestParam("patNo") String patNo, @RequestParam("times") Integer times) {
        return service.isMedinsSetl(patNo, times);
    }

    @PassToken
    @PostMapping("/sheetVerification")
    public ResultVo<Map<String, List<CodeName>>> sheetVerification(@RequestBody SheetOverview view) {
        return service.sheetVerification(view);
    }
}
