Class: Synthra::Types::HealthMedical::MedicalCode

Inherits:
Base
  • Object
show all
Defined in:
lib/synthra/types/health_medical/medical.rb

Overview

MedicalCode type

Instance Method Summary collapse

Instance Method Details

#generate_edge(rng, context, args) ⇒ Object



140
141
142
# File 'lib/synthra/types/health_medical/medical.rb', line 140

def generate_edge(rng, context, args)
  ["A00.0", "Z99.9", "10000", "A0000"].sample(random: rng.instance_variable_get(:@random))
end

#generate_invalid(rng, context, args) ⇒ Object



144
145
146
# File 'lib/synthra/types/health_medical/medical.rb', line 144

def generate_invalid(rng, context, args)
  [nil, "not a code", "invalid", [], {}].sample(random: rng.instance_variable_get(:@random))
end

#generate_random(rng, context, args) ⇒ String

Generate random medical code

Parameters:

Options Hash (args):

  • :type (Symbol)

    code type (:icd10, :cpt, :hcpcs)

Returns:

  • (String)

    generated medical code



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/synthra/types/health_medical/medical.rb', line 122

def generate_random(rng, context, args)
  type = (args[:type] || :icd10).to_sym

  case type
  when :cpt
    # CPT codes: 5 digits
    format("%05d", rng.int(10000, 99999))
  when :hcpcs
    # HCPCS codes: 1 letter + 4 digits
    letter = rng.sample(("A".."Z").to_a)
    format("%s%04d", letter, rng.int(0, 9999))
  else # :icd10
    # ICD-10 codes: Letter + 2 digits + . + digit
    letter = rng.sample(("A".."Z").to_a)
    format("%s%02d.%d", letter, rng.int(0, 99), rng.int(0, 9))
  end
end