Sha256: 018da0492fd8b84ec291c1d479ea95fce0d66eeb455b3c9d1d95c318fe2ab9a9

Contents?: true

Size: 898 Bytes

Versions: 5

Compression:

Stored size: 898 Bytes

Contents

# frozen_string_literal: true
module Dhis2
  module Api
    class DataElementGroup < Base
      class << self
        def create(client, groups)
          groups = [groups].flatten
          de_groups = {
            data_element_groups: groups.map do |group|
              mapped_group = {
                name:       group[:name],
                short_name: group[:short_name],
                code:       group[:code] || group[:short_name]
              }

              if group[:data_elements]
                data_elements = group[:data_elements].map do |element|
                  { id: element[:id] }
                end
                mapped_group[:data_elements] = data_elements
              end
              mapped_group
            end
          }
          response = client.post("metadata", de_groups)
          Dhis2::Status.new(response)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dhis2-2.3.5 lib/dhis2/api/data_element_group.rb
dhis2-2.3.4 lib/dhis2/api/data_element_group.rb
dhis2-2.3.3 lib/dhis2/api/data_element_group.rb
dhis2-2.3.2 lib/dhis2/api/data_element_group.rb
dhis2-2.3.1 lib/dhis2/api/data_element_group.rb