public void saveAndWriteRecent(boolean saveEmpty) {
    Database database = new Database(c);

    // We need server address or SSH server to be filled out to save. Otherwise,
    // we keep adding empty connections.
    // However, if there is partial data from a URI, we can present the edit screen.
    // Alternately, perhaps we could process some extra data
    if ((getConnectionType() == Constants.CONN_TYPE_SSH && getSshServer().equals("")
            || getAddress().equals(""))
        && !saveEmpty) {
      return;
    }

    SQLiteDatabase db = database.getWritableDatabase();
    db.beginTransaction();
    try {
      save(db);
      MostRecentBean mostRecent = getMostRecent(db);
      if (mostRecent == null) {
        mostRecent = new MostRecentBean();
        mostRecent.setConnectionId(get_Id());
        mostRecent.Gen_insert(db);
      } else {
        mostRecent.setConnectionId(get_Id());
        mostRecent.Gen_update(db);
      }
      db.setTransactionSuccessful();
    } finally {
      db.endTransaction();
      db.close();
    }
    if (db.isOpen()) {
      db.close();
    }
  }
 public JSONArray insertObservationData(
     String patientUuid, String visitUuid, JSONArray observationData) throws JSONException {
   SQLiteDatabase db = mDBHelper.getWritableDatabase();
   ContentValues values = new ContentValues();
   for (int index = 0; index < observationData.length(); index++) {
     JSONObject observation = observationData.getJSONObject(index);
     String observationUuid = observation.getString("uuid");
     if (observation.getJSONArray("groupMembers").length() > 0) {
       values.put("uuid", observationUuid);
       values.put("patientUuid", patientUuid);
       values.put("visitUuid", visitUuid);
       values.put("conceptName", observation.getJSONObject("concept").getString("name"));
       values.put("encounterUuid", observation.getString("encounterUuid"));
       values.put("observationJson", String.valueOf(observation));
       db.insertWithOnConflict("observation", null, values, SQLiteDatabase.CONFLICT_REPLACE);
     } else {
       deleteObservationByUuid(db, observationUuid, patientUuid);
     }
   }
   db.close();
   return observationData;
 }