Class: Oddb2xml::FHIR::Ingredient

Inherits:
Object
  • Object
show all
Defined in:
lib/oddb2xml/fhir_support.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ Ingredient

Returns a new instance of Ingredient.



425
426
427
428
429
430
431
432
433
# File 'lib/oddb2xml/fhir_support.rb', line 425

def initialize(resource)
  @substance_name = resource.dig("substance", "code", "concept", "text")
  strength = resource.dig("substance", "strength", 0)
  @quantity = strength&.dig("presentationQuantity", "value")
  @unit = strength&.dig("presentationQuantity", "unit")

  # Handle textPresentation for ranges like "340-660"
  @text_presentation = strength&.dig("textPresentation")
end

Instance Attribute Details

#quantityObject (readonly)

Returns the value of attribute quantity.



423
424
425
# File 'lib/oddb2xml/fhir_support.rb', line 423

def quantity
  @quantity
end

#substance_nameObject (readonly)

Returns the value of attribute substance_name.



423
424
425
# File 'lib/oddb2xml/fhir_support.rb', line 423

def substance_name
  @substance_name
end

#unitObject (readonly)

Returns the value of attribute unit.



423
424
425
# File 'lib/oddb2xml/fhir_support.rb', line 423

def unit
  @unit
end

Instance Method Details

#quantity_textObject



435
436
437
# File 'lib/oddb2xml/fhir_support.rb', line 435

def quantity_text
  @text_presentation || (@quantity ? "#{@quantity}" : "")
end