Hi @Wolffseb , welcome to the community!
I have discussed your issue with the core tracker team, and I think there are a few separate routes you could explore.
First, should it be allowed for a patient (TEI) to have multiple enrollments in your system? If this is a neonatal care surveillance, how rare would it be in practice for an infant to have multiple enrollments due to multiple hospital admissions? If this is an edge case, you may consider checking off
Only enroll once (per tracked entity instance lifetime)
in program configuration.
For those edge cases where a “new” patient has been found through Search to be previously enrolled, then a new TEI/patient ID could be generated. As an attribute, you can add a free text note where end users link it to the previous TEI’s patient ID, so the TEI can be merged in your research dataset later.
IF, multiple enrollments could and should be routinely collected per patient, then you can look into the other options below.
Second, consider adapting @Gassim 's solution above for your workflow.
a) Make a new Tracked Entity Attribute of value type text, called “Unique Enrollment ID”. Make it unique to the system and assign it to the program.
b) Create a program rule that auto-assigns the enrollment date combined with the manually-entered patient number to the “Unique Enrollment ID”.
Condition: d2:hasValue(V{enrollment_date} && d2:hasValue(A{patient_number})
Expression to evaluate and assign:
d2:concatenate(V{enrollment_date},"-", A{patient_number})
[there may be a warning thrown creating this action on some versions, but you can ignore it]
Now when a user tries to enroll the same TEI a second time on the same day, the “Unique Enrollment ID” would throw an error.
Third, if you are using Capture app, you could consider a Capture Form Field plugin, which uses an API request to find any “matching” enrollments and show a warning to the user before they create a new one. This will allow you to show a warning / block duplicate entries altogether in the web app that meet more complex conditions (e.g. Admission date ±3 days) Here are relevant docs to get you started with plugins.
I see you already have built some custom DHIS2 apps, but are using the Tracker Capture app, which has been superseded by Capture and does not have plugin support. So, if you are going to stick with Tracker Capture app, I recommend Point 1 or 2 above, or continuing with current scripts.
Prost from a Charité alumnus in Oslo
