Class: HealthDataStandards::Import::GreenC32::SectionImporter
- Inherits:
-
Object
- Object
- HealthDataStandards::Import::GreenC32::SectionImporter
show all
- Defined in:
- lib/health-data-standards/import/green_c32/section_importer.rb
Direct Known Subclasses
AdvanceDirectiveImporter, AllergyImporter, ConditionImporter, EncounterImporter, ImmunizationImporter, MedicalEquipmentImporter, MedicationImporter, ProcedureImporter, ResultImporter, SocialHistoryImporter, SupportImporter
Instance Method Summary
collapse
-
#extract_address(address_element) ⇒ Object
-
#extract_code(element, entry, xpath = "./gc32:code", attribute = :codes) ⇒ Object
-
#extract_description(element, entry) ⇒ Object
-
#extract_effective_time(element, entry) ⇒ Object
-
#extract_entry(element, entry) ⇒ Object
-
#extract_facility(facility_element) ⇒ Object
-
#extract_free_text(element, entry, free_text_element = "freeText") ⇒ Object
-
#extract_interval(element, entry, element_name = "effectiveTime") ⇒ Object
-
#extract_name(element, entry, name_element = "name") ⇒ Object
-
#extract_organization(organization_element) ⇒ Object
-
#extract_quantity(element, xpath) ⇒ Object
-
#extract_status(element, entry) ⇒ Object
-
#extract_telecom(telecom_element) ⇒ Object
-
#extract_time(element, entry, xpath = "./gc32:effectiveTime", attribute = "time") ⇒ Object
-
#extract_value(element, entry) ⇒ Object
-
#generic_import(element_xml, element_name = "entry") ⇒ Object
-
#import(entry_xml) ⇒ Object
-
#initialize ⇒ SectionImporter
constructor
A new instance of SectionImporter.
Constructor Details
Returns a new instance of SectionImporter.
8
9
10
11
12
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 8
def initialize
@description = "./gc32:code/gc32:originalText"
@status = "./gc32:status"
@value = "./gc32:value"
end
|
Instance Method Details
142
143
144
145
146
147
148
149
150
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 142
def (address_element)
return unless address_element
address = Address.new
address.street = address_element.xpath("./gc32:street").map { |st| (st) }
address.city = (address_element.xpath("./gc32:city"))
address.state = (address_element.xpath("./gc32:state"))
address.zip = (address_element.xpath("./gc32:postalCode"))
address
end
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 27
def (element, entry, xpath="./gc32:code", attribute=:codes)
code_element = element.at_xpath(xpath)
return unless code_element
codes = build_code(code_element)
code_element.xpath("./gc32:translation").each do |trans|
codes.merge!(build_code(trans))
end
entry.send("#{attribute}=", codes)
end
|
42
43
44
45
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 42
def (element, entry)
description = element.at_xpath(@description)
entry.description = (description)
end
|
53
54
55
56
57
58
59
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 53
def (element, entry)
if element.at_xpath("./gc32:effectiveTime/gc32:start")
(element,entry)
else
(element, entry)
end
end
|
102
103
104
105
106
107
108
109
110
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 102
def (element, entry)
(element, entry)
(element, entry)
(element, entry)
(element, entry)
(element, entry)
entry.free_text = element.at_xpath("./gc32:freeText").try(:inner_text)
entry
end
|
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 126
def (facility_element)
facility = Facility.new
facility.name = (facility_element.xpath("./gc32:name"))
facility.addresses = facility_element.xpath("./gc32:address").map { |addr| (addr) }
facility.telecoms = facility_element.xpath("./gc32:telecom").map { |tele| (tele) }
start_time = facility_element.at_xpath("./gc32:duration/gc32:start").try(:text)
if start_time
facility.start_time = Time.parse(start_time).utc.to_i
end
end_time = facility_element.at_xpath("./gc32:duration/gc32:end").try(:text)
if end_time
facility.end_time = Time.parse(end_time).utc.to_i
end
facility
end
|
161
162
163
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 161
def (element, entry, free_text_element="freeText")
entry.free_text = (element.at_xpath("./gc32:#{free_text_element}"))
end
|
77
78
79
80
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 77
def (element, entry, element_name="effectiveTime")
(element, entry, "./gc32:#{element_name}/gc32:start", "start_time")
(element, entry, "./gc32:#{element_name}/gc32:end", "end_time")
end
|
61
62
63
64
65
66
67
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 61
def (element, entry, name_element="name")
name_element = element.at_xpath("./gc32:#{name_element}")
return unless name_element
entry.title = name_element.at_xpath("./gc32:title").try(:content)
entry.given_name = name_element.at_xpath("./gc32:givenName").try(:content)
entry.family_name = name_element.at_xpath("./gc32:familyName").try(:content)
end
|
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 112
def (organization_element)
org_id = (organization_element.xpath("./gc32:id"))
organization = org_id ? Organization.find_or_create_by(id: org_id) : Organization.new
if organization.new_record?
else
organization.name = (organization_element.xpath("./gc32:name"))
organization.addresses = organization_element.xpath("./gc32:address").map { |addr| (addr) }
organization.telecoms = organization_element.xpath("./gc32:telecom").map { |tele| (tele) }
organization.save!
end
return organization
end
|
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 82
def (element, xpath)
value_element = element.at_xpath(xpath)
return unless value_element
node_value = (value_element, "amount", true)
node_units = (value_element, "unit")
return {} unless node_value
{"scalar" => node_value, "unit" => node_units}
end
|
47
48
49
50
51
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 47
def (element, entry)
status = (element.at_xpath(@status))
return unless status
entry.status = status
end
|
152
153
154
155
156
157
158
159
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 152
def (telecom_element)
return unless telecom_element
telecom = Telecom.new
telecom.use = (telecom_element, :type)
telecom.value = (telecom_element, :value)
telecom.preferred = (telecom_element, :preferred)
telecom
end
|
69
70
71
72
73
74
75
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 69
def (element, entry, xpath = "./gc32:effectiveTime", attribute = "time")
datetime = element.at_xpath(xpath)
return unless datetime && datetime['value']
entry.send("#{attribute}=", Time.parse(datetime['value']).utc.to_i)
end
|
95
96
97
98
99
100
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 95
def (element, entry)
pq = (element, @value)
if pq.present?
entry.values << PhysicalQuantityResultValue.new(pq)
end
end
|
#generic_import(element_xml, element_name = "entry") ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 19
def generic_import(element_xml, element_name="entry")
entry = Entry.new
element_xml.root.add_namespace_definition('gc32', "urn:hl7-org:greencda:c32")
element = element_xml.at_xpath("./gc32:#{element_name}")
(element, entry)
entry
end
|
#import(entry_xml) ⇒ Object
15
16
17
|
# File 'lib/health-data-standards/import/green_c32/section_importer.rb', line 15
def import(entry_xml)
generic_import(entry_xml)
end
|