Class: OpenEHR::AM::Template::OperationalTemplate

Inherits:
Archetype::Archetype show all
Defined in:
lib/openehr/am/template.rb

Overview

OPERATIONAL_TEMPLATE class represents a "compiled" template derived from a source TEMPLATE by a "flattening" process, used for generating and validating reference model instance data. According to openEHR AOM2 specification, it inherits from AUTHORED_ARCHETYPE.

Constant Summary

Constants inherited from Archetype::Archetype

Archetype::Archetype::NODE_ID_PATTERN

Constants included from Archetype::ADLDefinition

Archetype::ADLDefinition::CURRENT_ADL_VERSION

Instance Attribute Summary collapse

Attributes inherited from Archetype::Archetype

#adl_version, #archetype_id, #definition, #invariants, #ontology, #parent_archetype_id, #uid

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

#description, #original_language, #revision_history, #translations

Instance Method Summary collapse

Methods inherited from Archetype::Archetype

#concept_name, #constraint_references_valid?, create, #internal_references_valid?, #is_specialised?, #is_valid?, #logical_paths, #node_ids_vaild?, #node_ids_valid?, #physical_paths, #previous_version, #short_concept_name, #specialisation_depth, #to_rm, #version

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

#current_revision, #is_controlled?, #languages_available

Constructor Details

#initialize(args = {}) ⇒ OperationalTemplate

Returns a new instance of OperationalTemplate.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/openehr/am/template.rb', line 13

def initialize(args = {})
  # template_id must be validated before delegating to Archetype#initialize:
  # OPERATIONAL_TEMPLATE identifies itself by template_id, and archetype_id
  # is derived from it below, so an absent template_id must fail with a
  # template-specific message rather than falling through to Archetype's
  # own (unrelated) mandatory-field checks.
  self.template_id = args[:template_id]

  # Initialize parent archetype with template-specific archetype_id
  template_args = args.dup
  template_args[:archetype_id] = args[:template_id] if args[:template_id] && !args[:archetype_id]

  super(template_args)

  self.component_terminologies = args[:component_terminologies] || {}
  self.terminology_extracts = args[:terminology_extracts] || {}
end

Instance Attribute Details

#component_terminologiesObject

Returns the value of attribute component_terminologies.



11
12
13
# File 'lib/openehr/am/template.rb', line 11

def component_terminologies
  @component_terminologies
end

#template_idObject

Returns the value of attribute template_id.



11
12
13
# File 'lib/openehr/am/template.rb', line 11

def template_id
  @template_id
end

#terminology_extractsObject

Returns the value of attribute terminology_extracts.



11
12
13
# File 'lib/openehr/am/template.rb', line 11

def terminology_extracts
  @terminology_extracts
end

Instance Method Details

#conceptObject

Override concept to use template concept or fallback to archetype concept



88
89
90
# File 'lib/openehr/am/template.rb', line 88

def concept
  @concept || (archetype_id ? archetype_id.concept_name : nil)
end

#concept=(concept) ⇒ Object

An operational template's concept is commonly derived from its archetype_id (see #concept below) rather than supplied explicitly, so unlike Archetype#concept= it must not require a value up front.



43
44
45
# File 'lib/openehr/am/template.rb', line 43

def concept=(concept)
  @concept = concept
end

#description=(description) ⇒ Object

AuthoredResource#description has no mandatory check, but an operational template always carries its own resource description.



49
50
51
52
53
54
# File 'lib/openehr/am/template.rb', line 49

def description=(description)
  if description.nil?
    raise ArgumentError, 'description is mandatory'
  end
  @description = description
end

#is_specialized?Boolean

Returns whether the template is specialized (should be true for operational templates)

Returns:

  • (Boolean)


73
74
75
# File 'lib/openehr/am/template.rb', line 73

def is_specialized?
  !parent_archetype_id.nil?
end

#is_valid_operational_template?Boolean

Returns true if this is a valid operational template

Returns:

  • (Boolean)


65
66
67
68
69
70
# File 'lib/openehr/am/template.rb', line 65

def is_valid_operational_template?
  return false if template_id.nil?
  return false if definition.nil?
  return false if component_terminologies.nil?
  true
end

#languageObject

Compatibility method for backward compatibility with existing tests



93
94
95
# File 'lib/openehr/am/template.rb', line 93

def language
  original_language
end

#language=(language) ⇒ Object

Compatibility setter for language (maps to original_language)



98
99
100
# File 'lib/openehr/am/template.rb', line 98

def language=(language)
  self.original_language = language
end

#referenced_archetype_idsObject

Get all archetype identifiers referenced in this operational template



78
79
80
# File 'lib/openehr/am/template.rb', line 78

def referenced_archetype_ids
  component_terminologies.keys
end

#terminology_for_archetype(archetype_id) ⇒ Object

Get terminology for a specific archetype



83
84
85
# File 'lib/openehr/am/template.rb', line 83

def terminology_for_archetype(archetype_id)
  component_terminologies[archetype_id]
end