我正在sqlite数据库中保存患者详细信息。患者详细信息包括血压,糖,肌酐,日期,入院时间。关于BP,我将Systolic和Diastolic值存储在数据库中。我想在图表中显示用户输入的值和日期。我试图在x轴上显示存储在数据库中的日期。但我没有在x轴上获得日期。
ViewBloodPressureActivity.java
public class ViewBloodPressureActivity extends Activity {
SQLiteDatabase db;
String pName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_blood_pressure);
Intent intent = getIntent();
final String action = intent.getAction();
String gName = intent.getExtras().getString("GroupName");
pName = intent.getExtras().getString("PatientName");
Cursor cursor = null;
TextView tvPatientName = (TextView) this.findViewById(R.id.textViewPatientNameViewBP);
TextView tvDate = (TextView) this.findViewById(R.id.textViewPatientBPDate);
TextView tvTime = (TextView) this.findViewById(R.id.textViewPatientBPTime);
TextView tvSystolic = (TextView) this.findViewById(R.id.textViewPatientBPSystolic);
TextView tvDiastolic = (TextView) this.findViewById(R.id.textViewPatientBPDiastolic);
TextView tvNumOfRecords = (TextView) this.findViewById(R.id.textViewPatientBPNumOfRecords);
Button back = (Button) this.findViewById(R.id.buttonPatientBPBack);
Button trend = (Button) this.findViewById(R.id.buttonPatientBPTrend);
tvPatientName.setText(pName);
openPatientBPDatabase();
cursor = db.rawQuery("SELECT * FROM PatntBP WHERE PatientName = '"+pName+"';", null);
int rows = cursor.getCount();
tvNumOfRecords.setText(" "+rows+" for this patient");
switch (rows) {
case 0:Toast.makeText(getApplicationContext(), "No records in Database", Toast.LENGTH_LONG).show();break;
case 1: { cursor.moveToFirst();
tvDate.setText(cursor.getString(cursor.getColumnIndex("date")));
tvTime.setText(cursor.getString(cursor.getColumnIndex("time")));
tvSystolic.setText(cursor.getString(cursor.getColumnIndex("systolic")));
tvDiastolic.setText(cursor.getString(cursor.getColumnIndex("diastolic")));
break;
}
default : {
Log.v("BPDB", "There are :"+cursor.getCount()+" records.");
cursor.moveToLast();
tvDate.setText(cursor.getString(cursor.getColumnIndex("date")));
tvTime.setText(cursor.getString(cursor.getColumnIndex("time")));
tvSystolic.setText(cursor.getString(cursor.getColumnIndex("systolic")));
tvDiastolic.setText(cursor.getString(cursor.getColumnIndex("diastolic")));
Toast.makeText(getApplicationContext(), "Use Charts to view the Data", Toast.LENGTH_LONG).show();
}
}
closePatientBPDatabase();
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(ViewBloodPressureActivity.this, ListPatientForViewHDActivity.class);
intent.setAction(action);
startActivity(intent);
}
});
trend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(ViewBloodPressureActivity.this, TrendAnalysisForBPActivity.class);
intent.setAction(action);
intent.putExtra("PatientName", pName);
startActivity(intent);
}
});
}
private void closePatientBPDatabase() {
// TODO Auto-generated method stub
db.close();
}
private void openPatientBPDatabase() {
// TODO Auto-generated method stub
db = openOrCreateDatabase("HCDatabase", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS PatntBP (GroupName VARCHAR, PatientName VARCHAR, systolic VARCHAR, diastolic VARCHAR, date VARCHAR, time VARCHAR);");
}
public void lineGraphHandler(View view) {
LineGraph lineGraph = new LineGraph();
Intent lineIntent = lineGraph.getIntent(this);
startActivity(lineIntent);
}
private class LineGraph {
public Intent getIntent(Context context) {
//SQLiteDatabase db = context.openOrCreateDatabase("HCDatabase", 0, null);
// Cursor cursor = db.rawQuery("SELECT * FROM PatntBP", new String[] { pName });
SQLiteDatabase db1 = openOrCreateDatabase("HCDatabase", MODE_PRIVATE, null);
String sqlQuery = "SELECT * FROM PatntBP where PatientName = '"+pName+"';";
Log.v("BP Query", sqlQuery);
Cursor cursor = db1.rawQuery(sqlQuery, null);
int rows = cursor.getCount();
int y[] = new int[rows];
int y1[] = new int[rows];
if (cursor.getCount() > 0) {
cursor.moveToFirst();
int i = 0;
do {
String name = cursor.getString(cursor.getColumnIndex("PatientName"));
String systolic = cursor.getString(cursor.getColumnIndex("systolic"));
String diastolic = cursor.getString(cursor.getColumnIndex("diastolic"));
String date = cursor.getString(cursor.getColumnIndex("date"));
String[] ss = date.split("/");
Log.v("BP Query", "Row : "+name+" "+systolic+" "+diastolic+" "+ss[1]);
y[i] = Integer.parseInt(systolic);
y1[i] = Integer.parseInt(diastolic);
i++;
} while (cursor.moveToNext());
}
db1.close();
int x[] = {1,2,3,4,5,6,7,8,9,10};
int x1[] = {1,2,3,4,5,6,7,8,9,10};
TimeSeries series = new TimeSeries("Systolic");
for (int i = 0; i < y.length; i++) {
series.add(x[i], y[i]);
}
TimeSeries series1 = new TimeSeries("Diastolic");
for (int i = 0; i < y1.length; i++) {
series1.add(x1[i], y1[i]);
}
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(series);
dataset.addSeries(series1);
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setPointStyle(PointStyle.CIRCLE);
renderer.setColor(Color.RED);
XYSeriesRenderer renderer1 = new XYSeriesRenderer();
renderer1.setPointStyle(PointStyle.DIAMOND);
renderer1.setColor(Color.BLUE);
mRenderer.setChartTitle("Blood Pressure Variation");
mRenderer.addSeriesRenderer(renderer);
mRenderer.addSeriesRenderer(renderer1);
mRenderer.setYAxisMax(200);
mRenderer.setYAxisMin(40);
Intent intent = ChartFactory.getTimeChartIntent(context, dataset, mRenderer, "Blood Pressure Graph");
return intent;
}
}
}
EnterBloodPressureActivity.java
public class EnterBloodPressureActivity extends Activity {
SQLiteDatabase db;
Date date;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enter_blood_pressure);
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm");
Date date = new Date();
String dateStringAndTime = sdf.format(date);
String dateAndTime[] = dateStringAndTime.split(" ");
String dateString = dateAndTime[0];
String timeString = dateAndTime[1];
final EditText etSystolic = (EditText) this.findViewById(R.id.editTextSystolic);
final EditText etDiastolic = (EditText) this.findViewById(R.id.editTextDiastolic);
final EditText etDate = (EditText) this.findViewById(R.id.editTextBPDate);
etDate.setText(dateString);
final EditText etTime = (EditText) this.findViewById(R.id.editTextBPTime);
etTime.setText(timeString);
TextView patientName = (TextView) this.findViewById(R.id.textViewEnterBPDataPatientName);
Intent intent = getIntent();
final String action = intent.getAction();
patientName.setText(intent.getExtras().getString("PatientName"));
Button save = (Button) this.findViewById(R.id.buttonBPDataSave);
Button reset = (Button) this.findViewById(R.id.buttonBPDataReset);
Button back = (Button) this.findViewById(R.id.buttonBPDataBack);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
openPatientBPDatabase();
//get GroupName and PatientName
Intent intent = getIntent();
String gName = intent.getExtras().getString("GroupName");
String pName = intent.getExtras().getString("PatientName");
// ensure input data is not null
String systolic = etSystolic.getText().toString();
String diastolic = etDiastolic.getText().toString();
String date = etDate.getText().toString();
String time = etTime.getText().toString();
if (!systolic.equals("") && !diastolic.equals("") && !date.equals("") && !time.equals("")) {
String sqlStmt = "INSERT INTO PatntBP VALUES('"+gName+"', '"+pName+"', '"+systolic+"', '"+diastolic+"', '"+date+"', '"+time+"');";
Log.v("BP DEBUG", sqlStmt);
db.execSQL(sqlStmt);
closePatientBPDatabase();
Intent intent1 = new Intent(EnterBloodPressureActivity.this, ListPatientForEnterHDActivity.class);
intent1.setAction(action);
Toast.makeText(getApplicationContext(), "Data successfully entered", Toast.LENGTH_LONG).show();
startActivity(intent1);
} else {
Toast.makeText(getApplicationContext(), "No blank values allowed", Toast.LENGTH_LONG).show();
}
}
});
reset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
etSystolic.setText("");
etDiastolic.setText("");
etDate.setText("");
etTime.setText("");
}
});
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(EnterBloodPressureActivity.this, ListPatientForEnterHDActivity.class);
intent.setAction(action);
startActivity(intent);
}
});
}
protected void closePatientBPDatabase() {
// TODO Auto-generated method stub
db.close();
}
protected void openPatientBPDatabase() {
// TODO Auto-generated method stub
db = openOrCreateDatabase("HCDatabase", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS PatntBP (GroupName VARCHAR, PatientName VARCHAR, systolic VARCHAR, diastolic VARCHAR, date VARCHAR, time VARCHAR);");
}
}