Advertisement
andrey_zavyalov

Untitled

Dec 15th, 2023
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. class Report
  2. module Renderer
  3. class MciRenderer < BaseRenderer
  4. def trends
  5. @trends
  6. end
  7.  
  8. def impairment_classification
  9. case assessment_result_color
  10. when 'green'
  11. I18n.t('report.cfp.mci.potentially_cognitively_unimpaired')
  12. when 'yellow'
  13. I18n.t('report.cfp.mci.indicative_of_subjective_decline')
  14. when 'orange'
  15. I18n.t('report.cfp.mci.indicative_of_potential_mci')
  16. when 'red'
  17. I18n.t('report.cfp.mci.indicative_of_major_neurocognitive_disorder')
  18. else
  19. ''
  20. end
  21. end
  22. end
  23. end
  24. end
  25.  
  26. test_ids = [21, 17, 23, 19, 14, 20, 13, 24, 22, 18, 15, 16]
  27. test_titles = test_ids.map do |test_id|
  28. test = Test.find(test_id)
  29. task_code = test.task_code
  30. [I18n.t("report.task.#{task_code}.desc") + ' - SS', I18n.t("report.task.#{task_code}.desc") + ' - %']
  31. end.flatten
  32. titles = "Admin ID
  33. Patient ID
  34. Company Name
  35. Assessment Sent Date
  36. Assessment Completed Date
  37. Summary Statement
  38. Impairment Classification
  39. IQ-code score
  40. IADL score classification
  41. PHQ-9 Score
  42. GAD-7 Score".split("\n")
  43. titles = titles + test_titles
  44.  
  45. protocols = ::Health::Protocol.where(preset_code: :mci)
  46. sessions = ::Health::ProtocolSession.status_complete.where(protocol_id: protocols.ids)
  47. p_bar = ProgressBar.new(sessions.size)
  48.  
  49.  
  50. # CSV.open('tmp/CS-1273.csv', 'w') do |csv|
  51. # CSV.open('tmp/CS-1307.csv', 'w') do |csv|
  52. # CSV.open('tmp/CS-1308.csv', 'w') do |csv|
  53. # CSV.open('tmp/CS-1314.csv', 'w') do |csv|
  54. # CSV.open('tmp/CS-1320.csv', 'w') do |csv|
  55. CSV.open('tmp/CS-1341.csv', 'w') do |csv|
  56. csv << titles
  57. sessions.find_each do |session|
  58. p_bar.puts(session.id)
  59. p_bar.increment!
  60.  
  61. reports = session.reports
  62. batch_names = reports.map(&:batch).map(&:name)
  63. next if batch_names.exclude?('phq9')
  64. next if batch_names.exclude?('gad7')
  65. next if batch_names.exclude?('iadl')
  66. next if batch_names.exclude?('iqcodesr')
  67.  
  68. report = reports.find_by(cfp: true)
  69. renderer = Report::Renderer::MciRenderer.new(report, {filename: '', template: ''})
  70.  
  71. renderer.comparative_group
  72. renderer.trends
  73.  
  74. admin = report.admin_user.becomes(::Health::User).clinic_admin
  75.  
  76. admin_id = admin.id
  77. patient_id = report.admin_user.client_id
  78. company_name = admin.trial.name
  79. sent_at = session.created_at.humanize_datetime
  80. completed_at = reports.maximum(:completed_at).humanize_datetime
  81.  
  82.  
  83. summary_statement = renderer.assessment_summary_main_result[0].html_safe + renderer.assessment_summary_main_result[1].html_safe
  84. summary_statement = ActionView::Base.full_sanitizer.sanitize(summary_statement)
  85.  
  86. impairment_classification = renderer.impairment_classification
  87. iqcode_score = renderer.score_summary('IQCODE-SR')
  88. iadl_score_classification = renderer.iadl_result
  89. phq9_score = renderer.score_summary('PHQ-9')
  90. gad7_score = renderer.score_summary('GAD-7')
  91.  
  92.  
  93. row = [admin_id, patient_id,company_name,sent_at,completed_at,summary_statement,impairment_classification,iqcode_score,iadl_score_classification,phq9_score,gad7_score]
  94. scores = renderer.cog_report.test_scores
  95. test_ids.each do |test_id|
  96. score = scores.find{ |s| s.test_id == test_id }
  97. score_trends = renderer.trends.find{ |trend| trend[:task_id] == test_id }
  98. score_trend = score_trends[:scores].find{ |t| t[:id] == score.id }
  99. row += [score_trend[:adjusted_standard], score_trend[:not_rounded_adjusted_percentile].round(2)]
  100. end
  101. csv << row
  102. end
  103. nil
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement