# Path: dhis2_core/src/dhis2/facility_list/mcsd_resources.py
# def build_bundle(org_units: List[OrgUnit], base_url: str) -> Bundle:
#     bundle = Bundle()
#     bundle.type = "transaction"
#     bundle.entry = []
# 
#     log.info(f"Building FHIR bundle from '{len(org_units)}' organisation units")
# 
#     for org_unit in org_units:
#         bundle.entry.append(build_location_bundle_entry(org_unit, base_url))
#         bundle.entry.append(build_organization_bundle_entry(org_unit, base_url))
# 
#     return bundle
# 
# Path: dhis2_core/src/dhis2/facility_list/models/mcsd.py
# class MCSDConfig(BaseModel):
#     id: str = Field(default_factory=lambda: str(uuid4()))
#     source: MCSDSource
#     target: MCSDTarget
# 
# class OrgUnit(BaseEntity):
#     geometry: Optional[OrgUnitGeometry]
#     parent: Optional[BaseEntity]


import json
import logging
import sys
from typing import Any, Callable, Dict, List
from dhis2.core.http import BaseHttpRequest
from dhis2.core.inventory import HostResolved, Inventory, resolve_one
from fhir.resources.bundle import Bundle
from .mcsd_resources import build_bundle
from .models.mcsd import MCSDConfig, OrgUnit
        sys.exit(-1)

    log.info(f"Creating source from '{host.key}' with base url '{host.baseUrl}'")

    def call():
        req = BaseHttpRequest(host)
        filter = list(map(lambda x: f"id:eq:{x}", config.source.filters))

        # https://docs.dhis2.org/2.35/en/developer/html/webapi_metadata_object_filter.html
        if config.source.lastUpdated:
            filter.append(f"lastUpdated:ge:{config.source.lastUpdated}")

        data = req.get(
            "api/organisationUnits",
            params={
                "fields": "id,code,name,translations,geometry,parent[id,code]",
                "rootJunction": "OR",
                "filter": filter,
                "paging": False,
            },
        )

        return (
            host,
            data,
        )

    return call



# Path: dhis2_core/src/dhis2/facility_list/mcsd_resources.py
# def build_bundle(org_units: List[OrgUnit], base_url: str) -> Bundle:
#     bundle = Bundle()
#     bundle.type = "transaction"
#     bundle.entry = []
# 
#     log.info(f"Building FHIR bundle from '{len(org_units)}' organisation units")
# 
#     for org_unit in org_units:
#         bundle.entry.append(build_location_bundle_entry(org_unit, base_url))
#         bundle.entry.append(build_organization_bundle_entry(org_unit, base_url))
# 
#     return bundle
# 
# Path: dhis2_core/src/dhis2/facility_list/models/mcsd.py
# class MCSDConfig(BaseModel):
#     id: str = Field(default_factory=lambda: str(uuid4()))
#     source: MCSDSource
#     target: MCSDTarget
# 
# class OrgUnit(BaseEntity):
#     geometry: Optional[OrgUnitGeometry]
#     parent: Optional[BaseEntity]


# Path: dhis2_core/src/dhis2/facility_list/mcsd.py
import json
import logging
import sys
from typing import Any, Callable, Dict, List
from dhis2.core.http import BaseHttpRequest
from dhis2.core.inventory import HostResolved, Inventory, resolve_one
from fhir.resources.bundle import Bundle
from .mcsd_resources import build_bundle
from .models.mcsd import MCSDConfig, OrgUnit

        sys.exit(-1)

    log.info(f"Creating source from '{host.key}' with base url '{host.baseUrl}'")

    def call():
        req = BaseHttpRequest(host)
        filter = list(map(lambda x: f"id:eq:{x}", config.source.filters))

        # https://docs.dhis2.org/2.35/en/developer/html/webapi_metadata_object_filter.html
        if config.source.lastUpdated:
            filter.append(f"lastUpdated:ge:{config.source.lastUpdated}")

        data = req.get(
            "api/organisationUnits",
            params={
                "fields": "id,code,name,translations,geometry,parent[id,code]",
                "rootJunction": "OR",
                "filter": filter,
                "paging": False,
            },
        )

        return (
            host,
            data,
        )

    return call



def get_target(config: MCSDConfig, inventory: Inventory) -> Callable[[Any], Any]: