Skip to content

Commit 7c542ce

Browse files
author
John Pinto
committed
Updated app/models/template.rb.
Changes: - Added reference to API Server (fo third-party integration). - Added functionality for Question Identifiers.
1 parent 11c545a commit 7c542ce

1 file changed

Lines changed: 159 additions & 0 deletions

File tree

app/models/template.rb

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# updated_at :datetime
2020
# family_id :integer
2121
# org_id :integer
22+
# api_server_id :integer
2223
#
2324
# Indexes
2425
#
@@ -69,6 +70,8 @@ class Template < ApplicationRecord
6970

7071
belongs_to :org
7172

73+
belongs_to :api_server, optional: true
74+
7275
has_many :plans
7376

7477
has_many :phases, dependent: :destroy
@@ -81,6 +84,8 @@ class Template < ApplicationRecord
8184

8285
has_many :question_options, through: :questions
8386

87+
has_many :question_identifiers, through: :questions
88+
8489
has_many :conditions, through: :questions
8590

8691
# ===============
@@ -484,6 +489,160 @@ def self.new_family_id
484489
end
485490
end
486491

492+
# Check if template has question Identifiers
493+
def template_has_any_question_identifiers(template_id)
494+
template = Template.find(template_id)
495+
phases = template.phases
496+
for phase in phases do
497+
sections = phase.sections
498+
for section in sections do
499+
questions = section.questions
500+
for question in questions do
501+
if question.question_identifiers.exists?
502+
for qid in question.question_identifiers do
503+
if !qid.value.blank? && !qid.name.blank?
504+
return true
505+
break
506+
end
507+
end
508+
end
509+
end
510+
end
511+
end
512+
end
513+
514+
# This method is reponsible to generate the Question Identifiers list
515+
# for one template. It returns a html formated list.
516+
def html_question_identifiers_list(template_id)
517+
#Get the template
518+
template = Template.find(template_id)
519+
phases = template.phases
520+
521+
html = "<div>"
522+
for phase in phases do
523+
sections = phase.sections
524+
525+
526+
html += "<div>
527+
<h4 class=\"modal-title\">Phase - %{phase_title} </h4><hr/>" % { phase_title: phase.title }
528+
529+
for section in sections do
530+
questions = section.questions
531+
532+
# to verify if there is a question identifier in the section
533+
for question in questions do
534+
for qid in question.question_identifiers do
535+
if !qid.value.blank? && !qid.name.blank?
536+
html += "<div>
537+
<h5 class=\"modal-title\">Section - %{section_title}</h5>" % { section_title: section.title }
538+
end
539+
break
540+
end
541+
break
542+
end
543+
544+
# to display the question text and the question identifiers
545+
for question in questions do
546+
if question.question_identifiers.exists?
547+
html += "<ul>"
548+
549+
for qid in question.question_identifiers do
550+
if !qid.value.blank? && !qid.name.blank?
551+
clean_question_text = question.text.gsub(/<p>(.*?)<\/p>/, "\\1")
552+
html += "<div class=\"col-md-8\">
553+
<label>Question %{question_number} - %{question_text}</label></div>" % { question_number: question.number, question_text: clean_question_text }
554+
end
555+
break
556+
end
557+
558+
for qid in question.question_identifiers do
559+
if !qid.value.blank? && !qid.name.blank?
560+
html += "<li class=\"list-group-item\" style=\"border: none\">Identifier Value: %{identifier_value}</li>" % { identifier_value: qid.value }
561+
html += "<li class=\"list-group-item\" style=\"border: none\">Identifier Name: %{identifier_name}</li>" % { identifier_name: qid.name }
562+
end
563+
end
564+
html += "</ul>"
565+
566+
end
567+
568+
end
569+
html += "<hr/></div>"
570+
end
571+
html += "<hr/></div>"
572+
end
573+
574+
html += "</div>"
575+
end
576+
577+
578+
# This method is reponsible to generate the Question Identifiers list
579+
# for one template. It returns a html formated list.
580+
def export_question_identifiers_list(template_id)
581+
#Get the template
582+
template = Template.find(template_id)
583+
phases = template.phases
584+
585+
html = "<html>
586+
<head>
587+
<title>%{template_title}</title>
588+
</head>
589+
<body>" % { template_title: template.title }
590+
591+
for phase in phases do
592+
sections = phase.sections
593+
594+
html += "<h2>Phase - %{phase_title}</h2>" % { phase_title: phase.title }
595+
596+
for section in sections do
597+
questions = section.questions
598+
599+
# to verify if there is a question identifier in the section
600+
for question in questions do
601+
for qid in question.question_identifiers do
602+
if !qid.value.blank? && !qid.name.blank?
603+
html += "<h3>Section - %{section_title}</h3>" % { section_title: section.title }
604+
end
605+
break
606+
end
607+
break
608+
end
609+
610+
# to display the question text and the question identifiers
611+
for question in questions do
612+
if question.question_identifiers.exists?
613+
html += "<ul>"
614+
615+
for qid in question.question_identifiers do
616+
if !qid.value.blank? && !qid.name.blank?
617+
clean_question_text = question.text.gsub(/<p>(.*?)<\/p>/, "\\1")
618+
html += "
619+
<p>Question %{question_number} - %{question_text}</p>" % { question_number: question.number, question_text: clean_question_text }
620+
end
621+
break
622+
end
623+
624+
for qid in question.question_identifiers do
625+
if !qid.value.blank? && !qid.name.blank?
626+
html += "<li>Identifier Value: %{identifier_value}</li>" % { identifier_value: qid.value }
627+
html += "<li>Identifier Name: %{identifier_name}</li>" % { identifier_name: qid.name }
628+
end
629+
end
630+
html += "</ul><br>"
631+
632+
end
633+
634+
end
635+
html += "<br>"
636+
end
637+
end
638+
639+
html += "</body>
640+
</html>"
641+
end
642+
643+
644+
645+
487646
private
488647

489648
# ============================

0 commit comments

Comments
 (0)