Class: OpenEHR::AM::Archetype::Archetype

Inherits:
RM::Common::Resource::AuthoredResource show all
Includes:
ADLDefinition
Defined in:
lib/openehr/am/archetype.rb

Direct Known Subclasses

FlatArchetype, Template::OperationalTemplate

Constant Summary collapse

NODE_ID_PATTERN =
/\A(?:at|ac|id)\d+(\.\d+)*\z/

Constants included from ADLDefinition

OpenEHR::AM::Archetype::ADLDefinition::CURRENT_ADL_VERSION

Instance Attribute Summary collapse

Attributes inherited from RM::Common::Resource::AuthoredResource

#description, #original_language, #revision_history, #translations

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RM::Common::Resource::AuthoredResource

#current_revision, #is_controlled?, #languages_available

Constructor Details

#initialize(args = {}) ⇒ Archetype

Returns a new instance of Archetype.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/openehr/am/archetype.rb', line 16

def initialize(args = {})
  super(args)
  self.adl_version = args[:adl_version] 
  self.archetype_id = args[:archetype_id]
  self.uid = args[:uid]
  self.concept = args[:concept]
  self.parent_archetype_id = args[:parent_archetype_id]
  self.definition = args[:definition]
  self.ontology = args[:ontology]
  self.invariants = args[:invariants]
end

Instance Attribute Details

#adl_versionObject

Returns the value of attribute adl_version.



14
15
16
# File 'lib/openehr/am/archetype.rb', line 14

def adl_version
  @adl_version
end

#archetype_idObject

Returns the value of attribute archetype_id.



13
14
15
# File 'lib/openehr/am/archetype.rb', line 13

def archetype_id
  @archetype_id
end

#conceptObject

Returns the value of attribute concept.



13
14
15
# File 'lib/openehr/am/archetype.rb', line 13

def concept
  @concept
end

#definitionObject

Returns the value of attribute definition.



13
14
15
# File 'lib/openehr/am/archetype.rb', line 13

def definition
  @definition
end

#invariantsObject

Returns the value of attribute invariants.



14
15
16
# File 'lib/openehr/am/archetype.rb', line 14

def invariants
  @invariants
end

#ontologyObject

Returns the value of attribute ontology.



13
14
15
# File 'lib/openehr/am/archetype.rb', line 13

def ontology
  @ontology
end

#parent_archetype_idObject

Returns the value of attribute parent_archetype_id.



14
15
16
# File 'lib/openehr/am/archetype.rb', line 14

def parent_archetype_id
  @parent_archetype_id
end

#uidObject

Returns the value of attribute uid.



14
15
16
# File 'lib/openehr/am/archetype.rb', line 14

def uid
  @uid
end

Class Method Details

.create(args = {}, &block) ⇒ Object



194
195
196
197
198
199
200
# File 'lib/openehr/am/archetype.rb', line 194

def self.create(args ={}, &block)
  archetype = new(args)
  if block_given?
    yield archetype
  end
  return archetype
end

Instance Method Details

#concept_name(a_lang) ⇒ Object



64
65
66
# File 'lib/openehr/am/archetype.rb', line 64

def concept_name(a_lang)
  return @ontology.term_definition(:lang => a_lang, :code => @concept).items['text']
end

#constraint_references_valid?Boolean

A reference to a constraint definition (ADL "matches ac0001") is valid when it names a code actually present in the ontology's constraint_definitions. True when there are no such references at all; false (rather than vacuously true) when there are references but the ontology has no constraint_definitions section.

Returns:

  • (Boolean)


75
76
77
78
79
80
81
82
83
# File 'lib/openehr/am/archetype.rb', line 75

def constraint_references_valid?
  refs = collect(ConstraintModel::ConstraintRef) { |node| node.reference }
  return true if refs.empty?

  codes = ontology.constraint_codes
  return false if codes.nil?

  refs.all? { |ref| codes.include?(ref) }
