package com.docus.server.report.controller;

import com.alibaba.fastjson.JSONObject;
import com.docus.core.util.Func;
import com.docus.infrastructure.web.api.CommonResult;
import com.docus.server.report.job.ReportJob;
import com.docus.server.report.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author wyb
 * 文件上报下载服务
 */
@Slf4j
@Api(tags = "文件上报，补偿控制")
@RestController
@RequestMapping("/report/makeup")
public class ReportDownController {
    @Resource
    private ReportService reportService;
    @Resource
    ReportJob reportJob;
    @ApiOperation(value = " 移动护理采集 job 测试")
    @GetMapping("/sdRyNurseInsertSugarCollectJob")
    public CommonResult<String> sdRyNurseInsertSugarCollectJob() {
        reportJob.sdRyNurseInsertSugarCollectJob();
        return CommonResult.success("成功");
    }

    @ApiOperation(value = " lis 检验 采集 job 测试")
    @GetMapping("/sdRyLisCollectJob")
    public CommonResult<String> sdRyLisCollectJob() {
        reportJob.sdRyLisCollectJob();
        return CommonResult.success("成功");
    }

    @ApiOperation(value = " 检查(门诊) 采集 job 测试")
    @GetMapping("/sdRyMzInspectCollectJob")
    public CommonResult<String> sdRyMzInspectCollectJob() {
        reportJob.sdRyMzInspectCollectJob();
        return CommonResult.success("成功");
    }

    @ApiOperation(value = " 检查(住院) 采集 job 测试")
    @GetMapping("/sdRyZyInspectCollectJob")
    public CommonResult<String> sdRyZyInspectCollectJob() {
        reportJob.sdRyZyInspectCollectJob();
        return CommonResult.success("成功");
    }


    @ApiOperation(value = "根据任务id补偿报告下载(接收推送的报告)")
    @PostMapping("/makeupReportByTaskIds")
    public CommonResult<String> makeupReportByTaskIds(@RequestBody List<Long> taskIds) {
        if (Func.isEmpty(taskIds)) {
            return CommonResult.failed("补偿任务id不能为空！");
        }
        try {
            reportService.makeupThreePartyPushReportByTaskIds(taskIds);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return CommonResult.failed("补偿出现了一点小问题！");
        }
        return CommonResult.success("补偿成功！");
    }


