diff --git a/app/assets/javascripts/core.js.coffee b/app/assets/javascripts/core.js.coffee index 8484708..e55a9eb 100644 --- a/app/assets/javascripts/core.js.coffee +++ b/app/assets/javascripts/core.js.coffee @@ -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 @@ -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 ### @@ -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 diff --git a/test/unit/patient_api_test.rb b/test/unit/patient_api_test.rb index 9c35a7e..69ddef6 100644 --- a/test/unit/patient_api_test.rb +++ b/test/unit/patient_api_test.rb @@ -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()') @@ -198,4 +199,4 @@ def test_medical_equipment assert_equal '13648007', @context.eval('patient.medicalEquipment()[0].anatomicalStructure().code()') end -end \ No newline at end of file +end