icdbot / oldcode.py
oneilsh's picture
trying huggingface spaces...
c0aa211
raw
history blame
1.28 kB
# Not really useful, but don't want to delete it yet
def get_ancestors_yaml(self):
"""Returns a YAML string representing the node and its ancestors, with indentation. For example:
- A00 Cholera:
- A00.0 Cholera due to Vibrio cholerae 01, biovar cholerae
- A00.00 Cholera due to Vibrio cholerae 01, biovar cholerae, cholera gravis
..."""
my_yaml = f"- {self.code} {self.short_desc}:\n"
if self.parent:
parent_yaml, parent_level = self.parent.get_ancestors_yaml()
my_level = parent_level + 1
my_yaml = ' ' * (my_level) + my_yaml
yaml = parent_yaml + my_yaml
else:
yaml = my_yaml
my_level = 0
return yaml, my_level
def get_descendants_yaml(self):
"""Returns a YAML string representing the node and its descendants, with indentation. For example:
- A00 Cholera:
- A00.0 Cholera due to Vibrio cholerae 01, biovar cholerae
- A00.1 Cholera due to Vibrio cholerae 01, biovar eltor
- A00.9 Cholera, unspecified
..."""
yaml = f"- {self.code} {self.short_desc}:\n"
for child in self.children:
child_yaml = child.get_descendants_yaml()
child_yaml = child_yaml.replace('\n', '\n ')
yaml += f" {child_yaml}"
return yaml