test/unit/specifics_test.rb in hqmf2js-1.2.0 vs test/unit/specifics_test.rb in hqmf2js-1.2.1
- old
+ new
@@ -17,11 +17,11 @@
"
@context.eval(test_initialize_js)
end
- def test_specifics_initialized_proper
+ def test_specifics_initialized_properly
@context.eval('hqmf.SpecificsManager.keyLookup[0]').must_equal 'OccurrenceAEncounter'
@context.eval('hqmf.SpecificsManager.keyLookup[1]').must_equal 'OccurrenceBEncounter'
@context.eval("hqmf.SpecificsManager.indexLookup['OccurrenceAEncounter']").must_equal 0
@context.eval("hqmf.SpecificsManager.indexLookup['OccurrenceBEncounter']").must_equal 1
@@ -591,16 +591,104 @@
pop3f.specificContext = specific3
"
@context.eval(rows)
- @context.eval('hqmf.SpecificsManager.validate(hqmf.SpecificsManager.intersectSpecifics(pop1,pop2,pop3))').must_equal true
- @context.eval('hqmf.SpecificsManager.validate(hqmf.SpecificsManager.intersectSpecifics(pop1,pop2,pop4))').must_equal false
- @context.eval('hqmf.SpecificsManager.validate(hqmf.SpecificsManager.intersectSpecifics(pop1,pop2,pop5))').must_equal false
- @context.eval('hqmf.SpecificsManager.validate(hqmf.SpecificsManager.intersectSpecifics(pop3f,pop1,pop2))').must_equal false
+ @context.eval('hqmf.SpecificsManager.validate(hqmf.SpecificsManager.intersectSpecifics(pop1, hqmf.SpecificsManager.intersectSpecifics(pop2,pop3)))').must_equal true
+ @context.eval('hqmf.SpecificsManager.validate(hqmf.SpecificsManager.intersectSpecifics(pop1, hqmf.SpecificsManager.intersectSpecifics(pop2,pop4)))').must_equal false
+ @context.eval('hqmf.SpecificsManager.validate(hqmf.SpecificsManager.intersectSpecifics(pop1, hqmf.SpecificsManager.intersectSpecifics(pop2,pop5)))').must_equal false
+ @context.eval('hqmf.SpecificsManager.validate(hqmf.SpecificsManager.intersectSpecifics(pop3f,hqmf.SpecificsManager.intersectSpecifics(pop1,pop2)))').must_equal false
end
+
+ def test_episode_of_care_restrictions
+
+ rows = "
+ hqmf.SpecificsManager.initialize({},hqmfjs, {'id':'OccurrenceAEncounter1', 'type':'Encounter', 'function':'SourceOccurrenceAEncounter1'},
+ {'id':'OccurrenceAEncounter2', 'type':'Encounter', 'function':'SourceOccurrenceAEncounter2'},
+ {'id':'OccurrenceAEncounter3', 'type':'Encounter', 'function':'SourceOccurrenceAEncounter3'})
+
+
+ var row1 = new Row('OccurrenceAEncounter1',{'OccurrenceAEncounter1':{'id':1}});
+ var row2 = new Row('OccurrenceAEncounter2',{'OccurrenceAEncounter2':{'id':3}});
+ var row3 = new Row('OccurrenceAEncounter1',{'OccurrenceAEncounter1':{'id':1},'OccurrenceAEncounter2':{'id':3}});
+ var identityRow = hqmf.SpecificsManager.identity().rows[0];
+
+ var pop1 = new Boolean(true);
+ var pop2 = new Boolean(true);
+ var pop3 = new Boolean(true);
+ var pop4 = new Boolean(true);
+
+ pop1.specificContext = new hqmf.SpecificOccurrence([row1]);
+ pop2.specificContext = new hqmf.SpecificOccurrence([row2]);
+ pop3.specificContext = new hqmf.SpecificOccurrence([row3]);
+ pop4.specificContext = new hqmf.SpecificOccurrence([identityRow]);
+
+ var result = null;
+
+ "
+ @context.eval(rows)
+
+ # test allValuesAny
+ @context.eval('row1.allValuesAny([0,1,2])').must_equal false
+ @context.eval('row1.allValuesAny([1,2])').must_equal true
+ @context.eval('row1.allValuesAny([2])').must_equal true
+ @context.eval('row1.allValuesAny([1])').must_equal true
+ @context.eval('row1.allValuesAny([])').must_equal true
+ @context.eval('identityRow.allValuesAny([0,1,2])').must_equal true
+
+ # test checkEpisodeOfCare
+ @context.eval('Row.checkEpisodeOfCare({id: 1}, true) == hqmf.SpecificsManager.any').must_equal true
+ @context.eval('Row.checkEpisodeOfCare({id: 1}, false) == hqmf.SpecificsManager.any').must_equal false
+ @context.eval('Row.checkEpisodeOfCare({id: 1}, false).id == 1').must_equal true
+
+ # test intersect
+ @context.eval('row1.intersect(row2,[0,1]).allValuesAny([0,1,2])').must_equal true # this is the critical check. Make sure we drop bad episode of care intersections
+ @context.eval('row1.intersect(row2,[0]).allValuesAny([2])').must_equal true
+ @context.eval('row1.intersect(row2,[0]).values[0].id == 1').must_equal true
+ @context.eval('row1.intersect(row2,[0]).values[1].id == 3').must_equal true
+ @context.eval('row1.intersect(row2,[1]).allValuesAny([2])').must_equal true
+ @context.eval('row1.intersect(row2,[1]).values[0].id == 1').must_equal true
+ @context.eval('row1.intersect(row2,[1]).values[1].id == 3').must_equal true
+
+ @context.eval('identityRow.intersect(row1,[0]).values[0].id == 1').must_equal true
+ @context.eval('identityRow.intersect(row1,[0]).allValuesAny([1,2])').must_equal true
+ @context.eval('row1.intersect(identityRow,[0]).values[0].id == 1').must_equal true
+ @context.eval('row1.intersect(identityRow,[0]).allValuesAny([1,2])').must_equal true
+
+ # make sure we drop a bad strggler for encounter 2
+ @context.eval('row1.intersect(row3,[0,1]).allValuesAny([1,2])').must_equal true
+ @context.eval('row1.intersect(row3,[0,1]).values[0].id == 1').must_equal true
+
+ # test intersectSpecifics
+
+ @context.eval('hqmf.SpecificsManager.intersectSpecifics(pop1,pop2).specificContext.rows[0].values[0].id == 1').must_equal true
+ @context.eval('hqmf.SpecificsManager.intersectSpecifics(pop1,pop2).specificContext.rows[0].values[1].id == 3').must_equal true
+ @context.eval('hqmf.SpecificsManager.intersectSpecifics(pop1,pop2).specificContext.rows[0].values[2] == hqmf.SpecificsManager.any').must_equal true
+ @context.eval("hqmf.SpecificsManager.intersectSpecifics(pop1,pop2,['OccurrenceAEncounter1','OccurrenceAEncounter2','OccurrenceAEncounter3']).specificContext.rows[0].allValuesAny([0,1,2])").must_equal true
+ @context.eval("result = hqmf.SpecificsManager.intersectSpecifics(pop1,pop2,['OccurrenceAEncounter1']).specificContext.rows[0]")
+ @context.eval('result.allValuesAny([2])').must_equal true
+ @context.eval('result.values[0].id == 1').must_equal true
+ @context.eval('result.values[1].id == 3').must_equal true
+ @context.eval("result = hqmf.SpecificsManager.intersectSpecifics(pop1,pop2,['OccurrenceAEncounter2']).specificContext.rows[0]")
+ @context.eval('result.allValuesAny([2])').must_equal true
+ @context.eval('result.values[0].id == 1').must_equal true
+ @context.eval('result.values[1].id == 3').must_equal true
+
+ @context.eval("result = hqmf.SpecificsManager.intersectSpecifics(pop1,pop4,['OccurrenceAEncounter1']).specificContext.rows[0]")
+ @context.eval('result.values[0].id == 1').must_equal true
+ @context.eval('result.allValuesAny([1,2])').must_equal true
+
+ @context.eval("result = hqmf.SpecificsManager.intersectSpecifics(pop4,pop1,['OccurrenceAEncounter1']).specificContext.rows[0]")
+ @context.eval('result.values[0].id == 1').must_equal true
+ @context.eval('result.allValuesAny([1,2])').must_equal true
+
+ @context.eval("result = hqmf.SpecificsManager.intersectSpecifics(pop1,pop3,['OccurrenceAEncounter1','OccurrenceAEncounter2']).specificContext.rows[0]")
+ @context.eval('result.allValuesAny([1,2])').must_equal true
+ @context.eval('result.values[0].id == 1').must_equal true
+
+ end
def test_intersect_all
rows = "
var row1 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1}});
@@ -772,24 +860,24 @@
new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': new hQuery.CodedEntry({_id:14}), 'OccurrenceBEncounter':new hQuery.CodedEntry({'_id':2})}),
new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': new hQuery.CodedEntry({_id:15}), 'OccurrenceBEncounter':new hQuery.CodedEntry({'_id':3})})]
"
@context.eval(rows)
@context.eval('hqmf.SpecificsManager.extractEvents(undefined, non_specific_rows).length').must_equal 6
- @context.eval('hqmf.SpecificsManager.extractEvents(undefined, non_specific_rows)[0].id').must_equal 10
- @context.eval('hqmf.SpecificsManager.extractEvents(undefined, non_specific_rows)[1].id').must_equal 11
- @context.eval('hqmf.SpecificsManager.extractEvents(undefined, non_specific_rows)[2].id').must_equal 12
- @context.eval('hqmf.SpecificsManager.extractEvents(undefined, non_specific_rows)[3].id').must_equal 13
- @context.eval('hqmf.SpecificsManager.extractEvents(undefined, non_specific_rows)[4].id').must_equal 14
- @context.eval('hqmf.SpecificsManager.extractEvents(undefined, non_specific_rows)[5].id').must_equal 15
+ @context.eval('hqmf.SpecificsManager.extractEvents(undefined, non_specific_rows)[0].id').must_equal '10'
+ @context.eval('hqmf.SpecificsManager.extractEvents(undefined, non_specific_rows)[1].id').must_equal '11'
+ @context.eval('hqmf.SpecificsManager.extractEvents(undefined, non_specific_rows)[2].id').must_equal '12'
+ @context.eval('hqmf.SpecificsManager.extractEvents(undefined, non_specific_rows)[3].id').must_equal '13'
+ @context.eval('hqmf.SpecificsManager.extractEvents(undefined, non_specific_rows)[4].id').must_equal '14'
+ @context.eval('hqmf.SpecificsManager.extractEvents(undefined, non_specific_rows)[5].id').must_equal '15'
@context.eval("hqmf.SpecificsManager.extractEvents('OccurrenceAEncounter', specific_rows).length").must_equal 6
- @context.eval("hqmf.SpecificsManager.extractEvents('OccurrenceAEncounter', specific_rows)[0].id").must_equal 10
- @context.eval("hqmf.SpecificsManager.extractEvents('OccurrenceAEncounter', specific_rows)[1].id").must_equal 11
- @context.eval("hqmf.SpecificsManager.extractEvents('OccurrenceAEncounter', specific_rows)[2].id").must_equal 12
- @context.eval("hqmf.SpecificsManager.extractEvents('OccurrenceAEncounter', specific_rows)[3].id").must_equal 13
- @context.eval("hqmf.SpecificsManager.extractEvents('OccurrenceAEncounter', specific_rows)[4].id").must_equal 14
- @context.eval("hqmf.SpecificsManager.extractEvents('OccurrenceAEncounter', specific_rows)[5].id").must_equal 15
+ @context.eval("hqmf.SpecificsManager.extractEvents('OccurrenceAEncounter', specific_rows)[0].id").must_equal '10'
+ @context.eval("hqmf.SpecificsManager.extractEvents('OccurrenceAEncounter', specific_rows)[1].id").must_equal '11'
+ @context.eval("hqmf.SpecificsManager.extractEvents('OccurrenceAEncounter', specific_rows)[2].id").must_equal '12'
+ @context.eval("hqmf.SpecificsManager.extractEvents('OccurrenceAEncounter', specific_rows)[3].id").must_equal '13'
+ @context.eval("hqmf.SpecificsManager.extractEvents('OccurrenceAEncounter', specific_rows)[4].id").must_equal '14'
+ @context.eval("hqmf.SpecificsManager.extractEvents('OccurrenceAEncounter', specific_rows)[5].id").must_equal '15'
end
def test_specifics_subset_operators
@@ -828,67 +916,67 @@
moreThanOne = 'new IVL_PQ(new PQ(2))'
lessThanThree = 'new IVL_PQ(null, new PQ(2))'
exactly1 = 'new IVL_PQ(new PQ(1), new PQ(1))'
@context.eval("specific1.COUNT(#{moreThanOne}).rows.length").must_equal 5
- @context.eval("specific1.COUNT(#{moreThanOne}).rows[0].tempValue.id").must_equal 10
- @context.eval("specific1.COUNT(#{moreThanOne}).rows[1].tempValue.id").must_equal 11
- @context.eval("specific1.COUNT(#{moreThanOne}).rows[2].tempValue.id").must_equal 12
- @context.eval("specific1.COUNT(#{moreThanOne}).rows[3].tempValue.id").must_equal 13
- @context.eval("specific1.COUNT(#{moreThanOne}).rows[4].tempValue.id").must_equal 14
+ @context.eval("specific1.COUNT(#{moreThanOne}).rows[0].tempValue.id").must_equal '10'
+ @context.eval("specific1.COUNT(#{moreThanOne}).rows[1].tempValue.id").must_equal '11'
+ @context.eval("specific1.COUNT(#{moreThanOne}).rows[2].tempValue.id").must_equal '12'
+ @context.eval("specific1.COUNT(#{moreThanOne}).rows[3].tempValue.id").must_equal '13'
+ @context.eval("specific1.COUNT(#{moreThanOne}).rows[4].tempValue.id").must_equal '14'
@context.eval("specific1.COUNT(#{lessThanThree}).rows.length").must_equal 3
- @context.eval("specific1.COUNT(#{lessThanThree}).rows[0].tempValue.id").must_equal 10
- @context.eval("specific1.COUNT(#{lessThanThree}).rows[1].tempValue.id").must_equal 11
- @context.eval("specific1.COUNT(#{lessThanThree}).rows[2].tempValue.id").must_equal 15
+ @context.eval("specific1.COUNT(#{lessThanThree}).rows[0].tempValue.id").must_equal '10'
+ @context.eval("specific1.COUNT(#{lessThanThree}).rows[1].tempValue.id").must_equal '11'
+ @context.eval("specific1.COUNT(#{lessThanThree}).rows[2].tempValue.id").must_equal '15'
@context.eval("specific1.COUNT(#{exactly1}).rows.length").must_equal 1
- @context.eval("specific1.COUNT(#{exactly1}).rows[0].tempValue.id").must_equal 15
+ @context.eval("specific1.COUNT(#{exactly1}).rows[0].tempValue.id").must_equal '15'
@context.eval("specific2.COUNT(#{moreThanOne}).rows.length").must_equal 5
- @context.eval("specific2.COUNT(#{moreThanOne}).rows[0].values[0].id").must_equal 10
- @context.eval("specific2.COUNT(#{moreThanOne}).rows[1].values[0].id").must_equal 11
- @context.eval("specific2.COUNT(#{moreThanOne}).rows[2].values[0].id").must_equal 12
- @context.eval("specific2.COUNT(#{moreThanOne}).rows[3].values[0].id").must_equal 13
- @context.eval("specific2.COUNT(#{moreThanOne}).rows[4].values[0].id").must_equal 14
+ @context.eval("specific2.COUNT(#{moreThanOne}).rows[0].values[0].id").must_equal '10'
+ @context.eval("specific2.COUNT(#{moreThanOne}).rows[1].values[0].id").must_equal '11'
+ @context.eval("specific2.COUNT(#{moreThanOne}).rows[2].values[0].id").must_equal '12'
+ @context.eval("specific2.COUNT(#{moreThanOne}).rows[3].values[0].id").must_equal '13'
+ @context.eval("specific2.COUNT(#{moreThanOne}).rows[4].values[0].id").must_equal '14'
@context.eval("specific2.COUNT(#{lessThanThree}).rows.length").must_equal 3
- @context.eval("specific2.COUNT(#{lessThanThree}).rows[0].values[0].id").must_equal 10
- @context.eval("specific2.COUNT(#{lessThanThree}).rows[1].values[0].id").must_equal 11
- @context.eval("specific2.COUNT(#{lessThanThree}).rows[2].values[0].id").must_equal 15
+ @context.eval("specific2.COUNT(#{lessThanThree}).rows[0].values[0].id").must_equal '10'
+ @context.eval("specific2.COUNT(#{lessThanThree}).rows[1].values[0].id").must_equal '11'
+ @context.eval("specific2.COUNT(#{lessThanThree}).rows[2].values[0].id").must_equal '15'
@context.eval("specific2.COUNT(#{exactly1}).rows.length").must_equal 1
- @context.eval("specific2.COUNT(#{exactly1}).rows[0].values[0].id").must_equal 15
+ @context.eval("specific2.COUNT(#{exactly1}).rows[0].values[0].id").must_equal '15'
@context.eval("specific3.COUNT(#{exactly1}).rows.length").must_equal 1
@context.eval("specific4.COUNT(#{moreThanOne}).rows.length").must_equal 0
###
##### FIRST
###
@context.eval("specific1.FIRST().rows.length").must_equal 3
- @context.eval("specific1.FIRST().rows[0].tempValue.id").must_equal 11
- @context.eval("specific1.FIRST().rows[1].tempValue.id").must_equal 12
- @context.eval("specific1.FIRST().rows[2].tempValue.id").must_equal 15
+ @context.eval("specific1.FIRST().rows[0].tempValue.id").must_equal '11'
+ @context.eval("specific1.FIRST().rows[1].tempValue.id").must_equal '12'
+ @context.eval("specific1.FIRST().rows[2].tempValue.id").must_equal '15'
@context.eval("specific2.FIRST().rows.length").must_equal 3
- @context.eval("specific2.FIRST().rows[0].values[0].id").must_equal 11
- @context.eval("specific2.FIRST().rows[1].values[0].id").must_equal 12
- @context.eval("specific2.FIRST().rows[2].values[0].id").must_equal 15
+ @context.eval("specific2.FIRST().rows[0].values[0].id").must_equal '11'
+ @context.eval("specific2.FIRST().rows[1].values[0].id").must_equal '12'
+ @context.eval("specific2.FIRST().rows[2].values[0].id").must_equal '15'
@context.eval("specific3.FIRST().rows.length").must_equal 1
@context.eval("specific4.FIRST().rows.length").must_equal 0
###
##### MOST RECENT
###
@context.eval("specific1.RECENT().rows.length").must_equal 3
- @context.eval("specific1.RECENT().rows[0].tempValue.id").must_equal 10
- @context.eval("specific1.RECENT().rows[1].tempValue.id").must_equal 13
- @context.eval("specific1.RECENT().rows[2].tempValue.id").must_equal 15
+ @context.eval("specific1.RECENT().rows[0].tempValue.id").must_equal '10'
+ @context.eval("specific1.RECENT().rows[1].tempValue.id").must_equal '13'
+ @context.eval("specific1.RECENT().rows[2].tempValue.id").must_equal '15'
@context.eval("specific2.RECENT().rows.length").must_equal 3
- @context.eval("specific2.RECENT().rows[0].values[0].id").must_equal 10
- @context.eval("specific2.RECENT().rows[1].values[0].id").must_equal 13
- @context.eval("specific2.RECENT().rows[2].values[0].id").must_equal 15
+ @context.eval("specific2.RECENT().rows[0].values[0].id").must_equal '10'
+ @context.eval("specific2.RECENT().rows[1].values[0].id").must_equal '13'
+ @context.eval("specific2.RECENT().rows[2].values[0].id").must_equal '15'
@context.eval("specific3.RECENT().rows.length").must_equal 1
@context.eval("specific4.RECENT().rows.length").must_equal 0