package com.ywt.outpatient.controllers.patient;

import com.ywt.biz.common.enums.PaymentChannelEnum;
import com.ywt.biz.common.enums.TerminalEnum;
import com.ywt.biz.common.util.Checker;
import com.ywt.biz.common.util.DateUtil;
import com.ywt.biz.common.util.StringHelper;
import com.ywt.gapi.Result;
import com.ywt.gapi.ResultCode;
import com.ywt.gapi.ResultInt;
import com.ywt.gapi.order.*;
import com.ywt.gapi.third.taihe.*;
import com.ywt.gapi.user.UserService;
import com.ywt.outpatient.core.BaseResponse;
import com.ywt.outpatient.core.annotations.UserLogin;
import com.ywt.outpatient.core.utils.BizUtil;
import com.ywt.outpatient.core.Constant;
import com.ywt.outpatient.domain.models.enums.DatePeriodEnum;
import com.ywt.outpatient.service.web.taihe.TaiheSystemService;
import com.ywt.outpatient.service.web.taihe.TaiheUserService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 太和医院预约挂号
 */
@RestController("/hzmp/taihe/register")
@RequestMapping({"/hzmp/taihe/register"})
public class TaiheRegisterController {
    private static Logger logger = LoggerFactory.getLogger(TaiheRegisterController.class);

    @DubboReference
    private TaiheService taiheServiceBlockingStub;

    @DubboReference
    private OrderService orderServiceBlockingStub;

    @DubboReference
    private UserService userServiceBlockingStub;

    @Autowired
    private TaiheSystemService systemService;

    @Autowired
    private TaiheUserService userService;


    /**
     * 科室列表
     *
     * @return
     */
    @UserLogin(need = false)
    @RequestMapping({"/deptList"})
    public @ResponseBody
    BaseResponse getDeptList() {
        BaseResponse response = new BaseResponse();

        try {
            GetDeptListRequest getDeptListRequest = GetDeptListRequest.newBuilder()
                    .setHospitalId(BizUtil.getHospitalIdByTerminalId(BizUtil.getCurrentTerminalWrapped()))
                    .build();
            GetDeptListResponse getDeptListResponse = taiheServiceBlockingStub.getDeptList(getDeptListRequest);

            if (getDeptListResponse.getCode() == ResultCode.SUCCEED_VALUE) {
                List<Dept> depts = getDeptListResponse.getDeptsList();
                List lst = new ArrayList();

                for (Dept dept : depts) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("deptCode", dept.getDeptCode());        //科室代码
                    map.put("deptName", dept.getDeptName());        //科室名称
//                    map.put("deptIntro", dept.getDeptIntro());       //科室简介
//                    map.put("deptAddr", dept.getDeptAddr());        //科室地理位置
//                    map.put("parentCode", dept.getParentCode());    //上级科室代码(没有填-1)
//                    map.put("ageLimited", dept.getAgeLimited());    //挂号年龄限制
                    lst.add(map);
                }
                Map<String, Object> map = new LinkedHashMap<>();
                map.put("count", getDeptListResponse.getCount());
                map.put("list", lst);

                return response.succeed("处理成功", map);
            }

            return response.failed(BaseResponse.APP_ERROR, getDeptListResponse.getMsg());
        } catch (Exception e) {
            logger.error("deptList():{}", e.getMessage());
            return response.failed(BaseResponse.APP_EXCEPTION, Constant.ERROR_PROMPT);
        }
    }
