Class: Services::MdsAssessment

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
MdsAssessmentCategorizer
Defined in:
app/models/services/mds_assessment.rb

Constant Summary collapse

VERSION1_0 =
"1.00"
VERSION1_1 =
"1.10"
VERSION1_1_DATE =
"20120401"
CORRECTED =
1
MATCH_MAP =
{ 
  'x0150' => 'a0200',
  'x0600a' => 'a0310a',
  'x0600b' => 'a0310b',
  'x0600c' => 'a0310c',
  'x0600d' => 'a0310d',
  'x0600f' => 'a0310f',
  'x0700a' => 'a2300',
  'x0700b' => 'a2000',
  'x0700c' => 'a1600'
}
MISSING_ATTRIBUTE_VALUES =
%w{ ^ - }
CLEAN_ATTR_METHOD_REX =
/^clean_(\w+)$/
ADD_NEW_RECORD =

Record types

1
MODIFY_EXISTING_RECORD =
2
INACTIVATE_EXISTING_RECORD =
3
VALIDATED_FIELDS =

These are fields that must be treated as if they are full-fledged attributes of the assessment. If they are not listed here, any access to the field will raise an exception from #method_missing.

[ :itm_sbst_cd,
:fac_id,
:corrected,
:prior_isc_cd,
:state_cd,
:a0050,
:a0100b,
:a0200,
:a1600,
:a1800,
:a2000,
:a2200,
:a2300,
:a0310a,
:a0310b,
:a0310c,
:a0310d,
:a0310f,
:a0900,
:k0200a,
:k0200b,
:x0100]
CREATED =
0
PROCESSED =
1

Instance Method Summary collapse

Methods included from MdsAssessmentCategorizer

#a0310f_99?, #admission_assessment?, #any_type_of_correction_assessment?, #correction_applied?, #correction_record?, #death_assessment?, #discharge_assessment?, #discharge_or_death_assessment?, #entered_from_hospital?, #entry_assessment?, #inactivated?, #inactivation_assessment?, #ninety_day?, #quarterly?, #significant_correction_assessment?, #tracking_assessment?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
# File 'app/models/services/mds_assessment.rb', line 171

def method_missing(sym, *args)
  # If an attribute is referenced as mds.clean_* (e.g. mds.clean_k0200b), the value 
  # we will return the value of the attribute as nil if it is one of the special
  # mds values (^|-). If we do it this way, we don't have to splatter the special
  # value junk all over the code base.
  if sym.to_s =~ CLEAN_ATTR_METHOD_REX
    return filter_value(responses.present? ? responses[$1] : nil)
  end
  return responses.present? ? responses[sym.to_s] : nil if VALIDATED_FIELDS.include?(sym)
  return responses[sym.to_s] if responses.present? && responses.keys.include?(sym.to_s)
  super
end

Instance Method Details

#comatose?Boolean

Returns:

  • (Boolean)


232
233
234
# File 'app/models/services/mds_assessment.rb', line 232

def comatose?
  clean_b0100 == "1"
end

#discharge_dateObject



208
209
210
# File 'app/models/services/mds_assessment.rb', line 208

def discharge_date
  a2000
end

#discharge_typeObject



212
213
214
# File 'app/models/services/mds_assessment.rb', line 212

def discharge_type
  clean_a2100.blank? ? nil : clean_a2100.to_i
end

#entry_dateObject



204
205
206
# File 'app/models/services/mds_assessment.rb', line 204

def  
  a1600
end

#entry_typeObject



200
201
202
# File 'app/models/services/mds_assessment.rb', line 200

def entry_type
  (clean_a1700 == "2") ? Stay::REENTRY : Stay::ADMISSION
end

#first_nameObject



220
221
222
# File 'app/models/services/mds_assessment.rb', line 220

def first_name
 clean_a0500a || clean_x0200a || "" 
end

#genderObject



228
229
230
# File 'app/models/services/mds_assessment.rb', line 228

def gender
  clean_a0800 || clean_x0300 || ""
end

#has_responses?Boolean

Returns:

  • (Boolean)


188
189
190
# File 'app/models/services/mds_assessment.rb', line 188

def has_responses?
  responses.present?
end

#hash_field_values(fields, target = true) ⇒ Object



249
250
251
252
253
254
255
256
# File 'app/models/services/mds_assessment.rb', line 249

def hash_field_values(fields, target=true)
  field_values = fields.map do |f| 
    value_field = target ? f : MATCH_MAP[f]
    "#{f}=#{responses[value_field]}"
  end

  Digest::MD5.hexdigest(field_values.join(','))
end

#inact_corr_match_fields(entry_discharge_reporting) ⇒ Object



236
237
238
239
240
241
242
243
244
245
246
247
# File 'app/models/services/mds_assessment.rb', line 236

def inact_corr_match_fields(entry_discharge_reporting)
  fields = %w{ x0150 x0600a x0600b x0600c x0600d x0600f }
  case entry_discharge_reporting
  when 99
    fields << 'x0700a'
  when 01
    fields << 'x0700c'
  when 10, 11, 12
    fields << 'x0700b'
  end
  fields
end

#last_nameObject



224
225
226
# File 'app/models/services/mds_assessment.rb', line 224

def last_name
  clean_a0500c || clean_x0200c || ""
end

#respond_to_missing?(sym, include_private = false) ⇒ Boolean

Paired with method_missing

Returns:

  • (Boolean)


167
168
169
# File 'app/models/services/mds_assessment.rb', line 167

def respond_to_missing?(sym, include_private=false)
  VALIDATED_FIELDS.include?(sym) || (responses.present? && responses.keys.include?(sym.to_s)) || super
end

#ssnObject



216
217
218
# File 'app/models/services/mds_assessment.rb', line 216

def ssn 
  clean_a0600a || clean_x0500 || ""
end

#unit_idObject



184
185
186
# File 'app/models/services/mds_assessment.rb', line 184

def unit_id
  MDS_MODULE_ID
end

#version1_0?Boolean

Returns:

  • (Boolean)


192
193
194
# File 'app/models/services/mds_assessment.rb', line 192

def version1_0?
  reference_date <  Date.parse("20120401")
end

#version1_1?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'app/models/services/mds_assessment.rb', line 196

def version1_1?
  reference_date >= Date.parse("20120401")
end