Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
Add support for inline value sets and effectiveTime within data criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
hadleynet committed Mar 22, 2012
1 parent 52fa3dd commit 9c935ce
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/generator/data_criteria.js.erb
Expand Up @@ -7,10 +7,10 @@ var <%= criteria.js_name %> = <%= js_for_value(criteria.value) %>;
<%- all_criteria.select {|c| c.type != :variable}.each do |criteria| -%>
var <%= criteria.js_name %> = function(patient) {
<%- if criteria.type == :characteristic -%>
var value = patient.<%= criteria.property %>(<%= 'EndDate.asDate()' if criteria.property == :age %>);
var value = patient.<%= criteria.property %>(<%= js_for_date_bound(criteria) if criteria.property == :age %>);
return matchingValue(value, <%= js_for_bounds(criteria.value) %>);
<%- else -%>
var codes = getCodes("<%= criteria.code_list_id %>");
var codes = <%= js_for_code_list(criteria) %>;
<%- if criteria.effective_time -%>
<%- startExp = js_for_value(criteria.effective_time.low) -%>
var start = <%= startExp %><%= '.asDate()' if startExp != 'null' %>;
Expand Down
25 changes: 25 additions & 0 deletions lib/generator/js.rb
Expand Up @@ -43,6 +43,31 @@ def js_for_bounds(bounds)
end
end

def js_for_date_bound(criteria)
bound = nil
if criteria.effective_time
if criteria.effective_time.high
bound = criteria.effective_time.high
elsif criteria.effective_time.low
bound = criteria.effective_time.low
end
end

if bound
"#{js_for_value(bound)}.asDate()"
else
'EndDate.asDate()'
end
end

def js_for_code_list(criteria)
if criteria.inline_code_list
criteria.inline_code_list.to_json
else
"getCodes(\"#{criteria.code_list_id}\")"
end
end

# Returns the JavaScript generated for a HQMF::Precondition
def js_for_precondition(precondition, indent)
template_str = File.read(File.expand_path("../precondition.js.erb", __FILE__))
Expand Down
24 changes: 18 additions & 6 deletions lib/hqmf/data_criteria.rb
Expand Up @@ -12,21 +12,21 @@ def initialize(entry)
@entry = entry
@status = attr_val('./cda:observationCriteria/cda:statusCode/@code')
@id_xpath = './cda:observationCriteria/cda:id/@extension'
@code_list_xpath = './cda:observationCriteria/cda:code/@valueSet'
@code_list_xpath = './cda:observationCriteria/cda:code'
@value_xpath = './cda:observationCriteria/cda:value'
@effective_time_xpath = './*/cda:effectiveTime'

entry_type = attr_val('./*/cda:definition/*/cda:id/@extension')
case entry_type
when 'Problem', 'Problems'
@type = :diagnosis
@code_list_xpath = './cda:observationCriteria/cda:value/@valueSet'
@code_list_xpath = './cda:observationCriteria/cda:value'
@effective_time = extract_effective_time
@section = 'conditions'
when 'Encounter'
@type = :encounter
@id_xpath = './cda:encounterCriteria/cda:id/@extension'
@code_list_xpath = './cda:encounterCriteria/cda:code/@valueSet'
@code_list_xpath = './cda:encounterCriteria/cda:code'
@effective_time = extract_effective_time
@section = 'encounters'
when 'LabResults', 'Results'
Expand All @@ -37,21 +37,23 @@ def initialize(entry)
when 'Procedure'
@type = :procedure
@section = 'procedures'
@effective_time = extract_effective_time
when 'Medication'
@type = :medication
@id_xpath = './cda:substanceAdministrationCriteria/cda:id/@extension'
@code_list_xpath = './cda:substanceAdministrationCriteria/cda:participant/cda:roleParticipant/cda:code/@valueSet'
@code_list_xpath = './cda:substanceAdministrationCriteria/cda:participant/cda:roleParticipant/cda:code'
@effective_time = extract_effective_time
@section = 'medications'
when 'RX'
@type = :medication
@id_xpath = './cda:supplyCriteria/cda:id/@extension'
@code_list_xpath = './cda:supplyCriteria/cda:participant/cda:roleParticipant/cda:code/@valueSet'
@code_list_xpath = './cda:supplyCriteria/cda:participant/cda:roleParticipant/cda:code'
@effective_time = extract_effective_time
@section = 'medications'
when 'Demographics'
@type = :characteristic
@property = property_for_demographic
@effective_time = extract_effective_time
@value = extract_value
when nil
@type = :variable
Expand Down Expand Up @@ -82,7 +84,17 @@ def title
# Get the code list OID of the criteria, used as an index to the code list database
# @return [String] the code list identifier of this data criteria
def code_list_id
attr_val(@code_list_xpath)
attr_val("#{@code_list_xpath}/@valueSet")
end

def inline_code_list
codeSystemName = attr_val("#{@code_list_xpath}/@codeSystemName")
codeValue = attr_val("#{@code_list_xpath}/@code")
if codeSystemName && codeValue
{codeSystemName => [codeValue]}
else
nil
end
end

private
Expand Down
48 changes: 47 additions & 1 deletion test/fixtures/NQF59New.xml
Expand Up @@ -165,6 +165,47 @@
</definition>
</observationCriteria>
</entry>
<entry>
<localVariableName>dummyAge1</localVariableName>
<observationCriteria>
<id root="0" extension="ageBetween60and64"/>
<code code="424144002" codeSystem="2.16.840.1.113883.6.96"
displayName="Age"/>
<effectiveTime>
<low value="20100101"/>
<high value="20111231"/>
</effectiveTime>
<value xsi:type="IVL_PQ">
<low value="60" unit="a"/>
<high value="64" unit="a"/>
</value>
<definition>
<observationReference moodCode="DEF">
<id root="0" extension="Demographics"/>
</observationReference>
</definition>
</observationCriteria>
</entry>
<entry>
<localVariableName>dummyAge2</localVariableName>
<observationCriteria>
<id root="0" extension="ageBetween60and64"/>
<code code="424144002" codeSystem="2.16.840.1.113883.6.96"
displayName="Age"/>
<effectiveTime>
<low value="20100101"/>
</effectiveTime>
<value xsi:type="IVL_PQ">
<low value="60" unit="a"/>
<high value="64" unit="a"/>
</value>
<definition>
<observationReference moodCode="DEF">
<id root="0" extension="Demographics"/>
</observationReference>
</definition>
</observationCriteria>
</entry>
<entry>
<localVariableName>genderMale</localVariableName>
<observationCriteria>
Expand Down Expand Up @@ -240,7 +281,12 @@
<observationCriteria>
<id root="0" extension="DummyProcedure"/>
<statusCode code="completed"/>
<code valueSet="1.2.3.4"/>
<code codeSystemName="SNOMED-CT" codeSystem="2.16.840.1.113883.6.1"
displayName="" code="127355002"/>
<effectiveTime>
<low value="20100101"/>
<high value="20111231"/>
</effectiveTime>
<definition>
<observationReference moodCode="DEF">
<id root="0" extension="Procedure"/>
Expand Down
8 changes: 6 additions & 2 deletions test/unit/document_test.rb
Expand Up @@ -57,7 +57,7 @@ def test_population_criteria

def test_data_criteria
data_criteria = @doc.all_data_criteria
assert_equal 23, data_criteria.length
assert_equal 25, data_criteria.length

criteria = @doc.data_criteria('EndDate')
assert criteria.to_xml.include?('extension="EndDate"')
Expand Down Expand Up @@ -93,7 +93,11 @@ def test_data_criteria

criteria = @doc.data_criteria('DummyProcedure')
assert_equal :procedure, criteria.type
assert_equal '1.2.3.4', criteria.code_list_id
assert criteria.inline_code_list
assert_equal '127355002', criteria.inline_code_list['SNOMED-CT'][0]
assert criteria.effective_time
assert_equal '20100101', criteria.effective_time.low.value
assert_equal '20111231', criteria.effective_time.high.value
assert_equal 'completed', criteria.status

criteria = @doc.data_criteria('EDorInpatientEncounter')
Expand Down

0 comments on commit 9c935ce

Please sign in to comment.