package thyyxxk.webserver.controller.zhuyuanyizheng.emr;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.zhuyuanyisheng.emr.EmrAuditDetail;
import thyyxxk.webserver.entity.zhuyuanyisheng.emr.EmrLimitUnlock;
import thyyxxk.webserver.entity.zhuyuanyisheng.emrcontrolrule.*;
import thyyxxk.webserver.service.zhuyuanyisheng.emr.EmrControlRuleSever;
import thyyxxk.webserver.service.zhuyuanyisheng.emr.EmrControlRuleSeverV2;
import thyyxxk.webserver.utils.ResultVoUtil;

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

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/emrControlRule")
public class EmrControlRuleController {
    private final EmrControlRuleSever server;

    private final EmrControlRuleSeverV2 serverv2;

    public EmrControlRuleController(EmrControlRuleSever server, EmrControlRuleSeverV2 serverv2) {
        this.server = server;
        this.serverv2 = serverv2;
    }

    @GetMapping("/getAvailableObjects")
    public ResultVo<List<Map<String, Object>>> getAvailableObjects() {
        return server.getAvailableObjects();
    }

    @GetMapping("/specifyAdmissionQualityControl")
    public ResultVo<JSONObject> specifyAdmissionQualityControl(@RequestParam("start") String start,
                                                               @RequestParam("end") String end) {
        return serverv2.specifyAdmissionQualityControl(start, end);
    }

    @GetMapping("/myPatientQualityControl")
    public ResultVo<List<EmrAuditDetail>> myPatientQualityControl() {
        return serverv2.myPatientQualityControl();
    }


    @GetMapping("/getRuleList")
    public ResultVo<List<EmrRule>> getRuleList() {
        return ResultVoUtil.success(server.getRuleList());
    }

    @GetMapping("/switchQualityControl")
    public ResultVo<String> switchQualityControl(@RequestParam("id") String id,
                                                 @RequestParam("offOn") Integer offOn) {
        return server.switchQualityControl(id, offOn);
    }

    @GetMapping("/deleteRuleById")
    public ResultVo<String> deleteRuleById(@RequestParam("id") String id) {
        return server.deleteRuleById(id);
    }

    @GetMapping("/modifyTheAdmissionQualityControlTime")
    public ResultVo<String> modifyTheAdmissionQualityControlTime(@RequestParam("date") String date) {
        return server.modifyTheAdmissionQualityControlTime(date);
    }

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

    @GetMapping("/createRestrictions")
    public ResultVo<EmrRuleVerify> createRestrictions(@RequestParam("code") String code,
                                                      @RequestParam("id") String id,
                                                      @RequestParam("patNo") String patNo) {
        String[] strings = patNo.split("_");
        return server.createRestrictions(code, strings[0], Integer.valueOf(strings[1]), Integer.valueOf(strings[2]), id);
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////
    @PostMapping("/requestToUnlockMedicalRecords")
    public ResultVo<String> requestToUnlockMedicalRecords(@RequestBody EmrLimitUnlock param) {
        return server.requestToUnlockMedicalRecords(param);
    }

    @PostMapping("/getApplicationData")
    public ResultVo<IPage<EmrLimitUnlock>> getApplicationData(@RequestBody SelectUnlockParam param) {
        return server.getApplicationData(param);
    }

    @PostMapping("/exportExcelUnlock")
    @PassToken
    public void exportExcelUnlock(HttpServletResponse response, @RequestBody SelectUnlockParam param) {
        server.exportExcelUnlock(response, param);
    }

    @PostMapping("/reviewMedicalRecordsToUnlock")
    public ResultVo<String> reviewMedicalRecordsToUnlock(@RequestBody EmrLimitUnlock param) {
        return server.reviewMedicalRecordsToUnlock(param);
    }

    @GetMapping("/getMyUnlockByPatNo")
    @PassToken
    public ResultVo<EmrLimitUnlock> getMyUnlockByPatNo(@RequestParam("patNo") String patNo,
                                                       @RequestParam("times") Integer times) {
        return server.getMyUnlockByPatNo(patNo, times);
    }


    @PostMapping("/terminalPatients")
    public ResultVo<List<QualityControlAnalysisOfMedicalRecords>> terminalPatients(@RequestBody FinalQuery param) {
        return serverv2.terminalPatients(param);
    }

}