end

#internal_references_valid?Boolean

An ARCHETYPE_INTERNAL_REF's target_path must resolve to a node physically present in this same definition tree.

Returns:

  • (Boolean)


87
88
89
90
91
# File 'lib/openehr/am/archetype.rb', line 87

def internal_references_valid?
  refs = collect(ConstraintModel::ArchetypeInternalRef) { |node| node.target_path }
  paths = physical_paths
  refs.all? { |ref| paths.include?(ref) }
end

#is_specialised?Boolean

True when a specialise header was present (i.e. this archetype names a parent archetype to specialise).

Returns:

  • (Boolean)


95
96
97
# File 'lib/openehr/am/archetype.rb', line 95

def is_specialised?
  !parent_archetype_id.nil?
end

#is_valid?Boolean

Composition of the three granular structural checks above.

Returns:

  • (Boolean)


100
101
102
# File 'lib/openehr/am/archetype.rb', line 100

def is_valid?
  node_ids_valid? && constraint_references_valid? && internal_references_valid?
end

#logical_paths(a_lang) ⇒ Object

physical_paths with each at/ac/id-code predicate replaced by its ontology term text for a_lang (falling back to the bare code when no term text is found for it).



107
108
109
# File 'lib/openehr/am/archetype.rb', line 107

def logical_paths(a_lang)
  physical_paths.map { |path| localize_path(path, a_lang) }
end

#node_ids_vaild?Boolean

Returns:

  • (Boolean)


120
121
122
123
# File 'lib/openehr/am/archetype.rb', line 120

def node_ids_vaild?
  warn '[DEPRECATED] node_ids_vaild? is deprecated (typo); use node_ids_valid? instead'
  node_ids_valid?
end

#node_ids_valid?Boolean

Every node_id used in the definition, syntactically valid (at/ac/id-code, optionally dotted for specialisation) and present in the ontology's term codes.

Returns:

  • (Boolean)


114
115
116
117
118
# File 'lib/openehr/am/archetype.rb', line 114

def node_ids_valid?
  node_ids = collect_node_ids
  codes = ontology.term_codes
  node_ids.all? { |id| id =~ NODE_ID_PATTERN && codes.include?(id) }
end

#physical_pathsObject

The archetype path of every node physically present in the definition, in depth-first order, without duplicates (a node without its own node_id shares its parent attribute's path).



128
129
130
131
132
# File 'lib/openehr/am/archetype.rb', line 128

def physical_paths
  paths = []
  each_constraint_node(definition) { |node| paths << node.path if node.respond_to?(:path) }
  paths.uniq
end

#previous_versionObject

This gem does not parse ADL revision history, so a previous version can never be determined from a parsed archetype.



136
137
138
# File 'lib/openehr/am/archetype.rb', line 136

def previous_version
  nil
end

#short_concept_nameObject



60
61
62
# File 'lib/openehr/am/archetype.rb', line 60

def short_concept_name
  return @archetype_id.concept_name
end

#specialisation_depthObject

Prefers the ontology's own (parser-derived) specialisation_depth when available; otherwise falls back to what the archetype_id's domain_concept specialisation suffix can tell us. ArchetypeID currently only represents a single specialisation level, so this fallback can only ever return 0 or 1.



145
146
147
148
149
# File 'lib/openehr/am/archetype.rb', line 145

def specialisation_depth
  return ontology.specialisation_depth if ontology.specialisation_depth

  archetype_id.specialisation.nil? ? 0 : 1
end

#to_rmObject



202
203
204
205
206
207
# File 'lib/openehr/am/archetype.rb', line 202

def to_rm
  ::OpenEHR::RM::Factory.create(definition.rm_type_name,
                                archetype_node_id: definition.archetype_node_id,
                                name: definition
                                )
end

#versionObject



56
57
58
# File 'lib/openehr/am/archetype.rb', line 56

def version
  return @archetype_id.version_id
end