· Apr 1, 2022

##class(EnsLib.HL7.Schema).GetFieldNameFromNumber() Bug

Hello community!

I found a bug or may be I missed something.

I want to get  field name in "PID" segment by field number in HL7 Message using following object script expession:

set nl = $CHAR(10)
set str = "MSH|^~\&|MIHIN PATIENT GEN|||2.16.840.1.113883.3.1481|20200103000000+0000||ADT^A01^ADT_A01|1092|P|2.6|1091|||||||||Windward General Hospital|"_nl
_ "EVN||20200110000000+0000|||||"_nl
_ "PID|1|3170|44c8a6bba5c743538e476a813256959b^^^^CKS~000003170^^^^SS||Santana^Pearl||19900609|F||2054-5^Black or African American^HL70005|364 NE Oak Circle^^Trenton^MI^48183||||||||000003170|||N^Not Hispanic or Latino^HL70189|||||||20200110000000+0000|N"_nl
  _ "PD1|||Windward General Hospital^^^^^^^^^|9999992221^Johnston^Karl^^^^^^^^^^NPI^^^^^^^^MD"_nl
_ "PV1|1|I|^^67^||||9999992221^Johnston^Karl^^^^^^^^^^NPI||||||||||||17a5e3aa59a34ad5af017998278a5eb5||||||||||||||||||&HOME^20200110000000+0000|||||||20200103000000DG1|1||Z34.90^Normal pregnancy^I10||20200103000000+0000|F|^Become_Pregnant"_nl
_ "IN1|1|1772^STATE HEALTH PLAN|1027|MEDICAID||||||||||||Santana^Pearl^Gladys|||364 NE Oak Circle^^Trenton^MI^48183"_nl
set msg = ##class(EnsLib.HL7.Message).ImportFromString(str) 
set msg.DocType = "2.5:ADT_A01" 
set segment = msg.getSegmentByIndex(3) 
set fieldName = ##class(EnsLib.HL7.Schema).GetFieldNameFromNumber("2.5", segment.Name, "3(2).1") 
set fieldValue = segment.GetValueAt("3(2).1") 
write fieldName // output is null 
write fieldValue // output is "000003170"

The field number is "3(2).1" and the field name that I want to find is "patientIdentifierList(2).IdNumber", but the result is null;

At the same time when I want to find the value of this field by the number using method of class "<EnsLib.HL7.Segment> .GetValueAt("3(2).1")" it works correct.

Do you have an idea what the problem is?

Thank You!

Product version: IRIS 2020.1
Discussion (4)1
Log in or sign up to continue

You would only need to remove the repetition value from the argument passed to GetFieldNameFromNumber(); you would still continue to pass the full field index to GetValueAt(). Something like this:

set segment = msg.getSegmentByIndex(3)
Set fieldIndex = "3(2).1"
Set fieldNameIndex = ##class(User.Util.StringFunctions).ChangePattern(fieldIndex,"(\d)","()")
set fieldName = ##class(EnsLib.HL7.Schema).GetFieldNameFromNumber("2.5", segment.Name, fieldNameIndex)
set fieldValue = segment.GetValueAt(fieldIndex)

The ChangePattern method:

Class User.Util.StringFunctions Extends Ens.Util.FunctionSet
ClassMethod ChangePattern(pStr As %String, pPat As %String, pRep As %String) As %String
	Set tOut = pStr
	Do {
		Set tLoc = $LOCATE(tOut,pPat,,,tFnd)
		Set:$DATA(tFnd) tOut = $REPLACE(tOut,tFnd,pRep)
	} While tLoc '= 0
	Return tOut