Skip to content

Instantly share code, notes, and snippets.

@klippx
klippx / detect_bad_item_rows
Last active August 29, 2015 13:59
detect offline sync up item rows that may need to be deleted
def detect_bad_item_rows(input)
ids = []
input.each_with_index do |data, i|
if source = data["source_attributes"]
if rows = source["row_attributes"]
rows.each_with_index do |r, j|
if r["type"] == "ItemRow" && r["mandatory"] == false && r.keys.count == 3
ids << {array_index: i, row_attributes_index: j}
end
end
@klippx
klippx / diagnoses_belongs_to_me.rb
Created August 27, 2014 13:40
All your diagnoses are belong to me
def diagnoses_belongs_to_me
diagnoses_ids = []
rows_array = form.rows.to_a[0...self.position - 1].reverse
rows_array.each do |r|
next if r.id == self.id
break if r.kind_of?(Journal::FormRow::ItemRow) or (r.kind_of?(Journal::FormRow::LabSampleRow) and r.billing_record_rows.any?)
if r.kind_of?(Journal::FormRow::DiagnosisRow) && r.diagnosis_id
diagnoses_ids << r.diagnosis_id
@klippx
klippx / development.log
Created June 1, 2015 09:53
Sample output of Api::PouchOrdersController#index
=> Booting Thin
=> Rails 4.2.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on localhost:3000, CTRL+C to stop
Started GET "/" for 127.0.0.1 at 2015-06-01 11:49:34 +0200
@klippx
klippx / delete_pol.log
Created June 4, 2015 14:25
Deletear pouch order lines
2202 I, [2015-06-04T13:51:11.230236 #8457] INFO -- : Started GET "/labels/232.pdf" for 213.180.87.134 at 2015-06-04 13:51:11 +0200
2203 I, [2015-06-04T13:51:11.237208 #8457] INFO -- : Processing by LabelsController#show as PDF
2204 I, [2015-06-04T13:51:11.237313 #8457] INFO -- : Parameters: {"id"=>"232"}
2205 D, [2015-06-04T13:51:11.240117 #8457] DEBUG -- : User Load (0.7ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 42 ORDER BY `users`.`id` ASC LIMIT 1
2206 D, [2015-06-04T13:51:11.261844 #8457] DEBUG -- : TransportLabel Load (16.6ms) SELECT `transport_labels`.* FROM `transport_labels` WHERE `transport_labels`.`id` = 232 LIMIT 1
2207 D, [2015-06-04T13:51:11.277864 #8457] DEBUG -- : Address Load (0.7ms) SELECT `addresses`.* FROM `addresses` WHERE `addresses`.`owner_id` = 232 AND `addresses`.`owner_type` = 'TransportLabel' LIMIT 1
2208 I, [2015-06-04T13:51:11.297387 #8457] INFO -- : ***************WICKED***************
2209 D, [2015-06-04T13:51:11.461020 #8457]
@klippx
klippx / pouch_order.rb
Created July 2, 2015 06:49
1. Original version
# A pouch order is ordered to a ward for a patient from a prescriber. These
# will be produces as pouches through the HD-Medi system.
class PouchOrder < ActiveRecord::Base
include Workflow
belongs_to :ward
belongs_to :patient
belongs_to :file, class_name: 'MachineFile', foreign_key: 'machine_file_id'
belongs_to :transport_label
@klippx
klippx / pouch_order.rb
Created July 2, 2015 06:50
Final result: Pouch Order
# A pouch order is ordered to a ward for a patient from a prescriber. These
# will be produces as pouches through the HD-Medi system.
class PouchOrder < ActiveRecord::Base
# Workflow is handled in library module
include PouchOrder::WorkflowManager
include DatetimeChange
belongs_to :ward
belongs_to :patient
@klippx
klippx / workflow_manager.rb
Created July 2, 2015 06:53
Final result: PouchOrder::WorkflowManager
module PouchOrder::WorkflowManager
extend ActiveSupport::Concern
included do
include Workflow
workflow_column :status
workflow do
state :new do
event :receive, transitions_to: :received
@klippx
klippx / from_attachment.rb
Created July 2, 2015 06:55
Final result: FromAttachment
class PouchOrder::FromAttachment
include DatetimeChange
def initialize(attachment: attachment)
@attachment = attachment
@pouch_order = PouchOrder.new(
number: @attachment.header.order_number,
phone_number: @attachment.contact_telephone,
issued_at: @attachment.issued_at,
delivery_at: @attachment.delivery_at,
@klippx
klippx / gist:a119fcb8225bd9df46f4941562572040
Created November 15, 2017 16:14
Running spec/lib/phobos/listener_spec.rb:54 with ruby kafka 0.4.4
## With ruby kafka 0.4.4
#
~  src  phobos  debug-0.5.x-issues  ✎  docker-compose run -e DEFAULT_TIMEOUT=30 --rm test rspec spec/lib/phobos/listener_spec.rb:54
Starting phobos_zookeeper_1 ... done
Starting phobos_kafka_1 ... done
Run options: include {:locations=>{"./spec/lib/phobos/listener_spec.rb"=>[54]}}
Randomized with seed 16222
Phobos::Listener
@klippx
klippx / gist:0ca38936059118ecbd8d701b9d7ddb3d
Created November 15, 2017 16:15
Running spec/lib/phobos/listener_spec.rb:54 with ruby kafka 0.5.1
## With Ruby kafka 0.5.1
#
~  src  phobos  debug-0.5.x-issues  docker-compose run -e DEFAULT_TIMEOUT=30 --rm test rspec spec/lib/phobos/listener_spec.rb:54
Starting phobos_zookeeper_1 ... done
Starting phobos_kafka_1 ... done
Run options: include {:locations=>{"./spec/lib/phobos/listener_spec.rb"=>[54]}}
Randomized with seed 7064
Phobos::Listener