Skip to content

Commit

Permalink
Merge pull request #193 from sparc-request/ac-klok-import
Browse files Browse the repository at this point in the history
Ac klok import
  • Loading branch information
amcates committed Aug 9, 2016
2 parents 465ed04 + 5327df2 commit b9ff271
Show file tree
Hide file tree
Showing 14 changed files with 373 additions and 33 deletions.
11 changes: 11 additions & 0 deletions app/assets/javascripts/bootstrap-table-custom.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@ getOrder = ->

pastDueDateCleaner = (a) ->
return a.replace(" - PAST DUE", "").replace("<span class=\"overdue-task\">", "").replace("</span>", "")

(exports ? this).fulfillmentDateSorter = (a, b) ->
sort_a = new Date(fulfillmentDateCleaner(a))
sort_b = new Date(fulfillmentDateCleaner(b))

return 1 if sort_a > sort_b
return -1 if sort_a < sort_b
return 0

fulfillmentDateCleaner = (a) ->
return a.replace('<span class="fulfillment_date_for_klok_entry">', '').replace('</span><i class="glyphicon glyphicon-time"></i>', '')
9 changes: 8 additions & 1 deletion app/assets/stylesheets/study_level_activities.sass
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ td.wrap
word-break: break-all

.center-block
text-align: center
text-align: center

.fulfillment-date-for-klok-entry
margin: 0 5px

#fulfillment-klok-description
margin-top: 10px
text-align: center
13 changes: 11 additions & 2 deletions app/helpers/study_level_activities_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,22 @@ def fulfillment_options_buttons fulfillment
raw content_tag(:div, button + ul, class: 'btn-group')
end

def fulfillment_date_formatter fulfillment
if fulfillment.klok_entry_id.present? # this was imported from klok
content_tag(:span, format_date(fulfillment.fulfilled_at), class: 'fulfillment-date-for-klok-entry') +
content_tag(:i, '', class: 'glyphicon glyphicon-time')
else
format_date(fulfillment.fulfilled_at)
end
end

private

