Class: HealthDataStandards::Import::GreenC32::MedicationImporter

Inherits:
SectionImporter
  • Object
show all
Includes:
Singleton
Defined in:
lib/health-data-standards/import/green_c32/medication_importer.rb

Instance Method Summary collapse

Methods inherited from SectionImporter

#extract_address, #extract_code, #extract_description, #extract_effective_time, #extract_entry, #extract_facility, #extract_interval, #extract_name, #extract_organization, #extract_quantity, #extract_status, #extract_telecom, #extract_time, #extract_value, #generic_import, #initialize

Constructor Details

This class inherits a constructor from HealthDataStandards::Import::GreenC32::SectionImporter

Instance Method Details

#extract_administration_timing(element, entry) ⇒ Object



32
33
34
35
# File 'lib/health-data-standards/import/green_c32/medication_importer.rb', line 32

def extract_administration_timing(element,entry)
  entry.administration_timing = {"period" => extract_quantity(element, "./gc32:administrationTiming/gc32:period"), 
                                 "institutionSpecified" => extract_node_attribute(element.at_xpath("./gc32:administrationTiming"), :institutionSpecified)}
end

#extract_dose_restriction(element, entry) ⇒ Object



37
38
39
40
# File 'lib/health-data-standards/import/green_c32/medication_importer.rb', line 37

def extract_dose_restriction(element, entry)
  dose_element = element.at_xpath("./gc32:doseRestriction")
  entry.dose_restriction = {"numerator" => extract_quantity(dose_element, "./gc32:numerator"), "denominator" => extract_quantity(dose_element,"./gc32:denominator")}
end

#extract_fulfillment_history(med_element) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/health-data-standards/import/green_c32/medication_importer.rb', line 42

def extract_fulfillment_history(med_element)
  med_element.xpath("./gc32:fulfillmentHistory").map do |fh_doc|
    fh = FulfillmentHistory.new(quantityDispensed: extract_quantity(fh_doc, "./gc32:quantityDispensed"))
    fh.prescription_number = extract_node_text(fh_doc.at_xpath("./gc32:prescriptionUmber"))
    extract_time(fh_doc, fh,  "./gc32:dispenseDate", :dispense_date)
    fh
  end
end

#extract_med_code_attribute(doc, med, attribute, mongo_attribute_name = nil) ⇒ Object



60
61
62
63
# File 'lib/health-data-standards/import/green_c32/medication_importer.rb', line 60

def extract_med_code_attribute(doc, med, attribute, mongo_attribute_name=nil)
  mongo_attribute_name ||= attribute
  extract_code(doc, med, "./gc32:#{attribute}", mongo_attribute_name)
end

#extract_order_information(med_element) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/health-data-standards/import/green_c32/medication_importer.rb', line 51

def extract_order_information(med_element)
  med_element.xpath("./gc32:orderInformation").map do |oi_doc|
    oi = OrderInformation.new(fills: extract_node_attribute(oi_doc, :fills, true), orderNumber: extract_node_attribute(oi_doc, :orderNumber))
    extract_time(oi_doc, oi, "./gc32:orderDateTime", :order_date_time)
    extract_time(oi_doc, oi, "./gc32:expiresDateTime", :order_expiration_date_time)
    oi
  end
end

#import(med_xml) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/health-data-standards/import/green_c32/medication_importer.rb', line 7

def import(med_xml)
  med_xml.root.add_namespace_definition('gc32', "urn:hl7-org:greencda:c32")
  med_element = med_xml.at_xpath("./gc32:medication")
  medication = Medication.new
  extract_entry(med_element, medication)
  extract_interval(med_element, medication, "administrationTiming")
  extract_administration_timing(med_element, medication)
  medication.dose = extract_quantity(med_element, "./gc32:dose")
  extract_med_code_attribute(med_element, medication, :type, :typeOfMedication)
  extract_med_code_attribute(med_element, medication, :statusOfMedication)
  extract_med_code_attribute(med_element, medication, :route)
  extract_med_code_attribute(med_element, medication, :site)
  extract_dose_restriction(med_element, medication)
  extract_med_code_attribute(med_element, medication, :indication)
  extract_med_code_attribute(med_element, medication, :productForm)
  extract_med_code_attribute(med_element, medication, :vehicle)
  extract_med_code_attribute(med_element, medication, :reaction)
  extract_med_code_attribute(med_element, medication, :deliveryMethod)
  medication.fulfillment_instructions = extract_node_text(med_element.at_xpath("./gc32:patientInstructions"))
  medication.dose_indicator = extract_node_text(med_element.at_xpath("./gc32:doseIndicator"))
  medication.fulfillment_history = extract_fulfillment_history(med_element)
  medication.order_information = extract_order_information(med_element)
  medication
end