(
    dataset_map: Union[DataSetMap, SQLDataSetMap],
    ucr_row: dict,
)
return datavalues
Given a ``ucr_row`` that looks like ... ::

        {
            "org_unit_id": "ghi45678901",
            "data_element_cat_option_combo_1": 123,
            "data_element_cat_option_combo_2": 456,
            "data_element_cat_option_combo_3": 789,
        }

    ... returns rows of data values that look like ::

        {
            "dataElement": "abc45678901",
            "value": 123,
            "categoryOptionCombo": "def45678901",  /* optional */
            "period": 202101,  /* optional */
            "orgUnit": "ghi45678901",  /* optional */
            "comment": "A comment"  /* optional */
        }
Given a ``ucr_row`` that looks like ... ::
Given a ucr_row that looks like ... ::
def get_datavalues(
    dataset_map: Union[DataSetMap, SQLDataSetMap],
    ucr_row: dict,
) -> List[dict]:
    """
    Given a ``ucr_row`` that looks like ... ::

        {
            "org_unit_id": "ghi45678901",
            "data_element_cat_option_combo_1": 123,
            "data_element_cat_option_combo_2": 456,
            "data_element_cat_option_combo_3": 789,
        }

    ... returns rows of data values that look like ::

        {
            "dataElement": "abc45678901",
            "value": 123,
            "categoryOptionCombo": "def45678901",  /* optional */
            "period": 202101,  /* optional */
            "orgUnit": "ghi45678901",  /* optional */
            "comment": "A comment"  /* optional */
        }

    """
    info_for_columns = get_info_for_columns(dataset_map)

    datavalues = []
    org_unit = None
    period = None
    complete_date = None

    # First pass is to collate data element IDs and values
    for key, value in ucr_row.items():
        if key in info_for_columns:
            if info_for_columns[key]['is_org_unit']:
                org_unit = value
            elif info_for_columns[key]['is_period']:
                period = value
            elif info_for_columns[key]['is_complete_date']:
                complete_date = value
            else:
                datavalue = {
                    'dataElement': info_for_columns[key]['data_element_id'],
                    'value': value,
                }
                if info_for_columns[key].get('category_option_combo_id'):
                    datavalue['categoryOptionCombo'] = (
                        info_for_columns[key]['category_option_combo_id'])
                if info_for_columns[key].get('comment'):
                    datavalue['comment'] = info_for_columns[key]['comment']
                datavalues.append(datavalue)
    # Second pass is to set period, org unit and complete date
    if period or org_unit or complete_date:
        determine_complete_date_on_period_end = dataset_map.complete_date_option == COMPLETE_DATE_ON_PERIOD_END

        for datavalue in datavalues:
            if period:
                datavalue['period'] = period
                if determine_complete_date_on_period_end:
                    datavalue['completeDate'] = str(get_end_of_period(dataset_map.frequency, period))

            if org_unit:
                datavalue['orgUnit'] = org_unit

            # This implies dataset_map.complete_date_option == COMPLETE_DATE_COLUMN
            if complete_date:
                datavalue['completeDate'] = complete_date
    return datavalues
def get_datavalues ( dataset_map : Union [ DataSetMap , SQLDataSetMap ] , ucr_row : dict , ) -> List [ dict ] : info_for_columns = get_info_for_columns ( dataset_map ) datavalues = [ ] org_unit = None period = None complete_date = None # First pass is to collate data element IDs and values for key , value in ucr_row . items ( ) : if key in info_for_columns : if info_for_columns [ key ] [ 'is_org_unit' ] : org_unit = value elif info_for_columns [ key ] [ 'is_period' ] : period = value elif info_for_columns [ key ] [ 'is_complete_date' ] : complete_date = value else : datavalue = { 'dataElement' : info_for_columns [ key ] [ 'data_element_id' ] , 'value' : value , } if info_for_columns [ key ] . get ( 'category_option_combo_id' ) : datavalue [ 'categoryOptionCombo' ] = ( info_for_columns [ key ] [ 'category_option_combo_id' ] ) if info_for_columns [ key ] . get ( 'comment' ) : datavalue [ 'comment' ] = info_for_columns [ key ] [ 'comment' ] datavalues . append ( datavalue ) # Second pass is to set period, org unit and complete date if period or org_unit or complete_date : determine_complete_date_on_period_end = dataset_map . complete_date_option == COMPLETE_DATE_ON_PERIOD_END for datavalue in datavalues : if period : datavalue [ 'period' ] = period if determine_complete_date_on_period_end : datavalue [ 'completeDate' ] = str ( get_end_of_period ( dataset_map . frequency , period ) ) if org_unit : datavalue [ 'orgUnit' ] = org_unit # This implies dataset_map.complete_date_option == COMPLETE_DATE_COLUMN if complete_date : datavalue [ 'completeDate' ] = complete_date return datavalues