For most of our projects we generate a new test patient on every script run and many of them require us to use a real SSN number (so can’t use 999999999). To do this we have the below code
reset random -- work around for EPF 23..3.1 bug to reset the random (any item) seed
Set universal Patient.SSN to (any item of 0..9 for each item of 1..9) joined by empty
Then when we actually get into the system to register this patient there is always a chance the SSN is already i use so we have a repeat loop that essentially checks if SSN is already in use then run the above code again.
The issue is it will generate the same number every time as if random is not working. Eventually it does work but I have seen it do it up to 20 times. Is there a better way to do this
We had the same issue with names. We generate a random 7 digit first name for the patient and we kept getting the same first name so this code is ugly but seems to work. Not as possible with SSN so looking for options
Set Starting_NameChars to ["A","B","D","E","F","G","H","K","M","N","P","Q","R","S","T","U","V","W","X","Y","Z"] -- 21 characters in list. Prevent using Char that cause issues
Set Used_NameChars to Starting_NameChars
Set NumberOfChoices to 21
Repeat 7 times
Shuffle Used_NameChars
Set AlphaItem to random(NumberOfChoices) -- we use 21 possible char for a name
Set Name to Name & item AlphaItem of Used_NameChars
Delete item AlphaItem of Used_NameChars
Set NumberOfChoices to NumberOfChoices - 1
End repeat
I have resolved this with my Patient Creation script using a variety of methods:
I use the Patient Refused SSN for that particular Epic instance. This is a different value than the Unknown SSN in that it will not fire a Registration warning to gather the patient’s real SSN. I would occasionally get push back from Application Analysts, but rarely could they provide a concrete use case for “realistic” SSNs that were not actual SSNs (which is a different issue entirely).
I generate the SSN either within Eggplant and copy/paste it into my Patient Creation spreadsheet or generate the SSN within Excel itself. I can then use the Remove Duplicates function to pare this list down to unique values. As my script is running, I pull demographic data from the spreadsheet, including name, DOB, and SSN. For those cases in which Identity returned that the SSN was already in use, incrementing the last digit by one always left me with a unique value. Similarly, you could continue to increment the number by one in the unlikely event that you hit two existing SSNs in a row.
As an aside, neither of the following blocks of code generated duplicates for me on 25.3.100 running on Win 11.
repeat 10000 times
Set Patient.SSN to (any item of 0..9 for each item of 1..9) joined by empty
put Patient.SSN
end repeat
repeat 100 times
Set Starting_NameChars to ["A","B","D","E","F","G","H","K","M","N","P","Q","R","S","T","U","V","W","X","Y","Z"] -- 21 characters in list. Prevent using Char that cause issues
Set Used_NameChars to Starting_NameChars
Set NumberOfChoices to 21
Repeat 7 times
Shuffle Used_NameChars
Set AlphaItem to random(NumberOfChoices) -- we use 21 possible char for a name
Set Name to Name & item AlphaItem of Used_NameChars
Delete item AlphaItem of Used_NameChars
Set NumberOfChoices to NumberOfChoices - 1
End repeat
put Name
delete local Name
end repeat
Please let me know if there is something that I am missing.
Using (any item of 0..9 for each item of 1..9) joined by empty is a lovely way to generate a random 9-digit number, and as noted should work great (aside from the random bug which was present in one release).
Similarly, you could use (any item of A..Z for each item of 1..7) joined by empty for your random 7-character “name” (replacing A..Z with your custom character list if you like).
If it’s important to have “names” that don’t use any character more than once, here’s a slightly simpler way to do it than the earlier examples:
put "A".."Z" into nameChars // or a custom list of characters
repeat 7 times
pop any item of nameChars into nextChar
put nextChar after Name
end repeat
put Name
So I am trying to still collect data but here is more what is happening
The code above works if I put in a repeat 1000 times I never get the same number but…
I probably create 100 patients in a month. We just did a server wipe back in July so starting with no patients so at most I have made 1000 patients with unique SSN’s right now. In the last few weeks its gotten worse but I am getting dups of those 1000 sometimes up to 10 times in a row. So its hard to explain but to be there should be almost a billion numbers to choose from but it seems to be using the same few thousand numbers after a while. Yesterday when it happened it seem to be duplicating numbers used back in June/July. Just seem odd.
The work around I am about to put in place to try and force it to be more random is
Set Starting_NumChars to [1,2,3,4,5,6,7,8,9] -- Numbers used in SSN
Set NumberOfChoices to 9
Repeat 9 times
Shuffle Starting_NumChars -- shuffle order they are in, in the list
Set NumItem to random(NumberOfChoices) -- picks a random number 1-9. Used to pick item position in Starting_NumChars list
Set SSN to SSN & item NumItem of Starting_NumChars -- build SSN one number at a time
End repeat
Set universal Patient.SSN to SSN
People have a hard time with random numbers, because we intuitively feel that they should follow some rules, particularly that they shouldn’t repeat very often. But truly random numbers don’t follow any rules, they’re just random. So after flipping a coin that comes up heads 100 times in a row, our gut feeling is that the chance of the next toss also being heads is astronomically small. But in fact it’s 50% just like every other toss. So there will sometimes be (random) duplicates.
If you want to generate 1000 different SSNs, you can just check each time you make a new one to see if it’s already in the list of previous SSNs. If it’s a duplicate then just generate another until you come up with a unique one.
Another approach would be to just generate sequential numbers. Maybe start with 123450000, then 123450001 etc. Since it’s just for testing that might serve the purpose, and is incredibly simple. Or if you want more variety then you could use a hybrid approach: generate the first 5 digits at random and the last 4 sequentially. Then you’re guaranteed that the first 10,000 SSNs you generate will be unique even if the random part has a lot of duplicates.