//
//    /**
//     * 日期列表
//     *
//     * @return
//     */
//    @UserLogin(need = false)
//    @RequestMapping({"/dateList"})
//    public @ResponseBody
//    BaseResponse getDateList() {
//        BaseResponse response = new BaseResponse();
//        List<Map<String, Object>> lst = new LinkedList<>();
//        Calendar calendar = Calendar.getInstance();
//
//        for (int offset = 0; offset < 8; offset++) {
//            if (offset > 0) {
//                calendar.add(Calendar.DATE, 1);
//            }
//
//            Date date = calendar.getTime();
//            Map<String, Object> map = new HashMap<>();
//
//            map.put("offset", offset);
//            map.put("date", DateUtil.formatDate(date, "yyyy-MM-dd"));
//            map.put("strDate", DateUtil.formatDate(date, "yyyy年MM月dd日"));
//            map.put("week", DateUtil.getDayOfWeek(calendar));
//
//            lst.add(map);
//        }
//
//        Map<String, Object> data = new HashMap<>();
//        data.put("list", lst);
//
//        return response.succeed("处理成功", data);
//    }

    /**
     * 医生列表
     *
     * @param deptCode
     * @param doctorName
     * @return
     */
    @UserLogin(need = false)
    @RequestMapping({"/doctorList"})
    public @ResponseBody
    BaseResponse getDoctorList(@RequestParam(name = "hospitalId") int hospitalId,
                               @RequestParam(name = "deptCode", required = false,defaultValue = "") String deptCode,
                               @RequestParam(name = "doctorName", required = false) String doctorName) {
        BaseResponse response = new BaseResponse();

//        if (hospitalId != 12) {
//            return response.failed(BaseResponse.PARAMETER_ERROR, "医院不存在");
//        }

        if (StringHelper.isNullOrWhiteSpace(doctorName)) {
            doctorName = "";
        }

        try {
            GetDoctorListRequest getDoctorListRequest = GetDoctorListRequest.newBuilder()
                    .setDeptCode(deptCode)
                    .setDoctorName(doctorName)
                    .setHospitalId(BizUtil.getHospitalIdByTerminalId(BizUtil.getCurrentTerminalWrapped()))
                    .build();
            GetDoctorListResponse getDoctorListResponse = taiheServiceBlockingStub.getDoctorList(getDoctorListRequest);

            if (getDoctorListResponse.getCode() == ResultCode.SUCCEED_VALUE) {
                List<Doctor> doctorsList = getDoctorListResponse.getDoctorsList();
                List<Map<String, Object>> doctorList = new LinkedList<>();

                for (Doctor doctor : doctorsList) {

                    Map<String, Object> doctorMap = new LinkedHashMap<>();
                    doctorMap.put("doctorCode", doctor.getDoctorCode());        //医生代码
                    doctorMap.put("doctorName", doctor.getDoctorName());        //医生名称
                    doctorMap.put("doctorTitle", doctor.getDoctorTitle());      //医生职称
                    doctorMap.put("doctorSpeciality", doctor.getDoctorSpeciality());    //医生擅长
                    doctorMap.put("doctorIntro", doctor.getDoctorIntro());              //医生简介
                    doctorMap.put("deptName", doctor.getDoctorDept());                //医生科室
                    doctorMap.put("deptCode", doctor.getDoctorDeptCode());        //医生科室代码

                    doctorList.add(doctorMap);
                }

                Map<String, Object> map = new LinkedHashMap<>();
                map.put("hospitalId", hospitalId);
                map.put("count", getDoctorListResponse.getCount());
                map.put("list", doctorList);
                response.setData(map);
                return response.succeed("处理成功");
            }

            return response.failed(BaseResponse.APP_ERROR, getDoctorListResponse.getMsg());
        } catch (Exception e) {
            logger.error("getDoctorList():{}", e.getMessage());
            return response.failed(BaseResponse.APP_EXCEPTION, Constant.ERROR_PROMPT);
        }
    }

    /**
     * 得到排班记录
     *
     * @param hospitalId
     * @param deptCode
     * @param doctorCode
     * @param serviceDate
     * @return
     */
    @UserLogin(need = false)
    @RequestMapping({"/schedule"})
    public @ResponseBody
    BaseResponse getScheduleList(@RequestParam(name = "hospitalId") int hospitalId,
                                 @RequestParam(name = "deptCode",defaultValue = "") String deptCode,
                                 @RequestParam(name = "doctorCode", required = false, defaultValue = "") String doctorCode,
                                 @RequestParam(name = "serviceDate", required = false) String serviceDate) {
        BaseResponse response = new BaseResponse();

//        if (hospitalId != 12) {
//            return response.failed(BaseResponse.PARAMETER_ERROR, "医院不存在");
//        }

        try {
            List<Map<String, Object>> lst = new LinkedList<>();
            Calendar calendar = Calendar.getInstance();

            for (int offset = 0; offset < 8; offset++) {
                calendar.add(Calendar.DATE, 1);     //不包括今天

                String strDate = DateUtil.formatDate(calendar.getTime(), "yyyy-MM-dd"); //日期

                Map<String, Object> groupMap = new HashMap<>();
                groupMap.put("serviceDate", strDate);
                groupMap.put("offset", offset);
                groupMap.put("week", DateUtil.getDayOfWeekShort(calendar));

                GetScheduleListRequest getScheduleListRequest = GetScheduleListRequest.newBuilder()
                        .setDeptCode(deptCode)
                        .setDoctorCode(doctorCode)
                        .setServiceDate(strDate)
                        .setHospitalId(BizUtil.getHospitalIdByTerminalId(BizUtil.getCurrentTerminalWrapped()))
                        .build();
                GetScheduleListResponse getScheduleListResponse = taiheServiceBlockingStub.getScheduleList(getScheduleListRequest);

                if (getScheduleListResponse.getCode() == ResultCode.SUCCEED_VALUE) {
                    List<Schedule> scheduleList = getScheduleListResponse.getSchedulesList();
                    boolean hasScheduling = scheduleList.size() > 0;    //当期日期是否有排班

                    List<Map<String, Object>> forenoonList = new LinkedList<>();
                    List<Map<String, Object>> afternoonList = new LinkedList<>();
                    List<Map<String, Object>> nightList = new LinkedList<>();

                    for (Schedule s : scheduleList) {
                        Map<String, Object> scheduleMap = new HashMap<>();
                        scheduleMap.put("scheduleItemCode", s.getScheduleItemCode());       //门诊排班项记录标识
                        scheduleMap.put("serviceDate", s.getServiceDate());                 //门诊排班日期(yyyy-MM-dd)
                        scheduleMap.put("datePeriod", s.getDatePeriod());           //排班时段代码
                        scheduleMap.put("datePeriodName", s.getDatePeriodName());   //排班时段名称
                        scheduleMap.put("deptCode", s.getDeptCode());               //科室代码
                        scheduleMap.put("deptName", s.getDeptName());               //科室名称
                        scheduleMap.put("doctorCode", s.getDoctorCode());           //医生代码
                        scheduleMap.put("doctorName", s.getDoctorName());           //医生名称
                        scheduleMap.put("avatar", s.getAvatar());                   //医生图片链接
                        scheduleMap.put("doctorTitle", s.getDoctorTitle());         //医生职称
                        scheduleMap.put("doctorSpec", s.getDoctorSpec());           //医生专长
                        scheduleMap.put("fee", s.getFee());                         //预约挂号总费用
                        scheduleMap.put("regFee", s.getRegFee());                   //挂号费
                        scheduleMap.put("checkupFee", s.getCheckupFee());           //诊查费
                        scheduleMap.put("serviceFee", s.getServiceFee());           //服务费
                        scheduleMap.put("otherFee", s.getOtherFee());               //其它费
                        scheduleMap.put("admitAddress", s.getAdmitAddress());       //就诊地址
//                        scheduleMap.put("availableNumStr", s.getAvailableNumStr());
//                        scheduleMap.put("admitTimeRange", s.getAdmitTimeRange());
//                        scheduleMap.put("note", s.getNote());
//                        scheduleMap.put("startTime", s.getStartTime());
//                        scheduleMap.put("endTime", s.getEndTime());
//                        scheduleMap.put("timeRangeFlag", s.getTimeRangeFlag());
                        scheduleMap.put("scheduleStatus", s.getScheduleStatus());       //出诊状态（1-可预约 0-已满 2-停诊 3-其它(不可预约)）
                        scheduleMap.put("availableTotalNum", s.getAvailableTotalNum()); //该时段可预约的总号源数
                        scheduleMap.put("availableLeftNum", s.getAvailableLeftNum());   //该时段剩余号源数

                        String statusName = "";

                        switch (s.getScheduleStatus()) {
                            case 1:
                                statusName = "可预约";
                                break;
                            case 0:
                                statusName = "已满";
                                break;
                            case 2:
                                statusName = "停诊";
                                break;
                            default:
                                statusName = "停诊";
                                break;
                        }

                        scheduleMap.put("scheduleStatusName", statusName);

                        switch (s.getDatePeriod()) {
                            case 2:
                                forenoonList.add(scheduleMap);
                                break;
                            case 3:
                                afternoonList.add(scheduleMap);
                                break;
                            case 4:
                                nightList.add(scheduleMap);
                                break;
                        }
                    }

                    groupMap.put("hasScheduling", hasScheduling ? 1 : 0);   //当期日期是否有排班
                    groupMap.put("forenoonSchedules", forenoonList);        //上午排班记录
                    groupMap.put("afternoonSchedules", afternoonList);      //下午排班记录
                    groupMap.put("nightSchedules", nightList);              //晚上排班记录
                }

                lst.add(groupMap);
            }

            Map<String, Object> map = new HashMap<>();
            map.put("hospitalId", hospitalId);
            map.put("deptCode", deptCode);
            map.put("hospitalName", BizUtil.getHospitalNameByIdSimply(hospitalId));
            map.put("deptName", deptCode);
            map.put("list", lst);

            response.setData(map);
            return response.succeed("处理成功");

        } catch (Exception e) {
            logger.error("getScheduleList(){}", e.getMessage());
            return response.failed(BaseResponse.APP_EXCEPTION, Constant.ERROR_PROMPT);
        }
    }


    /**
     * 得到今日排班记录
     *
     * @param hospitalId
     * @param deptCode
     * @param doctorCode
     * @return
     */
    @UserLogin(need = false)
    @RequestMapping({"/todaySchedule"})
    public @ResponseBody
    BaseResponse getTodayScheduleList(@RequestParam(name = "hospitalId") int hospitalId,
                                      @RequestParam(name = "deptCode",defaultValue = "") String deptCode,
                                      @RequestParam(name = "doctorCode", required = false, defaultValue = "") String doctorCode) {
        BaseResponse response = new BaseResponse();

//        if (hospitalId != 12) {
//            return response.failed(BaseResponse.PARAMETER_ERROR, "医院不存在");
//        }

        try {
            List<Map<String, Object>> lst = new LinkedList<>();
            Calendar calendar = Calendar.getInstance();

//            for (int offset = 0; offset < 8; offset++) {

            String strDate = DateUtil.formatDate(calendar.getTime(), "yyyy-MM-dd"); //日期

            Map<String, Object> groupMap = new HashMap<>();
            groupMap.put("serviceDate", strDate);
//                groupMap.put("offset", offset);
            groupMap.put("week", DateUtil.getDayOfWeekShort(calendar));

            GetScheduleListRequest getScheduleListRequest = GetScheduleListRequest.newBuilder()
                    .setDeptCode(deptCode)
                    .setDoctorCode(doctorCode)
                    .setServiceDate(strDate)
                    .setHospitalId(BizUtil.getHospitalIdByTerminalId(BizUtil.getCurrentTerminalWrapped()))
                    .build();
            GetScheduleListResponse getScheduleListResponse = taiheServiceBlockingStub.getScheduleList(getScheduleListRequest);

            if (getScheduleListResponse.getCode() == ResultCode.SUCCEED_VALUE) {
                List<Schedule> scheduleList = getScheduleListResponse.getSchedulesList();
                boolean hasScheduling = scheduleList.size() > 0;    //当期日期是否有排班

                List<Map<String, Object>> forenoonList = new LinkedList<>();
                List<Map<String, Object>> afternoonList = new LinkedList<>();
                List<Map<String, Object>> nightList = new LinkedList<>();

                for (Schedule s : scheduleList) {
                    Map<String, Object> scheduleMap = new HashMap<>();
                    scheduleMap.put("scheduleItemCode", s.getScheduleItemCode());       //门诊排班项记录标识
                    scheduleMap.put("serviceDate", s.getServiceDate());                 //门诊排班日期(yyyy-MM-dd)
                    scheduleMap.put("datePeriod", s.getDatePeriod());           //排班时段代码
                    scheduleMap.put("datePeriodName", s.getDatePeriodName());   //排班时段名称
                    scheduleMap.put("deptCode", s.getDeptCode());               //科室代码
                    scheduleMap.put("deptName", s.getDeptName());               //科室名称
                    scheduleMap.put("doctorCode", s.getDoctorCode());           //医生代码
                    scheduleMap.put("doctorName", s.getDoctorName());           //医生名称
                    scheduleMap.put("avatar", s.getAvatar());                   //医生图片链接
                    scheduleMap.put("doctorTitle", s.getDoctorTitle());         //医生职称
                    scheduleMap.put("doctorSpec", s.getDoctorSpec());           //医生专长
                    scheduleMap.put("fee", s.getFee());                         //预约挂号总费用
                    scheduleMap.put("regFee", s.getRegFee());                   //挂号费
                    scheduleMap.put("checkupFee", s.getCheckupFee());           //诊查费
                    scheduleMap.put("serviceFee", s.getServiceFee());           //服务费
                    scheduleMap.put("otherFee", s.getOtherFee());               //其它费
                    scheduleMap.put("admitAddress", s.getAdmitAddress());       //就诊地址
//                        scheduleMap.put("availableNumStr", s.getAvailableNumStr());
//                        scheduleMap.put("admitTimeRange", s.getAdmitTimeRange());
//                        scheduleMap.put("note", s.getNote());
//                        scheduleMap.put("startTime", s.getStartTime());
//                        scheduleMap.put("endTime", s.getEndTime());
//                        scheduleMap.put("timeRangeFlag", s.getTimeRangeFlag());
                    scheduleMap.put("scheduleStatus", s.getScheduleStatus());       //出诊状态（1-可预约 0-已满 2-停诊 3-其它(不可预约)）
                    scheduleMap.put("availableTotalNum", s.getAvailableTotalNum()); //该时段可预约的总号源数
                    scheduleMap.put("availableLeftNum", s.getAvailableLeftNum());   //该时段剩余号源数

                    String statusName = "";

                    switch (s.getScheduleStatus()) {
                        case 1:
                            statusName = "可预约";
                            break;
                        case 0:
                            statusName = "已满";
                            break;
                        case 2:
                            statusName = "停诊";
                            break;
                        default:
                            statusName = "停诊";
                            break;
                    }

                    scheduleMap.put("scheduleStatusName", statusName);

                    switch (s.getDatePeriod()) {
                        case 2:
                            forenoonList.add(scheduleMap);
                            break;
                        case 3:
                            afternoonList.add(scheduleMap);
                            break;
                        case 4:
                            nightList.add(scheduleMap);
                            break;
                    }
                }

                groupMap.put("hasScheduling", hasScheduling ? 1 : 0);   //当期日期是否有排班
                groupMap.put("forenoonSchedules", forenoonList);        //上午排班记录
                groupMap.put("afternoonSchedules", afternoonList);      //下午排班记录
                groupMap.put("nightSchedules", nightList);              //晚上排班记录
            }

            lst.add(groupMap);
//            }

            Map<String, Object> map = new HashMap<>();
            map.put("hospitalId", hospitalId);
            map.put("deptCode", deptCode);
            map.put("hospitalName", BizUtil.getHospitalNameByIdSimply(hospitalId));
            map.put("deptName", deptCode);
            map.put("list", lst);

            response.setData(map);
            return response.succeed("处理成功");

        } catch (Exception e) {
            logger.error("getScheduleList(){}", e.getMessage());
            return response.failed(BaseResponse.APP_EXCEPTION, Constant.ERROR_PROMPT);
        }
    }

    /**
     * 得到医生分时排班信息
     *
     * @param hospitalId
     * @param deptCode
     * @param doctorCode
     * @param serviceDate
     * @param period
     * @return
     */
    @UserLogin(need = false)
    @RequestMapping({"/doctorSchedule"})
    public @ResponseBody
    BaseResponse getDoctorScheduleList(@RequestParam(name = "hospitalId") int hospitalId,
                                       @RequestParam(name = "deptCode") String deptCode,
                                       @RequestParam(name = "doctorCode") String doctorCode,
                                       @RequestParam(name = "serviceDate", required = false) String serviceDate,
                                       @RequestParam(name = "period", required = false) Integer period) {
        BaseResponse response = new BaseResponse();

//        if (hospitalId != 12) {
//            return response.failed(BaseResponse.PARAMETER_ERROR, "医院不存在");
//        }

        if (StringHelper.isNullOrWhiteSpace(deptCode)) {
            return response.failed(BaseResponse.PARAMETER_ERROR, "科室不存在");
        }

        if (StringHelper.isNullOrWhiteSpace(doctorCode)) {
            return response.failed(BaseResponse.PARAMETER_ERROR, "医生不存在");
        }

        List<Map<String, Object>> dataList = new LinkedList<>();

        if (!StringHelper.isNullOrWhiteSpace(serviceDate)) {
            //查询医生某一天的排班分时信息
            if (period == null) {
                return response.failed(BaseResponse.PARAMETER_ERROR, "请选择时段");
            }

            if (period != DatePeriodEnum.MORNING.getValue() && period != DatePeriodEnum.AFTERNOON.getValue() && period != DatePeriodEnum.NIGHT.getValue()) {
                return response.failed(BaseResponse.PARAMETER_ERROR, "时段不存在");
            }

            Map<String, Object> map = getScheduleTimeInfoResponse(deptCode + "", doctorCode + "", serviceDate, period);

            if (map != null) {
                dataList.add(map);
            }
        } else {
            //取医生8天排班的分时信息
            int[] periods = {DatePeriodEnum.MORNING.getValue(), DatePeriodEnum.AFTERNOON.getValue(), DatePeriodEnum.NIGHT.getValue()};
            Calendar calendar = Calendar.getInstance();

            for (int offset = 0; offset < 8; offset++) {
                calendar.add(Calendar.DATE, 1);
                String strDate = DateUtil.formatDate(calendar.getTime(), "yyyy-MM-dd");

                for (int p : periods) {
                    Map<String, Object> map = getScheduleTimeInfoResponse(deptCode + "", doctorCode + "", strDate, p);

                    if (map != null) {
                        dataList.add(map);
                    }
                }
            }
        }

        String deptName = "";
        String doctorName = "";
        String avatar = "";
        String doctorTitle = "";
        String doctorSpec = "";
        int fee = 0;
        int regFee = 0;
        int treatFee = 0;

        if (dataList.size() > 0) {
            Map<String, Object> map = dataList.get(0);
            String strDate = map.get("serviceDate").toString();
            GetScheduleListRequest getScheduleListRequest = GetScheduleListRequest.newBuilder()
                    .setDeptCode(deptCode)
                    .setDoctorCode(doctorCode)
                    .setServiceDate(strDate)
                    .setHospitalId(BizUtil.getHospitalIdByTerminalId(BizUtil.getCurrentTerminalWrapped()))
                    .build();
            GetScheduleListResponse getScheduleListResponse = taiheServiceBlockingStub.getScheduleList(getScheduleListRequest);

            if (getScheduleListResponse.getCode() == ResultCode.SUCCEED_VALUE) {
                List<Schedule> scheduleList = getScheduleListResponse.getSchedulesList();
                if (scheduleList.size() > 0) {
                    Schedule schedule = scheduleList.get(0);
                    deptName = schedule.getDeptName();
                    doctorName = schedule.getDoctorName();
                    avatar = schedule.getAvatar();
                    doctorTitle = schedule.getDoctorTitle();
                    doctorSpec = schedule.getDoctorSpec();
                    fee =  schedule.getFee();
                    regFee =  schedule.getRegFee();
                    treatFee =  schedule.getCheckupFee();
                }
            }
        }

        Map<String, Object> data = new HashMap<>();
        data.put("list", dataList);
        data.put("hospitalName", BizUtil.getHospitalNameByIdSimply(hospitalId));
        data.put("deptCode", deptCode);
        data.put("deptName", deptName);
        data.put("doctorCode", doctorCode);
        data.put("doctorName", doctorName);
        data.put("avatar", !Checker.isNone(avatar) ? avatar : Constant.DOCTOR_AVATAR_URL);
        data.put("doctorTitle", doctorTitle);
        data.put("doctorSpec", doctorSpec);
        data.put("fee", fee);
        data.put("regFee", regFee);
        data.put("treatFee", treatFee);
        data.put("doctorId", 10178);        //医生ID

        return response.succeed("处理成功", data);
    }


    /**
     * 得到分时排班信息
     *
     * @param deptCode
     * @param doctorCode
     * @param serviceDate
     * @param period
     * @return
     */
    private Map<String, Object> getScheduleTimeInfoResponse(String deptCode, String doctorCode, String serviceDate, int period) {
        List<Map<String, Object>> lst = new LinkedList<>();

        GetScheduleTimeInfoRequest getScheduleTimeInfoRequest = GetScheduleTimeInfoRequest.newBuilder()
                .setDeptCode(deptCode)
                .setDoctorCode(doctorCode)
                .setServiceDate(serviceDate)
                .setDatePeriod(period)
                .setHospitalId(BizUtil.getHospitalIdByTerminalId(BizUtil.getCurrentTerminalWrapped()))
                .build();
        GetScheduleTimeInfoResponse getScheduleTimeInfoResponse = taiheServiceBlockingStub.getScheduleTimeInfo(getScheduleTimeInfoRequest);

        if (getScheduleTimeInfoResponse.getCode() == ResultCode.SUCCEED_VALUE) {
            List<ScheduleTimeInfo> scheduleTimeInfoList = getScheduleTimeInfoResponse.getScheduleTimeInfosList();

            for (ScheduleTimeInfo scheduleTimeInfo : scheduleTimeInfoList) {

                Map<String, Object> map = new HashMap<>();
                map.put("scheduleItemCode", scheduleTimeInfo.getScheduleItemCode());
                map.put("startTime", scheduleTimeInfo.getStartTime());
                map.put("endTime", scheduleTimeInfo.getEndTime());
                map.put("availableTotalNum", scheduleTimeInfo.getAvailableTotalNum());
                map.put("availableLeftNum", scheduleTimeInfo.getAvailableLeftNum());
                map.put("availableFlag", scheduleTimeInfo.getAvailableFlag());

                lst.add(map);
            }
        }

        if (lst.size() > 0) {
            Map<String, Object> dateMap = new HashMap<>();
            dateMap.put("serviceDate", serviceDate);
            dateMap.put("period", period);
            dateMap.put("datePeriod", DatePeriodEnum.valueOf(period).getDisplayName());
            dateMap.put("schedule", lst);

            return dateMap;
        }

        return null;
    }

    /**
     * 创建预约挂号订单
     *
     * @param hospitalId       医院Id
     * @param deptCode         科室Code
     * @param deptName         科室名称
     * @param doctorCode       医生Code
     * @param doctorName       医生名称
     * @param registeredFee    挂号费
     * @param medicalFee       诊查费
     * @param registeredDate   预约日期
     * @param period           预约时间段
     * @param startTime        预约开始时间：HH:MI
     * @param endTime          预约结束时间：HH:MI
     * @param medicalCardId    就诊人Id
     * @param scheduleItemCode 门诊排班项记录标识
     * @return
     */
    @RequestMapping({"/createRegisteredOrder"})
    public @ResponseBody
    BaseResponse createRegisteredOrder(
            @RequestParam(name = "hospitalId") int hospitalId,
            @RequestParam(name = "deptCode") String deptCode,
            @RequestParam(name = "deptName") String deptName,
            @RequestParam(name = "doctorCode") String doctorCode,
            @RequestParam(name = "doctorName") String doctorName,
            @RequestParam(name = "registeredFee") double registeredFee,
            @RequestParam(name = "medicalFee") double medicalFee,
            @RequestParam(name = "registeredDate") String registeredDate,
            @RequestParam(name = "period") int period,
            @RequestParam(name = "startTime") String startTime,
            @RequestParam(name = "endTime") String endTime,
            @RequestParam(name = "medicalCardId") int medicalCardId,
            @RequestParam(name = "scheduleItemCode") String scheduleItemCode
//            ,@RequestParam(name = "paymentChannel") int paymentChannel
    ) {
        BaseResponse response = new BaseResponse();

        if (hospitalId < 1) {
            return response.failed(BaseResponse.PARAMETER_ERROR, "医院不存在");
        }

        if (StringHelper.isNullOrWhiteSpace(deptCode) || StringHelper.isNullOrWhiteSpace(deptName)) {
            return response.failed(BaseResponse.PARAMETER_ERROR, "科室不存在");
        }

        if (StringHelper.isNullOrWhiteSpace(doctorCode) || StringHelper.isNullOrWhiteSpace(doctorName)) {
            return response.failed(BaseResponse.PARAMETER_ERROR, "医生不存在");
        }

        if (StringHelper.isNullOrWhiteSpace(registeredDate)) {
            return response.failed(BaseResponse.PARAMETER_ERROR, "请选择挂号日期");
        }

        Date date;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        try {
            date = sdf.parse(registeredDate);
        } catch (ParseException e) {
            return response.failed(BaseResponse.PARAMETER_ERROR, "转入日期格式不正确");
        }

        if (period != DatePeriodEnum.MORNING.getValue() && period != DatePeriodEnum.AFTERNOON.getValue()) {
            return response.failed(BaseResponse.PARAMETER_ERROR, "预约时段不存在");
        }

        if (StringHelper.isNullOrWhiteSpace(startTime)) {
            return response.failed(BaseResponse.PARAMETER_ERROR, "预约开始时间不存在");
        }

        if (StringHelper.isNullOrWhiteSpace(endTime)) {
            return response.failed(BaseResponse.PARAMETER_ERROR, "预约结束时间不存在");
        }

        if (medicalCardId < 1) {
            return response.failed(BaseResponse.PARAMETER_ERROR, "请选择就诊人");
        }

        if (StringHelper.isNullOrWhiteSpace(scheduleItemCode)) {
            return response.failed(BaseResponse.PARAMETER_ERROR, "门诊排班项记录标识不能为空");
        }

//        if (paymentChannel != PaymentChannelEnum.Cash.getValue() && paymentChannel != PaymentChannelEnum.MedicalCard.getValue()) {
//            return response.failed(BaseResponse.PARAMETER_ERROR, "支付方式不正确");
//        }

        DatePeriodEnum datePeriodEnum = DatePeriodEnum.valueOf(period);

        if (datePeriodEnum == null) {
            return response.failed(BaseResponse.PARAMETER_ERROR, "预约时段不存在");
        }

        try {
            int source = TerminalEnum.TaiheWxOfficial.getValue();

            CreateTaiheRegisteredOrderRequest createTaiheRegisteredOrderRequest = CreateTaiheRegisteredOrderRequest.newBuilder()
                    .setHospitalId(hospitalId)
                    .setDeptCode(deptCode)
                    .setDeptName(deptName)
                    .setDoctorCode(doctorCode)
                    .setDoctorName(doctorName)
                    .setTotal((int) ((registeredFee + medicalFee) * 100))
                    .setRegisteredFee((int) (registeredFee * 100))
                    .setMedicalFee((int) (medicalFee * 100))
                    .setRegisteredDate(date.getTime())
                    .setStartTime(startTime)
                    .setEndTime(endTime)
                    .setUserId(userService.getCurrentUserIdWrapped())
                    .setMedicalCardId(medicalCardId)
                    .setScheduleItemCode(scheduleItemCode)
                    .setPaymentChannel(PaymentChannelEnum.MedicalCard.getValue())
                    .setSource(source)
                    .build();
            CreateTaiheRegisteredOrderResponse createTaiheRegisteredOrderResponse = orderServiceBlockingStub.createTaiheRegisteredOrder(createTaiheRegisteredOrderRequest);
            Result result = createTaiheRegisteredOrderResponse.getResult();

            if (result.getCode() == ResultCode.SUCCEED) {
                Map<String, Object> map = new HashMap<>();
                map.put("orderId", createTaiheRegisteredOrderResponse.getOrderId());
                map.put("orderType", createTaiheRegisteredOrderResponse.getOrderType());
                map.put("status", createTaiheRegisteredOrderResponse.getStatus());
                return response.succeed("处理成功",map);
            }

            return response.failed(BaseResponse.APP_ERROR, result.getInfo());
        } catch (Exception e) {
            logger.error("createTaiheRegisteredOrder():{}", e.getMessage());
            return response.failed(BaseResponse.APP_EXCEPTION, e.getMessage());
        }

    }

