lib/hqmf-generator/hqmf-generator.rb in health-data-standards-3.4.6 vs lib/hqmf-generator/hqmf-generator.rb in health-data-standards-3.5.0

- old
+ new

@@ -21,20 +21,36 @@ # Utility class used to supply a binding to Erb. Contains utility functions used # by the erb templates that are used to generate the HQMF document. class ErbContext < OpenStruct + def initialize(vars) super(vars) + @local_var_names = {} + @local_var_counter = {} end # Get a binding that contains all the instance variables # @return [Binding] def get_binding binding end + def xml_for_local_variable(criteria) + name = @local_var_names[criteria.id] + unless name + if criteria.specific_occurrence + name = "Occurrence#{criteria.specific_occurrence}#{criteria.id}" + else + name = criteria.id + end + @local_var_names[criteria.id] = name + end + HQMF2::Generator.render_template('local_variable', {'name' => name}) + end + def xml_for_reference_id(id) reference = HQMF::Reference.new(id) xml_for_reference(reference) end @@ -130,11 +146,15 @@ HQMF2::Generator.render_template('subset', {'doc' => doc, 'subset' => operator, 'criteria' => data_criteria}) end end subsets_xml.join() end - + + def xml_for_precondition_cv(precondition) + HQMF2::Generator.render_template('precondition_cv', {'doc' => doc, 'precondition' => precondition}) + end + def xml_for_precondition(precondition) HQMF2::Generator.render_template('precondition', {'doc' => doc, 'precondition' => precondition}) end def xml_for_data_criteria(data_criteria, is_source_data_criteria) @@ -142,11 +162,11 @@ end def xml_for_population_criteria(population, criteria_id) xml = '' population_criteria = doc.population_criteria(population[criteria_id]) - if population_criteria + if population_criteria && population_element_prefix(criteria_id) != "measureObservation" xml = HQMF2::Generator.render_template('population_criteria', {'doc' => doc, 'population' => population, 'criteria_id' => criteria_id, 'population_criteria' => population_criteria}) end xml end @@ -157,10 +177,27 @@ HQMF2::Generator.render_template('temporal_relationship', {'doc' => doc, 'relationship' => reference}) end end refs.join end + + def xml_for_measure_observation_definition(doc) + observation = doc.find_population_by_type(HQMF::PopulationCriteria::OBSERV) + msrpopl = doc.find_population_by_type( HQMF::PopulationCriteria::MSRPOPL) + HQMF2::Generator.render_template('measure_observation_definition', {'doc' => doc, 'observation' => observation, "msrpopl" => msrpopl}) + end + + def expression_for_observation(doc,observation) + "NOT IMPLEMENTED" + end + + def data_criteria_should_be_grouper?(criteria) + return false unless criteria + return false unless criteria.definition == 'derived' + return true unless criteria.subset_operators + criteria.subset_operators.all? {|o| o.supports_grouper_criteria?} + end def oid_for_name(code_system_name) HealthDataStandards::Util::CodeSystemHelper.oid_for_code_system(code_system_name) end @@ -187,12 +224,18 @@ 'PROC' when :medications, :allMedications 'SBADM' when :medication_supply 'SPLY' + when :observation + 'OBS' else - 'OBS' + if data_criteria_should_be_grouper?(referenced_criteria) + 'GROUPER' + else + 'OBS' + end end end def code_for_characteristic(characteristic) case characteristic @@ -210,11 +253,19 @@ '103579009' else raise "Unknown demographic code [#{characteristic}]" end end - + + def is_transfer(code) + if code == "TRANSFER_TO" || code == "TRANSFER_FROM" + true + else + false + end + end + def oid_for_characteristic(characteristic) case characteristic when :birthtime '2.16.840.1.113883.6.1' else @@ -243,10 +294,16 @@ end when 'patient_characteristic', 'patient_characteristic_birthdate', 'patient_characteristic_clinical_trial_participant', 'patient_characteristic_expired', 'patient_characteristic_gender', 'patient_characteristic_age', 'patient_characteristic_languages', 'patient_characteristic_marital_status', 'patient_characteristic_race' 'characteristic_criteria' when 'variable' 'variable_criteria' + when 'derived' + if data_criteria_should_be_grouper?(data_criteria) + 'grouper_criteria' + else + 'observation_criteria' + end else 'observation_criteria' end end @@ -264,29 +321,39 @@ when :medications, :allMedications 'substanceAdministration' when :medication_supply 'supply' else - 'observation' + if data_criteria_should_be_grouper?(data_criteria) + 'grouper' + else + 'observation' + end end end def population_element_prefix(population_criteria_code) case population_criteria_code when HQMF::PopulationCriteria::IPP - 'patientPopulation' + 'initialPopulation' when HQMF::PopulationCriteria::DENOM 'denominator' when HQMF::PopulationCriteria::NUMER 'numerator' when HQMF::PopulationCriteria::DENEXCEP 'denominatorException' when HQMF::PopulationCriteria::DENEX 'denominatorExclusion' - else + when HQMF::PopulationCriteria::MSRPOPL + 'measurePopulation' + when HQMF::PopulationCriteria::OBSERV + 'measureObservation' + when HQMF::PopulationCriteria::STRAT + 'stratifier' + else raise "Unknown population criteria type #{population_criteria_code}" end end end end -end \ No newline at end of file +end