mirror of
https://github.com/nichkara/InfinitumBotty.git
synced 2026-06-10 22:26:23 +02:00
build a dict once with icd10 codes instead of reopening and scanning the file for every code
This commit is contained in:
@@ -6,6 +6,12 @@ from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
|
|||||||
|
|
||||||
|
|
||||||
class ICDObserver(PrivMsgObserverPrototype):
|
class ICDObserver(PrivMsgObserverPrototype):
|
||||||
|
with open("care_icd10_de.csv", "r", encoding="utf8") as icd10_codes:
|
||||||
|
icd10_dict = {
|
||||||
|
row[0]: row[1]
|
||||||
|
for row in csv.reader(icd10_codes, delimiter=";", quotechar='"')
|
||||||
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def cmd():
|
def cmd():
|
||||||
return None
|
return None
|
||||||
@@ -14,27 +20,18 @@ class ICDObserver(PrivMsgObserverPrototype):
|
|||||||
def help():
|
def help():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_icd(self, code):
|
|
||||||
icd10_codes = open('care_icd10_de.csv', 'r',encoding='utf8')
|
|
||||||
icd10 = csv.reader(icd10_codes, delimiter=';', quotechar='"')
|
|
||||||
for row in icd10:
|
|
||||||
if row[0] == code:
|
|
||||||
return code +' - ' + row[1]
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def update_on_priv_msg(self, data, connection: Connection):
|
def update_on_priv_msg(self, data, connection: Connection):
|
||||||
if data['channel'] != connection.details.get_channel():
|
if data["channel"] == connection.details.get_channel():
|
||||||
return
|
regex = r"\b(\w\d{2}\.?\d?\d?)\b"
|
||||||
regex = r'\b(\w\d{2}\.?\d?\d?)\b'
|
codes = re.findall(regex, data["message"])
|
||||||
codes = re.findall(regex, data['message'])
|
for code in codes:
|
||||||
for code in codes:
|
code = code.capitalize()
|
||||||
code = code.capitalize()
|
text = self.icd10_dict.get(code, False)
|
||||||
text = self.get_icd(code)
|
if text == False:
|
||||||
if text == 0:
|
if "." in code:
|
||||||
if code.find('.') != -1:
|
code += "-"
|
||||||
code += '-'
|
else:
|
||||||
else:
|
code += ".-"
|
||||||
code += '.-'
|
text = self.icd10_dict.get(code, False)
|
||||||
text = self.get_icd(code)
|
if text:
|
||||||
if text != 0:
|
connection.send_back(f"{code} - {text}", data)
|
||||||
connection.send_back(text, data)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user