Skip to content

Commit

Permalink
Imahara edition now stores rejected lines in a collection for later a…
Browse files Browse the repository at this point in the history
…ttempts at repair and resubmission.
  • Loading branch information
michael-weinstein committed Jul 17, 2020
1 parent 0ee6382 commit 2fe0f48
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dev/* # here be my development stash with who-knows-what
.idea # here be PyCharm development stuff
*.pfx # here be certificates
config.txt # here be more credentials and other sensitive information
rejects.* # potentially more sensitive information

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
79 changes: 54 additions & 25 deletions zymoTransmit.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
import os
import sys
import traceback

contentRoot = os.path.split(os.path.abspath(__file__))[0]

import typing
import argparse

try: # Stuff will seriously break if there is no config file, so if it is missing, this will create the template
from zymoTransmitSupport import config
except FileNotFoundError:
import shutil
cleanConfig = os.path.join(contentRoot, "zymoTransmitSupport", "configClean.txt")
newConfig = os.path.join(contentRoot, "config.txt")
shutil.copy(cleanConfig, newConfig)
print("No config file was found at the expected location. Please input your lab information into the config file at:\n%s" %(os.path.abspath(newConfig)))
try:
import os
import sys
import traceback
import csv

contentRoot = os.path.split(os.path.abspath(__file__))[0]

import typing
import argparse

try: # Stuff will seriously break if there is no config file, so if it is missing, this will create the template
from zymoTransmitSupport import config
except FileNotFoundError:
import shutil
cleanConfig = os.path.join(contentRoot, "zymoTransmitSupport", "configClean.txt")
newConfig = os.path.join(contentRoot, "config.txt")
shutil.copy(cleanConfig, newConfig)
print("No config file was found at the expected location. Please input your lab information into the config file at:\n%s" %(os.path.abspath(newConfig)))
import zymoTransmitSupport
if zymoTransmitSupport.gui.active:
print("Opening config file for editing. Please save and exit when done.")
zymoTransmitSupport.gui.textEditFile(newConfig)
else:
print("GUI appears inactive, unable to open configuration file")
input("Press enter to quit.")
quit()

import zymoTransmitSupport
if zymoTransmitSupport.gui.active:
print("Opening config file for editing. Please save and exit when done.")
zymoTransmitSupport.gui.textEditFile(newConfig)
else:
print("GUI appears inactive, unable to open configuration file")
input("Press enter to quit.")
quit()

import zymoTransmitSupport
except Exception as err:
print("Encountered an unhandled error as follows:")
traceback.print_exc()
input("Run crashed before beginning. A common cause for this can be a corrupt config.txt file. Press enter to quit.")
sys.exit(1)


class CheckArgs(object):
Expand Down Expand Up @@ -159,6 +167,19 @@ def makeHL7TextRecord(hl7Blocks:typing.Dict[typing.Tuple[str, str], str]):
return textRecord


def processRejects(resultList:typing.List[zymoTransmitSupport.inputOutput.resultReader.TestResult]):
file = open(os.path.join(contentRoot, "rejects.csv"), 'a', newline="")
for result in resultList:
csvHandle = csv.writer(file)
if result.okToTransmit:
continue
if type(result.rawLine) == str:
print(result.rawLine, file=file, end="\n")
else:
csvHandle.writerow(result.rawLine)
file.close()


def prepareAndSendResults(args:CheckArgs):
if not args.hl7Directory:
if os.path.abspath(args.input) == os.path.join(contentRoot, "config.txt"):
Expand All @@ -176,6 +197,7 @@ def prepareAndSendResults(args:CheckArgs):
input("Press enter to quit.")
quit()
skippedData = []
resultList = []
certificateFilePath = os.path.join(contentRoot, config.Connection.certificateFolder, config.Connection.certificateFileName)
client, session = zymoTransmitSupport.inputOutput.connection.getSOAPClient(
config.Connection.wsdlURL, certificateFilePath, dumpClientInfo=False)
Expand All @@ -202,13 +224,20 @@ def prepareAndSendResults(args:CheckArgs):
print("%s:%s was skipped" %(patientID, specimenID))
else:
print("Results not transmitted due to argument noTransmit being set to true.")
if skippedData:
processRejects(resultList)


def makeDirectoriesIfNeeded():
if not os.path.isdir(os.path.join(contentRoot, config.Connection.certificateFolder)):
os.mkdir(os.path.join(contentRoot, config.Connection.certificateFolder))
if not os.path.isdir(os.path.join(contentRoot, config.Configuration.logFolder)):
os.mkdir(os.path.join(contentRoot, config.Configuration.logFolder))
if not os.path.isfile(os.path.join(contentRoot, "rejects.csv")):
file = open(os.path.join(contentRoot, "rejects.csv"), 'w')
file.write("#Header for lines that were not transmitted due to issue with interpretation\n")
file.close()
print("something")


class PlaceHolderException(Exception):
Expand Down

0 comments on commit 2fe0f48

Please sign in to comment.