-
Notifications
You must be signed in to change notification settings - Fork 2
/
MainScreen.java
173 lines (149 loc) · 6.36 KB
/
MainScreen.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package com.example.floatingtest;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Object;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import android.content.Intent;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.view.ViewGroup;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class MainScreen extends AppCompatActivity {
public final static String EXTRA_MESSAGE = "com.example.floatingtest.MESSAGE";
public final static String EXTRA_2 = "com.example.floatingtest.MESSAGE";
static Integer[] rxcuis = {313820, 1009145, 197321, 198520, 197636, 314119, 856987, 1603495, 1020477, 198603, 1011482, 998254, 997272};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
setContentView(R.layout.activity_main_screen);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// drugList.put("Acetaminophen", 313820);
//drugList.put("Adderall", 1009145);
//drugList.put("Alprazolam", 197321);
//drugList.put("Caffeine", 198520);
//drugList.put("Marijuana", 197636);
//drugList.put("Nicotine", 314119);
//drugList.put("Hydrocodone", 856987);
//drugList.put("Fentanyl", 1603495);
//drugList.put("Diphenhydramine", 1020477);
//drugList.put("Dimenhydrinate", 198603);
//drugList.put("Cetirizine", 1011482);
//drugList.put("Psuedoephedrine", 998254);
//drugList.put("Codeine", 997272);
}
public void printDrugInfo(View view) throws Exception
{
int rxcui = Integer.parseInt(view.getTag().toString());
drug d = pullAllInfo(rxcui);
//drugRelationship dr = pullRelationship(rxcui);
MessageBox("Drug: " + d.getRXTermProperties().getDisplayName());
}
public void MessageBox(String message)
{
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
//public void sendMessage(View view){
// Intent intent = new Intent(this, DisplayMessageActivity.class);
//EditText editText = (EditText) findViewById(R.id.edit_message);
//String message = editText.getText().toString();
//intent.putExtra(EXTRA_MESSAGE, message);
//startActivity(intent);
//}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main_screen, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public static String getHTML(String urlToRead) throws Exception {
StringBuilder result = new StringBuilder();
URL url = new URL(urlToRead);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
result.append(line);
}
rd.close();
return result.toString();
}
public static Object parseJSON(String JSON, String type)
{
Gson g = new GsonBuilder().create();
Object d = null;
if(type.equalsIgnoreCase("allInfo"))
{
d = g.fromJson(JSON, drug.class);
}
else if(type.equalsIgnoreCase("drugRelation"))
{
d = g.fromJson(JSON, drugRelationship.class);
}
return d;
}
public drug pullAllInfo(int rxcui) throws Exception
{
return (drug)parseJSON(getHTML("https://rxnav.nlm.nih.gov/REST/RxTerms/rxcui/"+rxcui+"/allinfo.json"), "allInfo");
}
public drugRelationship pullRelationship(int rxcui) throws Exception
{
drugRelationship d = (drugRelationship)parseJSON(getHTML("https://rxnav.nlm.nih.gov/REST/interaction/interaction.json?rxcui="+rxcui+"&sources=DrugBank"), "drugRelation");
return d;
}
public String[] severitySort(String[] array)
{
return null;
}
public void sendDrugMessage(View view)throws Exception {
Intent intent = new Intent(this, DisplayMessageActivity.class);
int rxcui = Integer.parseInt(view.getTag().toString());
drug d = pullAllInfo(rxcui);
drugRelationship dr = pullRelationship(rxcui);
String display;
interactionTypeGroup[] interactGroup = dr.getTypeGroup();
interactionType[] interactType = interactGroup[0].getInteractionType();
interactionPair[] p = interactType[0].getInteractionPair();
String doseForm = d.getRXTermProperties().getRXNormDoseForm();
display = "Drug: " + d.getRXTermProperties().getDisplayName() + "\nWay distributed: " + doseForm;
display+="\nReacts with: ";
for(int i=0; i<p.length; i++)
{
interactionConcept[] c = p[i].getinteractionConcept();
display += "\n" + c[1].getSourceConceptItem().getName() + ": " + p[i].getDescription();
}
intent.putExtra(EXTRA_MESSAGE, display);
//intent.putExtra(EXTRA_2, brand);
//intent.putExtra(EXTRA_MESSAGE, generic);
startActivity(intent);
}
}