Data.java 4.25 KB
package com.xkl.upsoft;


import com.xkl.Constants;
import org.json.JSONObject;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.text.DecimalFormat;

/**
 * Created by zhao yue on 2017/1/14.
 */
public class Data {
    public static final String USR_ACCOUNT = "15211112222";
    public static String AMP_REPORT = "";


    static {
        Data data = new Data();
        data.generateJsonFormatReport();
    }

    public static String readTxtFile(String filePath) {
        String line = "";
        try {
            String encoding = "UTF-8";
            File file = new File(filePath);
            if (file.isFile() && file.exists()) { //判断文件是否存在
                InputStreamReader read = new InputStreamReader(
                        new FileInputStream(file), encoding);//考虑到编码格式
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                while ((lineTxt = bufferedReader.readLine()) != null && !lineTxt.equals("")) {
                    line = lineTxt;
                    break;
                }
                read.close();
            } else {
                System.out.println("找不到指定的文件");
            }
        } catch (Exception e) {
            System.out.println("读取文件内容出错");
            e.printStackTrace();
        }
        return line;
    }

    @Test
    public void generateJsonFormatReport() {
        JSONObject report = new JSONObject();
        report.put("ABD", 35.66);
        report.put("LAC", 36.23);
        report.put("LCA", 32.94);
        report.put("RAC", 35.84);
        report.put("RCA", 33.05);
        report.put("total", 173.62); // sum of the above 5 temperature
        report.put("age", 24);
        report.put("atmospheric_pressure", 756.58);
        // The conclusion string of the report.
        report.put("basic_result", "初步检测结果(仅供参考):\\n\\n低渗性血管张力异常 \\n\\n有必要排除血凝异常 血凝升高 \\n\\n建议向胃肠病专家(精于胃十二指肠炎)进一步咨询 \\n\\n血管张力异常,静脉循环障碍 酒精性高血压 \\n\\n第三脑室宽度=6.42 \\n\\n建议向妇科医生进一步咨询 其它器官血流量占=4.1 \\n\\nTiffeneau指数持续减少83.6 (Tiffeneau测试) \\n\\n----------------------------------------------------------------------------------------------------------\\n\\n\\n");

        JSONObject details = new JSONObject();
        DecimalFormat df = new java.text.DecimalFormat("######.00");
        for (int i = 1; i <= 125; i++) {
            details.put(String.valueOf(i), df.format(Math.random() * 100)); // 125 items of the report.
        }
        report.put("detail", details);


        report.put("name", "user name"); // user name
        report.put("number", "report number"); //report number. Leave it empty if not exist. Such as : report.put("number", "");
        report.put("pulse", 79);
        report.put("report_date", System.currentTimeMillis()); // physical examination time of this report
        report.put("respiratory_rate", 18);
        report.put("sex", 0); // 0 is male;  1 is female
        report.put("stable", "99999");
        report.put("weight", 45);
        report.put("title", "AMP无创健康评估报告"); // report title
        report.put("account", Constants.USR_ACC); // user account
        report.put("machine_num", "10311212");//machine serial

//        /*
//         * Some other temperature serial which not display on the report.
//         */
//        report.put("T0", "{{{{{{{{{{{{{{{{{{{{{{");
//        report.put("T1", "............");
//        report.put("T2", "+++++++++++");
//        report.put("T3", "@@@@@@@@@@@");
//        report.put("T4", "!!!!!!!!!!!!");
//
//        /*
//         * The ID of the conclusion.
//         */
//        JSONArray basicResIds = new JSONArray();
//        basicResIds.put(1);
//        basicResIds.put(2);
//        basicResIds.put(3);
//        basicResIds.put(4);
//        report.put("basic_result_ids", basicResIds);

        AMP_REPORT = report.toString();
        // use http://www.jsoneditoronline.org/ to view the json easily
        System.out.println(AMP_REPORT);
    }
}