# Path: dhis2_core/src/dhis2/e2b/models/e2b.py
# class AttributeValue(BaseModel):
#     created: datetime
#     lastUpdated: datetime
#     attribute: str
#     value: str
#     storedBy: Optional[str]
# 
# 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 typing import Dict
from dhis2.core.http import BaseHttpRequest
from dhis2.core.inventory import HostResolved, resolve_one
from .models.e2b import AttributeValue, EventDataValue, TrackedEntity
import click
import dhis2.e2b.r2 as r2
#!/usr/bin/env python





def require_program(host: HostResolved, pr: str) -> None:
    request = BaseHttpRequest(host)
    request.get(f"api/programs/{pr}")


def get_aefi_patient(host: HostResolved, pr: str, te: str) -> TrackedEntity:
    require_program(host, pr)
    request = BaseHttpRequest(host)
    response = request.get(
        f"api/trackedEntityInstances/{te}",
        params={
            "fields": "*",
            "program": pr,
        },
    )


# Path: dhis2_core/src/dhis2/e2b/models/e2b.py
# class AttributeValue(BaseModel):
#     created: datetime
#     lastUpdated: datetime
#     attribute: str
#     value: str
#     storedBy: Optional[str]
# 
# 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/cli.py
from typing import Dict
from dhis2.core.http import BaseHttpRequest
from dhis2.core.inventory import HostResolved, resolve_one
from .models.e2b import AttributeValue, EventDataValue, TrackedEntity
import click
import dhis2.e2b.r2 as r2

#!/usr/bin/env python





def require_program(host: HostResolved, pr: str) -> None:
    request = BaseHttpRequest(host)
    request.get(f"api/programs/{pr}")


def get_aefi_patient(host: HostResolved, pr: str, te: str) -> TrackedEntity:
    require_program(host, pr)
    request = BaseHttpRequest(host)
    response = request.get(
        f"api/trackedEntityInstances/{te}",
        params={
            "fields": "*",
            "program": pr,
        },
    )


    te = TrackedEntity(**response)