(
    dataset_map: SQLDataSetMap,
    send_date: datetime.date
)
Sends a data set of data values in the following format. "period" is
    determined from ``send_date``. ::

        {
            "dataSet": "dataSetID",
            "completeDate": "date",
            "period": "period",
            "orgUnit": "orgUnitID",
            "attributeOptionCombo", "aocID",
            "dataValues": [
                {
                    "dataElement": "dataElementID",
                    "categoryOptionCombo": "cocID",
                    "value": "1",
                    "comment": "comment1"
                },
                {
                    "dataElement": "dataElementID",
                    "categoryOptionCombo": "cocID",
                    "value": "2",
                    "comment": "comment2"
                },
                {
                    "dataElement": "dataElementID",
                    "categoryOptionCombo": "cocID",
                    "value": "3",
                    "comment": "comment3"
                }
            ]
        }

    See `DHIS2 API docs`_ for more details.


    .. _DHIS2 API docs: https://docs.dhis2.org/master/en/developer/html/webapi_data_values.html
Sends a data set of data values in the following format. "period" is
    determined from ``send_date``. ::
Sends a data set of data values in the following format . period is determined from send_date . ::
def send_dataset(
    dataset_map: SQLDataSetMap,
    send_date: datetime.date
) -> dict:
    """
    Sends a data set of data values in the following format. "period" is
    determined from ``send_date``. ::

        {
            "dataSet": "dataSetID",
            "completeDate": "date",
            "period": "period",
            "orgUnit": "orgUnitID",
            "attributeOptionCombo", "aocID",
            "dataValues": [
                {
                    "dataElement": "dataElementID",
                    "categoryOptionCombo": "cocID",
                    "value": "1",
                    "comment": "comment1"
                },
                {
                    "dataElement": "dataElementID",
                    "categoryOptionCombo": "cocID",
                    "value": "2",
                    "comment": "comment2"
                },
                {
                    "dataElement": "dataElementID",
                    "categoryOptionCombo": "cocID",
                    "value": "3",
                    "comment": "comment3"
                }
            ]
        }

    See `DHIS2 API docs`_ for more details.


    .. _DHIS2 API docs: https://docs.dhis2.org/master/en/developer/html/webapi_data_values.html

    """
    # payload_id lets us filter API logs, and uniquely identifies the
    # dataset map, to help AEs and administrators link an API log back
    # to a dataset map.
    payload_id = f'dhis2/map/{dataset_map.pk}/'
    response_log_url = reverse(
        'motech_log_list_view',
        args=[dataset_map.domain],
        params={'filter_payload': payload_id}
    )

    with dataset_map.connection_settings.get_requests(payload_id) as requests:
        response = None
        try:
            datavalues_sets = parse_dataset_for_request(dataset_map, send_date)

            for datavalues_set in datavalues_sets:
                response = requests.post('/api/dataValueSets', json=datavalues_set,
                              raise_for_status=True)

        except DatabaseError as db_err:
            requests.notify_error(message=str(db_err),
                                  details=traceback.format_exc())
            return {
                'success': False,
                'error': _('There was an error retrieving some UCR data. '
                           'Try contacting support to help resolve this issue.'),
                'text': None,
                'log_url': response_log_url,
            }

        except Exception as err:
            requests.notify_error(message=str(err),
                                  details=traceback.format_exc())
            text = pformat_json(response.text if response else None)

            return {
                'success': False,
                'error': str(err),
                'status_code': response.status_code if response else None,
                'text': text,
                'log_url': response_log_url,
            }
        else:
            return {
                'success': True,
                'status_code': response.status_code,
                'text': pformat_json(response.text),
                'log_url': response_log_url,
            }
def send_dataset ( dataset_map : SQLDataSetMap , send_date : datetime . date ) -> dict : # payload_id lets us filter API logs, and uniquely identifies the # dataset map, to help AEs and administrators link an API log back # to a dataset map. payload_id = f'dhis2/map/{dataset_map.pk}/' response_log_url = reverse ( 'motech_log_list_view' , args = [ dataset_map . domain ] , params = { 'filter_payload' : payload_id } ) with dataset_map . connection_settings . get_requests ( payload_id ) as requests : response = None try : datavalues_sets = parse_dataset_for_request ( dataset_map , send_date ) for datavalues_set in datavalues_sets : response = requests . post ( '/api/dataValueSets' , json = datavalues_set , raise_for_status = True ) except DatabaseError as db_err : requests . notify_error ( message = str ( db_err ) , details = traceback . format_exc ( ) ) return { 'success' : False , 'error' : _ ( 'There was an error retrieving some UCR data. ' 'Try contacting support to help resolve this issue.' ) , 'text' : None , 'log_url' : response_log_url , } except Exception as err : requests . notify_error ( message = str ( err ) , details = traceback . format_exc ( ) ) text = pformat_json ( response . text if response else None ) return { 'success' : False , 'error' : str ( err ) , 'status_code' : response . status_code if response else None , 'text' : text , 'log_url' : response_log_url , } else : return { 'success' : True , 'status_code' : response . status_code , 'text' : pformat_json ( response . text ) , 'log_url' : response_log_url , }