diff --git a/zymoTransmit.py b/zymoTransmit.py index 809c4ba..2b3ceff 100644 --- a/zymoTransmit.py +++ b/zymoTransmit.py @@ -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 diff --git a/zymoTransmitSupport/config.py b/zymoTransmitSupport/config.py index db28617..2d871b8 100644 --- a/zymoTransmitSupport/config.py +++ b/zymoTransmitSupport/config.py @@ -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"] \ No newline at end of file + 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"] \ No newline at end of file diff --git a/zymoTransmitSupport/hl7Encoder/encoders.py b/zymoTransmitSupport/hl7Encoder/encoders.py index a497b32..8e2a347 100644 --- a/zymoTransmitSupport/hl7Encoder/encoders.py +++ b/zymoTransmitSupport/hl7Encoder/encoders.py @@ -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" @@ -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)) diff --git a/zymoTransmitSupport/hl7Encoder/observedResults.py b/zymoTransmitSupport/hl7Encoder/observedResults.py index e12c5fc..33fadfa 100644 --- a/zymoTransmitSupport/hl7Encoder/observedResults.py +++ b/zymoTransmitSupport/hl7Encoder/observedResults.py @@ -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": @@ -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") @@ -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": @@ -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") diff --git a/zymoTransmitSupport/inputOutput/resultReader.py b/zymoTransmitSupport/inputOutput/resultReader.py index 52c311c..ee964f2 100644 --- a/zymoTransmitSupport/inputOutput/resultReader.py +++ b/zymoTransmitSupport/inputOutput/resultReader.py @@ -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()