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.



372
373
374
375
376
377
378
379
380
# File 'lib/oddb2xml/fhir_support.rb', line 372

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.



370
371
372
# File 'lib/oddb2xml/fhir_support.rb', line 370

def quantity
  @quantity
end

#substance_nameObject (readonly)

Returns the value of attribute substance_name.



370
371
372
# File 'lib/oddb2xml/fhir_support.rb', line 370

def substance_name
  @substance_name
end

#unitObject (readonly)

Returns the value of attribute unit.



370
371
372
# File 'lib/oddb2xml/fhir_support.rb', line 370

def unit
  @unit
end

Instance Method Details

#quantity_textObject



382
383
384
# File 'lib/oddb2xml/fhir_support.rb', line 382

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