package thyyxxk.webserver.controller.zhuyuanyizheng;

import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.dictionary.pathwayTemplates.dto.ClinicalPathwayTemplates;
import thyyxxk.webserver.entity.dictionary.pathwayTemplates.vo.PathwayTemplatesVo;
import thyyxxk.webserver.entity.dictionary.pathwayTemplates.vo.TemplateDayVo;
import thyyxxk.webserver.entity.zhuyuanyisheng.patientClinicalPathway.dto.ClinicalPathwayPatientDayLog;
import thyyxxk.webserver.entity.zhuyuanyisheng.patientClinicalPathway.req.ExitClinicalPathwayReq;
import thyyxxk.webserver.entity.zhuyuanyisheng.patientClinicalPathway.req.PatientEnrollmentReq;
import thyyxxk.webserver.entity.zhuyuanyisheng.patientClinicalPathway.req.UpdatePatientDayReq;
import thyyxxk.webserver.entity.zhuyuanyisheng.patientClinicalPathway.vo.PatientDayWorkVo;
import thyyxxk.webserver.entity.zhuyuanyisheng.patientClinicalPathway.vo.PatientOrderDayVo;
import thyyxxk.webserver.service.dictionary.clinicalPathway.ClinicalPathwayService;
import thyyxxk.webserver.service.zhuyuanyiji.ClinicalPathwayPatientService;
import thyyxxk.webserver.utils.ResultVoUtil;

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

@RequestMapping("/clinicalPathwayPatient")
@RestController
@RequiredArgsConstructor
public class ClinicalPathwayPatientController {
    private final ClinicalPathwayPatientService service;
    private final ClinicalPathwayService clinicalPathwayService;


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

    @GetMapping("/obtainExecutableClinicalPathways")
    public ResultVo<List<PathwayTemplatesVo>> obtainExecutableClinicalPathways() {
        return ResultVoUtil.success(clinicalPathwayService.getTemplatesToTree(" (publish = 1 or is_dir = 1) "));
    }

    @GetMapping("/getClinicalPathwayDayLog")
    public ResultVo<List<PatientDayWorkVo>> getClinicalPathwayDayLog(@RequestParam("patNo") String patNo,
                                                                     @RequestParam("times") Integer times) {
        return ResultVoUtil.success(service.getClinicalPathwayDayLog(patNo, times));
    }

    @PostMapping("/patientEnrollment")
    public ResultVo<String> patientEnrollment(@RequestBody PatientEnrollmentReq req) {
        return service.patientEnrollment(req);
    }

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

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

    @PostMapping("/updatePatientDay")
    public ResultVo<String> updatePatientDay(@RequestBody UpdatePatientDayReq params) {
        return service.updatePatientDay(params);
    }

    @GetMapping("/getPatientOrderByDay")
    public ResultVo<Map<String, List<PatientOrderDayVo>>> getPatientOrderByDay(@RequestParam("patNo") String patNo,
                                                                               @RequestParam("times") Integer times,
                                                                               @RequestParam("dayId") String dayId) {
        return ResultVoUtil.success(service.getPatientOrderByDay(patNo, times, dayId));
    }

    @PostMapping("/exitClinicalPathway")
    public ResultVo<String> exitClinicalPathway(@RequestBody @Validated ExitClinicalPathwayReq req) {
        return service.exitClinicalPathway(req);
    }

}
