Class: HealthDataStandards::Import::Hdata::MetadataImporter

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/health-data-standards/import/hdata/metadata_importer.rb

Instance Method Summary collapse

Instance Method Details

#extract_author(pedi_el) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/health-data-standards/import/hdata/metadata_importer.rb', line 53

def extract_author(pedi_el)
  return unless pedi_el
  author = pedi_el.at_xpath("./hrf-md:Author")
  return unless author
  Metadata::Author.new(name: author.try(:content), 
                       type: author.attribute('typeCode').try("content"), 
                       role: author.attribute('role').try("content"))
end

#extract_change_info(change_info_el) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/health-data-standards/import/hdata/metadata_importer.rb', line 70

def extract_change_info(change_info_el)
  return unless change_info_el
  change_info = Metadata::ChangeInfo.new
  change_info.timestamp = change_info_el.at_xpath("./hrf-md:ChangeDateTime").try("content")
  change_info.pedigree = extract_pedigree(change_info_el.at_xpath("./hrf-md:PedigreeInfo"))
  change_info_el
  change_info
end


62
63
64
65
66
67
68
# File 'lib/health-data-standards/import/hdata/metadata_importer.rb', line 62

def extract_link_info(link_info_el)
  return unless link_info_el
  target_el = link_info_el.at_xpath("./hrf-md:Target")
  return unless target_el
  Metadata::LinkInfo.new(uri: target_el.content, 
               extension: target_el.attribute("TargetExtension").try(:content))
end

#extract_metadata(meta_element, meta) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/health-data-standards/import/hdata/metadata_importer.rb', line 19

def (meta_element, meta)
  meta.mime_types = meta_element.xpath("./hrf-md:MediaType").map { |media| media.text }
  meta.confidentiality = meta_element.at_xpath("./hrf-md:Confidentiality").try(:text)
  meta.pedigrees = meta_element.xpath("./hrf-md:PedigreeInfo").map { |ped| extract_pedigree(ped) }
  creation_el = meta_element.at_xpath("./hrf-md:RecordDate/hrf-md:CreatedDateTime")
  meta.original_creation_time = Time.parse(creation_el.text) if creation_el
  meta.linked_documents = meta_element.xpath("./hrf-md:LinkedDocuments/hrf-md:Link").map {|l| extract_link_info(l)}
  copied_elements = meta_element.xpath("./hrf-md:RecordDate/hrf-md:Copied/hrf-md:CopiedInfo")
  meta.copied_dates = copied_elements.map { |cp| extract_change_info(cp) }
  modified_elements = meta_element.xpath("./hrf-md:RecordDate/hrf-md:Modified/hrf-md:ModifiedInfo")
  meta.modified_dates = modified_elements.map { |md| extract_change_info(md) }
  meta
end

#extract_pedigree(pedi_el) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/health-data-standards/import/hdata/metadata_importer.rb', line 33

def extract_pedigree(pedi_el)
  return unless pedi_el
  
  author = extract_author(pedi_el)
  organization = pedi_el.at_xpath("./hrf-md:Organization")
  
  ped = Metadata::Pedigree.new(author: author,
                     organization: organization.try(:content))
                      
  source_pedigree_els = pedi_el.xpath("./hrf-md:Source/hrf-md:PedigreeInfo")
  ped.source_pedigrees = source_pedigree_els.map { |ped_el| extract_pedigree(ped_el) }
  ped.derived = pedi_el.attribute("derived")# == "true" ? true : false
  # ped.signature = pedi_el.at_xpath("./hrf-md:Signature/")
  
  source_doc_els = pedi_el.xpath("./hrf-md:Source/hrf-md:Document")
  ped.source_documents = source_doc_els.map { |doc_el| extract_link_info(doc_el) }
  
  ped
end

#import(meta_xml) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/health-data-standards/import/hdata/metadata_importer.rb', line 7

def import(meta_xml)
  meta_xml.root.add_namespace_definition("hrf-md", Metadata::NS)
  meta_element = meta_xml.at_xpath("./hrf-md:DocumentMetaData")
  return unless meta_element
  
  meta = Metadata::Base.new
  
  (meta_element, meta)

  meta
end