Vés al contingut

Mòdul:Medical infobox items

De la Viquipèdia, l'enciclopèdia lliure
local p = {}
local SA = require "Module:SimpleArgs"
local WD = require 'Module:Wikidades'
local SD = require 'Module:SimpleDebug'
local MLMT = require "Module:Multilang module tools"
local GIBT = require "Module:Global infobox tools"
local MIIi = require "Module:Medical infobox items/items"
local MIIi18n = require (SA.I18nName ("Medical infobox items"))

local ModuleAbbrev = 'MII'
local ModuleName = 'Medical infobox items'
local items = {
	[MIIi.k.Mesh] = {
		[MLMT.k.Args] = {
			[MIIi.k.MeshName]	= {"MeshName",          "_P486"},
			[MIIi.k.MeshNumber]	= {"MeshNumber",        ""},
			[MIIi.k.MeSH1]		= {{"MeshID","MeSH",
                                   "MeSH1"},            ""},
			[MIIi.k.MeshYear1]	= {{"MeshYear",
                                   "MeshYear1"},        ""},
			[MIIi.k.MeSH2]		= {"MeSH2",             ""},
			[MIIi.k.MeshYear2]	= {"MeshYear2",         ""},
			[MIIi.k.MeSH3]		= {"MeSH3",             ""},
			[MIIi.k.MeshYear3]	= {"MeshYear3",         ""},
			[MIIi.k.MeSH4]		= {"MeSH4",             ""},
			[MIIi.k.MeshYear4]	= {"MeshYear4",         ""},
			[MIIi.k.MeSH5]		= {"MeSH5",             ""},
			[MIIi.k.MeshYear5]	= {"MeshYear5",         ""},
			[MIIi.k.MeSH6]		= {"MeSH6",             ""},
			[MIIi.k.MeshYear6]	= {"MeshYear6",         ""},
			[MIIi.k.MeSH7]		= {"MeSH7",             ""},
			[MIIi.k.MeshYear7]	= {"MeshYear7",         ""},
			[MIIi.k.MeSH8]		= {"MeSH8",             ""},
			[MIIi.k.MeshYear8]	= {"MeshYear8",         ""},
			[MIIi.k.MeSH9]		= {"MeSH9",             ""},
			[MIIi.k.MeshYear9]	= {"MeshYear9",         ""},
		},
		[MLMT.k.Labels] = {
			[MIIi.k.Mesh]	    = "_Q199897",
		},	
	},
	[MIIi.k.eMed] = {
		[MLMT.k.Args] = {
			[MIIi.k.eMedicine]  	= {"eMedicine",     	"_P673"},
			[MIIi.k.eMedicineSubj]  = {"eMedicineSubj",     ""},
			[MIIi.k.eMedicineTopic] = {"eMedicineTopic",    ""},
			[MIIi.k.eMedicine_mult] = {"eMedicine_mult",    ""},
		},	
		[MLMT.k.Labels] = {
			[MIIi.k.eMed]	    = "_Q305913",
		},	
	},	
	[MIIi.k.Gene] = {
		[MLMT.k.Args] = {
			[MIIi.k.GeneReviewsID]		= {"GeneReviewsID",		 "_P668"},
			[MIIi.k.GeneReviewsNBK1]	= {{"GeneReviewsNBK",
											"GeneReviewsNBK1"},  ""},
			[MIIi.k.GeneReviewsName1]	= {{"GeneReviewsName",
											"GeneReviewsName1"}, ""},
			[MIIi.k.GeneReviewsNBK2]	= {"GeneReviewsNBK2",    ""},
			[MIIi.k.GeneReviewsName2]	= {"GeneReviewsName2",   ""},
			[MIIi.k.GeneReviewsNBK3]	= {"GeneReviewsNBK3",    ""},
			[MIIi.k.GeneReviewsName3]	= {"GeneReviewsName3",   ""},
			[MIIi.k.GeneReviewsNBK4]	= {"GeneReviewsNBK4",    ""},
			[MIIi.k.GeneReviewsName4]	= {"GeneReviewsName4",   ""},
			[MIIi.k.GeneReviewsNBK5]	= {"GeneReviewsNBK5",    ""},
			[MIIi.k.GeneReviewsName5]	= {"GeneReviewsName5",   ""},
			[MIIi.k.GeneReviewsNBK6]	= {"GeneReviewsNBK6",    ""},
			[MIIi.k.GeneReviewsName6]	= {"GeneReviewsName6",   ""},
			[MIIi.k.GeneReviewsNBK7]	= {"GeneReviewsNBK7",    ""},
			[MIIi.k.GeneReviewsName7]	= {"GeneReviewsName7",   ""},
		},	
		[MLMT.k.Labels] = {
			[MIIi.k.Gene]	    = "_Q3048291",
		},	
	},	
}
p.itemsM = {}

function p.LoadI18n ()
	p.itemsM[MIIi.k.Mesh] = MLMT.tableMerge (ModuleName, items[MIIi.k.Mesh], MIIi18n.items[MIIi.k.Mesh], true)
	p.itemsM[MIIi.k.eMed] = MLMT.tableMerge (ModuleName, items[MIIi.k.eMed], MIIi18n.items[MIIi.k.eMed], true)
	p.itemsM[MIIi.k.Gene] = MLMT.tableMerge (ModuleName, items[MIIi.k.Gene], MIIi18n.items[MIIi.k.Gene], true)
	MLMT.CheckLims (ModuleName, MIIi.arg_lims[MIIi.k.Mesh])
	MLMT.CheckLims (ModuleName, MIIi.arg_lims[MIIi.k.eMed])
	MLMT.add_mod_used (ModuleAbbrev, ModuleName)
end --LoadI18n

local function I18nArgMesh (key)
	return SA.CheckIsStrOrTab (p.itemsM[MIIi.k.Mesh][MLMT.k.Args][key][1], key)
end

local function I18nArgeMed (key)
	return SA.CheckIsStrOrTab (p.itemsM[MIIi.k.eMed][MLMT.k.Args][key][1], key)
end

local function I18nArgGene (key)
	return SA.CheckIsStrOrTab (p.itemsM[MIIi.k.Gene][MLMT.k.Args][key][1], key)
end

local function I18nLabel (key)
	return MLMT.GetLabel (p.itemsM[key], key) 
end

function p.arg_items (option, what)
	local function Do (key, ww)
		MLMT.add_arg_item (option, ModuleAbbrev, key, items[ww], MIIi18n.items[ww], MIIi.arg_lims[ww])
	end
	if MIIi.idx[what] == nil then
		error (what)
	end	
	for _, i in ipairs(MIIi.idx[what]) do
		i = i[2] --since only exists args:
		if what == MIIi.k.Mesh then
			Do (i, MIIi.k.Mesh)
		elseif what == MIIi.k.eMed then
			Do (i, MIIi.k.eMed)
		elseif what == MIIi.k.Gene then
			Do (i, MIIi.k.Gene)
		else
			error ('Invalid: '..what) --only for debug, don't translate
		end	
	end	
end --arg_items

function p.arglab_items (what)
	local function Do (key, ww) 
		GIBT.add_arglab_item (ModuleAbbrev, key, items[ww], MIIi18n.items[ww], MIIi.arg_lims[ww])
	end
	if MIIi.idx[what] == nil then
		error (what)
	end	
	for _, i in ipairs(MIIi.idx[what]) do 
		i = i[2] --since only exists args:
		if what == MIIi.k.Mesh then
			Do (i, MIIi.k.Mesh)
		elseif what == MIIi.k.eMed then
			Do (i, MIIi.k.eMed)
		elseif what == MIIi.k.Gene then
			Do (i, MIIi.k.Gene)
		else
			error ('Invalid: '..what) --only for debug, don't translate
		end	
	end	
end --arglab_items

function p.lab_items (what)
	local function write_tab (key)
		MLMT.add_lab_item (MLMT.GetLabelX (ModuleAbbrev, key, items[key], MIIi18n.items[what]))
	end	
	if what == MIIi.k.Mesh then
		write_tab (MIIi.k.Mesh)
	elseif what == MIIi.k.eMed then
		write_tab (MIIi.k.eMed)
	elseif what == MIIi.k.Gene then
		write_tab (MIIi.k.Gene)
	else
		error ('Invalid: '..what) --only for debug, don't translate
	end	
end --lab_items

function p.eMedicine (args)
	local Subj = nil
	local Topic = nil
	local mult = nil
	if GIBT.demo then
		Subj  = GIBT.ArgNameForDemo (items[MIIi.k.eMed], MIIi.k.eMedicineSubj)
		Topic = GIBT.ArgNameForDemo (items[MIIi.k.eMed], MIIi.k.eMedicineTopic)
		mult  = GIBT.ArgNameForDemo (items[MIIi.k.eMed], MIIi.k.eMedicine_mult)
	else	
		Subj = SA.Str_Par (args, I18nArgeMed(MIIi.k.eMedicineSubj))
	end	
	local res = ''
	if Subj == nil then
		res = WD.claim ({
			item=GIBT.id, 
			property='P673', 
			value=SA.Str_Par (args, I18nArgeMed(MIIi.k.eMedicine)), 
			formatting='[http://emedicine.medscape.com/article/$1 $1]'})
	else	
		if not GIBT.demo then
			Topic = SA.Str_Par (args, I18nArgeMed(MIIi.k.eMedicineTopic))
			mult = SA.Str_Par (args, I18nArgeMed(MIIi.k.eMedicine_mult))
		end	
		if Topic ~= nil then
			if Subj == 'search' then
				res = '[http://search.medscape.com/emedicine-search?queryText='..Topic..' topic list]'
			else
				if Subj == 'article' then
					res = '[http://emedicine.medscape.com/article/'..Topic..'-overview'
				else
					res = '[http://www.emedicine.com/'..Subj..'/topic'..Topic..'.htm'
				end	
				res = res..' '..Subj..'/'..Topic..']'
			end
			if mult ~= nil then
				res = res..' '..mult
			end	
		end	
	end
	if (res ~= nil) and (res ~= '') then
		GIBT.show (args, p.itemsM[MIIi.k.eMed], MIIi.k.eMed, res)
	end	
