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.



379
380
381
382
383
384
385
386
387
# File 'lib/oddb2xml/fhir_support.rb', line 379

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.



377
378
379
# File 'lib/oddb2xml/fhir_support.rb', line 377

def quantity
  @quantity
end

#substance_nameObject (readonly)

Returns the value of attribute substance_name.



377
378
379
# File 'lib/oddb2xml/fhir_support.rb', line 377

def substance_name
  @substance_name
end

#unitObject (readonly)

Returns the value of attribute unit.



377
378
379
# File 'lib/oddb2xml/fhir_support.rb', line 377

def unit
  @unit
end

Instance Method Details

#quantity_textObject



389
390
391
# File 'lib/oddb2xml/fhir_support.rb', line 389

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