app/assets/javascripts/hqmf_util.js.coffee in hqmf2js-1.1.0 vs app/assets/javascripts/hqmf_util.js.coffee in hqmf2js-1.2.0

- old
+ new

@@ -406,30 +406,30 @@ val = fieldOrContainerValue(scalarOrHash, 'scalar') val != null @ANYNonNull = ANYNonNull # Returns true if one or more of the supplied values is true -atLeastOneTrue = (values...) -> +atLeastOneTrue = (precondition, values...) -> trueValues = (value for value in values when value && value.isTrue()) trueValues.length>0 hqmf.SpecificsManager.unionAll(new Boolean(trueValues.length>0), values) @atLeastOneTrue = atLeastOneTrue # Returns true if all of the supplied values are true -allTrue = (values...) -> +allTrue = (precondition, values...) -> trueValues = (value for value in values when value && value.isTrue()) hqmf.SpecificsManager.intersectAll(new Boolean(trueValues.length>0 && trueValues.length==values.length), values) @allTrue = allTrue # Returns true if one or more of the supplied values is false -atLeastOneFalse = (values...) -> +atLeastOneFalse = (precondition, values...) -> falseValues = (value for value in values when value.isFalse()) hqmf.SpecificsManager.intersectAll(new Boolean(falseValues.length>0), values, true) @atLeastOneFalse = atLeastOneFalse # Returns true if all of the supplied values are false -allFalse = (values...) -> +allFalse = (precondition, values...) -> falseValues = (value for value in values when value.isFalse()) hqmf.SpecificsManager.unionAll(new Boolean(falseValues.length>0 && falseValues.length==values.length), values, true) @allFalse = allFalse # Return true if compareTo matches value @@ -512,10 +512,12 @@ @eventLists = [] for eventList in allEventLists @eventLists.push eventList for event in eventList this.push(event) + listCount: -> @eventLists.length + childList: (index) -> @eventLists[index] # Create a CrossProduct of the supplied event lists. XPRODUCT = (eventLists...) -> hqmf.SpecificsManager.intersectAll(new CrossProduct(eventLists), eventLists) @XPRODUCT = XPRODUCT @@ -543,11 +545,11 @@ else ts = new TS() ts.date = eventOrTimeStamp new IVL_TS(ts, ts) @getIVL = getIVL - + eventAccessor = { 'DURING': 'low', 'OVERLAP': 'low', 'SBS': 'low', 'SAS': 'low', @@ -818,9 +820,40 @@ return hqmf.SpecificsManager.maintainSpecifics(new Boolean(false), events) if events.length < 2 throw "cannot calculate against more than 2 events" if events.length > 2 hqmf.SpecificsManager.maintainSpecifics(new Boolean(withinRange('DATEDIFF', getIVL(events[0]), getIVL(events[1]), range)), events) @DATEDIFF = DATEDIFF +# Calculate the set of time differences in minutes between pairs of events +# events - a XPRODUCT of two event lists +# range - ignored +# initialSpecificContext - the specific context containing one row per permissible +# combination of events +TIMEDIFF = (events, range, initialSpecificContext) -> + if events.listCount() != 2 + throw "TIMEDIFF can only process 2 lists of events" + eventList1 = events.childList(0) + eventList2 = events.childList(1) + eventIndex1 = hqmf.SpecificsManager.getColumnIndex(eventList1.specific_occurrence) + eventIndex2 = hqmf.SpecificsManager.getColumnIndex(eventList2.specific_occurrence) + eventMap1 = {} + eventMap2 = {} + for event in eventList1 + eventMap1[event.id] = event + for event in eventList2 + eventMap2[event.id] = event + results = [] + for row in initialSpecificContext.rows + event1 = row.values[eventIndex1] + event2 = row.values[eventIndex2] + if event1 and event2 and event1 != hqmf.SpecificsManager.any and event2 != hqmf.SpecificsManager.any + # The maps contain the actual events we want to work with since these may contain + # time shifted clones of the events in the specificContext, e.g. via adjustBoundsForField + shiftedEvent1 = eventMap1[event1.id] + shiftedEvent2 = eventMap2[event2.id] + if shiftedEvent1 and shiftedEvent2 + results.push(shiftedEvent1.asTS().difference(shiftedEvent2.asTS(), 'min')) + results +@TIMEDIFF = TIMEDIFF @OidDictionary = {}; hqmfjs = hqmfjs||{} @hqmfjs = @hqmfjs||{};