@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(); switch (item.getItemId()) { // Respond to the action bar's Up/Home button case android.R.id.home: finish(); case R.id.action_save: DatabaseHandler databaseHandler = new DatabaseHandler(AddClinicalNotesActivity.this); try { if (historyObj._date != null) databaseHandler.addHistory(historyObj); if (examObj._date != null) databaseHandler.addExam(examObj); if (treatmentOb._date != null) databaseHandler.addTreatment(treatmentOb); if (Other_Notes_Activity.otherObj != null && Other_Notes_Activity.otherObj.size() > 0) { for (int i = 0; i < Other_Notes_Activity.otherObj.size(); i++) { databaseHandler.addOther(Other_Notes_Activity.otherObj.get(i)); } Other_Notes_Activity.otherObj.clear(); } } catch (Exception e) { e.printStackTrace(); } finish(); return true; } return super.onOptionsItemSelected(item); }
public Patient getPatientDataEdit(int id) { SQLiteDatabase myDataBase = openOrCreateDatabase("patientManager", MODE_PRIVATE, null); DatabaseHandler dbHandler = new DatabaseHandler(getApplicationContext()); dbHandler.onCreate(myDataBase); Patient patient = new Patient(); patient = dbHandler.getPatientForProfile(id); return patient; }
public void getDocumentsList(int id) { DatabaseHandler dbHandler = new DatabaseHandler(getApplicationContext()); ArrayList<Item> nameWithImage = new ArrayList<Item>(); Item displayDocument = new Item(); Patient patient = dbHandler.getPatient(id); setTitle(patient.get_name() + "'s Documents"); Bitmap bmpImage = null; document_obj doc_obj = new document_obj(); List<document_obj> documentList = dbHandler.getDocuments(id); for (int i = 0; i < documentList.size(); i++) { if ((documentList.get(i).get_doc_name() != null) || (documentList.get(i).get_doc_name() != null)) { displayDocument.setTitle(documentList.get(i).get_doc_name()); displayDocument.setDiagnosis(documentList.get(i).get_doc_path()); if (documentList.get(i).get_bmp() == null) { doc_obj = documentList.get(i); doc_obj = PhotoHelper.addMissingBmp(doc_obj); dbHandler.updateDocument(doc_obj, "0"); } bmpImage = BitmapFactory.decodeByteArray( documentList.get(i).get_bmp(), 0, documentList.get(i).get_bmp().length); displayDocument.setBmp(bmpImage); displayDocument.setPatient_id(documentList.get(i).get_id()); nameWithImage.add(displayDocument); displayDocument = new Item(); } } displayDocuments(nameWithImage); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Calendar c = Calendar.getInstance(); final DatabaseHandler dbHandler = new DatabaseHandler(getApplicationContext()); Resources resources = getResources(); Patient patient = dbHandler.getPatient(pid); SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy"); String formattedDate = df.format(c.getTime()); if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) { Bitmap bitmap; bitmap = BitmapFactory.decodeFile(doc_obj.get_doc_path()); ByteArrayOutputStream ostream = new ByteArrayOutputStream(); // save image into gallery bitmap.compress(Bitmap.CompressFormat.JPEG, 20, ostream); try { FileOutputStream fout = new FileOutputStream(photoFile); fout.write(ostream.toByteArray()); fout.close(); } catch (Exception e) { e.printStackTrace(); } // doc_obj.set_bmp(PhotoHelper.getBitmapAsByteArray(Bitmap.createScaledBitmap(bitmap,120,120,false))); doc_obj = PhotoHelper.addMissingBmp(doc_obj); if (doc_obj.get_bmp() != null) { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "IMG_" + timeStamp; doc_obj.set_doc_name(imageFileName); doc_obj.set_date(formattedDate); patient.set_last_seen_date(formattedDate); dbHandler.updatePatient(patient); dbHandler.addDocument(doc_obj); } utility.recreateActivityCompat(documents.this); // utility.recreateActivityCompat(this); } else if ((requestCode == PICKFILE_RESULT_CODE) && ((data != null) && (data.getData() != null))) { Uri uri = data.getData(); File file = null; String file_name = ""; String file_path = ""; ; // "/mnt/sdcard/FileName.mp3" try { file = new File(uri.getPath()); String a = file.getAbsolutePath(); } catch (Exception e) { e.printStackTrace(); } if (uri.getScheme().compareTo("content") == 0) { Cursor cursor = getContentResolver().query(uri, null, null, null, null); if (cursor.moveToFirst()) { int column_index = cursor.getColumnIndexOrThrow( MediaStore.Images.Media .DATA); // Instead of "MediaStore.Images.Media.DATA" can be used "_data" Uri filePathUri = Uri.parse(cursor.getString(column_index)); file_name = filePathUri.getLastPathSegment(); file_path = filePathUri.getPath(); } } else { Uri filePathUri = Uri.fromFile(file); file_name = filePathUri.getLastPathSegment(); file_path = filePathUri.getPath(); } if (file_name.contains(".doc")) { doc_obj.set_bmp( PhotoHelper.getBitmapAsByteArray( BitmapFactory.decodeResource(resources, R.drawable.ic_doc))); } else if (file_name.contains(".pdf")) { doc_obj.set_bmp( PhotoHelper.getBitmapAsByteArray( BitmapFactory.decodeResource(resources, R.drawable.ic_pdf))); } else if (file_name.contains(".txt")) { doc_obj.set_bmp( PhotoHelper.getBitmapAsByteArray( BitmapFactory.decodeResource(resources, R.drawable.ic_txt))); } else if ((file_name.contains(".jpg")) || (file_name.contains(".png"))) { doc_obj.set_bmp(PhotoHelper.getBitmapAsByteArray(BitmapFactory.decodeFile(file_path))); } doc_obj.set_doc_name(file_name); doc_obj.set_doc_path(file_path); doc_obj.set_id(pid); doc_obj.set_date(formattedDate); dbHandler.updatePatient(patient); dbHandler.addDocument(doc_obj); Toast.makeText( this, "File Name & PATH are:" + file_name + "\n" + file_path, Toast.LENGTH_LONG) .show(); // } } utility.recreateActivityCompat(documents.this); }