Question
· Aug 28, 2017

padding string in BPL

Hi folks, I'm trying to pad my patient MRN to 10 characters before I do a SQL lookup in my BPL. I've tried various approaches, and have not been successful.

When I add a "code" statement with the following code, I get an error as below.

set context.NewID = "0000000000"
set $EXTRACT(context.NewID,10-len(context.PatientID)) = context.PatientID
 
ERROR <Ens>ErrException: <OBJECT DISPATCH>zS8+5 ^CHSLI.BPLQueryDatabaseforPatientID.Thread1.1 *Property 'NewID'
in class 'CHSLI.BPLQueryDatabaseforPatientID.Context'
must be MultiDimensional -- logged as '-'
number - @'
set $EXTRACT(context.NewID,10-len(context.PatientID)) = context.PatientID'

Any ideas/help would be appreciated.

Thanks.

Discussion (9)1
Log in or sign up to continue

$EXCTRACT()  and also $LI(), $Piece()
is not allowed at the left side of SET when the target is an object property

use an intermediate variable instead.

e.g.

set tmp="0000000000"
set $EXTRACT(tmp,10-len(context.PatientID)) = context.PatientID
set context.NewID=tmp

it might be easier that way

set context.NewID=$EXTRACT("0000000000"_context.PatientID,*-9,*)

Cache dies not like an object property as a left side argument,

but you can solve the problem much simpler:

set context.NewID=$tr($j(context.PatientID,10)," ",0)

 

By the way, if your solution would work, the result would be longer then 10 chars

for example, if context.PatientID=123 then you

would get: "000000123000"

instead of: "0000000123"

Regards,

Julius

I'm not exactly clear on which you intend to hold the new ID (context.newID maybe by the name?)

Regardless, you can also use the built-in pad method:

set context.NewID = ##class(Ens.Rule.FunctionSet).Pad(context.PatientID,-10,0)

where context.PatientID holds your original Patient ID. -10 means you want to prepend to be 10 characters, and "0" is the character you want prepended.