Skip to content

Commit

Permalink
Imahara edition will not crash out when result string is uninterpreta…
Browse files Browse the repository at this point in the history
…ble, but will throw multiple warnings and explanations when encountering one. Will also remove it from the submission to avoid submitting a sample with blank results.
  • Loading branch information
michael-weinstein committed Jul 17, 2020
1 parent cf6806a commit 688ddab
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
5 changes: 5 additions & 0 deletions zymoTransmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ def makeHL7Codes(resultList:typing.List[zymoTransmitSupport.inputOutput.resultRe
currentSet.append(zymoTransmitSupport.hl7Encoder.encoders.makeSPMLine(result))
if result.note:
currentSet.append(zymoTransmitSupport.hl7Encoder.encoders.makeNTELine(result))
if not result.okToTransmit:
print("Skipping preparation of %s:%s for the following reasons:" %(result.patientID, result.specimenID))
for reason in result.reasonsNotToTransmit:
print("\t%s" %reason)
del hl7Sets[(patientID, specimenID)]
return hl7Sets


Expand Down
8 changes: 4 additions & 4 deletions zymoTransmitSupport/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Facility:
idType = "CLIA"

class ResultTerms:
positiveResultTerms = ["POSITIVE", "DETECTED", "POS"]
indeterminateResultTerms = ["INDETERMINATE", "N/A", "UNKNOWN", "INCONCLUSIVE", "INVALID"]
negativeResultTerms = ["ND", "NEG", "NEGATIVE", "NOT DETECTED"]
unsatisfactorySpecimenResultTerms = ["UNSATISFACTORY SPECIMEN", "SPECIMEN UNSATISFACTORY", "UNSATISFACTORY"]
positiveResultTerms = ["POSITIVE", "DETECTED", "POS", "260373001", "SARS-COV-2 NUCLEIC ACID DETECTED BY BDMAX", "POSITIVE SARS-COV-2", "DETECT", "REACTIVE", "DETECT", "2019-NCOV NUCLEIC ACID DETECTED BY GENEXPERT"]
indeterminateResultTerms = ["INDETERMINATE", "N/A", "UNKNOWN", "INCONCLUSIVE", "INVALID", "419984006"]
negativeResultTerms = ["ND", "NEG", "NEGATIVE", "NOT DETECTED", "260415000", "NOTDET", "NONE DETECTED", "NONREACTIVE", "NON-REACTIVE", "NOT_DETECTED", "COVID-19 (SARS-COV-2) RNA: NOT DETECTED"]
unsatisfactorySpecimenResultTerms = ["UNSATISFACTORY SPECIMEN", "SPECIMEN UNSATISFACTORY", "UNSATISFACTORY", "125154007"]
9 changes: 7 additions & 2 deletions zymoTransmitSupport/hl7Encoder/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ def makeOBRLine(result:inputOutput.resultReader.TestResult):
def makeOBXLine(result:inputOutput.resultReader.TestResult):
def makeObservationValueAndAbnormalityObjects(resultString:str):
resultStringUpper = resultString.upper()
if resultStringUpper in config.ResultTerms.indeterminateResultTerms:
if "NOT DETECTED" in resultStringUpper:
resultTerm = "negative"
elif resultStringUpper in config.ResultTerms.indeterminateResultTerms:
resultTerm = "indeterminate"
elif resultStringUpper in config.ResultTerms.positiveResultTerms:
resultTerm = "detected"
Expand All @@ -209,7 +211,10 @@ def makeObservationValueAndAbnormalityObjects(resultString:str):
elif resultStringUpper in config.ResultTerms.unsatisfactorySpecimenResultTerms:
resultTerm = "unsatisfactory"
else:
raise ValueError("Unable to classify result '%s'. Preferred terms are: detected, indeterminate, negative, and unsatisfactory specimen." %resultString)
print("Unable to classify result '%s' for patient %s specimen %s. Preferred terms are: detected, indeterminate, negative, and unsatisfactory specimen." %(resultString, result.patientID, result.specimenID))
resultTerm = ""
result.okToTransmit = False
result.reasonsNotToTransmit.append("Failed to interpret result value")
return (observedResults.getObservationValue(resultTerm),
observedResults.getAbnormalityObject(resultTerm))

Expand Down
8 changes: 6 additions & 2 deletions zymoTransmitSupport/hl7Encoder/observedResults.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def getObservationValue(result:str):
:param result: String describing the result. Must be in ["detected", "indeterminate", "negative"]
:return: An appropriate result as a generics.SystemCode object
'''
validResults = ["detected", "indeterminate", "negative", "unsatisfactory"]
validResults = ["detected", "indeterminate", "negative", "unsatisfactory", ""]
if not result in validResults:
raise ValueError("Result type must be in: " %validResults)
if result == "detected":
Expand All @@ -43,6 +43,8 @@ def getObservationValue(result:str):
return generics.SystemCode(code="260415000", text="Not detected", coding="SNOMED", codingSystemDateOrVersion="2.7")
elif result == "unsatisfactory":
return generics.SystemCode(code="125154007", text="Specimen unsatisfactory", coding="SNOMED", codingSystemDateOrVersion="2.7")
elif result == "":
return ""
else:
raise RuntimeError("This code should be unreachable if result validations is working properly and how we got here needs to be investigated")

Expand All @@ -61,7 +63,7 @@ def getAbnormalityObject(result:str):
:param result: String describing the result. Must be in ["detected", "indeterminate", "negative"]
:return: An appropriate result as a generics.SystemCode object
'''
validResults = ["detected", "indeterminate", "negative", "unsatisfactory"]
validResults = ["detected", "indeterminate", "negative", "unsatisfactory", ""]
if not result in validResults:
raise ValueError("Result type must be in: " %validResults)
if result == "detected":
Expand All @@ -72,6 +74,8 @@ def getAbnormalityObject(result:str):
return generics.SystemCode(code="260415000", text="Not detected", coding="SNOMED", codingSystemDateOrVersion="2.7")
elif result == "unsatisfactory":
return generics.SystemCode(code="125154007", text="Specimen unsatisfactory", coding="SNOMED", codingSystemDateOrVersion="2.7")
elif result == "":
return ""
else:
raise RuntimeError("This code should be unreachable if result validations is working properly and how we got here needs to be investigated")

Expand Down
2 changes: 2 additions & 0 deletions zymoTransmitSupport/inputOutput/resultReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def __init__(self, rawLine: [str, collections.Iterable], delimiter: str = "\t"):
self.analysisDateTime = self.processDateAndTime(analysisDate, analysisTime)
self.reportedDateTime = self.processDateAndTime(reportedDate, reportedTime)
self.auxiliaryData = {}
self.okToTransmit = True
self.reasonsNotToTransmit = []

def processRawLine(self, delimiter):
rawLine = self.rawLine.strip()
Expand Down

0 comments on commit 688ddab

Please sign in to comment.