Class: Facilities::VHAFacility

Inherits:
BaseFacility show all
Defined in:
app/models/facilities/vha_facility.rb

Constant Summary

Constants inherited from BaseFacility

BaseFacility::BENEFITS, BaseFacility::CEMETERY, BaseFacility::DAYS, BaseFacility::DOD_HEALTH, BaseFacility::FACILITY_MAPPINGS, BaseFacility::HEALTH, BaseFacility::HOURS_STANDARD_MAP, BaseFacility::PENSION_LOCATIONS, BaseFacility::PREFIX_MAP, BaseFacility::TYPES, BaseFacility::TYPE_MAP, BaseFacility::TYPE_NAME_MAP, BaseFacility::VET_CENTER, BaseFacility::YES

Class Method Summary collapse

Methods inherited from BaseFacility

#facility_type_prefix, find_facility_by_id, find_sti_class, max_per_page, per_page, query, sti_name, suggested, to_date

Methods inherited from ApplicationRecord

descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?

Class Method Details

.add_mental_health(facilities) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'app/models/facilities/vha_facility.rb', line 34

def add_mental_health(facilities)
  facilities.map do |fac|
    mh_data = FacilityMentalHealth.find(fac['unique_id'])

    fac['phone']['mental_health_clinic'] = format_mh_phone(mh_data.mh_phone, mh_data.mh_ext) if mh_data.present?

    fac
  end
end

.add_websites(facilities) ⇒ Object



26
27
28
29
30
31
32
# File 'app/models/facilities/vha_facility.rb', line 26

def add_websites(facilities)
  service = Facilities::WebsiteUrlService.new
  facilities.map do |fac|
    fac['website'] = service.find_for_station(fac['unique_id'], sti_name)
    fac
  end
end

.attribute_mapObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/models/facilities/vha_facility.rb', line 98

def attribute_map
  {
    'unique_id' => 'Sta_No',
    'name' => 'NAME',
    'classification' => method(:classification_mapping),
    'phone' => { 'main' => 'Sta_Phone', 'fax' => 'Sta_Fax',
                 'after_hours' => 'afterhoursphone', 'patient_advocate' => 'patientadvocatephone',
                 'enrollment_coordinator' => 'enrollmentcoordinatorphone',
                 'pharmacy' => 'pharmacyphone' },
    'physical' => { 'address_1' => 'Address2', 'address_2' => 'Address1',
                    'address_3' => 'Address3', 'city' => 'MUNICIPALITY', 'state' => 'STATE',
                    'zip' => method(:zip_plus_four) },
    'hours' => BaseFacility::HOURS_STANDARD_MAP,
    'access' => { 'health' => method(:wait_time_data) },
    'feedback' => { 'health' => method(:satisfaction_data) },
    'services' => health_services,
    'mobile' => 'Mobile',
    'visn' => 'Visn',
    'active_status' => 'Pod',
    'mapped_fields' => mapped_fields_list
  }
end

.classification_mapping(facility) ⇒ Object



121
122
123
124
125
126
127
# File 'app/models/facilities/vha_facility.rb', line 121

def classification_mapping(facility)
  classification_id = facility['CocClassificationID']
  mapped_value = classification_map[classification_id]
  return facility['S_Abbr'] if mapped_value.nil?

  mapped_value
end

.format_mh_phone(phone, ext) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'app/models/facilities/vha_facility.rb', line 44

def format_mh_phone(phone, ext)
  if phone.blank?
    ''
  elsif ext.blank?
    phone
  else
    [phone, ext].join(' x ')
  end
end

.get_all_the_facilities_dataObject



16
17
18
19
20
21
22
23
24
# File 'app/models/facilities/vha_facility.rb', line 16

def get_all_the_facilities_data
  gis_type = 'FacilitySitePoint_VHA'
  sort_field = 'Sta_No'
   = Facilities::Gis::MetadataClient.new.(gis_type)
  max_record_count = ['maxRecordCount']
  resp = Facilities::Gis::Client.new.get_all_facilities(gis_type, sort_field, max_record_count)
  resp_with_websites = add_websites(resp)
  add_mental_health(resp_with_websites)
end

.health_servicesObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'app/models/facilities/vha_facility.rb', line 129

