| |
| 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 |
|
|