require .icd to resolve ICD10 codes and limit answer to at most 5

This commit is contained in:
Context 77
2024-12-14 13:43:03 +01:00
parent f8f83e442f
commit 0abca6fb95

View File

@@ -21,17 +21,18 @@ class ICDObserver(PrivMsgObserverPrototype):
return None return None
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["message"].startswith(".icd "):
regex = r"\b(\w\d{2}\.?\d?\d?)\b" if data["channel"] == connection.details.get_channel():
codes = re.findall(regex, data["message"]) regex = r"\b(\w\d{2}\.?\d?\d?)\b"
for code in codes: codes = re.findall(regex, data["message"])
code = code.capitalize() for code in codes[:5]:
text = self.icd10_dict.get(code, False) code = code.capitalize()
if text == False: text = self.icd10_dict.get(code, False)
if "." in code: if text == False:
code += "-" if "." in code:
else: code += "-"
code += ".-" else:
text = self.icd10_dict.get(code, False) code += ".-"
if text: text = self.icd10_dict.get(code, False)
connection.send_back(f"{code} - {text}", data) if text:
connection.send_back(f"{code} - {text}", data)