Appending or inserting characters (dashes for SSN)
Good afternoon,
I'm trying to take an unformatted social security number and insert the dashes into it. I'm getting a value in PID-19 like this: "123456789" and would like to use a data transformation to set the value in PID-19 to "123-45-6789".
I can't find any insert or append functions and I can't find anything in the Intersystems doc repository that would do this. Can someone help point the way for me please? I would like to keep this as a "set" action in my DT. I'm a little new to calling classes so it would be helpful if you included some syntax that would go in the "Value" field. I've been pecking at this for several hours and would appreciate any assistance.
Cheers,
John
Product version: IRIS 2019.1
If you create the following class in IRIS Studio, a "FormatSSN()" function will be available in the DTL editor's expression editor, and you can use it in your set rules:
The method strips all non-numeric characters from the value passed to it, then formats it per the SSN format. It doesn't verify that the proper number of digits are present, but that's something that can be easily added.
In a DTL action, it would look like this:
Hi Jeffrey,
Thank you for this code! Unfortunately I don't have access to Studio right now but once I do I will go your code a go. Cheers!
John
Output:
256-12-8799
891-44-5555
Based on: Yet another use case for $translate: date conversion
People call it the reverse mode of $translate().
I saw this kind of usage of $tr() some 20 years ago. If I recall it right, it was mentioned in an article on usenet: comp.lang.mumps.
lol, haven't seen a reference to comp.lang.mumps for a LONG time!
It is still available on Google Groups.
Thank you for your solution Vitaliy! I believe that this would go into a class?
You can put something similar to Jeffrey's logic directly in the Value of the Set action. Instead of using $E ($EXTRACT) you would use DTL's built-in SubString function:
Hi Marc, Good morning! Your code was the 1st I tried and I gotta say... thanks!!! it did the tricks and there were no compile issues either. I was looking for something to plug right into the "Value" field. Have a great day.
Or you could use $E()!
To @John Klahn, My reason for suggesting the classmethod is that this type of thing is something that's done somewhat frequently, so having a reusable method can be a timesaver.
Alas, it does take a bit of investment in time to learn ObjectScript and Studio, but it can be very beneficial to your productivity even though you spend most of your time working on integrations through the management console.
Hi Jeffrey,
I get compile errors with this code. Granted, I'm very new to using functions in DTLs so I suspect that I'm missing some very basic things that are causing the errors. Sorry if this is obvious, but it is confusing to me.
Here is what I input:
set tSSN source.{PID:SSNNumberPatient}
set target.{PID:SSNNumberPatient} $E(tSSN,1,3)_"-"_$E(tSSN,4,5)_”-“_$E(tSSN,6,9)
And this is the Compile results:
Compilation started on 04/29/2022 18:27:15 with qualifiers 'k'
Compiling class SANDBOXPKG.JKlahnProduction.JKlahnProduction.EpicADT.Sandbox.ADTTransformCapitalization
Compiling routine SANDBOXPKG.JKlahnProduction.JKlahnProduction.EpicADT.Sandbox.ADTTransformCapitalization.1
ERROR: SANDBOXPKG.JKlahnProduction.JKlahnProduction.EpicADT.Sandbox.ADTTransformCapitalization.cls(Transform+52) #1054: Invalid expression : 'tSC1=target.SetValueAt($E(tSSN,1,3)_"-"_$E(tSSN,4,5)_”-“_$E(tSSN,6,9),"PID:SSNNumberPatient","set","")' : Offset:66 [zTransform+51^SANDBOXPKG.JKlahnProduction.JKlahnProduction.EpicADT.Sandbox.ADTTransformCapitalization.1]
TEXT: Try { Set tSC1=target.SetValueAt($E(tSSN,1,3)_"-"_$E(tSSN,4,5)_”-“_$E(tSSN,6,9),"PID:SSNNumberPatient","set","") } Catch ex { Set tSC1 = ex.AsStatus() }
ERROR: SANDBOXPKG.JKlahnProduction.JKlahnProduction.EpicADT.Sandbox.ADTTransformCapitalization.cls(Transform+65) #1043: QUIT argument not allowed : 'tSCTrans' : Offset:108 [zTransform+64^SANDBOXPKG.JKlahnProduction.JKlahnProduction.EpicADT.Sandbox.ADTTransformCapitalization.1]
TEXT: If ('tSCTrans) Do ##class(Ens.Util.Log).LogStatus($classname(),"Transform",tSCTrans) Quit:(''tSC) tSCTrans
ERROR: SANDBOXPKG.JKlahnProduction.JKlahnProduction.EpicADT.Sandbox.ADTTransformCapitalization.cls(Transform+67) #1043: QUIT argument not allowed : '}' : Offset:11 [zTransform+66^SANDBOXPKG.JKlahnProduction.JKlahnProduction.EpicADT.Sandbox.ADTTransformCapitalization.1]
TEXT: Quit tSC }
Detected 3 errors during compilation in 0.092s.
Assuming you cut and pasted from your DTL, the double-quote characters around the 2nd dash are incorrect. They appear to be the distinct open and close quote characters that Word automatically substitutes for the "standard" double-quote character:
set tSSN source.{PID:SSNNumberPatient}
set target.{PID:SSNNumberPatient} $E(tSSN,1,3)_"-"_$E(tSSN,4,5)_”-“_$E(tSSN,6,9)
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue