Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Report
- module Renderer
- class MciRenderer < BaseRenderer
- def trends
- @trends
- end
- def impairment_classification
- case assessment_result_color
- when 'green'
- I18n.t('report.cfp.mci.potentially_cognitively_unimpaired')
- when 'yellow'
- I18n.t('report.cfp.mci.indicative_of_subjective_decline')
- when 'orange'
- I18n.t('report.cfp.mci.indicative_of_potential_mci')
- when 'red'
- I18n.t('report.cfp.mci.indicative_of_major_neurocognitive_disorder')
- else
- ''
- end
- end
- end
- end
- end
- test_ids = [21, 17, 23, 19, 14, 20, 13, 24, 22, 18, 15, 16]
- test_titles = test_ids.map do |test_id|
- test = Test.find(test_id)
- task_code = test.task_code
- [I18n.t("report.task.#{task_code}.desc") + ' - SS', I18n.t("report.task.#{task_code}.desc") + ' - %']
- end.flatten
- titles = "Admin ID
- Patient ID
- Company Name
- Assessment Sent Date
- Assessment Completed Date
- Summary Statement
- Impairment Classification
- IQ-code score
- IADL score classification
- PHQ-9 Score
- GAD-7 Score".split("\n")
- titles = titles + test_titles
- protocols = ::Health::Protocol.where(preset_code: :mci)
- sessions = ::Health::ProtocolSession.status_complete.where(protocol_id: protocols.ids)
- p_bar = ProgressBar.new(sessions.size)
- # CSV.open('tmp/CS-1273.csv', 'w') do |csv|
- # CSV.open('tmp/CS-1307.csv', 'w') do |csv|
- # CSV.open('tmp/CS-1308.csv', 'w') do |csv|
- # CSV.open('tmp/CS-1314.csv', 'w') do |csv|
- # CSV.open('tmp/CS-1320.csv', 'w') do |csv|
- CSV.open('tmp/CS-1341.csv', 'w') do |csv|
- csv << titles
- sessions.find_each do |session|
- p_bar.puts(session.id)
- p_bar.increment!
- reports = session.reports
- batch_names = reports.map(&:batch).map(&:name)
- next if batch_names.exclude?('phq9')
- next if batch_names.exclude?('gad7')
- next if batch_names.exclude?('iadl')
- next if batch_names.exclude?('iqcodesr')
- report = reports.find_by(cfp: true)
- renderer = Report::Renderer::MciRenderer.new(report, {filename: '', template: ''})
- renderer.comparative_group
- renderer.trends
- admin = report.admin_user.becomes(::Health::User).clinic_admin
- admin_id = admin.id
- patient_id = report.admin_user.client_id
- company_name = admin.trial.name
- sent_at = session.created_at.humanize_datetime
- completed_at = reports.maximum(:completed_at).humanize_datetime
- summary_statement = renderer.assessment_summary_main_result[0].html_safe + renderer.assessment_summary_main_result[1].html_safe
- summary_statement = ActionView::Base.full_sanitizer.sanitize(summary_statement)
- impairment_classification = renderer.impairment_classification
- iqcode_score = renderer.score_summary('IQCODE-SR')
- iadl_score_classification = renderer.iadl_result
- phq9_score = renderer.score_summary('PHQ-9')
- gad7_score = renderer.score_summary('GAD-7')
- row = [admin_id, patient_id,company_name,sent_at,completed_at,summary_statement,impairment_classification,iqcode_score,iadl_score_classification,phq9_score,gad7_score]
- scores = renderer.cog_report.test_scores
- test_ids.each do |test_id|
- score = scores.find{ |s| s.test_id == test_id }
- score_trends = renderer.trends.find{ |trend| trend[:task_id] == test_id }
- score_trend = score_trends[:scores].find{ |t| t[:id] == score.id }
- row += [score_trend[:adjusted_standard], score_trend[:not_rounded_adjusted_percentile].round(2)]
- end
- csv << row
- end
- nil
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement