山东大学项目实训之安卓reportActivity上报不良事件

安卓reportActivity上报不良事件之普通事件上报
在这里插入图片描述
不良事件类型共有七中,前六种是普通事件
上报流程spinner选择事件类型
在这里插入图片描述
上报患者信息可以根据住院号或门诊号或就诊卡号从his系统获得患者信息自动加载
在这里插入图片描述
发生场所与患者信息来自数据库可更改的数据
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
级别与类别也是来自数据库可维护的数据
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
实现上传附件、暂存、匿名上报、实名上报等功能,见专栏中其他文章
顶部进度栏

  <com.anton46.stepsview.StepsView
            android:id="@+id/stepsView"
            android:layout_width="match_parent"
            android:layout_height="84dp"
            android:background="@color/colorWhiteblue"
            android:outlineAmbientShadowColor="@color/colorWhiteblue"
            android:outlineSpotShadowColor="@color/colorPrimary"
            android:textAlignment="gravity" />

需要在build.gradle中引入dependency
implementation ‘com.anton46:stepsview:0.0.2’

 mStepsView = findViewById(R.id.stepsView);

        spinnerGrade = findViewById(R.id.types_selection);
        spinnermethod = findViewById(R.id.identify_selection);
        final List<String> list_description = new ArrayList<String>();


        String[] steps = new String[]{"选择类型", "患者资料", "基本情况", "事件级类"};
        methods = new String[]{"住院号", "门诊号", "就诊卡"};
        key_edit = findViewById(R.id.edit_identify);
        mStepsView.setLabels(steps)
                //设置完成的步数
                .setBarColorIndicator(getResources().getColor(R.color.colorPrimary))
                .setProgressColorIndicator(getResources().getColor(R.color.colorLightblue))
                .setLabelColorIndicator(getResources().getColor(R.color.colorPrimary))
                .setCompletedPosition(0)
                .drawView();

获取事件类型

sharedPreferences = getSharedPreferences("tokenInfo", MODE_PRIVATE);//token2
        name2 = sharedPreferences.getString("token", "");
        Log.i("token", "token=" + name2);


        OkHttpClient okHttpClient2 = new OkHttpClient();
        //2.创建Request对象,设置一个url地址(百度地址),设置请求方式。
        Request request2 = new Request.Builder()
                .header("token", name2)
                .url("http://43.138.24.19:80/adverseEventPrimaryClassificationDicts").method("GET", null).build();
        //3.创建一个call对象,参数就是Request请求对象
        okhttp3.Call call2 = okHttpClient2.newCall(request2);
        //4.请求加入调度,重写回调方法
        call2.enqueue(new Callback() {
            @Override
            public void onResponse(@NotNull Call call, @NotNull okhttp3.Response response) throws IOException {
                Gson gson = new Gson();
                String msg;

                msg = response.body().string();
                Log.v("body", "body=" + msg);

                Type listType = new TypeToken<ResponseTypes<List<eventtype>>>() {
                }.getType();
                ResponseTypes data2 = gson.fromJson(msg, listType);
                //ResponseData data2 = gson.fromJson(msg,ResponseData.class);
                typeslist = data2.getData2();
                ;
                for (int i = 0; i < typeslist.size(); i++) {
                    int temp = typeslist.get(i).getId();
                    list_description.add(typeslist.get(i).getDescription());
                    Log.v("body", "body=" + temp);
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ArrayAdapter<String> typesAdapter = new ArrayAdapter(ReportActivity.this, android.R.layout.simple_spinner_dropdown_item, list_description);
                        spinnerGrade.setAdapter(typesAdapter);
                        //设置默认选中项

                    }
                });

            }

            //请求失败执行的方法
            @Override
            public void onFailure(Call call, IOException e) {
            }
            //请求成功执行的方法

        });

上报事件类型并获取用户信息

public void TypesPost(View view) {
        selected_types = spinnerGrade.getSelectedItem().toString();
        for (int i = 0; i < typeslist.size(); i++) {
            if (selected_types.contentEquals(typeslist.get(i).getDescription()) ) {
                selected_primary_type_id = typeslist.get(i).getId();
            }
        }

        mStepsView.setCompletedPosition(1);
        report1.setVisibility(GONE);
        report2.setVisibility(View.VISIBLE);
        ArrayAdapter<String> methodsAdapter = new ArrayAdapter(ReportActivity.this, android.R.layout.simple_spinner_dropdown_item, methods);
        spinnermethod.setAdapter(methodsAdapter);
        //设置默认选中项


        spinnermethod.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                final String selected_method = spinnermethod.getSelectedItem().toString();
                Log.i("选择的方法",selected_method);
                switch (selected_method) {
                    case "住院号":
                        method_selection = 0;
                        break;
                    case "门诊号":
                        method_selection = 1;
                        break;
                    case "就诊卡":
                        Log.i("2","2");
                        method_selection = 2;
                        break;
                    default:
                        Toast.makeText(getApplicationContext(),"请正确选择查找方法",Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
                Toast.makeText(getApplicationContext(),"请正确选择查找方法",Toast.LENGTH_LONG).show();
            }
        });



        key_edit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    key_selection = key_edit.getText().toString();
                    OkHttpClient okHttpClient = new OkHttpClient();

                    //2.创建Request对象,设置一个url地址(百度地址),设置请求方式。
                    Request request = new Request.Builder()
                            .header("token", name2)
                            .url("http://43.138.24.19:80/patientInfo/" + key_selection + "/" + method_selection).method("GET", null).build();
                    //3.创建一个call对象,参数就是Request请求对象
                    Log.i("data",request.toString());
                    okhttp3.Call call = okHttpClient.newCall(request);
                    //4.请求加入调度,重写回调方法
                    call.enqueue(new Callback() {
                        @Override
                        public void onFailure(@NotNull Call call, @NotNull IOException e) {

                        }

                        @Override
                        public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
                            try{
                            Gson gson = new Gson();
                            String msg = response.body().string();
                            Log.v("body", "body=" + msg);
                            data = gson.fromJson(msg, ResponsePatientInfo.class);

                            Log.i("data", data.toString());
                            if(data.getCode()==200){
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {

                                    if (data != null) {
                                        patientInfo patient = data.getData();
                                        String patient_age = patient.getAge();
                                        Toast.makeText(getApplicationContext(), "获取用户信息", Toast.LENGTH_SHORT).show();
                                        name.setText(patient.getName(), TextView.BufferType.NORMAL);
                                        name.setEnabled(false);
                                        age.setText(patient_age, TextView.BufferType.NORMAL);
                                        age.setEnabled(false);
                                        clinicalDiagnosis.setText(patient.getClinicalDiagnosis(), TextView.BufferType.NORMAL);
                                        clinicalDiagnosis.setEnabled(false);
                                        if (patient.getSex() == 1) {
                                            sex.setChecked(true);
                                        } else if (patient.getSex() == 2) {
                                            sex2.setChecked(true);
                                        }
                                        sex.setClickable(false);
                                        sex2.setClickable(false);
                                    }
                                }
                            });}
                        }catch(Exception e){}
                    }
                    });

                }
                return false;
            }
        });

    }