def health_services
  {
    'Audiology' => [],
    'ComplementaryAlternativeMed' => [],
    'DentalServices' => [],
    'DiagnosticServices' => %w[ImagingAndRadiology LabServices],
    'EmergencyDept' => [],
    'EyeCare' => [],
    'MentalHealthCare' => %w[OutpatientMHCare OutpatientSpecMHCare VocationalAssistance],
    'OutpatientMedicalSpecialty' => outpatient_medical_specialty_list,
    'OutpatientSurgicalSpecialty' => outpatient_surgical_specialty_list,
    'PrimaryCare' => [],
    'Rehabilitation' => [],
    'UrgentCare' => [],
    'WellnessAndPreventativeCare' => [],
    'DirectPatientSchedulingFlag' => []
  }
end

.identifierObject



94
95
96
# File 'app/models/facilities/vha_facility.rb', line 94

def identifier
  'Sta_No'
end

.mapped_fields_listObject



161
162
163
164
165
166
# File 'app/models/facilities/vha_facility.rb', line 161

def mapped_fields_list
  %w[Sta_No NAME CocClassificationID LASTUPDATE Address1 Address2 Address3 MUNICIPALITY STATE
     zip Zip4 Sta_Phone Sta_Fax afterhoursphone Mobile Visn
     patientadvocatephone enrollmentcoordinatorphone pharmacyphone Monday
     Tuesday Wednesday Thursday Friday Saturday Sunday Pod]
end

.outpatient_medical_specialty_listObject



148
149
150
151
152
153
154
# File 'app/models/facilities/vha_facility.rb', line 148

def outpatient_medical_specialty_list
  %w[
    AllergyAndImmunology CardiologyCareServices DermatologyCareServices
    Diabetes Dialysis Endocrinology Gastroenterology Hematology InfectiousDisease InternalMedicine
    Nephrology Neurology Oncology PulmonaryRespiratoryDisease Rheumatology SleepMedicine
  ]
end

.outpatient_surgical_specialty_listObject



156
157
158
159
# File 'app/models/facilities/vha_facility.rb', line 156

def outpatient_surgical_specialty_list
  %w[CardiacSurgery ColoRectalSurgery ENT GeneralSurgery Gynecology Neurosurgery Orthopedics
     PainManagement PlasticSurgery Podiatry ThoracicSurgery Urology VascularSurgery]
end

.pull_source_dataObject



12
13
14
# File 'app/models/facilities/vha_facility.rb', line 12

def pull_source_data
  get_all_the_facilities_data.map(&method(:new))
end

.satisfaction_data(attrs) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'app/models/facilities/vha_facility.rb', line 66

def satisfaction_data(attrs)
  result = {}
  datum = FacilitySatisfaction.find(attrs['Sta_No'].upcase)
  if datum.present?
    datum.metrics.each { |k, v| result[k.to_s] = v.present? ? v.round(2).to_f : nil }
    result['effective_date'] = to_date(datum.source_updated)
  end
  result
end

.service_listObject



54
55
56
57
# File 'app/models/facilities/vha_facility.rb', line 54

def service_list
  %w[PrimaryCare MentalHealthCare DentalServices UrgentCare EmergencyCare Audiology Cardiology Dermatology
     Gastroenterology Gynecology Ophthalmology Optometry Orthopedics Urology WomensHealth]
end

.wait_time_data(attrs) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'app/models/facilities/vha_facility.rb', line 76

def wait_time_data(attrs)
  result = {}
  datum = FacilityWaitTime.find(attrs['Sta_No'].upcase)
  if datum.present?
    datum.metrics.each { |k, v| result[k.to_s] = v }
    result['effective_date'] = to_date(datum.source_updated)
  end
  result
end

.with_services(services) ⇒ Object



86
87
88
89
90
91
92
# File 'app/models/facilities/vha_facility.rb', line 86

def with_services(services)
  conditions = services.map do |service|
    "services->'health' @> '[{\"sl1\":[\"#{service}\"]}]'"
  end.join(' OR ')

  where(conditions)
end

.zip_plus_four(attrs) ⇒ Object



59
60
61
62
63
64
# File 'app/models/facilities/vha_facility.rb', line 59

def zip_plus_four(attrs)
  zip = attrs['zip']
  zip4_is_empty = attrs['Zip4'].to_s.strip.empty? || attrs['Zip4'].to_s.strip == '0000'
  zip << "-#{attrs['Zip4']}" unless zip4_is_empty
  zip
end