package com.yihu.wlyy.web.doctor.record;

import com.yihu.wlyy.service.app.record.OutpatientService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.util.StringUtil;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by zhenglingfeng on 2016/10/17.
 */
@Controller
@RequestMapping(value = "/wlyy_service/record", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "医生端-健康档案门/急诊记录（测试）")
public class OutpatientController extends BaseController {

    @Autowired
    private OutpatientService outpatientService;


    @ApiOperation("XML转JSOn")
    @RequestMapping(value = "/xmlToJson", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public String xmlToJson(
            @ApiParam(name="xml",value="xml")
            @RequestBody String xml) {
        try {
            Map result = outpatientService.xmlToJson(xml);
            return write(200, "获取XML转JSOn数据成功！", "data", result);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "获取XML转JSOn数据成功！");
        }
    }


    @ApiOperation("get0102")
    @RequestMapping(value = "/get0102", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public String get0102() {
        try {
            Map result = outpatientService.getOutpatientCost();
            return write(200, "获取JSOn数据成功！", "data", result);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "获取JSOn数据成功！");
        }
    }

    @ApiOperation("get0121")
    @RequestMapping(value = "/get0121", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public String get0121() {
        try {
            Map result = outpatientService.getOutpatientLabReport();
            return write(200, "获取JSOn数据成功！", "data", result);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "获取JSOn数据成功！");
        }
    }

    @ApiOperation("get0131")
    @RequestMapping(value = "/get0131", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public String get0131() {
        try {
            Map result = outpatientService.getOutpatientExamReport();
            return write(200, "获取JSOn数据成功！", "data", result);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "获取JSOn数据成功！");
        }
    }

    @ApiOperation("get0141")
    @RequestMapping(value = "/get0141", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public String get0141() {
        try {
            Map result = outpatientService.getOutpatientDrugs();
            return write(200, "获取JSOn数据成功！", "data", result);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "获取JSOn数据成功！");
        }
    }

}
