Sha256: 05e9dfea7df2016de9bc81a56b5aaed19188df93abb18cb8a1a7b5be5af02778

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

module Dhis2
  module Api
    class DataElement < Base
      class << self
        def create(client, elements)
          elements          = [elements].flatten
          category_combo_id = client.category_combos.find_by(name: "default").id

          data_element = {
            data_elements: elements.map do |element|
              {
                name:             element[:name],
                short_name:       element[:short_name],
                code:             element[:code] || element[:short_name],
                domain_type:      element[:domain_type] || "AGGREGATE",
                value_type:       element[:value_type] || "NUMBER",
                aggregation_type: element[:aggregation_type] || "SUM",
                type:             element[:type] || "int", # for backward compatbility
                aggregation_operator: element[:aggregation_type] || "SUM", # for backward compatbility
                category_combo:   { id: category_combo_id }
              }
            end
          }

          response = client.post("metadata", data_element)
          Dhis2::Status.new(response)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dhis2-2.2.1 lib/dhis2/api/data_element.rb
dhis2-2.2.0 lib/dhis2/api/data_element.rb
dhis2-2.1.0 lib/dhis2/api/data_element.rb