Class: Immunization

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Commentable

included

Methods included from PatientChild

included

Class Method Details

.c32_component(immunizations, xml) ⇒ Object



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
# File 'app/models/immunization.rb', line 63

def self.c32_component(immunizations, xml)
  # Start Immunizations
  unless immunizations.empty?
    xml.component do
      xml.section do
        xml.templateId("root" => "2.16.840.1.113883.10.20.1.6", 
                       "assigningAuthorityName" => "CCD")
        xml.code("code" => "11369-6", 
                 "codeSystem" => "2.16.840.1.113883.6.1", 
                 "codeSystemName" => "LOINC")
        xml.title("Immunizations")
        xml.text do
          xml.table("border" => "1", "width" => "100%") do
            xml.thead do
              xml.tr do
                xml.th "Vaccine"
                xml.th "Administration Date"
              end
            end
            xml.tbody do
              immunizations.each do |immunization|
                xml.tr do 
                   if immunization.vaccine != nil
                    xml.td(immunization.vaccine.name)
                  end
                  xml.td(immunization.administration_date)
                end
              end
            end
          end
        end

        # XML content inspection
        yield

      end
    end
  end
  # End Immunizations
end

Instance Method Details

#randomize(birth_date) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/immunization.rb', line 50

def randomize(birth_date)
  self.administration_date = DateTime.new(birth_date.year + rand(DateTime.now.year - birth_date.year), rand(12) + 1, rand(28) + 1)
  self.lot_number_text = "mm345-417-DFF"
  self.vaccine = Vaccine.find :random
  if (rand > 0.5)
    self.refusal = true
    self.no_immunization_reason = NoImmunizationReason.find :random

  else
    self.refusal = false
  end
end

#requirementsObject



11
12
13
14
15
16
17
18
# File 'app/models/immunization.rb', line 11

def requirements
  {
    :vaccine_id => :required,
    :lot_number_text => :hitsp_r2_optional,
    :refusal => :required,
    :no_immunization_reason_id => :hitsp_r2_optional,
  }
end

#to_c32(xml) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/immunization.rb', line 20

def to_c32(xml)    
  xml.entry('typeCode'=>'DRIV') do
    xml.substanceAdministration('classCode' => 'SBADM', 'moodCode' => 'EVN', 'negationInd' => refusal) do
      xml.templateId("root" => "2.16.840.1.113883.10.20.1.24", "assigningAuthorityName" => "CCD")
      xml.templateId("root" => "2.16.840.1.113883.3.88.11.32.14", "assigningAuthorityName" => "HITSP/C32")
      xml.id('root'=>'41755f58-d7c0-4aab-9f7c-a3a5d8df4581')
      xml.statusCode('code' => 'completed')
      if administration_date
        xml.effectiveTime('xsi:type' => "IVL_TS") do
          xml.center('value' => administration_date.to_s(:brief)) 
        end
      end
      xml.consumable do
        xml.manufacturedProduct do
          xml.templateId('root' => '2.16.840.1.113883.10.20.1.53')
          xml.manufacturedMaterial do
            if vaccine
              vaccine.try(:to_c32, xml)
            end 
            xml.lotNumberText(lot_number_text)
          end
        end
      end
      if no_immunization_reason
        no_immunization_reason.try(:to_c32, xml)
      end 
    end
  end
end