上报患者信息并获取时间发生地点字典,搞成radiogroup以及患者状态搞成CheckBox


    public void patientInfoPost(View view) {
        if (key_edit.getText().toString().isEmpty()) {
            Toast.makeText(getApplicationContext(), "请填写患者信息", Toast.LENGTH_SHORT).show();
        }else{
        mStepsView.setCompletedPosition(2);
        report2.setVisibility(GONE);
        report3.setVisibility(View.VISIBLE);

        OkHttpClient okHttpClient = new OkHttpClient();
        //2.创建Request对象,设置一个url地址(百度地址),设置请求方式。
        Request request = new Request.Builder()
                .header("token", name2)
                .url("http://43.138.24.19:80/incidentOccurLocationDict").method("GET", null).build();
        //3.创建一个call对象,参数就是Request请求对象
        okhttp3.Call call = okHttpClient.newCall(request);
        //4.请求加入调度,重写回调方法
        call.enqueue(new Callback() {
            @Override
            public void onResponse(@NotNull Call call, @NotNull okhttp3.Response response) throws IOException {
                Gson gson = new Gson();
                String msg = response.body().string();
                Log.v("body", "body=" + msg);

                Type listType = new TypeToken<ResponseTypes<List<eventtype>>>() {
                }.getType();

                ResponseTypes data2 = gson.fromJson(msg, listType);
                if(data2.getCode()==200){
                //ResponseData data2 = gson.fromJson(msg,ResponseData.class);
                final List<eventtype> typeslist2 = data2.getData2();
                ;
                for (int i = 0; i < typeslist2.size(); i++) {
                    int temp = typeslist2.get(i).getId();

                    Log.v("body", "body=" + temp);
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {

                        for (int i = 0; i < typeslist2.size(); i++) {
                            String temp = typeslist2.get(i).getDescription();
                            RadioButton radioButton = new RadioButton(getApplicationContext());
                            radioButton.setText(temp);
                            radioButton.setTextSize(20);
                            occur_place.addView(radioButton);
                            Log.v("body", "body=" + temp);
                        }
                        occur_place.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                            @Override
                            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                                RadioButton radioButton2 = (RadioButton) findViewById(occur_place.getCheckedRadioButtonId());
                                String selected_occur_place_name = radioButton2.getText().toString();
                                Log.i("secondclassname", selected_occur_place_name);
                                for (int j = 0; j < typeslist2.size(); j++) {
                                    if (selected_occur_place_name == typeslist2.get(j).getDescription()) {
                                        selected_occur_place_id = typeslist2.get(j).getId();
                                    }
                                }
                            }
                        });
                        //ArrayAdapter<String> typesAdapter = new ArrayAdapter(ReportActivity.this, android.R.layout.simple_spinner_dropdown_item, list_description);
                        //spinnerGrade.setAdapter(typesAdapter);
                        //设置默认选中项
                        //spinnerGrade.setSelection(0);
                    }
                });}

            }

            //请求失败执行的方法
            @Override
            public void onFailure(Call call, IOException e) {
            }
            //请求成功执行的方法

        });
        OkHttpClient okHttpClient2 = new OkHttpClient();

        //2.创建Request对象,设置一个url地址(百度地址),设置请求方式。
        Request request2 = new Request.Builder()
                .header("token", name2)
                .url("http://43.138.24.19:80/patientStateBeforeIncidentDicts").method("GET", null).build();
        //3.创建一个call对象,参数就是Request请求对象
        okhttp3.Call call2 = okHttpClient2.newCall(request2);
        //4.请求加入调度,重写回调方法
        call2.enqueue(new Callback() {
            @Override
            public void onResponse(@NotNull Call call2, @NotNull okhttp3.Response response2) throws IOException {
                Gson gson = new Gson();
                String msg2 = response2.body().string();
                Log.v("body", "body=" + msg2);

                Type listType = new TypeToken<ResponseTypes<List<eventtype>>>() {
                }.getType();
                ResponseTypes data3 = gson.fromJson(msg2, listType);
                //ResponseData data2 = gson.fromJson(msg,ResponseData.class);
                final List<eventtype> typeslist3 = data3.getData2();
                ;
                for (int i = 0; i < typeslist3.size(); i++) {
                    int temp = typeslist3.get(i).getId();
                    Log.v("body", "body=" + temp);
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        for (int i = 0; i < typeslist3.size(); i++) {
                            String temp = typeslist3.get(i).getDescription();
                            final CheckBox checkBox = new CheckBox(getApplicationContext());
                            checkBox.setText(temp);
                            checkBox.setTextSize(20);
                            occur_patient.addView(checkBox);
                            Log.v("body", "body=" + temp);
                            checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                                @Override
                                public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                                    String selected_occur_patient_status = checkBox.getText().toString();
                                    int count = 0;
                                    for (int j = 0; j < typeslist3.size(); j++) {
                                        if (selected_occur_patient_status == typeslist3.get(j).getDescription()) {

                                            int selected_occur_patient_id = typeslist3.get(j).getId();


                                            set.add(selected_occur_patient_id);
                                        }
                                    }

                                }
                            });

                        }
                        //ArrayAdapter<String> typesAdapter = new ArrayAdapter(ReportActivity.this, android.R.layout.simple_spinner_dropdown_item, list_description);
                        //spinnerGrade.setAdapter(typesAdapter);
                        //设置默认选中项
                        //spinnerGrade.setSelection(0);
                    }
                });

            }

            //请求失败执行的方法
            @Override
            public void onFailure(Call call, IOException e) {
            }
            //请求成功执行的方法

        });
    }
    }