//    /**
//     * 预约挂号订单支付
//     *
//     * @param orderId
//     * @return
//     */
//    @RequestMapping({"/pay"})
//    public @ResponseBody
//    BaseResponse payOrder(@RequestParam(name = "orderId") int orderId) {
//        BaseResponse response = new BaseResponse();
//
//        if (orderId < 1) {
//            return response.failed(BaseResponse.PARAMETER_ERROR, "订单不存在");
//        }
//
//        try {
//            PayRegisteredOrderRequest payRegisteredOrderRequest = PayRegisteredOrderRequest.newBuilder()
//                    .setOrderId(orderId)
//                    .setUserId(userService.getCurrentUserId())
//                    .build();
//            PayRegisteredOrderResponse payRegisteredOrderResponse = orderServiceBlockingStub.payRegisteredOrder(payRegisteredOrderRequest);
//            Result result = payRegisteredOrderResponse.getResult();
//
//            if (result.getCode() == ResultCode.SUCCEED) {
//                return response.succeed("处理成功");
//            }
//
//            String info = result.getInfo();
//            if (!StringHelper.isNullOrWhiteSpace(info)) {
//                info = info.replaceAll(":", "");
//            }
//            return response.failed(BaseResponse.APP_ERROR, info);
//        } catch (Exception e) {
//            logger.error("payOrder(): {}", e.getMessage());
//            return response.error();
//        }
//    }

    /**
     * 在线取号
     *
     * @param orderId
     * @return
     */
    @RequestMapping({"/take"})
    public @ResponseBody
    BaseResponse takeOrder(@RequestParam(name = "orderId") int orderId) {
        BaseResponse response = new BaseResponse();

        if (orderId < 1) {
            return response.failed(BaseResponse.PARAMETER_ERROR, "订单不存在");
        }

        try {
            TakeTaiheRegisteredOrderRequest takelTaiheRegisteredOrderRequest = TakeTaiheRegisteredOrderRequest.newBuilder()
                    .setOrderId(orderId)
                    .setUserId(userService.getCurrentUserIdWrapped())
                    .build();
            TakeTaiheRegisteredOrderResponse resp = orderServiceBlockingStub.takeTaiheRegisteredOrder(takelTaiheRegisteredOrderRequest);

            if (resp.getResult().getCode() == ResultCode.SUCCEED) {
                Map<String, Object> map = new HashMap<>();
                map.put("registrationId", resp.getRegistrationId());

                return response.succeed("处理成功", map);
            }

            return response.failed(BaseResponse.APP_ERROR, response.getInfo());
        } catch (Exception e) {
            logger.error("cancelOrder(): {}", e.getMessage());
            return response.error();
        }
    }

    /**
     * 取消预约挂号订单
     *
     * @param orderId
     * @return
     */
    @RequestMapping({"/cancel"})
    public @ResponseBody
    BaseResponse cancelOrder(@RequestParam(name = "orderId") int orderId) {
        BaseResponse response = new BaseResponse();

        if (orderId < 1) {
            return response.failed(BaseResponse.PARAMETER_ERROR, "订单不存在");
        }

        try {
            CancelTaiheRegisteredOrderRequest cancelTaiheRegisteredOrderRequest = CancelTaiheRegisteredOrderRequest.newBuilder()
                    .setOrderId(orderId)
                    .setUserId(userService.getCurrentUserIdWrapped())
                    .build();
            ResultInt result = orderServiceBlockingStub.cancelTaiheRegisteredOrder(cancelTaiheRegisteredOrderRequest);

            if (result.getCode() == ResultCode.SUCCEED) {
                Map<String, Object> map = new HashMap<>();
                map.put("status", result.getValue());

                return response.succeed(result.getInfo(), map);
            }

            return response.failed(BaseResponse.APP_ERROR, response.getInfo());
        } catch (Exception e) {
            logger.error("cancelOrder(): {}", e.getMessage());
            return response.error();
        }
    }

