Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regex support to match #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions app/assets/javascripts/core.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ class hQuery.CodedValue
return true
return false

###*
Returns true if the contained code and codeSystemName match a code in the supplied codeSet.
@param {Object} codeSet a hash with code system names as keys and an array of codes (provided as regular expressions) as values
@returns {boolean}
###
regex_includedIn: (codeSet) ->
for codeSystemName, codes of codeSet
if @csn==codeSystemName
for code in codes
regex = RegExp(code,"i")
if regex.test(@c)
return true
return false

###*
Status as defined by value set 2.16.840.1.113883.5.14,
the ActStatus vocabulary maintained by HL7
Expand Down Expand Up @@ -437,6 +451,17 @@ class hQuery.CodedEntry
return true
return false

###*
Returns true if any of this entry codes match a code in the supplied codeSet.
@param {Object} codeSet a hash with code system names as keys and an array of codes (provided as regular expressions) as values
@returns {boolean}
###
regex_includesCodeFrom: (codeSet) ->
for codedValue in @_type
if codedValue.regex_includedIn(codeSet)
return true
return false

###*
@returns {Boolean} whether the entry was negated
###
Expand Down Expand Up @@ -507,6 +532,26 @@ class hQuery.CodedEntryList extends Array
cloned.push(entry)
cloned

###*
Return the number of entries that match the
supplied code set where those entries occur between the supplied time bounds
@param {Object} codeSet a hash with code system names as keys and an array of codes (provided as regular expressions) as values
@param {Date} start the start of the period during which the entry must occur, a null value will match all times
@param {Date} end the end of the period during which the entry must occur, a null value will match all times
@param {boolean} includeNegated whether the returned list of entries should include those that have been negated
@return {CodedEntryList} the matching entries
TODO - decide on what to do with includeNegated parameter
###
regex_match: (codeSet, start, end, includeNegated=false) ->
cloned = new hQuery.CodedEntryList()
for entry in this
afterStart = (!start || entry.timeStamp()>=start)
beforeEnd = (!end || entry.timeStamp()<=end)
matchesCode = codeSet == null || entry.regex_includesCodeFrom(codeSet)
if (afterStart && beforeEnd && matchesCode && (includeNegated || !entry.negationInd()))
cloned.push(entry)
cloned

###*
Return a new list of entries that is the result of concatenating the passed in entries with this list
@return {CodedEntryList} the set of concatenated entries
Expand Down
3 changes: 2 additions & 1 deletion test/unit/patient_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def test_procedures
assert_equal 'Colonscopy', @context.eval('patient.procedures()[0].freeTextType()')
assert @context.eval('patient.procedures()[0].includesCodeFrom({"CPT": ["44388"]})')
assert_equal 1, @context.eval('patient.procedures().match({"CPT": ["44388"]}).length')
assert_equal 1, @context.eval('patient.procedures().regex_match({"CPT": ["4438.*"]}).length')
assert_equal 0, @context.eval('patient.procedures().match({"CPT": ["44388"]}, sampleDate).length')
assert_equal 'SNOMED-CT', @context.eval('patient.procedures()[0].site().codeSystemName()')
assert_equal '71854001', @context.eval('patient.procedures()[0].site().code()')
Expand Down Expand Up @@ -198,4 +199,4 @@ def test_medical_equipment
assert_equal '13648007', @context.eval('patient.medicalEquipment()[0].anatomicalStructure().code()')
end

end
end