Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KG - Fulfillment Synchronization Report Script V1 #1766

Merged
merged 1 commit into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/models/arm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class Arm < ApplicationRecord
has_many :sub_service_requests, through: :line_items
has_many :visits, :through => :line_items_visits

########################
### CWF Associations ###
########################

has_many :fulfillment_arms, class_name: 'Shard::Fulfillment::Arm', foreign_key: :sparc_id

after_create :create_calendar_objects, if: Proc.new { |arm| arm.protocol.present? }
after_update :update_visit_groups
after_update :update_liv_subject_counts
Expand Down
6 changes: 6 additions & 0 deletions app/models/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class LineItem < ApplicationRecord
has_many :arms, through: :line_items_visits
has_one :protocol, through: :service_request

########################
### CWF Associations ###
########################

has_many :fulfillment_line_items, -> { order(:arm_id) }, class_name: 'Shard::Fulfillment::LineItem', foreign_key: :sparc_id

attr_accessor :pricing_scheme

accepts_nested_attributes_for :fulfillments, allow_destroy: true
Expand Down
4 changes: 3 additions & 1 deletion app/models/line_items_visit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ class LineItemsVisit < ApplicationRecord

belongs_to :arm
belongs_to :line_item

has_many :visits, :dependent => :destroy
has_many :ordered_visits, -> { ordered }, class_name: "Visit"
has_many :notes, as: :notable, dependent: :destroy

has_many :visit_groups, through: :visits

has_one :service_request, through: :line_item
has_one :sub_service_request, through: :line_item
has_one :service, through: :line_item
has_many :visit_groups, through: :visits

validate :subject_count_valid
validate :pppv_line_item
Expand Down
8 changes: 8 additions & 0 deletions app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class Protocol < ApplicationRecord
has_many :identities, through: :project_roles
has_many :services, through: :service_requests
has_many :line_items, through: :service_requests
has_many :line_items_visits, through: :arms
has_many :visit_groups, through: :arms
has_many :visits, through: :arms
has_many :organizations, through: :sub_service_requests
has_many :study_type_questions, through: :study_type_question_group
has_many :responses, through: :sub_service_requests
Expand All @@ -64,6 +67,11 @@ class Protocol < ApplicationRecord
has_many :coordinators, -> { where(project_roles: { role: 'research-assistant-coordinator' }) },
source: :identity, through: :project_roles

########################
### CWF Associations ###
########################

has_many :fulfillment_protocols, class_name: 'Shard::Fulfillment::Protocol', foreign_key: :sparc_id

validates :research_master_id, numericality: { only_integer: true }, allow_blank: true
validates :research_master_id, presence: true, if: :rmid_requires_validation?
Expand Down
38 changes: 38 additions & 0 deletions app/models/shard/fulfillment/arm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright © 2011-2019 MUSC Foundation for Research Development~
# All rights reserved.~

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:~

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.~

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following~
# disclaimer in the documentation and/or other materials provided with the distribution.~

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products~
# derived from this software without specific prior written permission.~

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,~
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT~
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL~
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS~
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR~
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.~

module Shard
module Fulfillment
class Arm < Shard::Fulfillment::Base
self.table_name = 'arms'

belongs_to :protocol

has_many :line_items
has_many :visit_groups

##########################
### SPARC Associations ###
##########################

belongs_to :sparc_arm, class_name: '::Arm', foreign_key: :sparc_id
end
end
end
40 changes: 40 additions & 0 deletions app/models/shard/fulfillment/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright © 2011-2019 MUSC Foundation for Research Development~
# All rights reserved.~

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:~

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.~

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following~
# disclaimer in the documentation and/or other materials provided with the distribution.~

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products~
# derived from this software without specific prior written permission.~

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,~
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT~
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL~
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS~
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR~
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.~

module Shard
module Fulfillment
class Base < ApplicationRecord
self.abstract_class = true
establish_connection(FULFILLMENT_DB)

def self.inherited(child)
child.establish_connection(FULFILLMENT_DB)
super
end

# Allow queries (in particular, JOINs) across both SPARC and
# CWF databases by explicitly prefixing the appropriate CWF
# database name to tables belonging to it.
def self.table_name_prefix
FULFILLMENT_DB["database"] + '.'
end
end
end
end
29 changes: 29 additions & 0 deletions app/models/shard/fulfillment/fulfillment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright © 2011-2019 MUSC Foundation for Research Development~
# All rights reserved.~

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:~

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.~

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following~
# disclaimer in the documentation and/or other materials provided with the distribution.~

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products~
# derived from this software without specific prior written permission.~

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,~
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT~
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL~
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS~
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR~
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.~

module Shard
module Fulfillment
class Fulfillment < Shard::Fulfillment::Base
self.table_name = 'fulfillments'

belongs_to :line_item
end
end
end
57 changes: 57 additions & 0 deletions app/models/shard/fulfillment/line_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright © 2011-2019 MUSC Foundation for Research Development~
# All rights reserved.~

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:~

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.~

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following~
# disclaimer in the documentation and/or other materials provided with the distribution.~

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products~
# derived from this software without specific prior written permission.~

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,~
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT~
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL~
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS~
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR~
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.~

module Shard
module Fulfillment
class LineItem < Shard::Fulfillment::Base
self.table_name = 'line_items'

belongs_to :arm

has_many :fulfillments
has_many :visits, -> { joins(:visit_group).order('visit_groups.position') }

has_many :procedures, through: :visits

##########################
### SPARC Associations ###
##########################

belongs_to :sparc_line_item, class_name: '::LineItem', foreign_key: :sparc_id
belongs_to :sparc_service, class_name: '::Service', foreign_key: :service_id

def one_time_fee?
self.sparc_line_item.one_time_fee?
end

def fulfilled?
if self.one_time_fee?
self.fulfillments.any?
else
self.procedures.where(status: %w(complete incomplete follow_up)).any?
end
end

def deleted?
self.deleted_at.present?
end
end
end
end
29 changes: 29 additions & 0 deletions app/models/shard/fulfillment/procedure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright © 2011-2019 MUSC Foundation for Research Development~
# All rights reserved.~

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:~

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.~

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following~
# disclaimer in the documentation and/or other materials provided with the distribution.~

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products~
# derived from this software without specific prior written permission.~

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,~
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT~
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL~
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS~
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR~
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.~

module Shard
module Fulfillment
class Procedure < Shard::Fulfillment::Base
self.table_name = 'procedures'

belongs_to :visit
end
end
end
38 changes: 38 additions & 0 deletions app/models/shard/fulfillment/protocol.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright © 2011-2019 MUSC Foundation for Research Development~
# All rights reserved.~

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:~

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.~

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following~
# disclaimer in the documentation and/or other materials provided with the distribution.~

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products~
# derived from this software without specific prior written permission.~

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,~
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT~
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL~
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS~
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR~
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.~

module Shard
module Fulfillment
class Protocol < Shard::Fulfillment::Base
self.table_name = 'protocols'

has_many :arms
has_many :pppv_line_items, -> { includes(:service).where(services: { one_time_fee: false }) }
has_many :otf_line_items, -> { includes(:service).where(services: { one_time_fee: true }) }

##########################
### SPARC Associations ###
##########################

belongs_to :sparc_protocol, class_name: '::Protocol', foreign_key: :sparc_id
belongs_to :sparc_sub_service_request, class_name: '::SubServiceRequest', foreign_key: :sub_service_request_id
end
end
end
36 changes: 36 additions & 0 deletions app/models/shard/fulfillment/visit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright © 2011-2019 MUSC Foundation for Research Development~
# All rights reserved.~

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:~

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.~

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following~
# disclaimer in the documentation and/or other materials provided with the distribution.~

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products~
# derived from this software without specific prior written permission.~

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,~
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT~
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL~
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS~
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR~
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.~

module Shard
module Fulfillment
class Visit < Shard::Fulfillment::Base
self.table_name = 'visits'

belongs_to :line_item
belongs_to :visit_group

##########################
### SPARC Associations ###
##########################

belongs_to :sparc_visit, class_name: '::Visit', foreign_key: :sparc_id
end
end
end
37 changes: 37 additions & 0 deletions app/models/shard/fulfillment/visit_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright © 2011-2019 MUSC Foundation for Research Development~
# All rights reserved.~

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:~

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.~

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following~
# disclaimer in the documentation and/or other materials provided with the distribution.~

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products~
# derived from this software without specific prior written permission.~

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,~
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT~
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL~
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS~
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR~
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.~

module Shard
module Fulfillment
class VisitGroup < Shard::Fulfillment::Base
self.table_name = 'visit_groups'

belongs_to :arm

has_many :visits

##########################
### SPARC Associations ###
##########################

belongs_to :sparc_visit_group, class_name: '::VisitGroup', foreign_key: :sparc_id
end
end
end
6 changes: 6 additions & 0 deletions app/models/visit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class Visit < ApplicationRecord
has_one :service, through: :line_item
has_one :sub_service_request, through: :line_item

########################
### CWF Associations ###
########################

has_many :fulfillment_visits, class_name: 'Shard::Fulfillment::Visit', foreign_key: :sparc_id

validates :research_billing_qty, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :insurance_billing_qty, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :effort_billing_qty, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
Expand Down