/**
 * Copyright (C), 2015-2019
 * Author:   HJL
 * Date:     2019/7/19 14:39
 * Description:病案召回
 */
package com.emr.controller;

import com.emr.entity.*;
import com.emr.service.Archive_MasterService;
import com.emr.service.Archive_Master_FollowingService;
import com.emr.service.ipml.ObservationRecordService;
import com.emr.util.Msg;
import com.emr.util.ThreadExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@PropertySource(value = "classpath:config/jdbc.properties", encoding = "UTF-8")
@Controller
@RequestMapping("/observationRecord")
public class ObservationRecordController {
    @Autowired
    private ObservationRecordService observationRecordService;
    @Autowired
    private Archive_MasterService archiveMasterService;
    @Autowired
    private Archive_Master_FollowingService archiveMasterFollowingService;

    @ResponseBody
    @RequestMapping(value = "/getObservationRecordList")
    public OffsetLimitPage getObservationRecordList(Archive_Master_Vo master, Integer offset, Integer limit) {
        OffsetLimitPage result = observationRecordService.getObservationRecordList(master, offset, limit);
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/exportExcel")
    public void exportExcel(HttpServletResponse response,Archive_Master_Vo master) throws Exception {
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        String[] header = {"患者ID","留观号","留观次数","姓名","留观开始日期","留观结束日期","归档状态","是否死亡"};
        String[] fileNames = {"patientId","inpNo","visitId","name","admissionDateTime","dischargeDateTime","archivestate","deathFlag"};
        //文件名
        String fileName = "留观病历信息数据" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xls";
        //构造excel的数据
        List<Archive_Master> list = observationRecordService.getList(master);
        ThreadExcelUtils utils = new ThreadExcelUtils(fileName, "", header, fileNames);
        utils.exportExcelToFilePath(response,utils.listConvert(list));
    }
}
 

