Class: AQI::AnesthesiaRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/aqi/anesthesia_record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encounter) ⇒ AnesthesiaRecord

Returns a new instance of AnesthesiaRecord.



5
6
7
# File 'lib/aqi/anesthesia_record.rb', line 5

def initialize(encounter)
  self.encounter = encounter
end

Instance Attribute Details

#encounterObject

Returns the value of attribute encounter.



3
4
5
# File 'lib/aqi/anesthesia_record.rb', line 3

def encounter
  @encounter
end

Instance Method Details

#anesthesia_caseObject



77
78
79
80
81
# File 'lib/aqi/anesthesia_record.rb', line 77

def anesthesia_case
  AnesthesiaCase.new(anesthesia_record_id: encounter.encounter_id,
                     anesthesia_staff_set: anesthesia_staffs)

end

#anesthesia_providersObject



73
74
75
# File 'lib/aqi/anesthesia_record.rb', line 73

def anesthesia_providers
  services.collect{|s| [s.provider_id,s.provider_type]}.uniq
end

#anesthesia_staffsObject



67
68
69
70
71
# File 'lib/aqi/anesthesia_record.rb', line 67

def anesthesia_staffs
  anesthesia_providers.collect do |id, type|
    AnesthesiaStaff.new(staff_id: id, role: type)
  end
end

#cpt_setObject



53
54
55
# File 'lib/aqi/anesthesia_record.rb', line 53

def cpt_set
  services.collect{|s| CPT.new(value: s.procedure_code)}
end

#demographicObject



25
26
27
28
29
30
31
# File 'lib/aqi/anesthesia_record.rb', line 25

def demographic
  Demographic.new(date_of_birth:  encounter.date_of_birth,
                  postal_code:    encounter.postal_code,
                  state:          encounter.state,
                  city:           encounter.city,
                  gender:         encounter.gender)
end

#end_timeObject



49
50
51
# File 'lib/aqi/anesthesia_record.rb', line 49

def end_time
  services.map{|s| s.end_time}.max
end

#outcome_eventsObject



33
34
35
36
37
38
39
# File 'lib/aqi/anesthesia_record.rb', line 33

def outcome_events
  outcomes = encounter.adverse_events.collect do |ae|
    {time_date: encounter.date_of_service, name: ae}
  end

  OutcomeEvents.new(outcomes: outcomes)
end

#pre_opObject



83
84
85
# File 'lib/aqi/anesthesia_record.rb', line 83

def pre_op
  PreOp.new(age: encounter.patient_age, icd_set: encounter.diagnosis_codes, asa_class: encounter.asa_class)
end

#procedureObject



57
58
59
60
61
62
63
64
65
# File 'lib/aqi/anesthesia_record.rb', line 57

def procedure
  Procedure.new(procedure_id: encounter.encounter_id,
            facility_id: encounter.location_id,
            start_time: start_time,
            end_time: end_time,
            location_type: encounter.place_of_service,
            location_details: encounter.location_name,
            cpt_set: cpt_set)
end

#servicesObject



41
42
43
# File 'lib/aqi/anesthesia_record.rb', line 41

def services
  @services ||= encounter.services + encounter.pqrs_services
end

#start_timeObject



45
46
47
# File 'lib/aqi/anesthesia_record.rb', line 45

def start_time
  services.map{|s| s.start_time}.min
end

#to_xmlObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/aqi/anesthesia_record.rb', line 9

def to_xml
  builder = Builder::XmlMarkup.new
  builder.AnesthesiaRecord do |ar|
    ar << demographic.to_xml
    ar << procedure.to_xml
    ar << anesthesia_case.to_xml
    ar << pre_op.to_xml
    ar << outcome_events.to_xml
    #ar << post_op
    #ar << timing_milestones
    #ar << outcomes_events
    #ar << anesthesia_details
    #ar << ic_event_set
  end
end