schemas.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from typing import List, Optional, Dict, Union
  2. class CDSSInt:
  3. type: str
  4. value: Union[int, float]
  5. def __init__(self, type:str='nubmer' , value: Union[int,float]=0):
  6. self.type = type
  7. self.value = value
  8. def __str__(self):
  9. return f"{self.type}:{self.value}"
  10. def value(self):
  11. return self.value
  12. class CDSSText:
  13. type: str
  14. value: Union[str, List[str]]
  15. def __init__(self, type:str='text', value: Union[str, List[str]]=""):
  16. self.type = type
  17. self.value = value
  18. def __str__(self):
  19. if isinstance(self.value, str):
  20. return f"{self.type}:{self.value}"
  21. return f"{self.type}:{','.join(self.value)}"
  22. def value(self):
  23. return self.value
  24. class CDSSDict:
  25. type: str
  26. value: Dict
  27. def __init__(self, type:str='dict', value: Dict={}):
  28. self.type = type
  29. self.value = value
  30. def __str__(self):
  31. return f"{self.type}:{self.value}"
  32. def value(self):
  33. return self.value
  34. # pat_name:患者名字,字符串,如"张三",无患者信息输出""
  35. # pat_sex:患者性别,字符串,如"男",无患者信息输出""
  36. # pat_age:患者年龄,数字,单位为年,如25岁,输出25,无年龄信息输出0
  37. # clinical_department:就诊科室,字符串,如"呼吸内科",无就诊科室信息输出""
  38. # chief_complaint:主诉,字符串列表,包括主要症状的列表,如["胸痛","发热"],无主诉输出[]
  39. # present_illness:现病史,字符串列表,包括症状发展过程、诱因、伴随症状(如疼痛性质、放射部位、缓解方式,无现病史信息输出[]
  40. # past_medical_history:既往病史,字符串列表,包括疾病史(如高血压、糖尿病)、手术史、药物过敏史、家族史等,无现病史信息输出[]
  41. # physical_examination:体格检查,字符串列表,如生命体征(血压、心率)、心肺腹部体征、实验室/影像学结果(如心电图异常、肌钙蛋白升高),无信息输出[]
  42. # lab_and_imaging:检验与检查,字符串列表,包括血常规、生化指标、心电图(ECG)、胸部X光、CT等检查项目,结果和报告等,无信息输出[]
  43. class CDSSInput:
  44. def __init__(self, **kwargs):
  45. self.pat_age = CDSSInt(type='year', value=0)
  46. self.pat_sex = CDSSInt(type='sex', value=0)
  47. self.department = CDSSText(type='department', value="")
  48. self.values = []
  49. for key, value in kwargs.items():
  50. if hasattr(self, key):
  51. setattr(self, key, value)
  52. else:
  53. self.values.append(CDSSText(key, value))
  54. def get_value(self, key)->CDSSText:
  55. for value in self.values:
  56. if value.type == key:
  57. return value.value
  58. class CDSSOutput:
  59. def __init__(self):
  60. self.departments = CDSSDict(type='departments', value={})
  61. self.diagnosis = CDSSDict(type='diagnosis', value={})
  62. self.count_diagnosis = CDSSDict(type='diagnosis', value={})
  63. self.checks = CDSSDict(type='checks', value={})
  64. self.drugs = CDSSDict(type='drugs', value={})