Class: AbstractResult

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Commentable, PatientChild
Defined in:
app/models/abstract_result.rb

Overview

This is the base class for Result and VitalSign. You can use this class to find objects of either type, but you can only create new instances using Result and VitalSign.

Direct Known Subclasses

Result, VitalSign

Defined Under Namespace

Classes: AbstractInstantiationError

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Commentable

included

Methods included from PatientChild

included

Class Method Details

.new(*args) ⇒ Object



7
8
9
10
11
12
# File 'app/models/abstract_result.rb', line 7

def self.new(*args)
  if self.name == 'AbstractResult'
    raise AbstractInstantiationError, 'this is an abstract class, use Result or VitalSign'
  end
  super(*args)
end

Instance Method Details

#code_system_codeObject



37
38
39
# File 'app/models/abstract_result.rb', line 37

def code_system_code
  code_system.try(:code)
end

#code_system_nameObject



41
42
43
# File 'app/models/abstract_result.rb', line 41

def code_system_name
  code_system.try(:name)
end

#randomizeObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/models/abstract_result.rb', line 88

def randomize()

  self.result_id = rand(100).to_s + 'd' + rand(100000).to_s + '-bd' + rand(100).to_s + '-4c90-891d-eb716d' + rand(10000).to_s + 'c4'
  self.result_date = DateTime.new(2000 + rand(9), rand(12) + 1, rand(28) + 1)
  self.code_system = CodeSystem.find_by_code("2.16.840.1.113883.6.1") # sets code system as LOINC
  self.status_code = 'N'
  self.value_scalar = (100 + rand(100)).to_s

  if (rand < 0.5)
    self.value_unit = 'lbs'
    self.result_code_display_name = 'Body Weight'
    self.result_code = '3141-9'
  else
    self.value_unit = 'mg/dL'
    self.result_code_display_name = 'Cholesterol'
    self.result_code = '2093-3'
  end

  # Only create organizer data 1/2 the time
  if (rand < 0.5)
    organizer_id = "33d07056-bd27-4c90-891d-eb716d3170c4"
    result_type_code = ResultTypeCode.find :random
    act_status_code = ActStatusCode.find :random
  end

end

#requirementsObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/abstract_result.rb', line 24

def requirements
  {
    :result_id => :required,
    :result_date => :required,
    :code_system_id => :required,
    :result_code => :required,
    :result_code_display_name => :required,
    :status_code => :required,
    :value_scalar => :required,
    :value_unit => :required,
  }
end

#statement_ccd_template_idObject



50
51
52
# File 'app/models/abstract_result.rb', line 50

def statement_ccd_template_id
  '2.16.840.1.113883.10.20.1.31'
end

#to_c32(xml) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/models/abstract_result.rb', line 54

def to_c32(xml)

  xml.entry do
    # Another nit-noid of the CCD specification... if there is an organizer of a lab result, and that 
    # organizaer has an id, result type and a status code, the XML is changed for the reults and is 
    # wrapped within an organizer/component XML element.
    #
    # Otherwise, that XPath is not included in the XML and the result is simply an observation...  This
    # is specified in the CCD documentation and NOT the C32 specification... so this really complicates
    # things for folks who only have access to the C32 spec.
    if organizer_id && result_type_code && act_status_code

      xml.organizer("classCode" => "BATTERY", "moodCode" => "EVN") do
        xml.templateId("root" => "2.16.840.1.113883.10.20.1.32")
        xml.id("root" => organizer_id)
        xml.code("code" => result_type_code.code, 
                "codeSystem" => "2.16.840.1.113883.6.96", 
                "displayName" => result_type_code.name)
        xml.statusCode("code" => act_status_code.code)
        if self.result_date
          xml.effectiveTime("value" => self.result_date.to_formatted_s(:brief))
        end
        xml.component do
          append_result_data_to_c32(xml)
        end
      end

    else
      append_result_data_to_c32(xml)
    end
  end

end

#valueObject

Return a string representation of the value using value_scalar and value_unit.



46
47
48
# File 'app/models/abstract_result.rb', line 46

def value
  "#{value_scalar} #{value_unit}"
end