package thyyxxk.webserver.controller.dictionary;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.zhuyuanyisheng.emr.EmrDataExtract;
import thyyxxk.webserver.entity.zhuyuanyisheng.emr.EmrDataMaintenance;
import thyyxxk.webserver.service.dictionary.EmrDataMaintenanceServer;

import java.util.List;

@RestController
@RequestMapping("/EmrDataMaintenance")
public class EmrDataMaintenanceContorller {

    private final EmrDataMaintenanceServer server;

    public EmrDataMaintenanceContorller(EmrDataMaintenanceServer server) {
        this.server = server;
    }


    @GetMapping("/getElectronicMedicalRecordDataElementSql")
    public ResultVo<Page<EmrDataMaintenance>> getElectronicMedicalRecordDataElementSql(@RequestParam("currentPage") int currentPage,
                                                                                       @RequestParam("pageSize") int pageSize,
                                                                                       @RequestParam("total") long total) {
        return server.getElectronicMedicalRecordDataElementSql(currentPage, pageSize, total);
    }


    @PostMapping("/testSql")
    public ResultVo<JSONObject> testSql(@RequestBody EmrDataMaintenance emr) {
        return server.testSql(emr);
    }

    @PostMapping("/addData")
    public ResultVo<String> addData(@RequestBody EmrDataMaintenance emr) {
        return server.addData(emr);
    }

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

    @PostMapping("/getEmrInpatientData")
    @PassToken
    public ResultVo<JSONObject> getEmrInpatientData(@RequestBody EmrDataMaintenance emr) throws Exception {
        return server.getEmrInpatientData(emr.getPatNo(), emr.getTimes());
    }

    @PostMapping("/updateData")
    public ResultVo<String> updateData(@RequestBody EmrDataMaintenance emr) {
        return server.updateData(emr);
    }


    @GetMapping("/getExtractDataSource")
    public ResultVo<List<EmrDataExtract>> getExtractDataSource() {
        return server.getExtractDataSource();
    }

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


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

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