File size: 1,280 Bytes
c0aa211
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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