def _data_to_attributes(self, data):
        """
        Convert tracked entity instance data, as returned by DHIS2, into a
        list of attributes, as accepted by DHIS2.
        """
        for attr in self._not_tracked_entity_attributes:
            data.pop(attr, None)
        # Convert data keys to tracked entity attribute IDs
        if any(key not in self._tracked_entity_attributes for key in data):
            # We are going to have to fetch at least one tracked entity
            # attribute ID. Fetch them all to avoid multiple API requests.
            self._fetch_tracked_entity_attributes()
        # Create a list of attributes, looking up the attribute ID of each one
        attributes = [{
            'attribute': self.get_te_attr_id(key),
            'value': value
        } for key, value in data.iteritems()]
        return attributes
dataset/ETHPy150Open dimagi/commcare-hq/custom/dhis2/models.py/Dhis2Api._data_to_attributes/original