Module:EURMP

MyWikiBiz, Author Your Legacy — Wednesday May 29, 2024
Jump to navigationJump to search

Documentation for this module may be created at Module:EURMP/doc

--[[
European Union Register of medicinal products (for human use)
Module:EURMP
--]]

local formaturl = "https://ec.europa.eu/health/documents/community-register/html/h$1.htm"

local p = {}

local eurmpdata = mw.loadData("Module:EURMP/data")

-- Check for duplicate brand names
function p.checkdup(frame)
	local msg = {}
	local dup = {}
	for pname, id in pairs(eurmpdata.id) do
		if dup[pname] then
			msg[#msg + 1] = pname
		end
		dup[pname] = (dup[pname] or 0) + 1
	end
	return table.concat(msg, "<br>")
end

-- return url of detail page
function p.pname2url(frame)
	local name = mw.text.trim(frame.args[1] or ""):lower()
	local elink = ""
	local id = eurmpdata.id[name]
	if id then
		elink = formaturl:gsub("$1", id:match("%d+/%d+/(%d+)"))
	end
	return elink
end

-- return external link to detail page
function p.pname2link(frame)
	local name = mw.text.trim(frame.args[1] or ""):lower()
	local elink = ""
	local id = eurmpdata.id[name]
	if id then
		elink = "[" .. formaturl:gsub("$1", id:match("%d+/%d+/(%d+)")) .. " " .. name .. "]"
	end
	return elink
end

return p