| | |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.ltkj.common.core.domain.AjaxResult; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | |
| | | * @Author: zhaowenxuan |
| | | * @Date: 2024/5/31 14:38 |
| | | */ |
| | | @Component |
| | | public class HisApiGetMethodService { |
| | | // 数据库配置文件路径 |
| | | private static final String CONFIG_PATH = "D:\\ltkjprojectconf\\config.properties"; |
| | | // 数据库名 |
| | | private static String DB_NAME = ""; |
| | | @Autowired |
| | | private HisApiMethodService controller; |
| | | |
| | | |
| | | /** |
| | | * 获取 |
| | | * |
| | | * @return |
| | | */ |
| | | public AjaxResult getHISData(String type, Map<String, Object> params) { |
| | | // Getoutaccountrecord 获取门诊结算记录 |
| | | // Getoutpatientcostinfo 获取门诊患者费用清单信息 |
| | | // Getlaburgentinfo 获取危急值信息 |
| | | // Getlabgermdetailinfo 获取微生物药敏信息 |
| | | // Getlabgermrepinfo 获取微生物报告记录信息 |
| | | // Getlabreportinfo 获取检验报告记录信息 |
| | | // Getlabapplyinfo 获取检验申请信息 |
| | | // Getexamurgentinfo 获取检查危急值信息 |
| | | // Getexamreportinfo 获取检查报告信息 |
| | | // Getexamapplyinfo 获取检查申请信息 |
| | | AjaxResult result = null; |
| | | switch (type) { |
| | | case "Getoutaccountrecord": |
| | | result = controller.Getoutaccountrecord(params); |
| | | result.put("limit",true); |
| | | break; |
| | | case "Getoutpatientcostinfo": |
| | | result = controller.Getoutpatientcostinfo(params); |
| | | result.put("limit",true); |
| | | break; |
| | | case "Getlaburgentinfo": |
| | | result = controller.Getlaburgentinfo(params); |
| | | result.put("limit",false); |
| | | break; |
| | | case "Getlabgermdetailinfo": |
| | | result = controller.Getlabgermdetailinfo(params); |
| | | result.put("limit",false); |
| | | break; |
| | | case "Getlabgermrepinfo": |
| | | result = controller.Getlabgermrepinfo(params); |
| | | result.put("limit",false); |
| | | break; |
| | | case "Getlabreportinfo": |
| | | result = controller.Getlabreportinfo(params); |
| | | result.put("limit",true); |
| | | break; |
| | | case "Getlabapplyinfo": |
| | | result = controller.Getlabapplyinfo(params); |
| | | result.put("limit",false); |
| | | break; |
| | | case "Getexamurgentinfo": |
| | | result = controller.Getexamurgentinfo(params); |
| | | result.put("limit",true); |
| | | break; |
| | | case "Getexamreportinfo": |
| | | result = controller.Getexamreportinfo(params); |
| | | result.put("limit",true); |
| | | break; |
| | | case "Getexamapplyinfo": |
| | | result = controller.Getexamapplyinfo(params); |
| | | result.put("limit",false); |
| | | break; |
| | | } |
| | | String json = result.get("data").toString(); |
| | | JSONObject response = JSONUtil.parseObj(json).getJSONObject("Response"); |
| | | if (response.getStr("ResultCode").toString().equals("0")) { |
| | | // TODO 如果不带分页参数 返回的数据都是对象 则在这里通过result.get("limit")进行判断 处理对象或集合并返回 |
| | | JSONArray resultData = response.getJSONArray("ResultData"); |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (Object resultDatum : resultData) { |
| | | JSONObject object = (JSONObject) resultDatum; |
| | | Map<String, Object> map = new HashMap<>(); |
| | | for (String key : object.keySet()) { |
| | | map.put(key, object.get(key)); |
| | | } |
| | | list.add(map); |
| | | } |
| | | AjaxResult ajaxResult = null; |
| | | if ((boolean)result.get("limit")){ |
| | | ajaxResult = saveArray(json, type); |
| | | }else { |
| | | ajaxResult = save(response.getJSONObject("ResultData"),type); |
| | | } |
| | | ajaxResult.put("data", list); |
| | | return ajaxResult; |
| | | } else { |
| | | return AjaxResult.error(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ResultData为对象 |
| | | * 根据his接口返回值 插入数据 |
| | | * 如果没有表则创建表 接口增加了字段则为表增加字段 |
| | | * @param json 请求返回json |
| | | * |
| | | * @param code 接口代码 |
| | | * @return 执行是否成功 |
| | | */ |
| | |
| | | String tabName = "ltkj_" + code; |
| | | // if (response.getStr("ResultCode").equals("0")) { |
| | | // JSONObject object = response.getJSONObject("ResultData"); |
| | | Connection connection = getConnection(); |
| | | Connection connection = getConnection(); |
| | | // for (Object resultDatum : resultData) { |
| | | // JSONObject object = (JSONObject) resultDatum; |
| | | Boolean isExists = tabIsExists(connection, tabName); |
| | | if (null == isExists) |
| | | return AjaxResult.error(); |
| | | if (!isExists) { |
| | | try { |
| | | creatTable(object, tabName, connection); |
| | | } catch (SQLException throwables) { |
| | | throwables.printStackTrace(); |
| | | return AjaxResult.error(); |
| | | } |
| | | } |
| | | //插入数据 |
| | | try { |
| | | operationTable(object, tabName, connection); |
| | | } catch (SQLException throwables) { |
| | | throwables.printStackTrace(); |
| | | return AjaxResult.error(); |
| | | } |
| | | // } |
| | | try { |
| | | if (connection != null) |
| | | connection.close(); |
| | | } catch (SQLException throwables) { |
| | | } |
| | | // } |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * ResultData为集合 |
| | | * 根据his接口返回值 插入数据 |
| | | * 如果没有表则创建表 接口增加了字段则为表增加字段 |
| | | * |
| | | * @param code 接口代码 |
| | | * @return 执行是否成功 |
| | | */ |
| | | public AjaxResult saveArray(String json, String code) { |
| | | code = code.toLowerCase(); |
| | | JSONObject jsonObject = JSONUtil.parseObj(json); |
| | | JSONObject response = jsonObject.getJSONObject("Response"); |
| | | String tabName = "ltkj_" + code; |
| | | if (response.getStr("ResultCode").equals("0")) { |
| | | JSONArray resultData = response.getJSONArray("ResultData"); |
| | | Connection connection = getConnection(); |
| | | for (Object resultDatum : resultData) { |
| | | JSONObject object = (JSONObject) resultDatum; |
| | | Boolean isExists = tabIsExists(connection, tabName); |
| | | if (null == isExists) |
| | | return AjaxResult.error(); |
| | |
| | | throwables.printStackTrace(); |
| | | return AjaxResult.error(); |
| | | } |
| | | // } |
| | | } |
| | | try { |
| | | if (connection != null) |
| | | connection.close(); |
| | | } catch (SQLException throwables) { |
| | | } |
| | | // } |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | |
| | | responseColums.removeAll(columns); |
| | | if (!responseColums.isEmpty()) { |
| | | for (String colum : responseColums) { |
| | | String sql = "alter table " + tabName + " add column " + colum + " text null"; |
| | | String sql = "alter table " + tabName + " add column " + colum + " VARCHAR(200) null"; |
| | | Statement statement = connection.createStatement(); |
| | | statement.executeUpdate(sql); |
| | | statement.close(); |
| | |
| | | private void creatTable(JSONObject data, String tabName, Connection connection) throws SQLException { |
| | | StringBuilder sql = new StringBuilder("CREATE TABLE " + tabName + " ("); |
| | | for (Map.Entry<String, Object> entry : data.entrySet()) { |
| | | sql.append(entry.getKey()).append(" text null,"); |
| | | sql.append(entry.getKey()).append(" VARCHAR(200) null,"); |
| | | } |
| | | sql.append("insert_time").append(" text null,"); |
| | | sql.append("insert_time").append(" VARCHAR(200) null,"); |
| | | sql = new StringBuilder(sql.substring(0, sql.length() - 1)); |
| | | sql.append(");"); |
| | | Statement statement = connection.createStatement(); |