def note_list_item params
content_tag(:li, raw(
content_tag(:button,
content_tag(:button,
raw(content_tag(:span, '', class: "glyphicon glyphicon-list-alt #{params[:span_class].nil? ? "" : params[:span_class]} #{params[:has_notes] ? "blue-notes" : ""}", aria: {hidden: "true"}))+
' Notes', type: 'button', class: 'btn btn-default #{params[:button_class].nil? ? "" : params[:button_class]} form-control actions-button notes list', data: {notable_id: params[:object].id, notable_type: params[:object].class.name}))
)
end
end
end
33 changes: 33 additions & 0 deletions app/models/concerns/klok_shard.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'active_support/concern'

module KlokShard

extend ActiveSupport::Concern

included do

octopus_establish_connection(Octopus.config[Rails.env][:klok])

allow_shard :klok

def self.inherited(child)
child.octopus_establish_connection Octopus.config[Rails.env][:klok]
super
end

def readonly?
Rails.env.production?
end

def self.klok_record?
true
end

# Allow queries (in particular, JOINs) across both Klok and
# CWF databases by explicitly prefixing the appropriate Klok
# database name to tables belonging to it.
def self.table_name_prefix
Octopus.config[Rails.env][:klok][:database] + '.'
end
end
end
44 changes: 44 additions & 0 deletions app/models/klok/entry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class Klok::Entry < ActiveRecord::Base
include KlokShard

self.primary_key = 'entry_id'

belongs_to :klok_person, class_name: 'Klok::Person', foreign_key: :resource_id
belongs_to :klok_project, class_name: 'Klok::Project', foreign_key: :project_id
has_one :service, through: :klok_project

delegate :local_protocol,
to: :klok_project,
allow_nil: true

delegate :local_identity,
to: :klok_person,
allow_nil: true

def start_time_stamp=(value)
super(DateTime.strptime(value,'%Q'))
end

def end_time_stamp=(value)
super(DateTime.strptime(value,'%Q'))
end

def rounded_duration
minutes = duration/60000.0
(minutes/15.0).ceil * 15.0
end

def decimal_duration
rounded_duration/60.0
end

def is_valid?
self.klok_project.present? &&
self.klok_project.ssr_id &&
self.klok_project.ssr_id.match(/\d\d\d\d-\d\d\d\d/) &&
self.local_protocol.present? &&
self.service.present? &&
self.klok_person.present? &&
self.local_identity.present?
end
end
15 changes: 15 additions & 0 deletions app/models/klok/person.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Klok::Person < ActiveRecord::Base
include KlokShard

self.primary_key = 'resource_id'

has_many :klok_entries, class_name: 'Klok::Entry', foreign_key: :resource_id
has_many :klok_projects, class_name: 'Klok::Project', foreign_key: :resource_id, through: :klok_entries

def local_identity
ldap_uid = name.split(" ").last.gsub(/[\(\)]*/, '')
ldap_uid += "@musc.edu" #### TODO, update Klok so that @musc.edu is added
Identity.where(ldap_uid: ldap_uid).first
end

end
20 changes: 20 additions & 0 deletions app/models/klok/project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Klok::Project < ActiveRecord::Base
include KlokShard

self.primary_key = 'project_id'

has_many :klok_entries, class_name: 'Klok::Entry', foreign_key: :project_id
has_many :klok_people, class_name: 'Klok::Person', foreign_key: :resource_id, through: :klok_entries
belongs_to :parent_project, class_name: 'Klok::Project', foreign_key: :parent_id
has_many :child_projects, class_name: 'Klok::Project', foreign_key: :parent_id
belongs_to :service, foreign_key: :code

def ssr_id
parent_project.try(:code) || code
end

def local_protocol
sparc_id, ssr_version = ssr_id.split('-')
Protocol.where(sparc_id: sparc_id).select{|p| p.sub_service_request.ssr_id == ssr_version}.first
end
end
4 changes: 2 additions & 2 deletions app/views/fulfillments/_fulfillment.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
json.(fulfillment)

json.id fulfillment.id
json.fulfillment_date format_date(fulfillment.fulfilled_at)
json.fulfillment_date fulfillment_date_formatter(fulfillment)
json.quantity fulfillment.quantity
json.quantity_type fulfillment.line_item.quantity_type
json.performed_by fulfillment.performer.full_name if fulfillment.performer
json.components fulfillment_components_dropdown(fulfillment.components)
json.options fulfillment_options_buttons(fulfillment)
json.options fulfillment_options_buttons(fulfillment)
40 changes: 21 additions & 19 deletions app/views/study_level_activities/_fulfillments_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,29 @@
%h4.modal-title.text-center
= header_text
.modal-body
%td{colspan: 11}
.bootstrap-table-dropdown-overflow
#fulfillment-custom-toolbar
%table.fulfillments{id: "fulfillments-table", data: {toggle: 'table', search: "true", "show-columns" => "true", "show-refresh" => "true", "show-toggle" => "true", url: fulfillments_path(format: :json, line_item_id: line_item.id), striped: "true", toolbar: "#fulfillment-custom-toolbar", "show-export" => "true", "export-types" => ['excel']}}
%thead.secondary-header
%tr
%th{data: {class: 'fulfillment_date', align: "left", sortable: 'true', sorter: "dateSorter", field: "fulfillment_date"}}
= t(:fulfillment)[:fulfillment_date]
%th{data: {class: 'quantity', align: "left", sortable: 'true', field: "quantity"}}
= t(:fulfillment)[:quantity]
%th{data: {class: 'qty_type', align: "left", sortable: 'true', field: "quantity_type"}}
= t(:fulfillment)[:qty_type]
%th{data: {class: 'performed_by', align: "left", sortable: 'true', field: "performed_by"}}
= t(:fulfillment)[:performed_by]
%th{data: {class: 'components', align: "center", field: "components"}}
= t(:fulfillment)[:components]
%th{data: {class: 'options', align: "center", field: "options"}}
= t(:actions)[:actions]
.bootstrap-table-dropdown-overflow
#fulfillment-custom-toolbar
%table.fulfillments{id: "fulfillments-table", data: {toggle: 'table', search: "true", "show-columns" => "true", "show-refresh" => "true", "show-toggle" => "true", url: fulfillments_path(format: :json, line_item_id: line_item.id), striped: "true", toolbar: "#fulfillment-custom-toolbar", "show-export" => "true", "export-types" => ['excel']}}
%thead.secondary-header
%tr
%th{data: {class: 'fulfillment_date', align: "left", sortable: 'true', sorter: "fulfillmentDateSorter", field: "fulfillment_date"}}
= t(:fulfillment)[:fulfillment_date]
%th{data: {class: 'quantity', align: "left", sortable: 'true', field: "quantity"}}
= t(:fulfillment)[:quantity]
%th{data: {class: 'qty_type', align: "left", sortable: 'true', field: "quantity_type"}}
= t(:fulfillment)[:qty_type]
%th{data: {class: 'performed_by', align: "left", sortable: 'true', field: "performed_by"}}
= t(:fulfillment)[:performed_by]
%th{data: {class: 'components', align: "center", field: "components"}}
= t(:fulfillment)[:components]
%th{data: {class: 'options', align: "center", field: "options"}}
= t(:actions)[:actions]
#fulfillment-klok-description
%i{class: 'glyphicon glyphicon-time'}
%span= t(:fulfillment)[:klok_description]
.modal-footer
.center-block
%button.btn.btn-default{type: 'button', data: {dismiss: 'modal'}}
= t(:actions)[:close]
%button.btn.btn-success.otf_fulfillment_new{type: "button", "aria-label" => "Add Fulfillment", data: {line_item_id: line_item.id}}
= t(:fulfillment)[:add_fulfillment]
= t(:fulfillment)[:add_fulfillment]
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ en:
quantity: "Quantity"
save_fulfillment: "Save Fulfillment"
view: "View Fulfillment Buttons"
klok_description: "Imported via Klok"

multiple_procedures_modal:
incomplete_header: "Incomplete Multiple Services"
Expand Down
107 changes: 107 additions & 0 deletions db/klok.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
-- MySQL dump 10.13 Distrib 5.7.12, for osx10.11 (x86_64)
--
-- Host: localhost Database: klok_development
-- ------------------------------------------------------
-- Server version 5.7.12

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `entries`
--

DROP TABLE IF EXISTS `entries`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `entries` (
`created_at` timestamp NULL DEFAULT NULL,
`project_id` int(11) NOT NULL,
`resource_id` int(11) DEFAULT NULL,
`rate` int(11) DEFAULT NULL,
`date` date DEFAULT NULL,
`start_time_stamp_formatted` varchar(255) DEFAULT NULL,
`start_time_stamp` timestamp NULL DEFAULT NULL,
`entry_id` int(11) NOT NULL,
`duration` int(11) DEFAULT NULL,
`submission_id` int(11) DEFAULT NULL,
`device_id` int(11) DEFAULT NULL,
`comments` text,
`end_time_stamp_formatted` varchar(255) DEFAULT NULL,
`end_time_stamp` timestamp NULL DEFAULT NULL,
`rollup_to` int(11) DEFAULT NULL,
PRIMARY KEY (`entry_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `people`
--

DROP TABLE IF EXISTS `people`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `people` (
`resource_id` int(11) NOT NULL,
`name` varchar(255) DEFAULT NULL,
`username` varchar(255) DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`resource_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `projects`
--

DROP TABLE IF EXISTS `projects`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `projects` (
`contact_email` varchar(255) DEFAULT NULL,
`project_id` int(11) NOT NULL,
`path` int(11) DEFAULT NULL,
`code` varchar(255) DEFAULT NULL,
`contact_phone` varchar(255) DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`project_type` varchar(255) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`parent_id` int(11) DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`contact_name` varchar(255) DEFAULT NULL,
`rollup_to` int(11) DEFAULT NULL,
PRIMARY KEY (`project_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `schema_migrations`
--

DROP TABLE IF EXISTS `schema_migrations`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `schema_migrations` (
`version` varchar(255) NOT NULL,
UNIQUE KEY `unique_schema_migrations` (`version`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2016-07-11 17:43:07
6 changes: 6 additions & 0 deletions db/migrate/20160707010804_add_klok_entry_id_to_line_items.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddKlokEntryIdToLineItems < ActiveRecord::Migration
def change
add_column :fulfillments, :klok_entry_id, :integer
add_index :fulfillments, :klok_entry_id
end
end
19 changes: 10 additions & 9 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160527165249) do
ActiveRecord::Schema.define(version: 20160707010804) do

create_table "appointment_statuses", force: :cascade do |t|
t.string "status", limit: 255
Expand Down Expand Up @@ -104,18 +104,19 @@
add_index "documents", ["documentable_id", "documentable_type"], name: "index_documents_on_documentable_id_and_documentable_type", using: :btree

create_table "fulfillments", force: :cascade do |t|
t.integer "sparc_id", limit: 4
t.integer "line_item_id", limit: 4
t.integer "sparc_id", limit: 4
t.integer "line_item_id", limit: 4
t.datetime "fulfilled_at"
t.decimal "quantity", precision: 10, scale: 2
t.decimal "quantity", precision: 10, scale: 2
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "deleted_at"
t.integer "creator_id", limit: 4
t.integer "performer_id", limit: 4
t.integer "service_id", limit: 4
t.string "service_name", limit: 255
t.integer "service_cost", limit: 4
t.integer "creator_id", limit: 4
t.integer "performer_id", limit: 4
t.integer "service_id", limit: 4
t.string "service_name", limit: 255
t.integer "service_cost", limit: 4
t.integer "klok_entry_id", limit: 4
end

add_index "fulfillments", ["creator_id"], name: "index_fulfillments_on_creator_id", using: :btree
Expand Down

0 comments on commit b9ff271

Please sign in to comment.