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

- old
+ new

@@ -52,23 +52,34 @@ hQuery.Encounter::lengthOfStay = (unit) -> ivl_ts = this.asIVL_TS() ivl_ts.low.difference(ivl_ts.high, unit) +hQuery.Encounter::transferTime = () -> + transfer = (@json['transferFrom'] || @json['transferTo']) + time = transfer.time if transfer + if time + hQuery.dateFromUtcSeconds(time) + else + if @json['transferTo'] + @endDate() + else + @startDate() + hQuery.AdministrationTiming::dosesPerDay = () -> #figure out the units and value and calculate p = this.period() switch(p.unit()) when "h" 24/p.value() when "d" 1/p.value() -hQuery.Fulfillment::daysInRange = (dateRange,doesPerDay) -> +hQuery.Fulfillment::daysInRange = (dateRange,dose, dosesPerDay) -> # this will give us the number of days this fullfilment was for - totalDays = this.quantityDispensed().value()/doesPerDay + totalDays = this.quantityDispensed().value()/dose/dosesPerDay totalDays = 0 if isNaN(totalDays) endDate = new Date(this.dispenseDate().getTime() + (totalDays*60*60*24*1000)) high = if dateRange && dateRange.high then dateRange.high.asDate() else endDate low = if dateRange && dateRange.low then dateRange.low.asDate() else this.dispenseDate() # from the date it was deispensed add the total number of days to @@ -92,21 +103,42 @@ # Determin sum the cmd for each fullFillment history based on the # date range hQuery.Medication::fulfillmentTotals = (dateRange)-> dpd = this.administrationTiming().dosesPerDay() + dose = this.dose().scalar this.fulfillmentHistory().reduce (t, s) -> - t + s.daysInRange(dateRange,dpd) + t + s.daysInRange(dateRange,dose,dpd) , 0 - + +# returns cumulativeMedicationDuration in terms of days hQuery.Medication::cumulativeMedicationDuration = (dateRange) -> - #assuming that the dose is the same across fills and that fills is stated in individual - #doses not total amount. Will need to flush this out more at a later point in time. - #Considering that liquid meds are probaly dispensed as total volume ex 325ml with a dose of - #say 25ml per dose. Will definatley need to revisit this. - this.fulfillmentTotals(dateRange) if this.administrationTiming() + #assuming that the dose is the same across fills and that fills is stated in individual + #doses not total amount. Will need to flush this out more at a later point in time. + #Considering that liquid meds are probaly dispensed as total volume ex 325ml with a dose of + #say 25ml per dose. Will definatley need to revisit this. + if this.administrationTiming() && this.dose() && @json['fulfillmentHistory'] + this.fulfillmentTotals(dateRange) + else if this.administrationTiming() && this.allowedAdministrations() + # this happens if we have a Medication, Order. + cumulativeMedicationDuration = this.allowedAdministrations() / this.administrationTiming().dosesPerDay() + # need to do in case of divide by zero error + cumulativeMedicationDuration = 0 if isNaN(cumulativeMedicationDuration) + cumulativeMedicationDuration +class hQuery.Reference + constructor: (@json) -> + referenced_id: -> @json["referenced_id"] + referenced_type: -> @json["reference"] + type: -> @json["type"] + +hQuery.CodedEntry::references = () -> + for ref in (@json["references"] || []) + new hQuery.Reference(ref) + +hQuery.CodedEntry::referencesByType = (type) -> + e for e in @references() when e.type() == type hQuery.CodedEntry::respondTo = (functionName) -> typeof(@[functionName]) == "function" hQuery.CodedEntryList::isTrue = ->