Question
Jonathan Harris · Jul 7

Delete first part of HL7 field up to first "(" character

I am doing a HL7 data transformation with object script but need to only write a substring from the first "(" of the NTE-3 field to the end.

example

Input: NTE|1|||Some text (HI) (321)|ABC

Desired Output: NTE|1|||(HI) (321)|ABC

Basically I'd like to delete "Some text  ".

If I were writing a shell script I would use sed 's/^.*(/(/' with perhaps a modification to get only the first.

I use the function wizard but can't seem to get the right code.

0
0 369
Discussion (9)2
Log in or sign up to continue

$EXTRACT(input,$FIND(input,"(")-1,*)

$EXTRACT(string,index1,index2) creates a substring out of the initial string from index1 to index2. $FIND finds the first occurrence of ( in the string, so that -1 includes the ( itself. When you're using extract, * is shorthand of the last character of the string.

This version does not recognize EXTRACT or FIND.

Is it possible to do a SubString from an index to the end

It seems like they have no function for this.

..ReplaceStr(input,start to "(","(") where I replace everything up to the first parens with just a parens.

This would be so simple, I thought.

If you're on IRIS, it definitely has those functions. Did you put just the $ in front of them?

What version are you running where $EXTRACT is not available? Not sure I’ve heard of such a situation.  
 

edit: noted you referenced ..ReplaceStr which is an Interoperability function. There are semi-equivalents of $EXTRACT and $FIND in there as well - $EXTRACT is ..SubString. But note if you use the solution I or David presented, don’t use .. in front of $EXTRACT, $FIND or $PIECE as these aren't interoperability functions but pure ObjectScript functions. 
 

my suggestion, that I know works as we do something similar, is as follows:

“(“_$PIECE(input,”(“,2)

Have to re-add the opening paren since we’re using that as our splitter, but some find it easier than chaining multiple functions together. David’s solution is certainly valid too.

https://docs.intersystems.com/iris20221/csp/docbook/Doc.View.cls?KEY=RCO...

I put the $ in and the code worked. I wound up using this, $EXTRACT(input,$FIND(input,"(")-1,*).

I liked Craig's suggestion which is a single object script function

"("_$P(input,"(",2,999)

Not sure how to accept a reply, but the $EXTRACT(input,$FIND(input,"(")-1,*) did the trick once I worked out the details of syntax. Thanks again. Now I dive in further over my head to the next "we never did this before" project.

On whichever answers you want to mark as an answer, click the check mark next to the reply button. That should mark that reply as an answer.