    @ApiOperation(value = "inspect检查报告测试地址", hidden = true)
    @PostMapping("/inspectTest/query")
    public JSONObject inspectTest(@RequestParam("uuid") String uuid,
                                  @RequestParam("action") String action,
                                  @RequestParam("accessKey") String accessKey,
                                  @RequestParam("creationTime") String creationTime,
                                  @RequestBody Map<String, Object> map) {
        System.out.println("请求的参数为 uuid：" + uuid);
        System.out.println("请求的参数为 action：" + action);
        System.out.println("请求的参数为 accessKey：" + accessKey);
        System.out.println("请求的参数为 creationTime：" + creationTime);
        System.out.println("请求的参数为 body：" + map);

        String result = "{\n" +
                "\"compcode\": \"INSPECT_REPORTQuery\",\n" +
                "\"compname\": \"检查报告查询服务\",\n" +
                "\"count\": 2,\n" +
                "\"data\": {\n" +
                "\"result\": [\n" +
                "{\n" +
                "\"RN\": 1,\n" +
                "\"EXAM_REPORT_SN\": \"0002290956_1\",\n" +
                "\"VISIT_SN\": \"00057762240012\",\n" +
                "\"PATIENT_SN\": \"m000577622400\",\n" +
                "\"PATIENT_DOMAIN\": \"4560886379\",\n" +
                "\"PATIENT_AGE\": \"52\",\n" +
                "\"ORG_CODE\": \"4560886379\",\n" +
                "\"ORG_NAME\": \"南方医科大学顺德医院\",\n" +
                "\"EXAM_REPORT_LID\": \"0002290956_1\",\n" +
                "\"ITEM_CLASS\": \"0027\",\n" +
                "\"ITEM_CLASS_NAME\": \"耳鼻喉\",\n" +
                "\"EXAMINATION_DATE\": \"2023-03-28T02:24:27.000+00:00\",\n" +
                "\"EXAMINATION_DEPT\": \"11\",\n" +
                "\"EXAM_DEPT_NAME\": \"耳鼻咽喉头颈外科\",\n" +
                "\"IMAGING_CONCLUSION\": \"右 耳：鼓室测试结果显示A型鼓室图。\\n 镫骨肌声\n" +
                "反射同侧部分能引出。\\n\\n左 耳：鼓室测试结果显示As型鼓室图。\\n 镫骨肌声反射同侧未能引\n" +
                "出。\",\n" +
                "\"REPORT_DOCTOR\": \"A-476\",\n" +
                "\"REPORT_DOCTOR_NAME\": \"杨嘉英\",\n" +
                "\"REPORT_DATE\": \"2023-03-28T02:36:28.000+00:00\",\n" +
                "\"REVIEW_DOCTOR\": \"A-476\",\n" +
                "\"REVIEW_DOCTOR_NAME\": \"杨嘉英\",\n" +
                "\"REVIEW_DATE\": \"2023-03-28T02:36:29.000+00:00\",\n" +
                "\"REPORT_TYPE_NAME\": \"1.声导抗组合（导抗+镫骨肌）\",\n" +
                "\"CREATE_TIME\": \"2023-03-28T02:36:33.000+00:00\",\n" +
                "\"UPDATE_TIME\": \"2023-03-28T02:36:33.000+00:00\",\n" +
                "\"UPDATEBY\": \"ES-001\",\n" +
                "\"EXAM_RESULT_NO\": \"0002290956_1\",\n" +
                "\"PATIENT_TYPE_CODE\": \"1\",\n" +
                "\"PATIENT_TYPE_NAME\": \"门诊\",\n" +
                "\"ID_CARD_NUM\": \"310107197007241224\",\n" +
                "\"KEEP_ORG_CODE\": \"4560886379\",\n" +
                "\"KEEP_ORG_NAME\": \"南方医科大学顺德医院\",\n" +
                "\"EXAM_TECH_SIGN\": \"杨嘉英\",\n" +
                "\"EXAM_DR_SIGN\": \"杨嘉英\",\n" +
                "\"DIAG_CODE\": \"Z32.100\",\n" +
                "\"DIAG_NAME\": \"耳鸣\",\n" +
                "\"MAIN_SUIT\": \"主诉：耳鸣1月。\\n\\n现病史：1月前出现耳鸣，无头痛，无听力下\n" +
                "降，无涕 血。\\n\\n体格检查：双耳鼓膜完整，标识清。\",\n" +
                "\"SYMPTOM_DESC\": \"主诉：耳鸣1月。\\n\\n现病史：1月前出现耳鸣，无头痛，无听力\n" +
                "下降，无涕 血。\\n\\n体格检查：双耳鼓膜完整，标识清。\",\n" +
                "\"REQUEST_SN\": \"MZ73813541\",\n" +
                "\"REQ_DEPT\": \"M010527\",\n" +
                "\"REQ_DEPT_NAME\": \"耳鼻咽喉头颈外科门诊\",\n" +
                "\"IH_TIMES\": 12,\n" +
                "\"PATHOLOGY_NO\": \"EBH230328079\",\n" +
                "\"PH_CODE\": \"1\",\n" +
                "\"PATIENT_ID\": \"m000577622400\",\n" +
                "\"FILE_PATH\": \"http://192.168.5.51/ClinicView/html/report.htm?\n" +
                "exam_no=0002290956&report_no=1\",\n" +
                "\"REPORT_NAME\": \"声导抗镫骨肌组合\",\n" +
                "\"COMPLETE_TIME\": \"2023-03-28T02:36:18.000+00:00\",\n" +
                "\"detail\": [\n" +
                "{\n" +
                "\"ITEM_SN\": null,\n" +
                "\"ITEM_VALUE\": \"右 耳：鼓室测试结果显示A型鼓室图。\\n 镫骨肌声\n" +
                "反射同侧部分能引出。\\n\\n左 耳：鼓室测试结果显示As型鼓室图。\\n 镫骨肌声反射同侧未能引\n" +
                "出。\",\n" +
                "\"ITEM_RESULT_CODE\": \"3\",\n" +
                "\"ITEM_RESULT_NAME\": \"不确定\",\n" +
                "\"ITEM_RATION_RESULT\": \"136\",\n" +
                "\"ITEM_RATION_RESULT_UNIT\": \"nmol/L\",\n" +
                "\"EXAM_REPORT_SN\": \"0002290956_1\",\n" +
                "\"ITEM_CODE\": \"18156\",\n" +
                "\"ITEM_NAME\": \"声导抗镫骨肌组合\",\n" +
                "\"SPECIAL_EXAM_FLAG\": \"F\",\n" +
                "\"EXAM_TYPE_NAME\": \"耳鼻喉\"\n" +
                "}\n" +
                "]\n" +
                "},\n" +
                "{\n" +
                "\"RN\": 2,\n" +
                "\"EXAM_REPORT_SN\": \"0002290952_1\",\n" +
                "\"VISIT_SN\": \"00057762240012\",\n" +
                "\"PATIENT_SN\": \"m000577622400\",\n" +
                "\"PATIENT_DOMAIN\": \"4560886379\",\n" +
                "\"PATIENT_AGE\": \"52\",\n" +
                "\"ORG_CODE\": \"4560886379\",\n" +
                "\"ORG_NAME\": \"南方医科大学顺德医院\",\n" +
                "\"EXAM_REPORT_LID\": \"0002290952_1\",\n" +
                "\"ITEM_CLASS\": \"0027\",\n" +
                "\"ITEM_CLASS_NAME\": \"耳鼻喉\",\n" +
                "\"EXAMINATION_DATE\": \"2023-03-28T02:24:13.000+00:00\",\n" +
                "\"EXAMINATION_DEPT\": \"11\",\n" +
                "\"EXAM_DEPT_NAME\": \"耳鼻咽喉头颈外科\",\n" +
                "\"IMAGING_CONCLUSION\": \"右 耳:听阈平均16dBHL，听力大致正常。\\n左 耳:听阈\n" +
                "平均14dBHL，听力大致正常。\",\n" +
                "\"REPORT_DOCTOR\": \"A-476\",\n" +
                "\"REPORT_DOCTOR_NAME\": \"杨嘉英\",\n" +
                "\"REPORT_DATE\": \"2023-03-28T02:41:44.000+00:00\",\n" +
                "\"REVIEW_DOCTOR\": \"A-476\",\n" +
                "\"REVIEW_DOCTOR_NAME\": \"杨嘉英\",\n" +
                "\"REVIEW_DATE\": \"2023-03-28T02:41:45.000+00:00\",\n" +
                "\"REPORT_TYPE_NAME\": \"纯音测听报告\",\n" +
                "\"CREATE_TIME\": \"2023-03-28T02:41:49.000+00:00\",\n" +
                "\"UPDATE_TIME\": \"2023-03-28T02:41:49.000+00:00\",\n" +
                "\"UPDATEBY\": \"ES-001\",\n" +
                "\"EXAM_RESULT_NO\": \"0002290952_1\",\n" +
                "\"PATIENT_TYPE_CODE\": \"1\",\n" +
                "\"PATIENT_TYPE_NAME\": \"门诊\",\n" +
                "\"ID_CARD_NUM\": \"310107197007241224\",\n" +
                "\"KEEP_ORG_CODE\": \"4560886379\",\n" +
                "\"KEEP_ORG_NAME\": \"南方医科大学顺德医院\",\n" +
                "\"EXAM_TECH_SIGN\": \"杨嘉英\",\n" +
                "\"EXAM_DR_SIGN\": \"杨嘉英\",\n" +
                "\"DIAG_CODE\": \"Z32.100\",\n" +
                "\"DIAG_NAME\": \"耳鸣\",\n" +
                "\"MAIN_SUIT\": \"主诉：耳鸣1月。\\n\\n现病史：1月前出现耳鸣，无头痛，无听力下\n" +
                "降，无涕 血。\\n\\n体格检查：双耳鼓膜完整，标识清。\",\n" +
                "\"SYMPTOM_DESC\": \"主诉：耳鸣1月。\\n\\n现病史：1月前出现耳鸣，无头痛，无听力\n" +
                "下降，无涕 血。\\n\\n体格检查：双耳鼓膜完整，标识清。\",\n" +
                "\"REQUEST_SN\": \"MZ73813540\",\n" +
                "\"REQ_DEPT\": \"M010527\",\n" +
                "\"REQ_DEPT_NAME\": \"耳鼻咽喉头颈外科门诊\",\n" +
                "\"IH_TIMES\": 12,\n" +
                "\"PATHOLOGY_NO\": \"EBH230328079\",\n" +
                "\"PH_CODE\": \"1\",\n" +
                "\"PATIENT_ID\": \"m000577622400\",\n" +
                "\"FILE_PATH\": \"http://192.168.5.51/ClinicView/html/report.htm?\n" +
                "exam_no=0002290952&report_no=1\",\n" +
                "\"REPORT_NAME\": \"纯音听阈测定\",\n" +
                "\"COMPLETE_TIME\": \"2023-03-28T02:41:33.000+00:00\",\n" +
                "\"detail\": [\n" +
                "{\n" +
                "\"ITEM_SN\": null,\n" +
                "\"ITEM_VALUE\": \"右 耳:听阈平均16dBHL，听力大致正常。\\n左 耳:听阈\n" +
                "平均14dBHL，听力大致正常。\",\n" +
                "\"ITEM_RESULT_CODE\": \"3\",\n" +
                "\"ITEM_RESULT_NAME\": \"不确定\",\n" +
                "\"ITEM_RATION_RESULT\": \"136\",\n" +
                "\"ITEM_RATION_RESULT_UNIT\": \"nmol/L\",\n" +
                "\"EXAM_REPORT_SN\": \"0002290952_1\",\n" +
                "\"ITEM_CODE\": \"18120\",\n" +
                "\"ITEM_NAME\": \"纯音听阈测定\",\n" +
                "\"SPECIAL_EXAM_FLAG\": \"F\",\n" +
                "\"EXAM_TYPE_NAME\": \"耳鼻喉\"\n" +
                "}\n" +
                "]\n" +
                "}\n" +
                "]\n" +
                "},\n" +
                "\"ResultMessage\": \"查询成功\",\n" +
                "\"ResultCode\": \"0\"\n" +
                "}";

        return Func.readJson(result, JSONObject.class);

    }


