Class: Allergy

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Commentable

included

Methods included from PatientChild

included

Class Method Details

.c32_component(allergies, xml) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'app/models/allergy.rb', line 168

def self.c32_component(allergies, xml)
  if allergies.size > 0
    xml.component do
      xml.section do
        xml.templateId("root" => "2.16.840.1.113883.10.20.1.2", 
                       "assigningAuthorityName" => "CCD")
        xml.templateId("root" => "1.3.6.1.4.1.19376.1.5.3.1.3.13",  #C32 2.4
                        "assigningAuthorityName" => "CCD")
        xml.code("code" => "48765-2", 
                 "codeSystem" => "2.16.840.1.113883.6.1")
        xml.title "Allergies, Adverse Reactions, Alerts"
        xml.text do
          xml.table("border" => "1", "width" => "100%") do
            xml.thead do
              xml.tr do
                xml.th "Substance"
                xml.th "Event Type"
                xml.th "Severity"
              end
            end
            xml.tbody do
              allergies.try(:each) do |allergy|
                xml.tr do
                  if allergy.free_text_product != nil
                    xml.td do
                      xml.content(allergy.free_text_product, "ID" => "product-" + allergy.id.to_s)
                    end
                  else
                    xml.td
                  end 
                  if allergy.adverse_event_type != nil
                    xml.td do
                      xml.content(allergy.adverse_event_type.name, "ID" => "adverse-event-type-" + allergy.id.to_s)
                    end
                  else
                    xml.td
                  end  
                  if allergy.severity_term != nil
                    xml.td do
                      xml.content(allergy.severity_term.name, 
                                  "ID" => "severity-" + allergy.id.to_s)
                    end
                  else
                    xml.td
                  end
                end
              end
            end
          end
        end

        # XML content inspection
        yield

      end
    end
  end
end

Instance Method Details

#randomize(birth_date) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'app/models/allergy.rb', line 153

def randomize(birth_date)
  @possible_allergin = ["Asprin 1191", "Codeine 2670", "Penicillin 70618"]
  @allergin = @possible_allergin[rand(3)]
  self.free_text_product = @allergin.split[0]
  self.product_code = @allergin.split[1]
  self.code_system = CodeSystem.find_by_code("2.16.840.1.113883.6.88")  #RxNorm

  self.start_event = DateTime.new(birth_date.year + rand(DateTime.now.year - birth_date.year), rand(12) + 1, rand(28) +1)

  self.adverse_event_type = AdverseEventType.find :random
  self.severity_term = SeverityTerm.find :random
  self.allergy_type_code = AllergyTypeCode.find :random
  self.allergy_status_code = AllergyStatusCode.find :random
end

#requirementsObject



14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/allergy.rb', line 14

def requirements
  {
    :free_text_product => :hitsp_optional,
    :product_code => :hitsp_r2_required,
    :code_system_id => :hitsp_r2_required,
    :adverse_event_type_id => :required,
    :start_event => :hitsp_r2_optional,
    :end_event => :hitsp_r2_optional,
    :allergy_status_code_id => :hitsp_r2_optional,
  }
end

#to_c32(xml) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
87
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'app/models/allergy.rb', line 26

