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); } }
private static void putEnrollment(Enrollment enrollment, DhisApi dhisApi) throws APIException { try { Response response = dhisApi.putEnrollment(enrollment.getEnrollment(), 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())) { // enrollment.setState(State.SYNCED); enrollment.setFromServer(true); enrollment.save(); clearFailedItem(FailedItem.ENROLLMENT, enrollment.getLocalId()); UpdateEnrollmentTimestamp(enrollment, dhisApi); } } } catch (APIException apiException) { NetworkUtils.handleEnrollmentSendException(apiException, enrollment); } }
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); } }
public void performSoftDeleteOfTrackedEntityInstance( TrackedEntityInstance trackedEntityInstance) { List<Enrollment> enrollments = TrackerController.getEnrollments(mState.getProgramId(), trackedEntityInstance); Enrollment activeEnrollment = null; for (Enrollment enrollment : enrollments) { if (Enrollment.ACTIVE.equals(enrollment.getStatus())) { activeEnrollment = enrollment; } } if (activeEnrollment != null) { List<Event> eventsForActiveEnrollment = TrackerController.getEventsByEnrollment(activeEnrollment.getLocalId()); if (eventsForActiveEnrollment != null) { for (Event event : eventsForActiveEnrollment) { event.delete(); } } activeEnrollment.delete(); } }
private static void UpdateEnrollmentTimestamp(Enrollment enrollment, DhisApi dhisApi) throws APIException { try { final Map<String, String> QUERY_PARAMS = new HashMap<>(); QUERY_PARAMS.put("fields", "created,lastUpdated"); Enrollment updatedEnrollment = dhisApi.getEnrollment(enrollment.getEnrollment(), QUERY_PARAMS); // merging updated timestamp to local enrollment model enrollment.setCreated(updatedEnrollment.getCreated()); enrollment.setLastUpdated(updatedEnrollment.getLastUpdated()); enrollment.save(); } catch (APIException apiException) { NetworkUtils.handleApiException(apiException); } }
public void showDataEntryFragment(Event event, String programStage) { Bundle args = getArguments(); DataEntryFragment fragment; String progId = mForm.getProgram().getId(); // new line :AgeToday if (event == null) { fragment = DataEntryFragment.newInstanceWithEnrollment( args.getString(ORG_UNIT_ID), args.getString(PROGRAM_ID), programStage, mForm.getEnrollment().localId); } else if (progId.equals("u9FZUM7kn38") && event != null) { /*- The If-Else block below is used to add the AgeToday Feature, a requirement for the HPV Campaign Program -*/ fragment = DataEntryFragment.newInstanceWithEnrollment( args.getString(ORG_UNIT_ID), args.getString(PROGRAM_ID), programStage, event.getLocalEnrollmentId(), event.getLocalId()); Enrollment enrollment = DataValueController.getEnrollment(event.getLocalEnrollmentId()); List<TrackedEntityAttributeValue> teav = enrollment.getAttributes(); // getActionBar().setSubtitle("Learner's AgeToday is: " + displayAge); // getActionBar().setDisplayShowTitleEnabled(true); for (TrackedEntityAttributeValue val : teav) { System.out.println("The learner details are: ->" + val.getValue()); } // If passport number is entered then : String learnerDob = teav.get(4).getValue(); // String learnerDob = teav.get(3).getValue(); Training Instance - Position for LearnerDOB // when IDNumber is entered String learnerDob = teav.get(2).getValue(); // Staging Instance // String learnerDob = teav.get(3).getValue(); if (!isValidDate(learnerDob)) learnerDob = teav.get(3).getValue(); System.out.println("What is in learnerstring :" + learnerDob); // --Use Joda Time to compute the learner's age today LocalDate birthdate = new LocalDate(learnerDob); LocalDate now = new LocalDate(); // Compute learners age today Years learnersAgeToday = Years.yearsBetween(birthdate, now); System.out.println("The learners age today is:====>" + learnersAgeToday); ageToday = String.valueOf(learnersAgeToday); StringBuilder sbAgeToday = new StringBuilder(ageToday); sbAgeToday.delete(0, 1); sbAgeToday.append("EARS"); System.out.println("The OLD learners age is:" + ageToday); // String myDisplay = printLearnersAge(); displayAge = sbAgeToday.toString(); System.out.println("THE NEW LEARNERS AGE FIXED: " + displayAge); // List<ProgramStageDataElement> programStageDataElements = // MetaDataController.getProgramStageDataElements // (MetaDataController.getProgramStage(event.getProgramStageId())); // for(ProgramStageDataElement de: programStageDataElements) { // System.out.println("The data elements in the program are:" + de.getDataElement()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder .setMessage("The learner's Age Today is: " + displayAge) .setCancelable(false) .setTitle("Learner's Age Today Notification") .setPositiveButton( "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); AlertDialog dialog = builder.create(); dialog.show(); } else { fragment = DataEntryFragment.newInstanceWithEnrollment( args.getString(ORG_UNIT_ID), args.getString(PROGRAM_ID), programStage, event.getLocalEnrollmentId(), event.getLocalId()); } mNavigationHandler.switchFragment(fragment, ProgramOverviewFragment.CLASS_TAG, true); }