package thyyxxk.webserver.controller.inpatient.adverseevent;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.adverseevent.*;
import thyyxxk.webserver.entity.dictionary.CodeName;
import thyyxxk.webserver.service.inpatient.adverseevent.AdverseEventService;
import thyyxxk.webserver.utils.ResultVoUtil;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/adverseEvent")
public class AdverseEventController {
    private final AdverseEventService service;

    @Autowired
    public AdverseEventController(AdverseEventService service) {
        this.service = service;
    }

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

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

    @GetMapping({"/getReportDetail"})
    public ResultVo<ReportDetail> getReportDetail(@RequestParam("pid") Integer pid, @RequestParam("level") String level) {
        return service.getReportDetail(pid, level);
    }

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

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

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

    @GetMapping({"/updateDeleted"})
    public ResultVo<String> updateDeleted(@RequestParam("pid") Integer pid) {
        return service.updateDeleted(pid);
    }

    @PostMapping({"/getAllReports"})
    public ResultVo<Map<String, Object>> getAllReports(@RequestBody QueryParam param) {
        return service.getAllReports(param);
    }

    @PostMapping("/exportExcel")
    public void exportExcel(HttpServletResponse response, @RequestBody QueryParam param) {
        service.exportExcel(response, param);
    }

    @PostMapping({"/updateFinalHandled"})
    public ResultVo<ReportDetail> updateFinalHandled(@RequestBody HandlerInfo param) {
        return service.updateFinalHandled(param);
    }

    @GetMapping({"/updatePrinted"})
    public ResultVo<String> updatePrinted(@RequestParam("pid") Integer pid) {
        return service.updatePrinted(pid);
    }

    @PostMapping("/updateFeedback")
    public ResultVo<String> updateFeedback(@RequestBody HandlerInfo body) {
        return service.updateFeedback(body);
    }

    @GetMapping("/getAllAdverseDept")
    public ResultVo<List<AdverseDept>> getAllAdverseDept() {
        return ResultVoUtil.success(service.getAllAdverseDept());
    }

    @PostMapping("/saveAdverseDept")
    public ResultVo<String> saveAdverseDept(@RequestBody AdverseDept adverseDept) {
        return ResultVoUtil.success(service.saveAdverseDept(adverseDept));
    }
}
