Source:
<code>public Observable<List<Visit>> getVisitsByPatientID(final Long patientID) { <START> return createObservable(() -> { <END> List<Visit> visits = new ArrayList<>(); DBOpenHelper helper = OpenMRSDBOpenHelper.getInstance().getDBOpenHelper(); String where = String.format("%s = ?", VisitTable.Column.PATIENT_KEY_ID); String[] whereArgs = new String[]{patientID.toString()}; String orderBy = VisitTable.Column.START_DATE + " DESC"; final Cursor cursor = helper.getReadableDatabase().query(VisitTable.TABLE_NAME, null, where, whereArgs, null, null, orderBy); if (null != cursor) { try { while (cursor.moveToNext()) { int visitUUID_CI = cursor.getColumnIndex(VisitTable.Column.UUID); int visitID_CI = cursor.getColumnIndex(VisitTable.Column.ID); int visitType_CI = cursor.getColumnIndex(VisitTable.Column.VISIT_TYPE); int visitPlace_CI = cursor.getColumnIndex(VisitTable.Column.VISIT_PLACE); int visitStart_CI = cursor.getColumnIndex(VisitTable.Column.START_DATE); int visitStop_CI = cursor.getColumnIndex(VisitTable.Column.STOP_DATE); int visitPatientID_CI = cursor.getColumnIndex(VisitTable.Column.PATIENT_KEY_ID); Visit visit = new Visit(); visit.setUuid(cursor.getString(visitUUID_CI)); visit.setId(cursor.getLong(visitID_CI)); visit.setVisitType(new VisitType(cursor.getString(visitType_CI))); visit.setLocation(new Location(cursor.getString(visitPlace_CI))); visit.setStartDatetime(cursor.getString(visitStart_CI)); visit.setStopDatetime(cursor.getString(visitStop_CI)); visit.setEncounters(new EncounterDAO().findEncountersByVisitID(visit.getId())); visit.setPatient(new PatientDAO().findPatientByID(String.valueOf(cursor.getLong(visitPatientID_CI)))); visits.add(visit); } } finally { cursor.close(); } } return visits; }); }</code><technical_language>call createObservableIO IO purpose (db operations)</technical_language>

Target:
public Observable<List<Visit>> getVisitsByPatientID(final Long patientID) { return createObservableIO(() -> { List<Visit> visits = new ArrayList<>(); DBOpenHelper helper = OpenMRSDBOpenHelper.getInstance().getDBOpenHelper(); String where = String.format("%s = ?", VisitTable.Column.PATIENT_KEY_ID); String[] whereArgs = new String[]{patientID.toString()}; String orderBy = VisitTable.Column.START_DATE + " DESC"; final Cursor cursor = helper.getReadableDatabase().query(VisitTable.TABLE_NAME, null, where, whereArgs, null, null, orderBy); if (null != cursor) { try { while (cursor.moveToNext()) { int visitUUID_CI = cursor.getColumnIndex(VisitTable.Column.UUID); int visitID_CI = cursor.getColumnIndex(VisitTable.Column.ID); int visitType_CI = cursor.getColumnIndex(VisitTable.Column.VISIT_TYPE); int visitPlace_CI = cursor.getColumnIndex(VisitTable.Column.VISIT_PLACE); int visitStart_CI = cursor.getColumnIndex(VisitTable.Column.START_DATE); int visitStop_CI = cursor.getColumnIndex(VisitTable.Column.STOP_DATE); int visitPatientID_CI = cursor.getColumnIndex(VisitTable.Column.PATIENT_KEY_ID); Visit visit = new Visit(); visit.setUuid(cursor.getString(visitUUID_CI)); visit.setId(cursor.getLong(visitID_CI)); visit.setVisitType(new VisitType(cursor.getString(visitType_CI))); visit.setLocation(new Location(cursor.getString(visitPlace_CI))); visit.setStartDatetime(cursor.getString(visitStart_CI)); visit.setStopDatetime(cursor.getString(visitStop_CI)); visit.setEncounters(new EncounterDAO().findEncountersByVisitID(visit.getId())); visit.setPatient(new PatientDAO().findPatientByID(String.valueOf(cursor.getLong(visitPatientID_CI)))); visits.add(visit); } } finally { cursor.close(); } } return visits; }); }