i have a field (ORC.12) that i need to replace but sometimes the HL7 doesnt go that far and i get the ‘list doesn’t contain element 12’ error. I am using lreplace. How do i get around this using tcl?
You could have wrapped your ORC.12 logic in a catch.
catch {
set ORC_fields [lreplace $ORC_fields 12 12 with your replacement]
}
If ORC fields come inbound shorter, than there is nothing to replace. Having said that, if for some reason you must have something entered in ORC.12, you would go with the field length to build it out.
No need to check length of the segment. The above code would do nothing if field 12 or above were populated.
Anytime I am to change a field in a list, unless I know for sure the list will be of adequate length I use this code. For example you would not need if you were to place a value in MSH.4 because you know the segment must have more fields than that.
Maybe you picked this up in one of my classes. I always covered that.