-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathVistARoutineImport.py
105 lines (99 loc) · 4.29 KB
/
VistARoutineImport.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#---------------------------------------------------------------------------
# Copyright 2012-2019 The Open Source Electronic Health Record Alliance
# Copyright 2024 Sam Habiel: Python 3.12 support
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#---------------------------------------------------------------------------
from __future__ import print_function
from __future__ import with_statement
from builtins import object
import sys
import os
import argparse
from VistATestClient import VistATestClientFactory, createTestClientArgParser
from LoggerManager import getTempLogFile
class VistARoutineImport(object):
def __init__(self):
pass
def __importRoutineCache__(self, connection, routineImportFile):
connection.expect("Device: ")
connection.send("%s\r" % routineImportFile)
connection.expect(r"Parameters\? ")
connection.send("\r")
while True:
index = connection.expect([r"Override and use this File with %RI\? No =>",
"Please enter a number from the above list:",
"Routine Input Option:",
])
if index == 0:
connection.send("YES\r")
elif index == 1:
connection.send("\r")
else:
connection.send("All\r")
break
connection.expect(r"shall it replace the one on file\? No =>")
connection.send("YES\r")
connection.expect(r"Recompile\? Yes =>")
connection.send("\r")
connection.expect(r"Display Syntax Errors\? Yes =>")
connection.send("\r")
def __importRoutineGTM__(self, connection, routineImportFile,
routineOutputDir):
connection.expect(r"Formfeed delimited <No>\? ")
connection.send("No\r")
connection.expect("Input device: <terminal>: ")
connection.send("%s\r" % routineImportFile)
connection.expect("Output directory : ")
connection.send("%s\r" % routineOutputDir)
def importRoutines(self, vistATestClient, routineImportFile,
routineOutputDir, timeout=1200):
assert os.path.exists(routineImportFile)
absRtnImportFile = os.path.normpath(os.path.abspath(routineImportFile))
vistATestClient.waitForPrompt()
connection = vistATestClient.getConnection()
connection.send("D ^%RI\r")
if vistATestClient.isCache():
self.__importRoutineCache__(connection, absRtnImportFile)
elif vistATestClient.isGTM():
absRtnOutDir = os.path.normpath(os.path.abspath(routineOutputDir))
self.__importRoutineGTM__(connection, absRtnImportFile,
os.path.join(absRtnOutDir, ""))
vistATestClient.waitForPrompt(timeout)
connection.send('\r')
DEFAULT_OUTPUT_LOG_FILE_NAME = "RoutineImportTest.log"
def main():
testClientParser = createTestClientArgParser()
parser = argparse.ArgumentParser(description='VistA Routine Import',
parents=[testClientParser])
parser.add_argument('routineImportFile',
help='path to Routine Import File in .ro format')
parser.add_argument('-o', '--routineOutputDir', default=None,
help='path to Routine output Dir, GTM only')
result = parser.parse_args();
print (result)
routineImportFile = result.routineImportFile
assert os.path.exists(routineImportFile)
routineOutputDir = result.routineOutputDir
""" create the VistATestClient"""
testClient = VistATestClientFactory.createVistATestClientWithArgs(result)
assert testClient
with testClient as vistAClient:
logFilename = getTempLogFile(DEFAULT_OUTPUT_LOG_FILE_NAME)
print("Log File is %s" % logFilename)
vistAClient.setLogFile(logFilename)
vistARoutineImport = VistARoutineImport()
vistARoutineImport.importRoutines(vistAClient, routineImportFile,
routineOutputDir)
if __name__ == '__main__':
main()