def to_c32(xml)
  xml.entry do
    xml.act("classCode" => "ACT", "moodCode" => "EVN") do
      xml.templateId("root" => "2.16.840.1.113883.10.20.1.27")
      xml.templateId("root" => "2.16.840.1.113883.3.88.11.32.6")
      xml.templateId("root" => "2.16.840.1.113883.3.88.11.83.6", "assigningAuthorityName" => "HITSP C83" )
      xml.templateId("root" => "1.3.6.1.4.1.19376.1.5.3.1.4.5.1")
      xml.templateId("root" => "1.3.6.1.4.1.19376.1.5.3.1.4.5.3")

      xml.id("root" => "2C748172-7CC2-4902-8AF0-23A105C4401B")
      xml.code("nullFlavor"=>"NA")
      xml.statusCode("code" => "completed")
      if start_event.present? || end_event.present?
        xml.effectiveTime do
          if start_event.present?
            xml.low("value" => start_event.to_s(:brief))
          end
          if end_event.present?
            xml.high("value" => end_event.to_s(:brief))
          else
            xml.high("nullFlavor" => "UNK")
          end
        end
      end
      xml.entryRelationship("typeCode" => "SUBJ", "inversionInd" => "false") do
        xml.observation("classCode" => "OBS", "moodCode" => "EVN") do
          xml.templateId("root" => "2.16.840.1.113883.10.20.1.18")
          xml.templateId("root" => "2.16.840.1.113883.10.20.1.28")
          xml.templateId("root" => "1.3.6.1.4.1.19376.1.5.3.1.4.5", "assigningAuthorityName" => "IHE PCC")
          xml.templateId("root" => "1.3.6.1.4.1.19376.1.5.3.1.4.6", "assigningAuthorityName" => "IHE PCC")
          xml.id
          if adverse_event_type 
            xml.code("code" => adverse_event_type.code, 
                     "displayName" => adverse_event_type.name, 
                     "codeSystem" => "2.16.840.1.113883.6.96", 
                     "codeSystemName" => "SNOMED CT") do
              xml.originalText do
                xml.reference(:value => "#adverse-event-type-" + self.id.to_s)
              end
            end
          else
            xml.code("nullFlavor"=>"N/A") do
                xml.originalText do
                  xml.reference
                end
            end
          end
          xml.text do 
            xml.reference
          end
          xml.statusCode("code"=>"completed")
          if start_event != nil || end_event != nil
            xml.effectiveTime do
              if start_event != nil 
                xml.low("value" => start_event.to_s(:brief))
              end
              if end_event != nil
                xml.high("value" => end_event.to_s(:brief))
              else
                xml.high("nullFlavor" => "UNK")
              end
            end
          end
          xml.value("xsi:type" => "CD",
                    "code" => adverse_event_type.code,
                    "codeSystem" => "2.16.840.1.113883.6.96",
                    "displayName" => adverse_event_type.name,
                    "codeSystemName" => "SNOMED CT")
          xml.participant("typeCode" => "CSM") do
            xml.participantRole("classCode" => "MANU") do
              xml.playingEntity("classCode" => "MMAT") do
                xml.code("code" => product_code, 
                         "displayName" => free_text_product, 
                         "codeSystem" => code_system.code,
                         "codeSystemName" => code_system.name) do
                  xml.originalText do
                    xml.reference(:value => "#product-" + self.id.to_s)
                  end
                end
                xml.name free_text_product
              end
            end
          end
          if allergy_status_code
            xml.entryRelationship("typeCode" => "REFR", "inversionInd" => "false") do
              xml.observation("classCode" => "OBS", "moodCode" => "EVN") do
                xml.templateId("root" => "2.16.840.1.113883.10.20.1.39")
                xml.code("code" => "33999-4", 
                         "displayName" => "Status",
                         "codeSystem" => "2.16.840.1.113883.6.1", 
                         "codeSystemName" => "AlertStatusCode")
                xml.statusCode("code" => "completed")
                xml.value("xsi:type" => "CE", 
                          "code" => allergy_status_code.code,
                          "displayName" => allergy_status_code.name,
                          "codeSystem" => "2.16.840.1.113883.6.96", 
                          "codeSystemName" => "SNOMED CT") 
              end
            end
          end
        end
      end
      #if severity_term
      #  xml.entryRelationship("typeCode" => "SUBJ", "inversionInd" => "true") do
      #    xml.observation("classCode" => "OBS", "moodCode" => "EVN") do
      #      xml.templateId("root" => "2.16.840.1.113883.10.20.1.55")
      #     xml.code("code" => "SEV", 
      #              "displayName" => "Severity",
      #               "codeSystem" => "2.16.840.1.113883.5.4", 
      #               "codeSystemName" => "ActCode")
      #     xml.text do
      #        xml.reference("value" => "#severity-" + id.to_s)
      #     end
      #     xml.statusCode("code" => "completed")
      #     xml.value("xsi:type" => "CD", 
      #               "code" => severity_term.code,
      #              "displayName" => severity_term.name,
      #               "codeSystem" => "2.16.840.1.113883.6.96", 
      #               "codeSystemName" => "SNOMED CT")
      #    end
      #  end
      #end
    end
  end

end