static void sendEnrollmentChanges( DhisApi dhisApi, List<Enrollment> enrollments, boolean sendEvents) throws APIException { if (enrollments == null || enrollments.isEmpty()) { return; } for (int i = 0; i < enrollments.size(); i++) { /* workaround for not attempting to upload enrollments with local tei reference*/ Enrollment enrollment = enrollments.get(i); if (Utils.isLocal(enrollment.getTrackedEntityInstance())) { enrollments.remove(i); i--; } } Log.d(CLASS_TAG, "got this many enrollments to send:" + enrollments.size()); for (Enrollment enrollment : enrollments) { sendEnrollmentChanges(dhisApi, enrollment, sendEvents); } }
static void sendEnrollmentChanges(DhisApi dhisApi, Enrollment enrollment, boolean sendEvents) throws APIException { if (enrollment == null) { return; } if (Utils.isLocal( enrollment.getTrackedEntityInstance())) { // don't send enrollment with locally made uid return; } if (enrollment.getCreated() == null) { postEnrollment(enrollment, dhisApi); if (sendEvents) { List<Event> events = TrackerController.getEventsByEnrollment(enrollment.getLocalId()); sendEventChanges(dhisApi, events); } } else { if (sendEvents) { List<Event> events = TrackerController.getEventsByEnrollment(enrollment.getLocalId()); sendEventChanges(dhisApi, events); } putEnrollment(enrollment, dhisApi); } }