package com.docus.server.trusthis.controller;

import com.docus.infrastructure.web.api.CommonResult;
import com.docus.server.trusthis.mapper.JsOrdersMapper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author YongBin Wen
 * @date 2024/3/8 15:21
 */
@Slf4j
@RequestMapping("/mmry-collect")
@RestController
public class ManualFunctionController {
    @Resource
    private JsOrdersMapper jsOrdersMapper;

    @ApiOperation(value = "测试获取医嘱序号", tags = "茂名采集控制-测试")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "inpatientNo", value = "病案号", required = true, dataTypeClass = String.class),
                    @ApiImplicitParam(name = "admissionOrDisDate", value = "入院或者出院日期 yyyy-MM-dd", required = true, dataTypeClass = String.class),
                    @ApiImplicitParam(name = "disDate", value = "出院日期 yyyy-MM-dd", required = true, dataTypeClass = String.class)
            }
    )
    @GetMapping("/test/getOrderIndex")
    public CommonResult<List<String>> getOrderIndex(@RequestParam("inpatientNo") String inpatientNo, @RequestParam("admissionOrDisDate") String admissionOrDisDate, @RequestParam("disDate") String disDate) {
        String pattern = "yyyy-MM-dd";
        int patternLen = pattern.length();
        if (admissionOrDisDate.length() != patternLen || disDate.length() != patternLen) {
            return CommonResult.failed("请传入正确的时间格式 yyyy-MM-dd");
        }
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        try {
            sdf.parse(admissionOrDisDate);
            sdf.parse(disDate);
        } catch (Exception ex) {
            return CommonResult.failed("请传入正确的时间格式 yyyy-MM-dd");
        }

        List<String> orderIndex = jsOrdersMapper.getOrderIndex(inpatientNo, admissionOrDisDate, disDate);
        return CommonResult.success(orderIndex);
    }


}
