/** Get events filtered by program orgUnit and between dates. */ public static List<Event> getEvents(String program, String orgUnit, Date minDate, Date maxDate) { try { Response response; String DHIS_URL = PreferencesState.getInstance().getDhisURL(); String startDate = EventExtended.format(minDate, EventExtended.AMERICAN_DATE_FORMAT); String endDate = EventExtended.format( new Date(maxDate.getTime() + (8 * 24 * 60 * 60 * 1000)), EventExtended.AMERICAN_DATE_FORMAT); String url = String.format(DHIS_URL + DHIS_CHECK_EVENT_API, program, orgUnit, startDate, endDate); Log.d(TAG, url); url = ServerAPIController.encodeBlanks(url); response = ServerAPIController.executeCall(null, url, "GET"); if (!response.isSuccessful()) { Log.e(TAG, "pushData (" + response.code() + "): " + response.body().string()); throw new IOException(response.message()); } JSONObject events = new JSONObject(response.body().string()); ObjectMapper mapper = new ObjectMapper(); JsonNode jsonNode = mapper.convertValue(mapper.readTree(events.toString()), JsonNode.class); return EventsWrapper.getEvents(jsonNode); } catch (Exception ex) { ex.printStackTrace(); return null; } }
/** * Given an event, check through all its DVs if the survey completion date is present in the event * in the form of the control DE "Time Capture" whose UID is hardcoded * * @param survey * @param event * @return */ private static boolean surveyDateExistsInEventTimeCaptureControlDE(Survey survey, Event event) { for (DataValue dataValue : event.getDataValues()) { if (dataValue.getDataElement().equals(PushClient.DATETIME_CAPTURE_UID) && dataValue .getValue() .equals( EventExtended.format( survey.getCompletionDate(), EventExtended.COMPLETION_DATE_FORMAT))) { Log.d( TAG, "Found survey" + survey.getId_survey() + "date " + survey.getCompletionDate() + "dateevent" + dataValue.getValue()); return true; } } return false; }