private static void postTrackedEntityInstance(
      TrackedEntityInstance trackedEntityInstance, DhisApi dhisApi) throws APIException {
    try {
      Response response = dhisApi.postTrackedEntityInstance(trackedEntityInstance);
      if (response.getStatus() == 200) {
        ImportSummary importSummary = getImportSummary(response);
        handleImportSummary(
            importSummary, FailedItem.TRACKEDENTITYINSTANCE, trackedEntityInstance.getLocalId());
        if (ImportSummary.SUCCESS.equals(importSummary.getStatus())
            || ImportSummary.OK.equals(importSummary.getStatus())) {

          // change state and save trackedentityinstance

          // trackedEntityInstance.setState(State.SYNCED);
          trackedEntityInstance.setFromServer(true);
          trackedEntityInstance.save();

          clearFailedItem(FailedItem.TRACKEDENTITYINSTANCE, trackedEntityInstance.getLocalId());
          UpdateTrackedEntityInstanceTimestamp(trackedEntityInstance, dhisApi);
        }
      }
    } catch (APIException apiException) {
      NetworkUtils.handleTrackedEntityInstanceSendException(apiException, trackedEntityInstance);
    }
  }
  private static void putEvent(Event event, DhisApi dhisApi) throws APIException {
    try {
      Response response = dhisApi.putEvent(event.getEvent(), event);
      if (response.getStatus() == 200) {
        ImportSummary importSummary = getImportSummary(response);
        handleImportSummary(importSummary, FailedItem.EVENT, event.getLocalId());
        if (ImportSummary.SUCCESS.equals(importSummary.getStatus())
            || ImportSummary.OK.equals(importSummary.getStatus())) {

          event.setFromServer(true);
          event.save();
          clearFailedItem(FailedItem.EVENT, event.getLocalId());
          UpdateEventTimestamp(event, dhisApi);
        }
      }
    } catch (APIException apiException) {
      NetworkUtils.handleEventSendException(apiException, event);
    }
  }
  private static void postEnrollment(Enrollment enrollment, DhisApi dhisApi) throws APIException {
    try {
      Response response = dhisApi.postEnrollment(enrollment);
      if (response.getStatus() == 200) {
        ImportSummary importSummary = getImportSummary(response);
        handleImportSummary(importSummary, FailedItem.ENROLLMENT, enrollment.getLocalId());

        if (ImportSummary.SUCCESS.equals(importSummary.getStatus())
            || ImportSummary.OK.equals(importSummary.getStatus())) {
          // change state and save enrollment

          // enrollment.setState(State.SYNCED);
          enrollment.setFromServer(true);
          enrollment.save();
          clearFailedItem(FailedItem.ENROLLMENT, enrollment.getLocalId());
          UpdateEnrollmentTimestamp(enrollment, dhisApi);
        }
      }
    } catch (APIException apiException) {
      NetworkUtils.handleEnrollmentSendException(apiException, enrollment);
    }
  }
 private static void postEvent(Event event, DhisApi dhisApi) throws APIException {
   try {
     Response response = dhisApi.postEvent(event);
     if (response.getStatus() == 200) {
       ImportSummary importSummary = getImportSummary(response);
       handleImportSummary(importSummary, FailedItem.EVENT, event.getLocalId());
       if (ImportSummary.SUCCESS.equals(importSummary.getStatus())
           || ImportSummary.OK.equals(importSummary.getStatus())) {
         // also, we will need to find UUID of newly created event,
         // which is contained inside of HTTP Location header
         Header header = NetworkUtils.findLocationHeader(response.getHeaders());
         // change state and save event
         event.setFromServer(true);
         event.save();
         clearFailedItem(FailedItem.EVENT, event.getLocalId());
         UpdateEventTimestamp(event, dhisApi);
       }
     }
   } catch (APIException apiException) {
     NetworkUtils.handleEventSendException(apiException, event);
   }
 }