Class: Encounter

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

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from PersonLike

included

Methods included from Commentable

included

Methods included from PatientChild

included

Class Method Details

+ (Object) c32_component(encounters, xml)



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

def self.c32_component(encounters, xml)
  # Start Encounters
  unless encounters.empty?
    xml.component do
      xml.section do
         xml.templateId("root" => "2.16.840.1.113883.10.20.1.3", 
               "assigningAuthorityName" => "CCD")
         xml.code("code" => "46240-8", 
                  "codeSystem" => "2.16.840.1.113883.6.1", 
                  "codeSystemName" => "LOINC")
         xml.title("Encounters")  
         xml.text do
          xml.table("border" => "1", "width" => "100%") do
            xml.thead do
              xml.tr do
                xml.th "Encounter"
                xml.th "Encounter Date"
              end
            end
            xml.tbody do
              encounters.each do |encounter|
                xml.tr do 
                  xml.td(encounter.name)
                  xml.td(encounter.encounter_date)
                end
              end
            end
          end
        end

        # XML content inspection
        yield

      end
    end
  end
  # End Encounters
end

Instance Method Details

- (Object) randomize(birth_date)



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

def randomize(birth_date)
  possible_procedures = ['Heart Valve', 'IUD', 'Artificial Hip', 'Bypass', 'Hypothermia']
  descriptions = ['Heart Valve Replacement', 'Insertion of intrauterine device (IUD)', 'Hip replacement surgery', 'Bypass surgery', 'Treatement for hypothermia']
  possible_procedures_index = rand(possible_procedures.size)

  possible_encounter_locations = ['South Shore Hospital', 'General Hospital', 'Lahey Clinic', 'Darwin Clinic', 'Sagacious Hospital']
  possible_encounter_locations_index = rand(possible_encounter_locations.size)

  self.encounter_date = DateTime.new(birth_date.year + rand(DateTime.now.year - birth_date.year), rand(12) + 1, rand(28) +1)
  self.encounter_id = UUID.generate
  self.person_name = PersonName.new
  self.person_name.name_prefix = 'Dr.'
  self.person_name.first_name = Faker::Name.first_name
  self.person_name.last_name = Faker::Name.last_name
  self.address = Address.new
  self.address.randomize()
  self.telecom = Telecom.new
  self.telecom.randomize()

  self.free_text = possible_procedures[possible_procedures_index]
  self.name = descriptions[possible_procedures_index]    

  self.location_name = possible_encounter_locations[possible_encounter_locations_index]
  
  self.encounter_location_code = EncounterLocationCode.find(:random)
end

- (Object) requirements



13
14
15
16
17
18
19
20
# File 'app/models/encounter.rb', line 13

def requirements
  {
    :encounter_date => :required,
    :encounter_id => :required,
    :free_text => :required,
    :encounter_type_id => :hitsp_r2_optional,
  }
end

- (Object) to_c32(xml)



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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/encounter.rb', line 23

def to_c32(xml)    
  xml.entry('typeCode'=>'DRIV') do
    xml.encounter('classCode'=>'ENC', 'moodCode'=>'EVN') do
      xml.templateId('root' => '2.16.840.1.113883.10.20.1.21', 
                     'assigningAuthorityName' => 'CCD')
      xml.templateId('root' => '2.16.840.1.113883.3.88.11.32.17',
                     'assigningAuthorityName' => 'HITSP/C32') 
      xml.id('root' => encounter_id)
      if encounter_type
        xml.code("code" => encounter_type.code, "codeSystem" => "2.16.840.1.113883.5.4", "displayName" => encounter_type.name) do
          xml.originalText free_text
        end
      end
      if encounter_date != nil 
        xml.effectiveTime do
          xml.low('value'=> encounter_date.to_s(:brief))
        end
      end
      xml.participant('typeCode'=>'PRF') do
        xml.participantRole('classCode' => 'PROV') do
          address.try(:to_c32, xml)
          telecom.try(:to_c32, xml)  
          xml.playingEntity do
            person_name.try(:to_c32, xml)
          end
        end
      end
      if location_name
        xml.participant("typeCode" => "LOC") do
          xml.templateId("root" => "2.16.840.1.113883.10.20.1.45")
          xml.participantRole("classCode" => "SDLOC") do
            xml.id("root" => "2.16.840.1.113883.19.5")
            if encounter_location_code
              xml.code("code" => encounter_location_code.code, 
                       "displayName" => encounter_location_code.name, 
                       "codeSystem" => "2.16.840.1.113883.1.11.17660")
            end
            xml.playingEntity("classCode" => "PLC") do
              xml.name location_name
            end
          end
        end
      end
    end
  end
end