Skip to content

Instantly share code, notes, and snippets.

@amitpatelx
Created October 16, 2018 09:39
Show Gist options
  • Save amitpatelx/8a7524801f1ba3745b2b624d2abaafdd to your computer and use it in GitHub Desktop.
Save amitpatelx/8a7524801f1ba3745b2b624d2abaafdd to your computer and use it in GitHub Desktop.
Investigating STAS-39
# Search product by show_name
p = Product.filter_by(show_name: 'Sildenafil').results
# Collect uniq drug names for search products
p.each_with_object([]) { |p, o| o << p.drug.name }.uniq
# => ["sildenafil 20 MG Oral Tablet", "sildenafil 100 MG Oral Tablet"]
# Search all drug with name `sildenafil`
Drug.where("name ilike '%sildenafil%'").pluck :name, :id
# => [["sildenafil 20 MG Oral Tablet", 1024], ["sildenafil 100 MG Oral Tablet", 1723], ["sildenafil 25 MG Oral Tablet", 2062], ["sildenafil 50 MG Oral Tablet", 4139], ["sildenafil 10 MG/ML Oral Suspension", 5588]]
# Find a drug which doesn't belongs to search product but is `sildenafil`
d=Drug.find 2062
d.products.count
# => 1
d.products.first.custom_name
# => "VIAGRA 25"
d.products.first.inventory_group.custom_name
# => "VIAGRA 25"
d.products.first.drug.show_name
# => "sildenafil 25 MG Oral Tablet"
# As per the following condition
text :show_name do
custom_name || inventory_group.custom_name || drug.show_name
end
# drug.show_name is gets the least priority for indexing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment