package thyyxxk.webserver.controller.reports;

import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import thyyxxk.webserver.config.exception.ExceptionEnum;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.inpatient.patient.Patient;
import thyyxxk.webserver.service.reports.PatientDistributionAddressServer;
import thyyxxk.webserver.utils.ResultVoUtil;
import thyyxxk.webserver.utils.StringUtil;

import java.util.List;

@RestController
@RequestMapping("/PatientDistributionAddress")
public class PatientDistributionAddressController {
    private final Integer BE_HOSPITALIZED = 1;
    private final Integer 门诊 = 2;

    private final Integer 在院 = 1;
    private final Integer LEAVE_HOSPITAL = 2;

    private final PatientDistributionAddressServer server;

    public PatientDistributionAddressController(PatientDistributionAddressServer server) {
        this.server = server;
    }

    @GetMapping("/patientAddress")
    public ResultVo<List<Patient>> patientAddress(@Param("patientType") Integer patientType,
                                                  @Param("inHospital") Integer inHospital,
                                                  @Param("startTime") String startTime,
                                                  @Param("endTime") String endTime) {
        if (patientType.equals(BE_HOSPITALIZED)) {
            if (StringUtil.isBlank(startTime) && inHospital.equals(LEAVE_HOSPITAL)) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "出院患者必须选择时间范围");
            }
            return server.inpatientLocation(inHospital.equals(LEAVE_HOSPITAL) ? "zy_inactpatient" : "zy_actpatient", startTime, endTime);
        } else {
            if (StringUtil.isBlank(startTime)) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "门诊患者请选择时间范围");
            }
            return server.mzLocation(startTime, endTime);
        }

    }


}
