From 4bf13d9c33a105c6e7f3171503732c2b7a24a55d Mon Sep 17 00:00:00 2001
From: Jorn van de Beek <jornvandebeek@roqua.nl>
Date: Thu, 24 Jun 2021 15:23:06 +0200
Subject: [PATCH] Allow outcome_table to be set to nil to hide values from
 outcome tables

---
 .ruby-version                                       |  2 +-
 lib/quby/compiler/entities/subscore_schema.rb       |  3 ++-
 lib/quby/compiler/outputs/roqua_serializer.rb       |  1 +
 spec/quby/compiler/outputs/roqua_serializer_spec.rb | 13 ++++++++++++-
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/.ruby-version b/.ruby-version
index 860487c..37c2961 100644
--- a/.ruby-version
+++ b/.ruby-version
@@ -1 +1 @@
-2.7.1
+2.7.2
diff --git a/lib/quby/compiler/entities/subscore_schema.rb b/lib/quby/compiler/entities/subscore_schema.rb
index b265898..ec16fc3 100644
--- a/lib/quby/compiler/entities/subscore_schema.rb
+++ b/lib/quby/compiler/entities/subscore_schema.rb
@@ -16,7 +16,8 @@ module Quby
         attribute :calculation_key?, Types::Symbol
         # [Optional argument] The name of the outcome table where this subscore should be shown. Used for cases where scores
         # differ in subscores too much to be shown as one table. By default, all scores end up in the `:main` table.
-        attribute :outcome_table, Types::Symbol.default(:main).meta(omittable: true)
+        # When outcome_table is explicitly nil, the value should not be shown in outcome tables
+        attribute :outcome_table, Types::Symbol.optional.default(:main)
       end
     end
   end
diff --git a/lib/quby/compiler/outputs/roqua_serializer.rb b/lib/quby/compiler/outputs/roqua_serializer.rb
index 4fb8565..bf03072 100644
--- a/lib/quby/compiler/outputs/roqua_serializer.rb
+++ b/lib/quby/compiler/outputs/roqua_serializer.rb
@@ -91,6 +91,7 @@ module Quby
           
           questionnaire.score_schemas.values.each do |schema|
             schema.subscore_schemas.each do |subschema|
+              next if subschema.outcome_table.blank?
               tables[subschema.outcome_table][:subscore_keys] << subschema.key
               tables[subschema.outcome_table][:score_keys] << schema.key
               headers[subschema.key] = subschema.label
diff --git a/spec/quby/compiler/outputs/roqua_serializer_spec.rb b/spec/quby/compiler/outputs/roqua_serializer_spec.rb
index 44c57b0..47f0a85 100644
--- a/spec/quby/compiler/outputs/roqua_serializer_spec.rb
+++ b/spec/quby/compiler/outputs/roqua_serializer_spec.rb
@@ -32,8 +32,19 @@ describe Quby::Compiler::Outputs::RoquaSerializer do
           1
         end
       end
+
+      score_schema :score4, 'Score 4' do
+        subscore :value, 'Waarde', export_key: :score4, outcome_table: nil do
+          2
+        end
+        subscore :mean, 'Gemiddelde', export_key: :score4_m, outcome_table: :means do
+          1
+        end
+      end
     end
+
     serializer = described_class.new(questionnaire)
+
     expect(serializer.as_json).to \
       include({
                 outcome_tables_schema: {
@@ -41,7 +52,7 @@ describe Quby::Compiler::Outputs::RoquaSerializer do
                   tables: {
                     main: {:score_keys => [:score0], :subscore_keys => [:something]},
                     values: {:score_keys => [:score1, :score2], :subscore_keys => [:value, :int]},
-                    means: {:score_keys => [:score3], :subscore_keys => [:mean]}
+                    means: {:score_keys => [:score3, :score4], :subscore_keys => [:mean]}
                   }
                 }
               })
-- 
GitLab