Can't find TEI after opening in EnrollmentFormActivity Class - Android Skeleton App

Hi,
I’m practicing with Android-Skeleton-App. When I opened a TEI in EnrollmentFormActivity form and cancel it by pressing Back button, I can’t see the TEI in the list. I debugged the code and found that TEI are in the list but hasn’t shown by filtering program UID. I’m using https://github.com/RahmanMonjur/dhis2-android-skeleton-app/tree/ereg_matlab
Note that, I’m using Sdk.d2().trackedEntityModule().trackedEntityInstanceQuery() instead of Sdk.d2().trackedEntityModule().trackedEntityInstances().

Maybe the SDK masters can help you here? @vgarciabnz @marcos.campos ?

Hi @jaime.bosque, good to hear from you.

1 Like

Hi @RahmanMonjur,

Based on your explanation (I haven’t gone through the code yet), my guess is that the TEI is being created when you pressed the “+” button, but the enrollment is not. So at the end you have a TEI without enrollment. And that could be why the TEI is not shown if you filter by program. Please check it, you can use the Enrollment repository and filter by TEI id to see if there is any enrollment associated.

If that is the problem, I would recommend to postpone the TEI creation to the enrollment screen. Once the user confirm the enrollment, you can create create the TEI and the enrollment one after the other.

Let me know it that solves it.

Thanks @vgarciabnz. I looked on the detail and not able to find the clue. I opened an old TEI which is already enrolled in a program. When the form gets RESULT_OK while exiting, the TEI stays in the list. But when it gets RESULT_CANCEL while exiting I don’t find it in the list. Hope it clarifies. Also, when when I create a new TEI and enrollment by clicking + button, and exit the form with clicking back button, it cancels the enrollment but it creates a TEI.
Note: If you are checking the codes, please choose the first organisation unit, and in the program list choose second program. And, in the tracked entity list, please click on the image sign for opening an old TEI in the enrolment form.

Thanks @vgarciabnz. I think I’ve got the things and solved it temporarily. However, something is here to understand properly. And that is, if I enrol a TEI in a program by calling EnrollmentFormService.getInstance().init() method in the background and that TEI belong to some other program already, how does the current enrolment get attribute values from the other program?

Hi @RahmanMonjur, good to hear you could solve it.
The TrackedEntityAttributeValues are shared along all the enrollments so the value for the pair TEI - Attribute is unique. You can get the TEI attributes by d2.trackedEntityModule().trackedEntityAttributeValues().byTrackedEntityInstance().eq("uid").

1 Like