# Path: dhis2_core/src/dhis2/e2b/models/e2b.py
# class Enrollment(BaseModel):
#     created: datetime
#     lastUpdated: datetime
#     enrollment: str
#     trackedEntityInstance: str
#     orgUnit: str
#     storedBy: Optional[str]
#     status: str
#     completedDate: Optional[str]
#     events: List[Event] = []
#     attributes: Union[Dict[str, AttributeValue], List[AttributeValue]] = []
# 
# class Event(BaseModel):
#     created: datetime
#     lastUpdated: datetime
#     event: str
#     program: str
#     programStage: str
#     trackedEntityInstance: str
#     orgUnit: str
#     status: str
#     dueDate: datetime
#     eventDate: datetime
#     completedDate: Optional[str]
#     storedBy: Optional[str]
#     dataValues: Union[Dict[str, EventDataValue], List[EventDataValue]] = []
# 
# class EventDataValue(BaseModel):
#     created: datetime
#     lastUpdated: datetime
#     dataElement: str
#     value: str
#     providedElsewhere: bool
#     storedBy: Optional[str]
# 
# class TrackedEntity(BaseModel):
#     created: datetime
#     lastUpdated: datetime
#     trackedEntityInstance: str
#     trackedEntityType: str
#     orgUnit: str
#     storedBy: Optional[str]
#     enrollments: List[Enrollment] = []
#     attributes: Union[Dict[str, AttributeValue], List[AttributeValue]] = []


from datetime import datetime
from typing import Union
from .models.e2b import Enrollment, Event, EventDataValue, TrackedEntity


def get_yes_no(de: str, te: TrackedEntity, idx: int = 0):
    dv: EventDataValue = get_data_value(de, te, idx)

    if "true" == dv:
        return "1"

    return "2"


def get_patient_sex(te: TrackedEntity) -> str:
    value = get_attribute_value("CklPZdOd6H1", te)

    if not value:
        value = get_attribute_value("oindugucx72", te)

    if "MALE" == value:
        return "1"
    elif "FEMALE" == value:
        return "2"

    return ""


def get_reaction_outcome(te: TrackedEntity):
    value = get_data_value("yRrSDiR5v1M", te)

    if "Recovered/resolved" == value:
        return "1"

# Path: dhis2_core/src/dhis2/e2b/models/e2b.py
# class Enrollment(BaseModel):
#     created: datetime
#     lastUpdated: datetime
#     enrollment: str
#     trackedEntityInstance: str
#     orgUnit: str
#     storedBy: Optional[str]
#     status: str
#     completedDate: Optional[str]
#     events: List[Event] = []
#     attributes: Union[Dict[str, AttributeValue], List[AttributeValue]] = []
# 
# class Event(BaseModel):
#     created: datetime
#     lastUpdated: datetime
#     event: str
#     program: str
#     programStage: str
#     trackedEntityInstance: str
#     orgUnit: str
#     status: str
#     dueDate: datetime
#     eventDate: datetime
#     completedDate: Optional[str]
#     storedBy: Optional[str]
#     dataValues: Union[Dict[str, EventDataValue], List[EventDataValue]] = []
# 
# class EventDataValue(BaseModel):
#     created: datetime
#     lastUpdated: datetime
#     dataElement: str
#     value: str
#     providedElsewhere: bool
#     storedBy: Optional[str]
# 
# class TrackedEntity(BaseModel):
#     created: datetime
#     lastUpdated: datetime
#     trackedEntityInstance: str
#     trackedEntityType: str
#     orgUnit: str
#     storedBy: Optional[str]
#     enrollments: List[Enrollment] = []
#     attributes: Union[Dict[str, AttributeValue], List[AttributeValue]] = []


# Path: dhis2_core/src/dhis2/e2b/common.py
from datetime import datetime
from typing import Union
from .models.e2b import Enrollment, Event, EventDataValue, TrackedEntity



def get_yes_no(de: str, te: TrackedEntity, idx: int = 0):
    dv: EventDataValue = get_data_value(de, te, idx)

    if "true" == dv:
        return "1"

    return "2"


def get_patient_sex(te: TrackedEntity) -> str:
    value = get_attribute_value("CklPZdOd6H1", te)

    if not value:
        value = get_attribute_value("oindugucx72", te)

    if "MALE" == value:
        return "1"
    elif "FEMALE" == value:
        return "2"

    return ""


def get_reaction_outcome(te: TrackedEntity):
    value = get_data_value("yRrSDiR5v1M", te)

    if "Recovered/resolved" == value:
        return "1"

    elif "Recovering/resolving" == value: