package thyyxxk.webserver.controller.view;

import com.alibaba.fastjson.JSONObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.casefrontsheet.CaseFrontsheetMain;
import thyyxxk.webserver.entity.casefrontsheet.JieShouHuiZhenPojo;
import thyyxxk.webserver.entity.casefrontsheet.YshHzRecord;
import thyyxxk.webserver.entity.casefrontsheet.request.SheetOverview;
import thyyxxk.webserver.entity.markmtfees.MzDepositFile;
import thyyxxk.webserver.entity.outpatient.medicalinfo.MzBlRecord;
import thyyxxk.webserver.entity.view.patient360.MedicalTrack;
import thyyxxk.webserver.entity.view.patient360.PatientInfo360;
import thyyxxk.webserver.entity.view.patient360.ZyFeeDetail;
import thyyxxk.webserver.entity.zhuyuanyisheng.emr.EmrPatientData;
import thyyxxk.webserver.entity.zhuyuanyisheng.emr.YzTemperatureParam;
import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.XinZhenYzActOrder;
import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.YiZhuFeiYongChaXunTiaoJian;
import thyyxxk.webserver.service.inpatient.casefrontsheet.CaseFrontSheetMainService;
import thyyxxk.webserver.service.inpatient.casefrontsheet.JieShouHuiZhenService;
import thyyxxk.webserver.service.medicalinsurance.SiMzService;
import thyyxxk.webserver.service.view.Patient360Server;
import thyyxxk.webserver.service.zhuyuanyisheng.HuiZhenShenQingService;
import thyyxxk.webserver.service.zhuyuanyisheng.emr.EmrServer;
import thyyxxk.webserver.utils.ResultVoUtil;

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


@RestController
@RequestMapping("/patient360")
public class Patient360Controller {
    private final Patient360Server server;
    private final CaseFrontSheetMainService caseFrontSheetMainService;
    private final EmrServer emrServer;
    private final HuiZhenShenQingService hzService;

    private final JieShouHuiZhenService jshzService;
    private final SiMzService siMzService;

    public Patient360Controller(Patient360Server server, CaseFrontSheetMainService caseFrontSheetMainService, EmrServer emrServer, HuiZhenShenQingService hzService, JieShouHuiZhenService jshzService, SiMzService siMzService) {
        this.server = server;
        this.caseFrontSheetMainService = caseFrontSheetMainService;
        this.emrServer = emrServer;
        this.hzService = hzService;
        this.jshzService = jshzService;
        this.siMzService = siMzService;
    }

    @GetMapping("/getMedicalTrack")
    public ResultVo<PatientInfo360> getMedicalTrack(@RequestParam("patientId") String patientId,
                                                    @RequestParam("outOrHosp") Integer outOrHosp) {
        return server.getMedicalTrack(patientId, outOrHosp);
    }


    @PostMapping("/hosp/getYz")
    public ResultVo<List<XinZhenYzActOrder>> getYz(@RequestBody @Validated YiZhuFeiYongChaXunTiaoJian param) {
        return server.getYz(param);
    }

    @PostMapping("/hosp/getYzTemperature")
    public ResultVo<JSONObject> getYzTemperature(@RequestBody YzTemperatureParam param) {
        return server.getYzTemperature(param);
    }

    @PostMapping("/hosp/electronicMedicalRecords")
    public ResultVo<List<EmrPatientData>> getEmrData(@RequestBody MedicalTrack p) {
        return emrServer.getPatientDataTree(p.getPatNo(), p.getTimes());
    }

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

    @GetMapping("/hosp/hzInfo")
    public ResultVo<List<YshHzRecord>> chaKanHuiZhenShenQing(@RequestParam("inpatientNo") String inpatientNo,
                                                             @RequestParam("admissTimes") Integer admissTimes) {
        return hzService.chaKanHuiZhenShenQing(inpatientNo, admissTimes);
    }

    @GetMapping("/hosp/hzDetails")
    public ResultVo<JieShouHuiZhenPojo> getHuanZheXinXi(@RequestParam("admissTimes") Integer admissTimes,
                                                        @RequestParam("reqTimes") Integer reqTimes,
                                                        @RequestParam("inpatientNo") String inpatientNo) {
        return jshzService.getHuanZheXinXi(admissTimes, reqTimes, inpatientNo);
    }


    @PostMapping("/hosp/getZyFeeDetail")
    public ResultVo<List<ZyFeeDetail>> getZyFeeDetail(@RequestBody ZyFeeDetail.ZyFeeDetailParams params) {
        return server.getZyFeeDetail(params);
    }

    @GetMapping("/hosp/getOrderDetailByOrderNo")
    public ResultVo<Patient360Server.YzDetail> getOrderDetailByOrderNo(@RequestParam("orderNo") String orderNo) {
        return server.getOrderDetailByOrderNo(orderNo);
    }

    @GetMapping("/mz/getMzReceipts")
    public ResultVo<List<MzDepositFile>> getMzReceipts(@RequestParam("mzNo") String mzNo,
                                                       @RequestParam("date") String date) {
        return server.getMzReceipts(mzNo, date);
    }


    @PostMapping("/mz/getHistoryReceiptDetail")
    public ResultVo<Map<String, Object>> getHistoryReceiptDetail(@RequestBody MzDepositFile mzDepositFile) {
        return ResultVoUtil.success(siMzService.getHistoryReceiptDetail(mzDepositFile));
    }


    @GetMapping("/mz/selectMzBlRecord")
    public ResultVo<MzBlRecord> selectMzBlRecord(@RequestParam("patNo") String patNo, @RequestParam("times") Integer times) {
        return server.selectMzBlRecord(patNo, times);
    }

}