end --eMedicine	

function p.mesh (frame, args)
	local t = {}
	local function meshNYear (N, Year)
		table.insert (t, frame:expandTemplate {
		    title = 'mesh2',
		    args = {N, year=Year}})
	end	
	local function meshNNum (N, Num)
		table.insert (t, "''"..frame:expandTemplate {
		    title = 'mesh2',
		    args = {name=N, number=Num}}.."''")
	end	
	local MeshName = nil
	local MeshNumber = nil
	if GIBT.demo then
		MeshName = GIBT.ArgNameForDemo (items[MIIi.k.Mesh], MIIi.k.MeshName)
		MeshNumber = GIBT.ArgNameForDemo (items[MIIi.k.Mesh], MIIi.k.MeshNumber)
	else	
		MeshName = SA.Str_Par (args, I18nArgMesh(MIIi.k.MeshName))
		MeshNumber = SA.Str_Par (args, I18nArgMesh(MIIi.k.MeshNumber))
	end	
	local MeSH = 'MeSH'
	local MeshYear = 'MeshYear'
	if GIBT.demo then
		for i = 1, 9 do
			meshNYear (MeSH..i, 2000+i)
		end	
	else
		for i = 1, 9 do
			local MeshId = SA.Str_Par (args, I18nArgMesh(MeSH..i), nil)
			local MeshYear = SA.Int_Par (args, I18nArgMesh(MeshYear..i), nil)
			if MeshId == nil then
				break
			elseif MeshYear ~= nil then	
				meshNYear (MeshId, MeshYear)
			else
				break
			end	
		end	
	end	
	if (MeshName ~= nil) and (MeshNumber ~= nil) then
		meshNNum (MeshName, MeshNumber)	
	end	
	if #t == 0 then
		local res = ''
		res = WD.claim ({item=GIBT.id, property='P486', formatting='[https://www.nlm.nih.gov/cgi/mesh/'..os.date('%Y')..'/MB_cgi?field=uid&term=$1 $1]'})
		if res ~= '' then
			table.insert (t, res)
		end	
	end
	if #t ~= 0 then
		GIBT.show (args, p.itemsM[MIIi.k.Mesh], MIIi.k.Mesh, table.concat (t, ', '))
	end	
end --mesh

function p.gene (frame, args)
	local t = {}
	local ID = nil
	local NBK = nil
	local Name = nil
	if GIBT.demo then
		ID   = GIBT.ArgNameForDemo (items[MIIi.k.Gene], MIIi.k.GeneReviewsID)
		NBK  = GIBT.ArgNameForDemo (items[MIIi.k.Gene], MIIi.k.GeneReviewsNBK1)
		Name = GIBT.ArgNameForDemo (items[MIIi.k.Gene], MIIi.k.GeneReviewsName1)
	else	
		ID = SA.Str_Par (args, I18nArgGene(MIIi.k.GeneReviewsID), nil)
		NBK = SA.Str_Par (args, I18nArgGene(MIIi.k.GeneReviewsNBK1), nil)
		Name = SA.Str_Par (args, I18nArgGene(MIIi.k.GeneReviewsName1), nil)
	end
	local function NCBIBook2 (ANBK, AName)
		table.insert (t, frame:expandTemplate {
		    title = 'NCBIBook2',
		    args = {ANBK, AName}})
	end	
	if NBK ~= nil then
		if Name ~= nil then
			NCBIBook2 (NBK, Name)
		end	
	elseif ID ~= nil then	
		if Name == nil then
			ID = ID..' '..ID
		else	
			ID = ID..' '..Name
		end
		table.insert (t, '[http://www.ncbi.nlm.nih.gov/books/n/gene/'..ID..']')
	end
	if (NBK ~= nil)  or (ID ~= nil) then
		local GeneReviewsNBK = 'GeneReviewsNBK'
		local GeneReviewsName = 'GeneReviewsName'
		if GIBT.demo then
			for i = 2, 7 do
				NCBIBook2 ('NBK'..i, 'Name'..i)
			end	
		else
			for i = 2, 7 do
				local NBK = SA.Str_Par (args, I18nArgGene(GeneReviewsNBK..i), nil)
				local Name = SA.Str_Par (args, I18nArgGene(GeneReviewsName..i), nil)
				if NBK == nil then
					break
				else	
					NCBIBook2 (NBK, Name)	
				end	
			end	
		end	
	elseif (not GIBT.demo) then
		local res = ''
		res = WD.claim ({item=GIBT.id, property='P668', formatting='[https://www.ncbi.nlm.nih.gov/books/$1 Panoramica]'})
		if res ~= '' then
			table.insert (t, res)
		end	
	end
	if #t ~= 0 then
		GIBT.show (args, p.itemsM[MIIi.k.Gene], MIIi.k.Gene, table.concat (t, '</br>'))
	end	
end --gene

return p