› Clovertech Forums › Cloverleaf › TCL to delete OBX
I have following TCL that will delete whole OBX segment if OBX.5 = “DNR”.
I tested it and it deleted most OBX segments if OBX.5 is “DNR”. But there are still some OBX segments can’t be deleted. I have verified the HL7 format in all OBX segment is the same. I am not sure why it can only delete some of them. Thanks!
set obxcount [countSegments $msg OBX]
for {set i 0} {$i < $obxcount} {incr i} {
#delete OBX is OBX.5 is “DNR”
set obx5 [getField $msg OBX<$i> 5]
if {[regexp {DNR} $obx5]} then {
set msg [deleteSegment “$msg” “OBX<$i>”]}
set msg [setField “QUEST” $msg OBX<$i> 15]
}
I’m not sure why you’re trying to setField “QUEST” in the segment after you’ve removed it. That seems like it won’t work.
Also, after you remove a segment, it’s probably throwing the count off on the remaining segments.
Try getting rid of the QUEST line and replace it with a line that says “incr i -1”. This should adjust for the fact that you’ve removed a segment. Also, you’ll need another line that does “incr obxcount -1”. If you remove the segment the overall count goes down, so you’ll have to stop your loop earlier.
I replaced setField “QUEST” is add it to OBX.15 with “incr i -1” and I get dead loop.
Following is the test message, it has more than 30 OBXs that has “DNR” in it. The TCL deleted more than 30 OBXs. Only 6 of them are not deleted. They are OBX|10|, OBX|12|, OBX|14|, OBX|23|, OBX|25| and OBX|27|
OBX|1|TX|5644-0^Ethanol Ur Ql^LN^82000600^Alcohol Metabolites^QDIWDL||INTERFERENCE|ng/mL|<500|A|||F|||20230607143600|CB NTE|1||See Note A
OBX|2|ST|54247-2^Drug screen comment Ur-Imp^LN^82000601^medMATCH Alcohol Metab^QDIWDL||INCONSISTENT|||A|||F|||20230607143600|CB
OBX|3|ST|58378-1^Ethyl glucuronide Ur Cfm-mCnc^LN^82000610^ Ethyl Glucuronide (ETG)^QDIWDL||INTERFERENCE|ng/mL|<500|A|||F|||20230607143600|CB
OBX|4|ST|54247-2^Drug screen comment Ur-Imp^LN^82000611^medMATCH ETG^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|5|ST|58425-0^Ethyl sulfate Ur Cfm-mCnc^LN^82000620^ Ethyl Sulfate (ETS)^QDIWDL||INTERFERENCE|ng/mL|<100|A|||F|||20230607143600|CB
OBX|6|ST|54247-2^Drug screen comment Ur-Imp^LN^82000621^medMATCH ETS^QDIWDL||INCONSISTENT|||A|||F|||20230607143600|CB
OBX|7|ST|54247-2^Drug screen comment Ur-Imp^LN^86025927^Alcohol Metab Comments^QDIWDL||I||||||F|||20230607143600|CB
OBX|8|TX|3349-8^Amphetamines Ur Ql^LN^82000000^Amphetamines^QDIWDL||INTERFERENCE|ng/mL|<500|A|||F|||20230607143600|CB NTE|1||See Note A
OBX|9|ST|54247-2^Drug screen comment Ur-Imp^LN^82000001^medMATCH Amphetamines^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|10|ST|19346-6^Amphet Ur-mCnc^LN^82000010^ Amphetamine^QDIWDL||DNR|ng/mL|<250|N|||X|||20230607143600|CB
OBX|11|ST|54247-2^Drug screen comment Ur-Imp^LN^82000011^medMATCH Amphetamine^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|12|ST|3780-4^Methamphet Ur-mCnc^LN^82000020^ Methamphetamine^QDIWDL||DNR|ng/mL|<250|N|||X|||20230607143600|CB
OBX|13|ST|54247-2^Drug screen comment Ur-Imp^LN^82000021^medMATCH Methamphetamine^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|14|ST|54247-2^Drug screen comment Ur-Imp^LN^86025913^Amphetamines Comments^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|15|TX|3377-9^Barbiturates Ur Ql^LN^82000030^Barbiturates^QDIWDL||INTERFERENCE|ng/mL|<300|A|||F|||20230607143600|CB NTE|1||See Note A
OBX|16|ST|54247-2^Drug screen comment Ur-Imp^LN^82000031^medMATCH Barbiturates^QDIWDL||INCONSISTENT|||A|||F|||20230607143600|CB
OBX|17|ST|11230-0^Amobarbital Ur-mCnc^LN^82000040^ Amobarbital^QDIWDL||INTERFERENCE|ng/mL|<100|A|||F|||20230607143600|CB
OBX|18|ST|54247-2^Drug screen comment Ur-Imp^LN^82000041^medMATCH Amobarbital^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|19|ST|11071-8^Butalbital Ur-mCnc^LN^82000050^ Butalbital^QDIWDL||INTERFERENCE|ng/mL|<100|A|||F|||20230607143600|CB
OBX|20|ST|54247-2^Drug screen comment Ur-Imp^LN^82000051^medMATCH Butalbital^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|21|ST|3926-3^Pentobarb Ur-mCnc^LN^82000060^ Pentobarbital^QDIWDL||INTERFERENCE|ng/mL|<100|A|||F|||20230607143600|CB
OBX|22|ST|54247-2^Drug screen comment Ur-Imp^LN^82000061^medMATCH Pentobarbital^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|23|ST|3950-3^Phenobarb Ur-mCnc^LN^82000070^ Phenobarbital^QDIWDL||DNR|ng/mL|<100|N|||X|||20230607143600|CB
OBX|24|ST|54247-2^Drug screen comment Ur-Imp^LN^82000071^medMATCH Phenobarbital^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|25|ST|19695-6^Secobarbital Ur-mCnc^LN^82000080^ Secobarbital^QDIWDL||DNR|ng/mL|<100|N|||X|||20230607143600|CB
OBX|26|ST|54247-2^Drug screen comment Ur-Imp^LN^82000081^medMATCH Secobarbital^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|27|ST|54247-2^Drug screen comment Ur-Imp^LN^86025914^Barbiturates Comments^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|28|TX|3390-2^Benzodiaz Ur Ql^LN^82000090^Benzodiazepines^QDIWDL||INTERFERENCE|ng/mL|<100|A|||F|||20230607143600|CB NTE|1||See Note A
OBX|29|ST|54247-2^Drug screen comment Ur-Imp^LN^82000091^medMATCH Benzodiazepines^QDIWDL||INCONSISTENT|||A|||F|||20230607143600|CB
OBX|30|ST|19328-4^A-OH Alpraz Ur-mCnc^LN^82000130^ Alphahydroxyalprazolam^QDIWDL||INTERFERENCE|ng/mL|<25|A|||F|||20230607143600|CB
OBX|31|ST|54247-2^Drug screen comment Ur-Imp^LN^82000131^medMATCH aOH alprazolam^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|32|ST|59589-2^1OH-midazolam Ur-mCnc^LN^86011279^ Alphahydroxymidazolam^QDIWDL||INTERFERENCE|ng/mL|<50|A|||F|||20230607143600|CB
OBX|33|ST|54247-2^Drug screen comment Ur-Imp^LN^86011309^medMATCH aOH midazolam^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|34|ST|60677-2^A-OH-triazolam Ur-mCnc^LN^82000150^ Alphahydroxytriazolam^QDIWDL||NEGATIVE|ng/mL|<50|N|||F|||20230607143600|CB
OBX|35|ST|54247-2^Drug screen comment Ur-Imp^LN^82000151^medMATCH aOH triazolam^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|36|ST|28073-5^7Aminoclonazepam Ur-mCnc^LN^86011280^ Aminoclonazepam^QDIWDL||NEGATIVE|ng/mL|<25|N|||F|||20230607143600|CB
OBX|37|ST|54247-2^Drug screen comment Ur-Imp^LN^86011310^medMATCH Aminoclonazepam^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|38|ST|12602-9^OH-Ethylfluraz Ur-mCnc^LN^86011281^ Hydroxyethylflurazepam^QDIWDL||NEGATIVE|ng/mL|<50|N|||F|||20230607143600|CB
OBX|39|ST|54247-2^Drug screen comment Ur-Imp^LN^86011311^medMATCH OH,Et flurazepam^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|40|ST|3725-9^LORazepam Ur-mCnc^LN^82000120^ Lorazepam^QDIWDL||NEGATIVE|ng/mL|<50|N|||F|||20230607143600|CB
OBX|41|ST|54247-2^Drug screen comment Ur-Imp^LN^82000121^medMATCH Lorazepam^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|42|ST|15372-6^Nordiazepam Ur-mCnc^LN^82000100^ Nordiazepam^QDIWDL||INTERFERENCE|ng/mL|<50|A|||F|||20230607143600|CB
OBX|43|ST|54247-2^Drug screen comment Ur-Imp^LN^82000101^medMATCH Nordiazepam^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|44|ST|3887-7^Oxazepam Ur-mCnc^LN^82000110^ Oxazepam^QDIWDL||INTERFERENCE|ng/mL|<50|A|||F|||20230607143600|CB
OBX|45|ST|54247-2^Drug screen comment Ur-Imp^LN^82000111^medMATCH Oxazepam^QDIWDL||DNR|||N|||X|||20230607143600|CB
OBX|46|ST|12382-8^Temazepam Ur-mCnc^LN^82000158^ Temazepam^QDIWDL||INTERFERENCE|ng/mL|<50|A|||F|||20230607143600|CB
OBX|47|ST|54247-2^Drug screen comment Ur-Imp^LN^82000159^medMATCH Temazepam^QDIWDL||INCONSISTENT|||A|||F|||20230607143600|CB
OBX|48|ST|54247-2^Drug screen comment Ur-Imp^LN^86025915^Benzodiazepines Comments^QDIWDL||SEE BELOW||||||F|||20230607143600|CB OBX|49|TX|3393-6^BZE Ur Ql^LN^82000180^Cocaine Metabolite^QDIWDL||INTERFERENCE|ng/mL|<150|A|||F|||20230607143600|CB NTE|1||See Note A
………………..
Can you post the updated code?
Simple:
Assume all segments in a list (segList) and separator char is (|) $sepChar
# Get a list of OBX locations
set obxNums [lsearch -all -regexp $segList {^OBX}]
# Note we go in reverse order so as not to skew list
foreach num [lsort -integer -decreasing $obxNums] {
set lst [split [lindex $segList $num] $setChar]
if {[lindex $lst 5] eq “DNR”} {lvarpop segList $num}
}
# segList should now contain only the wanted segments.
I hope I did not fat finger anything
Why not use an Iterate in an XLate:
COPY =0 -> $%g9
ITERATE / group / 1(0).1(0).3 / %g1
IF 1(0).1(0).3(%g1).OBX(0).#5(0).[0] ne =DNR
PATHCOPY 1(0).1(0).3(%g1).OBX(0) -> 1(0).1(0).3(%g9).OBX(0)
MATH: ADD $%g9 / =1 -> $%g9
COPY $%g9 -> (0).1(0).3(%g9).OBX(0).#1(0).[0]
Regards, Jim
If you wanted to add OBX sequence numbers (OBX.1) just add this after the code above
set cnt 1
foreach num [lsearch -all -regexp $segList {^OBX}] {
set seg [split [lindex $segList $num] $sepChar]
set seg [lreplace $seg 1 1 $cnt]
incr cnt
set segList [lreplace $segList $num $num [join $seg $sepChar]]
}
Loop trough twice but fast