app/assets/javascripts/custom_calculations.js.coffee in hqmf2js-1.3.0 vs app/assets/javascripts/custom_calculations.js.coffee in hqmf2js-1.4.0

- old
+ new

@@ -1,16 +1,30 @@ @hqmf.CustomCalc = {} +@ADE_PRE_V4_ID = ['40280381-454E-C5FA-0145-517F7383016D'] @hqmf.CustomCalc.ADE_TTR_OBSERV = (patient, hqmfjs) -> - inrReadings = DURING(hqmfjs.LaboratoryTestResultInr(patient), hqmfjs.MeasurePeriod(patient)); + if (ADE_PRE_V4_ID.indexOf(hqmfjs.hqmf_id)!=-1) + inrReadings = DURING(hqmfjs.LaboratoryTestResultInr(patient), hqmfjs.MeasurePeriod(patient)); + else + inrReadings = DURING(hqmfjs.LaboratoryTestPerformedInr(patient), hqmfjs.MeasurePeriod(patient)); inrReadings = new hqmf.CustomCalc.PercentTTREntries(inrReadings) - [inrReadings.calculatePercentTTR()] + return [inrReadings.calculatePercentTTR()] +@hqmf.CustomCalc.ADE_TTR_MSRPOPL = (patient, hqmfjs) -> + if (ADE_PRE_V4_ID.indexOf(hqmfjs.hqmf_id)!=-1) + inrReadings = DURING(hqmfjs.LaboratoryTestResultInr(patient), hqmfjs.MeasurePeriod(patient)); + else + inrReadings = DURING(hqmfjs.LaboratoryTestPerformedInr(patient), hqmfjs.MeasurePeriod(patient)); + inrReadings = new hqmf.CustomCalc.PercentTTREntries(inrReadings) + return new Boolean(inrReadings.calculateNumberOfIntervals() > 1) + class @hqmf.CustomCalc.PercentTTREntries extends hQuery.CodedEntryList constructor: (events) -> super() + @inrRanges = 0 + @totalNumberOfDays = 0 @minInr = 2.0 @maxInr = 3.0 @minOutOfRange = 0.8 @maxOutOfRange = 10 @closestSetpoint = 2.5 @@ -69,21 +83,25 @@ else return one calculateDaysInRange: (firstInr, secondInr) -> - - if ((@belowRange(firstInr) and @belowRange(secondInr)) or (@aboveRange(firstInr) and @aboveRange(secondInr))) - 0 - else if (@inRange(firstInr) and @inRange(secondInr)) - @differenceInDays(firstInr,secondInr) - else if (@outsideRange(firstInr) and @inRange(secondInr)) - @calculateCrossingRange(firstInr,secondInr) - else if (@inRange(firstInr) and @outsideRange(secondInr)) - @calculateCrossingRange(secondInr, firstInr) + if(@differenceInDays(firstInr, secondInr) < 57) + @inrRanges = @inrRanges + 1 + @totalNumberOfDays = @totalNumberOfDays + @differenceInDays(firstInr, secondInr) + if ((@belowRange(firstInr) and @belowRange(secondInr)) or (@aboveRange(firstInr) and @aboveRange(secondInr))) + 0 + else if (@inRange(firstInr) and @inRange(secondInr)) + @differenceInDays(firstInr,secondInr) + else if (@outsideRange(firstInr) and @inRange(secondInr)) + @calculateCrossingRange(firstInr,secondInr) + else if (@inRange(firstInr) and @outsideRange(secondInr)) + @calculateCrossingRange(secondInr, firstInr) + else + @calculateSpanningRange(firstInr, secondInr) else - @calculateSpanningRange(firstInr, secondInr) + 0 calculateCrossingRange: (outside,inside) -> outsideInr = @inrValue(outside) insideInr = @inrValue(inside) boundary = @maxInr @@ -112,19 +130,28 @@ getIVL(first).low.difference(getIVL(second).low, 'd') inrValue: (entry) -> entry.values()[0].scalar() - totalNumberOfDays: () -> - @differenceInDays(this[0],this[this.length-1]) - calculateTTR: () -> total = 0 for left, i in this if (i < this.length-1) right = this[i+1] total += @calculateDaysInRange(left, right) total + calculateNumberOfIntervals: () -> + total = 0 + for left, i in this + if (i < this.length-1) + right = this[i+1] + if(@differenceInDays(left, right) < 57) + total = total + 1 + total + calculatePercentTTR: () -> - @calculateTTR()/@totalNumberOfDays()*100 - + @totalNumberOfDays = 0 + if (@calculateNumberOfIntervals() > 1) + @calculateTTR()/@totalNumberOfDays*100 + else + return \ No newline at end of file