Skip to content

Instantly share code, notes, and snippets.

@carlossanchezp
Last active August 29, 2015 14:08
Show Gist options
  • Save carlossanchezp/1e67f017a9fb13f7012c to your computer and use it in GitHub Desktop.
Save carlossanchezp/1e67f017a9fb13f7012c to your computer and use it in GitHub Desktop.
module RowUtils
extend ActiveSupport::Concern
FILE_HEADERS = %W(ID_PAIS ID_PROVINCIA ID_POBLACION ID_PROVEEDOR ID_ESPECIALIDAD ID_GRUPO ID_INFRAESTRUCTURA ID_TIPO_PROVEEDOR ID_COD_POSTAL ID_CENTRO_HIS ID_SERVICIO_HIS ID_SEXO ID_PROFESIONAL ID_SEXO_PROF ID_IDIOMA ID_EXCEPCION ID_AMBITO ID_TIPO_EXCEPCION ID_CAMPO ID_EQUIPO SW_JEFE_EQUIPO NUM_TELEFONO OBS_TELEFONO DESC_PROVINCIA DESC_POBLACION ID_TRATAMIENTO DESC_TRATAMIENTO DESC_PROVEEDOR DESC_ESPECIALIDAD DESC_GRUPO DESC_TIPO_PROVEEDOR RAZON_SOCIAL DESC_DOMICILIO DESC_HORARIO DESC_PROFESIONAL ID_TRATAMIENTO_PROF DESC_TRATAMIENTO_PROF DESC_IDIOMA EXCEPCION F_ALTA ID_CITACION CX CY ORDEN ID_TIPO_PERSONA)
included do
FILE_HEADERS.each do |header|
define_method header.underscore do
value = self[header]
value =~ /^\d+$/ ? value.to_i : value
end
end
end
def is_a_doctor?
self.id_tipo_persona == 1
end
def is_a_center?
self.id_tipo_persona == 2
end
def get_id_province
self.id_provincia
end
def get_id_city
self.id_poblacion
end
def get_id_provider
self.id_poblacion
end
def get_id_infrastructure
self.id_infraestructura
end
def get_name_provider
self.desc_proveedor
end
def doctor_attributes
{
external_id: self.id_profesional,
email: ActiveSupport::Inflector.transliterate(desc_profesional).downcase.gsub(/[^AZa-z1-9]+/, '.') + '@sanitas.com',
show_email: 0,
show_telephone: 0,
languages: self.desc_idioma || 'Nativo',
type_id: 0,
active: 0,
adress_as: professional_title(self.desc_tratamiento),
first_name: self.desc_profesional.split(',')[0] || 'SN',
last_name: self.desc_profesional.split(',')[1]
}
end
def spec_attributes
{
external_id: self.id_especialidad,
name: self.desc_especialidad,
slug: ActiveSupport::Inflector.transliterate(subspec_name.to_s).downcase.gsub(/[^a-z1-9]+/, '-').chomp('-')
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment