I created my unique Id using the first 2 letters of the name, surname, last 2 digits of the year of birth and the org unit code. In a case were I have 2 or more people that have same names, same date of birth and from the same region, how do I create a sequence to help add maybe an extra character to the code in this instance?
Maybe add to the text pattern SEQUENTIAL(###): first 2 letters of the name, surname, last 2 digits of the year of birth and the org unit code + SEQUENTIAL(##)
Have you tried @Gassim solution? It should solve the issue that you are experiencing.
It would be great if you could provide us with the result of the solution suggested, otherwise please let me know how I can be of assistance at this point.
Hey @Tangy , if you are planning to use the Android App with the specific configuration please read the following: Android implementation - DHIS2 Documentation as the system might not behave as you initially expected.
Hi @ayman.tuffaha , I have tried the text pattern SEQUENTIAL and it seems to be giving me any error. Maybe I am doing the placement wrongly in my expression, See image below please and advice
Hi @ayman.tuffaha thank you for your response. I already have the org unit code in my expression and the correct pattern from my end for org unit code is: ORGUNIT_CODE. What I am failing to understand however is why I should include it in my sequence pattern, if you could please enlighten me. Also, every other thing is giving an error, if I am to remove the ORG_UNIT_CODE from your example. See image below:
If you look at my code you will see d2:substring(V{orgunit_code}, 0,2), for org unit code, which is working perfectly fine.
ORG_UNIT_CODE(format): is a segment that represents the organization unit code associated with the generation.
SEQUENTIAL(format): Sequential segments will be replaced by a number, based on a counting value on the server. Sequential segments will start at the value 1, and for each generated value count up until no more values are available, based on the format. Like Random segments, uniqueness is based on the rest of the pattern, so each possible version of the pattern will have it’s own sequential counter starting from 1.
“^…” and “…” will use “^” Used when you want to enforce the length of the input value. For example, “^…$” will accept AAAA, since it’s 4 characters between the start and end, but PARIS will be rejected since it has 5 characters.
I hope this will answer your question, if you need further details I encourage you to go over the below URL link which has plenty of details about the text pattern syntax in DHIS2:
@ayman.tuffaha thank you for the link and for your assistance. I have a better understanding now.
I kinda just have an issue with “SEQUENTIAL” giving an error in my code.
I do not want it attached to the org unit so we can exclude the ORG_UNIT_CODE for now, I want the sequence to come after an attribute.
If the last variable in my unique code is A{IM.RE_code}, then adding a sequence right after that should be A{IM.RE_code} +SEQUENTIAL(####) right?
Yes, that’s right @Tangy, but make sure that A{IM.RE_code} is working with no issues
I prefer to add separation between two codes to be more readable to the user by adding concatenation A{IM.RE_code}+ “-” +SEQUENTIAL(####)
@ayman.tuffaha the A{IM.RE_code} is working perfectly, it is what I am using as a placeholder for now while waiting for the sequence to work. And it is still not working
This specific line of code is not recognized from my end… Is there perhaps any other way to look into this. Maybe it the version of DHIS2 I am using, which is 2.37.8; perhaps the code is different for that version upward.
@Gassim I created a new program under https://play.dhis2.org/2.37nightly/dhis-web-dashboard/ called “Sequential Unique Code Testing” I then created 3 attributes; Sequential unique code Name, Sequential unique code last name and Sequential unique code(which will be assigned a value from name and last name plus the sequence).
Below is my program rule, without the +SEQUENTIAL and it is working perfectly.
d2:concatenate(d2:substring( A{Sequential.01}, 0, 2 ), d2:substring(A{Sequential.02}, 0, 2 )
However, when I added the sequential suggested by @ayman.tuffaha it gives an error, see image below:
It’s not clear how the expression above would work because it’s not formulated properly as a condition and thus I’m not able to reproduce the issue you posted. Could you take a screenshot of the one that’s working please?