//    /**
//     * 获取检验报告列表
//     *
//     * @param medicalCardId 诊疗卡Id
//     * @return
//     */
//    @RequestMapping({"/getreportlist"})
//    public @ResponseBody
//    BaseResponse getReportList(@RequestParam(name = "medicalCardId") int medicalCardId) {
//        BaseResponse response = new BaseResponse();
//        Map<String, Object> data = new LinkedHashMap<>();
//        List<Map<String, Object>> list = new LinkedList<>();
//
//        try {
//            GetLatestRegisteredOrderByMedicalCardIdRequest req =
//                    GetLatestRegisteredOrderByMedicalCardIdRequest.newBuilder()
//                            .setMedicalCardId(medicalCardId)
//                            .build();
//            GetLatestRegisteredOrderByMedicalCardIdResponse res = orderServiceBlockingStub.getLatestRegisteredOrderByMedicalCardId(req);
//            Result result = res.getResult();
//            RegisteredOrder order = res.getOrder();
//
//            if (result.getCode() == ResultCode.SUCCEED && order != null && !StringHelper.isNullOrWhiteSpace(order.getHisClinicCode())) {
//                int clinicCode = Checker.parseInt(order.getHisClinicCode());
//
//                GetReportListRequest getReportListRequest = GetReportListRequest.newBuilder()
//                        .setClinicSeq(clinicCode)
//                        .build();
//                GetReportListResponse getReportListResponse = nfyyServiceBlockingStub.getReportList(getReportListRequest);
//
//                if (getReportListResponse.getCode() == ResultCode.SUCCEED_VALUE) {
//                    List<Report> reports = getReportListResponse.getReportList();
//
//                    for (Report report : reports) {
//                        Map<String, Object> reportMap = new LinkedHashMap<>();
//                        reportMap.put("checkDoctorName", report.getCheckDoctorName());
//                        reportMap.put("clinicalDiagnosis", report.getClinicalDiagnosis());
//                        reportMap.put("clinicSeq", report.getClinicSeq());
//                        reportMap.put("deptName", report.getDeptName());
//                        reportMap.put("gender", report.getGender());
//                        reportMap.put("inpatientId", report.getInpatientId());
//                        reportMap.put("inspectionDate", report.getInspectionDate());
//                        reportMap.put("inspectionId", report.getInspectionId());
//                        reportMap.put("inspectionName", report.getInspectionName());
//                        reportMap.put("patientAge", report.getPatientAge());
//                        reportMap.put("patientName", report.getPatientName());
//                        reportMap.put("reportDoctorName", report.getReportDoctorName());
//                        reportMap.put("status", report.getStatus());
//                        list.add(reportMap);
//                    }
//
//                    data.put("count", list.size());
//                    data.put("list", list);
//
//                    return response.succeed("处理成功", data);
//                }
//            }
//
//            data.put("count", list.size());
//            data.put("list", list);
//
//            return response.succeed("处理成功", data);
//        } catch (Exception e) {
//            logger.error("getReportList(): {}", e.getMessage(), e);
//            return response.error();
//        }
//    }
//
//    /**
//     * 获取检验报告详情
//     *
//     * @param inspectionId
//     * @return
//     */
//    @RequestMapping({"/getreportdetail"})
//    public @ResponseBody
//    BaseResponse getReportDetail(@RequestParam(name = "inspectionId") String inspectionId) {
//        BaseResponse response = new BaseResponse();
//
//        try {
//            GetReportDetailRequest getReportDetailRequest = GetReportDetailRequest.newBuilder().setInspectionId(inspectionId).build();
//            GetReportDetailResponse getReportDetailResponse = nfyyServiceBlockingStub.getReportDetail(getReportDetailRequest);
//
//            if (getReportDetailResponse.getCode() == BaseResponse.SUCCEED) {
//                List<Map<String, Object>> list = new LinkedList<>();
//                List<ReportDetail> details = getReportDetailResponse.getReportDetailListList();
//
//                for (ReportDetail data : details) {
//                    Map<String, Object> itemMap = new LinkedHashMap<>();
//                    itemMap.put("itemId", data.getItemId());
//                    itemMap.put("itemName", data.getItemName());
//                    itemMap.put("itemRef", data.getItemRef());
//                    itemMap.put("orderNo", data.getOrderNo());
//                    itemMap.put("resultFlag", data.getResultFlag());
//                    itemMap.put("specimType", data.getSpecimType());
//                    itemMap.put("testDate", data.getTestDate());
//                    itemMap.put("testEngName", data.getTestEngName());
//                    itemMap.put("testResult", data.getTestResult());
//                    itemMap.put("unit", data.getUnit());
//                    list.add(itemMap);
//                }
//
//                Map<String, Object> data = new LinkedHashMap<>();
//                data.put("count", list.size());
//                data.put("list", list);
//
//                return response.succeed("处理成功", data);
//            }
//
//            return response.failed(BaseResponse.APP_ERROR, getReportDetailResponse.getMsg());
//        } catch (Exception e) {
//            logger.error("getReportDetail(): {}", e.getMessage());
//            return response.error();
//        }
//    }
//
//    /**
//     * 获取排队信息
//     *
//     * @param clinicCode 就诊号
//     * @return
//     */
//    @RequestMapping({"/getqueueinfo"})
//    public @ResponseBody
//    BaseResponse getQueueInfo(@RequestParam(name = "clinicCode") int clinicCode) {
//        BaseResponse response = new BaseResponse();
//
//        try {
//            GetQueueInfoRequest getQueueInfoRequest = GetQueueInfoRequest.newBuilder().setAdmNo(clinicCode).build();
//            GetQueueInfoResponse getQueueInfoResponse = nfyyServiceBlockingStub.getQueueInfo(getQueueInfoRequest);
//
//            if (getQueueInfoResponse.getCode() == ResultCode.SUCCEED_VALUE) {
//                QueueInfo data = getQueueInfoResponse.getQueueInfo();
//                Map<String, Object> itemMap = new LinkedHashMap<>();
//                itemMap.put("admDoc", data.getAdmDoc());
//                itemMap.put("admLoc", data.getAdmLoc());
//                itemMap.put("patName", data.getPatName());
//                itemMap.put("waitingNumber", data.getWaitingNumber());
//
//                return response.succeed("处理成功", itemMap);
//            }
//
//            return response.failed(BaseResponse.APP_ERROR, getQueueInfoResponse.getMsg());
//        } catch (Exception e) {
//            logger.error("getQueueInfo(): {}", e.getMessage());
//            return response.error();
//        }
//    }
//
//    @RequestMapping({"/getClinicInfo"})
//    public @ResponseBody
//    BaseResponse getClinicInfo(@RequestParam(name = "admNo") int admNo) {
//        BaseResponse response = new BaseResponse();
//        try {
//            GetClinicInfoRequest getClinicInfoRequest = GetClinicInfoRequest.newBuilder().setAdmNo(admNo).build();
//            GetClinicInfoResponse getClinicInfoResponse = nfyyServiceBlockingStub.getClinicInfo(getClinicInfoRequest);
//
//            if (getClinicInfoResponse.getCode() == BaseResponse.SUCCEED) {
//                ClinicInfo data = getClinicInfoResponse.getClinicInfo();
//                Map<String, Object> itemMap = new LinkedHashMap<>();
//                itemMap.put("admDoc", data.getAdmDoc());
//                itemMap.put("admLoc", data.getAdmLoc());
//                itemMap.put("admitDate", data.getAdmitDate());
//                itemMap.put("diagnosis", data.getDiagnosis());
//                itemMap.put("patientID", data.getPatientID());
//
//                return response.succeed("处理成功", itemMap);
//            }
//            return response.failed(BaseResponse.APP_ERROR, getClinicInfoResponse.getMsg());
//        } catch (Exception e) {
//            logger.error("getClinicInfo(): {}", e.getMessage());
//            return response.error();
//        }
//    }
//
//    /**
//     * 获取病历详情
//     *
//     * @param clinicCode 就诊号
//     * @return
//     */
//    @RequestMapping({"/getmedicalrecorddetail"})
//    public @ResponseBody
//    BaseResponse getMedicalRecordDetail(@RequestParam(name = "clinicCode") String clinicCode) {
//        BaseResponse response = new BaseResponse();
//
//        try {
//            GetMedicalRecordByClinicCodeRequest req = GetMedicalRecordByClinicCodeRequest.newBuilder()
//                    .setClinicCode(clinicCode).build();
//            GetMedicalRecordByClinicCodeResponse res = userServiceBlockingStub.getMedicalRecordByClinicCode(req);
//            Result result = res.getResult();
//
//            if (result.getCode() == ResultCode.SUCCEED) {
//                MedicalRecordsDetail detail = res.getDetail();
//
//                Map<String, Object> data = new HashMap<>();
//                data.put("admTime", detail.getAdmTime());
//                data.put("hospitalName", detail.getHospitalName());
//                data.put("doctorName", detail.getDoctorName());
//                data.put("patientName", detail.getPatientName());
//                data.put("selfReport", detail.getSelfReport());
//                data.put("phyExam", detail.getPhyExam());
//                data.put("diagnose", detail.getDiagnose());
//                data.put("suggestion", detail.getSuggestion());
//                data.put("advice", detail.getAdvice());           //医嘱
//
//                List<Map<String, Object>> laboratoryReportList = new LinkedList<>();
//                List<Map<String, Object>> inspectionReportList = new LinkedList<>();
//
//                if (detail.getLaboratoryReportList() != null) {
//                    for (com.ywt.gapi.user.LaboratoryReport report : detail.getLaboratoryReportList()) {
//                        Map<String, Object> item = new HashMap<>();
//                        item.put("id", report.getId());
//                        item.put("title", report.getInspectionName());
//                        item.put("inspectionId", report.getInspectionId());
//                        item.put("reportDate", DateUtil.convertTimestampToDateString(report.getInspectionDate(), "yyyy年MM月dd日"));
//
//                        laboratoryReportList.add(item);
//                    }
//                }
//
//                if(detail.getInspectionReportList() != null){
//                    for(com.ywt.gapi.user.InspectionReport report : detail.getInspectionReportList()){
//                        Map<String, Object> map = new HashMap<>();
//                        map.put("id", report.getId());
//                        map.put("title", report.getReportTitle());
//                        map.put("reportId", report.getReportId());
//                        map.put("reportDate", DateUtil.convertTimestampToDateString(report.getReportDate(), "yyyy年MM月dd日"));
//
//                        inspectionReportList.add(map);
//                    }
//                }
//
//                data.put("laboratoryReportList", laboratoryReportList);
//                data.put("inspectionReportList", inspectionReportList);
//
//                return response.succeed(data);
//            }
//
//            return response.failed(BaseResponse.APP_ERROR, result.getInfo());
//        } catch (Exception e) {
//            logger.error("getMedicalRecordDetail({}): {}", clinicCode, e.getMessage(), e);
//            return response.error();
//        }
//    }
//
//    /**
//     * 获取门诊病历列表
//     *
//     * @param medicalCardId 就诊卡Id
//     * @param pageIndex     页码
//     * @param pageSize      页大小
//     * @return
//     */
//    @RequestMapping({"/medicalrecordlist"})
//    public @ResponseBody
//    BaseResponse getMedicalRecordsList(@RequestParam(name = "medicalCardId") int medicalCardId,
//                                       @RequestParam(name = "pageIndex") int pageIndex,
//                                       @RequestParam(name = "pageSize") int pageSize) {
//        BaseResponse response = new BaseResponse();
//
//        if (pageIndex < 1) {
//            return response.failed(BaseResponse.PARAMETER_ERROR, "页码错误");
//        }
//
//        if (pageSize < 1) {
//            return response.failed(BaseResponse.PARAMETER_ERROR, "页大小错误");
//        }
//
//        try {
//            GetMedicalRecordsListRequest req = GetMedicalRecordsListRequest.newBuilder()
//                    .setPageIndex(pageIndex)
//                    .setPageSize(pageSize)
//                    .setMedicalCardId(medicalCardId)
//                    .setUserId(userService.getCurrentUserId())
//                    .build();
//            GetMedicalRecordsListResponse resp = userServiceBlockingStub.getMedicalRecordsList(req);
//            Result result = resp.getResult();
//
//            if (result.getCode() == ResultCode.SUCCEED) {
//                List<Map<String, Object>> lst = new LinkedList<>();
//
//                for (MedicalRecords records : resp.getRecordsList()) {
//                    Map<String, Object> map = new HashMap<>();
//                    map.put("admTime", records.getAdmTime());
//                    map.put("clinicCode", records.getClinicCode());
//                    map.put("hospitalName", records.getHospitalName());
//                    map.put("doctorName", records.getDoctorName());
//                    map.put("doctorTitle", records.getDoctorTitle());
//
//                    lst.add(map);
//                }
//
//                Map<String, Object> map = new HashMap<>();
//                map.put("count", resp.getCount());
//                map.put("totalPages", resp.getTotalPages());
//                map.put("list", lst);
//
//                return response.succeed("处理成功", map);
//            }
//
//            return response.failed(BaseResponse.APP_ERROR, result.getInfo());
//        } catch (Exception e) {
//            logger.error("getMedicalRecordsList(): {}", e.getMessage(), e);
//            return response.error();
//        }
//    }
//
//    /**
//     * 获取检查结果报告列表
//     *
//     * @param medicalCardId
//     * @return
//     */
//    @RequestMapping({"/getInspectionReportList"})
//    public @ResponseBody
//    BaseResponse getInspectionReportList(@RequestParam(name = "medicalCardId") int medicalCardId) {
//        BaseResponse response = new BaseResponse();
//        List<Map<String, Object>> lst = new LinkedList<>();
//
//        if (medicalCardId < 0) {
//            return response.failed(BaseResponse.PARAMETER_ERROR, "诊疗卡Id不存在");
//        }
//
//        try {
//            com.ywt.gapi.user.GetInspectionReportListRequest req = com.ywt.gapi.user.GetInspectionReportListRequest.newBuilder()
//                    .setMedicalCardId(medicalCardId)
//                    .setUserId(userService.getCurrentUserId())
//                    .build();
//            com.ywt.gapi.user.GetInspectionReportListResponse res = userServiceBlockingStub.getInspectionReportList(req);
//            Result result = res.getResult();
//
//            if (result.getCode() == ResultCode.SUCCEED) {
//                for (com.ywt.gapi.user.InspectionReport report : res.getReportList()) {
//                    Map<String, Object> map = new HashMap<>();
//                    map.put("id", report.getId());
//                    map.put("title", report.getReportTitle());
//                    map.put("reportId", report.getReportId());
//                    map.put("reportDate", DateUtil.convertTimestampToDateString(report.getReportDate(), "yyyy年MM月dd日"));
//
//                    lst.add(map);
//                }
//
//                Map<String, Object> data = new HashMap<>();
//                data.put("list", lst);
//                return response.succeed(data);
//            }
//
//            return response.failed(BaseResponse.APP_ERROR, result.getInfo());
//        } catch (Exception e) {
//            logger.error("getInspectionReportList({}): {}", medicalCardId, e.getMessage(), e);
//            return response.error();
//        }
//    }
//
//    /**
//     * 获取检查结果报告详情
//     *
//     * @param reportId
//     * @return
//     */
//    @RequestMapping({"/getInspectionReportDetail"})
//    public @ResponseBody
//    BaseResponse getInspectionReportDetail(@RequestParam(name = "reportId") String reportId) {
//        BaseResponse response = new BaseResponse();
//
//        if (StringHelper.isNullOrWhiteSpace(reportId)) {
//            return response.failed(BaseResponse.PARAMETER_ERROR, "参数错误");
//        }
//
//        try {
//            com.ywt.gapi.user.GetInspectionReportDetailRequest req = com.ywt.gapi.user.GetInspectionReportDetailRequest.newBuilder()
//                    .setReportId(reportId)
//                    .build();
//            com.ywt.gapi.user.GetInspectionReportDetailResponse res = userServiceBlockingStub.getInspectionReportDetail(req);
//            Result result = res.getResult();
//
//            if (result.getCode() == ResultCode.SUCCEED) {
//                com.ywt.gapi.user.InspectionReportDetail detail = res.getReport();
//                Map<String, Object> map = new HashMap<>();
//
//                map.put("Id", detail.getId());
//                map.put("reportId", detail.getReportId());
//                map.put("deptName", detail.getDeptName());
//                map.put("appDocName", detail.getAppDocName());
//                map.put("checkParts", detail.getCheckParts());
//                map.put("examination", detail.getExamination());
//                map.put("diagnosis", detail.getDiagnosis());
//                map.put("checkDoctorName", detail.getCheckDoctorName());
//                map.put("examinationDate", DateUtil.convertTimestampToDateString(detail.getExaminationDate(), "yyyy年MM月dd日 HH:mm:ss"));
//
//                return response.succeed(map);
//            }
//
//            return response.failed(BaseResponse.APP_ERROR, result.getInfo());
//        } catch (Exception e) {
//            logger.error("getInspectionReportDetail({}): {}", reportId, e.getMessage(), e);
//            return response.error();
//        }
//    }
//
//    /**
//     * 获取化验结果报告列表
//     *
//     * @param medicalCardId
//     * @return
//     */
//    @RequestMapping({"/getLaboratoryReportList"})
//    public @ResponseBody
//    BaseResponse getLaboratoryReportList(@RequestParam(name = "medicalCardId") int medicalCardId) {
//        BaseResponse response = new BaseResponse();
//        List<Map<String, Object>> lst = new LinkedList<>();
//
//        if (medicalCardId < 0) {
//            return response.failed(BaseResponse.PARAMETER_ERROR, "诊疗卡Id不存在");
//        }
//
//        try {
//            com.ywt.gapi.user.GetLaboratoryReportListRequest req = com.ywt.gapi.user.GetLaboratoryReportListRequest.newBuilder()
//                    .setMedicalCardId(medicalCardId)
//                    .setUserId(userService.getCurrentUserId())
//                    .build();
//            com.ywt.gapi.user.GetLaboratoryReportListResponse res = userServiceBlockingStub.getLaboratoryReportList(req);
//            Result result = res.getResult();
//
//            if (result.getCode() == ResultCode.SUCCEED) {
//                for (com.ywt.gapi.user.LaboratoryReport report : res.getReportList()) {
//                    Map<String, Object> map = new HashMap<>();
//                    map.put("id", report.getId());
//                    map.put("title", report.getInspectionName());
//                    map.put("inspectionId", report.getInspectionId());
//                    map.put("reportDate", DateUtil.convertTimestampToDateString(report.getInspectionDate(), "yyyy年MM月dd日"));
//
//                    lst.add(map);
//                }
//
//                Map<String, Object> data = new HashMap<>();
//                data.put("list", lst);
//                return response.succeed(data);
//            }
//
//            return response.failed(BaseResponse.APP_ERROR, result.getInfo());
//        } catch (Exception e) {
//            logger.error("getLaboratoryReportList({}): {}", medicalCardId, e.getMessage(), e);
//            return response.error();
//        }
//    }
//
//    /**
//     * 获取检查结果报告详情
//     *
//     * @param inspectionId
//     * @return
//     */
//    @RequestMapping({"/getLaboratoryReportDetail"})
//    public @ResponseBody
//    BaseResponse getLaboratoryReportDetail(@RequestParam(name = "inspectionId") String inspectionId) {
//        BaseResponse response = new BaseResponse();
//
//        if (StringHelper.isNullOrWhiteSpace(inspectionId)) {
//            return response.failed(BaseResponse.PARAMETER_ERROR, "参数错误");
//        }
//
//        try {
//            com.ywt.gapi.user.GetLaboratoryReportDetailRequest req = com.ywt.gapi.user.GetLaboratoryReportDetailRequest.newBuilder()
//                    .setInspectionId(inspectionId)
//                    .build();
//            com.ywt.gapi.user.GetLaboratoryReportDetailResponse res = userServiceBlockingStub.getLaboratoryReportDetail(req);
//            Result result = res.getResult();
//
//            if (result.getCode() == ResultCode.SUCCEED) {
//                List<Map<String, Object>> lst = new LinkedList<>();
//
//                for (com.ywt.gapi.user.LaboratoryReportDetail detail : res.getDetailList()) {
//                    Map<String, Object> itemMap = new LinkedHashMap<>();
//                    itemMap.put("itemId", detail.getItemId());
//                    itemMap.put("itemName", detail.getItemName());
//                    itemMap.put("itemRef", detail.getItemRef());
//                    itemMap.put("orderNo", detail.getOrderNo());
//                    itemMap.put("resultFlag", detail.getResultFlag());
//                    itemMap.put("specimType", detail.getSpecimType());
//                    itemMap.put("testDate", DateUtil.convertTimestampToDateString(detail.getTestDate(), "yyyy-MM-dd HH:mm:ss"));
//                    itemMap.put("testEngName", detail.getTestEngName());
//                    itemMap.put("testResult", detail.getTestResult());
//                    itemMap.put("unit", detail.getUnit());
//                    lst.add(itemMap);
//                }
//
//                Map<String, Object> data = new LinkedHashMap<>();
//                data.put("title", res.getInspectionName());
//                data.put("reportDate", DateUtil.convertTimestampToDateString(res.getInspectionDate()));
//                data.put("status", res.getStatus() == 0 ? "未审核" : "已审核");
//                data.put("checkDoctorName", res.getCheckDoctorName());
//                data.put("specimenNo", "");
//                data.put("count", lst.size());
//                data.put("list", lst);
//                return response.succeed(data);
//            }
//
//            return response.failed(BaseResponse.APP_ERROR, result.getInfo());
//        } catch (Exception e) {
//            logger.error("getInspectionReportDetail({}): {}", inspectionId, e.getMessage(), e);
//            return response.error();
//        }
//    }
//

}
