Skip to content

Commit

Permalink
Add the hqmf identifier to a statement reference (#25)
Browse files Browse the repository at this point in the history
* Add the hqmf identifier to a statement reference
  • Loading branch information
dczulada authored and jbradl11 committed Apr 22, 2019
1 parent 82976cd commit 8ac8a7a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
2 changes: 2 additions & 0 deletions lib/hqmf-parser/cql/document_helpers/doc_population_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def extract_observations
# The at_xpath(...).values returns an array of a single element.
# The match returns an array and since we don't want the double quotes we take the second element
cql_define_function[:function_name] = entry.at_xpath("*/cda:measureObservationDefinition/cda:value/cda:expression").values.first.match('\\"([A-Za-z0-9 ]+)\\"')[1]
cql_define_function[:function_aggregation_type] = entry.at_xpath("*/cda:measureObservationDefinition/cda:methodCode/cda:item").attributes['code'].value
cql_define_function[:function_hqmf_oid] = entry.at_xpath("*/cda:measureObservationDefinition/cda:id").attributes['root'].value
# The criteria_reference_id is the id of the measurePopulationCriteria that should be used for this observation function
measure_population_id = entry.at_xpath("*/cda:measureObservationDefinition/cda:component/cda:criteriaReference/cda:id").attributes['root'].value
# Get the name of the parameter to the observation function within the measurePopulationCriteria section
Expand Down
54 changes: 26 additions & 28 deletions lib/measure-loader/hqmf_measure_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ def add_fields_from_hqmf_model_hash(measure, hqmf_model_hash)
# add observation info, note population_sets needs to have been added to the measure by now
(hqmf_model_hash[:observations] || []).each do |observation|
observation = CQM::Observation.new(
hqmf_id: observation[:function_hqmf_oid],
aggregation_type: observation[:function_aggregation_type],
observation_function: CQM::StatementReference.new(
library_name: hqmf_model_hash[:cql_measure_library],
statement_name: observation[:function_name]
statement_name: observation[:function_name],
hqmf_id: observation[:function_hqmf_oid]
),
observation_parameter: CQM::StatementReference.new(
library_name: hqmf_model_hash[:cql_measure_library],
statement_name: observation[:parameter]
statement_name: observation[:parameter],
hqmf_id: observation[:function_hqmf_oid]
)
)
# add observation to each population set
Expand Down Expand Up @@ -84,19 +88,20 @@ def extract_population_set_models(qmd, measure_scoring)
)

population_set.populations = construct_population_map(measure_scoring)
ps_hash[:populations].each do |pop_code,statement_ref_string|
population_set.populations[pop_code] = modelize_statement_ref_string(statement_ref_string)
ps_hash[:populations].each do |pop_code,statement_ref_hash|
population_set.populations[pop_code] = CQM::StatementReference.new(statement_ref_hash)
end

ps_hash[:supplemental_data_elements].each do |statement_ref_string|
population_set.supplemental_data_elements << modelize_statement_ref_string(statement_ref_string)
ps_hash[:supplemental_data_elements].each do |statement_ref_hash|
population_set.supplemental_data_elements << CQM::StatementReference.new(statement_ref_hash)
end

