Advertisement
andrey_zavyalov

Untitled

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