Last active
August 29, 2015 14:02
-
-
Save jmercedes/8c7b60bb652f94f55214 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'open-uri' | |
| task :result => :environment do | |
| xml = open("https://s3.amazonaws.com/bionuclear/154948_Tabla3.xml") | |
| document = Nokogiri::XML(xml) | |
| articles = document.css('ARTICULOS') | |
| articles.each do |result| | |
| email = result.css('email').first.content | |
| doctor_name = result.css('Medico').first.content | |
| insurance_company = result.css('Aseguradora').first.content | |
| patient_type = result.css('Tipo_Paciente').first.content | |
| patient_name = result.css('nombre_paciente').first.content | |
| personal_identification_number = result.css('cedula').first.content | |
| times_printed = result.css('impreso').first.content | |
| amount_samples_delivered = result.css('muestra_entregada').first.content | |
| date_delivered = result.css('fecha_entrega').first.content | |
| description = result.css('descripcion').first.content #<descripcion>HEMOGLUCOTEX (GLICEMIA)</descripcion> | |
| lab_support = result.css('laboratorio_apoyo').first.content #<laboratorio_apoyo /> | |
| department = result.css('departamento').first.content | |
| method = result.css('metodo').first.content #<metodo /> | |
| protocol = result.css('protocolo').first.content #<protocolo>1308-2994</protocolo> | |
| date_created = result.css('fecha_creado').first.content #<fecha_creado>2013-08-28T14:39:14.487-08:00</fecha_creado> | |
| age = result.css('edad').first.content #<edad>68</edad> | |
| period = result.css('periodo').first.content #<periodo>A</periodo> | |
| id_header_analysis_reception = result.css('id_header_recepcion_analisis').first.content #<id_header_recepcion_analisis>154952</id_header_recepcion_analisis> | |
| id_patient = result.css('id_paciente').first.content #<id_paciente>1037502</id_paciente> | |
| sample_type = result.css('tipo_muestra').first.content #<tipo_muestra>SUERO</tipo_muestra> | |
| id_detail_analysis_reception = result.css('id_detalle_recepcion_analisis').first.content #<id_detalle_recepcion_analisis>549022</id_detalle_recepcion_analisis> | |
| id_analysis = result.css('id_analisis').first.content #<id_analisis>glu-d</id_analisis> | |
| #document_number = result.css('numero_documento').first.content #<numero_documento>17855</numero_documento> | |
| #line_items values | |
| #<resultado_registrado>1</resultado_registrado> | |
| variable = result.css('Variable').first.content #<Variable>WBC</Variable> | |
| unit = result.css('unidad').first.try(:content) #<unidad>K/µl</unidad> | |
| test_result = result.css('resultado').first.content #<resultado>8.6</resultado> | |
| expected_value_minimun = result.css('minimo').first.try(:content) #<minimo>4.00</minimo> | |
| expected_value_maximum = result.css('maximo').first.try(:content) #<maximo>10.00</maximo> | |
| # <comentario>4.0 -10.00</comentario> | |
| # <observacion /> | |
| # <descriptivo /> | |
| # <orden>1</orden> | |
| # <interpretacion>{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fmodern Courier New;}} | |
| #\viewkind4\uc1\pard\f0\fs20\par | |
| #} | |
| #</interpretacion> | |
| user = User.find_or_create_by!(email: email) do |user| | |
| user.password = 'penita_pena' | |
| #NewResult.new_result(user).deliver | |
| end | |
| user.results.create!(doctor_name: doctor_name, | |
| insurance_company: insurance_company, | |
| patient_type: patient_type, | |
| patient_name: patient_name, | |
| personal_identification_number: personal_identification_number, | |
| times_printed: times_printed, | |
| amount_samples_delivered: amount_samples_delivered, | |
| date_delivered: date_delivered, | |
| description: description, | |
| lab_support: lab_support, | |
| department: department, | |
| method: method, | |
| protocol: protocol, | |
| date_created: date_created, | |
| age: age, | |
| period: period, | |
| id_header_analysis_reception: id_header_analysis_reception, | |
| id_patient: id_patient, | |
| sample_type: sample_type, | |
| id_detail_analysis_reception: id_detail_analysis_reception, | |
| id_analysis: id_analysis) | |
| patient_result = user.results.where(protocol: protocol) | |
| patient_result.line_items.create!(variable: variable, | |
| unit: unit, | |
| expected_value_minimun: expected_value_minimun, | |
| expected_value_maximum: expected_value_maximum, | |
| test_result: test_result) | |
| #Enviar correo al paciente notificando que sus resultados | |
| #están listos. | |
| NewResult.new_result(user).deliver | |
| ############################################################# | |
| #generated_password = Devise.friendly_token.first(8) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| create_table "line_items", force: true do |t| | |
| t.string "variable" | |
| t.string "alarm" | |
| t.string "result" | |
| t.string "espected_value" | |
| t.string "unit" | |
| t.datetime "created_at" | |
| t.datetime "updated_at" | |
| t.integer "result_id" | |
| end | |
| create_table "results", force: true do |t| | |
| t.string "doctor_name" | |
| t.string "insurance_company" | |
| t.string "patient_type" | |
| t.string "patient_name" | |
| t.string "personal_identification_number" | |
| t.string "times_printed" | |
| t.integer "amount_samples_delivered" | |
| t.string "date_delivered" | |
| t.string "description" | |
| t.string "lab_support" | |
| t.string "department" | |
| t.string "method" | |
| t.string "protocol" | |
| t.string "date_created" | |
| t.string "age" | |
| t.string "period" | |
| t.string "id_header_analysis_reception" | |
| t.string "id_patient" | |
| t.string "sample_type" | |
| t.string "id_detail_analysis_reception" | |
| t.string "id_analysis" | |
| t.string "document_no" | |
| t.datetime "created_at" | |
| t.datetime "updated_at" | |
| t.integer "user_id" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment