Module: ADIWG::Mdcodes

Defined in:
lib/adiwg/mdcodes.rb,
lib/adiwg/mdcodes/version.rb

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.getAllCodeistsDetail(format = 'hash') ⇒ Object

return all codelists with full details



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/adiwg/mdcodes.rb', line 27

def self.getAllCodeistsDetail(format='hash')
    path = getYamlPath + '/*.yml'
    hCodeLists = {}
    Dir.glob(path) do |item|
        hCodeList = YAML.load_file(item)
        hCodeLists[hCodeList['codelistName']] = hCodeList
    end
      if format == 'json'
        return hCodeLists.to_json
      else
        return hCodeLists
      end
end

.getAllStaticCodelists(format = 'hash') ⇒ Object

return all static codelist with only the item names



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/adiwg/mdcodes.rb', line 57

def self.getAllStaticCodelists(format='hash')
    codeLists = getAllCodeistsDetail
    hCodeLists = {}
    codeLists.each do |key, value|
        if value['codelistType'] == 'staticList'
            aItems = value['codelist']
            aList = []
            aItems.each do |item|
                aList << item['codeName']
            end
            hCodeLists[key] = aList
        end
    end
      if format == 'json'
        hCodeLists.to_json if format == 'json'
      else
        return hCodeLists
      end
end

.getCodelistDetail(codeList, format = 'hash') ⇒ Object

return a single codelist with full details



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/adiwg/mdcodes.rb', line 42

def self.getCodelistDetail(codeList, format='hash')
    file = File.join(getYamlPath, codeList + '.yml')
    if File.exist?(file)
        hCodeList = YAML.load_file(file)
    else
        return nil
    end
      if format == 'json'
        return hCodeList.to_json
      else
        return hCodeList
      end
end

.getStaticCodelist(codeList, format = 'hash') ⇒ Object

return a single static codelist with only the item names



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/adiwg/mdcodes.rb', line 78

def self.getStaticCodelist(codeList, format='hash')
    hCodeList = getCodelistDetail(codeList)
    if hCodeList
        hCodeNames = {}
        aItems = hCodeList['codelist']
        aList = []
        aItems.each do |item|
            aList << item['codeName']
        end
        hCodeNames[hCodeList['codelistName']] = aList
        if format == 'json'
            return hCodeNames.to_json
        else
            return hCodeNames
        end
    else
        return nil
    end
end

.getYamlPathObject

return the path to yaml files.



22
23
24
# File 'lib/adiwg/mdcodes.rb', line 22

def self.getYamlPath
    File.join(File.dirname(__FILE__),'..','..','resources')
end