[3] | 1 | #! /usr/bin/env ruby
|
---|
| 2 | # component: openEHR Ruby reference implementation
|
---|
| 3 | # description: This file includes Archetype
|
---|
| 4 | # class that contains Archetype values.
|
---|
| 5 | # Main concept is based on Java ref impl.
|
---|
| 6 | # We should make refactoring to suit for Ruby way.
|
---|
| 7 | # keywords: archetype
|
---|
| 8 | # author: Shinji KOBAYASHI
|
---|
| 9 | # support: openEHR.jp
|
---|
| 10 | # license: openEHR open source license
|
---|
| 11 | #
|
---|
| 12 | require 'set'
|
---|
| 13 | class Archetype < AuthordResource
|
---|
| 14 | attr_reader :adlVersion, :id, :parentId
|
---|
| 15 | attr_reader :concept, :definition, :ontology
|
---|
| 16 | attr_accessor :description, :isControled, :originalLanguage
|
---|
| 17 | attr_accessor :revisionHistory, :translation
|
---|
| 18 | def initialize(adlVersion, id = nil , parentId, concept
|
---|
| 19 | originalLanguage = nil, translation = nil
|
---|
| 20 | description, revisionHistory, isControled
|
---|
| 21 | defitnition, ontology)
|
---|
| 22 | if id == nil
|
---|
| 23 | raise Exception.new("illegal argument error, id == nil")
|
---|
| 24 | end
|
---|
| 25 | if originalLanguage == nil
|
---|
| 26 | raise Exception.new("illegal argument error, originalLanguage == nil")
|
---|
| 27 | end
|
---|
| 28 | if translation == nil
|
---|
| 29 | raise Exception.new("illegal argument error, translation == nil")
|
---|
| 30 | end
|
---|
| 31 | @adlVersion = adlVersion
|
---|
| 32 | @id = id
|
---|
| 33 | @parentId = parentId
|
---|
| 34 | @concept = concept
|
---|
| 35 | @originalLanguage = originalLanguage
|
---|
| 36 | @translation = translation
|
---|
| 37 | @description = description
|
---|
| 38 | @revisionHistory = revisionHistory
|
---|
| 39 | @isControled = isControled
|
---|
| 40 | @defitnition = defitnition
|
---|
| 41 | @ontology = ontology
|
---|
| 42 | loadMaps(definition)
|
---|
| 43 | end
|
---|
| 44 |
|
---|
| 45 | end
|
---|
| 46 | class AuthoredResource
|
---|
| 47 | attr_reader :is_controled
|
---|
| 48 | attr_reader :revision_history, :translations
|
---|
| 49 | attr_accessor :description, :original_language
|
---|
| 50 | def initialize(original_language, translations,
|
---|
| 51 | description, revision_history = nil)
|
---|
| 52 | if original_language == nil
|
---|
| 53 | raise Exception.new("original language nil")
|
---|
| 54 | end
|
---|
| 55 | if translations == nil
|
---|
| 56 | raise Exception.new("translation empty")
|
---|
| 57 | end
|
---|
| 58 | if revision_history == nil
|
---|
| 59 | is_controled = false
|
---|
| 60 | else
|
---|
| 61 | is_controled = true
|
---|
| 62 | end
|
---|
| 63 | @original_language = original_language
|
---|
| 64 | @translations = translations
|
---|
| 65 | @description = description
|
---|
| 66 | @revision_history = revision_history
|
---|
| 67 | end
|
---|
| 68 | def current_version
|
---|
| 69 | @revision_history.most_recent_revision
|
---|
| 70 | end
|
---|
| 71 | def language_available
|
---|
| 72 | languages = Set.new
|
---|
| 73 | if translations != nil
|
---|
| 74 | languages << translations.keys
|
---|
| 75 | end
|
---|
| 76 | languages << original_language.code_string
|
---|
| 77 | end
|
---|
| 78 | end
|
---|
| 79 | class RevisionHistory
|
---|
| 80 | end
|
---|
| 81 | class CodePhrase
|
---|
| 82 | attr_reader :terminology_id, :code_string
|
---|
| 83 | def initialize(terminology_id, codeString)
|
---|
| 84 | if terminlogyID == nil
|
---|
| 85 | raise Exception.new("nil terminology")
|
---|
| 86 | end
|
---|
| 87 | if codeString == nil
|
---|
| 88 | raise Exception.new("empty codeString")
|
---|
| 89 | end
|
---|
| 90 | if terminology_id.instance_of?(TerminologyID)
|
---|
| 91 | @terminology_id = terminology_id
|
---|
| 92 | else
|
---|
| 93 | @terminologyID = TerminologyID.new(terminology_id)
|
---|
| 94 | end
|
---|
| 95 | @code_string = code_string
|
---|
| 96 | end
|
---|
| 97 | end
|
---|
| 98 |
|
---|
| 99 | class TerminologyID < ObjectID
|
---|
| 100 | attr_reader :name
|
---|
| 101 | def initialize(arg0, arg1=nil)
|
---|
| 102 | if arg1 == nil
|
---|
| 103 | super(arg0)
|
---|
| 104 | else
|
---|
| 105 | super(toValue(arg0, arg1))
|
---|
| 106 | @name = arg0
|
---|
| 107 | @version = arg1
|
---|
| 108 | end
|
---|
| 109 | end
|
---|
| 110 | def setValue(value)
|
---|
| 111 | loadValue(value)
|
---|
| 112 | super.value = value
|
---|
| 113 | end
|
---|
| 114 | def version_id
|
---|
| 115 | @version
|
---|
| 116 | end
|
---|
| 117 | private
|
---|
| 118 | def loadValue(value)
|
---|
| 119 | if /\(.*\)$/ =~ value
|
---|
| 120 | @name, @version = value.split(\())
|
---|
| 121 | @version.chop!
|
---|
| 122 | else
|
---|
| 123 | @name = value
|
---|
| 124 | @version = nil
|
---|
| 125 | end
|
---|
| 126 | end
|
---|
| 127 |
|
---|
| 128 | def toValue(name, version)
|
---|
| 129 | if name == ""
|
---|
| 130 | raise Exception.new("empty name")
|
---|
| 131 | end
|
---|
| 132 | name + (version == nil ? "" : "(" + version + ")")
|
---|
| 133 | end
|
---|
| 134 | end
|
---|
| 135 |
|
---|
| 136 | # Ancestor class of identification class
|
---|
| 137 | #
|
---|
| 138 | class ObjectID
|
---|
| 139 | attr_accessor :value
|
---|
| 140 | def initiallize(value)
|
---|
| 141 | if value == nil
|
---|
| 142 | raise Exception.new("empty value")
|
---|
| 143 | end
|
---|
| 144 | @value = value
|
---|
| 145 | end
|
---|
| 146 | end
|
---|