ps_hash[:stratifications].each_with_index do |statement_ref_string, index|
ps_hash[:stratifications].each_with_index do |statement_ref_hash, index|
population_set.stratifications << CQM::Stratification.new(
hqmf_id: statement_ref_hash[:hqmf_id],
stratification_id: "#{population_set.population_set_id}_Stratification_#{index+1}",
title: "PopSet#{pop_index+1} Stratification #{index+1}",
statement: modelize_statement_ref_string(statement_ref_string)
statement: CQM::StatementReference.new(statement_ref_hash)
)
end
population_set
Expand All @@ -111,30 +116,32 @@ def extract_population_set(population_hqmf_node)
criteria_components.each do |cc|
statement_ref = cc.at_css('precondition/criteriaReference/id')
next if statement_ref.nil?
statement_ref_string = statement_ref.attr('extension')
statement_ref_hash = { library_name: statement_ref.attr('extension').split('.')[0],
statement_name: Utilities.remove_enclosing_quotes(statement_ref.attr('extension').split('.')[1]),
hqmf_id: cc.at_css('id').attr('root') }
case cc.name
when 'initialPopulationCriteria'
ps[:populations][HQMF::PopulationCriteria::IPP] = statement_ref_string
ps[:populations][HQMF::PopulationCriteria::IPP] = statement_ref_hash
when 'denominatorCriteria'
ps[:populations][HQMF::PopulationCriteria::DENOM] = statement_ref_string
ps[:populations][HQMF::PopulationCriteria::DENOM] = statement_ref_hash
when 'numeratorCriteria'
ps[:populations][HQMF::PopulationCriteria::NUMER] = statement_ref_string
ps[:populations][HQMF::PopulationCriteria::NUMER] = statement_ref_hash
when 'numeratorExclusionCriteria'
ps[:populations][HQMF::PopulationCriteria::NUMEX] = statement_ref_string
ps[:populations][HQMF::PopulationCriteria::NUMEX] = statement_ref_hash
when 'denominatorExclusionCriteria'
ps[:populations][HQMF::PopulationCriteria::DENEX] = statement_ref_string
ps[:populations][HQMF::PopulationCriteria::DENEX] = statement_ref_hash
when 'denominatorExceptionCriteria'
ps[:populations][HQMF::PopulationCriteria::DENEXCEP] = statement_ref_string
ps[:populations][HQMF::PopulationCriteria::DENEXCEP] = statement_ref_hash
when 'measurePopulationCriteria'
ps[:populations][HQMF::PopulationCriteria::MSRPOPL] = statement_ref_string
ps[:populations][HQMF::PopulationCriteria::MSRPOPL] = statement_ref_hash
when 'measurePopulationExclusionCriteria'
ps[:populations][HQMF::PopulationCriteria::MSRPOPLEX] = statement_ref_string
ps[:populations][HQMF::PopulationCriteria::MSRPOPLEX] = statement_ref_hash
when 'stratifierCriteria'
# Ignore Supplemental Data Elements
next if holds_supplemental_data_elements(cc)
ps[:stratifications] << statement_ref_string
ps[:stratifications] << statement_ref_hash
when 'supplementalDataElement'
ps[:supplemental_data_elements] << statement_ref_string
ps[:supplemental_data_elements] << statement_ref_hash
end
end
return ps
Expand All @@ -158,15 +165,6 @@ def construct_population_map(measure_scoring)
raise StandardError.new("Unknown measure scoring type encountered #{measure_scoring}")
end
end

def modelize_statement_ref_string(statement_ref_string)
library_name, statement_name = statement_ref_string.split('.', 2)
return CQM::StatementReference.new(
library_name: library_name,
statement_name: Utilities.remove_enclosing_quotes(statement_name)
)
end

end
end
end
8 changes: 8 additions & 0 deletions test/unit/measure-loader/cql_loader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,31 @@ def test_stratifications_and_observations
assert_equal 'Population Criteria Section', population_set.title
assert population_set.populations.instance_of?(CQM::ContinuousVariablePopulationMap)
assert_equal 'Initial Population', population_set.populations.IPP.statement_name
assert_equal '93C1E91C-806B-4F57-946D-D145D1BD08E2', population_set.populations.IPP.hqmf_id
assert_equal 'Measure Population', population_set.populations.MSRPOPL.statement_name
assert_equal '4725E77E-3D0F-46AC-A175-8DEFDE19EC8A', population_set.populations.MSRPOPL.hqmf_id
assert_equal 'Measure Population Exclusions', population_set.populations.MSRPOPLEX.statement_name
assert_equal '31E49A75-5D9F-441D-96D0-FE2FED1B006B', population_set.populations.MSRPOPLEX.hqmf_id

# check stratifications
assert_equal 2, population_set.stratifications.size
assert_equal 'PopulationSet_1_Stratification_1', population_set.stratifications[0].stratification_id
assert_equal 'PopSet1 Stratification 1', population_set.stratifications[0].title
assert_equal '4DB7BC72-5DD8-4EEB-AB62-D039567CF620', population_set.stratifications[0].hqmf_id
assert_equal 'Stratification 1', population_set.stratifications[0].statement.statement_name
assert_equal '4DB7BC72-5DD8-4EEB-AB62-D039567CF620', population_set.stratifications[0].statement.hqmf_id
assert_equal 'MedianAdmitDecisionTimetoEDDepartureTimeforAdmittedPatients', population_set.stratifications[0].statement.library_name
assert_equal 'PopulationSet_1_Stratification_2', population_set.stratifications[1].stratification_id
assert_equal 'PopSet1 Stratification 2', population_set.stratifications[1].title
assert_equal '46958FCE-9FF3-4F1A-89AB-0A21D1F47F52', population_set.stratifications[1].hqmf_id
assert_equal 'Stratification 2', population_set.stratifications[1].statement.statement_name
assert_equal '46958FCE-9FF3-4F1A-89AB-0A21D1F47F52', population_set.stratifications[1].statement.hqmf_id
assert_equal 'MedianAdmitDecisionTimetoEDDepartureTimeforAdmittedPatients', population_set.stratifications[1].statement.library_name

# check observation
assert_equal population_set.observations.size, 1
assert_equal 'Measure Observation', population_set.observations[0].observation_function.statement_name
assert_equal '2D7701F3-F93D-4994-84F6-0FA00FAA81C9', population_set.observations[0].hqmf_id
assert_equal 'Measure Population', population_set.observations[0].observation_parameter.statement_name

# check SDE
Expand Down

0 comments on commit 8ac8a7a

Please sign in to comment.