I want to keep only first instance of OBR.16 when OBR.16.1 length equals 10.
There could be repeating fields where OBR.16.1 equals 10 and these OBR.16 fields should be deleted and other repeating OBR.16 fields should be deleted.
This code works great when only 1 instance of OBR.16.1 length equals 10, but if repeating OBR.16.1 length equals 10, it does not delete.
Message will have only 1 OBR segment.
Example
Expected
There could be repeating fields where OBR.16.1 equals 10 and these OBR.16 fields should be deleted and other repeating OBR.16 fields should be deleted.
This code works great when only 1 instance of OBR.16.1 length equals 10, but if repeating OBR.16.1 length equals 10, it does not delete.
Code:
for (var npi = msg['OBR']['OBR.16'].length() - 1; npi >= 0; npi--) { if (msg['OBR']['OBR.16'][npi]['OBR.16.1'].toString().length != 10) delete msg['OBR']['OBR.16'][npi]; }
Example
Code:
OBR|1|||||||||||||||1234567891^PHYLAST^PHYFIRST^^^^^^^^^^OTHER~16492578^PHYLAST^PHYFIRST^^~1234567891^PHYLAST^PHYFIRST^^^^^^|
Expected
Code:
OBR|1|||||||||||||||1234567891^PHYLAST^PHYFIRST^^^^^^^^^^OTHER|
Comment