Module: QRDA::Cat1::DemographicsImporter

Included in:
PatientImporter
Defined in:
lib/qrda-import/base-importers/demographics_importer.rb

Instance Method Summary collapse

Instance Method Details

#code_if_present(code_element, codes) ⇒ Object



32
33
34
35
36
# File 'lib/qrda-import/base-importers/demographics_importer.rb', line 32

def code_if_present(code_element, codes)
  return unless code_element && code_element['code'] && code_element['codeSystem']
  codes.add("#{code_element['code']}:#{code_element['codeSystem']}")
  QDM::Code.new(code_element['code'], code_element['codeSystem'])
end

#get_demographics(patient, doc, codes) ⇒ Object



4
5
6
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/qrda-import/base-importers/demographics_importer.rb', line 4

def get_demographics(patient, doc, codes)
  patient_role_element = doc.at_xpath('/cda:ClinicalDocument/cda:recordTarget/cda:patientRole')
  patient_element = patient_role_element.at_xpath('./cda:patient')
  patient.givenNames = [patient_element.at_xpath('cda:name/cda:given').text]
  patient.familyName = patient_element.at_xpath('cda:name/cda:family').text
  patient.qdmPatient.birthDatetime = DateTime.parse(patient_element.at_xpath('cda:birthTime')['value'])
  pcbd = QDM::PatientCharacteristicBirthdate.new
  pcbd.birthDatetime = patient.qdmPatient.birthDatetime
  pcbd.dataElementCodes = [QDM::Code.new('21112-8', '2.16.840.1.113883.6.1')]
  codes.add("21112-8:2.16.840.1.113883.6.1")
  patient.qdmPatient.dataElements << pcbd

  pcs = QDM::PatientCharacteristicSex.new
  code_element = patient_element.at_xpath('cda:administrativeGenderCode')
  pcs.dataElementCodes = [code_if_present(code_element, codes)]
  patient.qdmPatient.dataElements << pcs unless pcs.dataElementCodes.compact.blank?

  pcr = QDM::PatientCharacteristicRace.new
  code_element = patient_element.at_xpath('cda:raceCode')
  pcr.dataElementCodes = [code_if_present(code_element, codes)]
  patient.qdmPatient.dataElements << pcr unless pcr.dataElementCodes.compact.blank?

  pce = QDM::PatientCharacteristicEthnicity.new
  code_element = patient_element.at_xpath('cda:ethnicGroupCode')
  pce.dataElementCodes = [code_if_present(code_element, codes)]
  patient.qdmPatient.dataElements << pce unless pce.dataElementCodes.compact.blank?
end