Skip to content

Commit 5976ea4

Browse files
Attempt to parse HL7 and LUT files to determine their internal name
`$system.OBJ.Load` is able to load CLS and INC files to determine their internal name. However it is not able to load the HL7 and LUT files exported by Embedded Git. These are XML files with the internal name readily available within, make an attempt to parse the file and get the internal name. This will help avoid situations such as HL7 or LUT files being introduced at the same time as their Embedded Git mappings where the internal name was previously not able to be determined due to the mappings getting loaded in later and resulting in them not being loaded at all after a pull.
1 parent 18999e9 commit 5976ea4

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

cls/SourceControl/Git/File.cls

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
62101
Storage Default
63102
{
64103
<Data name="FileDefaultData">

0 commit comments

Comments
 (0)