Skip to content

Symptom tag

SymptomTag

Bases: IntEnum

A tag for the symptoms exhibited by a person.

Higher numbers are more severe.

Source code in june/epidemiology/infection/symptom_tag.py
 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class SymptomTag(IntEnum):
    """A tag for the symptoms exhibited by a person.

    Higher numbers are more severe.

    """

    @classmethod
    def load_from_yaml(cls, yaml_path: str):
        """Dynamically load symptom tags from a YAML file.

        Args:
            yaml_path (str): Path to the YAML file containing symptom tag definitions.

        Returns:
            dict: A dictionary mapping symptom tag names to their values.

        """
        with open(yaml_path, "r") as f:
            config = yaml.safe_load(f)

        symptom_tags = config.get("disease", {}).get("symptom_tags", [])
        if not symptom_tags:
            raise ValueError(f"No 'symptom_tags' found in YAML at {yaml_path}")

        return {tag["name"]: tag["value"] for tag in symptom_tags}

    @classmethod
    def from_string(cls, string: str, dynamic_tags: dict = None) -> "SymptomTag":
        """Convert a string to a SymptomTag, checking both static and dynamic tags.

        Args:
            string (str): The name of the symptom tag.
            dynamic_tags (dict, optional): A dictionary of dynamically loaded tags. (Default value = None)

        Returns:
            SymptomTag: 

        """


        # Check static tags first
        for item in SymptomTag:
            if item.name == string:
                return item

        # Check dynamic tags if provided
        if dynamic_tags and string in dynamic_tags:
            return dynamic_tags[string]

        raise ValueError(f"{string} is not a valid SymptomTag")

from_string(string, dynamic_tags=None) classmethod

Convert a string to a SymptomTag, checking both static and dynamic tags.

Parameters:

Name Type Description Default
string str

The name of the symptom tag.

required
dynamic_tags dict

A dictionary of dynamically loaded tags. (Default value = None)

None

Returns:

Name Type Description
SymptomTag SymptomTag
Source code in june/epidemiology/infection/symptom_tag.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@classmethod
def from_string(cls, string: str, dynamic_tags: dict = None) -> "SymptomTag":
    """Convert a string to a SymptomTag, checking both static and dynamic tags.

    Args:
        string (str): The name of the symptom tag.
        dynamic_tags (dict, optional): A dictionary of dynamically loaded tags. (Default value = None)

    Returns:
        SymptomTag: 

    """


    # Check static tags first
    for item in SymptomTag:
        if item.name == string:
            return item

    # Check dynamic tags if provided
    if dynamic_tags and string in dynamic_tags:
        return dynamic_tags[string]

    raise ValueError(f"{string} is not a valid SymptomTag")

load_from_yaml(yaml_path) classmethod

Dynamically load symptom tags from a YAML file.

Parameters:

Name Type Description Default
yaml_path str

Path to the YAML file containing symptom tag definitions.

required

Returns:

Name Type Description
dict

A dictionary mapping symptom tag names to their values.

Source code in june/epidemiology/infection/symptom_tag.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@classmethod
def load_from_yaml(cls, yaml_path: str):
    """Dynamically load symptom tags from a YAML file.

    Args:
        yaml_path (str): Path to the YAML file containing symptom tag definitions.

    Returns:
        dict: A dictionary mapping symptom tag names to their values.

    """
    with open(yaml_path, "r") as f:
        config = yaml.safe_load(f)

    symptom_tags = config.get("disease", {}).get("symptom_tags", [])
    if not symptom_tags:
        raise ValueError(f"No 'symptom_tags' found in YAML at {yaml_path}")

    return {tag["name"]: tag["value"] for tag in symptom_tags}