static void sendTrackedEntityInstanceChanges(
     DhisApi dhisApi, TrackedEntityInstance trackedEntityInstance, boolean sendEnrollments)
     throws APIException {
   if (trackedEntityInstance == null) {
     return;
   }
   if (trackedEntityInstance.getCreated() == null) {
     postTrackedEntityInstance(trackedEntityInstance, dhisApi);
   } else {
     putTrackedEntityInstance(trackedEntityInstance, dhisApi);
   }
   if (sendEnrollments) {
     List<Enrollment> enrollments = TrackerController.getEnrollments(trackedEntityInstance);
     sendEnrollmentChanges(dhisApi, enrollments, sendEnrollments);
   }
 }
  private static void UpdateTrackedEntityInstanceTimestamp(
      TrackedEntityInstance trackedEntityInstance, DhisApi dhisApi) throws APIException {
    try {
      final Map<String, String> QUERY_PARAMS = new HashMap<>();
      QUERY_PARAMS.put("fields", "created,lastUpdated");
      TrackedEntityInstance updatedTrackedEntityInstance =
          dhisApi.getTrackedEntityInstance(
              trackedEntityInstance.getTrackedEntityInstance(), QUERY_PARAMS);

      // merging updated timestamp to local trackedentityinstance model
      trackedEntityInstance.setCreated(updatedTrackedEntityInstance.getCreated());
      trackedEntityInstance.setLastUpdated(updatedTrackedEntityInstance.getLastUpdated());
      trackedEntityInstance.save();
    } catch (APIException apiException) {
      NetworkUtils.handleApiException(apiException);
    }
  }