@@ -35,6 +35,11 @@ ClassMethod ExternalNameToInternalName(ExternalName As %String) As %String
3535 }
3636 new %SourceControl //don't trigger source hooks with this test load to get the Name
3737 set sc =$system .OBJ .Load (ExternalName ," -d" ,,.outName ,1 )
38+ // If the test load was unsuccessful then it may be due to an unsupported
39+ // file type (e.g. hl7 or lut) that we may otherwise be able to handle
40+ if $$$ISERR(sc ) {
41+ set outName = ..ParseFileForInternalName (ExternalName )
42+ }
3843 set itemIsPTD = 0
3944 if $data (outName ) = 11 {
4045 set key = $order (outName (" " ))
@@ -59,6 +64,40 @@ ClassMethod ExternalNameToInternalName(ExternalName As %String) As %String
5964 quit internalName
6065}
6166
67+ /// Attempt to determine the internal name of a given file based on its content
68+ /// Intended to be used in situations where $system.OBJ.Load is unable to
69+ ClassMethod ParseFileForInternalName (fileName As %String ) As %String [ Private ]
70+ {
71+ Set internalName = " "
72+
73+ Set fileExtension = $ZCONVERT ($PIECE (fileName ," ." ,*)," U" )
74+ If (fileExtension = " HL7" ) {
75+ Set tSC = ##class (%XML.TextReader ).ParseFile (fileName , .textReader )
76+ If ($$$ISOK(tSC )) {
77+ // The HL7 schema name is in the 'name' attribute of the 'Category' element
78+ // Example: <Category name="...">
79+ If (textReader .ReadStartElement (" Category" ) && textReader .MoveToAttributeName (" name" )) {
80+ If (textReader .Value '= " " ) {
81+ Set internalName = textReader .Value _" ." _fileExtension
82+ }
83+ }
84+ }
85+ } ElseIf (fileExtension = " LUT" ) {
86+ Set tSC = ##class (%XML.TextReader ).ParseFile (fileName , .textReader )
87+ If $$$ISOK(tSC ) {
88+ // The lookup table name is in the 'table' attribute of any 'entry' element
89+ // Example: <entry table="...">
90+ If (textReader .ReadStartElement (" entry" ) && textReader .MoveToAttributeName (" table" )) {
91+ If (textReader .Value '= " " ) {
92+ Set internalName = textReader .Value _" ." _fileExtension
93+ }
94+ }
95+ }
96+ }
97+
98+ Quit internalName
99+ }
100+
62101Storage Default
63102{
64103<Data name =" FileDefaultData" >
0 commit comments