repo
stringlengths
5
92
file_url
stringlengths
80
287
file_path
stringlengths
5
197
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:37:27
2026-01-04 17:58:21
truncated
bool
2 classes
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segment_generator.rb
lib/segment_generator.rb
# frozen_string_literal: true # Class for grouping the messages delimiter class HL7::Message::Delimiter attr_accessor :item, :element, :segment def initialize(element_delim, item_delim, segment_delim) @element = element_delim @item = item_delim @segment = segment_delim end end # Methods for creating segments in Message class HL7::Message::SegmentGenerator attr_reader :element, :last_seg, :delimiter attr_accessor :seg_parts, :seg_name def initialize(element, last_seg, delimiter) @element = element @last_seg = last_seg @delimiter = delimiter @seg_parts = HL7::MessageParser.split_by_delimiter(element, delimiter.element) end def valid_segments_parts? return true if @seg_parts&.length&.positive? raise HL7::EmptySegmentNotAllowed if HL7.configuration.empty_segment_is_error false end def build klass = get_segment_class klass.new(@element, [@delimiter.element, @delimiter.item]) end def get_segment_class segment_to_search = @seg_name.to_sym segment_to_search = @seg_name if RUBY_VERSION < "1.9" if HL7::Message::Segment.constants.index(segment_to_search) eval(format("HL7::Message::Segment::%s", @seg_name)) else HL7::Message::Segment::Default end end end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/ruby-hl7.rb
lib/ruby-hl7.rb
# frozen_string_literal: true #= ruby-hl7.rb # Ruby HL7 is designed to provide a simple, easy to use library for # parsing and generating HL7 (2.x) messages. # # # Author: Mark Guzman (mailto:segfault@hasno.info) # # Copyright: (c) 2006-2009 Mark Guzman # # License: BSD # # $Id$ # # == License # see the LICENSE file # require "rubygems" require "stringio" require "date" require "configuration" require "helpers/time_formatter_helper" module HL7 # :nodoc: # Gives access to the current Configuration. def self.configuration @configuration ||= Configuration.new end # Allows easy setting of multiple configuration options. See Configuration # for all available options. def self.configure config = configuration yield(config) end end # Encapsulate HL7 specific exceptions class HL7::Exception < StandardError end # Parsing failed class HL7::ParseError < HL7::Exception end # Attempting to use an invalid indice class HL7::RangeError < HL7::Exception end # Attempting to assign invalid data to a field class HL7::InvalidDataError < HL7::Exception end # Attempting to add an empty segment # This error per configuration setting class HL7::EmptySegmentNotAllowed < HL7::ParseError end require "message_parser" require "message" require "segment_list_storage" require "segment_generator" require "segment_fields" require "segment" require "segment_default" require "core_ext/date_time" require "core_ext/string"
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segment.rb
lib/segment.rb
# frozen_string_literal: true # Ruby Object representation of an hl7 2.x message segment # The segments can be setup to provide aliases to specific fields with # optional validation code that is run when the field is modified # The segment field data is also accessible via the e<number> method. # # == Defining a New Segment # class HL7::Message::Segment::NK1 < HL7::Message::Segment # weight 100 # segments are sorted ascendingly # add_field :something_you_want # assumes :idx=>1 # add_field :something_else, :idx=>6 # :idx=>6 and field count=6 # add_field :something_more # :idx=>7 # add_field :block_example do |value| # raise HL7::InvalidDataError.new # unless value.to_i < 100 && value.to_i > 10 # return value # end # # this block will be executed when seg.block_example= is called # # and when seg.block_example is called # class HL7::Message::Segment extend HL7::Message::SegmentListStorage extend TimeFormatterHelper include HL7::Message::SegmentFields attr_accessor :segment_parent attr_reader :element_delim, :item_delim, :segment_weight METHOD_MISSING_FOR_INITIALIZER = <<-END def method_missing( sym, *args, &blk ) __seg__.send( sym, args, blk ) end END # setup a new HL7::Message::Segment # raw_segment:: is an optional String or Array which will be used as the # segment's field data # delims:: an optional array of delimiters, where # delims[0] = element delimiter # delims[1] = item delimiter def initialize(raw_segment = "", delims = [], &blk) @segments_by_name = {} @field_total = 0 @is_child = false setup_delimiters delims @elements = elements_from_segment(raw_segment) return unless block_given? callctx = eval("self", blk.binding, __FILE__, __LINE__) def callctx.__seg__(val = nil) @__seg_val__ ||= val end callctx.__seg__(self) # TODO: find out if this pollutes the calling namespace permanently... eval(METHOD_MISSING_FOR_INITIALIZER, blk.binding) yield self eval("class << self; remove_method :method_missing;end", blk.binding, __FILE__, __LINE__) end # Breaks the raw segment into elements # raw_segment:: is an optional String or Array which will be used as the # segment's field data def elements_from_segment(raw_segment) if raw_segment.is_a? Array elements = raw_segment else elements = HL7::MessageParser.split_by_delimiter(raw_segment, @element_delim) if raw_segment == "" elements[0] = self.class.to_s.split("::").last elements << "" end end elements end def to_info format("%s: empty segment >> %s", self.class.to_s, @elements.inspect) end # output the HL7 spec version of the segment def to_s @elements.join(@element_delim) end # at the segment level there is no difference between to_s and to_hl7 alias_method :to_hl7, :to_s # handle the e<number> field accessor # and any aliases that didn't get added to the system automatically def method_missing(sym, *args, &blk) base_str = sym.to_s.delete("=") base_sym = base_str.to_sym if self.class.fields.include?(base_sym) # base_sym is ok, let's move on elsif /e([0-9]+)/ =~ base_str # base_sym should actually be $1, since we're going by # element id number base_sym = $1.to_i else super end if sym.to_s.include?("=") write_field(base_sym, args) elsif args.length.positive? write_field(base_sym, args.flatten.select {|arg| arg }) else read_field(base_sym) end end # sort-compare two Segments, 0 indicates equality def <=>(other) return nil unless other.is_a?(HL7::Message::Segment) # per Comparable docs: http://www.ruby-doc.org/core/classes/Comparable.html diff = weight - other.weight return -1 if diff.positive? return 1 if diff.negative? 0 end # get the defined sort-weight of this segment class # an alias for self.weight def weight self.class.weight end # return true if the segment has a parent def is_child_segment? (@is_child_segment ||= false) end # indicate whether or not the segment has a parent def is_child_segment=(val) @is_child_segment = val end # yield each element in the segment def each # :yields: element return unless @elements @elements.each { |e| yield e } end # get the length of the segment (number of fields it contains) def length 0 unless @elements @elements.length end def has_children? respond_to?(:children) end private def self.singleton # :nodoc: class << self; self end end def setup_delimiters(delims) delims = [delims].flatten @element_delim = delims.length.positive? ? delims[0] : "|" @item_delim = delims.length > 1 ? delims[1] : "^" end # DSL element to define a segment's sort weight # returns the segment's current weight by default # segments are sorted ascending def self.weight(new_weight = nil) if new_weight singleton.module_eval do @my_weight = new_weight end end singleton.module_eval do return 999 unless @my_weight @my_weight end end def self.convert_to_ts(value) # :nodoc: if value.is_a?(Time) || value.is_a?(DateTime) hl7_formatted_timestamp(value) elsif value.is_a?(Date) hl7_formatted_date(value) else value end end def self.sanitize_admin_sex!(value) raise HL7::InvalidDataError, "bad administrative sex value (not F|M|O|U|A|N|C)" unless /^[FMOUANC]$/.match(value) || value.nil? || value == "" value ||= "" value end end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/message.rb
lib/message.rb
# frozen_string_literal: true # Ruby Object representation of an hl7 2.x message # the message object is actually a "smart" collection of hl7 segments # == Examples # # ==== Creating a new HL7 message # # # create a message # msg = HL7::Message.new # # # create a MSH segment for our new message # msh = HL7::Message::Segment::MSH.new # msh.recv_app = "ruby hl7" # msh.recv_facility = "my office" # msh.processing_id = rand(10000).to_s # # msg << msh # add the MSH segment to the message # # puts msg.to_s # readable version of the message # # puts msg.to_hl7 # hl7 version of the message (as a string) # # puts msg.to_mllp # mllp version of the message (as a string) # # ==== Parse an existing HL7 message # # raw_input = open( "my_hl7_msg.txt" ).readlines # msg = HL7::Message.new( raw_input ) # # puts "message type: %s" % msg[:MSH].message_type # # class HL7::Message include Enumerable # we treat an hl7 2.x message as a collection of segments extend HL7::MessageBatchParser attr_reader :message_parser, :element_delim, :item_delim, :segment_delim, :delimiter # setup a new hl7 message # raw_msg:: is an optional object containing an hl7 message # it can either be a string or an Enumerable object def initialize(raw_msg = nil, &blk) @segments = [] @segments_by_name = {} @item_delim = "^" @element_delim = "|" @segment_delim = "\r" @delimiter = HL7::Message::Delimiter.new(@element_delim, @item_delim, @segment_delim) @message_parser = HL7::MessageParser.new(@delimiter) parse(raw_msg) if raw_msg return unless block_given? yield self end def parse(inobj) if inobj.is_a?(String) generate_segments(message_parser.parse_string(inobj)) elsif inobj.respond_to?(:each) generate_segments_enumerable(inobj) else raise HL7::ParseError, "object to parse should be string or enumerable" end end def generate_segments_enumerable(enumerable) enumerable.each do |segment| generate_segments(message_parser.parse_string(segment.to_s)) end end # access a segment of the message # index:: can be a Range, Integer or anything that # responds to to_sym def [](index) ret = nil if index.is_a?(Range) || index.is_a?(Integer) ret = @segments[index] elsif index.respond_to? :to_sym ret = @segments_by_name[index.to_sym] ret = ret.first if ret && ret.length == 1 end ret end # modify a segment of the message # index:: can be a Range, Integer or anything that # responds to to_sym # value:: an HL7::Message::Segment object def []=(index, value) unless value.is_a?(HL7::Message::Segment) raise HL7::Exception, "attempting to assign something other than an HL7 Segment" end if index.is_a?(Range) || index.is_a?(Integer) @segments[index] = value elsif index.respond_to?(:to_sym) (@segments_by_name[index.to_sym] ||= []) << value else raise HL7::Exception, "attempting to use an indice that is not a Range, Integer or to_sym providing object" end value.segment_parent = self end # return the index of the value if it exists, nil otherwise # value:: is expected to be a string def index(value) return nil unless value.respond_to?(:to_sym) segs = @segments_by_name[value.to_sym] return nil unless segs @segments.index(segs.to_a.first) end # add a segment or array of segments to the message # * will force auto set_id sequencing for segments containing set_id's def <<(value) # do nothing if value is nil return unless value if value.is_a? Array value.map {|item| append(item) } else append(value) end end def append(value) unless value.is_a?(HL7::Message::Segment) raise HL7::Exception, "attempting to append something other than an HL7 Segment" end value.segment_parent = self unless value.segment_parent (@segments ||= []) << value name = value.class.to_s.gsub("HL7::Message::Segment::", "").to_sym (@segments_by_name[name] ||= []) << value sequence_segments unless defined?(@parsing) && @parsing # let's auto-set the set-id as we go end # yield each segment in the message def each # :yields: segment return unless @segments @segments.each { |s| yield s } end # return the segment count def length 0 unless @segments @segments.length end # provide a screen-readable version of the message def to_s @segments.collect {|s| s if s.to_s.length.positive? }.join("\n") end # provide a HL7 spec version of the message def to_hl7 @segments.collect {|s| s if s.to_s.length.positive? }.join(@delimiter.segment) end # provide the HL7 spec version of the message wrapped in MLLP def to_mllp pre_mllp = to_hl7 "\v#{pre_mllp}\u001C\r" end # auto-set the set_id fields of any message segments that # provide it and have more than one instance in the message def sequence_segments(base = nil) last = nil segs = @segments segs = base.children if base segs.each do |s| if s.is_a?(last.class) && s.respond_to?(:set_id) last.set_id = 1 unless last.set_id&.to_i&.positive? s.set_id = last.set_id.to_i + 1 end sequence_segments(s) if s.has_children? last = s end end # Checks if any of the results is a correction def correction? Array(self[:OBX]).any?(&:correction?) end private def generate_segments(ary) raise HL7::ParseError, "no array to generate segments" unless ary.length.positive? @parsing = true segment_stack = [] ary.each do |elm| update_delimiters(elm) if elm.slice(0, 3) == "MSH" generate_segment(elm, segment_stack) end @parsing = nil end def update_delimiters(elm) @item_delim = message_parser.parse_item_delim(elm) @element_delim = message_parser.parse_element_delim(elm) @delimiter.item = @item_delim @delimiter.element = @element_delim end def generate_segment(elm, segment_stack) segment_generator = HL7::Message::SegmentGenerator.new(elm, segment_stack, @delimiter) return nil unless segment_generator.valid_segments_parts? segment_generator.seg_name = segment_generator.seg_parts[0] new_seg = segment_generator.build new_seg.segment_parent = self choose_segment_from(segment_stack, new_seg, segment_generator.seg_name) end def choose_segment_from(segment_stack, new_seg, seg_name) # Segments have been previously seen while segment_stack.length.positive? if segment_stack.last&.has_children? && segment_stack.last&.accepts?(seg_name) # If a previous segment can accept the current segment as a child, # add it to the previous segments children segment_stack.last.children << new_seg new_seg.is_child_segment = true segment_stack << new_seg break else segment_stack.pop end end # Root of segment 'tree' return unless segment_stack.empty? @segments << new_seg segment_stack << new_seg setup_segment_lookup_by_name(seg_name, new_seg) end # Allow segment lookup by name def setup_segment_lookup_by_name(seg_name, new_seg) seg_sym = get_symbol_from_name(seg_name) return unless seg_sym @segments_by_name[seg_sym] ||= [] @segments_by_name[seg_sym] << new_seg end def get_symbol_from_name(seg_name) seg_name.to_s.strip.length.positive? ? seg_name.to_sym : nil end end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/configuration.rb
lib/configuration.rb
# frozen_string_literal: true module HL7 # This class enables detailed configuration of the HL7 parser services. # # By calling # # HL7.configuration # => instance of HL7::Configuration # # or # HL7.configure do |config| # config # => instance of HL7::Configuration # end # # you are able to perform configuration updates. # # Setting the keys with this Configuration # # HL7.configure do |config| # config.empty_segment_is_error = false # end # class Configuration attr_accessor :empty_segment_is_error def initialize # :nodoc: @empty_segment_is_error = true end end end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segment_default.rb
lib/segment_default.rb
# frozen_string_literal: true # Provide a catch-all information preserving segment # * nb: aliases are not provided BUT you can use the numeric element accessor # # seg = HL7::Message::Segment::Default.new # seg.e0 = "NK1" # seg.e1 = "SOMETHING ELSE" # seg.e2 = "KIN HERE" # class HL7::Message::Segment::Default < HL7::Message::Segment def initialize(raw_segment = "", delims = []) segs = [] if raw_segment == "" segs ||= raw_segment super(segs, delims) end end # load our segments Dir["#{File.dirname(__FILE__)}/segments/*.rb"].each {|ext| load ext }
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/helpers/time_formatter_helper.rb
lib/helpers/time_formatter_helper.rb
# frozen_string_literal: true module TimeFormatterHelper class ValueTypeNotSupportedError < StandardError; end # Get an HL7 timestamp (type TS) for a Time or DateTime instance. # # fraction_digits:: specifies a number of digits of fractional seconds. # Its default value is 0. # hl7_formatted_timestamp(Time.parse('01:23')) # => "20091202012300" # hl7_formatted_timestamp(Time.now, 3) # => "20091202153652.302" def hl7_formatted_timestamp(value, fraction_digits = 0) raise ValueTypeNotSupportedError, "Value must be an instance of Time or DateTime" unless value.is_a?(Time) || value.is_a?(DateTime) value.strftime("%Y%m%d%H%M%S") + hl7_formatted_fractions(value, fraction_digits) end # Get an HL7 timestamp (type TS) for a Date instance. def hl7_formatted_date(value) raise ValueTypeNotSupportedError, "Value must be an instance of Date" unless value.is_a?(Date) value.strftime("%Y%m%d") end private def hl7_formatted_fractions(value, fraction_digits = 0) return "" unless fraction_digits.positive? time_fraction = if value.respond_to?(:usec) value.usec else value.sec_fraction.to_f * 1_000_000 end answer = ".#{format("%06d", time_fraction)}" answer += "0" * ((fraction_digits - 6)).abs if fraction_digits > 6 answer[0, 1 + fraction_digits] end end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/test/hl7_messages.rb
lib/test/hl7_messages.rb
# frozen_string_literal: true # Copyright (C) 2007, 2008, 2009, 2010 The Collaborative Software Foundation # # This file is part of TriSano. # # TriSano is free software: you can redistribute it and/or modify it under the # terms of the GNU Affero General Public License as published by the # Free Software Foundation, either version 3 of the License, # or (at your option) any later version. # # TriSano is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with TriSano. If not, see http://www.gnu.org/licenses/agpl-3.0.txt. HL7MESSAGES = {} def hl7_messages HL7MESSAGES end HL7MESSAGES[:arup_1] = <<~ARUP1 MSH|^~&|ARUP|ARUP LABORATORIES^46D0523979^CLIA|UTDOH|UT|200903261645||ORU^R01|200903261645128667|P|2.3.1|1\rPID|1||17744418^^^^MR||ZHANG^GEORGE^^^^^L||19830922|M||U^Unknown^HL70005|42 HAPPY LN^^SALT LAKE CITY^UT^84444^^M||^^PH^^^801^5552346|||||||||U^Unknown^HL70189\rORC||||||||||||^FARNSWORTH^MABEL^W|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBR|1||09078102377|13954-3^Hepatitis Be Antigen^LN|||200903191011|||||||200903191011|BLOOD|^FARNSWORTH^MABEL^W||||||200903191011|||F||||||9^Unknown\rOBX|1|ST|13954-3^Hepatitis Be Antigen^LN|1|Positive|Metric Ton|Negative||||F|||200903210007\r ARUP1 HL7MESSAGES[:unknown_observation_value] = <<~UNKNOWNOBSERVATIONVALUE MSH|^~&|ARUP|ARUP LABORATORIES^46D0523979^CLIA|UTDOH|UT|200903261645||ORU^R01|200903261645128667|P|2.3.1|1\rPID|1||17744418^^^^MR||ZHANG^GEORGE^^^^^L||19830922|M||U^Unknown^HL70005|42 HAPPY LN^^SALT LAKE CITY^UT^84444^^M||^^PH^^^801^5552346|||||||||U^Unknown^HL70189\rORC||||||||||||^FARNSWORTH^MABEL^W|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBR|1||09078102377|13954-3^Hepatitis Be Antigen^LN|||200903191011|||||||200903191011|BLOOD|^FARNSWORTH^MABEL^W||||||200903191011|||F||||||9^Unknown\rOBX|1|ST|13954-3^Hepatitis Be Antigen^LN|1|Scary||Negative||||F|||200903210007\r UNKNOWNOBSERVATIONVALUE HL7MESSAGES[:arup_2] = <<~ARUP2 MSH|^~&|ARUP|ARUP LABORATORIES^46D0523979^CLIA|UTDOH|UT|200903261645||ORU^R01|200903261645128673|P|2.3.1|1\rPID|1||16106551^^^^MR||HARKER^JONATHAN^P^^^^L||19650102|M||W^White^HL70005|1492 COLUMBUS CIR^^ATLANTIS^UT^84455^^M||^^PH^^^801^5558132|||||||||U^Unknown^HL70189\rORC||||||||||||^GOULD^HARRIET|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBR|1||09078110757|5221-7^HIV-1 Antibody Confirm, Western Blot^LN|||200903191514|||||||200903191514|X|^GOULD^HARRIET|||||||||F||||||9^Unknown\rOBX|1|ST|5221-7^HIV-1 Antibody Confirm, Western Blot^LN|1|Sick||||||F|||200903211440\rOBX|2|ST|13954-3^Hepatitis Be Antigen^LN|1|Very sick||Negative||||F|||200903210007\r ARUP2 # This is not a real message. The sample SPM segment from the Realm # document was simply inserted into the previous message in order to # provide a test message with an SPM segment. HL7MESSAGES[:arup_3] = <<~ARUP3 MSH|^~&|ARUP|ARUP LABORATORIES^46D0523979^CLIA|UTDOH|UT|200903261645||ORU^R01|200903261645128673|P|2.3.1|1\rPID|1||16106551^^^^MR||HARKER^JONATHAN^P^^^^L||19650102|M||W^White^HL70005|1492 COLUMBUS CIR^^ATLANTIS^UT^84455^^M||^^PH^^^801^5558132|||||||||U^Unknown^HL70189\rORC||||||||||||^GOULD^HARRIET|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBR|1||09078110757|5221-7^HIV-1 Antibody Confirm, Western Blot^LN|||200903191514|||||||200903191514|X|^GOULD^HARRIET|||||||||F||||||9^Unknown\rSPM|1|23456&EHR&2.16.840.1.113883.19.3.2.3&ISO^9700122&Lab&2.16.840.1.113883.19.3.1.6&ISO||WB^Whole Blood^HL70487^^^^^2.5.1||THYO^Thyoglycollate broth^HL70371^^^^2.5.1|BCAE^Blood Culture, Aerobic Bottle^HL70488^^^^2.5.1|49852007^Structure of median cubital vein (body structure)^SCT^^^^20080731|||P^Patient^HL60369^^^^2.5.1|2.0^mL&MilliLiter [SI Volume Units]&UCUM&&&&1.6|||||200808151030-0700|200808151100-0700\rOBX|1|ST|5221-7^HIV-1 Antibody Confirm, Western Blot^LN|1|Sick||||||F|||200903211440\rOBX|2|ST|13954-3^Hepatitis Be Antigen^LN|1|Very sick||Negative||||F|||200903210007\r ARUP3 HL7MESSAGES[:ihc_1] = <<~IHC1 MSH|^~&|RT-CEND|IHC-LD|||200902251217Z||ORU^R01||P|2.5\rPID|||362087||HARRIS^JOSEPH^R||196811040000Z|M||W|7755 E RTE 4501^^BARLOWE^UT^849320146^USA||(801)555-4412\rPV1||I||||||||MED|||||||||112750906~948223|||||||||||||||||||||||||200902181810Z\rOBR|1|||NOTF|||||||||||||||||||||||||||""^SNM\rOBX|1|TM|00000-0^ALERT DATE^LN||200902250930Z\rOBX|2|PN|00000-0^PROVIDER NAME^LN||MICHAELS^RACHEL^R\rOBX|3|TN|00000-0^PROVIDER PHONE^LN||8014081819\rOBX|4|NM|22025-1^PROVIDER ID^LN||02337\rOBX|5|ST|45403-3^ROOM NUMBER^LN||E820\rOBX|6|ST|42347-5^ADMIT DIAGNOSIS^LN||ALTERED MENTAL STATU\rOBX|7|TM|00000-0^PREVIOUS ADMIT DATE^LN||200811240953Z\rOBX|8|TM|00000-0^PREVIOUS DISCHARGE DATE^LN||200812261601Z\rOBX|9|ST|00000-0^CONTACT NAME^LN||Carrie Taylor\rOBX|10|TN|00000-0^CONTACT PHONE^LN||8015077782\rOBX|11|NM|21612-7^PATIENT AGE^LN||38\rOBR|2|186936||LABRPT||200902210950Z||||||||200902210956Z|&Bronchial Alveolar L||||||||||P\rOBX|1|CE|00000-0^Culture ^LN||^""\r IHC1 HL7MESSAGES[:no_msh] = <<~NOMSH PID|1||17744418^^^^MR||ZHANG^GEORGE^^^^^L||19830922|M||U^Unknown^HL70005|42 HAPPY LN^^SALT LAKE CITY^UT^84444^^M||^^PH^^^801^5552346|||||||||U^Unknown^HL70189\rORC||||||||||||^FARNSWORTH^MABEL^W|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBR|1||09078102377|13954-3^Hepatitis Be Antigen^LN|||200903191011|||||||200903191011|X|^FARNSWORTH^MABEL^W||||||200903191011|||F||||||9^Unknown\rOBX|1|ST|13954-3^Hepatitis Be Antigen^LN|1|Positive||Negative||||F|||200903210007\r NOMSH HL7MESSAGES[:no_pid] = <<~NOPID MSH|^~&|ARUP|ARUP LABORATORIES^46D0523979^CLIA|UTDOH|UT|200903261645||ORU^R01|200903261645128667|P|2.3.1|1\rORC||||||||||||^FARNSWORTH^MABEL^W|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBR|1||09078102377|13954-3^Hepatitis Be Antigen^LN|||200903191011|||||||200903191011|X|^FARNSWORTH^MABEL^W||||||200903191011|||F||||||9^Unknown\rOBX|1|ST|13954-3^Hepatitis Be Antigen^LN|1|Positive||Negative||||F|||200903210007\r NOPID HL7MESSAGES[:no_obr] = <<~NOOBR MSH|^~&|ARUP|ARUP LABORATORIES^46D0523979^CLIA|UTDOH|UT|200903261645||ORU^R01|200903261645128667|P|2.3.1|1\rPID|1||17744418^^^^MR||ZHANG^GEORGE^^^^^L||19830922|M||U^Unknown^HL70005|42 HAPPY LN^^SALT LAKE CITY^UT^84444^^M||^^PH^^^801^5552346|||||||||U^Unknown^HL70189\rORC||||||||||||^FARNSWORTH^MABEL^W|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBX|1|ST|13954-3^Hepatitis Be Antigen^LN|1|Positive||Negative||||F|||200903210007\r NOOBR HL7MESSAGES[:no_obx] = <<~NOOBX MSH|^~&|ARUP|ARUP LABORATORIES^46D0523979^CLIA|UTDOH|UT|200903261645||ORU^R01|200903261645128667|P|2.3.1|1\rPID|1||17744418^^^^MR||ZHANG^GEORGE^^^^^L||19830922|M||U^Unknown^HL70005|42 HAPPY LN^^SALT LAKE CITY^UT^84444^^M||^^PH^^^801^5552346|||||||||U^Unknown^HL70189\rORC||||||||||||^FARNSWORTH^MABEL^W|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBR|1||09078102377|13954-3^Hepatitis Be Antigen^LN|||200903191011|||||||200903191011|X|^FARNSWORTH^MABEL^W||||||200903191011|||F||||||9^Unknown\r NOOBX HL7MESSAGES[:no_last_name] = <<~NOLASTNAME MSH|^~&|ARUP|ARUP LABORATORIES^46D0523979^CLIA|UTDOH|UT|200903261645||ORU^R01|200903261645128667|P|2.3.1|1\rPID|1||17744418^^^^MR||^GEORGE^^^^^L||19830922|M||U^Unknown^HL70005|42 HAPPY LN^^SALT LAKE CITY^UT^84444^^M||^^PH^^^801^5552346|||||||||U^Unknown^HL70189\rORC||||||||||||^FARNSWORTH^MABEL^W|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBR|1||09078102377|13954-3^Hepatitis Be Antigen^LN|||200903191011|||||||200903191011|BLOOD|^FARNSWORTH^MABEL^W||||||200903191011|||F||||||9^Unknown\rOBX|1|ST|13954-3^Hepatitis Be Antigen^LN|1|Positive||Negative||||F|||200903210007\r NOLASTNAME HL7MESSAGES[:no_loinc_code] = <<~NOLOINCCODE MSH|^~&|ARUP|ARUP LABORATORIES^46D0523979^CLIA|UTDOH|UT|200903261645||ORU^R01|200903261645128667|P|2.3.1|1\rPID|1||17744418^^^^MR||ZHANG^GEORGE^^^^^L||19830922|M||U^Unknown^HL70005|42 HAPPY LN^^SALT LAKE CITY^UT^84444^^M||^^PH^^^801^5552346|||||||||U^Unknown^HL70189\rORC||||||||||||^FARNSWORTH^MABEL^W|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBR|1||09078102377||||200903191011|||||||200903191011|BLOOD|^FARNSWORTH^MABEL^W||||||200903191011|||F||||||9^Unknown\rOBX|1|ST|^Hepatitis Be Antigen^LN|1|Positive||Negative||||F|||200903210007\r NOLOINCCODE HL7MESSAGES[:unknown_loinc] = <<~UNKNOWN_LOINC MSH|^~&|ARUP|ARUP LABORATORIES^46D0523979^CLIA|UTDOH|UT|200903261645||ORU^R01|200903261645128667|P|2.3.1|1\rPID|1||17744418^^^^MR||ZHANG^GEORGE^^^^^L||19830922|M||U^Unknown^HL70005|42 HAPPY LN^^SALT LAKE CITY^UT^84444^^M||^^PH^^^801^5552346|||||||||U^Unknown^HL70189\rORC||||||||||||^FARNSWORTH^MABEL^W|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBR|1||09078102377|20000-0^Hepatitis Be Antigen^LN|||200903191011|||||||200903191011|BLOOD|^FARNSWORTH^MABEL^W||||||200903191011|||F||||||9^Unknown\rOBX|1|ST|20000-0^Hepatitis Be Antigen^LN|1|Positive||Negative||||F|||200903210007\r UNKNOWN_LOINC HL7MESSAGES[:unlinked_loinc] = <<~UNLINKED_LOINC MSH|^~&|ARUP|ARUP LABORATORIES^46D0523979^CLIA|UTDOH|UT|200903261645||ORU^R01|200903261645128667|P|2.3.1|1\rPID|1||17744418^^^^MR||ZHANG^GEORGE^^^^^L||19830922|M||U^Unknown^HL70005|42 HAPPY LN^^SALT LAKE CITY^UT^84444^^M||^^PH^^^801^5552346|||||||||U^Unknown^HL70189\rORC||||||||||||^FARNSWORTH^MABEL^W|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBR|1||09078102377|10000-1^Hepatitis Be Antigen^LN|||200903191011|||||||200903191011|BLOOD|^FARNSWORTH^MABEL^W||||||200903191011|||F||||||9^Unknown\rOBX|1|ST|10000-1^Hepatitis Be Antigen^LN|1|Positive||Negative||||F|||200903210007\r UNLINKED_LOINC HL7MESSAGES[:arup_simple_pid] = <<~ARUP_SIMPLE_PID MSH|^~&|ARUP|ARUP LABORATORIES^46D0523979^CLIA|UTDOH|UT|200903261645||ORU^R01|200903261645128667|P|2.3.1|1\rPID|1||17744418^^^^MR||ZHANG^GEORGE^^^^^L||19830922|M||U^Unknown^HL70005||||||||||||U^Unknown^HL70189\rORC||||||||||||^FARNSWORTH^MABEL^W|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBR|1||09078102377|13954-3^Hepatitis Be Antigen^LN|||200903191011|||||||200903191011|BLOOD|^FARNSWORTH^MABEL^W||||||200903191011|||F||||||9^Unknown\rOBX|1|ST|13954-3^Hepatitis Be Antigen^LN|1|Repeatedly Reactive||Negative||||F|||200903210007\r ARUP_SIMPLE_PID # HL7MESSAGES[:arup_replace_name] = Proc.new do |patient_name| # first_name, last_name = patient_name.split # <<ARUP # MSH|^~\&|ARUP|ARUP LABORATORIES^46D0523979^CLIA|UTDOH|UT|200903261645||ORU^R01|200903261645128667|P|2.3.1|1\rPID|1||17744418^^^^MR||#{last_name}^#{first_name}^^^^^L||19830922|M||U^Unknown^HL70005|42 HAPPY LN^^SALT LAKE CITY^UT^84444^^M||^^PH^^^801^5552346|||||||||U^Unknown^HL70189\rORC||||||||||||^FARNSWORTH^MABEL^W|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBR|1||09078102377|13954-3^Hepatitis Be Antigen^LN|||200903191011|||||||200903191011|BLOOD|^FARNSWORTH^MABEL^W||||||200903191011|||F||||||9^Unknown\rOBX|1|ST|13954-3^Hepatitis Be Antigen^LN|1|Positive|Metric Ton|Negative||||F|||200903210007\r # ARUP # end # # HL7MESSAGES[:arup_replace_lab] = Proc.new do |lab_name| # <<ARUP # MSH|^~\&|ARUP|#{lab_name}^46D0523979^CLIA|UTDOH|UT|200903261645||ORU^R01|200903261645128667|P|2.3.1|1\rPID|1||17744418^^^^MR||ZHANG^GEORGE^^^^^L||19830922|M||U^Unknown^HL70005|42 HAPPY LN^^SALT LAKE CITY^UT^84444^^M||^^PH^^^801^5552346|||||||||U^Unknown^HL70189\rORC||||||||||||^FARNSWORTH^MABEL^W|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBR|1||09078102377|13954-3^Hepatitis Be Antigen^LN|||200903191011|||||||200903191011|BLOOD|^FARNSWORTH^MABEL^W||||||200903191011|||F||||||9^Unknown\rOBX|1|ST|13954-3^Hepatitis Be Antigen^LN|1|Positive|Metric Ton|Negative||||F|||200903210007\r # ARUP # end # # HL7MESSAGES[:arup_replace_collection_date] = Proc.new do |collection_date| # <<ARUP # MSH|^~\&|ARUP|ARUP LABORATORIES^46D0523979^CLIA|UTDOH|UT|200903261645||ORU^R01|200903261645128667|P|2.3.1|1\rPID|1||17744418^^^^MR||ZHANG^GEORGE^^^^^L||19830922|M||U^Unknown^HL70005|42 HAPPY LN^^SALT LAKE CITY^UT^84444^^M||^^PH^^^801^5552346|||||||||U^Unknown^HL70189\rORC||||||||||||^FARNSWORTH^MABEL^W|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBR|1||09078102377|13954-3^Hepatitis Be Antigen^LN|||#{collection_date}|||||||200903191011|BLOOD|^FARNSWORTH^MABEL^W||||||200903191011|||F||||||9^Unknown\rOBX|1|ST|13954-3^Hepatitis Be Antigen^LN|1|Positive|Metric Ton|Negative||||F|||200903210007\r # ARUP # end # # HL7MESSAGES[:arup_replace_test_type] = Proc.new do |test_type| # <<ARUP # MSH|^~\&|ARUP|ARUP LABORATORIES^46D0523979^CLIA|UTDOH|UT|200903261645||ORU^R01|200903261645128667|P|2.3.1|1\rPID|1||17744418^^^^MR||ZHANG^GEORGE^^^^^L||19830922|M||U^Unknown^HL70005|42 HAPPY LN^^SALT LAKE CITY^UT^84444^^M||^^PH^^^801^5552346|||||||||U^Unknown^HL70189\rORC||||||||||||^FARNSWORTH^MABEL^W|||||||||University Hospital UT|50 North Medical Drive^^Salt Lake City^UT^84132^USA^B||^^^^^USA^B\rOBR|1||09078102377|13954-3^Hepatitis Be Antigen^LN|||200903191011|||||||200903191011|BLOOD|^FARNSWORTH^MABEL^W||||||200903191011|||F||||||9^Unknown\rOBX|1|ST|13954-3^#{test_type}^LN|1|Positive|Metric Ton|Negative||||F|||200903210007\r # ARUP # end # The following messages are taken from the HL7 2.5.1 ELR to Public # Health US Realm document. # All the sample messages in the Realm document have the same PID-10 # field '2106-3^White^CDCREC^^^^04/24/2007.' Manually change the # Realm Campylobacter jejuni message to use # # 1002-5^American Indian or Alaska Native^CDCREC^^^^04/24/2007 # # for PID-10 rather than the 2106-3 code. You will also need to add # something in MSH-4 before the first circumflex, e.g., My # Lab^1234^CLIA. Post this staged message and then create a new CMR # event from it. The Demographic tab will show that the patient is # "Alaskan Native and American Indian." (Both race codes AA and AK # are assigned to the patient.) HL7MESSAGES[:realm_lead_laboratory_result] = <<~REALM_LEAD_LABORATORY_RESULT MSH|^~&|Lab1^1234^CLIA|^1234^CLIA|ELR^2.16.840.1.113883.19.3.2^ISO|SPH^2.16.840.1.113883.19.3.2^ISO|20080818183002.1-0700||ORU^R01^ORU_R01|1234567890|P^T|2.5.1|||NE|NE|USA||||USELR1.0^^2.16.840.1.114222.4.10.3^ISO\rSFT|1|Level Seven Healthcare Software, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|1.2|An Lab System|56734||20080817\rPID|1||36363636^^^MPI&2.16.840.1.113883.19.3.2.1&ISO^MR^A&2.16.8 40.1.113883.19.3.2.1&ISO~444333333^^^&2.16.840.1.113883.4.1^ISO^SS||Everyman^Adam^A^^^^L^^^^^^^BS|Mum^Martha^M^^^^M|20050602|M||2106-3^White^CDCREC^^^^04/24/2007|2222 Home Street^^Ann Arbor^MI^99999^USA^H||^PRN^PH^^1^555^5552004|^WPN^PH^^1^955^5551009|eng^English^ISO6392^^^^3/29/2007|M^Married^HL70002^^^^2. 5.1||||||N^Not Hispanic or Latino^HL70189^^^^2.5.1||||||||N|||200808151000-0700|Reliable^2.16.840.1.113883.19.3.1^ISO\rNK1|1|Mum^Martha^M^^^^L|MTH^Mother^HL70063^^^^2.5.1| 444 Home Street^Apt B^Ann Arbor^MI^99999^USA^H|^PRN^PH^^1^555^5552006\rPV1|1|O|4E^234^A^Good Health Hospital&2.16.840.1.113883.19.3.2.3&ISO^N^N^Building 1^4^Nursing unit 4 East^1234&&2.16.840.1.113883.19.3.2.3&ISO^&2.16.840.1.113883.19.3.2.3&ISO|R||||||||||||||||||||||||||||||||||||||||200808151000-0700|200808151200-0700\rPV2|||1^Sick^99AdmitReason|||||||||||||N||||||||Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|||20010603|||19990603\rORC|RE|23456^EHR^2.16.840.1.113883.19.3.2.3^ISO|9700123^Lab^2.16.840.1.113883.19.3.1.6^ISO|||||||||1234^Admit^Alan^A^III^Dr^^^&2.16.840.1.113883.19.4.6^ISO^L^^^EI^&2.16.840.1.113883.19.4.6^ISO^^^^^^^^MD||^WPN^PH^^1^555^5551005|||||||Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|1005 Healthcare Drive^^Ann Arbor^MI^99999^USA^B|^WPN^PH^^1^555^5553001|4444 Healthcare Drive^Suite 123^Ann Arbor^MI^99999^USA^B\rOBR|1|23456^EHR^2.16.840.1.113883.19.3.2.3^ISO|9700123^Lab^2.16.840.1.113883.19.3.1.6^ISO|10368-9^Lead BldCmCnc^LN^3456543^Blood lead test^99USI^2.24|||200808151030-0700||||||diarrhea|||1234^Admit^Alan^A^III^Dr^^^&2.16.840.1.113883.19.4.6^ISO^L^^^EI^&2.16.840.1.113883.19.4.6^ISO^^^^^^^^MD|^WPN^PH^^1^555^5551005|||||2008081830-0700|||F||||||787.91^DIARRHEA^I9CDX^^^^07/09/2008|1235&Slide&Stan&S&&Dr&MD&&DOC&2.16.840.1.113883.19.4.6&ISO\rOBX|1|NM|10368-9^Lead BldCmCnc^LN^^^^2.24|1|50|ug/dL^micro-gram per deciliter^UCUM^^^^1.6|<10 ug/dL|H|||F|||200808151030-0700|||||200808181800-0700||||Lab^L^^^^CLIA&2.16.840.1.113883.19.4.6&ISO^XX^^^1236|3434 Industrial Loop^^Ann Arbor^MI^99999^USA^B|9876543^Slide^Stan^S^^^^^NPPES&2.16.840.1.113883.19.4.6&ISO^L^^^NPI\rSPM|1|23456&EHR&2.16.840.1.113883.19.3.2.3&ISO^9700122&Lab&2.16.840.1.113883.19.3.1.6&ISO||122554006^Capillary blood specimen^SCT^BLDC^Blood capillary^HL70070^20080131^2.5.1||HEPA^Ammonium heparin^HL70371^^^^2.5.1|CAP^Capillary Specimen^HL70488^^^^2.5.1|181395001^Venous structure of digit^SCT^^^^20080731|||P^Patient^HL60369^^^^2.5.1|50^uL&Micro Liter&UCUM&&&&1.6|||||200808151030-0700|200808151100-0700\rOBX|2|NM|35659-2^Age at specimen collection^LN^^^^2.24||3|a^year^UCUM^^^^1.6|||||F|||200808151030-0700|||||200808151030-0700||||Lab^L^^^^CLIA&2.16.840.1.113883.19.4.6&ISO^XX^^^1236|3434 Industrial Loop^^Ann Arbor^MI^99999^USA^B|9876543^Slide^Stan^S^^^^^NPPES&2.16.840.1.113883.19.4.6&ISO^L^^^NPI REALM_LEAD_LABORATORY_RESULT HL7MESSAGES[:realm_campylobacter_jejuni] = <<~REALM_CAMPYLOBACTER_JEJUNI MSH|^~&|Lab1^1234^CLIA|^1234^CLIA|ELR^2.16.840.1.113883.19.3.2^ISO|SPH^2.16.840.1.113883.19.3.2^ISO|20080818183002.1-0700||ORU^R01^ORU_R01|1234567890|P^T|2.5.1|||NE|NE|USA||||USELR1.0^^2.16.840.1.114222.4.10.3^ISO\rSFT|1|Level Seven Healthcare Software, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|1.2|An Lab System|56734||20080817\rPID|1||36363636^^^MPI&2.16.840.1.113883.19.3.2.1&ISO^MR^A&2.16.840.1.113883.19.3.2.1&ISO~444333333^^^&2.16.840.1.113883.4.1^ISO^SS||Everyman^Adam^A^^^^L^^^^^^^BS|Mum^Martha^M^^^^M|19800602|M||2106-3^White^CDCREC^^^^04/24/2007|2222 Home Street^^Ann Arbor^MI^99999^USA^H||^PRN^PH^^1^555^5552004|^WPN^PH^^1^955^5551009|eng^English^ISO6392^^^^3/29/2007|M^Married^HL70002^^^^2.5.1||||||N^Not Hispanic or Latino^HL70189^^^^2.5.1||||||||N|||200808151000-0700|Reliable^2.16.840.1.113883.19.3.1^ISO\rPV1|1|O|4E^234^A^Good Health Hospital&2.16.840.1.113883.19.3.2.3&ISO^N^N^Building 1^4^Nursing unit 4 East^1234&&2.16.840.1.113883.19.3.2.3&ISO^&2.16.840.1.113883.19.3.2.3&ISO|R||||||||||||||||||||||||||||||||||||||||200808151000-0700|200808151200-0700\rPV2|||1^Sick^99AdmitReason|||||||||||||N||||||||Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|||20010603|||19990603\rORC|RE|23456^EHR^2.16.840.1.113883.19.3.2.3^ISO|9700123^Lab^2.16.840.1.113883.19.3.1.6^ISO|||||||||1234^Admit^Alan^A^III^Dr^^^&2.16.840.1.113883.19.4.6^ISO^L^^^EI^&2.16.840.1.113883.19.4.6^ISO^^^^^^^^MD||^WPN^PH^^1^555^5551005|||||||Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|1005 Healthcare Drive^^Ann Arbor^MI^99999^USA^B|^WPN^PH^^1^555^5553001|4444 Healthcare Drive^Suite 123^Ann Arbor^MI^99999^USA^B\rOBR|1|23456^EHR^2.16.840.1.113883.19.3.2.3^ISO|9700123^Lab^2.16.840.1.113883.19.3.1.6^ISO|625-4^Bacteria identified^LN^3456543^ CULTURE, STOOL^99USI^2.26|||200808151030-0700||||||diarrhea|||1234^Admit^Alan^A^III^Dr^^^&2.16.840.1.113883.19.4.6^ISO^L^^^EI^&2.16.840.1.113883.19.4.6^ISO^^^^^^^^MD|^WPN^PH^^1^555^5551005|||||2008081830-0700|||F||||||787.91^DIARRHEA^I9CDX^^^^07/09/2008|1235&Slide&Stan&S&&Dr&MD&&DOC&2.16.840.1.113883.19.4.6&ISO\rOBX|1|CWE|625-4^Bacteria identified:Prid:Pt:Stool:Nom:Culture^LN^^^^2.26|1|66543000^Campylobacter jejuni^SCT^^^^January 2007||||||P|||200906041458|||0086^Bacterial identification^OBSMETHOD^^^^501-20080815||200906051700||||GHH Lab^L^^^^CLIA&2.16.840.1.113883.19.4.6&ISO^XX^^^1236|3434 Industrial Loop^^Ann Arbor^MI^99999^USA^B|9876543^Slide^Stan^S^^^^^NPPES&2.16.840.1.113883.19.4.6&ISO^L^^^NPI\rSPM|1|23456&EHR&2.16.840.1.113883.19.3.2.3&ISO^9700122&Lab&2.16.840.1.113883.19.3.1.6&ISO||119339001^Stool specimen^SCT^^^^20080131|||||||P^Patient^HL60369^^^^2.5.1|10^g&gram&UCUM&&&&1.6|||||200808151030-0700|200808151100-0700 REALM_CAMPYLOBACTER_JEJUNI HL7MESSAGES[:realm_campy_jejuni_bad_race_condition] = <<~REALM_CAMPYLOBACTER_JEJUNI MSH|^~&|My Lab1^1234^CLIA|^1234^CLIA|ELR^2.16.840.1.113883.19.3.2^ISO|SPH^2.16.840.1.113883.19.3.2^ISO|20080818183002.1-0700||ORU^R01^ORU_R01|1234567890|P^T|2.5.1|||NE|NE|USA||||USELR1.0^^2.16.840.1.114222.4.10.3^ISO\rSFT|1|Level Seven Healthcare Software, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|1.2|An Lab System|56734||20080817\rPID|1||36363636^^^MPI&2.16.840.1.113883.19.3.2.1&ISO^MR^A&2.16.840.1.113883.19.3.2.1&ISO~444333333^^^&2.16.840.1.113883.4.1^ISO^SS||Everyman^Adam^A^^^^L^^^^^^^BS|Mum^Martha^M^^^^M|19800602|M||4302-1^Foobar^CDCREC^^^^04/24/2007|2222 Home Street^^Ann Arbor^MI^99999^USA^H||^PRN^PH^^1^555^5552004|^WPN^PH^^1^955^5551009|eng^English^ISO6392^^^^3/29/2007|M^Married^HL70002^^^^2.5.1||||||N^Not Hispanic or Latino^HL70189^^^^2.5.1||||||||N|||200808151000-0700|Reliable^2.16.840.1.113883.19.3.1^ISO\rPV1|1|O|4E^234^A^Good Health Hospital&2.16.840.1.113883.19.3.2.3&ISO^N^N^Building 1^4^Nursing unit 4 East^1234&&2.16.840.1.113883.19.3.2.3&ISO^&2.16.840.1.113883.19.3.2.3&ISO|R||||||||||||||||||||||||||||||||||||||||200808151000-0700|200808151200-0700\rPV2|||1^Sick^99AdmitReason|||||||||||||N||||||||Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|||20010603|||19990603\rORC|RE|23456^EHR^2.16.840.1.113883.19.3.2.3^ISO|9700123^Lab^2.16.840.1.113883.19.3.1.6^ISO|||||||||1234^Admit^Alan^A^III^Dr^^^&2.16.840.1.113883.19.4.6^ISO^L^^^EI^&2.16.840.1.113883.19.4.6^ISO^^^^^^^^MD||^WPN^PH^^1^555^5551005|||||||Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|1005 Healthcare Drive^^Ann Arbor^MI^99999^USA^B|^WPN^PH^^1^555^5553001|4444 Healthcare Drive^Suite 123^Ann Arbor^MI^99999^USA^B\rOBR|1|23456^EHR^2.16.840.1.113883.19.3.2.3^ISO|9700123^Lab^2.16.840.1.113883.19.3.1.6^ISO|625-4^Bacteria identified^LN^3456543^ CULTURE, STOOL^99USI^2.26|||200808151030-0700||||||diarrhea|||1234^Admit^Alan^A^III^Dr^^^&2.16.840.1.113883.19.4.6^ISO^L^^^EI^&2.16.840.1.113883.19.4.6^ISO^^^^^^^^MD|^WPN^PH^^1^555^5551005|||||2008081830-0700|||F||||||787.91^DIARRHEA^I9CDX^^^^07/09/2008|1235&Slide&Stan&S&&Dr&MD&&DOC&2.16.840.1.113883.19.4.6&ISO\rOBX|1|CWE|625-4^Bacteria identified:Prid:Pt:Stool:Nom:Culture^LN^^^^2.26|1|66543000^Campylobacter jejuni^SCT^^^^January 2007||||||P|||200906041458|||0086^Bacterial identification^OBSMETHOD^^^^501-20080815||200906051700||||GHH Lab^L^^^^CLIA&2.16.840.1.113883.19.4.6&ISO^XX^^^1236|3434 Industrial Loop^^Ann Arbor^MI^99999^USA^B|9876543^Slide^Stan^S^^^^^NPPES&2.16.840.1.113883.19.4.6&ISO^L^^^NPI\rSPM|1|23456&EHR&2.16.840.1.113883.19.3.2.3&ISO^9700122&Lab&2.16.840.1.113883.19.3.1.6&ISO||119339001^Stool specimen^SCT^^^^20080131|||||||P^Patient^HL60369^^^^2.5.1|10^g&gram&UCUM&&&&1.6|||||200808151030-0700|200808151100-0700 REALM_CAMPYLOBACTER_JEJUNI HL7MESSAGES[:realm_campy_jejuni_unknown] = <<~REALM_CAMPYLOBACTER_JEJUNI MSH|^~&|My Lab1^1234^CLIA|^1234^CLIA|ELR^2.16.840.1.113883.19.3.2^ISO|SPH^2.16.840.1.113883.19.3.2^ISO|20080818183002.1-0700||ORU^R01^ORU_R01|1234567890|P^T|2.5.1|||NE|NE|USA||||USELR1.0^^2.16.840.1.114222.4.10.3^ISO\rSFT|1|Level Seven Healthcare Software, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|1.2|An Lab System|56734||20080817\rPID|1||36363636^^^MPI&2.16.840.1.113883.19.3.2.1&ISO^MR^A&2.16.840.1.113883.19.3.2.1&ISO~444333333^^^&2.16.840.1.113883.4.1^ISO^SS||Everyman^Adam^A^^^^L^^^^^^^BS|Mum^Martha^M^^^^M|19800602|M||U^Unknown^CDCREC^^^^04/24/2007|2222 Home Street^^Ann Arbor^MI^99999^USA^H||^PRN^PH^^1^555^5552004|^WPN^PH^^1^955^5551009|eng^English^ISO6392^^^^3/29/2007|M^Married^HL70002^^^^2.5.1||||||N^Not Hispanic or Latino^HL70189^^^^2.5.1||||||||N|||200808151000-0700|Reliable^2.16.840.1.113883.19.3.1^ISO\rPV1|1|O|4E^234^A^Good Health Hospital&2.16.840.1.113883.19.3.2.3&ISO^N^N^Building 1^4^Nursing unit 4 East^1234&&2.16.840.1.113883.19.3.2.3&ISO^&2.16.840.1.113883.19.3.2.3&ISO|R||||||||||||||||||||||||||||||||||||||||200808151000-0700|200808151200-0700\rPV2|||1^Sick^99AdmitReason|||||||||||||N||||||||Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|||20010603|||19990603\rORC|RE|23456^EHR^2.16.840.1.113883.19.3.2.3^ISO|9700123^Lab^2.16.840.1.113883.19.3.1.6^ISO|||||||||1234^Admit^Alan^A^III^Dr^^^&2.16.840.1.113883.19.4.6^ISO^L^^^EI^&2.16.840.1.113883.19.4.6^ISO^^^^^^^^MD||^WPN^PH^^1^555^5551005|||||||Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|1005 Healthcare Drive^^Ann Arbor^MI^99999^USA^B|^WPN^PH^^1^555^5553001|4444 Healthcare Drive^Suite 123^Ann Arbor^MI^99999^USA^B\rOBR|1|23456^EHR^2.16.840.1.113883.19.3.2.3^ISO|9700123^Lab^2.16.840.1.113883.19.3.1.6^ISO|625-4^Bacteria identified^LN^3456543^ CULTURE, STOOL^99USI^2.26|||200808151030-0700||||||diarrhea|||1234^Admit^Alan^A^III^Dr^^^&2.16.840.1.113883.19.4.6^ISO^L^^^EI^&2.16.840.1.113883.19.4.6^ISO^^^^^^^^MD|^WPN^PH^^1^555^5551005|||||2008081830-0700|||F||||||787.91^DIARRHEA^I9CDX^^^^07/09/2008|1235&Slide&Stan&S&&Dr&MD&&DOC&2.16.840.1.113883.19.4.6&ISO\rOBX|1|CWE|625-4^Bacteria identified:Prid:Pt:Stool:Nom:Culture^LN^^^^2.26|1|66543000^Campylobacter jejuni^SCT^^^^January 2007||||||P|||200906041458|||0086^Bacterial identification^OBSMETHOD^^^^501-20080815||200906051700||||GHH Lab^L^^^^CLIA&2.16.840.1.113883.19.4.6&ISO^XX^^^1236|3434 Industrial Loop^^Ann Arbor^MI^99999^USA^B|9876543^Slide^Stan^S^^^^^NPPES&2.16.840.1.113883.19.4.6&ISO^L^^^NPI\rSPM|1|23456&EHR&2.16.840.1.113883.19.3.2.3&ISO^9700122&Lab&2.16.840.1.113883.19.3.1.6&ISO||119339001^Stool specimen^SCT^^^^20080131|||||||P^Patient^HL60369^^^^2.5.1|10^g&gram&UCUM&&&&1.6|||||200808151030-0700|200808151100-0700 REALM_CAMPYLOBACTER_JEJUNI HL7MESSAGES[:realm_campy_jejuni_hawaiian] = <<~REALM_CAMPYLOBACTER_JEJUNI MSH|^~&|My Lab1^1234^CLIA|^1234^CLIA|ELR^2.16.840.1.113883.19.3.2^ISO|SPH^2.16.840.1.113883.19.3.2^ISO|20080818183002.1-0700||ORU^R01^ORU_R01|1234567890|P^T|2.5.1|||NE|NE|USA||||USELR1.0^^2.16.840.1.114222.4.10.3^ISO\rSFT|1|Level Seven Healthcare Software, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|1.2|An Lab System|56734||20080817\rPID|1||36363636^^^MPI&2.16.840.1.113883.19.3.2.1&ISO^MR^A&2.16.840.1.113883.19.3.2.1&ISO~444333333^^^&2.16.840.1.113883.4.1^ISO^SS||Everyman^Adam^A^^^^L^^^^^^^BS|Mum^Martha^M^^^^M|19800602|M||2076-8^Native Hawaiian or Other Pacific Islander^CDCREC^^^^04/24/2007|2222 Home Street^^Ann Arbor^MI^99999^USA^H||^PRN^PH^^1^555^5552004|^WPN^PH^^1^955^5551009|eng^English^ISO6392^^^^3/29/2007|M^Married^HL70002^^^^2.5.1||||||N^Not Hispanic or Latino^HL70189^^^^2.5.1||||||||N|||200808151000-0700|Reliable^2.16.840.1.113883.19.3.1^ISO\rPV1|1|O|4E^234^A^Good Health Hospital&2.16.840.1.113883.19.3.2.3&ISO^N^N^Building 1^4^Nursing unit 4 East^1234&&2.16.840.1.113883.19.3.2.3&ISO^&2.16.840.1.113883.19.3.2.3&ISO|R||||||||||||||||||||||||||||||||||||||||200808151000-0700|200808151200-0700\rPV2|||1^Sick^99AdmitReason|||||||||||||N||||||||Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|||20010603|||19990603\rORC|RE|23456^EHR^2.16.840.1.113883.19.3.2.3^ISO|9700123^Lab^2.16.840.1.113883.19.3.1.6^ISO|||||||||1234^Admit^Alan^A^III^Dr^^^&2.16.840.1.113883.19.4.6^ISO^L^^^EI^&2.16.840.1.113883.19.4.6^ISO^^^^^^^^MD||^WPN^PH^^1^555^5551005|||||||Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|1005 Healthcare Drive^^Ann Arbor^MI^99999^USA^B|^WPN^PH^^1^555^5553001|4444 Healthcare Drive^Suite 123^Ann Arbor^MI^99999^USA^B\rOBR|1|23456^EHR^2.16.840.1.113883.19.3.2.3^ISO|9700123^Lab^2.16.840.1.113883.19.3.1.6^ISO|625-4^Bacteria identified^LN^3456543^ CULTURE, STOOL^99USI^2.26|||200808151030-0700||||||diarrhea|||1234^Admit^Alan^A^III^Dr^^^&2.16.840.1.113883.19.4.6^ISO^L^^^EI^&2.16.840.1.113883.19.4.6^ISO^^^^^^^^MD|^WPN^PH^^1^555^5551005|||||2008081830-0700|||F||||||787.91^DIARRHEA^I9CDX^^^^07/09/2008|1235&Slide&Stan&S&&Dr&MD&&DOC&2.16.840.1.113883.19.4.6&ISO\rOBX|1|CWE|625-4^Bacteria identified:Prid:Pt:Stool:Nom:Culture^LN^^^^2.26|1|66543000^Campylobacter jejuni^SCT^^^^January 2007||||||P|||200906041458|||0086^Bacterial identification^OBSMETHOD^^^^501-20080815||200906051700||||GHH Lab^L^^^^CLIA&2.16.840.1.113883.19.4.6&ISO^XX^^^1236|3434 Industrial Loop^^Ann Arbor^MI^99999^USA^B|9876543^Slide^Stan^S^^^^^NPPES&2.16.840.1.113883.19.4.6&ISO^L^^^NPI\rSPM|1|23456&EHR&2.16.840.1.113883.19.3.2.3&ISO^9700122&Lab&2.16.840.1.113883.19.3.1.6&ISO||119339001^Stool specimen^SCT^^^^20080131|||||||P^Patient^HL60369^^^^2.5.1|10^g&gram&UCUM&&&&1.6|||||200808151030-0700|200808151100-0700 REALM_CAMPYLOBACTER_JEJUNI HL7MESSAGES[:realm_campy_jejuni_black] = <<~REALM_CAMPYLOBACTER_JEJUNI MSH|^~&|My Lab1^1234^CLIA|^1234^CLIA|ELR^2.16.840.1.113883.19.3.2^ISO|SPH^2.16.840.1.113883.19.3.2^ISO|20080818183002.1-0700||ORU^R01^ORU_R01|1234567890|P^T|2.5.1|||NE|NE|USA||||USELR1.0^^2.16.840.1.114222.4.10.3^ISO\rSFT|1|Level Seven Healthcare Software, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|1.2|An Lab System|56734||20080817\rPID|1||36363636^^^MPI&2.16.840.1.113883.19.3.2.1&ISO^MR^A&2.16.840.1.113883.19.3.2.1&ISO~444333333^^^&2.16.840.1.113883.4.1^ISO^SS||Everyman^Adam^A^^^^L^^^^^^^BS|Mum^Martha^M^^^^M|19800602|M||2054-5^Black or African American^CDCREC^^^^04/24/2007|2222 Home Street^^Ann Arbor^MI^99999^USA^H||^PRN^PH^^1^555^5552004|^WPN^PH^^1^955^5551009|eng^English^ISO6392^^^^3/29/2007|M^Married^HL70002^^^^2.5.1||||||N^Not Hispanic or Latino^HL70189^^^^2.5.1||||||||N|||200808151000-0700|Reliable^2.16.840.1.113883.19.3.1^ISO\rPV1|1|O|4E^234^A^Good Health Hospital&2.16.840.1.113883.19.3.2.3&ISO^N^N^Building 1^4^Nursing unit 4 East^1234&&2.16.840.1.113883.19.3.2.3&ISO^&2.16.840.1.113883.19.3.2.3&ISO|R||||||||||||||||||||||||||||||||||||||||200808151000-0700|200808151200-0700\rPV2|||1^Sick^99AdmitReason|||||||||||||N||||||||Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|||20010603|||19990603\rORC|RE|23456^EHR^2.16.840.1.113883.19.3.2.3^ISO|9700123^Lab^2.16.840.1.113883.19.3.1.6^ISO|||||||||1234^Admit^Alan^A^III^Dr^^^&2.16.840.1.113883.19.4.6^ISO^L^^^EI^&2.16.840.1.113883.19.4.6^ISO^^^^^^^^MD||^WPN^PH^^1^555^5551005|||||||Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|1005 Healthcare Drive^^Ann Arbor^MI^99999^USA^B|^WPN^PH^^1^555^5553001|4444 Healthcare Drive^Suite 123^Ann Arbor^MI^99999^USA^B\rOBR|1|23456^EHR^2.16.840.1.113883.19.3.2.3^ISO|9700123^Lab^2.16.840.1.113883.19.3.1.6^ISO|625-4^Bacteria identified^LN^3456543^ CULTURE, STOOL^99USI^2.26|||200808151030-0700||||||diarrhea|||1234^Admit^Alan^A^III^Dr^^^&2.16.840.1.113883.19.4.6^ISO^L^^^EI^&2.16.840.1.113883.19.4.6^ISO^^^^^^^^MD|^WPN^PH^^1^555^5551005|||||2008081830-0700|||F||||||787.91^DIARRHEA^I9CDX^^^^07/09/2008|1235&Slide&Stan&S&&Dr&MD&&DOC&2.16.840.1.113883.19.4.6&ISO\rOBX|1|CWE|625-4^Bacteria identified:Prid:Pt:Stool:Nom:Culture^LN^^^^2.26|1|66543000^Campylobacter jejuni^SCT^^^^January 2007||||||P|||200906041458|||0086^Bacterial identification^OBSMETHOD^^^^501-20080815||200906051700||||GHH Lab^L^^^^CLIA&2.16.840.1.113883.19.4.6&ISO^XX^^^1236|3434 Industrial Loop^^Ann Arbor^MI^99999^USA^B|9876543^Slide^Stan^S^^^^^NPPES&2.16.840.1.113883.19.4.6&ISO^L^^^NPI\rSPM|1|23456&EHR&2.16.840.1.113883.19.3.2.3&ISO^9700122&Lab&2.16.840.1.113883.19.3.1.6&ISO||119339001^Stool specimen^SCT^^^^20080131|||||||P^Patient^HL60369^^^^2.5.1|10^g&gram&UCUM&&&&1.6|||||200808151030-0700|200808151100-0700 REALM_CAMPYLOBACTER_JEJUNI HL7MESSAGES[:realm_campy_jejuni_ai_or_an] = <<~REALM_CAMPYLOBACTER_JEJUNI
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
true
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/core_ext/string.rb
lib/core_ext/string.rb
# frozen_string_literal: true # Adding a helper to the String class for the batch parse. class String def hl7_batch? !!match(/^FHS/) end end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/core_ext/date_time.rb
lib/core_ext/date_time.rb
# frozen_string_literal: true module HL7Time # Get a HL7 timestamp (type TS) for a Time instance. # # fraction_digits:: specifies a number of digits of fractional seconds. # Its default value is 0. # Time.parse('01:23').to_hl7 # => "20091202012300" # Time.now.to_hl7(3) # => "20091202153652.302" def to_hl7(fraction_digits = 0) strftime("%Y%m%d%H%M%S") + hl7_fractions(fraction_digits) end private def hl7_fractions(fraction_digits = 0) return "" unless fraction_digits.positive? time_fraction = hl7_time_fraction answer = ".#{format("%06d", time_fraction)}" answer += "0" * ((fraction_digits - 6)).abs if fraction_digits > 6 answer[0, 1 + fraction_digits] end def hl7_time_fraction if respond_to? :usec usec else sec_fraction.to_f * 1_000_000 end end end # Adding the to_hl7 method to the ruby Date class. class Date # Get a HL7 timestamp (type TS) for a Date instance. # # Date.parse('2009-12-02').to_hl7 # => "20091202" def to_hl7 strftime("%Y%m%d") end end # Adding the to_hl7 method to the ruby Time class. class Time include HL7Time end # Adding the to_hl7 method to the ruby DateTime class. class DateTime include HL7Time end # TODO # parse an hl7 formatted date # def Date.from_hl7( hl7_date ) # end # def Date.to_hl7_short( ruby_date ) # end # def Date.to_hl7_med( ruby_date ) # end # def Date.to_hl7_long( ruby_date ) # end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/evn.rb
lib/segments/evn.rb
# frozen_string_literal: true class HL7::Message::Segment::EVN < HL7::Message::Segment weight 0 # should occur after the MSH segment add_field :type_code add_field :recorded_date do |value| convert_to_ts(value) end add_field :planned_date do |value| convert_to_ts(value) end add_field :reason_code add_field :operator_id add_field :event_occurred do |value| convert_to_ts(value) end add_field :event_facility end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/rol.rb
lib/segments/rol.rb
# frozen_string_literal: true class HL7::Message::Segment::ROL < HL7::Message::Segment add_field :role_instance, :idx => 1 add_field :action_code, :idx => 2 add_field :role, :idx => 3 add_field :role_person, :idx => 4 add_field :role_begin_date_time, :idx => 5 do |value| convert_to_ts(value) end add_field :role_end_date_time, :idx => 6 do |value| convert_to_ts(value) end add_field :role_duration, :idx => 7 add_field :role_action_reason, :idx => 8 add_field :provider_type, :idx => 9 add_field :organization_unit_type, :idx => 10 add_field :office_home_address_birthplace, :idx => 11 add_field :phone_number, :idx => 12 add_field :person_location, :idx => 13 add_field :organization, :idx => 14 end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/dg1.rb
lib/segments/dg1.rb
# frozen_string_literal: true module HL7 class Message::Segment::DG1 < HL7::Message::Segment weight 92 add_field :set_id add_field :diagnosis_coding_method add_field :diagnosis_code add_field :diagnosis_description add_field :diagnosis_date_time do |value| convert_to_ts(value) end add_field :diagnosis_type add_field :major_diagnostic_category add_field :diagnosis_related_group add_field :drg_approval_indicator add_field :drg_grouper_review_code add_field :outlier_type add_field :outlier_days add_field :outlier_cost add_field :grouper_version_and_type add_field :diagnosis_priority add_field :diagnosis_clinician add_field :diagnosis_classification add_field :confidential_indicator add_field :attestation_date_time do |value| convert_to_ts(value) end end end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/nte.rb
lib/segments/nte.rb
# frozen_string_literal: true class HL7::Message::Segment::NTE < HL7::Message::Segment weight 4 add_field :set_id, :idx => 1 add_field :source, :idx => 2 add_field :comment, :idx => 3 add_field :comment_type, :idx => 4 end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/pv1.rb
lib/segments/pv1.rb
# frozen_string_literal: true class HL7::Message::Segment::PV1 < HL7::Message::Segment weight 2 add_field :set_id add_field :patient_class add_field :assigned_location add_field :admission_type add_field :preadmit_number add_field :prior_location add_field :attending_doctor add_field :referring_doctor add_field :consulting_doctor add_field :hospital_service add_field :temporary_location add_field :preadmit_indicator add_field :readmit_indicator add_field :admit_source add_field :ambulatory_status add_field :vip_indicator add_field :admitting_doctor add_field :patient_type add_field :visit_number add_field :financial_class add_field :charge_price_indicator add_field :courtesy_code add_field :credit_rating add_field :contract_code add_field :contract_effective_date add_field :contract_amount add_field :contract_period add_field :interest_code add_field :transfer_bad_debt_code add_field :transfer_bad_debt_date add_field :bad_debt_agency_code add_field :bad_debt_transfer_amount add_field :bad_debt_recovery_amount add_field :delete_account_indicator add_field :delete_account_date add_field :discharge_disposition add_field :discharge_to_location add_field :diet_type add_field :servicing_facility add_field :bed_status add_field :account_status add_field :pending_location add_field :prior_temporary_location add_field :admit_date do |value| convert_to_ts(value) end add_field :discharge_date do |value| convert_to_ts(value) end add_field :current_patient_balance add_field :total_charges add_field :total_adjustments add_field :total_payments add_field :alternate_visit_id add_field :visit_indicator add_field :other_healthcare_provider end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/in1.rb
lib/segments/in1.rb
# frozen_string_literal: true # via https://github.com/bbhoss/ruby-hl7/blob/master/lib/segments/in1.rb class HL7::Message::Segment::IN1 < HL7::Message::Segment add_field :set_id add_field :insurance_plan_id add_field :insurance_company_id add_field :insurance_company_name add_field :insurance_company_address add_field :insurance_company_contact_person add_field :insurance_company_phone_number add_field :group_number add_field :group_name add_field :insureds_group_employee_id add_field :insureds_group_employee_name add_field :plan_effective_date add_field :plan_expiration_date add_field :authorization_information add_field :plan_type add_field :name_of_insured add_field :insureds_relationship_to_patient add_field :insureds_date_of_birth add_field :insureds_address add_field :assignment_of_benefits add_field :coordination_of_benefits add_field :coordination_of_benefits_priority add_field :notice_of_admission_flag add_field :notice_of_admission_date add_field :report_of_eligibility_flag add_field :report_of_eligibility_date add_field :release_information_code add_field :pre_admit_cert add_field :verification_date_time add_field :verification_by add_field :type_of_agreement_code add_field :billing_status add_field :lifetime_reserve_days add_field :delay_before_lr_day add_field :company_plan_code add_field :policy_number add_field :policy_deductible add_field :policy_limit_amount add_field :policy_limit_days add_field :room_rate_semi_private add_field :room_rate_private add_field :insureds_employment_status add_field :insureds_sex add_field :insureds_employer_address add_field :verification_status add_field :prior_insurance_plan_id add_field :coverage_type add_field :handicap add_field :insureds_id_number add_field :signature_code add_field :signature_code_date add_field :insureds_birth_place add_field :vip_indicator end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/obr.rb
lib/segments/obr.rb
# frozen_string_literal: true class HL7::Message::Segment::OBR < HL7::Message::Segment weight 89 # obx.weight-1 has_children %i[NTE OBX SPM] add_field :set_id add_field :placer_order_number add_field :filler_order_number add_field :universal_service_id add_field :priority add_field :requested_date do |value| convert_to_ts(value) end add_field :observation_date do |value| convert_to_ts(value) end add_field :observation_end_date do |value| convert_to_ts(value) end add_field :collection_volume add_field :collector_identifier add_field :specimen_action_code add_field :danger_code add_field :relevant_clinical_info add_field :specimen_received_date do |value| convert_to_ts(value) end add_field :specimen_source add_field :ordering_provider add_field :order_callback_phone_number add_field :placer_field_1 add_field :placer_field_2 add_field :filler_field_1 add_field :filler_field_2 add_field :results_status_change_date do |value| convert_to_ts(value) end add_field :charge_to_practice add_field :diagnostic_serv_sect_id add_field :result_status add_field :parent_result add_field :quantity_timing add_field :result_copies_to add_field :parent add_field :transport_mode add_field :reason_for_study add_field :principal_result_interpreter add_field :assistant_result_interpreter add_field :technician add_field :transcriptionist add_field :scheduled_date do |value| convert_to_ts(value) end add_field :number_of_sample_containers add_field :transport_logistics_of_sample add_field :collectors_comment add_field :transport_arrangement_responsibility add_field :transport_arranged add_field :escort_required add_field :planned_patient_transport_comment add_field :procedure_code add_field :procedure_code_modifier add_field :placer_supplemental_service_info add_field :filler_supplemental_service_info add_field :medically_necessary_dup_procedure_reason # longest method name ever. sry. add_field :result_handling add_field :parent_universal_service_identifier end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/mfi.rb
lib/segments/mfi.rb
# frozen_string_literal: true class HL7::Message::Segment::MFI < HL7::Message::Segment weight 0 add_field :master_file_identifier add_field :master_file_application_identifier add_field :file_level_event_code add_field :entered_date_time do |value| convert_to_ts(value) end add_field :effective_date_time do |value| convert_to_ts(value) end add_field :response_level_code end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/spm.rb
lib/segments/spm.rb
# frozen_string_literal: true class HL7::Message::Segment::SPM < HL7::Message::Segment # Weight doesn't really matter, since this always occurs as a child # of an OBR segment. weight 100 # fixme has_children [:OBX] add_field :set_id add_field :specimen_id add_field :specimen_parent_ids add_field :specimen_type add_field :specimen_type_modifier add_field :specimen_additives add_field :specimen_collection_method add_field :specimen_source_site add_field :specimen_source_site_modifier add_field :specimen_collection_site add_field :specimen_role add_field :specimen_collection_amount add_field :grouped_specimen_count add_field :specimen_description add_field :specimen_handling_code add_field :specimen_risk_code add_field :specimen_collection_date add_field :specimen_received_date add_field :specimen_expiration_date add_field :specimen_availability add_field :specimen_reject_reason add_field :specimen_quality add_field :specimen_appropriateness add_field :specimen_condition add_field :specimen_current_quantity add_field :number_of_specimen_containers add_field :container_type add_field :container_condition add_field :specimen_child_role end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/ail.rb
lib/segments/ail.rb
# frozen_string_literal: true class HL7::Message::Segment::AIL < HL7::Message::Segment weight 0 add_field :set_id add_field :segment_action_code add_field :location_resource_id add_field :location_type add_field :location_group add_field :start_date_time add_field :start_date_time_offset add_field :start_date_time_offset_units add_field :duration add_field :duration_units add_field :allow_substitution_code add_field :filler_status_code end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/msa.rb
lib/segments/msa.rb
# frozen_string_literal: true class HL7::Message::Segment::MSA < HL7::Message::Segment weight 1 # should occur after the msh segment add_field :ack_code add_field :control_id add_field :text add_field :expected_seq add_field :delayed_ack_type add_field :error_cond end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/orc.rb
lib/segments/orc.rb
# frozen_string_literal: true class HL7::Message::Segment::ORC < HL7::Message::Segment weight 88 # obr.weight-1 has_children [:OBR] add_field :order_control add_field :placer_order_number add_field :filler_order_number add_field :placer_group_number add_field :order_status add_field :response_flag add_field :quantity_timing add_field :parent add_field :date_time_of_transaction do |value| convert_to_ts(value) end add_field :entered_by add_field :verified_by add_field :ordering_provider add_field :enterers_location add_field :call_back_phone_number add_field :order_effective_date_time do |value| convert_to_ts(value) end add_field :order_control_code_reason add_field :entering_organization add_field :entering_device add_field :action_by add_field :advanced_beneficiary_notice_code add_field :ordering_facility_name add_field :ordering_facility_address add_field :ordering_facility_phone_number add_field :ordering_provider_address add_field :order_status_modifier add_field :advanced_beneficiary_notice_override_reason add_field :fillers_expected_availability_date_time add_field :confidentiality_code add_field :order_type add_field :enterer_authorization_mode add_field :parent_universal_service_identifier def self.convert_to_ts(value) # :nodoc: return value.to_hl7 if value.is_a?(Time) || value.is_a?(Date) value end end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/mrg.rb
lib/segments/mrg.rb
# frozen_string_literal: true class HL7::Message::Segment::MRG < HL7::Message::Segment weight 4 add_field :prior_patient_identifier_list add_field :prior_alternate_patient_id add_field :prior_patient_account_number add_field :prior_patient_id add_field :prior_visit_number add_field :prior_alternate_visit_id add_field :prior_patient_name end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/mfe.rb
lib/segments/mfe.rb
# frozen_string_literal: true class HL7::Message::Segment::MFE < HL7::Message::Segment weight 0 add_field :record_level_event_code add_field :mfn_control_id add_field :effective_date_time do |value| convert_to_ts(value) end add_field :primary_key_value add_field :primary_key_value_type end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/prd.rb
lib/segments/prd.rb
# frozen_string_literal: true class HL7::Message::Segment::PRD < HL7::Message::Segment weight 2 add_field :provider_role add_field :provider_name add_field :provider_address add_field :provider_location add_field :provider_communication_information add_field :preferred_method_of_contact add_field :provider_identifiers add_field :effective_start_date_of_provider_role do |value| convert_to_ts(value) end add_field :effective_end_date_of_provider_role do |value| convert_to_ts(value) end end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/obx.rb
lib/segments/obx.rb
# frozen_string_literal: true class HL7::Message::Segment::OBX < HL7::Message::Segment weight 90 has_children [:NTE] add_field :set_id add_field :value_type add_field :observation_id add_field :observation_sub_id add_field :observation_value add_field :units add_field :references_range add_field :abnormal_flags add_field :probability add_field :nature_of_abnormal_test add_field :observation_result_status add_field :effective_date_of_reference_range do |value| convert_to_ts(value) end add_field :user_defined_access_checks add_field :observation_date do |value| convert_to_ts(value) end add_field :producer_id add_field :responsible_observer add_field :observation_method add_field :equipment_instance_id add_field :analysis_date do |value| convert_to_ts(value) end add_field :observation_site add_field :observation_instance_id add_field :mood_code add_field :performing_organization_name add_field :performing_organization_address add_field :performing_organization_medical_director def correction? observation_result_status == "C" end end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/ft1.rb
lib/segments/ft1.rb
# frozen_string_literal: true module HL7 class Message::Segment::FT1 < HL7::Message::Segment weight 10 add_field :set_id add_field :transaction_id add_field :transaction_batch_id add_field :date_of_service do |value| convert_to_ts(value) end add_field :transaction_posting_date do |value| convert_to_ts(value) end add_field :transaction_type add_field :transaction_code add_field :transaction_description add_field :transaction_description_alt add_field :transaction_quantity add_field :transaction_amount_extended add_field :transaction_amount_unit add_field :department_code add_field :insurance_plan_id add_field :insurance_amount add_field :assigned_patient_location add_field :fees_schedule add_field :patient_type # https://www.findacode.com/icd-9/icd-9-cm-diagnosis-codes.html # http://www.icd10data.com/ICD10CM/Codes add_field :diagnosis_code # https://en.wikipedia.org/wiki/National_Provider_Identifier add_field :performed_by_provider add_field :ordering_provider add_field :unit_cost add_field :filler_order_number add_field :entered_by # https://en.wikipedia.org/wiki/Current_Procedural_Terminology (CPT) add_field :procedure_code add_field :procedure_code_modifier add_field :advanced_beneficiary_notice_code add_field :medically_necessary_duplicate_procedure_reason add_field :ndc_code add_field :payment_reference_id add_field :transaction_reference_key add_field :performing_facility add_field :ordering_facility add_field :item_number add_field :model_number add_field :special_processing_code add_field :clinic_code add_field :referral_number add_field :authorization_number add_field :service_provider_taxonomy_code add_field :revenue_code add_field :prescription_number add_field :ndc_qty_and_uom end end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/rf1.rb
lib/segments/rf1.rb
# frozen_string_literal: true class HL7::Message::Segment::RF1 < HL7::Message::Segment weight 0 # should occur after the MSH segment add_field :referral_status add_field :referral_priority add_field :referral_type add_field :referral_disposition add_field :referral_category add_field :originating_referral_identifier add_field :effective_date do |value| convert_to_ts(value) end add_field :expiration_date do |value| convert_to_ts(value) end add_field :process_date do |value| convert_to_ts(value) end add_field :referral_reason add_field :external_referral_identifier end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/ais.rb
lib/segments/ais.rb
# frozen_string_literal: true class HL7::Message::Segment::AIS < HL7::Message::Segment weight 1 add_field :set_id add_field :segment_action_code add_field :universal_service_identifier add_field :start_time add_field :start_time_offset add_field :start_time_offset_units add_field :duration add_field :duration_units add_field :allow_subsitution_code add_field :filler_status_code add_field :placer_supplemental_service_information add_field :filler_supplemental_service_information alias_field :start_date, :start_time alias_field :start_date_offset, :start_time_offset alias_field :start_date_offset_units, :start_time_offset_units end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/sch.rb
lib/segments/sch.rb
# frozen_string_literal: true class HL7::Message::Segment::SCH < HL7::Message::Segment weight 0 add_field :placer_appointment_id add_field :filler_appointment_id add_field :occurance_number add_field :placer_group_number add_field :schedule_id add_field :event_reason add_field :appointment_reason add_field :appointment_type add_field :appointment_duration add_field :appointment_duration_units add_field :appointment_timing_quantity add_field :placer_contact_person add_field :placer_contact_phone_number add_field :placer_contact_address add_field :placer_contact_location add_field :filler_contact_person add_field :filler_contact_phone_number add_field :filler_contact_address add_field :filler_contact_location add_field :entered_by_person add_field :entered_by_phone_number add_field :entered_by_location add_field :parent_placer_appointment_id add_field :parent_filler_appointment_id add_field :filler_status_code add_field :placer_order_number add_field :filler_order_number end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/sft.rb
lib/segments/sft.rb
# frozen_string_literal: true class HL7::Message::Segment::SFT < HL7::Message::Segment weight 0 add_field :software_vendor_organization add_field :software_certified_version_or_release_number # NEW longest method name ever. add_field :software_product_name add_field :software_binary_id add_field :software_product_information add_field :software_install_date end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/oru.rb
lib/segments/oru.rb
# frozen_string_literal: true class HL7::Message::Segment::ORU < HL7::Message::Segment end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/fts.rb
lib/segments/fts.rb
# frozen_string_literal: true class HL7::Message::Segment::FTS < HL7::Message::Segment weight 1001 # at the end add_field :file_batch_count add_field :file_trailer_comment end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/txa.rb
lib/segments/txa.rb
# frozen_string_literal: true class HL7::Message::Segment::TXA < HL7::Message::Segment add_field :set_id add_field :document_type add_field :document_content_presentation add_field :activity_date_time add_field :primary_activity_provider_code add_field :origination_date_time add_field :transcription_date_time add_field :edit_date_time add_field :originator_code add_field :assigned_document_authenticator add_field :transcriptionist_code add_field :unique_document_number add_field :parent_document_number add_field :placer_order_number add_field :filler_order_number add_field :unique_document_file_name add_field :document_completion_status add_field :document_confidentiality_status add_field :document_availability_status add_field :document_storage_status add_field :document_change_reason add_field :authentication_person_time_stamp add_field :distributed_copies_code add_field :folder_assignment add_field :document_title add_field :agreed_due_date_time end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/rgs.rb
lib/segments/rgs.rb
# frozen_string_literal: true class HL7::Message::Segment::RGS < HL7::Message::Segment weight 3 add_field :set_id add_field :segment_action_code add_field :resource_group_id end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/tq1.rb
lib/segments/tq1.rb
# frozen_string_literal: true class HL7::Message::Segment::TQ1 < HL7::Message::Segment weight 2 add_field :set_id add_field :quantity add_field :repeat_pattern add_field :explicit_time add_field :relative_time_and_units add_field :service_duration add_field :start_time add_field :end_time add_field :priority add_field :condition_text add_field :text_instruction add_field :conjunction add_field :occurrence_duration add_field :total_occurrences alias_field :start_date, :start_time alias_field :end_date, :end_time end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/aig.rb
lib/segments/aig.rb
# frozen_string_literal: true class HL7::Message::Segment::AIG < HL7::Message::Segment weight 1 add_field :set_id add_field :segment_action_code add_field :resource_id add_field :resource_type add_field :resource_group add_field :resource_quantity add_field :resource_quantity_units add_field :start_time add_field :start_time_offset add_field :start_time_offset_units add_field :duration add_field :duration_units add_field :allow_subsitution_code add_field :filler_status_status alias_field :start_date, :start_time alias_field :start_date_offset, :start_time_offset alias_field :start_date_offset_units, :start_time_offset_units end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/qrd.rb
lib/segments/qrd.rb
# frozen_string_literal: true class HL7::Message::Segment::QRD < HL7::Message::Segment weight 84 add_field :query_date add_field :query_format_code add_field :query_priority add_field :query_id add_field :deferred_response_type add_field :deferred_response_date add_field :quantity_limited_request add_field :who_subject_filter add_field :what_subject_filter add_field :what_department_code add_field :what_data_code add_field :query_results_level end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/nk1.rb
lib/segments/nk1.rb
# frozen_string_literal: true class HL7::Message::Segment::NK1 < HL7::Message::Segment add_field :set_id, :idx => 1 add_field :name, :idx => 2 add_field :relationship, :idx => 3 add_field :address, :idx => 4 add_field :phone_number, :idx => 5 add_field :business_phone_number, :idx => 6 add_field :contact_role, :idx => 7 add_field :start_date, :idx => 8 do |value| convert_to_ts(value) end add_field :end_date, :idx => 9 do |value| convert_to_ts(value) end add_field :job_title, :idx => 10 add_field :job_code, :idx => 11 add_field :employee_number, :idx => 12 add_field :organization_name, :idx => 13 add_field :marital_status, :idx => 14 add_field :admin_sex, :idx => 15 do |sex| sanitize_admin_sex!(sex) end add_field :date_of_birth, :idx => 16 do |value| convert_to_ts(value) end add_field :living_dependency, :idx => 17 add_field :ambulatory_status, :idx => 18 add_field :citizenship, :idx => 19 add_field :primary_language, :idx => 20 add_field :living_arrangement, :idx => 21 add_field :publicity_code, :idx => 22 add_field :protection_indicator, :idx => 23 add_field :student_indicator, :idx => 24 add_field :religion, :idx => 25 add_field :mother_maiden_name, :idx => 26 add_field :nationality, :idx => 27 add_field :ethnic_group, :idx => 28 add_field :contact_reason, :idx => 29 add_field :contact_persons_name, :idx => 30 add_field :contact_persons_telephone_number, :idx => 31 add_field :contact_persons_address, :idx => 32 add_field :identifiers, :idx => 33 add_field :job_status, :idx => 34 add_field :race, :idx => 35 add_field :handicap, :idx => 36 add_field :contact_persons_ssn, :idx => 37 add_field :birth_place, :idx => 38 add_field :vip_indicator, :idx => 39 add_field :telecommunication_information, :idx => 40 add_field :contact_persons_telecommunication_information, :idx => 41 end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/msh.rb
lib/segments/msh.rb
# frozen_string_literal: true class HL7::Message::Segment::MSH < HL7::Message::Segment weight(-1) # the msh should always start a message add_field :enc_chars add_field :sending_app add_field :sending_facility add_field :recv_app add_field :recv_facility add_field :time do |value| convert_to_ts(value) end add_field :security add_field :message_type add_field :message_control_id add_field :processing_id add_field :version_id add_field :seq add_field :continue_ptr add_field :accept_ack_type add_field :app_ack_type add_field :country_code add_field :charset add_field :principal_language_of_message add_field :alternate_character_set_handling_scheme add_field :message_profile_identifier add_field :sending_responsible_org add_field :receiving_responsible_org add_field :sending_network_address add_field :receiving_network_address end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/gt1.rb
lib/segments/gt1.rb
# frozen_string_literal: true module HL7 class Message::Segment::GT1 < HL7::Message::Segment add_field :set_id add_field :guarantor_number add_field :guarantor_name add_field :guarantor_spouse_name add_field :guarantor_address add_field :guarantor_home_phone add_field :guarantor_business_phone add_field :guarantor_date_of_birth add_field :guarantor_sex do |sex| sanitize_admin_sex!(sex) end add_field :guarantor_type add_field :guarantor_relationship add_field :guarantor_ssn add_field :guarantor_begin_date do |value| convert_to_ts(value) end add_field :guarantor_end_date do |value| convert_to_ts(value) end add_field :guarantor_priority add_field :guarantor_employer_name add_field :guarantor_employer_address add_field :guarantor_employer_phone add_field :guarantor_employee_id add_field :guarantor_employment_status add_field :guarantor_billing_hold_flag add_field :guarantor_date_of_death do |value| convert_to_ts(value) end add_field :guarantor_death_flag add_field :guarantor_charge_adjustment_code add_field :guarantor_household_annual_income add_field :guarantor_household_size add_field :guarantor_employer_id_number add_field :guarantor_marital_status_code add_field :guarantor_hire_effective_date do |value| convert_to_ts(value) end add_field :employment_stop_date do |value| convert_to_ts(value) end add_field :living_dependency add_field :ambulatory_status add_field :citizenship add_field :primary_language add_field :living_arrangement add_field :publicity_indicator add_field :protection_indicator add_field :student_indicator add_field :religion add_field :mothers_maiden_name add_field :nationality add_field :ethnic_group add_field :contact_persons_name add_field :contact_persons_phone_number add_field :contact_reason add_field :contact_relationship add_field :contact_job_title add_field :job_code add_field :guarantor_employers_organization add_field :handicap add_field :job_status add_field :guarantor_financial_class add_field :guarantor_race add_field :guarantor_birth_place add_field :vip_indicator end end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/err.rb
lib/segments/err.rb
# frozen_string_literal: true class HL7::Message::Segment::ERR < HL7::Message::Segment weight 2 add_field :error_code_and_location add_field :error_location add_field :hl7_error_code add_field :severity add_field :application_error_code add_field :application_error_parameter add_field :diagnostic_information add_field :user_message add_field :help_desk_contact_point, :idx => 12 end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/qrf.rb
lib/segments/qrf.rb
# frozen_string_literal: true class HL7::Message::Segment::QRF < HL7::Message::Segment weight 85 add_field :where_subject_filter add_field :when_start_date add_field :when_end_date add_field :what_user_qualifier add_field :other_qry_subject_filter add_field :which_date_qualifier add_field :which_date_status_qualifier add_field :date_selection_qualifier add_field :when_timing_qualifier add_field :search_confidence_threshold end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/prt.rb
lib/segments/prt.rb
# frozen_string_literal: true class HL7::Message::Segment::PRT < HL7::Message::Segment add_field :participation_instance_id, :idx => 1 add_field :action_code, :idx => 2 add_field :action_reason, :idx => 3 add_field :participation, :idx => 4 add_field :participation_person, :idx => 5 add_field :participation_person_provider_type, :idx => 6 add_field :participation_organization_unit_type, :idx => 7 add_field :participation_organization, :idx => 8 add_field :participation_location, :idx => 9 add_field :participation_device, :idx => 10 add_field :participation_begin_date_time, :idx => 11 do |value| convert_to_ts(value) end add_field :participation_end_date_time, :idx => 12 do |value| convert_to_ts(value) end add_field :participation_qualitative_duration, :idx => 13 add_field :participation_address, :idx => 14 add_field :participation_telecommunication_address, :idx => 15 end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/aip.rb
lib/segments/aip.rb
# frozen_string_literal: true class HL7::Message::Segment::AIP < HL7::Message::Segment weight 0 add_field :set_id add_field :segment_action_code add_field :personnel_resource_id add_field :resource_role add_field :resource_group add_field :start_date_time add_field :start_date_time_offset add_field :start_date_time_offset_units add_field :duration add_field :duration_units add_field :allow_substitution_code add_field :filler_status_code end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/pv2.rb
lib/segments/pv2.rb
# frozen_string_literal: true class HL7::Message::Segment::PV2 < HL7::Message::Segment weight 3 add_field :prior_pending_location, :idx => 1 add_field :accommodation_code, :idx => 2 add_field :admit_reason, :idx => 3 add_field :transfer_reason, :idx => 4 add_field :patient_valuables, :idx => 5 add_field :patient_valuables_location, :idx => 6 add_field :visit_user_code, :idx => 7 add_field :expected_admit_date, :idx => 8 add_field :expected_discharge_date, :idx => 9 add_field :estimated_inpatient_stay_length, :idx => 10 add_field :actual_inpatient_stay_length, :idx => 11 add_field :visit_description, :idx => 12 add_field :referral_source_code, :idx => 13 add_field :previous_service_date, :idx => 14 add_field :employment_illness_related_indicator, :idx => 15 add_field :purge_status_code, :idx => 16 add_field :purge_status_date, :idx => 17 add_field :special_program_code, :idx => 18 add_field :retention_indicator, :idx => 19 add_field :expected_number_of_insurance_plans, :idx => 20 add_field :visit_publicity_code, :idx => 21 add_field :visit_protection_indicator, :idx => 22 add_field :clinic_organization_name, :idx => 23 add_field :patient_status_code, :idx => 24 add_field :visit_priority_code, :idx => 25 add_field :previous_treatment_date, :idx => 26 add_field :expected_discharge_disposition, :idx => 27 add_field :signature_on_file, :idx => 28 add_field :first_similar_illness_date, :idx => 29 add_field :patient_charge_adjustment_code, :idx => 30 add_field :recurring_service_code, :idx => 31 add_field :billing_media_code, :idx => 32 add_field :expected_surgery_date, :idx => 33 add_field :military_partnership_code, :idx => 34 add_field :military_non_availability_code, :idx => 35 add_field :newborn_baby_indicator, :idx => 36 add_field :baby_detained_indicator, :idx => 37 add_field :mode_of_arrival_code, :idx => 38 add_field :recreational_drug_use_code, :idx => 39 add_field :admission_level_of_care_code, :idx => 40 add_field :precaution_code, :idx => 41 add_field :patient_condition_code, :idx => 42 add_field :living_will_code, :idx => 43 add_field :organ_donor_code, :idx => 44 add_field :advance_directive_code, :idx => 45 add_field :patient_status_effective_date, :idx => 46 add_field :expected_loa_return_date, :idx => 47 add_field :expected_preadmission_testing_date, :idx => 48 add_field :notify_clergy_code, :idx => 49 def military_non_availibility_code warn "DEPRECATION WARNING: PV2-35 is defined as 'military_non_availability_code'; " \ "the 'military_non_availibility_code' alias is retained for backwards compatibility only." military_non_availability_code end def military_non_availibility_code=(code) warn "DEPRECATION WARNING: PV2-35 is defined as 'military_non_availability_code'; " \ "the 'military_non_availibility_code' alias is retained for backwards compatibility only." self.military_non_availability_code = code end end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
ruby-hl7/ruby-hl7
https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segments/pid.rb
lib/segments/pid.rb
# frozen_string_literal: true class HL7::Message::Segment::PID < HL7::Message::Segment weight 1 has_children %i[NK1 NTE PV1 PV2] add_field :set_id add_field :patient_id add_field :patient_id_list add_field :alt_patient_id add_field :patient_name add_field :mother_maiden_name add_field :patient_dob do |value| convert_to_ts(value) end add_field :admin_sex do |sex| sanitize_admin_sex!(sex) end add_field :patient_alias add_field :race add_field :address add_field :county_code add_field :phone_home add_field :phone_business add_field :primary_language add_field :marital_status add_field :religion add_field :account_number add_field :social_security_num add_field :driver_license_num add_field :mothers_id add_field :ethnic_group add_field :birthplace add_field :multi_birth add_field :birth_order add_field :citizenship add_field :vet_status add_field :nationality add_field :death_date do |value| convert_to_ts(value) end add_field :death_indicator add_field :id_unknown_indicator add_field :id_reliability_code add_field :last_update_date do |value| convert_to_ts(value) end add_field :last_update_facility add_field :species_code add_field :breed_code add_field :strain add_field :production_class_code add_field :tribal_citizenship def country_code warn "DEPRECATION WARNING: PID-12 is defined as 'county_code'; " \ "the 'country_code' alias is retained for backwards compatibility only." county_code end def country_code=(country_code) warn "DEPRECATION WARNING: PID-12 is defined as 'county_code'; " \ "the 'country_code' alias is retained for backwards compatibility only." self.county_code = country_code end def id_readability_code warn "DEPRECATION WARNING: PID-32 is defined as 'id_reliability_code'; " \ "the 'id_readability_code' alias is retained for backwards compatibility only." id_reliability_code end def id_readability_code=(code) warn "DEPRECATION WARNING: PID-32 is defined as 'id_reliability_code'; " \ "the 'id_readability_code' alias is retained for backwards compatibility only." self.id_reliability_code = code end end
ruby
MIT
d5c8ee0288d225591c611a8474da5c520e5415f6
2026-01-04T17:51:14.403379Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/test/test_chordy.rb
test/test_chordy.rb
require 'helper' class TestChordy < Test::Unit::TestCase def test_chord Chord.new(:M, 6) end def reset_test_chords no_auto clear end should "have methods and constants for all chord flags" do c = test_chord methods = c.methods class_flags = Chord::CHORD_FLAGS consts = Chord.constants # class methods class_flags.each { |f| assert(consts.include?(f.upcase.to_sym), "no constant '#{f}' in Chord") } class_flags.each { |method| assert(methods.include?(method.to_sym), "no class method '#{method}' in Chord") } instance_flags = class_flags.select { |c| c!= "dont_play"}.map { |c| "play_" + c.to_s } # instance methods instance_flags.each { |method| assert(methods.include?(method.to_sym), "no instance method '#{method}' in Chord") } end should "knows all chord types" do short_chords = Chord.short_chords short_chords.keys.each { |k| assert_not_nil(Chord.new(k, 6)) } short_chords.values.each { |k| assert_not_nil(Chord.new(k, 6)) } end should "has all chord types for all chord families" do chord_families = [C, CSharp, DFlat, D, DSharp, EFlat, E, F, FSharp, GFlat, G, GSharp, AFlat, A, ASharp, B] short_chords = Chord.short_chords.values short_chord_methods = short_chords.map { |c| "play_" + c.to_s } chord_families.each do |family| family_methods = family.instance_methods short_chord_methods.each { |method| assert(family_methods.include?(method.to_sym), "no method '#{method}' in #{family}") } end end should "support any tuning length" do reset_test_chords tuning_range = 1..20 tuning_range.each do |t| assert_nothing_raised do tuning = ["a"] * t tune tuning play :C end end end should "print to string" do reset_test_chords string = 1 no_of_strings = 6 play [string] * no_of_strings a = print_chords_to_string a_parts = a.split("\n").first(no_of_strings) a_parts.each { |c| assert(c.include? string.to_s) } end should "be able to show/hide divider" do reset_test_chords string_a = [0] Chordy.line_length = 4 play string_a play string_a play string_a play string_a Chordy.show_half_length_delimiter = false chords_without_divider = print_chords_to_string assert(!chords_without_divider.include?(Chordy.half_length_delimiter), "divider is shown") Chordy.show_half_length_delimiter = true chords_with_divider = print_chords_to_string assert(chords_with_divider.include?(Chordy.half_length_delimiter), "divider is not shown") end should "know strings at different positions" do # TODO implement true end end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/test/helper.rb
test/helper.rb
require 'rubygems' require 'bundler' begin Bundler.setup(:default, :development) rescue Bundler::BundlerError => e $stderr.puts e.message $stderr.puts "Run `bundle install` to install missing gems" exit e.status_code end require 'test/unit' require 'shoulda' $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib', 'chordy')) $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'chordy' class Test::Unit::TestCase end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy_script.rb
lib/chordy_script.rb
require 'chordy' no_auto
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy.rb
lib/chordy.rb
require 'stringio' includes = ['chords', 'util'] include_dirs = includes.map { |dir| "chordy/#{dir}/" } include_dirs.each do |dir| Dir[File.join(File.dirname(__FILE__), dir + '**.rb')].each do |file| require file end end module Chordy extend self, Util, Util::Tuning attr_accessor :chords, :line_length, :separator_length, :tuning attr_accessor :auto, :show_half_length_delimiter, :low_to_high attr_accessor :chord_space, :half_length_delimiter, :start_delimiter, :end_delimiter @line_length = 8 @separator_length = 40 @chords = [] @auto = true @show_half_length_delimiter = true @tuning = tuning_6_standard @low_to_high = false # printing delimiters @chord_space = "-" @half_length_delimiter = "|" @start_delimiter = "[" @end_delimiter = "]" def do_auto a=true Chordy.auto = a Chordy.auto end def no_auto Chordy.auto = false Chordy.auto end def do_low_to_high Chordy.low_to_high = true do_print end def do_high_to_low Chordy.low_to_high = false do_print end def clear Chordy.chords = [] do_print end # TODO document + examples def set_chords_to_tuning tuning longest_tuning_str_length = tuning.max.length Chordy.tuning = tuning.map { |e| e.rjust(longest_tuning_str_length) } Chordy.chords.select { |c| c.is_a? Chord } .each { |e| e.pad_or_trim Chordy.tuning.length, true } end def tune new_tuning, direction=:low_to_high to_do_print = false strings = [6, 7, 8] if new_tuning.is_a? Array if direction == :high_to_low new_tuning = new_tuning.reverse end set_chords_to_tuning new_tuning to_do_print = true else if is_tuning? new_tuning.to_s new_tuning = eval("#{new_tuning}") set_chords_to_tuning new_tuning to_do_print = true else puts "Unknown or invalid tuning" end end if to_do_print do_print end end def check_sharp_or_flat_chord chord_name chord = chord_name.capitalize sharp_re = /!$/ flat_re = /_$/ if sharp_re =~ chord chord = chord.gsub(sharp_re, "Sharp") elsif flat_re =~ chord chord = chord.gsub(flat_re, "Flat") end chord end def check_chord_class chord_name eval("defined?(#{chord_name}) == 'constant' and #{chord_name}.class == Class") end def check_exec_eval(chords, chord_type) chords_and_type = chords.to_s + chord_type.to_s chords_and_type.include?("exec") or chords_and_type.include?("eval") end def play chords, chord_type_or_direction=:major chord = nil begin if check_exec_eval(chords, chord_type_or_direction) throw "Permission denied" else if chords.instance_of? Array chord = Chord.new(chords, Chordy.tuning.length) # play high-to-low, unless :low_to_high is specified if chord_type_or_direction != :low_to_high chord.reverse_strings! end else chord_name = chords.to_s if !check_chord_class chord_name chord_name = check_sharp_or_flat_chord chord_name end chord_init = "#{chord_name}.new :#{chord_type_or_direction}, #{Chordy.tuning.length}" chord = eval(chord_init) end end Chordy.chords.push chord do_print rescue NameError => ne puts "Unknown chord or chord type" puts ne.message puts ne.backtrace rescue Exception => e puts e.class.to_s puts e.message puts e.backtrace end chord end def text text Chordy.chords.push Util::Text.new(text) do_print end def section title="" Chordy.chords.push Util::Section.new(title, Chordy.separator_length) do_print end def separator section end def do_print if Chordy.auto print_chords end end def print_chords lines_to_print = [] chord_index = 0 chords_in_section = 0 tuning_length = Chordy.tuning.length is_done = false is_new_line = true is_even_line_length = (Chordy.line_length % 2) == 0 is_next_chord_section_or_text = false to_print_start_chords = false to_skip_end_strings = false chords = Chordy.chords.to_a chords.select { |c| c.is_a? Util::Section } .map { |s| s.separator_length = Chordy.separator_length } while !is_done if is_new_line or to_print_start_chords if chords[chord_index].is_a? Chord start_strings = Chord.start_of_strings Chordy.tuning, Chordy.start_delimiter, Chordy.low_to_high start_strings.each { |s| lines_to_print.push s } end to_print_start_chords = false is_new_line = false end last_chord_lines = lines_to_print.last(tuning_length + 1) curr_chord = chords[chord_index] if curr_chord.is_a? Chord last_chord_lines.each_with_index do |line, i| if i == tuning_length line << curr_chord.print_flag else line << curr_chord.print_string_at(i, Chordy.chord_space, Chordy.low_to_high) end end chords_in_section = chords_in_section + 1 to_skip_end_strings = false elsif (chords[chord_index].is_a? Util::Text) or (chords[chord_index].is_a? Util::Section) lines_to_print.push chords[chord_index].to_s to_skip_end_strings = true chords_in_section = 0 if chords[chord_index + 1].is_a? Chord to_print_start_chords = true end end chord_index = chord_index + 1 if (chords[chord_index].is_a? Util::Text) or (chords[chord_index].is_a? Util::Section) is_next_chord_section_or_text = true else is_next_chord_section_or_text = false end if ((chords_in_section % Chordy.line_length) == 0) or (chord_index == chords.length) or is_next_chord_section_or_text if to_skip_end_strings to_skip_end_strings = false else end_strings = Chord.end_of_strings Chordy.tuning, Chordy.end_delimiter last_chord_lines.each_with_index do |line, i| line << end_strings[i] end end # start the next actual line lines_to_print.push "" is_new_line = true elsif (chords_in_section % Chordy.line_length) == (Chordy.line_length / 2) and is_even_line_length if Chordy.show_half_length_delimiter last_chord_lines.each_with_index do |line, i| line << Chord.print_half_length_string_at(i, Chordy.tuning, Chordy.half_length_delimiter, Chordy.chord_space) end end end if is_next_chord_section_or_text is_new_line = false end if chord_index >= chords.length is_done = true end end # print the buffer lines_to_print.each { |l| puts l } nil end def print_chords_to_string sio = StringIO.new old_stdout, $stdout = $stdout, sio print_chords $stdout = old_stdout sio.string end Chord::CHORD_FLAGS.each_with_index do |name,i| eval <<-ENDOFEVAL def #{name} saved_auto = Chordy.auto saved_chord_index = Chordy.chords.length Chordy.auto = false begin chord = yield if block_given? num_new_chords = Chordy.chords.length - saved_chord_index Chordy.chords.last(num_new_chords).each { |c| c.send :#{name} } rescue Exception => e puts e.class.to_s puts e.message puts e.backtrace end Chordy.auto = saved_auto do_print chord end ENDOFEVAL if name != "dont_play" eval <<-ENDOFEVAL def play_#{name} chords, chord_type_or_direction=:major #{name} { play chords, chord_type_or_direction } end ENDOFEVAL end end Chord.short_chords.values.each do |s| short_chord_name = s.to_s eval <<-ENDOFEVAL def #{short_chord_name} :#{s} end ENDOFEVAL end end include Chordy
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy/chord.rb
lib/chordy/chord.rb
module Chordy class Chord CHORD_FLAGS = %w(mute harmonic bend pull hammer_down slide_down slide_up dont_play vibrato) def self.all_flags CHORD_FLAGS.to_a end # gets number of high strings in a tuning by approximation def self.get_num_high_strings length (length / 3.0).ceil end def self.start_of_strings tuning, start_delimiter, low_to_high num_strings = tuning.length num_high_strings = get_num_high_strings num_strings strings_in_downcase = tuning.map { |s| s.downcase } high_strings = strings_in_downcase.last(num_high_strings) low_strings = strings_in_downcase.first(num_strings - num_high_strings).map { |s| s.capitalize } strings_range = low_strings + high_strings if !low_to_high strings_range = strings_range.reverse end strings_to_print = strings_range.map { |s| s.rjust(2) + start_delimiter.rjust(2) } strings_to_print + [ " " * 4 ] end def self.end_of_strings tuning, end_delimiter num_strings = tuning.length ([ end_delimiter ] * num_strings) + [ "" ] end def self.print_half_length_string_at string_pos, tuning, half_length_delimiter, chord_space if string_pos == tuning.length "".rjust(2) else half_length_delimiter.rjust(2, chord_space) end end def self.short_chords { :M => :major, :m => :minor, :_7 => :dominant_7, :_7_5 => :dominant_7_5, :_9 => :diminished_9, :M6 => :major_6, :M7 => :major_7, :M9 => :major_9, :m5 => :diminished_5, :m6 => :minor_6, :m7 => :minor_7, :m7_5 => :half_diminished_7, :mM7 => :minor_major_7, :aug5 => :augmented_5, :aug7 => :augmented_7, :aug7_5 => :augmented_major_7, :dim => :diminished_7, :dim7 => :diminished_7, :dim5 => :diminished_5, :dim9 => :diminished_9, :sus => :suspended_4, :sus4 => :suspended_4, :sus7 => :suspended_7, } end def initialize chord, strings @strings = [-1] * strings pad_low = false if chord.instance_of? String or chord.instance_of? Symbol short_chords = Chord.short_chords if short_chords.key? chord chord_strings = play short_chords[chord] @type = short_chords[chord] else chord_strings = play chord.to_sym @type = chord.to_sym end pad_low = true elsif chord.instance_of? Array chord_strings = chord.to_a end @strings = chord_strings pad_or_trim strings, pad_low @flags = 0 end def pad_or_trim length, pad_low if @strings.length > length @strings = @strings.last length elsif @strings.length < length diff = length - @strings.length if pad_low first = @strings.first min = @strings.min # play as bar chord bar_chord_string = ((first == min) and (min > 0) and (first > 0)) ? first : -1 @strings = ([bar_chord_string] * diff) + @strings else @strings = @strings + [-1] * diff end self end end def play chord_type method_for_chord_type = "play_" + chord_type.to_s chord = eval(method_for_chord_type) if chord.length > @strings.length chord = chord.last @strings.length end chord end def reverse_strings! @strings = @strings.reverse self end def strings @strings end def flags @flags end def has_flag flag (@flags & flag) == flag end def add_flag flag @flags = @flags | flag self end def get_index_to_print i, low_to_high if low_to_high i else @strings.length - i - 1 end end def print_string_at i, chord_space, low_to_high=false to_print = chord_space index_to_print = get_index_to_print i, low_to_high string = @strings[index_to_print] if string != -1 to_print = string.to_s end to_print = to_print.rjust(3, chord_space) if @flags != 0 to_print = print_string_with_flag_at index_to_print, to_print, chord_space end to_print.ljust(4, chord_space) end def print_string_with_flag_at i, printed_string, chord_space to_print = printed_string string = @strings[i] if string != -1 if has_flag DONT_PLAY to_print = "x".rjust(3, chord_space) elsif has_flag BEND to_print = to_print + "b" elsif has_flag HAMMER_DOWN to_print = to_print + "h" elsif has_flag PULL to_print = to_print + "p" elsif has_flag SLIDE_UP to_print = to_print + "/" elsif has_flag SLIDE_DOWN to_print = to_print + "\\" elsif has_flag VIBRATO to_print = to_print + "~" end end to_print end # for printing flags on diff line def print_flag to_print = "" if has_flag MUTE to_print = "M" elsif has_flag HARMONIC to_print = "H" end to_print.rjust(3).ljust(4) end end Chord::CHORD_FLAGS.each_with_index do |name,i| Chord.class_eval <<-ENDOFEVAL #{name.upcase} = #{2**i} def #{name} add_flag #{name.upcase} self end ENDOFEVAL end Chord.short_chords.values.each do |chord_type| chord_type_str = chord_type.to_s Chord.class_eval <<-ENDOFEVAL def play_#{chord_type_str} [-1] * 6 end ENDOFEVAL end end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy/util/text.rb
lib/chordy/util/text.rb
module Util class Text < String end end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy/util/section.rb
lib/chordy/util/section.rb
module Util class Section attr_accessor :separator_length def initialize(title="", separator_length=40) @title = title @separator_length = separator_length end def to_s title_str = @title.to_s title_str.rjust(title_str.length + 2, "-").ljust(@separator_length, "-") end end end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy/util/tuning.rb
lib/chordy/util/tuning.rb
module Util module Tuning def is_tuning? tuning Tuning.instance_methods.include? tuning.to_s true end def tuning_6_standard ["e", "a", "d", "g", "b", "e"] end def tuning_6_a ["a", "d", "g", "c", "e", "a"] end def tuning_6_b ["b", "e", "a", "d", "f#", "b"] end def tuning_6_c ["c", "f", "a#", "d#", "g", "c"] end def tuning_6_d ["d", "g", "c", "f", "a", "d"] end def tuning_6_drop_a ["a", "e", "a", "d", "f#", "b"] end def tuning_6_drop_c ["c", "g", "c", "f", "a", "d"] end def tuning_6_drop_d ["d", "a", "d", "g", "b", "e"] end def tuning_7_standard ["b", "e", "a", "d", "g", "b", "e"] end def tuning_7_a ["a", "d", "g", "c", "f", "a", "d"] end def tuning_7_a_sharp ["a#", "d#", "g#", "c#", "f#", "a#", "d#"] end def tuning_7_c ["c", "f", "a#", "d#", "g#", "c", "f"] end def tuning_7_d ["d", "g", "c", "f", "a#", "d", "g"] end def tuning_7_drop_a ["a", "e", "a", "d", "f#", "b", "e"] end def tuning_7_drop_g ["g", "d", "g", "c", "f", "a", "d"] end def tuning_7_drop_g_sharp ["g#", "d#", "g#", "c#", "f#", "a#", "d#"] end def tuning_8_standard ["f#", "b", "e", "a", "d", "g", "b", "e"] end def tuning_8_a ["a", "d", "g", "c", "f", "a", "d", "g"] end def tuning_8_e ["e", "a", "d", "g", "c", "f", "a", "d"] end def tuning_8_f ["fb", "bb", "eb", "ab", "db", "gb", "bb", "eb"] end def tuning_8_drop_d_sharp ["eb", "bb", "eb", "ab", "db", "gb", "bb", "eb"] end def tuning_8_drop_e ["e", "b", "e", "a", "d", "g", "b", "e"] end alias :tuning_standard :tuning_6_standard alias :tuning_a :tuning_6_a alias :tuning_b :tuning_6_b alias :tuning_c :tuning_6_c alias :tuning_d :tuning_6_d alias :tuning_drop_a :tuning_6_drop_a alias :tuning_drop_c :tuning_6_drop_c alias :tuning_drop_d :tuning_6_drop_d alias :tuning_7 :tuning_7_standard alias :tuning_7_a! :tuning_7_a_sharp alias :tuning_7_drop_g! :tuning_7_drop_g_sharp alias :tuning_8_drop_d! :tuning_8_drop_d_sharp end end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy/chords/e.rb
lib/chordy/chords/e.rb
require File.join(File.dirname(__FILE__), '..', 'chord') module Chordy class E < Chord def play_major [0, 2, 2, 1, 0, 0] end def play_minor [0, 2, 2, 0, 0, 0] end def play_dominant_7 [0, 2, 2, 1, 3, 0] end def play_dominant_7_5 [-1, -1, 2, 3, 3, 4] end def play_major_6 [0, 2, 2, 1, 2, 0] end def play_major_7 [0, 2, 1, 1, 0, 0] end def play_major_9 [0, 2, 0, 1, 0, 2] end def play_minor_6 [0, 2, 2, 0, 2, 0] end def play_minor_7 [0, 2, 0, 0, 0, 0] end def play_half_diminished_7 [0, 1, 0, 0, 3, 0] end def play_minor_major_7 [0, 2, 1, 0, 0, 0] end def play_augmented_5 [0, -1, 2, 1, 1, 0] end def play_augmented_7 [0, 2, 0, 1, 1, 0] end def play_augmented_major_7 [0, -1, 1, 1, 1, 0] end def play_diminished_5 [3, -1, 5, 3, 5, 3] end def play_diminished_7 [0, 1, 2, 0, 2, 0] end def play_diminished_9 [0, 2, 0, 1, 0, 1] end def play_suspended_4 [0, 2, 2, 2, 0, 0] end def play_suspended_7 [0, 2, 0, 2, 0, 0] end end end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy/chords/d_sharp.rb
lib/chordy/chords/d_sharp.rb
require File.join(File.dirname(__FILE__), '..', 'chord') module Chordy class DSharp < Chord def play_major [-1, 1, 1, 3, 4, 3] end def play_minor [-1, 1, 1, 3, 4, 2] end def play_dominant_7 [-1, 1, 1, 3, 2, 3] end def play_dominant_7_5 [-1, 0, 1, 2, 2, 3] end def play_major_6 [-1, 1, 1, 3, 1, 3] end def play_major_7 [-1, 1, 1, 3, 3, 3] end def play_major_9 [1, 1, 1, 3, 2, 3] end def play_minor_6 [-1, 1, 1, 3, 1, 2] end def play_minor_7 [-1, 1, 1, 3, 2, 2] end def play_half_diminished_7 [2, -1, 1, 2, 2, 2] end def play_minor_major_7 [-1, 1, 1, 3, 3, 2] end def play_augmented_5 [3, 2, 1, 0, 0, 3] end def play_augmented_7 [-1, -1, 1, 4, 2, 3] end def play_augmented_major_7 [-1, 2, 1, 0, 3, 3] end def play_diminished_5 [2, -1, 4, 2, 4, 2] end def play_diminished_7 [-1, 0, 1, 2, 1, 2] end def play_diminished_9 [0, 1, 1, 0, 2, 0] end def play_suspended_4 [-1, 1, 1, 1, 4, 4] end def play_suspended_7 [-1, 1, 1, 1, 2, 4] end end EFlat = DSharp end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy/chords/c.rb
lib/chordy/chords/c.rb
require File.join(File.dirname(__FILE__), '..', 'chord') module Chordy class C < Chord def play_major [3, 3, 2, 0, 1, 0] end def play_minor [-1, 3, 1, 0, 4, 3] end def play_dominant_7 [0, 3, 2, 3, 1, 0] end def play_dominant_7_5 [-1, 1, 2, 3, 1, 2] end def play_major_6 [0, 3, 2, 1, 1, 0] end def play_major_7 [0, 3, 2, 0, 0, 0] end def play_major_9 [0, 3, 2, 3, 3, 0] end def play_minor_6 [-1, 3, 1, 2, 1, 3] end def play_minor_7 [-1, 1, 1, 3, 1, 3] end def play_half_diminished_7 [-1, 1, 1, 3, 1, 2] end def play_minor_major_7 [-1, 2, 1, 0, 0, 3] end def play_augmented_5 [0, 3, 2, 1, 1, 0] end def play_augmented_7 [-1, 1, 2, 3, 1, 4] end def play_augmented_major_7 [0, 3, 2, 1, 0, 0] end def play_diminished_5 [-1, -1, 4, 5, 4, 2] end def play_diminished_7 [-1, -1, 1, 2, 1, 2] end def play_diminished_9 [-1, 3, 2, 3, 2, 3] end def play_suspended_4 [3, 3, 3, 0, 1, 1] end def play_suspended_7 [1, 1, 3, 3, 1, 1] end end end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy/chords/g_sharp.rb
lib/chordy/chords/g_sharp.rb
require File.join(File.dirname(__FILE__), '..', 'chord') module Chordy class GSharp < Chord def play_major [4, 3, 1, 1, 1, 4] end def play_minor [-1, 2, 1, 4, 4, 4] end def play_dominant_7 [4, 3, 1, 1, 1, 2] end def play_dominant_7_5 [-1, -1, 0, 1, 1, 2] end def play_major_6 [4, 3, 1, 1, 1, 1] end def play_major_7 [-1, 3, 1, 1, 1, 3] end def play_major_9 [-1, 1, 1, 1, 1, 2] end def play_minor_6 [-1, -1, 1, 1, 0, 1] end def play_minor_7 [0, 0, 2, 2, 1, 3] end def play_half_diminished_7 [2, 2, 0, 1, 0, 2] end def play_minor_major_7 [-1, -1, 1, 1, 0, 3] end def play_augmented_5 [0, 3, 2, 1, 1, 0] end def play_augmented_7 [-1, 3, 2, 1, 1, 2] end def play_augmented_major_7 [0, 3, 2, 1, 1, 3] end def play_diminished_5 [4, 5, 0, 4, 3, 4] end def play_diminished_7 [-1, -1, 0, 1, 0, 1] end def play_diminished_9 [2, 0, 1, 1, 1, 2] end def play_suspended_4 [4, 4, 6, 6, 4, 4] end def play_suspended_7 [4, 4, 4, 6, 4, 4] end end AFlat = GSharp end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy/chords/g.rb
lib/chordy/chords/g.rb
require File.join(File.dirname(__FILE__), '..', 'chord') module Chordy class G < Chord def play_major [3, 2, 0, 0, 0, 3] end def play_minor [-1, 1, 0, 3, 3, 3] end def play_dominant_7 [3, 2, 0, 0, 0, 1] end def play_dominant_7_5 [-1, -1, 3, 4, 2, 3] end def play_major_6 [3, 2, 0, 0, 0, 0] end def play_major_7 [3, 2, 0, 0, 0, 2] end def play_major_9 [0, 0, 0, 0, 0, 1] end def play_minor_6 [0, 1, 0, 0, 3, 0] end def play_minor_7 [3, 5, 3, 3, 3, 3] end def play_half_diminished_7 [3, 4, 3, 3, 6, 3] end def play_minor_major_7 [3, 5, 4, 3, 3, 3] end def play_augmented_5 [3, 2, 1, 0, 0, 3] end def play_augmented_7 [3, 2, 1, 0, 0, 1] end def play_augmented_major_7 [3, 2, 1, 0, 0, 3] end def play_diminished_5 [3, 4, 0, 3, 2, 3] end def play_diminished_7 [0, 1, 2, 0, 2, 0] end def play_diminished_9 [-1, 2, 3, 1, 0, 3] end def play_suspended_4 [3, 3, 0, 0, 1, 3] end def play_suspended_7 [3, 3, 0, 0, 1, 1] end end end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy/chords/f_sharp.rb
lib/chordy/chords/f_sharp.rb
require File.join(File.dirname(__FILE__), '..', 'chord') module Chordy class FSharp < Chord def play_major [2, 4, 4, 3, 2, 2] end def play_minor [2, 4, 4, 2, 2, 2] end def play_dominant_7 [2, 4, 2, 3, 2, 2] end def play_dominant_7_5 [-1, -1, 2, 3, 1, 2] end def play_major_6 [-1, 4, 4, 6, 4, 6] end def play_major_7 [2, 4, 3, 3, 2, 2] end def play_major_9 [2, 4, 2, 3, 2, 4] end def play_minor_6 [-1, 4, 4, 6, 4, 5] end def play_minor_7 [2, 4, 2, 2, 2, 2] end def play_half_diminished_7 [2, 3, 2, 2, 5, 2] end def play_minor_major_7 [2, 4, 3, 2, 2, 2] end def play_augmented_5 [2, -1, 4, 3, 3, 2] end def play_augmented_7 [2, 4, 2, 3, 3, 2] end def play_augmented_major_7 [-1, -1, 3, 3, 3, 2] end def play_diminished_5 [2, 0, 4, 2, 1, 2] end def play_diminished_7 [2, 3, 4, 2, 4, 2] end def play_diminished_9 [2, 4, 2, 3, 2, 3] end def play_suspended_4 [2, 2, 4, 4, 2, 2] end def play_suspended_7 [2, 4, 2, 4, 2, 2] end end GFlat = FSharp end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy/chords/d.rb
lib/chordy/chords/d.rb
require File.join(File.dirname(__FILE__), '..', 'chord') module Chordy class D < Chord def play_major [-1, 0, 0, 2, 3, 2] end def play_minor [-1, 0, 0, 2, 3, 1] end def play_dominant_7 [-1, 0, 0, 2, 1, 2] end def play_dominant_7_5 [-1, -1, 0, 1, 1, 2] end def play_major_6 [-1, 0, 0, 2, 0, 2] end def play_major_7 [-1, 0, 0, 2, 2, 2] end def play_major_9 [0, 0, 0, 2, 1, 2] end def play_minor_6 [-1, 0, 0, 2, 0, 1] end def play_minor_7 [-1, 0, 0, 2, 1, 1] end def play_half_diminished_7 [1, -1, 0, 1, 1, 1] end def play_minor_major_7 [-1, 0, 0, 2, 2, 1] end def play_augmented_5 [2, -1, 4, 3, 3, 2] end def play_augmented_7 [-1, -1, 0, 3, 1, 2] end def play_augmented_major_7 [2, 5, 4, 3, 2, 2] end def play_diminished_5 [1, -1, 3, 1, 3, 1] end def play_diminished_7 [-1, -1, 0, 1, 0, 1] end def play_diminished_9 [0, 0, 1, 2, 1, 2] end def play_suspended_4 [-1, 0, 0, 2, 3, 3] end def play_suspended_7 [-1, 0, 0, 2, 1, 3] end end end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy/chords/c_sharp.rb
lib/chordy/chords/c_sharp.rb
require File.join(File.dirname(__FILE__), '..', 'chord') module Chordy class CSharp < Chord def play_major [1, 4, 3, 1, 2, 1] end def play_minor [0, -1, 2, 1, 2, 4] end def play_dominant_7 [1, 2, 3, 1, 2, 1] end def play_dominant_7_5 [-1, 2, 3, 4, 2, 3] end def play_major_6 [1, 1, 3, 1, 2, 1] end def play_major_7 [1, 4, 3, 1, 1, 1] end def play_major_9 [1, 2, 1, 1, 2, 1] end def play_minor_6 [0, 4, 2, 3, 2, 4] end def play_minor_7 [0, 2, 2, 4, 2, 4] end def play_half_diminished_7 [0, 2, 2, 4, 2, 3] end def play_minor_major_7 [0, 3, 2, 1, 1, 4] end def play_augmented_5 [-1, 0, 3, 2, 2, 1] end def play_augmented_7 [-1, 2, 3, 4, 2, 5] end def play_augmented_major_7 [1, 4, 3, 2, 1, 1] end def play_diminished_5 [0, -1, 2, 0, 2, 3] end def play_diminished_7 [-1, -1, 2, 3, 2, 3] end def play_diminished_9 [-1, 4, 3, 4, 3, 4] end def play_suspended_4 [4, 4, 6, 6, 7, 4] end def play_suspended_7 [2, 2, 4, 4, 2, 2] end end DFlat = CSharp end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy/chords/a.rb
lib/chordy/chords/a.rb
require File.join(File.dirname(__FILE__), '..', 'chord') module Chordy class A < Chord def play_major [0, 0, 2, 2, 2, 0] end def play_minor [0, 0, 2, 2, 1, 0] end def play_dominant_7 [0, 0, 2, 0, 2, 0] end def play_dominant_7_5 [-1, 0, 1, 0, 2, 3] end def play_major_6 [0, 0, 2, 2, 2, 2] end def play_major_7 [0, 0, 2, 1, 2, 0] end def play_major_9 [-1, 2, 2, 2, 2, 3] end def play_minor_6 [2, 0, 2, 2, 1, 2] end def play_minor_7 [0, 0, 2, 0, 1, 0] end def play_half_diminished_7 [-1, 0, 1, 0, 1, 3] end def play_minor_major_7 [0, 0, 2, 1, 1, 0] end def play_augmented_5 [1, 0, 3, 2, 2, 1] end def play_augmented_7 [1, 4, 3, 0, 2, 1] end def play_augmented_major_7 [-1, 0, -1, 1, 2, 1] end def play_diminished_5 [5, 6, 7, 5, 4, 5] end def play_diminished_7 [-1, -1, 1, 2, 1, 2] end def play_diminished_9 [2, -1, 5, 3, 2, 5] end def play_suspended_4 [0, 0, 2, 2, 3, 0] end def play_suspended_7 [0, 0, 2, 0, 3, 0] end end end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy/chords/a_sharp.rb
lib/chordy/chords/a_sharp.rb
require File.join(File.dirname(__FILE__), '..', 'chord') module Chordy class ASharp < Chord def play_major [1, 1, 3, 3, 3, 1] end def play_minor [1, 1, 3, 3, 2, 1] end def play_dominant_7 [1, 1, 3, 1, 3, 1] end def play_dominant_7_5 [0, 1, 2, 1, 3, 4] end def play_major_6 [1, 1, 3, 3, 3, 3] end def play_major_7 [1, 1, 3, 2, 3, 1] end def play_major_9 [-1, 1, 0, 1, 1, 1] end def play_minor_6 [-1, -1, 3, 3, 2, 3] end def play_minor_7 [1, 1, 3, 1, 2, 1] end def play_half_diminished_7 [1, 1, 2, 1, 2, 4] end def play_minor_major_7 [1, 1, 3, 2, 2, 1] end def play_augmented_5 [2, -1, 4, 3, 3, 2] end def play_augmented_7 [-1, 1, 4, 1, 3, 2] end def play_augmented_major_7 [-1, 1, 0, 2, 3, 2] end def play_diminished_5 [0, 1, 2, 3, 2, 0] end def play_diminished_7 [-1, -1, 2, 3, 2, 3] end def play_diminished_9 [1, 1, 0, 1, 0, 1] end def play_suspended_4 [1, 1, 1, 3, 4, 1] end def play_suspended_7 [1, 1, 1, 1, 3, 1] end end BFlat = ASharp end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy/chords/f.rb
lib/chordy/chords/f.rb
require File.join(File.dirname(__FILE__), '..', 'chord') module Chordy class F < Chord def play_major [1, 3, 3, 2, 1, 1] end def play_minor [1, 3, 3, 1, 1, 1] end def play_dominant_7 [1, 3, 1, 2, 1, 1] end def play_dominant_7_5 [1, 0, 1, 2, 0, 1] end def play_major_6 [-1, 3, 3, 5, 3, 5] end def play_major_7 [1, 3, 2, 2, 1, 1] end def play_major_9 [1, 3, 1, 2, 1, 3] end def play_minor_6 [1, 3, 3, 1, 3, 1] end def play_minor_7 [1, 3, 1, 1, 1, 1] end def play_half_diminished_7 [1, 2, 1, 1, 4, 1] end def play_minor_major_7 [1, 3, 2, 1, 1, 1] end def play_augmented_5 [1, -1, 3, 2, 2, 1] end def play_augmented_7 [1, 3, 1, 2, 2, 1] end def play_augmented_major_7 [0, 0, 2, 2, 2, 1] end def play_diminished_5 [1, 2, 3, 1, 0, 1] end def play_diminished_7 [1, 2, 3, 1, 3, 1] end def play_diminished_9 [1, 3, 1, 2, 1, 2] end def play_suspended_4 [1, 1, 3, 3, 1, 1] end def play_suspended_7 [1, 3, 1, 3, 1, 1] end end end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
darth10/chordy
https://github.com/darth10/chordy/blob/341faceca396bc956a9609588f5058b7066311fd/lib/chordy/chords/b.rb
lib/chordy/chords/b.rb
require File.join(File.dirname(__FILE__), '..', 'chord') module Chordy class B < Chord def play_major [2, 2, 4, 4, 4, 2] end def play_minor [2, 2, 4, 4, 3, 2] end def play_dominant_7 [2, 2, 4, 2, 4, 2] end def play_dominant_7_5 [-1, 2, 1, 2, 0, 1] end def play_major_6 [2, 2, 4, 4, 4, 4] end def play_major_7 [2, 2, 4, 3, 4, 2] end def play_major_9 [-1, 2, 1, 2, 2, 2] end def play_minor_6 [-1, 2, 0, 1, 3, 2] end def play_minor_7 [-1, 2, 0, 2, 0, 2] end def play_half_diminished_7 [1, 0, 0, 2, 0, 1] end def play_minor_major_7 [2, 2, 4, 3, 3, 2] end def play_augmented_5 [3, -1, 5, 4, 4, 3] end def play_augmented_7 [-1, 2, 1, 2, 0, 3] end def play_augmented_major_7 [-1, 2, -1, 3, 4, 3] end def play_diminished_5 [1, -1, 3, 4, 3, 1] end def play_diminished_7 [-1, -1, 0, 1, 0, 1] end def play_diminished_9 [-1, 2, 1, 2, 1, 2] end def play_suspended_4 [2, 2, 4, 4, 5, 2] end def play_suspended_7 [2, 2, 2, 2, 5, 2] end end end
ruby
MIT
341faceca396bc956a9609588f5058b7066311fd
2026-01-04T17:51:15.304937Z
false
zverok/hm
https://github.com/zverok/hm/blob/cd0ec27397c465f21a90d193be75538d24c6d8ae/spec/hm_spec.rb
spec/hm_spec.rb
RSpec.describe Hm do subject(:hm) { described_class.new(data) } def result_of(method) ->(*args) { if args.last.is_a?(Proc) hm.public_send(method, *args[0..-2], &args.last).to_h else hm.public_send(method, *args).to_h end } end let(:data) { { order: { time: Time.parse('2017-03-01 14:30'), items: [ {title: 'Beer', price: 10.0}, {title: 'Beef', price: 5.0}, {title: 'Potato', price: 7.8} ] } } } describe '#dig' do subject { hm.method(:dig) } context 'regular' do its_call(:order, :time) { is_expected.to ret Time.parse('2017-03-01 14:30') } its_call(:order, :items, 0, :price) { is_expected.to ret 10.0 } its_call(:order, :total) { is_expected.to ret nil } its_call(:order, :items, 4, :price) { is_expected.to ret nil } its_call(:order, :items, 2, :price, :count) { is_expected.to raise_error TypeError } end context 'wildcards' do its_call(:order, :*) { is_expected.to ret [ Time.parse('2017-03-01 14:30'), [ {title: 'Beer', price: 10.0}, {title: 'Beef', price: 5.0}, {title: 'Potato', price: 7.8} ] ] } its_call(:order, :items, :*, :price) { is_expected.to ret [10.0, 5.0, 7.8] } its_call(:order, :items, :*, :id) { is_expected.to ret [nil, nil, nil] } its_call(:order, :time, :*) { is_expected.to raise_error TypeError } end end describe '#dig!' do subject { hm.method(:dig!) } context 'regular' do its_call(:order, :time) { is_expected.to ret Time.parse('2017-03-01 14:30') } its_call(:order, :items, 0, :price) { is_expected.to ret 10.0 } its_call(:order, :total) { is_expected.to raise_error KeyError } its_call(:order, :items, 4, :price) { is_expected.to raise_error 'Key not found: :order/:items/4' } its_call(:order, :items, 2, :price, :count) { is_expected.to raise_error TypeError } end context 'wildcards' do its_call(:order, :*) { is_expected.to ret [ Time.parse('2017-03-01 14:30'), [ {title: 'Beer', price: 10.0}, {title: 'Beef', price: 5.0}, {title: 'Potato', price: 7.8} ] ] } its_call(:order, :items, :*, :price) { is_expected.to ret [10.0, 5.0, 7.8] } its_call(:order, :items, :*, :id) { is_expected.to raise_error KeyError } its_call(:order, :time, :*) { is_expected.to raise_error TypeError } end it 'supports default block' do expect(hm.dig!(:order, :total) { 111 }).to eq 111 end end describe '#bury' do subject { result_of(:bury) } let(:data) { {a: {b: 1, is: [{x: 1, y: 2}]}} } context 'regular' do its_call(:a, :n, 3) { is_expected.to ret(a: {b: 1, is: [{x: 1, y: 2}], n: 3}) } its_call(:a, :n, :c, 3) { is_expected.to ret(a: {b: 1, is: [{x: 1, y: 2}], n: {c: 3}}) } its_call(:a, :is, 0, 'replaced') { is_expected.to ret(a: {b: 1, is: ['replaced']}) } its_call(:a, :is, 1, 'inserted') { is_expected.to ret(a: {b: 1, is: [{x: 1, y: 2}, 'inserted']}) } end context 'wildcards' do its_call(:a, :*, 3) { is_expected.to ret(a: {b: 3, is: 3}) } its_call(:a, :is, :*, 'x') { is_expected.to ret(a: {b: 1, is: ['x']}) } its_call(:a, :is, :*, :t, 'x') { is_expected.to ret(a: {b: 1, is: [{x: 1, y: 2, t: 'x'}]}) } end end describe '#transform' do subject { result_of(:transform) } let(:data) { {a: {b: 1, is: [{x: 1, y: 2}, {x: 4, y: 5}]}} } context 'regular' do its_call(%i[a b] => %i[a bb]) { is_expected.to ret(a: {bb: 1, is: [{x: 1, y: 2}, {x: 4, y: 5}]}) } its_call(%i[a b] => %i[a bb], [:a, :is, 0] => %i[a first]) { is_expected.to ret(a: {bb: 1, is: [{x: 4, y: 5}], first: {x: 1, y: 2}}) } end context 'wildcards' do its_call(%i[a *] => %i[a x]) { is_expected.to ret(a: {x: [1, [{x: 1, y: 2}, {x: 4, y: 5}]]}) } its_call(%i[a *] => %i[a x *]) { is_expected.to ret(a: {x: {b: 1, is: [{x: 1, y: 2}, {x: 4, y: 5}]}}) } its_call(%i[a is * y] => %i[a is * yy]) { is_expected.to ret(a: {b: 1, is: [{x: 1, yy: 2}, {x: 4, yy: 5}]}) } its_call(%i[a is * y] => %i[a ys *]) { is_expected.to ret(a: {b: 1, is: [{x: 1}, {x: 4}], ys: [2, 5]}) } its_call(%i[a is * y] => %i[a ys * m]) { is_expected.to ret(a: {b: 1, is: [{x: 1}, {x: 4}], ys: [{m: 2}, {m: 5}]}) } end it 'supports value processing' do expect(hm.transform(%i[a is * y] => :ys, &:to_s).to_h) .to eq(a: {b: 1, is: [{x: 1}, {x: 4}]}, ys: %w[2 5]) end end describe '#update' do subject { result_of(:update) } let(:data) { {a: {b: 1, is: [{x: 1, y: 2}, {x: 4, y: 5}]}} } its_call(%i[a b] => %i[a bb]) { is_expected.to ret(a: {b: 1, bb: 1, is: [{x: 1, y: 2}, {x: 4, y: 5}]}) } end describe '#transform_values' do subject { result_of(:transform_values) } let(:data) { {a: {b: 1, is: [{x: 1, y: 2}, {x: 4, y: 5}]}} } its_call(:to_s.to_proc) { is_expected.to ret(a: {b: '1', is: [{x: '1', y: '2'}, {x: '4', y: '5'}]}) } its_call(%i[a is * y], :to_s.to_proc) { is_expected.to ret(a: {b: 1, is: [{x: 1, y: '2'}, {x: 4, y: '5'}]}) } its_call(%i[a is * *], :to_s.to_proc) { is_expected.to ret(a: {b: 1, is: [{x: '1', y: '2'}, {x: '4', y: '5'}]}) } its_call(%i[a is *], :to_s.to_proc) { is_expected.to ret(a: {b: 1, is: ['{:x=>1, :y=>2}', '{:x=>4, :y=>5}']}) } its_call(:a, ->(*) { 1 }) { is_expected.to ret(a: 1) } end describe '#except' do subject { result_of(:except) } let(:data) { {a: {b: 1, is: [{x: 1, y: 2}, {x: 4, y: 5}]}} } its_call(%i[a is * y]) { is_expected.to ret(a: {b: 1, is: [{x: 1}, {x: 4}]}) } its_call([:a, :is, 1]) { is_expected.to ret(a: {b: 1, is: [{x: 1, y: 2}]}) } end describe '#slice' do subject { result_of(:slice) } let(:data) { {a: {b: 1, is: [{x: 1, y: 2}, {x: 4, y: 5}]}} } its_call(%i[a is * y]) { is_expected.to ret(a: {is: [{y: 2}, {y: 5}]}) } its_call([:a, :is, 1, :y]) { is_expected.to ret(a: {is: [nil, {y: 5}]}) } context 'with nils in data' do let(:data) { {a: {b: nil, is: [{x: 1, y: nil}, {x: 4, y: 5}]}, c: nil} } its_call(:c) { is_expected.to ret(c: nil) } end end describe '#transform_keys' do subject { result_of(:transform_keys) } let(:data) { {a: {b: 1, is: [{x: 1, y: 2}, {x: 4, y: 5}]}} } its_call(:to_s.to_proc) { is_expected.to ret('a' => {'b' => 1, 'is' => [{'x' => 1, 'y' => 2}, {'x' => 4, 'y' => 5}]}) } its_call(%i[a is * *], :to_s.to_proc) { is_expected.to ret(a: {b: 1, is: [{'x' => 1, 'y' => 2}, {'x' => 4, 'y' => 5}]}) } # TODO: Not sure what will be right thing to do here. Does not work, anyways # its_call(%i[a is *], :succ.to_proc) { # is_expected.to ret(a: {b: 1, is: [nil, {x: 1, y: 2}, {x: 4, y: 5}]}) # } end describe '#compact' do subject { result_of(:compact) } let(:data) { {a: {b: nil, is: [nil, {x: nil, y: 2}, {x: 4, y: 5}, nil]}} } it { is_expected.to ret(a: {is: [{y: 2}, {x: 4, y: 5}]}) } end describe '#cleanup' do subject { result_of(:cleanup) } let(:data) { {a: {b: nil, c: {}, is: [{x: nil, y: 2}, {x: 4, y: ''}, [nil]]}} } it { is_expected.to ret(a: {is: [{y: 2}, {x: 4}]}) } end describe '#select' do subject { result_of(:select) } let(:data) { {a: {b: 1, is: [{x: 1, y: 2}, {x: 4, y: 5}]}} } its_call(->(path, val) { path.last == :y && val > 3 }) { is_expected.to ret(a: {is: [nil, {y: 5}]}) } its_call(%i[a is * y], ->(_, val) { val > 3 }) { is_expected.to ret(a: {is: [nil, {y: 5}]}) } end describe '#reject' do subject { result_of(:reject) } let(:data) { {a: {b: 1, is: [{x: 1, y: 2}, {x: 4, y: 5}]}} } its_call(->(path, val) { path.last == :y && val < 3 }) { is_expected.to ret(a: {b: 1, is: [{x: 1}, {x: 4, y: 5}]}) } its_call(%i[a is * y], ->(_, val) { val < 3 }) { is_expected.to ret(a: {b: 1, is: [{x: 1}, {x: 4, y: 5}]}) } end describe '#reduce' do subject { result_of(:reduce) } let(:data) { {a: {b: 1, is: [{x: 1, y: 2}, {x: 4, y: 5}]}} } its_call({%i[a is * y] => %i[a ys]}, :+.to_proc) { is_expected.to ret(a: {b: 1, is: [{x: 1, y: 2}, {x: 4, y: 5}], ys: 7}) } end describe 'immutability of source' do subject(:data) { {a: {b: nil, is: [{x: 1, y: 2}, {}]}} } before { hm.cleanup } it { is_expected.to eq(a: {b: nil, is: [{x: 1, y: 2}, {}]}) } end describe '#visit' do let(:data) { {a: {b: 1, is: [{x: 1, y: 2}, {x: 4}]}} } it 'works' do found = [] not_found = [] hm.visit(:a, :is, :*, :y, not_found: ->(_, path, _) { not_found << path }) { |_, path, val| found << [path, val] } expect(found).to eq [[[:a, :is, 0, :y], 2]] expect(not_found).to eq [[:a, :is, 1, :y]] end end describe '#partition' do subject { hm.method(:partition) } let(:data) { { points: [{x: 1, y: 2}, {x: 3, y: 4}], total: 5, meta: {next: 3, prev: 1} } } its_call(:total, %i[points * x], %i[meta next]) { is_expected.to ret( [ {total: 5, points: [{x: 1}, {x: 3}], meta: {next: 3}}, {points: [{y: 2}, {y: 4}], meta: {prev: 1}} ] ) } its_call(:points) { is_expected.to ret( [ {points: [{x: 1, y: 2}, {x: 3, y: 4}]}, {total: 5, meta: {prev: 1, next: 3}} ] ) } its_call(%i[points *]) { is_expected.to ret( [ {points: [{x: 1, y: 2}, {x: 3, y: 4}]}, # It slices away everything inside points, but not points: key per se {points: [], total: 5, meta: {prev: 1, next: 3}} ] ) } end end
ruby
MIT
cd0ec27397c465f21a90d193be75538d24c6d8ae
2026-01-04T17:51:19.419456Z
false
zverok/hm
https://github.com/zverok/hm/blob/cd0ec27397c465f21a90d193be75538d24c6d8ae/spec/spec_helper.rb
spec/spec_helper.rb
require 'rspec/its' require 'saharspec' require 'hm' require 'time'
ruby
MIT
cd0ec27397c465f21a90d193be75538d24c6d8ae
2026-01-04T17:51:19.419456Z
false
zverok/hm
https://github.com/zverok/hm/blob/cd0ec27397c465f21a90d193be75538d24c6d8ae/examples/weather.rb
examples/weather.rb
require 'json' require 'pp' $LOAD_PATH.unshift 'lib' require 'hm' data = JSON.parse(File.read('examples/weather.json')) pp data pp Hm.new(data) .transform_keys(&:to_sym) # symbolize all keys .except(:id, :cod, %i[sys id], %i[weather * id]) # remove some system values .transform( %i[main *] => :*, # move all {main: {temp: 1}} to just {temp: 1} %i[sys *] => :*, # same for :sys %i[coord *] => :coord, # gather values for coord.lat, coord.lng into Array in coord: [:weather, 0] => :weather, # move first of :weather Array to just weather: key dt: :timestamp # rename :dt to :timestamp ) .cleanup # remove now empty main: {} and sys: {} hashes .transform_values( :timestamp, :sunrise, :sunset, &Time.method(:at)) # parse timestamps .bury(:weather, :comment, 'BAD') # insert some random new key .to_h
ruby
MIT
cd0ec27397c465f21a90d193be75538d24c6d8ae
2026-01-04T17:51:19.419456Z
false
zverok/hm
https://github.com/zverok/hm/blob/cd0ec27397c465f21a90d193be75538d24c6d8ae/examples/benchmark.rb
examples/benchmark.rb
require 'json' require 'benchmark/ips' $LOAD_PATH.unshift 'lib' require 'hm' DATA = JSON.parse(File.read('examples/weather.json')) def hm Hm.new(DATA) .transform_keys(&:to_sym) .except(:id, :cod, %i[sys id], %i[sys message], %i[weather * id]) .transform( %i[main *] => :*, %i[sys *] => :*, %i[coord *] => :coord, [:weather, 0] => :weather, dt: :timestamp ) .cleanup .transform_values( :timestamp, :sunrise, :sunset, &Time.method(:at)) .bury(:weather, :comment, 'BAD') .to_h end def raw weather = DATA.dig('weather', 0) main = DATA['main'] sys = DATA['sys'] {coord: [DATA.dig('coord', 'lat'), DATA.dig('coord', 'lng')], weather: {main: weather['main'], description: weather['description'], icon: weather['icon'], comment: "BAD"}, base: DATA['base'], visibility: DATA['visibility'], wind: {speed: DATA.dig('wind', 'speed'), deg: DATA.dig('wind', 'deg')}, clouds: {all: DATA.dig('clouds', 'all')}, name: DATA['name'], temp: main['temp'], pressure: main['pressure'], humidity: main['humidity'], temp_min: main['temp_min'], temp_max: main['temp_max'], type: sys['type'], country: sys['country'], sunrise: Time.at(sys['sunrise']), sunset: Time.at(sys['sunset']), timestamp: Time.at(DATA['dt'])} end Benchmark.ips do |b| b.report('hm') { hm } b.report('raw') { raw } b.compare! end
ruby
MIT
cd0ec27397c465f21a90d193be75538d24c6d8ae
2026-01-04T17:51:19.419456Z
false
zverok/hm
https://github.com/zverok/hm/blob/cd0ec27397c465f21a90d193be75538d24c6d8ae/examples/profile.rb
examples/profile.rb
require 'json' require 'ruby-prof' $LOAD_PATH.unshift 'lib' require 'hm' DATA = JSON.parse(File.read('examples/weather.json')) def hm Hm.new(DATA) .transform_keys(&:to_sym) .except(:id, :cod, %i[sys id], %i[sys message], %i[weather * id]) .transform( %i[main *] => :*, %i[sys *] => :*, %i[coord *] => :coord, [:weather, 0] => :weather, dt: :timestamp ) .cleanup .transform_values( :timestamp, :sunrise, :sunset, &Time.method(:at)) .bury(:weather, :comment, 'BAD') .to_h end result = RubyProf.profile do 10_000.times { hm } end RubyProf::GraphHtmlPrinter.new(result).print(File.open('tmp/prof.html', 'w'))
ruby
MIT
cd0ec27397c465f21a90d193be75538d24c6d8ae
2026-01-04T17:51:19.419456Z
false
zverok/hm
https://github.com/zverok/hm/blob/cd0ec27397c465f21a90d193be75538d24c6d8ae/lib/hm.rb
lib/hm.rb
# `Hm` is a wrapper for chainable, terse, idiomatic Hash modifications. # # @example # order = { # 'items' => { # '#1' => {'title' => 'Beef', 'price' => '18.00'}, # '#2' => {'title' => 'Potato', 'price' => '8.20'} # } # } # Hm(order) # .transform_keys(&:to_sym) # .transform(%i[items *] => :items) # .transform_values(%i[items * price], &:to_f) # .reduce(%i[items * price] => :total, &:+) # .to_h # # => {:items=>[{:title=>"Beef", :price=>18.0}, {:title=>"Potato", :price=>8.2}], :total=>26.2} # # @see #Hm class Hm # @private WILDCARD = :* # @note # `Hm.new(collection)` is also available as top-level method `Hm(collection)`. # # @param collection Any Ruby collection that has `#dig` method. Note though, that most of # transformations only work with hashes & arrays, while {#dig} is useful for anything diggable. def initialize(collection) @hash = Algo.deep_copy(collection) end # Like Ruby's [#dig](https://docs.ruby-lang.org/en/2.4.0/Hash.html#method-i-dig), but supports # wildcard key `:*` meaning "each item at this point". # # Each level of data structure should have `#dig` method, otherwise `TypeError` is raised. # # @example # order = {items: [{title: "Beef", price: 18.0}, {title: "Potato", price: 8.2}], total: 26.2} # Hm(order).dig(:items, 0, :title) # # => "Beef" # Hm(order).dig(:items, :*, :title) # # => ["Beef", "Potato"] # Hm(order).dig(:items, 0, :*) # # => ["Beef", 18.0] # Hm(order).dig(:items, :*, :*) # # => [["Beef", 18.0], ["Potato", 8.2]] # Hm(order).dig(:items, 3, :*) # # => nil # Hm(order).dig(:total, :count) # # TypeError: Float is not diggable # # @param path Array of keys. # @return Object found or `nil`, def dig(*path) Algo.visit(@hash, path) { |_, _, val| val } end # Like {#dig!} but raises when key at any level is not found. This behavior can be changed by # passed block. # # @example # order = {items: [{title: "Beef", price: 18.0}, {title: "Potato", price: 8.2}], total: 26.2} # Hm(order).dig!(:items, 0, :title) # # => "Beef" # Hm(order).dig!(:items, 2, :title) # # KeyError: Key not found: :items/2 # Hm(order).dig!(:items, 2, :title) { |collection, path, rest| # puts "At #{path}, #{collection} does not have a key #{path.last}. Rest of path: #{rest}"; # 111 # } # # At [:items, 2], [{:title=>"Beef", :price=>18.0}, {:title=>"Potato", :price=>8.2}] does not have a key 2. Rest of path: [:title] # # => 111 # # @param path Array of keys. # @yieldparam collection Substructure "inside" which we are currently looking # @yieldparam path Path that led us to non-existent value (including current key) # @yieldparam rest Rest of the requested path we'd need to look if here would not be a missing value. # @return Object found or `nil`, def dig!(*path, &not_found) not_found ||= ->(_, pth, _) { fail KeyError, "Key not found: #{pth.map(&:inspect).join('/')}" } Algo.visit(@hash, path, not_found: not_found) { |_, _, val| val } end # Stores value into deeply nested collection. `path` supports wildcards ("store at each matched # path") the same way {#dig} and other methods do. If specified path does not exists, it is # created, with a "rule of thumb": if next key is Integer, Array is created, otherwise it is Hash. # # Caveats: # # * when `:*`-referred path does not exists, just `:*` key is stored; # * as most of transformational methods, `bury` does not created and tested to work with `Struct`. # # @example # order = {items: [{title: "Beef", price: 18.0}, {title: "Potato", price: 8.2}], total: 26.2} # # Hm(order).bury(:items, 0, :price, 16.5).to_h # # => {:items=>[{:title=>"Beef", :price=>16.5}, {:title=>"Potato", :price=>8.2}], :total=>26.2} # # # with wildcard # Hm(order).bury(:items, :*, :discount, true).to_h # # => {:items=>[{:title=>"Beef", :price=>18.0, :discount=>true}, {:title=>"Potato", :price=>8.2, :discount=>true}], :total=>26.2} # # # creating nested structure (note that 0 produces Array item) # Hm(order).bury(:payments, 0, :amount, 20.0).to_h # # => {:items=>[...], :total=>26.2, :payments=>[{:amount=>20.0}]} # # # :* in nested insert is not very useful # Hm(order).bury(:payments, :*, :amount, 20.0).to_h # # => {:items=>[...], :total=>26.2, :payments=>{:*=>{:amount=>20.0}}} # # @param path One key or list of keys leading to the target. `:*` is treated as # each matched subpath. # @param value Any value to store at path # @return [self] def bury(*path, value) Algo.visit( @hash, path, not_found: ->(at, pth, rest) { at[pth.last] = Algo.nest_hashes(value, *rest) } ) { |at, pth, _| at[pth.last] = value } self end # Low-level collection walking mechanism. # # @example # order = {items: [{title: "Beef", price: 18.0}, {title: "Potato"}]} # order.visit(:items, :*, :price, # not_found: ->(at, path, rest) { puts "#{at} at #{path}: nothing here!" } # ) { |at, path, val| puts "#{at} at #{path}: #{val} is here!" } # # {:title=>"Beef", :price=>18.0} at [:items, 0, :price]: 18.0 is here! # # {:title=>"Potato"} at [:items, 1, :price]: nothing here! # # @param path Path to values to visit, `:*` wildcard is supported. # @param not_found [Proc] Optional proc to call when specified path is not found. Params are `collection` # (current sub-collection where key is not found), `path` (current path) and `rest` (the rest # of path we need to walk). # @yieldparam collection Current subcollection we are looking at # @yieldparam path [Array] Current path we are at (in place of `:*` wildcards there are real # keys). # @yieldparam value Current value # @return [self] def visit(*path, not_found: ->(*) {}, &block) Algo.visit(@hash, path, not_found: not_found, &block) self end # Renames input pathes to target pathes, with wildcard support. # # @note # Currently, only one wildcard per each from and to pattern is supported. # # @example # order = {items: [{title: "Beef", price: 18.0}, {title: "Potato", price: 8.2}], total: 26.2} # Hm(order).transform(%i[items * price] => %i[items * price_cents]).to_h # # => {:items=>[{:title=>"Beef", :price_cents=>18.0}, {:title=>"Potato", :price_cents=>8.2}], :total=>26.2} # Hm(order).transform(%i[items * price] => %i[items * price_usd]) { |val| val / 100.0 }.to_h # # => {:items=>[{:title=>"Beef", :price_usd=>0.18}, {:title=>"Potato", :price_usd=>0.082}], :total=>26.2} # Hm(order).transform(%i[items *] => :*).to_h # copying them out # # => {:items=>[], :total=>26.2, 0=>{:title=>"Beef", :price=>18.0}, 1=>{:title=>"Potato", :price=>8.2}} # # @see #transform_keys # @see #transform_values # @see #update # @param keys_to_keys [Hash] Each key-value pair of input hash represents "source path to take # values" => "target path to store values". Each can be single key or nested path, # including `:*` wildcard. # @param processor [Proc] Optional block to process value with while moving. # @yieldparam value # @return [self] def transform(keys_to_keys, &processor) keys_to_keys.each { |from, to| transform_one(Array(from), Array(to), &processor) } self end # Like {#transform}, but copies values instead of moving them (original keys/values are preserved). # # @example # order = {items: [{title: "Beef", price: 18.0}, {title: "Potato", price: 8.2}], total: 26.2} # Hm(order).update(%i[items * price] => %i[items * price_usd]) { |val| val / 100.0 }.to_h # # => {:items=>[{:title=>"Beef", :price=>18.0, :price_usd=>0.18}, {:title=>"Potato", :price=>8.2, :price_usd=>0.082}], :total=>26.2} # # @see #transform_keys # @see #transform_values # @see #transform # @param keys_to_keys [Hash] Each key-value pair of input hash represents "source path to take # values" => "target path to store values". Each can be single key or nested path, # including `:*` wildcard. # @param processor [Proc] Optional block to process value with while copying. # @yieldparam value # @return [self] def update(keys_to_keys, &processor) keys_to_keys.each { |from, to| transform_one(Array(from), Array(to), remove: false, &processor) } self end # Performs specified transformations on keys of input sequence, optionally limited only by specified # pathes. # # Note that when `pathes` parameter is passed, only keys directly matching the pathes are processed, # not entire sub-collection under this path. # # @example # order = {items: [{title: "Beef", price: 18.0}, {title: "Potato", price: 8.2}], total: 26.2} # Hm(order).transform_keys(&:to_s).to_h # # => {"items"=>[{"title"=>"Beef", "price"=>18.0}, {"title"=>"Potato", "price"=>8.2}], "total"=>26.2} # Hm(order) # .transform_keys(&:to_s) # .transform_keys(['items', :*, :*], &:capitalize) # .transform_keys(:*, &:upcase).to_h # # => {"ITEMS"=>[{"Title"=>"Beef", "Price"=>18.0}, {"Title"=>"Potato", "Price"=>8.2}], "TOTAL"=>26.2} # # @see #transform_values # @see #transform # @param pathes [Array] List of pathes (each being singular key, or array of keys, including # `:*` wildcard) to look at. # @yieldparam key [Array] Current key to process. # @return [self] def transform_keys(*pathes) if pathes.empty? Algo.visit_all(@hash) do |at, path, val| if at.is_a?(Hash) at.delete(path.last) at[yield(path.last)] = val end end else pathes.each do |path| Algo.visit(@hash, path) do |at, pth, val| Algo.delete(at, pth.last) at[yield(pth.last)] = val end end end self end # Performs specified transformations on values of input sequence, limited only by specified # pathes. # # If no `pathes` are passed, all "terminal" values (e.g. not diggable) are yielded and transformed. # # @example # order = {items: [{title: "Beef", price: 18.0}, {title: "Potato", price: 8.2}], total: 26.2} # Hm(order).transform_values(%i[items * price], :total, &:to_s).to_h # # => {:items=>[{:title=>"Beef", :price=>"18.0"}, {:title=>"Potato", :price=>"8.2"}], :total=>"26.2"} # Hm(order).transform_values(&:to_s).to_h # # => {:items=>[{:title=>"Beef", :price=>"18.0"}, {:title=>"Potato", :price=>"8.2"}], :total=>"26.2"} # # @see #transform_keys # @see #transform # @param pathes [Array] List of pathes (each being singular key, or array of keys, including # `:*` wildcard) to look at. # @yieldparam value [Array] Current value to process. # @return [self] def transform_values(*pathes) if pathes.empty? Algo.visit_all(@hash) do |at, pth, val| at[pth.last] = yield(val) unless Dig.diggable?(val) end else pathes.each do |path| Algo.visit(@hash, path) { |at, pth, val| at[pth.last] = yield(val) } end end self end # Removes all specified pathes from input sequence. # # @example # order = {items: [{title: "Beef", price: 18.0}, {title: "Potato", price: 8.2}], total: 26.2} # Hm(order).except(%i[items * title]).to_h # # => {:items=>[{:price=>18.0}, {:price=>8.2}], :total=>26.2} # Hm(order).except([:items, 0, :title], :total).to_h # # => {:items=>[{:price=>18.0}, {:title=>"Potato", :price=>8.2}]} # # @see #slice # @param pathes [Array] List of pathes (each being singular key, or array of keys, including # `:*` wildcard) to look at. # @return [self] def except(*pathes) pathes.each do |path| Algo.visit(@hash, path) { |what, pth, _| Algo.delete(what, pth.last) } end self end # Preserves only specified pathes from input sequence. # # @example # order = {items: [{title: "Beef", price: 18.0}, {title: "Potato", price: 8.2}], total: 26.2} # Hm(order).slice(%i[items * title]).to_h # # => {:items=>[{:title=>"Beef"}, {:title=>"Potato"}]} # # @see #except # @param pathes [Array] List of pathes (each being singular key, or array of keys, including # `:*` wildcard) to look at. # @return [self] def slice(*pathes) result = Hm.new({}) pathes.each do |path| Algo.visit(@hash, path) { |_, new_path, val| result.bury(*new_path, val) } end @hash = result.to_h self end # Removes all `nil` values, including nested structures. # # @example # order = {items: [{title: "Beef", price: nil}, nil, {title: "Potato", price: 8.2}], total: 26.2} # Hm(order).compact.to_h # # => {:items=>[{:title=>"Beef"}, {:title=>"Potato", :price=>8.2}], :total=>26.2} # # @return [self] def compact Algo.visit_all(@hash) do |at, path, val| Algo.delete(at, path.last) if val.nil? end end # Removes all "empty" values and subcollections (`nil`s, empty strings, hashes and arrays), # including nested structures. Empty subcollections are removed recoursively. # # @example # order = {items: [{title: "Beef", price: 18.2}, {title: '', price: nil}], total: 26.2} # Hm(order).cleanup.to_h # # => {:items=>[{:title=>"Beef", :price=>18.2}], :total=>26.2} # # @return [self] def cleanup deletions = -1 # We do several runs to delete recursively: {a: {b: [nil]}} # first: {a: {b: []}} # second: {a: {}} # third: {} # More effective would be some "inside out" visiting, probably until deletions.zero? deletions = 0 Algo.visit_all(@hash) do |at, path, val| if val.nil? || val.respond_to?(:empty?) && val.empty? deletions += 1 Algo.delete(at, path.last) end end end self end # Select subset of the collection by provided block (optionally looking only at pathes specified). # # Method is added mostly for completeness, as filtering out wrong values is better done with # {#reject}, and selecting just by subset of keys by {#slice} and {#except}. # # @example # order = {items: [{title: "Beef", price: 18.0}, {title: "Potato", price: 8.2}], total: 26.2} # Hm(order).select { |path, val| val.is_a?(Float) }.to_h # # => {:items=>[{:price=>18.0}, {:price=>8.2}], :total=>26.2} # Hm(order).select([:items, :*, :price]) { |path, val| val > 10 }.to_h # # => {:items=>[{:price=>18.0}]} # # @see #reject # @param pathes [Array] List of pathes (each being singular key, or array of keys, including # `:*` wildcard) to look at. # @yieldparam path [Array] Current path at which the value is found # @yieldparam value Current value # @yieldreturn [true, false] Preserve value (with corresponding key) if true. # @return [self] def select(*pathes) res = Hm.new({}) if pathes.empty? Algo.visit_all(@hash) do |_, path, val| res.bury(*path, val) if yield(path, val) end else pathes.each do |path| Algo.visit(@hash, path) do |_, pth, val| res.bury(*pth, val) if yield(pth, val) end end end @hash = res.to_h self end # Drops subset of the collection by provided block (optionally looking only at pathes specified). # # @example # order = {items: [{title: "Beef", price: 18.0}, {title: "Potato", price: 8.2}], total: 26.2} # Hm(order).reject { |path, val| val.is_a?(Float) && val < 10 }.to_h # # => {:items=>[{:title=>"Beef", :price=>18.0}, {:title=>"Potato"}], :total=>26.2} # Hm(order).reject(%i[items * price]) { |path, val| val < 10 }.to_h # # => {:items=>[{:title=>"Beef", :price=>18.0}, {:title=>"Potato"}], :total=>26.2} # Hm(order).reject(%i[items *]) { |path, val| val[:price] < 10 }.to_h # # => {:items=>[{:title=>"Beef", :price=>18.0}], :total=>26.2} # # @see #select # @param pathes [Array] List of pathes (each being singular key, or array of keys, including # `:*` wildcard) to look at. # @yieldparam path [Array] Current path at which the value is found # @yieldparam value Current value # @yieldreturn [true, false] Remove value (with corresponding key) if true. # @return [self] def reject(*pathes) if pathes.empty? Algo.visit_all(@hash) do |at, path, val| Algo.delete(at, path.last) if yield(path, val) end else pathes.each do |path| Algo.visit(@hash, path) do |at, pth, val| Algo.delete(at, pth.last) if yield(pth, val) end end end self end # Calculates one value from several values at specified pathes, using specified block. # # @example # order = {items: [{title: "Beef", price: 18.0}, {title: "Potato", price: 8.2}]} # Hm(order).reduce(%i[items * price] => :total, &:+).to_h # # => {:items=>[{:title=>"Beef", :price=>18.0}, {:title=>"Potato", :price=>8.2}], :total=>26.2} # Hm(order).reduce(%i[items * price] => :total, %i[items * title] => :title, &:+).to_h # # => {:items=>[{:title=>"Beef", :price=>18.0}, {:title=>"Potato", :price=>8.2}], :total=>26.2, :title=>"BeefPotato"} # # @param keys_to_keys [Hash] Each key-value pair of input hash represents "source path to take # values" => "target path to store result of reduce". Each can be single key or nested path, # including `:*` wildcard. # @yieldparam memo # @yieldparam value # @return [self] def reduce(keys_to_keys, &block) keys_to_keys.each do |from, to| bury(*to, dig(*from).reduce(&block)) end self end # Split hash into two: the one with the substructure matching `pathes`, and the with thos that do # not. # # @example # order = {items: [{title: "Beef", price: 18.0}, {title: "Potato", price: 8.2}], total: 26.2} # Hm(order).partition(%i[items * price], :total) # # => [ # # {:items=>[{:price=>18.0}, {:price=>8.2}], :total=>26.2}, # # {:items=>[{:title=>"Beef"}, {:title=>"Potato"}]} # # ] # # @param pathes [Array] List of pathes (each being singular key, or array of keys, including # `:*` wildcard) to look at. # @yieldparam value [Array] Current value to process. # @return [Array<Hash>] Two hashes def partition(*pathes) # FIXME: this implementation is naive, it performs 2 additional deep copies and 2 full cycles of # visiting instead of just splitting existing data in one pass. It works, though [ Hm(@hash).slice(*pathes).to_h, Hm(@hash).except(*pathes).to_h ] end # Returns the result of all the processings inside the `Hm` object. # # Note, that you can pass an Array as a top-level structure to `Hm`, and in this case `to_h` will # return the processed Array... Not sure what to do about that currently. # # @return [Hash] def to_h @hash end alias to_hash to_h private def transform_one(from, to, remove: true, &_processor) # rubocop:disable Metrics/AbcSize,Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity to.count(:*) > 1 || from.count(:*) > 1 and fail NotImplementedError, 'Transforming to multi-wildcards is not implemented' from_values = {} Algo.visit( @hash, from, # [:item, :*, :price] -- if one item is priceless, should go to output sequence # ...but what if last key is :*? something like from_values.keys.last.succ or?.. not_found: ->(_, path, rest) { from_values[path + rest] = nil } ) { |_, path, val| from_values[path] = block_given? ? yield(val) : val } except(from) if remove if (ti = to.index(:*)) fi = from.index(:*) # TODO: what if `from` had no wildcard? # we unpack [:items, :*, :price] with keys we got from gathering values, # like [:items, 0, :price], [:items, 1, :price] etc. from_values .map { |key, val| [to.dup.tap { |a| a[ti] = key[fi] }, val] } .each { |path, val| bury(*path, val) } else val = from_values.count == 1 ? from_values.values.first : from_values.values bury(*to, val) end end end require_relative 'hm/version' require_relative 'hm/algo' require_relative 'hm/dig' # Shortcut for {Hm}.new def Hm(hash) # rubocop:disable Naming/MethodName Hm.new(hash) end
ruby
MIT
cd0ec27397c465f21a90d193be75538d24c6d8ae
2026-01-04T17:51:19.419456Z
false
zverok/hm
https://github.com/zverok/hm/blob/cd0ec27397c465f21a90d193be75538d24c6d8ae/lib/hm/version.rb
lib/hm/version.rb
class Hm MAJOR = 0 MINOR = 0 PATCH = 4 PRE = nil VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join('.') end
ruby
MIT
cd0ec27397c465f21a90d193be75538d24c6d8ae
2026-01-04T17:51:19.419456Z
false
zverok/hm
https://github.com/zverok/hm/blob/cd0ec27397c465f21a90d193be75538d24c6d8ae/lib/hm/algo.rb
lib/hm/algo.rb
class Hm # @private module Algo module_function def delete(collection, key) collection.is_a?(Array) ? collection.delete_at(key) : collection.delete(key) end # JRuby, I am looking at you NONDUPABLE = [Symbol, Numeric, NilClass, TrueClass, FalseClass].freeze def deep_copy(value) # FIXME: ignores Struct/OpenStruct (which are diggable too) case value when Hash value.map { |key, val| [key, deep_copy(val)] }.to_h when Array value.map(&method(:deep_copy)) when *NONDUPABLE value else value.dup end end # Enumerates through entire collection with "current key/current value" at each point, even # if elements are deleted in a process of enumeration def robust_enumerator(collection) case collection when Hash, Struct collection.each_pair.to_a when Array Enumerator.new do |y| cur = collection.size until cur.zero? pos = collection.size - cur y << [pos, collection[pos]] cur -= 1 end end when ->(c) { c.respond_to?(:each_pair) } collection.each_pair.to_a else fail TypeError, "Can't dig/* in #{collection.class}" end end def nest_hashes(value, *keys) return value if keys.empty? key = keys.shift val = keys.empty? ? value : nest_hashes(value, *keys) key.is_a?(Integer) ? [].tap { |arr| arr[key] = val } : {key => val} end def visit(what, rest, path = [], not_found: ->(*) {}, &found) Dig.diggable?(what) or fail TypeError, "#{what.class} is not diggable" key, *rst = rest if key == WILDCARD visit_wildcard(what, rst, path, found: found, not_found: not_found) else visit_regular(what, key, rst, path, found: found, not_found: not_found) end end def visit_all(what, path = [], &block) robust_enumerator(what).each do |key, val| yield(what, [*path, key], val) visit_all(val, [*path, key], &block) if Dig.diggable?(val) end end def visit_wildcard(what, rest, path, found:, not_found:) iterator = robust_enumerator(what) if rest.empty? iterator.map { |key, val| found.(what, [*path, key], val) } else iterator.map { |key, el| visit(el, rest, [*path, key], not_found: not_found, &found) } end end def visit_regular(what, key, rest, path, found:, not_found:) # rubocop:disable Metrics/ParameterLists internal = Dig.dig(what, key) # NB: NotFound is signified by special value, because `nil` can still be legitimate value in hash return not_found.(what, [*path, key], rest) if internal == Dig::NotFound rest.empty? and return found.(what, [*path, key], internal) visit(internal, rest, [*path, key], not_found: not_found, &found) end end end
ruby
MIT
cd0ec27397c465f21a90d193be75538d24c6d8ae
2026-01-04T17:51:19.419456Z
false
zverok/hm
https://github.com/zverok/hm/blob/cd0ec27397c465f21a90d193be75538d24c6d8ae/lib/hm/dig.rb
lib/hm/dig.rb
class Hm # @private module Dig # TODO: Struct/OpenStruct are also diggable in Ruby core, can be added for future implementation DIGGABLE_CLASSES = [Hash, Array].freeze NotFound = Object.new.freeze def self.dig(what, key, *keys) # We want to return special value when key is not present, because # 1. "at some point in path, we have a value, and this value is `nil`", and # 2. "at some point in path, we don't have a value (key is absent)" # ...should be different in Algo.visit return NotFound unless key?(what, key) return what.dig(key, *keys) if what.respond_to?(:dig) ensure_diggable?(what) or fail TypeError, "#{value.class} is not diggable" value = what[key] keys.empty? ? value : dig(value, *keys) end def self.key?(what, key) case what when Array (0...what.size).cover?(key) when Hash what.key?(key) end end def self.diggable?(what) DIGGABLE_CLASSES.include?(what.class) end end end
ruby
MIT
cd0ec27397c465f21a90d193be75538d24c6d8ae
2026-01-04T17:51:19.419456Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/init.rb
init.rb
# Include hook code here ActiveRecord::Base.send :include, ExpectedBehavior::ActsAsArchivalActiveRecordMethods ActiveRecord::Base.send :include, ExpectedBehavior::ActsAsArchival
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/polymorphic_test.rb
test/polymorphic_test.rb
require_relative "test_helper" class PolymorphicTest < ActiveSupport::TestCase test "archive item with polymorphic association" do archival = Archival.create! poly = archival.polys.create! archival.archive! assert archival.reload.archived? assert poly.reload.archived? end test "does not archive polymorphic association of different item with same id" do archival = Archival.create! another_polys_holder = AnotherPolysHolder.create!(id: archival.id) poly = another_polys_holder.polys.create! archival.archive! assert_not poly.reload.archived? end test "unarchive item with polymorphic association" do archive_attributes = { archive_number: "test", archived_at: Time.now } archival = Archival.create!(archive_attributes) poly = archival.polys.create!(archive_attributes) archival.unarchive! assert_not archival.reload.archived? assert_not poly.reload.archived? end test "does not unarchive polymorphic association of different item with same id" do archive_attributes = { archive_number: "test", archived_at: Time.now } archival = Archival.create!(archive_attributes) another_polys_holder = AnotherPolysHolder.create!(archive_attributes.merge(id: archival.id)) poly = another_polys_holder.polys.create!(archive_attributes) archival.unarchive! assert poly.reload.archived? end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/scope_test.rb
test/scope_test.rb
# coding: utf-8 require_relative "test_helper" class ScopeTest < ActiveSupport::TestCase test "simple unarchived scope" do Archival.create! Archival.create! assert_equal 2, Archival.unarchived.count end test "simple archived scope" do Archival.create!.archive! Archival.create!.archive! assert_equal 2, Archival.archived.count end test "mixed scopes" do Archival.create! Archival.create!.archive! assert_equal 1, Archival.archived.count assert_equal 1, Archival.unarchived.count end test "simple archived_from_archive_number" do archive_number = "TEST-IT" Archival.create!.archive!(archive_number) Archival.create!.archive!(archive_number) assert_equal 2, Archival.archived_from_archive_number(archive_number).count end test "negative archived_from_archive_number" do archive_number = "TEST-IT" bogus_number = "BROKE-IT" Archival.create!.archive!(archive_number) Archival.create!.archive!(archive_number) assert_equal 0, Archival.archived_from_archive_number(bogus_number).count end test "mixed archived_from_archive_number" do archive_number = "TEST-IT" Archival.create!.archive!(archive_number) Archival.create!.archive! assert_equal 1, Archival.archived_from_archive_number(archive_number).count end test "table_name is set to 'legacy'" do archived_sql = "SELECT \"legacy\".* FROM \"legacy\" " \ 'WHERE "legacy"."archived_at" IS NOT NULL AND "legacy"."archive_number" IS NOT NULL' unarchived_sql = "SELECT \"legacy\".* FROM \"legacy\" " \ 'WHERE "legacy"."archived_at" IS NULL AND "legacy"."archive_number" IS NULL' assert_equal archived_sql, ArchivalTableName.archived.to_sql assert_equal unarchived_sql, ArchivalTableName.unarchived.to_sql end test "combines with other scope properly" do Archival.create!(name: "Robert") Archival.create!(name: "Bobby") Archival.create!(name: "Sue") bob = Archival.create!(name: "Bob") bob.archive! assert_equal 3, Archival.bobs.count assert_equal 3, Archival.unarchived.count assert_equal 2, Archival.bobs.unarchived.count assert_equal 2, Archival.unarchived.bobs.count assert_equal 1, Archival.bobs.archived.count assert_equal 1, Archival.archived.bobs.count end test "scopes combine with relations correctly" do parent = Archival.create! parent.archivals.create! parent.archivals.create! child = parent.archivals.create! child.archive! assert_equal 3, parent.archivals.count assert_equal 1, parent.archivals.archived.count assert_equal 2, parent.archivals.unarchived.count end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/application_record_test.rb
test/application_record_test.rb
require_relative "test_helper" # Rails 5 introduced a new base class, and this is gonna test that if defined?(ApplicationRecord) class ApplicationRecordTest < ActiveSupport::TestCase test "archive archives the record" do archival = ApplicationRecordRow.create! archival.archive! assert archival.reload.archived? end test "unarchive unarchives archival records" do archival = ApplicationRecordRow.create!(archived_at: Time.now, archive_number: 1) archival.unarchive! assert_not archival.reload.archived? end end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/relations_test.rb
test/relations_test.rb
require_relative "test_helper" class RelationsTest < ActiveSupport::TestCase test "archive_all! archives all records in an AR Association" do 3.times { Archival.create! } archivals = Archival.all archivals.archive_all! assert archivals.first.archived? assert archivals.last.archived? end test "archive_all! archives all records with the same archival number" do 3.times { Archival.create! } archivals = Archival.all archivals.archive_all! assert_equal archivals.first.archive_number, archivals.last.archive_number end test "archive_all! archives children records" do 3.times do parent = Archival.create! 2.times do parent.archivals.create! end end parents = Archival.all parents.archive_all! assert parents.first.archivals.first.archived? assert parents.first.archivals.last.archived? end test "unarchive_all! unarchives all records in an AR Assocation" do 3.times { Archival.create! } archivals = Archival.all archivals.archive_all! archivals.unarchive_all! assert_not archivals.first.archived? assert_not archivals.last.archived? end test "unarchive_all! unarchives children records" do 3.times do parent = Archival.create! 2.times do parent.archivals.create! end end parents = Archival.all parents.archive_all! parents.unarchive_all! assert_not parents.first.archivals.first.archived? assert_not parents.first.archivals.last.archived? end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/column_test.rb
test/column_test.rb
require_relative "test_helper" class ColumnTest < ActiveSupport::TestCase test "acts_as_archival raises during create if missing archived_at column" do assert_raises(ExpectedBehavior::ActsAsArchival::MissingArchivalColumnError) do MissingArchivedAt.create!(name: "foo-foo") end end test "acts_as_archival raises during create if missing archive_number column" do assert_raises(ExpectedBehavior::ActsAsArchival::MissingArchivalColumnError) do MissingArchiveNumber.create!(name: "rover") end end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/responds_test.rb
test/responds_test.rb
require_relative "test_helper" class RespondsTest < ActiveSupport::TestCase test "archival class responds correctly to 'archival?'" do assert Archival.archival? assert_not Plain.archival? end test "archival object responds correctly to 'archival?'" do assert Archival.new.archival? assert_not Plain.new.archival? end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/basic_test.rb
test/basic_test.rb
require_relative "test_helper" class BasicTest < ActiveSupport::TestCase test "archive archives the record" do archival = Archival.create! archival.archive! assert_equal true, archival.reload.archived? end test "unarchive unarchives archival records" do archival = Archival.create!(archived_at: Time.now, archive_number: 1) archival.unarchive! assert_equal false, archival.reload.archived? end test "archive returns true on success" do normal = Archival.create! assert_equal true, normal.archive! end test "archive returns false on failure" do readonly = Archival.create! readonly.readonly! assert_equal false, readonly.archive! end test "unarchive returns true on success" do normal = Archival.create!(archived_at: Time.now, archive_number: "1") assert_equal true, normal.unarchive! end test "unarchive returns false on failure" do readonly = Archival.create!(archived_at: Time.now, archive_number: "1") readonly.readonly! assert_equal false, readonly.unarchive! end test "archive sets archived_at to the time of archiving" do archival = Archival.create! before = DateTime.now sleep(0.001) archival.archive! sleep(0.001) after = DateTime.now assert before < archival.archived_at.to_datetime assert after > archival.archived_at.to_datetime end test "archive sets the archive number to the md5 hexdigest for the model and id that is archived" do archival = Archival.create! archival.archive! expected_digest = Digest::MD5.hexdigest("#{archival.class.name}#{archival.id}") assert_equal expected_digest, archival.archive_number end test "archive on archived object doesn't alter the archive_number" do archived = Archival.create archived.archive! initial_number = archived.archive_number archived.reload.archive! second_number = archived.archive_number assert_equal initial_number, second_number end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/deep_nesting_test.rb
test/deep_nesting_test.rb
require_relative "test_helper" class DeepNestingTest < ActiveSupport::TestCase test "archiving deeply nested items" do archival = Archival.create! child = archival.archivals.create! grandchild = child.archivals.create! archival.archive! assert archival.reload.archived? assert child.reload.archived? assert grandchild.reload.archived? assert_equal archival.archive_number, child.archive_number assert_equal archival.archive_number, grandchild.archive_number end test "unarchiving deeply nested items doesn't blow up" do archival_attributes = { archived_at: Time.now, archive_number: "test" } archival = Archival.create!(archival_attributes) child = archival.archivals.create!(archival_attributes) grandchild = child.archivals.create!(archival_attributes) archival.unarchive! assert_not archival.reload.archived? assert_not child.reload.archived? assert_not grandchild.reload.archived? end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/transaction_test.rb
test/transaction_test.rb
require_relative "test_helper" require "rr" class TransactionTest < ActiveSupport::TestCase test "archiving is transactional" do archival = Archival.create! exploder = archival.exploders.create! any_instance_of(Exploder) do |canary| stub(canary).archive! { raise "Rollback Imminent" } end archival.archive! assert_not archival.archived?, "If this failed, you might be trying to test on a system that doesn't support nested transactions" assert_not exploder.reload.archived? end test "unarchiving is transactional" do archival = Archival.create! exploder = archival.exploders.create! any_instance_of(Exploder) do |canary| stub(canary).unarchive! { raise "Rollback Imminent" } end archival.archive! archival.unarchive! assert archival.reload.archived? assert exploder.reload.archived? end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/test_helper.rb
test/test_helper.rb
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") require "bundler/setup" require "minitest/autorun" require "minitest/pride" require "active_record" require "assertions" require "database_cleaner" require "acts_as_archival" if ActiveSupport::TestCase.respond_to?(:test_order=) ActiveSupport::TestCase.test_order = :random end def prepare_for_tests setup_logging setup_database_cleaner create_test_tables require_test_classes end def setup_logging require "logger" logfile = "#{File.dirname(__FILE__)}/debug.log" ActiveRecord::Base.logger = Logger.new(logfile) end def setup_database_cleaner DatabaseCleaner.strategy = :truncation ActiveSupport::TestCase.send(:setup) do DatabaseCleaner.clean end end def sqlite_config { adapter: "sqlite3", database: "aaa_test.sqlite3", pool: 5, timeout: 5000 } end def create_test_tables schema_file = "#{File.dirname(__FILE__)}/schema.rb" puts "** Loading schema for SQLite" ActiveRecord::Base.establish_connection(sqlite_config) load(schema_file) if File.exist?(schema_file) end BASE_FIXTURE_CLASSES = [ :another_polys_holder, :archival, :archival_kid, :archival_grandkid, :archival_table_name, :exploder, :independent_archival, :missing_archived_at, :missing_archive_number, :plain, :poly, :readonly_when_archived, :application_record, :application_record_row, :callback_archival ].freeze def require_test_classes ActiveSupport::Inflector.inflections do |inflect| inflect.irregular "poly", "polys" end BASE_FIXTURE_CLASSES.each do |test_class_file| require_relative "fixtures/#{test_class_file}" end end prepare_for_tests
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/associations_test.rb
test/associations_test.rb
require_relative "test_helper" class AssociationsTest < ActiveSupport::TestCase test "archive archives 'has_' associated archival objects that are dependent destroy" do archival = Archival.create! child = archival.archivals.create! archival.archive! assert archival.reload.archived? assert child.reload.archived? end test "archive acts on all objects in the 'has_' relationship" do archival = Archival.create! children = [archival.archivals.create!, archival.archivals.create!] archival.archive! assert archival.reload.archived? assert children.map(&:reload).all?(&:archived?) end test "archive does not act on already archived objects" do archival = Archival.create! archival.archivals.create! prearchived_child = archival.archivals.create! prearchived_child.archive! archival.archive! assert_not_equal archival.archive_number, prearchived_child.reload.archive_number end test "archive does not archive 'has_' associated archival objects that are not dependent destroy" do archival = Archival.create! non_dependent_child = archival.independent_archivals.create! archival.archive! assert archival.reload.archived? assert_not non_dependent_child.reload.archived? end test "archive doesn't do anything to associated dependent destroy models that are non-archival" do archival = Archival.create! plain = archival.plains.create! archival.archive! assert archival.archived? assert plain.reload end test "archive sets the object hierarchy to all have the same archive_number" do archival = Archival.create! child = archival.archivals.create! archival.archive! expected_digest = Digest::MD5.hexdigest("Archival#{archival.id}") assert_equal expected_digest, archival.archive_number assert_equal expected_digest, child.reload.archive_number end test "unarchive acts on child objects" do archival = Archival.create! child = archival.archivals.create! archival.archive! archival.unarchive! assert_not archival.archived? assert_not child.reload.archived? end test "unarchive does not act on already archived objects" do archival = Archival.create! child = archival.archivals.create! prearchived_child = archival.archivals.create! prearchived_child.archive! archival.archive! archival.unarchive! assert_not archival.archived? assert_not child.reload.archived? assert prearchived_child.reload.archived? end test "unarchive acts on 'has_' associated non-dependent_destroy objects" do archival = Archival.create! independent = archival.independent_archivals.create! archival.archive! independent.archive!(archival.archive_number) archival.unarchive! assert_not archival.reload.archived? assert_not independent.reload.archived? end test "unarchive doesn't unarchive associated objects if the head object is already unarchived" do archival = Archival.create! prearchived_child = archival.archivals.create! prearchived_child.archive! archival.unarchive! assert prearchived_child.reload.archived? end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/through_association_test.rb
test/through_association_test.rb
require_relative "test_helper" class ThroughAssociationTest < ActiveSupport::TestCase test "archive a through associated object whose 'bridge' is archival" do archival = Archival.create! bridge = archival.archival_kids.create! through = bridge.archival_grandkids.create! archival.archive! assert archival.reload.archived? assert bridge.reload.archived? assert through.reload.archived? end # TODO: Make something like this pass # test "archive a through associated object whose 'bridge' is not archival" do # archival = Archival.create! # bridge = archival.independent_archival_kids.create! # through = bridge.archival_grandkids.create! # archival.archive # assert archival.reload.archived? # assert through.reload.archived? # end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/readonly_when_archived_test.rb
test/readonly_when_archived_test.rb
require_relative "test_helper" class ReadonlyWhenArchivedTest < ActiveSupport::TestCase test "acts_as_archival objects can normally be altered after archive" do archival = Archival.create!(name: "original") archival.archive! archival.name = "updated" archival.save! assert_equal "updated", archival.reload.name end test "acts_as_archival marked as readonly_when_archived cannot be updated after archive" do archival = ReadonlyWhenArchived.create!(name: "original") archival.archive! archival.name = "updated" assert_not archival.save assert_equal "Cannot modify an archived record.", archival.errors.full_messages.first end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/ambiguous_table_test.rb
test/ambiguous_table_test.rb
require_relative "test_helper" class AmbiguousTableTest < ActiveSupport::TestCase test "no ambiguous table problem" do archival = Archival.create! child = archival.archivals.create! child.archive! # this is a bug fix for a problem wherein table names weren't being # namespaced, so if a table joined against itself, incorrect SQL was # generated assert_equal 1, Archival.unarchived.joins(:archivals).count end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/schema.rb
test/schema.rb
ActiveRecord::Schema.define(version: 1) do create_table :another_polys_holders, force: true do |t| t.column :name, :string t.column :archival_id, :integer t.column :archive_number, :string t.column :archived_at, :datetime end create_table :archivals, force: true do |t| t.column :name, :string t.column :archival_id, :integer t.column :archive_number, :string t.column :archived_at, :datetime end create_table :exploders, force: true do |t| t.column :archival_id, :integer t.column :archive_number, :string t.column :archived_at, :datetime end create_table :archival_kids, force: true do |t| t.column :archival_id, :integer t.column :archive_number, :string t.column :archived_at, :datetime end create_table :archival_grandkids, force: true do |t| t.column :archival_kid_id, :integer t.column :archive_number, :string t.column :archived_at, :datetime end create_table :independent_archivals, force: true do |t| t.column :name, :string t.column :archival_id, :integer t.column :archive_number, :string t.column :archived_at, :datetime end create_table :plains, force: true do |t| t.column :name, :string t.column :archival_id, :integer end create_table :readonly_when_archiveds, force: true do |t| t.column :name, :string t.column :archive_number, :string t.column :archived_at, :datetime end create_table :missing_archived_ats, force: true do |t| t.column :name, :string t.column :archive_number, :string end create_table :missing_archive_numbers, force: true do |t| t.column :name, :string t.column :archived_at, :datetime end create_table :polys, force: true do |t| t.references :archiveable, polymorphic: true t.column :archive_number, :string t.column :archived_at, :datetime end create_table :legacy, force: true do |t| t.column :name, :string t.column :archive_number, :string t.column :archived_at, :datetime end create_table :application_record_rows, force: true do |t| t.column :archive_number, :string t.column :archived_at, :datetime end create_table :callback_archivals, force: true do |t| t.column :settable_field, :string t.column :archive_number, :string t.column :archived_at, :datetime end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/callbacks_test.rb
test/callbacks_test.rb
require_relative "test_helper" class CallbacksTest < ActiveSupport::TestCase test "can set a value as part of archiving" do archival = CallbackArchival.create archival.set_this_value = "a test string" assert_nil archival.settable_field archival.archive! assert_equal "a test string", archival.reload.settable_field end test "can be halted" do archival = CallbackArchival.create archival.set_this_value = "a test string" archival.pass_callback = false assert_nil archival.settable_field archival.archive! assert_nil archival.reload.settable_field end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/fixtures/independent_archival.rb
test/fixtures/independent_archival.rb
# name - string # archival_id - integer # archive_number - string # archived_at - datetime class IndependentArchival < ActiveRecord::Base acts_as_archival belongs_to :archival end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/fixtures/callback_archival.rb
test/fixtures/callback_archival.rb
class CallbackArchival < ApplicationRecord acts_as_archival attr_accessor :set_this_value, :pass_callback before_archive :set_value, :conditional_callback_passer private def set_value self.settable_field = set_this_value end def conditional_callback_passer # we want to throw only for the value false throw(:abort) unless pass_callback || pass_callback.nil? end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/fixtures/plain.rb
test/fixtures/plain.rb
# name - string # archival_id - integer class Plain < ActiveRecord::Base belongs_to :archival end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/fixtures/application_record_row.rb
test/fixtures/application_record_row.rb
# Rails 5 introduced a new base class, and this is gonna be used in the tests of that if defined?(ApplicationRecord) class ApplicationRecordRow < ApplicationRecord acts_as_archival end end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/fixtures/archival.rb
test/fixtures/archival.rb
# name - string # archival_id - integer # archive_number - string # archived_at - datetime class Archival < ActiveRecord::Base acts_as_archival has_many :archivals, dependent: :destroy has_many :archival_kids, dependent: :destroy has_many :archival_grandkids, dependent: :destroy, through: :archival_kids has_many :exploders, dependent: :destroy has_many :plains, dependent: :destroy has_many :polys, dependent: :destroy, as: :archiveable has_many :independent_archivals scope :bobs, -> { where(name: %w[Bob Bobby Robert]) } end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/fixtures/archival_grandkid.rb
test/fixtures/archival_grandkid.rb
# archival_kid_id - integer # archive_number - string # archived_at - datetime class ArchivalGrandkid < ActiveRecord::Base acts_as_archival belongs_to :archival_kid end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false
expectedbehavior/acts_as_archival
https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/fixtures/readonly_when_archived.rb
test/fixtures/readonly_when_archived.rb
# name - string # archive_number - string # archived_at - datetime class ReadonlyWhenArchived < ActiveRecord::Base acts_as_archival readonly_when_archived: true end
ruby
MIT
65a6f284884d49cfbf1276602178fdae5982a09f
2026-01-04T17:51:12.709644Z
false