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



168
169
170
171
172
173
174
175
176
177
178
179
# File 'app/models/services/mds_assessment.rb', line 168

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)


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

def comatose?
  clean_b0100 == "1"
end

#discharge_dateObject



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

def discharge_date
  a2000
end

#discharge_typeObject



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

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

#entry_dateObject



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

def  
  a1600
end

#entry_typeObject



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

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

#first_nameObject



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

def first_name
 clean_a0500a || clean_x0200a || "" 
end

#genderObject



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

def gender
  clean_a0800 || clean_x0300 || ""
end

#has_responses?Boolean

Returns:

  • (Boolean)


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

def has_responses?
  responses.present?
end

#hash_field_values(fields, target = true) ⇒ Object



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

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

  # binding.pry

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

#inact_corr_match_fields(entry_discharge_reporting) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
# File 'app/models/services/mds_assessment.rb', line 233

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



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

def last_name
  clean_a0500c || clean_x0200c || ""
end

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

Paired with method_missing

Returns:

  • (Boolean)


164
165
166
# File 'app/models/services/mds_assessment.rb', line 164

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

#ssnObject



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

def ssn 
  clean_a0600a || clean_x0500 || ""
end

#unit_idObject



181
182
183
# File 'app/models/services/mds_assessment.rb', line 181

def unit_id
  MDS_MODULE_ID
end

#version1_0?Boolean

Returns:

  • (Boolean)


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

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

#version1_1?Boolean

Returns:

  • (Boolean)


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

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