普通不良事件上报

 public void NormalReportPost(View view){
        //selected_primary_type_id;

        if (selected_event_rank ==0 || selected_second_type_id==0) {
            Toast.makeText(getApplicationContext(), "请填写事件信息", Toast.LENGTH_SHORT).show();
        } else {
            OkHttpClient mOkHttpClient = new OkHttpClient();
//2,创建Request
            key_selection = key_edit.getText().toString();
            //MultipartBody.Part reportlist = new MultipartBody.Part().body().
            JsonArrayBean jsonarray = new JsonArrayBean();
            String[] newone = new String[]{"1", "2"};
            NormalReport normalReport = new NormalReport();
            normalReport.setCategory(selected_second_type_id);
            normalReport.setCategoryPrimary(selected_primary_type_id);
            normalReport.setOccurExactLocation(event_occur_exact_place_report);
            if (method_selection == 0) {
                normalReport.setInpatientNum(key_selection);

            } else if (method_selection == 1) {
                normalReport.setOutpatientNum(key_selection);
            } else if (method_selection == 2) {
                normalReport.setMedicalCardNum(key_selection);
            }
            normalReport.setIsAnonymous(0);
            normalReport.setDescription(event_description_report);
            normalReport.setLevel(selected_event_rank);
            normalReport.setIncidentOccurLocation(selected_occur_place_id);
            normalReport.setOccurTime(timeStamp);
            Log.i("timeStamp",timeStamp);
            nameList = nameList2.toArray(new String[nameList2.size()]);
            if(nameList!=null){normalReport.setNewNameList(nameList);}
            else{
                normalReport.setNewNameList(null);
            }
            Integer[] patientStates = new Integer[set.size()];
            set.toArray(patientStates);
            normalReport.setPatientStateBeforeIncident(patientStates);

            Gson gson = new Gson();
            //使用Gson将对象转换为json字符串
            String json = gson.toJson(normalReport);

            RequestBody body = RequestBody.create(MediaType.parse("application/json"), json);
            Log.i("requestbody", json);

            Request request = new Request.Builder()
                    .header("token", name2)
                    .url("http://43.138.24.19/adverseEventReport/submit").post(body).build();
//3,创建call对象并将请求对象添加到调度中
            Log.i("request", request.toString());
            mOkHttpClient.newCall(request).enqueue(new Callback() {
                @Override
                public void onFailure(Call call, IOException e) {
                    Log.e("测试", e + "");
                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    Log.e("测试", response.code() + "");
                    if (response.isSuccessful()) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(getApplicationContext(),"实名上报成功",Toast.LENGTH_SHORT).show();
                                Intent intent = new Intent(ReportActivity.this,SlideActivity.class);
                                startActivity(intent);
                            }

                        });
                    }
                }

            });
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值