    @ApiOperation(value = "inspect检查报告测试地址 ", hidden = true)
    @PostMapping("/inspectTestNoResult/query")
    public JSONObject inspectTestNoResult(@RequestParam("uuid") String uuid,
                                          @RequestParam("action") String action,
                                          @RequestParam("accessKey") String accessKey,
                                          @RequestParam("creationTime") String creationTime,
                                          @RequestBody Map<String, Object> map) {
        System.out.println("请求的参数为 uuid：" + uuid);
        System.out.println("请求的参数为 action：" + action);
        System.out.println("请求的参数为 accessKey：" + accessKey);
        System.out.println("请求的参数为 creationTime：" + creationTime);
        System.out.println("请求的参数为 body：" + map);

        String result = "{\n" +
                "\"compcode\": \"INSPECT_REPORTQuery\",\n" +
                "\"compname\": \"检查报告查询服务\",\n" +
                "\"count\": 0,\n" +
                "\"data\": [],\n" +
                "\"ResultMessage\": \"查询成功\",\n" +
                "\"ResultCode\": \"0\"\n" +
                "}";

        return Func.readJson(result, JSONObject.class);

    }


    @ApiOperation(value = "lis检验报告测试地址", hidden = true)
    @PostMapping("/lisTest/query")
    public JSONObject lisTest(@RequestParam("uuid") String uuid,
                              @RequestParam("action") String action,
                              @RequestParam("accessKey") String accessKey,
                              @RequestParam("creationTime") String creationTime,
                              @RequestBody Map<String, Object> map) {
        System.out.println("请求的参数为 uuid：" + uuid);
        System.out.println("请求的参数为 action：" + action);
        System.out.println("请求的参数为 accessKey：" + accessKey);
        System.out.println("请求的参数为 creationTime：" + creationTime);
        System.out.println("请求的参数为 body：" + map);

        String result = "{\n" +
                "\"compcode\": \"LIS_REPORTQuery\",\n" +
                "\"compname\": \"检验报告查询服务\",\n" +
                "\"count\": 4,\n" +
                "\"data\": {\n" +
                "\"result\": [\n" +
                "{\n" +
                "\"RN\": 1,\n" +
                "\"LAB_REPORT_SN\": \"20230317G0303385\",\n" +
                "\"VISIT_SN\": \"0020851475001\",\n" +
                "\"PATIENT_SN\": \"m002085147500\",\n" +
                "\"PATIENT_DOMAIN\": \"4560886379\",\n" +
                "\"ORG_CODE\": \"4560886379\",\n" +
                "\"ORG_NAME\": \"南方医科大学顺德医院\",\n" +
                "\"LAB_REPORT_LID\": \"20230317G0303385\",\n" +
                "\"SAMPLE_NO\": \"1647681900\",\n" +
                "\"SAMPLE_TYPE\": \"a001\",\n" +
                "\"SAMPLE_TYPE_NAME\": \"全血\",\n" +
                "\"SAMPLING_TIME\": \"2023-03-17T15:10:58.000+00:00\",\n" +
                "\"GATHERER_CODE\": \"2-320\",\n" +
                "\"GATHERER_NAME\": \"张桂芬\",\n" +
                "\"SEND_SAMPLE_PURPOSE_CODE\": \"1\",\n" +
                "\"REQUEST_TIME\": \"2023-03-17T14:48:26.000+00:00\",\n" +
                "\"RECEIVE_TIME\": \"2023-03-17T15:23:21.000+00:00\",\n" +
                "\"LAB_DEPT\": \"30\",\n" +
                "\"LAB_DEPT_NAME\": \"检验科\",\n" +
                "\"TESTER_ID\": \"3-216\",\n" +
                "\"TESTER_NAME\": \"黄建玲\",\n" +
                "\"TEST_DATE\": \"2023-03-17T15:23:21.000+00:00\",\n" +
                "\"REPORTER_ID\": \"3-336\",\n" +
                "\"REPORTER_NAME\": \"潘碧燕\",\n" +
                "\"REPORT_DATE\": \"2023-03-17T15:37:02.000+00:00\",\n" +
                "\"REVIEWER_ID\": \"3-336\",\n" +
                "\"REVIEWER_NAME\": \"潘碧燕\",\n" +
                "\"REVIEW_DATE\": \"2023-03-17T15:37:02.000+00:00\",\n" +
                "\"REPORT_MEMO\": null,\n" +
                "\"MEMO\": null,\n" +
                "\"EXPECTED_AGE\": 0,\n" +
                "\"FETAL_NUMBER\": 0,\n" +
                "\"SUPPLIER_NAME\": \"梁拾壹\",\n" +
                "\"SUPPLIER_GENDER\": \"男\",\n" +
                "\"SUPPLIER_AGE\": \"92岁\",\n" +
                "\"DIAGNOSIS_TEXT\": \"神志不清查因\",\n" +
                "\"WITHDRAW_FLAG\": 1,\n" +
                "\"REPORT_TYPE_CODE\": \"LIS465\",\n" +
                "\"REPORT_TYPE_NAME\": \"血常规(五分类)+CRP\",\n" +
                "\"SEND_HOSPITAL\": \"南方医科大学顺德医院\",\n" +
                "\"CREATE_TIME\": \"2023-03-17T15:37:08.000+00:00\",\n" +
                "\"UPDATE_TIME\": \"2023-03-17T17:15:00.000+00:00\",\n" +
                "\"UPDATE_COUNT\": 5,\n" +
                "\"DELETE_FLAG\": \"0\",\n" +
                "\"DELETE_TIME\": null,\n" +
                "\"UPDATEBY\": \"LIS\",\n" +
                "\"DELETEBY\": null,\n" +
                "\"REQUEST_SN\": \"1647681900\",\n" +
                "\"REQUEST_NO\": \"1647681900\",\n" +
                "\"TEST_METHOD\": \"荧光免疫\",\n" +
                "\"ITEM_CODE\": \"LIS465\",\n" +
                "\"SAMPLE_STATUS\": \"合格\",\n" +
                "\"CREATEBY\": \"LIS\",\n" +
                "\"MICRO_COUNT\": null,\n" +
                "\"ITEM_TYPE\": \"1\",\n" +
                "\"OUTP_NUM\": \"0020851475001\",\n" +
                "\"IH_NUM\": null,\n" +
                "\"IH_TIMES\": \"1\",\n" +
                "\"VISIT_CLASS_CODE\": \"1\",\n" +
                "\"VISIT_CLASS_NAME\": \"门诊\",\n" +
                "\"PDF_URL\":\n" +
                "\"http://192.168.5.61:16703//2023/03/17/20230317G0303385.pdf\",\n" +
                "\"DESCRIBE\": null,\n" +
                "\"item\": [\n" +
                "{\n" +
                "\"ITEM_CODE\": \"6467\",\n" +
                "\"ITEM_NAME_CN\": \"C反应蛋白\",\n" +
                "\"ITEM_NAME_EN\": \"CRP\",\n" +
                "\"ITEM_VALUE\": \"<5.0\",\n" +
                "\"ITEM_UNIT\": \"mg/L\",\n" +
                "\"LOW_VALUE\": \"0\",\n" +
                "\"HIGH_VALUE\": \"10\",\n" +
                "\"NORMAL_REF_VALUE_TEXT\": \"0-10\",\n" +
                "\"WARN_FLAG_NAME\": \"不危险\",\n" +
                "\"WARN_FLAG\": \"1\",\n" +
                "\"QUALITATIVE_RESULTS\": \"<5.0\",\n" +
                "\"DISPLAY_ORDER\": 2,\n" +
                "\"TIP\": \"正常\",\n" +
                "\"TEST_METHOD_CODE\": \"LIS205 \",\n" +
                "\"TEST_METHOD\": \"荧光免疫\",\n" +
                "\"TEST_METHOD_DESC\": \"荧光免疫\",\n" +
                "\"ITEM_TYPE_CODE\": \"LIS465\",\n" +
                "\"ITEM_TYPE_NAME\": \"血常规(五分类)+CRP\",\n" +
                "\"STATUS_CODE\": \"1\",\n" +
                "\"TypeCode\": \"0\",\n" +
                "\"DRUG_CODE\": null,\n" +
                "\"DRUG_NAME_CN\": null,\n" +
                "\"DRUG_NAME_EN\": null,\n" +
                "\"SENSITIVITY\": null,\n" +
                "\"MIC\": null,\n" +
                "\"KB\": null,\n" +
                "\"BREAKPOINT\": null,\n" +
                "\"MICRO_NO\": null,\n" +
                "\"MICRO_NAME\": null\n" +
                "}\n" +
                "]\n" +
                "}\n" +
                "]\n" +
                "},\n" +
                "\"ResultMessage\": \"查询成功\",\n" +
                "\"ResultCode\": \"0\"\n" +
                "}";

        return Func.readJson(result, JSONObject.class);

    }


    @ApiOperation(value = "lis检验报告测试地址", hidden = true)
    @PostMapping("/lisTestNoResult/query")
    public JSONObject lisTestNoResult(@RequestParam("uuid") String uuid,
                                      @RequestParam("action") String action,
                                      @RequestParam("accessKey") String accessKey,
                                      @RequestParam("creationTime") String creationTime,
                                      @RequestBody Map<String, Object> map) {
        System.out.println("请求的参数为 uuid：" + uuid);
        System.out.println("请求的参数为 action：" + action);
        System.out.println("请求的参数为 accessKey：" + accessKey);
        System.out.println("请求的参数为 creationTime：" + creationTime);
        System.out.println("请求的参数为 body：" + map);

        String result = "{\n" +
                "\"compcode\": \"ObtainInpatientInformation\",\n" +
                "\"compname\": \"获取患者住院信息(移动护理定制)\",\n" +
                "\"count\": 0,\n" +
                "\"data\": [],\n" +
                "\"ResultMessage\": \"查询成功\",\n" +
                "\"ResultCode\": \"0\"\n" +
                "}";

        return Func.readJson(result, JSONObject.class);

    }


}
