· Apr 28, 2022

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.



Product version: IRIS 2019.1
Discussion (12)2
Log in or sign up to continue

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:

Class Misc.Util.StringFunction Extends Ens.Rule.FunctionSet
ClassMethod FormatSSN(pStr As %String) As %String
   Set tStr = $ZSTRIP(pStr,"*AWP")
   Return $E(tStr,1,3)_"-"_$E(tStr,4,5)_"-"_$E(tStr,6,9)

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:

Or you could use $E()! laugh

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)